2
* Copyright (c) 2009, 2010 Intel, Inc.
3
* Copyright (c) 2010 Red Hat, Inc.
5
* The Control Center is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by the
7
* Free Software Foundation; either version 2 of the License, or (at your
8
* option) any later version.
10
* The Control Center is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15
* You should have received a copy of the GNU General Public License along
16
* with the Control Center; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
* Author: Thomas Wood <thos@gnome.org>
24
#include <glib/gi18n.h>
27
#include "gnome-control-center.h"
31
#include <libnotify/notify.h>
33
#ifdef GDK_WINDOWING_X11
37
#include "cc-shell-log.h"
39
G_GNUC_NORETURN static gboolean
40
option_version_cb (const gchar *option_name,
45
g_print ("%s %s\n", PACKAGE, VERSION);
49
static char **start_panels = NULL;
50
static gboolean show_overview = FALSE;
51
static gboolean verbose = FALSE;
52
static gboolean show_help = FALSE;
53
static gboolean show_help_gtk = FALSE;
54
static gboolean show_help_all = FALSE;
56
const GOptionEntry all_options[] = {
57
{ "version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_version_cb, NULL, NULL },
58
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, N_("Enable verbose mode"), NULL },
59
{ "overview", 'o', 0, G_OPTION_ARG_NONE, &show_overview, N_("Show the overview"), NULL },
60
{ "help", 'h', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &show_help, N_("Show help options"), NULL },
61
{ "help-all", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &show_help_all, N_("Show help options"), NULL },
62
{ "help-gtk", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &show_help_gtk, N_("Show help options"), NULL },
63
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &start_panels, N_("Panel to display"), NULL },
64
{ NULL, 0, 0, 0, NULL, NULL, NULL } /* end the list */
68
application_command_line_cb (GApplication *application,
69
GApplicationCommandLine *command_line,
70
GnomeControlCenter *shell)
75
GOptionContext *context;
79
show_overview = FALSE;
83
argv = g_application_command_line_get_arguments (command_line, &argc);
85
context = g_option_context_new (N_("- System Settings"));
86
g_option_context_add_main_entries (context, all_options, GETTEXT_PACKAGE);
87
g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);
88
g_option_context_add_group (context, gtk_get_option_group (TRUE));
89
g_option_context_set_help_enabled (context, FALSE);
91
if (g_option_context_parse (context, &argc, &argv, &error) == FALSE)
93
g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
94
error->message, argv[0]);
96
g_option_context_free (context);
100
if (show_help || show_help_all || show_help_gtk)
105
if (show_help || show_help_all)
108
group = gtk_get_option_group (FALSE);
110
help = g_option_context_get_help (context, FALSE, group);
111
g_print ("%s", help);
113
g_option_context_free (context);
117
g_option_context_free (context);
119
cc_shell_log_set_debug (verbose);
121
gnome_control_center_show (shell, GTK_APPLICATION (application));
125
gnome_control_center_set_overview_page (shell);
127
else if (start_panels != NULL && start_panels[0] != NULL)
129
const char *start_id;
132
start_id = start_panels[0];
135
g_debug ("Extra argument: %s", start_panels[1]);
137
g_debug ("No extra argument");
139
if (!cc_shell_set_active_panel_from_id (CC_SHELL (shell), start_id, (const gchar**)start_panels+1, &err))
141
g_warning ("Could not load setting panel \"%s\": %s", start_id,
142
(err) ? err->message : "Unknown error");
152
gnome_control_center_present (shell);
153
gdk_notify_startup_complete ();
156
if (start_panels != NULL)
158
g_strfreev (start_panels);
161
show_overview = FALSE;
167
help_activated (GSimpleAction *action,
171
GnomeControlCenter *shell = user_data;
172
CcPanel *panel = cc_shell_get_active_panel (CC_SHELL (shell));
173
GtkWidget *window = cc_shell_get_toplevel (CC_SHELL (shell));
174
const char *uri = NULL;
177
uri = cc_panel_get_help_uri (panel);
179
gtk_show_uri (gtk_widget_get_screen (window),
180
uri ? uri : "help:gnome-help/prefs",
181
GDK_CURRENT_TIME, NULL);
185
quit_activated (GSimpleAction *action,
189
GnomeControlCenter *shell = user_data;
190
g_object_unref (shell);
194
application_startup_cb (GApplication *application,
195
GnomeControlCenter *shell)
197
GMenu *menu, *section;
200
action = G_ACTION (g_simple_action_new ("help", NULL));
201
g_action_map_add_action (G_ACTION_MAP (application), action);
202
g_signal_connect (action, "activate", G_CALLBACK (help_activated), shell);
204
action = G_ACTION (g_simple_action_new ("quit", NULL));
205
g_action_map_add_action (G_ACTION_MAP (application), action);
206
g_signal_connect (action, "activate", G_CALLBACK (quit_activated), shell);
208
menu = g_menu_new ();
210
section = g_menu_new ();
211
g_menu_append (section, _("Help"), "app.help");
212
g_menu_append (section, _("Quit"), "app.quit");
214
g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
216
gtk_application_set_app_menu (GTK_APPLICATION (application),
217
G_MENU_MODEL (menu));
219
gtk_application_add_accelerator (GTK_APPLICATION (application),
220
"F1", "app.help", NULL);
222
/* nothing else to do here, we don't want to show a window before
223
* we've looked at the commandline
228
main (int argc, char **argv)
230
GnomeControlCenter *shell;
231
GtkApplication *application;
234
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
235
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
236
textdomain (GETTEXT_PACKAGE);
238
#ifdef GDK_WINDOWING_X11
242
gtk_init (&argc, &argv);
243
cc_shell_log_init ();
245
/* register a symbolic icon size for use in sidebar lists */
246
gtk_icon_size_register ("cc-sidebar-list", 24, 24);
248
notify_init ("gnome-control-center");
250
shell = gnome_control_center_new ();
252
/* enforce single instance of this application */
253
application = gtk_application_new ("org.gnome.ControlCenter", G_APPLICATION_HANDLES_COMMAND_LINE);
254
g_signal_connect (application, "startup",
255
G_CALLBACK (application_startup_cb), shell);
256
g_signal_connect (application, "command-line",
257
G_CALLBACK (application_command_line_cb), shell);
259
status = g_application_run (G_APPLICATION (application), argc, argv);
261
g_object_unref (application);