summaryrefslogtreecommitdiff
path: root/capplet/main.c
blob: 257618f702946b71a1866611376751c79394a266 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
 * main.c
 * Copyright (C) 1999 Free Software Foundation, Inc.
 * Copyright (C) 2008 Lucas Rocha.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

#include <config.h>

#include <unistd.h>
#include <stdlib.h>

#include <glib/gi18n.h>
#include <gtk/gtk.h>

#include "gsm-properties-dialog.h"

static gboolean show_version = FALSE;

static GOptionEntry options[] = {
	{"version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Version of this application"), NULL},
	{NULL, 0, 0, 0, NULL, NULL, NULL}
};

static void dialog_response(GsmPropertiesDialog* dialog, guint response_id, gpointer data)
{
#if GTK_CHECK_VERSION (3, 22, 0)
	GError* error;

	if (response_id == GTK_RESPONSE_HELP)
	{
		error = NULL;
		gtk_show_uri_on_window (GTK_WINDOW (dialog), "help:mate-user-guide/gosstartsession-2",
					gtk_get_current_event_time (), &error);
#else
	GdkScreen* screen;
	GError* error;

	if (response_id == GTK_RESPONSE_HELP)
	{
		screen = gtk_widget_get_screen(GTK_WIDGET (dialog));

		error = NULL;
		gtk_show_uri (screen, "help:mate-user-guide/gosstartsession-2",
			      gtk_get_current_event_time (), &error);
#endif

		if (error != NULL)
		{
			GtkWidget* d = gtk_message_dialog_new(GTK_WINDOW(dialog), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", _("Could not display help document"));
			gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(d), "%s", error->message);
			g_error_free(error);

			gtk_dialog_run(GTK_DIALOG (d));
			gtk_widget_destroy(d);
		}
	}
	else
	{
		gtk_widget_destroy(GTK_WIDGET (dialog));
		gtk_main_quit();
	}
}

int main(int argc, char* argv[])
{
	GError* error;
	GtkWidget* dialog;

	bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
	textdomain(GETTEXT_PACKAGE);

	error = NULL;

	if (!gtk_init_with_args(&argc, &argv, " - MATE Session Properties", options, GETTEXT_PACKAGE, &error))
	{
		g_warning("Unable to start: %s", error->message);
		g_error_free(error);
		return 1;
	}

	if (show_version)
	{
		g_print("%s %s\n", argv[0], VERSION);
		return 0;
	}

	dialog = gsm_properties_dialog_new();
	g_signal_connect(dialog, "response", G_CALLBACK(dialog_response), NULL);
	gtk_widget_show(dialog);

	gtk_main();

	return 0;
}