~ubuntu-branches/debian/experimental/xfce4-panel/experimental

« back to all changes in this revision

Viewing changes to panel/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez, Lionel Le Folgoc, Yves-Alexis Perez
  • Date: 2011-02-06 18:10:07 UTC
  • mfrom: (1.3.13 upstream) (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110206181007-vpw5z3xnm3hdvybx
Tags: 4.8.1-1
[ Lionel Le Folgoc ]
* New upstream bugfix release.
* debian/control:
  - refreshed (b-)deps for this new major release
  - add myself to Uploaders
  - bump Standards-Version to 3.9.1.
* debian/NEWS: dropped, unneeded.
* debian/xfce4-panel.shlibs: refreshed, bump to (>= 4.7.2).
* debian/xfce4-panel.lintian-overrides: refreshed, new lib name.
* debian/xfce4-panel.preinst: added, handles removal of old conffiles.
* debian/xfce4-panel.postinst: explicitly set -e.
* debian/*.install: refreshed.
* debian/rules:
  - call dpkg-buildflags
  - dropped rc files mangling as they don't exist anymore
  - updated removal of *.{l,}a files.
  - drop overrides for dh_auto_{configure,clean}, obsolete.
* debian/xfce4-panel.{preinst,postinst,prerm}: use dpkg-maintscript-helper
  to remove pre-xfconf config files.
* Bugs fixed by 4.7.x/4.8.x series:
  - rgba support                                                  lp: #586012
  - disappearing menus                                             lp: #53897
  - xrandr support                               lp: #176174, Closes: #432914
  - Fails to reap children, creating zombies                      lp: #420187
  - DND of desktop-files on the panel to create new launchers Closes: #480380
* Bumped shlibs to >= 4.7.7, abi break for external plugins.

[ Yves-Alexis Perez ]
* New upstream development release
* debian/xfce4-panel.install:
  - install wrapper and migrate tools in xfce4-panel package
  - update plugins paths
* debian/rules:
  - update path when removing .a/.la files for plugins.
  - add hardening flags to {C,LD}FLAGS
* debian/control:
  - add build-dep on hardening-includes
  - update build-dep on garcon to 0.1.4.
* debian/copyright updated for new release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: main.c 29188 2009-01-12 17:08:56Z nick $
2
 
 *
3
 
 * Copyright (c) 2005 Jasper Huijsmans <jasper@xfce.org>
 
1
/*
 
2
 * Copyright (C) 2008-2010 Nick Schermer <nick@xfce.org>
4
3
 *
5
4
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published
7
 
 * by the Free Software Foundation; either version 2 of the License, or
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
8
7
 * (at your option) any later version.
9
8
 *
10
9
 * This program is distributed in the hope that it will be useful,
11
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU Library General Public License for more details.
 
12
 * GNU General Public License for more details.
14
13
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
14
 * You should have received a copy of the GNU General Public License along
 
15
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
17
 */
19
18
 
20
19
#ifdef HAVE_CONFIG_H
21
20
#include <config.h>
22
21
#endif
23
22
 
 
23
#ifdef HAVE_STDIO_H
 
24
#include <stdio.h>
 
25
#endif
24
26
#ifdef HAVE_STDLIB_H
25
27
#include <stdlib.h>
26
28
#endif
30
32
#ifdef HAVE_STRING_H
31
33
#include <string.h>
32
34
#endif
33
 
#ifdef HAVE_LOCALE_H
34
 
#include <locale.h>
 
35
#ifdef HAVE_SIGNAL_H
 
36
#include <signal.h>
35
37
#endif
36
38
 
37
 
#include <gtk/gtk.h>
 
39
#include <glib.h>
 
40
#include <dbus/dbus-glib.h>
38
41
#include <libxfce4util/libxfce4util.h>
39
 
 
40
 
#include "panel-app.h"
41
 
#include "panel-app-messages.h"
42
 
 
43
 
#ifndef _
44
 
#define _(x) x
45
 
#endif
46
 
 
47
 
/* globals */
48
 
static gboolean  opt_version   = FALSE;
49
 
static gboolean  opt_customize = FALSE;
50
 
static gboolean  opt_save      = FALSE;
51
 
static gboolean  opt_restart   = FALSE;
52
 
static gboolean  opt_quit      = FALSE;
53
 
static gboolean  opt_exit      = FALSE;
54
 
static gboolean  opt_add       = FALSE;
55
 
static gchar    *opt_client_id = NULL;
 
42
#include <libxfce4ui/libxfce4ui.h>
 
43
 
 
44
#include <common/panel-private.h>
 
45
#include <common/panel-debug.h>
 
46
#include <libxfce4panel/libxfce4panel.h>
 
47
#include <panel/panel-application.h>
 
48
#include <panel/panel-dbus-service.h>
 
49
#include <panel/panel-dbus-client.h>
 
50
#include <panel/panel-preferences-dialog.h>
 
51
 
 
52
 
 
53
 
 
54
static gint       opt_preferences = -1;
 
55
static gint       opt_add_items = -1;
 
56
static gboolean   opt_save = FALSE;
 
57
static gchar     *opt_add = NULL;
 
58
static gboolean   opt_restart = FALSE;
 
59
static gboolean   opt_quit = FALSE;
 
60
static gboolean   opt_version = FALSE;
 
61
static gchar     *opt_plugin_event = NULL;
 
62
static gchar    **opt_arguments = NULL;
 
63
static gboolean   sm_client_saved_state = FALSE;
 
64
 
 
65
 
 
66
 
 
67
static gboolean panel_callback_handler (const gchar  *name,
 
68
                                        const gchar  *value,
 
69
                                        gpointer      user_data,
 
70
                                        GError      **error);
 
71
 
 
72
 
56
73
 
57
74
/* command line options */
 
75
#define PANEL_CALLBACK_OPTION G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, panel_callback_handler
58
76
static GOptionEntry option_entries[] =
59
77
{
60
 
    { "version",   'V', 0, G_OPTION_ARG_NONE, &opt_version,   N_ ("Print version information and exit"), NULL },
61
 
    { "customize", 'c', 0, G_OPTION_ARG_NONE, &opt_customize, N_ ("Show 'Customize Panel' dialog"), NULL },
62
 
    { "save",      's', 0, G_OPTION_ARG_NONE, &opt_save,      N_ ("Save the panel configuration"), NULL },
63
 
    { "restart",   'r', 0, G_OPTION_ARG_NONE, &opt_restart,   N_ ("Restart the running instance of xfce4-panel"), NULL },
64
 
    { "quit",      'q', 0, G_OPTION_ARG_NONE, &opt_quit,      N_ ("Log out the active session"), NULL },
65
 
    { "exit",      'x', 0, G_OPTION_ARG_NONE, &opt_exit,      N_ ("Close all panels and end the program"), NULL },
66
 
    { "add",       'a', 0, G_OPTION_ARG_NONE, &opt_add,       N_ ("Show 'Add New Items' dialog"), NULL },
67
 
    { "sm-client-id", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_client_id, NULL, NULL },
68
 
    { NULL }
 
78
  { "preferences", 'p', PANEL_CALLBACK_OPTION, N_("Show the 'Panel Preferences' dialog"), N_("PANEL-NUMBER") },
 
79
  { "add-items", 'a', PANEL_CALLBACK_OPTION, N_("Show the 'Add New Items' dialog"), N_("PANEL-NUMBER") },
 
80
  { "save", 's', 0, G_OPTION_ARG_NONE, &opt_save, N_("Save the panel configuration"), NULL },
 
81
  { "add", '\0', 0, G_OPTION_ARG_STRING, &opt_add, N_("Add a new plugin to the panel"), N_("PLUGIN-NAME") },
 
82
  { "restart", 'r', 0, G_OPTION_ARG_NONE, &opt_restart, N_("Restart the running panel instance"), NULL },
 
83
  { "quit", 'q', 0, G_OPTION_ARG_NONE, &opt_quit, N_("Quit the running panel instance"), NULL },
 
84
  { "version", 'V', 0, G_OPTION_ARG_NONE, &opt_version, N_("Print version information and exit"), NULL },
 
85
  { "plugin-event", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_plugin_event, NULL, NULL },
 
86
  { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &opt_arguments, NULL, NULL },
 
87
  { NULL }
69
88
};
70
89
 
71
 
/* main program */
 
90
 
 
91
 
 
92
static gboolean
 
93
panel_callback_handler (const gchar  *name,
 
94
                        const gchar  *value,
 
95
                        gpointer      user_data,
 
96
                        GError      **error)
 
97
{
 
98
  panel_return_val_if_fail (name != NULL, FALSE);
 
99
 
 
100
  if (strcmp (name, "--preferences") == 0
 
101
      || strcmp (name, "-p") == 0)
 
102
    {
 
103
      opt_preferences = value != NULL ? MAX (0, atoi (value)) : 0;
 
104
    }
 
105
  else if (strcmp (name, "--add-items") == 0
 
106
           || strcmp (name, "-a") == 0)
 
107
    {
 
108
      opt_add_items = value != NULL ? MAX (0, atoi (value)) : 0;
 
109
    }
 
110
  else
 
111
    {
 
112
      panel_assert_not_reached ();
 
113
      return FALSE;
 
114
    }
 
115
 
 
116
  return TRUE;
 
117
}
 
118
 
 
119
 
 
120
 
 
121
static void
 
122
panel_signal_handler (gint signum)
 
123
{
 
124
  panel_debug (PANEL_DEBUG_MAIN,
 
125
               "received signal %s <%d>, %s panel",
 
126
               g_strsignal (signum), signum,
 
127
               signum == SIGUSR1 ? "restarting" : "quiting");
 
128
 
 
129
  panel_dbus_service_exit_panel (signum == SIGUSR1);
 
130
}
 
131
 
 
132
 
 
133
 
 
134
static void
 
135
panel_sm_client_quit (XfceSMClient *sm_client)
 
136
{
 
137
  panel_return_if_fail (XFCE_IS_SM_CLIENT (sm_client));
 
138
  panel_return_if_fail (!panel_dbus_service_get_restart ());
 
139
 
 
140
  panel_debug (PANEL_DEBUG_MAIN,
 
141
               "terminate panel for session manager");
 
142
 
 
143
  gtk_main_quit ();
 
144
}
 
145
 
 
146
 
 
147
 
 
148
static void
 
149
panel_sm_client_save_state (XfceSMClient     *sm_client,
 
150
                            PanelApplication *application)
 
151
{
 
152
  panel_return_if_fail (XFCE_IS_SM_CLIENT (sm_client));
 
153
  panel_return_if_fail (PANEL_IS_APPLICATION (application));
 
154
 
 
155
  panel_debug (PANEL_DEBUG_MAIN,
 
156
               "save configuration for session manager");
 
157
 
 
158
  panel_application_save (application, TRUE);
 
159
 
 
160
  sm_client_saved_state = TRUE;
 
161
}
 
162
 
 
163
 
 
164
 
 
165
static void
 
166
panel_debug_notify_proxy (void)
 
167
{
 
168
  gchar       *path;
 
169
  const gchar *proxy_cmd;
 
170
 
 
171
  if (G_UNLIKELY (panel_debug_has_domain (PANEL_DEBUG_GDB)))
 
172
    proxy_cmd = "gdb";
 
173
  else if (G_UNLIKELY (panel_debug_has_domain (PANEL_DEBUG_VALGRIND)))
 
174
    proxy_cmd = "valgrind";
 
175
  else
 
176
    return;
 
177
 
 
178
  path = g_find_program_in_path (proxy_cmd);
 
179
  if (G_LIKELY (path != NULL))
 
180
    {
 
181
      panel_debug (PANEL_DEBUG_MAIN,
 
182
                   "running external plugins with %s, logs stored in %s",
 
183
                   path, g_get_tmp_dir ());
 
184
      g_free (path);
 
185
 
 
186
      if (panel_debug_has_domain (PANEL_DEBUG_GDB))
 
187
        {
 
188
          /* performs sanity checks on the released memory slices */
 
189
          g_setenv ("G_SLICE", "debug-blocks", TRUE);
 
190
        }
 
191
      else if (panel_debug_has_domain (PANEL_DEBUG_VALGRIND))
 
192
        {
 
193
          /* use g_malloc() and g_free() instead of slices */
 
194
          g_setenv ("G_SLICE", "always-malloc", TRUE);
 
195
          g_setenv ("G_DEBUG", "gc-friendly", TRUE);
 
196
        }
 
197
    }
 
198
  else
 
199
    {
 
200
      panel_debug (PANEL_DEBUG_MAIN, "%s not found in PATH", proxy_cmd);
 
201
    }
 
202
}
 
203
 
 
204
 
 
205
 
72
206
gint
73
207
main (gint argc, gchar **argv)
74
208
{
75
 
    gint    msg = -1;
76
 
    GError *error = NULL;
77
 
 
78
 
    /* translation domain */
79
 
    xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
80
 
 
81
 
    /* application name */
82
 
    g_set_application_name (PACKAGE_NAME);
83
 
 
84
 
    MARK ("start gtk_init_with_args ()");
85
 
 
86
 
    /* initialize gtk */
87
 
    if (!gtk_init_with_args (&argc, &argv, (gchar *) "", option_entries, (gchar *) GETTEXT_PACKAGE, &error))
88
 
    {
89
 
        /* TRANSLATORS: Errors when gtk_init failed, probably the command
90
 
           executed without xserver running */
91
 
        g_print ("%s: %s\n", PACKAGE_NAME, error ? error->message : _("Failed to open display"));
92
 
 
93
 
        if (error != NULL)
94
 
            g_error_free (error);
95
 
 
96
 
        return EXIT_FAILURE;
97
 
    }
98
 
 
99
 
    /* handle the options */
100
 
    if (G_UNLIKELY (opt_version))
101
 
    {
102
 
        g_print ("%s %s (Xfce %s)\n\n", PACKAGE_NAME, PACKAGE_VERSION, xfce_version_string ());
103
 
        g_print ("%s\n", "Copyright (c) 2004-2009");
104
 
        g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved."));
105
 
        
106
 
        /* TRANSLATORS: Bug report website, %s points to bugzilla.xfce.org */
107
 
        g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT);
108
 
        g_print ("\n");
109
 
 
110
 
        return EXIT_SUCCESS;
111
 
    }
112
 
    else if (G_UNLIKELY (opt_customize))
113
 
        msg = PANEL_APP_CUSTOMIZE;
114
 
    else if (G_UNLIKELY (opt_save))
115
 
        msg = PANEL_APP_SAVE;
116
 
    else if (G_UNLIKELY (opt_restart))
117
 
        msg = PANEL_APP_RESTART;
118
 
    else if (G_UNLIKELY (opt_quit))
119
 
        msg = PANEL_APP_QUIT;
120
 
    else if (G_UNLIKELY (opt_exit))
121
 
        msg = PANEL_APP_EXIT;
122
 
    else if (G_UNLIKELY (opt_add))
123
 
        msg = PANEL_APP_ADD;
124
 
 
125
 
    /* handle the message, if there is any */
126
 
    if (G_UNLIKELY (msg >= 0))
127
 
    {
128
 
        if (!panel_app_send (msg))
129
 
        {
130
 
            if (msg != PANEL_APP_RESTART )
131
 
            {
132
 
                return EXIT_FAILURE;
133
 
            }
134
 
            /* else: continue and start new panel */
135
 
        }
136
 
        else
137
 
        {
138
 
            return EXIT_SUCCESS;
139
 
        }
140
 
    }
141
 
 
142
 
    MARK ("start panel_init()");
143
 
    msg = panel_app_init ();
144
 
 
145
 
    if (G_UNLIKELY (msg == INIT_FAILURE))
146
 
    {
147
 
        return EXIT_FAILURE;
148
 
    }
149
 
    else if (G_UNLIKELY (msg == INIT_RUNNING))
150
 
    {
151
 
        g_message (_("Xfce4-panel already running"));
152
 
 
153
 
        return EXIT_SUCCESS;
154
 
    }
155
 
 
156
 
    MARK ("start panel_app_run()");
157
 
    msg = panel_app_run (opt_client_id);
158
 
    MARK ("end panel_app_run()");
159
 
 
160
 
    if (G_UNLIKELY (msg == RUN_RESTART))
161
 
    {
162
 
        g_message (_("Restarting xfce4-panel..."));
163
 
        
164
 
        /* restart */
165
 
        execvp (argv[0], argv);
166
 
    }
167
 
 
168
 
    return G_UNLIKELY (msg == RUN_FAILURE) ? EXIT_FAILURE : EXIT_SUCCESS;
 
209
  GOptionContext   *context;
 
210
  PanelApplication *application;
 
211
  GError           *error = NULL;
 
212
  PanelDBusService *dbus_service;
 
213
  gboolean          succeed = FALSE;
 
214
  guint             i;
 
215
  const gint        signums[] = { SIGINT, SIGQUIT, SIGTERM, SIGABRT, SIGUSR1 };
 
216
  const gchar      *error_msg;
 
217
  XfceSMClient     *sm_client;
 
218
 
 
219
  panel_debug (PANEL_DEBUG_MAIN,
 
220
               "version %s on gtk+ %d.%d.%d (%d.%d.%d), glib %d.%d.%d (%d.%d.%d)",
 
221
               LIBXFCE4PANEL_VERSION,
 
222
               gtk_major_version, gtk_minor_version, gtk_micro_version,
 
223
               GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION,
 
224
               glib_major_version, glib_minor_version, glib_micro_version,
 
225
               GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
 
226
 
 
227
  /* inform the user about usage of gdb/valgrind */
 
228
  panel_debug_notify_proxy ();
 
229
 
 
230
  /* set translation domain */
 
231
  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 
232
 
 
233
#ifdef G_ENABLE_DEBUG
 
234
  /* do NOT remove this line for now, If something doesn't work,
 
235
   * fix your code instead! */
 
236
  g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
 
237
#endif
 
238
 
 
239
  /* parse context options */
 
240
  context = g_option_context_new (_("[ARGUMENTS...]"));
 
241
  g_option_context_add_main_entries (context, option_entries, GETTEXT_PACKAGE);
 
242
  g_option_context_add_group (context, gtk_get_option_group (TRUE));
 
243
  g_option_context_add_group (context, xfce_sm_client_get_option_group (argc, argv));
 
244
  if (!g_option_context_parse (context, &argc, &argv, &error))
 
245
    {
 
246
      g_print ("%s: %s.\n", PACKAGE_NAME, error->message);
 
247
      g_print (_("Type \"%s --help\" for usage."), G_LOG_DOMAIN);
 
248
      g_print ("\n");
 
249
      g_error_free (error);
 
250
 
 
251
      return EXIT_FAILURE;
 
252
    }
 
253
  g_option_context_free (context);
 
254
 
 
255
  gtk_init (&argc, &argv);
 
256
 
 
257
  if (opt_version)
 
258
    {
 
259
      /* print version information */
 
260
      if (opt_arguments != NULL && *opt_arguments != NULL)
 
261
        g_print ("%s (%s)", *opt_arguments, PACKAGE_NAME);
 
262
      else
 
263
        g_print ("%s", PACKAGE_NAME);
 
264
      g_print (" %s (Xfce %s)\n\n", PACKAGE_VERSION, xfce_version_string ());
 
265
      g_print ("%s\n", "Copyright (c) 2004-2011");
 
266
      g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved."));
 
267
      g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT);
 
268
      g_print ("\n");
 
269
 
 
270
      return EXIT_SUCCESS;
 
271
    }
 
272
  else if (opt_preferences >= 0)
 
273
    {
 
274
      /* send a signal to the running instance to show the preferences dialog */
 
275
      succeed = panel_dbus_client_display_preferences_dialog (opt_preferences, &error);
 
276
      goto dbus_return;
 
277
    }
 
278
  else if (opt_add_items >= 0)
 
279
    {
 
280
      /* send a signal to the running instance to show the add items dialog */
 
281
      succeed = panel_dbus_client_display_items_dialog (opt_add_items, &error);
 
282
      goto dbus_return;
 
283
    }
 
284
  else if (opt_save)
 
285
    {
 
286
      /* send a save signal to the running instance */
 
287
      succeed = panel_dbus_client_save (&error);
 
288
      goto dbus_return;
 
289
    }
 
290
  else if (opt_add != NULL)
 
291
    {
 
292
      /* send a add-new-item signal to the running instance */
 
293
      succeed = panel_dbus_client_add_new_item (opt_add, opt_arguments, &error);
 
294
      goto dbus_return;
 
295
    }
 
296
  else if (opt_restart || opt_quit)
 
297
    {
 
298
      /* send a terminate signal to the running instance */
 
299
      succeed = panel_dbus_client_terminate (opt_restart, &error);
 
300
      goto dbus_return;
 
301
    }
 
302
  else if (opt_plugin_event != NULL)
 
303
    {
 
304
      /* send the plugin event to the running instance */
 
305
      succeed = panel_dbus_client_plugin_event (opt_plugin_event, &error);
 
306
      goto dbus_return;
 
307
    }
 
308
 
 
309
  launch_panel:
 
310
 
 
311
  /* start dbus service */
 
312
  dbus_service = panel_dbus_service_get ();
 
313
  if (!panel_dbus_service_is_owner (dbus_service))
 
314
    {
 
315
      /* quit without error if an instance is running */
 
316
      succeed = TRUE;
 
317
 
 
318
      g_print ("%s: %s\n\n", G_LOG_DOMAIN, _("There is already a running instance"));
 
319
      goto dbus_return;
 
320
    }
 
321
 
 
322
  /* start session management */
 
323
  sm_client = xfce_sm_client_get ();
 
324
  xfce_sm_client_set_restart_style (sm_client, XFCE_SM_CLIENT_RESTART_IMMEDIATELY);
 
325
  xfce_sm_client_set_priority (sm_client, XFCE_SM_CLIENT_PRIORITY_CORE);
 
326
  g_signal_connect (G_OBJECT (sm_client), "quit",
 
327
      G_CALLBACK (panel_sm_client_quit), NULL);
 
328
  if (!xfce_sm_client_connect (sm_client, &error))
 
329
    {
 
330
      g_printerr ("%s: Failed to connect to session manager: %s\n",
 
331
                  G_LOG_DOMAIN, error->message);
 
332
      g_clear_error (&error);
 
333
    }
 
334
 
 
335
  /* setup signal handlers to properly quit the main loop */
 
336
  for (i = 0; i < G_N_ELEMENTS (signums); i++)
 
337
    signal (signums[i], panel_signal_handler);
 
338
 
 
339
  application = panel_application_get ();
 
340
 
 
341
  /* save the state before the quit signal if we can, this is a bit safer */
 
342
  g_signal_connect (G_OBJECT (sm_client), "save-state",
 
343
      G_CALLBACK (panel_sm_client_save_state), application);
 
344
 
 
345
  /* open dialog if we started from launch_panel */
 
346
  if (opt_preferences >= 0)
 
347
    panel_preferences_dialog_show (panel_application_get_nth_window (application, opt_preferences));
 
348
 
 
349
  gtk_main ();
 
350
 
 
351
  /* make sure there are no incomming events when we close */
 
352
  g_object_unref (G_OBJECT (dbus_service));
 
353
 
 
354
  /* destroy all the opened dialogs */
 
355
  panel_application_destroy_dialogs (application);
 
356
 
 
357
  /* only save if we do not quit by the sm client */
 
358
  if (!sm_client_saved_state)
 
359
    panel_application_save (application, TRUE);
 
360
 
 
361
  g_object_unref (G_OBJECT (application));
 
362
  g_object_unref (G_OBJECT (sm_client));
 
363
 
 
364
  if (panel_dbus_service_get_restart ())
 
365
    {
 
366
      /* spawn ourselfs again */
 
367
      g_print ("%s: %s\n\n", G_LOG_DOMAIN, _("Restarting..."));
 
368
      g_spawn_command_line_async (argv[0], NULL);
 
369
    }
 
370
 
 
371
  return EXIT_SUCCESS;
 
372
 
 
373
dbus_return:
 
374
 
 
375
  /* stop any running startup notification */
 
376
  gdk_notify_startup_complete ();
 
377
 
 
378
  if (G_UNLIKELY (error != NULL))
 
379
    {
 
380
      /* get suitable error message */
 
381
      if (opt_preferences >= 0)
 
382
        error_msg = _("Failed to show the preferences dialog");
 
383
      else if (opt_add_items >= 0)
 
384
        error_msg = _("Failed to show the add new items dialog");
 
385
      else if (opt_save)
 
386
        error_msg = _("Failed to save the panel configuration");
 
387
      else if (opt_add)
 
388
        error_msg = _("Failed to add a plugin to the panel");
 
389
      else if (opt_restart)
 
390
        error_msg = _("Failed to restart the panel");
 
391
      else if (opt_quit)
 
392
        error_msg = _("Failed to quit the panel");
 
393
      else
 
394
        error_msg = _("Failed to send D-Bus message");
 
395
 
 
396
      /* show understandable message for this common error */
 
397
      if (error->code == DBUS_GERROR_NAME_HAS_NO_OWNER)
 
398
        {
 
399
          /* normally start the panel */
 
400
          if (opt_preferences >= 0)
 
401
            {
 
402
              g_clear_error (&error);
 
403
 
 
404
              if (xfce_dialog_confirm (NULL, GTK_STOCK_EXECUTE, NULL,
 
405
                                       _("Do you want to start the panel? If you do, make sure "
 
406
                                         "you save the session on logout, so the panel is "
 
407
                                         "automatically started the next time you login."),
 
408
                                       _("No running instance of %s was found"), G_LOG_DOMAIN))
 
409
                {
 
410
                  panel_debug (PANEL_DEBUG_MAIN, "user confirmed to start the panel");
 
411
                  goto launch_panel;
 
412
                }
 
413
              else
 
414
                {
 
415
                  return EXIT_FAILURE;
 
416
                }
 
417
            }
 
418
          else
 
419
            {
 
420
              /* I18N: %s is replaced with xfce4-panel */
 
421
              g_clear_error (&error);
 
422
              g_set_error (&error, 0, 0, _("No running instance of %s was found"), G_LOG_DOMAIN);
 
423
            }
 
424
        }
 
425
 
 
426
      /* show error dialog */
 
427
      xfce_dialog_show_error (NULL, error, "%s", error_msg);
 
428
      g_error_free (error);
 
429
    }
 
430
 
 
431
  return succeed ? EXIT_SUCCESS : EXIT_FAILURE;
169
432
}
170