/**
 * Thread safe method that sets status to XFBURN_PROGRESS_DIALOG_STATUS_FAILED and shows
 * an error message box.
 **/
void
xfburn_progress_dialog_burning_failed (XfburnProgressDialog * dialog, const gchar * msg_error)
{
  xfburn_progress_dialog_set_status_with_text (dialog, XFBURN_PROGRESS_DIALOG_STATUS_FAILED, _("Failure"));

  gdk_threads_enter ();
  xfce_dialog_show_error (NULL, NULL, "%s", msg_error);
  gdk_threads_leave ();
}
static void exitbutton_plugin_button_spawn_command(const gchar *command)
{
  GError *error = NULL;

  if (g_getenv ("SESSION_MANAGER") == NULL)
    {
      /* TRANSLATORS: no session manager is launched, so avoid any
       * problems and ask the user to quit the panel so users without
       * xfce4-session can still close the xserver */
      if (xfce_dialog_confirm (NULL, GTK_STOCK_QUIT, NULL,
          _("You have started X without session manager. Clicking Quit will close the X server."),
          _("Are you sure you want to quit the panel?")))
         command = "xfce4-panel --quit";
       else
         return;
    }

  if (!g_spawn_command_line_async (command, &error))
    {
      xfce_dialog_show_error (NULL, error, _("Failed to execute command \"%s\""), command);
      g_error_free (error);
    }
}
static void
xfce_dialog_show_help_uri (GdkScreen *screen,
                           GtkWindow *parent,
                           GString   *uri)
{
  GError   *error = NULL;
  gchar    *path;
  gchar    *cmd;
  gboolean  result;

  g_return_if_fail (GDK_IS_SCREEN (screen));
  g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));

  path = g_find_program_in_path ("exo-open");
  if (G_LIKELY (path != NULL))
    {
      cmd = g_strdup_printf ("%s --launch WebBrowser '%s'", path, uri->str);

      result = xfce_spawn_command_line_on_screen (screen, cmd, FALSE, TRUE, &error);

      g_free (path);
      g_free (cmd);
    }
  else
    {
      /* not very likely to happen, but it is possible exo is not installed */
      result = gtk_show_uri (screen, uri->str, gtk_get_current_event_time (), &error);
    }

  if (!result)
    {
      xfce_dialog_show_error (parent, error,
          _("Failed to open web browser for online documentation"));
      g_error_free (error);
    }
}
int main (int argc, char **argv)
{
    GDBusConnection *bus;
    GError *error = NULL;
    XfpmPowerManager *proxy;
    GOptionContext *octx;
     
    gboolean run        = FALSE;
    gboolean quit       = FALSE;
    gboolean config     = FALSE;
    gboolean version    = FALSE;
    gboolean reload     = FALSE;
    gboolean no_daemon  = FALSE;
    gboolean debug      = FALSE;
    gboolean dump       = FALSE;
    gchar   *client_id  = NULL;
    
    GOptionEntry option_entries[] = 
    {
	{ "run",'r', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &run, NULL, NULL },
	{ "no-daemon",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &no_daemon, N_("Do not daemonize"), NULL },
	{ "debug",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &debug, N_("Enable debugging"), NULL },
	{ "dump",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &dump, N_("Dump all information"), NULL },
	{ "restart", '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &reload, N_("Restart the running instance of Xfce power manager"), NULL},
	{ "customize", 'c', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &config, N_("Show the configuration dialog"), NULL },
	{ "quit", 'q', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &quit, N_("Quit any running xfce power manager"), NULL },
	{ "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &version, N_("Version information"), NULL },
	{ "sm-client-id", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &client_id, NULL, NULL },
	{ NULL, },
    };

    /* Parse the options */
    octx = g_option_context_new("");
    g_option_context_set_ignore_unknown_options(octx, TRUE);
    g_option_context_add_main_entries(octx, option_entries, NULL);
    g_option_context_add_group(octx, xfce_sm_client_get_option_group(argc, argv));
    /* We can't add the following command because it will invoke gtk_init
       before we have a chance to fork.
       g_option_context_add_group(octx, gtk_get_option_group(TRUE));
     */

    if(!g_option_context_parse(octx, &argc, &argv, &error)) {
        g_printerr(_("Failed to parse arguments: %s\n"), error->message);
        g_option_context_free(octx);
        g_error_free(error);

        return EXIT_FAILURE;
    }

    g_option_context_free(octx);

    if ( version )    
        show_version ();

    /* Fork if needed */
    if ( dump == FALSE && debug == FALSE && no_daemon == FALSE && daemon(0,0) )
    {
        g_critical ("Could not daemonize");
    }

    /* Initialize */
    xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");

    g_set_application_name (PACKAGE_NAME);

    if (!gtk_init_check (&argc, &argv))
    {
        if (G_LIKELY (error))
        {
            g_printerr ("%s: %s.\n", G_LOG_DOMAIN, error->message);
            g_printerr (_("Type '%s --help' for usage."), G_LOG_DOMAIN);
            g_printerr ("\n");
            g_error_free (error);
        }
        else
        {
            g_error ("Unable to open display.");
        }

        return EXIT_FAILURE;
    }
    
    xfpm_debug_init (debug);
    
    bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
            
    if ( error )
    {
	xfce_dialog_show_error (NULL, 
				error, 
				"%s",
				_("Unable to get connection to the message bus session"));
	g_error ("%s: \n", error->message);
    }
    
    if ( quit )
    {
	if (!xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager") )
        {
            g_print (_("Xfce power manager is not running"));
	    g_print ("\n");
            return EXIT_SUCCESS;
        }
	else
	{
	    proxy = xfpm_power_manager_proxy_new_sync (bus,
						       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
						       G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
						       "org.xfce.PowerManager",
						       "/org/xfce/PowerManager",
						       NULL,
						       NULL);
	    if ( !proxy ) 
	    {
		g_critical ("Failed to get proxy");
		g_object_unref(bus);
            	return EXIT_FAILURE;
	    }
	    xfpm_power_manager_call_quit_sync (proxy, NULL, &error);
	    g_object_unref (proxy);
	    
	    if ( error)
	    {
		g_critical ("Failed to send quit message %s:\n", error->message);
		g_error_free (error);
	    }
	}
	return EXIT_SUCCESS;
    }
    
    if ( config )
    {
	g_spawn_command_line_async ("xfce4-power-manager-settings", &error);
	
	if ( error )
	{
	    g_critical ("Failed to execute xfce4-power-manager-settings: %s", error->message);
	    g_error_free (error);
	    return EXIT_FAILURE;
	}
	return EXIT_SUCCESS;
    }
    
    if ( reload )
    {
	if (!xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager") &&
	    !xfpm_dbus_name_has_owner (bus, "org.freedesktop.PowerManagement"))
	{
	    g_print ("Xfce power manager is not running\n");
	    xfpm_start (bus, client_id, dump);
	}
	
	proxy = xfpm_power_manager_proxy_new_sync (bus,
						   G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
						   G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
						   "org.xfce.PowerManager",
						   "/org/xfce/PowerManager",
						   NULL,
						   NULL);
	if ( !proxy ) 
	{
	    g_critical ("Failed to get proxy");
	    g_object_unref (bus);
	    return EXIT_FAILURE;
	}
	    
	if ( !xfpm_power_manager_call_restart_sync (proxy, NULL, NULL) )
	{
	    g_critical ("Unable to send reload message");
	    g_object_unref (proxy);
	    g_object_unref (bus);
	    return EXIT_SUCCESS;
	}
	return EXIT_SUCCESS;
    }
    
    if (dump)
    {
	if (xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager"))
	{
	    xfpm_dump_remote (bus);
	    return EXIT_SUCCESS;
	}
    }
    
    if (xfpm_dbus_name_has_owner (bus, "org.freedesktop.PowerManagement") )
    {
	g_print ("%s: %s\n", 
		 _("Xfce Power Manager"),
		 _("Another power manager is already running"));
		  
    }
    else if (xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager"))
    {
	g_print (_("Xfce power manager is already running"));
	g_print ("\n");
    	return EXIT_SUCCESS;
    }
    else
    {	
	xfpm_start (bus, client_id, dump);
    }
    
    return EXIT_SUCCESS;
}
int main (int argc, char **argv)
{
    DBusGConnection *bus;
    GError *error = NULL;
    DBusGProxy *proxy;
     
    gboolean run        = FALSE;
    gboolean quit       = FALSE;
    gboolean config     = FALSE;
    gboolean version    = FALSE;
    gboolean reload     = FALSE;
    gboolean no_daemon  = FALSE;
    gboolean debug      = FALSE;
    gboolean dump       = FALSE;
    gchar   *client_id  = NULL;
    
    GOptionEntry option_entries[] = 
    {
	{ "run",'r', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &run, NULL, NULL },
	{ "no-daemon",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &no_daemon, N_("Do not daemonize"), NULL },
	{ "debug",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &debug, N_("Enable debugging"), NULL },
	{ "dump",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &dump, N_("Dump all information"), NULL },
	{ "restart", '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &reload, N_("Restart the running instance of Xfce power manager"), NULL},
	{ "customize", 'c', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &config, N_("Show the configuration dialog"), NULL },
	{ "quit", 'q', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &quit, N_("Quit any running xfce power manager"), NULL },
	{ "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &version, N_("Version information"), NULL },
	{ "sm-client-id", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &client_id, NULL, NULL },
	{ NULL, },
    };

#if !GLIB_CHECK_VERSION (2, 32, 0)
    if ( !g_thread_supported () )
	g_thread_init (NULL);
#endif

    dbus_g_thread_init ();

    xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
    
    g_set_application_name (PACKAGE_NAME);
    
    if (!gtk_init_with_args (&argc, &argv, (gchar *)"", option_entries, (gchar *)PACKAGE, &error)) 
    {
        if (G_LIKELY (error)) 
        {
            g_printerr ("%s: %s.\n", G_LOG_DOMAIN, error->message);
            g_printerr (_("Type '%s --help' for usage."), G_LOG_DOMAIN);
            g_printerr ("\n");
            g_error_free (error);
        }
        else
        {
            g_error ("Unable to open display.");
	}

        return EXIT_FAILURE;
    }
    
    if ( version )    
    {
	show_version ();
    }
    
    xfpm_debug_init (debug);

    if ( dump == FALSE && debug == FALSE && no_daemon == FALSE && daemon(0,0) )
    {
	g_critical ("Could not daemonize");
    }
    
    bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
            
    if ( error )
    {
	xfce_dialog_show_error (NULL, 
				error, 
				"%s",
				_("Unable to get connection to the message bus session"));
	g_error ("%s: \n", error->message);
    }
    
    if ( quit )
    {
	if (!xfpm_dbus_name_has_owner (dbus_g_connection_get_connection(bus), 
				       "org.xfce.PowerManager") )
        {
            g_print (_("Xfce power manager is not running"));
	    g_print ("\n");
            return EXIT_SUCCESS;
        }
	else
	{
	    proxy = dbus_g_proxy_new_for_name (bus, 
			                       "org.xfce.PowerManager",
					       "/org/xfce/PowerManager",
					       "org.xfce.Power.Manager");
	    if ( !proxy ) 
	    {
		g_critical ("Failed to get proxy");
		dbus_g_connection_unref(bus);
            	return EXIT_FAILURE;
	    }
	    xfpm_manager_dbus_client_quit (proxy , &error);
	    g_object_unref (proxy);
	    
	    if ( error)
	    {
		g_critical ("Failed to send quit message %s:\n", error->message);
		g_error_free (error);
	    }
	}
	return EXIT_SUCCESS;
    }
    
    if ( config )
    {
	g_spawn_command_line_async ("xfce4-power-manager-settings", &error);
	
	if ( error )
	{
	    g_critical ("Failed to execute xfce4-power-manager-settings: %s", error->message);
	    g_error_free (error);
	    return EXIT_FAILURE;
	}
	return EXIT_SUCCESS;
    }
    
    if ( reload )
    {
	if (!xfpm_dbus_name_has_owner (dbus_g_connection_get_connection (bus), "org.xfce.PowerManager") &&
	    !xfpm_dbus_name_has_owner (dbus_g_connection_get_connection (bus), "org.freedesktop.PowerManagement"))
	{
	    g_print ("Xfce power manager is not running\n");
	    xfpm_start (bus, client_id, dump);
	}
	
	proxy = dbus_g_proxy_new_for_name (bus, 
			                   "org.xfce.PowerManager",
					   "/org/xfce/PowerManager",
					   "org.xfce.Power.Manager");
	if ( !proxy ) 
	{
	    g_critical ("Failed to get proxy");
	    dbus_g_connection_unref (bus);
	    return EXIT_FAILURE;
	}
	    
	if ( !xfpm_manager_dbus_client_restart (proxy, NULL) )
	{
	    g_critical ("Unable to send reload message");
	    g_object_unref (proxy);
	    dbus_g_connection_unref (bus);
	    return EXIT_SUCCESS;
	}
	return EXIT_SUCCESS;
    }
    
    if (dump)
    {
	if (xfpm_dbus_name_has_owner (dbus_g_connection_get_connection (bus), 
				      "org.xfce.PowerManager"))
	{
	    xfpm_dump_remote (bus);
	    return EXIT_SUCCESS;
	}
    }
    
    if (xfpm_dbus_name_has_owner (dbus_g_connection_get_connection (bus), "org.freedesktop.PowerManagement") )
    {
	g_print ("%s: %s\n", 
		 _("Xfce Power Manager"),
		 _("Another power manager is already running"));
		  
    }
    else if (xfpm_dbus_name_has_owner (dbus_g_connection_get_connection(bus), 
				       "org.xfce.PowerManager"))
    {
	g_print (_("Xfce power manager is already running"));
	g_print ("\n");
    	return EXIT_SUCCESS;
    }
    else
    {	
	xfpm_start (bus, client_id, dump);
    }
    
    return EXIT_SUCCESS;
}
Exemple #6
0
/* entry point */
int
main (int argc, char **argv)
{
  GtkWidget *mainwin;
  gint n_burners;
  GError *error = NULL;
#ifdef HAVE_GUDEV
  gchar *error_msg;
#endif
  XfburnTranscoder *transcoder;
  XfburnDeviceList *devlist;

#if DEBUG > 0
  /* I have to disable this until GtkTreeView gets fixed,
   * and doesn't complain anymore when a DnD doesn't add any
   * rows
  g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
   */
#endif
  
  g_set_application_name (_("Xfburn"));

  gdk_threads_init ();
  gdk_threads_enter ();

  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");

  if (!gtk_init_with_args (&argc, &argv, "", optionentries, GETTEXT_PACKAGE, &error)) {
    if (error != NULL) {
      g_print (_("%s: %s\nTry %s --help to see a full list of available command line options.\n"), PACKAGE, error->message, PACKAGE_NAME);
      g_error_free (error);
      return EXIT_FAILURE;
    }
  }

  if (!burn_initialize ()) {
    g_critical ("Unable to initialize libburn");
    xfce_dialog_show_error (NULL, NULL, _("Unable to initialize the burning backend."));
    gdk_threads_leave ();
    return EXIT_FAILURE;
  }

#ifdef HAVE_GST
  if (!gst_init_check (&argc, &argv, &error)) {
    g_critical ("Failed to initialize gstreamer!");
    /* I'm assuming this pretty much never happens. If it does, we should make this a soft failure and fall back to basic */
    gdk_threads_leave ();
    burn_finish ();
    return EXIT_FAILURE;
  }
#endif

  if (show_version) {
#ifdef HAVE_GST
    const char *nano_str;
    guint gst_major, gst_minor, gst_micro, gst_nano;
#endif

    g_print ("%s version %s for Xfce %s\n", PACKAGE, VERSION, xfce_version_string ());
    g_print ("\tbuilt with GTK+-%d.%d.%d, ", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
    g_print ("linked with GTK+-%d.%d.%d.\n", gtk_major_version, gtk_minor_version, gtk_micro_version);

#ifdef HAVE_GST
    gst_version (&gst_major, &gst_minor, &gst_micro, &gst_nano);

    if (gst_nano == 1)
      nano_str = " (CVS)";
    else if (gst_nano == 2)
      nano_str = " (Prerelease)";
    else
      nano_str = "";

    g_print ("\tGStreamer support (built with %d.%d.%d, linked against %d.%d.%d%s)\n",
             GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO,
             gst_major, gst_minor, gst_micro, nano_str);
             
#endif
    exit (EXIT_SUCCESS);
  }

  if (transcoder_selection && strcmp (transcoder_selection, "list") == 0) {
    print_available_transcoders();
    gdk_threads_leave ();
    burn_finish ();
    return EXIT_SUCCESS;
  }

  DBG ("%s version %s for Xfce %s\n", PACKAGE, VERSION, xfce_version_string ());

  xfburn_settings_init ();
  
#ifdef HAVE_GUDEV
  error_msg = xfburn_udev_manager_create_global ();
  if (error_msg) {
    xfce_dialog_show_error (NULL, NULL, "%s", error_msg);
    gdk_threads_leave ();
    burn_finish ();
    return EXIT_FAILURE;
  } else {
    g_message ("Using UDEV");
  }
#endif

  xfburn_stock_init ();
  devlist = xfburn_device_list_new ();
  g_object_get (devlist, "num-burners", &n_burners, NULL);

  if (n_burners < 1) {
    GtkMessageDialog *dialog = (GtkMessageDialog *) gtk_message_dialog_new (NULL,
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
                                    GTK_MESSAGE_WARNING,
                                    GTK_BUTTONS_CLOSE,
                                    ((const gchar *) _("No burners are currently available")));
    gtk_message_dialog_format_secondary_text (dialog,
                                    _("Possibly the disc(s) are in use, and cannot get accessed.\n\n"
                                      "Please unmount and restart the application.\n\n"
                                      "If no disc is in the drive, check that you have read and write access to the drive with the current user."));
    gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_destroy (GTK_WIDGET (dialog));
  }


  /*----------Transcoder--------------------------------------------------*/

  if (!transcoder_selection) {
    /* select the best available */
#ifdef HAVE_GST
    transcoder = XFBURN_TRANSCODER (xfburn_transcoder_gst_new ());
#else
    transcoder = XFBURN_TRANSCODER (xfburn_transcoder_basic_new ());
#endif
#ifdef HAVE_GST
  } else if (strcmp (transcoder_selection, "gst") == 0) {
    transcoder = XFBURN_TRANSCODER (xfburn_transcoder_gst_new ());
#endif
  } else if (strcmp (transcoder_selection, "basic") == 0) {
    transcoder = XFBURN_TRANSCODER (xfburn_transcoder_basic_new ());
  } else {
    g_print ("'%s' is an invalid transcoder selection.\n",
             transcoder_selection);
    g_print ("\n");
    print_available_transcoders();
    gdk_threads_leave ();
    burn_finish ();
    return EXIT_FAILURE;
  }

  if (!xfburn_transcoder_is_initialized (transcoder, &error)) {
    xfce_dialog_show_warning(NULL, NULL, _("Failed to initialize %s transcoder: %s\n\t(falling back to basic implementation)"), xfburn_transcoder_get_name (transcoder), error->message);
    g_error_free (error);
    g_object_unref (transcoder);
    transcoder = XFBURN_TRANSCODER (xfburn_transcoder_basic_new ());
  } else {
    g_message ("Using %s transcoder.", xfburn_transcoder_get_name (transcoder));
  }
  xfburn_transcoder_set_global (transcoder);


  /*----------evaluate parsed command line action options-------------------------*/

  /* heuristic for file names on the commandline */
  if (argc == 2 && !add_data_composition && !add_audio_composition) {
    /* exactly one filename, assume it is an image */
      image_filename = argv[1];
  } else if (argc > 2) {
    /* several file names, for now just open up a data composition */
    /* TODO: auto-detect music files for audio compositions */
    add_data_composition = TRUE;
  }


  if (show_main) {
    xfburn_main_enter_main_window ();
  }

  if (image_filename != NULL) {
    GtkWidget *dialog = xfburn_burn_image_dialog_new ();
    other_action = TRUE;

    DBG ("image_filename = '%s'\n", image_filename);

    if (*image_filename != '\0') {
      gchar *image_fullname;

      if (!g_path_is_absolute (image_filename))
	image_fullname  = g_build_filename (g_get_current_dir (), image_filename, NULL);
      else
	image_fullname = image_filename;

      if (g_file_test (image_fullname, G_FILE_TEST_EXISTS))
	xfburn_burn_image_dialog_set_filechooser_name (dialog, image_fullname);
      else
        xfce_dialog_show_error (NULL, NULL, _("Image file '%s' does not exist."), image_fullname);
    }

    gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_destroy (dialog);
  } else if (blank) {
    GtkWidget *dialog = xfburn_blank_dialog_new ();

    other_action = TRUE;
    gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_destroy (dialog);
  }


  /*----------main window--------------------------------------------------*/

  if (!other_action || show_main) {
    xfburn_main_enter_main_window ();
    mainwin = xfburn_main_window_new ();

    gtk_widget_show (mainwin);
  
    if (add_data_composition)
      xfburn_main_window_add_data_composition_with_files (XFBURN_MAIN_WINDOW (mainwin), argc-1, argv+1);

    if (add_audio_composition)
      xfburn_main_window_add_audio_composition_with_files (XFBURN_MAIN_WINDOW (mainwin), argc-1, argv+1);
  }


  gtk_main ();


  /*----------shutdown--------------------------------------------------*/

  g_object_unref (devlist);
  g_object_unref (transcoder);

#ifdef HAVE_GUDEV
  xfburn_udev_manager_shutdown ();
#endif

  xfburn_settings_flush ();
  xfburn_settings_free ();
  
  burn_finish ();

  gdk_threads_leave ();

  return EXIT_SUCCESS;
}
Exemple #7
0
gint
main (gint    argc,
      gchar **argv)
{
  GtkBuilder *builder;
  GError     *error = NULL;
  GObject    *dialog;
  GObject    *object;
  gchar      *version;

  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");

  if (G_UNLIKELY (!gtk_init_with_args (&argc, &argv, NULL, opt_entries, PACKAGE, &error)))
    {
      if (G_LIKELY (error != NULL))
        {
          g_print ("%s: %s.\n", G_LOG_DOMAIN, error->message);
          g_print (_("Type '%s --help' for usage information."), G_LOG_DOMAIN);
          g_print ("\n");

          g_error_free (error);
        }
      else
        g_error (_("Unable to initialize GTK+."));

      return EXIT_FAILURE;
    }

  if (G_UNLIKELY (opt_version))
    {
      g_print ("%s %s (Xfce %s)\n\n", G_LOG_DOMAIN, PACKAGE_VERSION, xfce_version_string ());
      g_print ("%s\n", "Copyright (c) 2008-2019");
      g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved."));
      g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT);
      g_print ("\n");

      return EXIT_SUCCESS;
    }

  builder = gtk_builder_new ();
  if (!gtk_builder_add_from_string (builder, xfce_about_dialog_ui,
                                    xfce_about_dialog_ui_length, &error))
    {
      xfce_dialog_show_error (NULL, error, _("Failed to load interface"));
      g_error_free (error);
      g_object_unref (G_OBJECT (builder));

      return EXIT_FAILURE;
    }

  dialog = gtk_builder_get_object (builder, "window");
  g_signal_connect_swapped (G_OBJECT (dialog), "delete-event",
      G_CALLBACK (gtk_main_quit), NULL);

#ifdef VENDOR_INFO
  /* I18N: first %s will be replaced by the version, second by
   * the name of the distribution (--with-vendor-info=NAME) */
  version = g_strdup_printf (_("Version %s, distributed by %s"),
                             xfce_version_string (), VENDOR_INFO);
#else
  /* I18N: %s will be replaced by the Xfce version number */
  version = g_strdup_printf (_("Version %s"), xfce_version_string ());
#endif
  xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dialog), version);
  g_free (version);

  object = gtk_builder_get_object (builder, "about-buffer");
  xfce_about_about (GTK_TEXT_BUFFER (object));

  object = gtk_builder_get_object (builder, "credits-buffer");
  xfce_about_credits (GTK_TEXT_BUFFER (object));

  object = gtk_builder_get_object (builder, "copyright-buffer");
  xfce_about_copyright (GTK_TEXT_BUFFER (object));

#ifdef VENDOR_INFO
  xfce_about_vendor (builder);
#endif

  object = gtk_builder_get_object (builder, "gpl-button");
  g_signal_connect_swapped (G_OBJECT (object), "clicked",
      G_CALLBACK (xfce_about_license_gpl), builder);

  object = gtk_builder_get_object (builder, "lgpl-button");
  g_signal_connect_swapped (G_OBJECT (object), "clicked",
      G_CALLBACK (xfce_about_license_lgpl), builder);

  object = gtk_builder_get_object (builder, "bsd-button");
  g_signal_connect_swapped (G_OBJECT (object), "clicked",
      G_CALLBACK (xfce_about_license_bsd), builder);

  object = gtk_builder_get_object (builder, "help-button");
  g_signal_connect (G_OBJECT (object), "clicked",
      G_CALLBACK (xfce_about_help), dialog);

  object = gtk_builder_get_object (builder, "close-button");
  g_signal_connect_swapped (G_OBJECT (object), "clicked",
      G_CALLBACK (gtk_main_quit), NULL);

  gtk_widget_show (GTK_WIDGET (dialog));

  gtk_main ();

  g_object_unref (G_OBJECT (builder));

  return EXIT_SUCCESS;
}
Exemple #8
0
int
main(int argc,
     char **argv)
{
    GtkBuilder *builder;
    GtkWidget *notebook, *xfae_page, *lbl;
    GError *error = NULL;
    XfconfChannel *channel;

    xfce_textdomain(GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");

    if(!gtk_init_with_args (&argc, &argv, "", option_entries,
                            GETTEXT_PACKAGE, &error))
    {
        if(G_LIKELY(error)) {
            g_print("%s: %s.\n", G_LOG_DOMAIN, error->message);
            g_print(_("Type '%s --help' for usage."), G_LOG_DOMAIN);
            g_print("\n");
            g_error_free (error);
        } else
            g_error("Unable to open display.");

        return EXIT_FAILURE;
    }

    if(G_UNLIKELY(opt_version)) {
        g_print("%s %s (Xfce %s)\n\n", G_LOG_DOMAIN, PACKAGE_VERSION, xfce_version_string ());
        g_print("%s\n", "Copyright (c) 2004-2014");
        g_print("\t%s\n\n", _("The Xfce development team. All rights reserved."));
        g_print(_("Please report bugs to <%s>."), PACKAGE_BUGREPORT);
        g_print("\n");

        return EXIT_SUCCESS;
    }

    if(G_UNLIKELY(!xfconf_init(&error))) {
        xfce_dialog_show_error (NULL,
                                error,
                                _("Unable to contact settings server"));
        g_error_free(error);
        return EXIT_FAILURE;
    }

    gtk_window_set_default_icon_name("xfce4-session");

    /* hook to make sure the libxfce4ui library is linked */
    if (xfce_titled_dialog_get_type() == 0)
        return EXIT_FAILURE;

    builder = gtk_builder_new();
    gtk_builder_add_from_string(builder,
                                xfce4_session_settings_ui,
                                xfce4_session_settings_ui_length,
                                &error);

    if(!builder) {
        xfce_dialog_show_error(NULL, error,
                               _("Unable to create user interface from embedded definition data"));
        g_error_free (error);
        return EXIT_FAILURE;
    }

    splash_settings_init(builder);
    session_editor_init(builder);

    /* FIXME: someday, glade-ify this, maybe. */
    xfae_page = xfae_window_new();
    gtk_widget_show(xfae_page);
    notebook = GTK_WIDGET(gtk_builder_get_object(builder, "plug-child"));
    lbl = gtk_label_new_with_mnemonic(_("App_lication Autostart"));
    gtk_widget_show(lbl);
    gtk_notebook_insert_page(GTK_NOTEBOOK(notebook), xfae_page, lbl, 2);

    channel = xfconf_channel_get(SETTINGS_CHANNEL);

    /* bind widgets to xfconf */
    xfconf_g_property_bind(channel, "/chooser/AlwaysDisplay", G_TYPE_BOOLEAN,
                           gtk_builder_get_object(builder, "chk_display_chooser"),
                           "active");
    xfconf_g_property_bind(channel, "/general/AutoSave", G_TYPE_BOOLEAN,
                           gtk_builder_get_object(builder, "chk_session_autosave"),
                           "active");
    xfconf_g_property_bind(channel, "/general/PromptOnLogout", G_TYPE_BOOLEAN,
                           gtk_builder_get_object(builder, "chk_logout_prompt"),
                           "active");
    xfconf_g_property_bind(channel, "/compat/LaunchGNOME", G_TYPE_BOOLEAN,
                           gtk_builder_get_object(builder, "chk_compat_gnome"),
                           "active");
    xfconf_g_property_bind(channel, "/compat/LaunchKDE", G_TYPE_BOOLEAN,
                           gtk_builder_get_object(builder, "chk_compat_kde"),
                           "active");
    xfconf_g_property_bind(channel, "/security/EnableTcp", G_TYPE_BOOLEAN,
                           gtk_builder_get_object(builder, "chk_enable_tcp"),
                           "active");
    xfconf_g_property_bind(channel, "/shutdown/LockScreen", G_TYPE_BOOLEAN,
                           gtk_builder_get_object(builder, "chk_lock_screen"),
                           "active");

    if(G_UNLIKELY(opt_socket_id == 0)) {
        GtkWidget *dialog = GTK_WIDGET(gtk_builder_get_object(builder, "xfce4_session_settings_dialog"));

        g_signal_connect(dialog, "response", G_CALLBACK(xfce4_session_settings_dialog_response), NULL);
        g_signal_connect(dialog, "delete-event", G_CALLBACK(gtk_main_quit), NULL);

        gtk_widget_show(dialog);

        /* To prevent the settings dialog to be saved in the session */
        gdk_set_sm_client_id ("FAKE ID");

        gtk_main();
    } else {
        GtkWidget *plug, *plug_child;

        plug = gtk_plug_new(opt_socket_id);
        gtk_widget_show(plug);
        g_signal_connect(plug, "delete-event",
                         G_CALLBACK(gtk_main_quit), NULL);

        plug_child = GTK_WIDGET(gtk_builder_get_object(builder, "plug-child"));
        gtk_widget_reparent(plug_child, plug);
        gtk_widget_show(plug_child);

        /* Stop startup notification */
        gdk_notify_startup_complete();

        gtk_main();
    }

    g_object_unref(builder);

    return EXIT_SUCCESS;
}
Exemple #9
0
gint
main (gint argc, gchar **argv)
{
  GError        *error = NULL;
  GtkWidget     *dialog;
  GtkWidget     *button;
  gint           result;
  gint           retval = EXIT_SUCCESS;
  gint           default_response = GTK_RESPONSE_CANCEL;
  XfconfChannel *channel;
  gint           configver;
  gchar         *filename_46;
  gchar         *filename_default;
  gboolean       migrate_vendor_default;

  /* set translation domain */
  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");

#ifndef NDEBUG
  /* terminate the program on warnings and critical messages */
  g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
#endif

  gtk_init (&argc, &argv);

  if (!xfconf_init (&error))
    {
      g_critical ("Failed to initialize Xfconf: %s", error->message);
      g_error_free (error);
      return EXIT_FAILURE;
    }

  channel = xfconf_channel_get (XFCE_PANEL_CHANNEL_NAME);
  if (!xfconf_channel_has_property (channel, "/panels"))
    {
      /* lookup the old 4.6 config file */
      filename_46 = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, XFCE_46_CONFIG);

      /* lookup the default configuration */
      xfce_resource_push_path (XFCE_RESOURCE_CONFIG, XDGCONFIGDIR);
      filename_default = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, DEFAULT_CONFIG_FILENAME);
      xfce_resource_pop_path (XFCE_RESOURCE_CONFIG);

      if (filename_46 == NULL && filename_default == NULL)
        {
          g_warning ("No default or old configuration found");
          return EXIT_FAILURE;
        }

      /* if the default configuration does not match with the file found
       * by the resource lookup, migrate it without asking */
      migrate_vendor_default = (g_strcmp0 (DEFAULT_CONFIG_PATH, filename_default) != 0);

      /* check if we auto-migrate the default configuration */
      if (g_getenv ("XFCE_PANEL_MIGRATE_DEFAULT") != NULL
          || migrate_vendor_default)
        {
          if (filename_46 != NULL)
            g_message ("Tried to auto-migrate, but old configuration found");
          else if (filename_default == NULL)
            g_message ("Tried to auto-migrate, but no default configuration found");
          else
            goto migrate_default;
        }

      /* create question dialog */
      dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
                                       _("Welcome to the first start of the panel"));
      gtk_window_set_title (GTK_WINDOW (dialog), _("Panel"));
      gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_PREFERENCES);
      gtk_window_stick (GTK_WINDOW (dialog));
      gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);

      if (filename_46 != NULL)
        {
          gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s\n%s",
              _("Because the panel moved to a new system for storing the "
                "settings, it has to load a fresh initial configuration."),
              _("Choose below which setup you want for the first startup."));

          button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Migrate old config"), GTK_RESPONSE_OK);
          gtk_widget_set_tooltip_text (button, _("Migrate the old 4.6 configuration to Xfconf"));
          default_response = GTK_RESPONSE_OK;
        }
      else
        {
          gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
              _("Choose below which setup you want for the first startup."));
        }

      if (filename_default != NULL)
        {
          button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Use default config"), GTK_RESPONSE_YES);
          gtk_widget_set_tooltip_text (button, _("Load the default configuration"));

          if (default_response == GTK_RESPONSE_CANCEL)
            default_response = GTK_RESPONSE_YES;
        }

      button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("One empty panel"), GTK_RESPONSE_CANCEL);
      gtk_widget_set_tooltip_text (button, _("Start with one empty panel"));

      gtk_dialog_set_default_response (GTK_DIALOG (dialog), default_response);
      result = gtk_dialog_run (GTK_DIALOG (dialog));
      gtk_widget_destroy (dialog);

      if (result == GTK_RESPONSE_OK && filename_46 != NULL)
        {
          /* restore 4.6 config */
          if (!migrate_46 (filename_46, channel, &error))
            {
              xfce_dialog_show_error (NULL, error, _("Failed to migrate the old panel configuration"));
              g_error_free (error);
              retval = EXIT_FAILURE;
            }
        }
      else if (result == GTK_RESPONSE_YES && filename_default != NULL)
        {
          migrate_default:

          /* apply default config */
          if (!migrate_default (filename_default, &error))
            {
              xfce_dialog_show_error (NULL, error, _("Failed to load the default configuration"));
              g_error_free (error);
              retval = EXIT_FAILURE;
            }
        }

      g_free (filename_46);
      g_free (filename_default);
    }

  configver = xfconf_channel_get_int (channel, "/configver", -1);
  if (configver < XFCE4_PANEL_CONFIG_VERSION)
    {
      g_message (_("Panel config needs migration..."));

      if (!migrate_config (channel, configver, &error))
        {
          xfce_dialog_show_error (NULL, error, _("Failed to migrate the existing configuration"));
          g_error_free (error);
          retval = EXIT_FAILURE;
        }
      else
        {
          g_message (_("Panel configuration has been updated."));
        }

      /* migration complete, set new version */
      xfconf_channel_set_int (channel, "/configver", XFCE4_PANEL_CONFIG_VERSION);
    }

  xfconf_shutdown ();

  return retval;
}
int main (int argc, char **argv)
{
    GtkWidget *dialog;
    XfpmUnique *unique;

    GError *error = NULL;
    DBusGConnection *bus;
    GHashTable *config_hash;
    
    gboolean has_battery;
    gboolean auth_suspend;
    gboolean auth_hibernate;
    gboolean can_suspend;
    gboolean can_hibernate;
    gboolean can_shutdown;
    gboolean has_lcd_brightness;
    gboolean has_sleep_button;
    gboolean has_hibernate_button;
    gboolean has_power_button;
    gboolean has_lid;
    gboolean start_xfpm_if_not_running;
    gboolean debug = FALSE;

    GdkNativeWindow socket_id = 0;
    gchar *device_id = NULL;

    XfconfChannel *channel;
    DBusGProxy *proxy;
    
    GOptionEntry option_entries[] = 
    {
	{ "socket-id", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT, &socket_id, N_("Settings manager socket"), N_("SOCKET ID") },
	{ "device-id", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &device_id, N_("Display a specific device by UpDevice object path"), N_("UpDevice object path") },
	{ "debug",    '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &debug, N_("Enable debugging"), NULL },
	{ NULL, },
    };

    xfce_textdomain(GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
    
    if( !gtk_init_with_args (&argc, &argv, (gchar *)"", option_entries, (gchar *)PACKAGE, &error)) 
    {
        if( error) 
        {
            g_printerr("%s: %s.\n", G_LOG_DOMAIN, error->message);
            g_printerr(_("Type '%s --help' for usage."), G_LOG_DOMAIN);
            g_printerr("\n");
            g_error_free(error);
        }
        else
        {
            g_error("Unable to open display.");
	}
        return EXIT_FAILURE;
    }
    
    bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
    
    if ( error )
    {
	g_error ("%s\n",error->message);
    }

    while ( !xfpm_dbus_name_has_owner (dbus_g_connection_get_connection(bus), "org.xfce.PowerManager") )
    {
	g_print(_("Xfce power manager is not running"));
	g_print("\n");
	start_xfpm_if_not_running =
	    xfce_dialog_confirm (NULL, 
				 GTK_STOCK_EXECUTE,
				 _("Run"), NULL,
				 _("Xfce4 Power Manager is not running, do you want to launch it now?"));

	if ( start_xfpm_if_not_running ) 
	{
	    g_spawn_command_line_async("xfce4-power-manager",NULL);
	    /* wait 2 seconds for xfpm to startup */
	    g_usleep ( 2 * 1000000 );
	}
	else
	{
	    /* continue without starting xfpm, this will probably error out */
	    break;
	}
    }

    unique = xfpm_unique_new ("org.xfce.PowerManager.Config");

    if ( !xfpm_unique_app_is_running (unique) )
    {
	if ( !xfconf_init(&error) )
	{
	    g_critical("xfconf init failed: %s using default settings\n", error->message);
	    xfce_dialog_show_warning (NULL,
				      _("Xfce Power Manager"),
				      "%s",
				      _("Failed to load power manager configuration, using defaults"));
	    g_error_free (error);
	    error = NULL;
	    return EXIT_FAILURE;
	}

#if !GLIB_CHECK_VERSION (2, 32, 0)
    if ( !g_thread_supported () )
        g_thread_init (NULL);
#endif

	dbus_g_thread_init ();

	channel = xfconf_channel_new(XFPM_CHANNEL_CFG);

	proxy = dbus_g_proxy_new_for_name(bus,
					   "org.xfce.PowerManager",
					   "/org/xfce/PowerManager",
					   "org.xfce.Power.Manager");

	xfpm_manager_dbus_client_get_config (proxy,
					     &config_hash,
					     &error);

	if ( error )
	{
	    g_critical ("Unable to get configuration information from xfce power manager: %s", error->message);
	    xfce_dialog_show_error (NULL, error, "%s", _("Unable to connect to Xfce Power Manager"));
	    g_error_free (error);
	    return EXIT_FAILURE;
	}

	xfpm_debug_init (debug);

	has_battery = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-battery"));
	has_lid = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-lid"));
	can_suspend = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-suspend"));
	can_hibernate = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-hibernate"));
	auth_suspend = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "auth-suspend"));
	auth_hibernate = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "auth-hibernate"));
	has_lcd_brightness = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-brightness"));
	has_sleep_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "sleep-button"));
	has_power_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "power-button"));
	has_hibernate_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "hibernate-button"));
	can_shutdown = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-shutdown"));

	g_hash_table_destroy (config_hash);

	dialog = xfpm_settings_dialog_new (channel, auth_suspend, auth_hibernate,
					   can_suspend, can_hibernate, can_shutdown, has_battery, has_lcd_brightness,
					   has_lid, has_sleep_button, has_hibernate_button, has_power_button,
					   socket_id, device_id);

	g_signal_connect_swapped (unique, "ping-received",
				  G_CALLBACK (gtk_window_present), dialog);

	gtk_main();

	xfpm_dbus_release_name(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager.Config");
	dbus_g_connection_unref (bus);
	g_object_unref (proxy);

	g_object_unref (unique);

	return EXIT_SUCCESS;
    }
    
    return EXIT_SUCCESS;
}
Exemple #11
0
gint
main (gint argc, gchar **argv)
{
  GOptionContext   *context;
  PanelApplication *application;
  GError           *error = NULL;
  PanelDBusService *dbus_service;
  gboolean          succeed = FALSE;
  gboolean          remote_succeed;
  guint             i;
  const gint        signums[] = { SIGINT, SIGQUIT, SIGTERM, SIGABRT, SIGUSR1 };
  const gchar      *error_msg;
  XfceSMClient     *sm_client;

  panel_debug (PANEL_DEBUG_MAIN,
               "version %s on gtk+ %d.%d.%d (%d.%d.%d), glib %d.%d.%d (%d.%d.%d)",
               LIBXFCE4PANEL_VERSION,
               gtk_major_version, gtk_minor_version, gtk_micro_version,
               GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION,
               glib_major_version, glib_minor_version, glib_micro_version,
               GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);

  /* inform the user about usage of gdb/valgrind */
  panel_debug_notify_proxy ();

  /* set translation domain */
  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");

#ifdef G_ENABLE_DEBUG
  /* do NOT remove this line for now, If something doesn't work,
   * fix your code instead! */
  g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
#endif

  /* parse context options */
  context = g_option_context_new (_("[ARGUMENTS...]"));
  g_option_context_add_main_entries (context, option_entries, GETTEXT_PACKAGE);
  g_option_context_add_group (context, gtk_get_option_group (TRUE));
  g_option_context_add_group (context, xfce_sm_client_get_option_group (argc, argv));
  if (!g_option_context_parse (context, &argc, &argv, &error))
    {
      g_print ("%s: %s.\n", PACKAGE_NAME, error->message);
      g_print (_("Type \"%s --help\" for usage."), G_LOG_DOMAIN);
      g_print ("\n");
      g_error_free (error);

      return EXIT_FAILURE;
    }
  g_option_context_free (context);

  gtk_init (&argc, &argv);

  if (opt_version)
    {
      /* print version information */
      if (opt_arguments != NULL && *opt_arguments != NULL)
        g_print ("%s (%s)", *opt_arguments, PACKAGE_NAME);
      else
        g_print ("%s", PACKAGE_NAME);
      g_print (" %s (Xfce %s)\n\n", PACKAGE_VERSION, xfce_version_string ());
      g_print ("%s\n", "Copyright (c) 2004-2011");
      g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved."));
      g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT);
      g_print ("\n");

      return EXIT_SUCCESS;
    }
  else if (opt_preferences >= 0)
    {
      /* send a signal to the running instance to show the preferences dialog */
      succeed = panel_dbus_client_display_preferences_dialog (opt_preferences, opt_socket_id, &error);
      goto dbus_return;
    }
  else if (opt_add_items >= 0)
    {
      /* send a signal to the running instance to show the add items dialog */
      succeed = panel_dbus_client_display_items_dialog (opt_add_items, &error);
      goto dbus_return;
    }
  else if (opt_save)
    {
      /* send a save signal to the running instance */
      succeed = panel_dbus_client_save (&error);
      goto dbus_return;
    }
  else if (opt_add != NULL)
    {
      /* send a add-new-item signal to the running instance */
      succeed = panel_dbus_client_add_new_item (opt_add, opt_arguments, &error);
      goto dbus_return;
    }
  else if (opt_restart || opt_quit)
    {
      /* send a terminate signal to the running instance */
      succeed = panel_dbus_client_terminate (opt_restart, &error);
      goto dbus_return;
    }
  else if (opt_plugin_event != NULL)
    {
      /* send the plugin event to the running instance */
      remote_succeed = FALSE;
      succeed = panel_dbus_client_plugin_event (opt_plugin_event, &remote_succeed, &error);

      /* the panel returns EXIT_FAILURE if the dbus event succeeds, but
       * no suitable plugin was found on the service side */
      if (succeed && !remote_succeed)
        succeed = FALSE;

      goto dbus_return;
    }

  launch_panel:

  /* start dbus service */
  dbus_service = panel_dbus_service_get ();
  if (!panel_dbus_service_is_owner (dbus_service))
    {
      /* quit without error if an instance is running */
      succeed = TRUE;

      g_print ("%s: %s\n\n", G_LOG_DOMAIN, _("There is already a running instance"));
      goto dbus_return;
    }

  /* start session management */
  sm_client = xfce_sm_client_get ();
  xfce_sm_client_set_restart_style (sm_client, XFCE_SM_CLIENT_RESTART_IMMEDIATELY);
  xfce_sm_client_set_priority (sm_client, XFCE_SM_CLIENT_PRIORITY_CORE);
  g_signal_connect (G_OBJECT (sm_client), "quit",
      G_CALLBACK (panel_sm_client_quit), NULL);
  if (!xfce_sm_client_connect (sm_client, &error))
    {
      g_printerr ("%s: Failed to connect to session manager: %s\n",
                  G_LOG_DOMAIN, error->message);
      g_clear_error (&error);
    }

  /* setup signal handlers to properly quit the main loop */
  for (i = 0; i < G_N_ELEMENTS (signums); i++)
    signal (signums[i], panel_signal_handler);

  application = panel_application_get ();
  panel_application_load (application, opt_disable_wm_check);

  /* open dialog if we started from launch_panel */
  if (opt_preferences >= 0)
    panel_preferences_dialog_show_from_id (opt_preferences, opt_socket_id);

  gtk_main ();

  /* make sure there are no incomming events when we close */
  g_object_unref (G_OBJECT (dbus_service));

  /* destroy all the opened dialogs */
  panel_application_destroy_dialogs (application);

  g_object_unref (G_OBJECT (application));
  g_object_unref (G_OBJECT (sm_client));

  if (panel_dbus_service_get_restart ())
    {
      /* spawn ourselfs again */
      g_print ("%s: %s\n\n", G_LOG_DOMAIN, _("Restarting..."));
      g_spawn_command_line_async (argv[0], NULL);
    }

  return EXIT_SUCCESS;

dbus_return:

  /* stop any running startup notification */
  gdk_notify_startup_complete ();

  if (G_UNLIKELY (error != NULL))
    {
      /* get suitable error message */
      if (opt_preferences >= 0)
        error_msg = _("Failed to show the preferences dialog");
      else if (opt_add_items >= 0)
        error_msg = _("Failed to show the add new items dialog");
      else if (opt_save)
        error_msg = _("Failed to save the panel configuration");
      else if (opt_add)
        error_msg = _("Failed to add a plugin to the panel");
      else if (opt_restart)
        error_msg = _("Failed to restart the panel");
      else if (opt_quit)
        error_msg = _("Failed to quit the panel");
      else
        error_msg = _("Failed to send D-Bus message");

      /* show understandable message for this common error */
      if (error->code == DBUS_GERROR_NAME_HAS_NO_OWNER)
        {
          /* normally start the panel */
          if (opt_preferences >= 0 || opt_restart)
            {
              g_clear_error (&error);

              if (xfce_dialog_confirm (NULL, GTK_STOCK_EXECUTE, NULL,
                                       _("Do you want to start the panel? If you do, make sure "
                                         "you save the session on logout, so the panel is "
                                         "automatically started the next time you login."),
                                       _("No running instance of %s was found"), G_LOG_DOMAIN))
                {
                  panel_debug (PANEL_DEBUG_MAIN, "user confirmed to start the panel");
                  goto launch_panel;
                }
              else
                {
                  return EXIT_FAILURE;
                }
            }
          else
            {
              /* I18N: %s is replaced with xfce4-panel */
              g_clear_error (&error);
              g_set_error (&error, 0, 0, _("No running instance of %s was found"), G_LOG_DOMAIN);
            }
        }

      /* show error dialog */
      xfce_dialog_show_error (NULL, error, "%s", error_msg);
      g_error_free (error);
    }

  return succeed ? EXIT_SUCCESS : EXIT_FAILURE;
}