void pragha_init_session_support(PraghaApplication *pragha) { XfceSMClient *client; GError *error = NULL; client = xfce_sm_client_get (); xfce_sm_client_set_priority (client, XFCE_SM_CLIENT_PRIORITY_DEFAULT); xfce_sm_client_set_restart_style (client, XFCE_SM_CLIENT_RESTART_NORMAL); xfce_sm_client_set_desktop_file(client, DESKTOPENTRY); g_signal_connect (G_OBJECT (client), "quit", G_CALLBACK (pragha_session_quit), pragha); g_signal_connect (G_OBJECT (client), "save-state", G_CALLBACK (pragha_session_save_state), pragha); if(!xfce_sm_client_connect (client, &error)) { g_warning ("Failed to connect to session manager: %s", error->message); g_error_free (error); } }
/* Perform full initialization of this application instance */ static gboolean _xfdashboard_application_initialize_full(XfdashboardApplication *self, XfdashboardStage **outStage) { XfdashboardApplicationPrivate *priv; GError *error; ClutterActor *stage; #if !GARCON_CHECK_VERSION(0,3,0) const gchar *desktop; #endif g_return_val_if_fail(XFDASHBOARD_IS_APPLICATION(self), FALSE); g_return_val_if_fail(outStage==NULL || *outStage==NULL, FALSE); priv=self->priv; error=NULL; /* Initialize garcon for current desktop environment */ #if !GARCON_CHECK_VERSION(0,3,0) desktop=g_getenv("XDG_CURRENT_DESKTOP"); if(G_LIKELY(desktop==NULL)) { /* If we could not determine current desktop environment * assume Xfce as this application is developed for this DE. */ desktop="XFCE"; } /* If desktop enviroment was found but has no name * set NULL to get all menu items shown. */ else if(*desktop==0) desktop=NULL; garcon_set_environment(desktop); #else garcon_set_environment_xdg(GARCON_ENVIRONMENT_XFCE); #endif /* Setup the session management */ priv->sessionManagementClient=xfce_sm_client_get(); xfce_sm_client_set_priority(priv->sessionManagementClient, XFCE_SM_CLIENT_PRIORITY_DEFAULT); xfce_sm_client_set_restart_style(priv->sessionManagementClient, XFCE_SM_CLIENT_RESTART_IMMEDIATELY); g_signal_connect_swapped(priv->sessionManagementClient, "quit", G_CALLBACK(_xfdashboard_application_on_session_quit), self); if(!xfce_sm_client_connect(priv->sessionManagementClient, &error)) { g_warning("Failed to connect to session manager: %s", (error && error->message) ? error->message : _("unknown error")); g_clear_error(&error); } /* Initialize xfconf */ if(!xfconf_init(&error)) { g_critical(_("Could not initialize xfconf: %s"), (error && error->message) ? error->message : _("unknown error")); if(error) g_error_free(error); return(FALSE); } priv->xfconfChannel=xfconf_channel_get(XFDASHBOARD_XFCONF_CHANNEL); /* Set up keyboard and pointer bindings */ priv->bindings=xfdashboard_bindings_pool_get_default(); if(!priv->bindings) { g_critical(_("Could not initialize bindings")); return(FALSE); } if(!xfdashboard_bindings_pool_load(priv->bindings, &error)) { g_critical(_("Could not load bindings: %s"), (error && error->message) ? error->message : _("unknown error")); if(error!=NULL) g_error_free(error); return(FALSE); } /* Set up application database */ priv->appDatabase=xfdashboard_application_database_get_default(); if(!priv->appDatabase) { g_critical(_("Could not initialize application database")); return(FALSE); } if(!xfdashboard_application_database_load(priv->appDatabase, &error)) { g_critical(_("Could not load application database: %s"), (error && error->message) ? error->message : _("unknown error")); if(error!=NULL) g_error_free(error); return(FALSE); } /* Set up application tracker */ priv->appTracker=xfdashboard_application_tracker_get_default(); if(!priv->appTracker) { g_critical(_("Could not initialize application tracker")); return(FALSE); } /* Set up and load theme */ priv->xfconfThemeChangedSignalID=xfconf_g_property_bind(priv->xfconfChannel, THEME_NAME_XFCONF_PROP, G_TYPE_STRING, self, "theme-name"); if(!priv->xfconfThemeChangedSignalID) { g_warning(_("Could not create binding between xfconf property and local resource for theme change notification.")); } /* Set up default theme in Xfcond if property in channel does not exist * because it indicates first start. */ if(!xfconf_channel_has_property(priv->xfconfChannel, THEME_NAME_XFCONF_PROP)) { xfconf_channel_set_string(priv->xfconfChannel, THEME_NAME_XFCONF_PROP, DEFAULT_THEME_NAME); } /* At this time the theme must have been loaded, either because we * set the default theme name because of missing theme property in * xfconf channel or the value of xfconf channel property has been read * and set when setting up binding (between xfconf property and local property) * what caused a call to function to set theme name in this object * and also caused a reload of theme. * So if no theme object is set in this object then loading theme has * failed and we have to return FALSE. */ if(!priv->theme) return(FALSE); /* Register built-in views (order of registration is important) */ priv->viewManager=xfdashboard_view_manager_get_default(); xfdashboard_view_manager_register(priv->viewManager, XFDASHBOARD_TYPE_WINDOWS_VIEW); xfdashboard_view_manager_register(priv->viewManager, XFDASHBOARD_TYPE_APPLICATIONS_VIEW); xfdashboard_view_manager_register(priv->viewManager, XFDASHBOARD_TYPE_SEARCH_VIEW); /* Register built-in search providers */ priv->searchManager=xfdashboard_search_manager_get_default(); xfdashboard_search_manager_register(priv->searchManager, XFDASHBOARD_TYPE_APPLICATIONS_SEARCH_PROVIDER); /* Create single-instance of focus manager to keep it alive while * application is running. */ priv->focusManager=xfdashboard_focus_manager_get_default(); /* Create stage containing all monitors */ stage=xfdashboard_stage_new(); g_signal_connect_swapped(stage, "delete-event", G_CALLBACK(_xfdashboard_application_on_delete_stage), self); /* Emit signal 'theme-changed' to get current theme loaded at each stage created */ g_signal_emit(self, XfdashboardApplicationSignals[SIGNAL_THEME_CHANGED], 0, priv->theme); /* Set return results */ if(outStage) *outStage=XFDASHBOARD_STAGE(stage); /* Initialization was successful so return TRUE */ #ifdef DEBUG xfdashboard_notify(NULL, NULL, _("Welcome to %s (%s)!"), PACKAGE_NAME, PACKAGE_VERSION); #else xfdashboard_notify(NULL, NULL, _("Welcome to %s!"), PACKAGE_NAME); #endif return(TRUE); }
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; }