2
* This file is part of the Control Center.
4
* Copyright (c) 2006 Novell, Inc.
6
* The Control Center is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License as published by the Free
8
* Software Foundation; either version 2 of the License, or (at your option)
11
* The Control Center is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16
* You should have received a copy of the GNU General Public License along with
17
* the Control Center; if not, write to the Free Software Foundation, Inc., 51
18
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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>
21
22
#include "config.h"
23
24
#include <glib/gi18n.h>
27
#include "gnome-control-center.h"
24
29
#include <gtk/gtk.h>
25
#include <libgnome/gnome-desktop-item.h>
26
#include <unique/unique.h>
28
#include <libslab/slab.h>
30
void handle_static_action_clicked (Tile * tile, TileEvent * event, gpointer data);
31
static GSList *get_actions_list ();
33
#define CONTROL_CENTER_PREFIX "/apps/control-center/cc_"
34
#define CONTROL_CENTER_ACTIONS_LIST_KEY (CONTROL_CENTER_PREFIX "actions_list")
35
#define CONTROL_CENTER_ACTIONS_SEPARATOR ";"
36
#define EXIT_SHELL_ON_STATIC_ACTION "exit_shell_on_static_action"
39
get_actions_list (void)
43
GSList *actions_list = NULL;
46
key_list = get_slab_gconf_slist (CONTROL_CENTER_ACTIONS_LIST_KEY);
49
g_warning (_("key not found [%s]\n"), CONTROL_CENTER_ACTIONS_LIST_KEY);
53
for (l = key_list; l != NULL; l = l->next)
55
gchar *entry = (gchar *) l->data;
58
action = g_new (AppAction, 1);
59
temp = g_strsplit (entry, CONTROL_CENTER_ACTIONS_SEPARATOR, 2);
60
action->name = g_strdup (temp[0]);
61
if ((action->item = load_desktop_item_from_unknown (temp[1])) == NULL)
63
g_warning ("get_actions_list() - PROBLEM - Can't load %s\n", temp[1]);
67
actions_list = g_slist_prepend (actions_list, action);
73
g_slist_free (key_list);
75
return g_slist_reverse (actions_list);
79
handle_static_action_clicked (Tile * tile, TileEvent * event, gpointer data)
82
AppShellData *app_data = (AppShellData *) data;
83
GnomeDesktopItem *item =
84
(GnomeDesktopItem *) g_object_get_data (G_OBJECT (tile), APP_ACTION_KEY);
86
if (event->type == TILE_EVENT_ACTIVATED_DOUBLE_CLICK)
88
open_desktop_item_exec (item);
90
temp = g_strdup_printf("%s%s", app_data->gconf_prefix, EXIT_SHELL_ON_STATIC_ACTION);
91
if (get_slab_gconf_bool(temp))
93
if (app_data->exit_on_close)
96
hide_shell (app_data);
101
static UniqueResponse
102
message_received_cb (UniqueApp *app,
103
UniqueCommand command,
104
UniqueMessageData *message,
109
AppShellData *app_data = user_data;
112
case UNIQUE_ACTIVATE:
113
/* move the main window to the screen that sent us the command */
114
gtk_window_set_screen (GTK_WINDOW (app_data->main_app),
115
unique_message_data_get_screen (message));
116
if (!app_data->main_app_window_shown_once)
117
show_shell (app_data);
119
gtk_window_present_with_time (GTK_WINDOW (app_data->main_app),
122
gtk_widget_grab_focus (SLAB_SECTION (app_data->filter_section)->contents);
124
res = UNIQUE_RESPONSE_OK;
127
res = UNIQUE_RESPONSE_PASSTHROUGH;
32
#include "cc-shell-log.h"
34
G_GNUC_NORETURN static gboolean
35
option_version_cb (const gchar *option_name,
40
g_print ("%s %s\n", PACKAGE, VERSION);
44
static char **start_panels = NULL;
45
static gboolean show_overview = FALSE;
46
static gboolean verbose = FALSE;
47
static gboolean show_help = FALSE;
49
const GOptionEntry all_options[] = {
50
{ "version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_version_cb, NULL, NULL },
51
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, N_("Enable verbose mode"), NULL },
52
{ "overview", 'o', 0, G_OPTION_ARG_NONE, &show_overview, N_("Show the overview"), NULL },
53
{ "help", '?', 0, G_OPTION_ARG_NONE, &show_help, N_("Show help options"), NULL },
54
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &start_panels, N_("Panel to display"), NULL },
55
{ NULL } /* end the list */
59
application_command_line_cb (GApplication *application,
60
GApplicationCommandLine *command_line,
61
GnomeControlCenter *shell)
66
GOptionContext *context;
70
show_overview = FALSE;
74
argv = g_application_command_line_get_arguments (command_line, &argc);
76
context = g_option_context_new (N_("- System Settings"));
77
g_option_context_add_main_entries (context, all_options, GETTEXT_PACKAGE);
78
g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);
79
g_option_context_add_group (context, gtk_get_option_group (TRUE));
80
g_option_context_set_help_enabled (context, FALSE);
82
if (g_option_context_parse (context, &argc, &argv, &error) == FALSE)
84
g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
85
error->message, argv[0]);
87
g_option_context_free (context);
95
help = g_option_context_get_help (context, FALSE, NULL);
98
g_option_context_free (context);
102
g_option_context_free (context);
104
cc_shell_log_set_debug (verbose);
106
gnome_control_center_show (shell, GTK_APPLICATION (application));
110
gnome_control_center_set_overview_page (shell);
112
else if (start_panels != NULL && start_panels[0] != NULL)
114
const char *start_id;
117
start_id = start_panels[0];
119
if (!cc_shell_set_active_panel_from_id (CC_SHELL (shell), start_id, &err))
121
g_warning ("Could not load setting panel \"%s\": %s", start_id,
122
(err) ? err->message : "Unknown error");
132
gnome_control_center_present (shell);
133
gdk_notify_startup_complete ();
136
if (start_panels != NULL)
138
g_strfreev (start_panels);
141
show_overview = FALSE;
147
application_startup_cb (GApplication *application,
148
GnomeControlCenter *shell)
150
/* nothing to do here, we don't want to show a window before
151
* we've looked at the commandline
135
main (int argc, char *argv[])
156
main (int argc, char **argv)
137
gboolean hidden = FALSE;
138
UniqueApp *unique_app;
139
AppShellData *app_data;
142
GOptionEntry options[] = {
143
{ "hide", 0, 0, G_OPTION_ARG_NONE, &hidden, N_("Hide on start (useful to preload the shell)"), NULL },
148
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
149
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
150
textdomain (GETTEXT_PACKAGE);
154
if (!gtk_init_with_args (&argc, &argv,
155
NULL, options, GETTEXT_PACKAGE, &error)) {
156
g_printerr ("%s\n", error->message);
157
g_error_free (error);
161
unique_app = unique_app_new ("org.gnome.gnome-control-center.shell", NULL);
162
if (unique_app_is_running (unique_app)) {
166
UniqueResponse response;
167
response = unique_app_send_message (unique_app,
170
retval = (response != UNIQUE_RESPONSE_OK);
173
g_object_unref (unique_app);
177
app_data = appshelldata_new ("gnomecc.menu", NULL, CONTROL_CENTER_PREFIX,
178
GTK_ICON_SIZE_DND, FALSE, TRUE);
179
generate_categories (app_data);
181
actions = get_actions_list ();
182
layout_shell (app_data, _("Filter"), _("Groups"), _("Common Tasks"), actions,
183
handle_static_action_clicked);
185
create_main_window (app_data, "MyControlCenter", _("Control Center"),
186
"gnome-control-center", 975, 600, hidden);
188
unique_app_watch_window (unique_app, GTK_WINDOW (app_data->main_app));
189
g_signal_connect (unique_app, "message-received",
190
G_CALLBACK (message_received_cb), app_data);
194
g_object_unref (unique_app);
158
GnomeControlCenter *shell;
159
GtkApplication *application;
162
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
163
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
164
textdomain (GETTEXT_PACKAGE);
167
g_thread_init (NULL);
168
gtk_init (&argc, &argv);
169
cc_shell_log_init ();
171
shell = gnome_control_center_new ();
173
/* enforce single instance of this application */
174
application = gtk_application_new ("org.gnome.ControlCenter", G_APPLICATION_HANDLES_COMMAND_LINE);
175
g_signal_connect (application, "startup",
176
G_CALLBACK (application_startup_cb), shell);
177
g_signal_connect (application, "command-line",
178
G_CALLBACK (application_command_line_cb), shell);
180
status = g_application_run (G_APPLICATION (application), argc, argv);
182
g_object_unref (application);