~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to shell/control-center.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * This file is part of the Control Center.
3
 
 *
4
 
 * Copyright (c) 2006 Novell, Inc.
5
 
 *
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)
9
 
 * any later version.
10
 
 *
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
14
 
 * more details.
15
 
 *
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.
 
4
 *
 
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.
 
9
 *
 
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
 
13
 * for more details.
 
14
 *
 
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
 
18
 *
 
19
 * Author: Thomas Wood <thos@gnome.org>
19
20
 */
20
21
 
21
22
#include "config.h"
22
23
 
23
24
#include <glib/gi18n.h>
 
25
#include <stdlib.h>
 
26
 
 
27
#include "gnome-control-center.h"
 
28
 
24
29
#include <gtk/gtk.h>
25
 
#include <libgnome/gnome-desktop-item.h>
26
 
#include <unique/unique.h>
27
 
 
28
 
#include <libslab/slab.h>
29
 
 
30
 
void handle_static_action_clicked (Tile * tile, TileEvent * event, gpointer data);
31
 
static GSList *get_actions_list ();
32
 
 
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"
37
 
 
38
 
static GSList *
39
 
get_actions_list (void)
40
 
{
41
 
        GSList *l;
42
 
        GSList *key_list;
43
 
        GSList *actions_list = NULL;
44
 
        AppAction *action;
45
 
 
46
 
        key_list = get_slab_gconf_slist (CONTROL_CENTER_ACTIONS_LIST_KEY);
47
 
        if (!key_list)
48
 
        {
49
 
                g_warning (_("key not found [%s]\n"), CONTROL_CENTER_ACTIONS_LIST_KEY);
50
 
                return NULL;
51
 
        }
52
 
 
53
 
        for (l = key_list; l != NULL; l = l->next)
54
 
        {
55
 
                gchar *entry = (gchar *) l->data;
56
 
                gchar **temp;
57
 
 
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)
62
 
                {
63
 
                        g_warning ("get_actions_list() - PROBLEM - Can't load %s\n", temp[1]);
64
 
                }
65
 
                else
66
 
                {
67
 
                        actions_list = g_slist_prepend (actions_list, action);
68
 
                }
69
 
                g_strfreev (temp);
70
 
                g_free (entry);
71
 
        }
72
 
 
73
 
        g_slist_free (key_list);
74
 
 
75
 
        return g_slist_reverse (actions_list);
76
 
}
77
 
 
78
 
void
79
 
handle_static_action_clicked (Tile * tile, TileEvent * event, gpointer data)
80
 
{
81
 
        gchar *temp;
82
 
        AppShellData *app_data = (AppShellData *) data;
83
 
        GnomeDesktopItem *item =
84
 
                (GnomeDesktopItem *) g_object_get_data (G_OBJECT (tile), APP_ACTION_KEY);
85
 
 
86
 
        if (event->type == TILE_EVENT_ACTIVATED_DOUBLE_CLICK)
87
 
                return;
88
 
        open_desktop_item_exec (item);
89
 
 
90
 
        temp = g_strdup_printf("%s%s", app_data->gconf_prefix, EXIT_SHELL_ON_STATIC_ACTION);
91
 
        if (get_slab_gconf_bool(temp))
92
 
        {
93
 
                if (app_data->exit_on_close)
94
 
                        gtk_main_quit ();
95
 
                else
96
 
                        hide_shell (app_data);
97
 
        }
98
 
        g_free (temp);
99
 
}
100
 
 
101
 
static UniqueResponse
102
 
message_received_cb (UniqueApp         *app,
103
 
                     UniqueCommand      command,
104
 
                     UniqueMessageData *message,
105
 
                     guint              time,
106
 
                     gpointer           user_data)
107
 
{
108
 
        UniqueResponse  res;
109
 
        AppShellData   *app_data = user_data;
110
 
 
111
 
        switch (command) {
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);
118
 
 
119
 
                gtk_window_present_with_time (GTK_WINDOW (app_data->main_app),
120
 
                                              time);
121
 
 
122
 
                gtk_widget_grab_focus (SLAB_SECTION (app_data->filter_section)->contents);
123
 
 
124
 
                res = UNIQUE_RESPONSE_OK;
125
 
                break;
126
 
        default:
127
 
                res = UNIQUE_RESPONSE_PASSTHROUGH;
128
 
                break;
129
 
        }
130
 
 
131
 
        return res;
 
30
#include <string.h>
 
31
 
 
32
#include "cc-shell-log.h"
 
33
 
 
34
G_GNUC_NORETURN static gboolean
 
35
option_version_cb (const gchar *option_name,
 
36
                   const gchar *value,
 
37
                   gpointer     data,
 
38
                   GError     **error)
 
39
{
 
40
  g_print ("%s %s\n", PACKAGE, VERSION);
 
41
  exit (0);
 
42
}
 
43
 
 
44
static char **start_panels = NULL;
 
45
static gboolean show_overview = FALSE;
 
46
static gboolean verbose = FALSE;
 
47
static gboolean show_help = FALSE;
 
48
 
 
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 */
 
56
};
 
57
 
 
58
static int
 
59
application_command_line_cb (GApplication  *application,
 
60
                             GApplicationCommandLine  *command_line,
 
61
                             GnomeControlCenter      *shell)
 
62
{
 
63
  int argc;
 
64
  char **argv;
 
65
  int retval = 0;
 
66
  GOptionContext *context;
 
67
  GError *error = NULL;
 
68
 
 
69
  verbose = FALSE;
 
70
  show_overview = FALSE;
 
71
  show_help = FALSE;
 
72
  start_panels = NULL;
 
73
 
 
74
  argv = g_application_command_line_get_arguments (command_line, &argc);
 
75
 
 
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);
 
81
 
 
82
  if (g_option_context_parse (context, &argc, &argv, &error) == FALSE)
 
83
    {
 
84
      g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
 
85
               error->message, argv[0]);
 
86
      g_error_free (error);
 
87
      g_option_context_free (context);
 
88
      return 1;
 
89
    }
 
90
 
 
91
  if (show_help)
 
92
    {
 
93
      gchar *help;
 
94
 
 
95
      help = g_option_context_get_help (context, FALSE, NULL);
 
96
      g_print ("%s", help);
 
97
      g_free (help);
 
98
      g_option_context_free (context);
 
99
      return 0;
 
100
    }
 
101
 
 
102
  g_option_context_free (context);
 
103
 
 
104
  cc_shell_log_set_debug (verbose);
 
105
 
 
106
  gnome_control_center_show (shell, GTK_APPLICATION (application));
 
107
 
 
108
  if (show_overview)
 
109
    {
 
110
      gnome_control_center_set_overview_page (shell);
 
111
    }
 
112
  else if (start_panels != NULL && start_panels[0] != NULL)
 
113
    {
 
114
      const char *start_id;
 
115
      GError *err = NULL;
 
116
 
 
117
      start_id = start_panels[0];
 
118
 
 
119
      if (!cc_shell_set_active_panel_from_id (CC_SHELL (shell), start_id, &err))
 
120
        {
 
121
          g_warning ("Could not load setting panel \"%s\": %s", start_id,
 
122
                     (err) ? err->message : "Unknown error");
 
123
          retval = 1;
 
124
          if (err)
 
125
            {
 
126
              g_error_free (err);
 
127
              err = NULL;
 
128
            }
 
129
        }
 
130
    }
 
131
 
 
132
  gnome_control_center_present (shell);
 
133
  gdk_notify_startup_complete ();
 
134
 
 
135
  g_strfreev (argv);
 
136
  if (start_panels != NULL)
 
137
    {
 
138
      g_strfreev (start_panels);
 
139
      start_panels = NULL;
 
140
    }
 
141
  show_overview = FALSE;
 
142
 
 
143
  return retval;
 
144
}
 
145
 
 
146
static void
 
147
application_startup_cb (GApplication       *application,
 
148
                        GnomeControlCenter *shell)
 
149
{
 
150
  /* nothing to do here, we don't want to show a window before
 
151
   * we've looked at the commandline
 
152
   */
132
153
}
133
154
 
134
155
int
135
 
main (int argc, char *argv[])
 
156
main (int argc, char **argv)
136
157
{
137
 
        gboolean hidden = FALSE;
138
 
        UniqueApp *unique_app;
139
 
        AppShellData *app_data;
140
 
        GSList *actions;
141
 
        GError *error;
142
 
        GOptionEntry options[] = {
143
 
          { "hide", 0, 0, G_OPTION_ARG_NONE, &hidden, N_("Hide on start (useful to preload the shell)"), NULL },
144
 
          { NULL }
145
 
        };
146
 
 
147
 
#ifdef ENABLE_NLS
148
 
        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
149
 
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
150
 
        textdomain (GETTEXT_PACKAGE);
151
 
#endif
152
 
 
153
 
        error = NULL;
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);
158
 
                return 1;
159
 
        }
160
 
 
161
 
        unique_app = unique_app_new ("org.gnome.gnome-control-center.shell", NULL);
162
 
        if (unique_app_is_running (unique_app)) {
163
 
                int retval = 0;
164
 
 
165
 
                if (!hidden) {
166
 
                        UniqueResponse response;
167
 
                        response = unique_app_send_message (unique_app,
168
 
                                                            UNIQUE_ACTIVATE,
169
 
                                                            NULL);
170
 
                        retval = (response != UNIQUE_RESPONSE_OK);
171
 
                }
172
 
 
173
 
                g_object_unref (unique_app);
174
 
                return retval;
175
 
        }
176
 
 
177
 
        app_data = appshelldata_new ("gnomecc.menu", NULL, CONTROL_CENTER_PREFIX,
178
 
                                     GTK_ICON_SIZE_DND, FALSE, TRUE);
179
 
        generate_categories (app_data);
180
 
 
181
 
        actions = get_actions_list ();
182
 
        layout_shell (app_data, _("Filter"), _("Groups"), _("Common Tasks"), actions,
183
 
                handle_static_action_clicked);
184
 
 
185
 
        create_main_window (app_data, "MyControlCenter", _("Control Center"),
186
 
                "gnome-control-center", 975, 600, hidden);
187
 
 
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);
191
 
 
192
 
        gtk_main ();
193
 
 
194
 
        g_object_unref (unique_app);
195
 
 
196
 
        return 0;
197
 
};
 
158
  GnomeControlCenter *shell;
 
159
  GtkApplication *application;
 
160
  int status;
 
161
 
 
162
  bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
 
163
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
164
  textdomain (GETTEXT_PACKAGE);
 
165
 
 
166
 
 
167
  g_thread_init (NULL);
 
168
  gtk_init (&argc, &argv);
 
169
  cc_shell_log_init ();
 
170
 
 
171
  shell = gnome_control_center_new ();
 
172
 
 
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);
 
179
 
 
180
  status = g_application_run (G_APPLICATION (application), argc, argv);
 
181
 
 
182
  g_object_unref (application);
 
183
 
 
184
  return status;
 
185
}