Пример #1
0
gboolean
panel_dialogs_kiosk_warning (void)
{
  PanelApplication *application;
  gboolean          locked;

  application = panel_application_get ();
  locked = panel_application_get_locked (application);
  g_object_unref (G_OBJECT (application));

  if (locked)
    {
      xfce_dialog_show_warning (NULL,
          _("Because the panel is running in kiosk mode, you are not allowed "
            "to make changes to the panel configuration as a regular user"),
          _("Modifying the panel is not allowed"));
    }

  return locked;
}
Пример #2
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;
}