1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2  * main.c
3  * Copyright (C) 1999 Free Software Foundation, Inc.
4  * Copyright (C) 2008 Lucas Rocha.
5  * Copyright (C) 2012-2021 MATE Developers
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301, USA.
21  */
22 
23 #include <config.h>
24 
25 #include <unistd.h>
26 #include <stdlib.h>
27 
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.h>
30 
31 #include "gsm-properties-dialog.h"
32 
33 static gboolean show_version = FALSE;
34 
35 static GOptionEntry options[] = {
36 	{"version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Version of this application"), NULL},
37 	{NULL, 0, 0, 0, NULL, NULL, NULL}
38 };
39 
dialog_response(GsmPropertiesDialog * dialog,guint response_id,gpointer data)40 static void dialog_response(GsmPropertiesDialog* dialog, guint response_id, gpointer data)
41 {
42 	GError* error;
43 
44 	if (response_id == GTK_RESPONSE_HELP)
45 	{
46 		error = NULL;
47 		gtk_show_uri_on_window (GTK_WINDOW (dialog), "help:mate-user-guide/gosstartsession-2",
48 					gtk_get_current_event_time (), &error);
49 
50 		if (error != NULL)
51 		{
52 			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"));
53 			gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(d), "%s", error->message);
54 			g_error_free(error);
55 
56 			gtk_dialog_run(GTK_DIALOG (d));
57 			gtk_widget_destroy(d);
58 		}
59 	}
60 	else
61 	{
62 		gtk_widget_destroy(GTK_WIDGET (dialog));
63 		gtk_main_quit();
64 	}
65 }
66 
main(int argc,char * argv[])67 int main(int argc, char* argv[])
68 {
69 	GError* error;
70 	GtkWidget* dialog;
71 
72 #ifdef ENABLE_NLS
73 	bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
74 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
75 	textdomain(GETTEXT_PACKAGE);
76 #endif /* ENABLE_NLS */
77 
78 	error = NULL;
79 
80 	if (!gtk_init_with_args(&argc, &argv, _("- MATE Session Properties"), options, GETTEXT_PACKAGE, &error))
81 	{
82 		g_warning("Unable to start: %s", error->message);
83 		g_error_free(error);
84 		return 1;
85 	}
86 
87 	if (show_version)
88 	{
89 		g_print("%s %s\n", argv[0], VERSION);
90 		return 0;
91 	}
92 
93 	dialog = gsm_properties_dialog_new();
94 	g_signal_connect(dialog, "response", G_CALLBACK(dialog_response), NULL);
95 	gtk_widget_show(dialog);
96 
97 	gtk_main();
98 
99 	return 0;
100 }
101