diff options
author | Bastien Nocera <hadess@hadess.net> | 2016-09-26 19:09:00 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2016-10-11 11:00:56 +0200 |
commit | 950251e7eb4264e4b8e6c31a972ff5232c4a0f9d (patch) | |
tree | a1cb2996810a1c54564a329caa8dff6c1536aa20 /gnome-settings-daemon | |
parent | 6d01a434ca2faa88acb2aed1224d23cea329f1f8 (diff) | |
download | gnome-settings-daemon-950251e7eb4264e4b8e6c31a972ff5232c4a0f9d.tar.gz |
main: Remove gnome-settings-daemon binary
https://bugzilla.gnome.org/show_bug.cgi?id=772370
Diffstat (limited to 'gnome-settings-daemon')
-rw-r--r-- | gnome-settings-daemon/Makefile.am | 33 | ||||
-rw-r--r-- | gnome-settings-daemon/gnome-settings-manager.c | 456 | ||||
-rw-r--r-- | gnome-settings-daemon/gnome-settings-manager.h | 68 | ||||
-rw-r--r-- | gnome-settings-daemon/main.c | 449 |
4 files changed, 1 insertions, 1005 deletions
diff --git a/gnome-settings-daemon/Makefile.am b/gnome-settings-daemon/Makefile.am index b6beb0f6..d1125d22 100644 --- a/gnome-settings-daemon/Makefile.am +++ b/gnome-settings-daemon/Makefile.am @@ -88,11 +88,6 @@ libgsd_la_LDFLAGS = \ -no-undefined \ $(NULL) -gsddir = $(libexecdir) - -gsd_PROGRAMS = \ - gnome-settings-daemon - EXTRA_DIST = \ org.gnome.SessionManager.xml \ org.gnome.ScreenSaver.xml \ @@ -103,33 +98,7 @@ apidir = $(includedir)/gnome-settings-daemon-$(GSD_API_VERSION)/gnome-settings api_DATA = \ gnome-settings-plugin.h -gnome_settings_daemon_SOURCES = \ - main.c \ - gnome-settings-manager.c \ - gnome-settings-manager.h \ - gnome-settings-plugin.c \ - gnome-settings-plugin.h \ - gnome-settings-plugin-info.c \ - gnome-settings-plugin-info.h \ - gnome-settings-module.c \ - gnome-settings-module.h \ - $(NULL) - -gnome_settings_daemon_CPPFLAGS = \ - $(AM_CPPFLAGS) - -gnome_settings_daemon_CFLAGS = \ - $(AM_CFLAGS) - -gnome_settings_daemon_LDFLAGS = \ - $(AM_LDFLAGS) - -gnome_settings_daemon_LDADD = \ - libgsd.la \ - $(SETTINGS_DAEMON_LIBS) \ - $(LIBNOTIFY_LIBS) \ - $(GNOME_DESKTOP_LIBS) \ - $(NULL) +EXTRA_DIST += $(api_DATA) CLEANFILES = $(gsd_SCRIPTS) diff --git a/gnome-settings-daemon/gnome-settings-manager.c b/gnome-settings-daemon/gnome-settings-manager.c deleted file mode 100644 index 05f568b3..00000000 --- a/gnome-settings-daemon/gnome-settings-manager.c +++ /dev/null @@ -1,456 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <string.h> - -#include <glib.h> -#include <glib/gi18n.h> -#include <glib-object.h> -#include <gio/gio.h> - -#define GNOME_DESKTOP_USE_UNSTABLE_API -#include <libgnome-desktop/gnome-pnp-ids.h> - -#include "gnome-settings-plugin.h" -#include "gnome-settings-plugin-info.h" -#include "gnome-settings-manager.h" -#include "gnome-settings-profile.h" - -#define DEFAULT_SETTINGS_PREFIX "org.gnome.settings-daemon" - -#define PLUGIN_EXT ".gnome-settings-plugin" - -#define GNOME_SETTINGS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNOME_TYPE_SETTINGS_MANAGER, GnomeSettingsManagerPrivate)) - -static const gchar introspection_xml[] = -"<node name='/org/gnome/SettingsDaemon'>" -" <interface name='org.gnome.SettingsDaemon'>" -" <annotation name='org.freedesktop.DBus.GLib.CSymbol' value='gnome_settings_manager'/>" -" <signal name='PluginActivated'>" -" <arg name='name' type='s'/>" -" </signal>" -" <signal name='PluginDeactivated'>" -" <arg name='name' type='s'/>" -" </signal>" -" </interface>" -"</node>"; - -struct GnomeSettingsManagerPrivate -{ - guint owner_id; - GDBusNodeInfo *introspection_data; - GDBusConnection *connection; - guint dbus_register_object_id; - GCancellable *cancellable; - - GSettings *settings; - char **whitelist; - GnomePnpIds *pnp_ids; - GSList *plugins; -}; - -static void gnome_settings_manager_class_init (GnomeSettingsManagerClass *klass); -static void gnome_settings_manager_init (GnomeSettingsManager *settings_manager); - -G_DEFINE_TYPE (GnomeSettingsManager, gnome_settings_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - -GQuark -gnome_settings_manager_error_quark (void) -{ - static GQuark ret = 0; - if (ret == 0) { - ret = g_quark_from_static_string ("gnome_settings_manager_error"); - } - - return ret; -} - -static void -activate_plugin (GnomeSettingsPluginInfo *info, gpointer user_data) -{ - gboolean res; - res = gnome_settings_plugin_info_activate (info); - if (res) { - g_debug ("Plugin %s: active", gnome_settings_plugin_info_get_location (info)); - } else { - g_debug ("Plugin %s: activation failed", gnome_settings_plugin_info_get_location (info)); - } -} - -static gint -compare_location (GnomeSettingsPluginInfo *a, - GnomeSettingsPluginInfo *b) -{ - const char *loc_a; - const char *loc_b; - - loc_a = gnome_settings_plugin_info_get_location (a); - loc_b = gnome_settings_plugin_info_get_location (b); - - if (loc_a == NULL || loc_b == NULL) { - return -1; - } - - return strcmp (loc_a, loc_b); -} - -static int -compare_priority (GnomeSettingsPluginInfo *a, - GnomeSettingsPluginInfo *b) -{ - int prio_a; - int prio_b; - - prio_a = gnome_settings_plugin_info_get_priority (a); - prio_b = gnome_settings_plugin_info_get_priority (b); - - return prio_a - prio_b; -} - -static void -emit_signal (GnomeSettingsManager *manager, - const char *signal, - const char *name) -{ - GError *error = NULL; - - /* FIXME: maybe we should queue those up until the D-Bus - * connection is available... */ - if (manager->priv->connection == NULL) - return; - - if (g_dbus_connection_emit_signal (manager->priv->connection, - NULL, - GSD_DBUS_PATH, - GSD_DBUS_NAME, - "PluginActivated", - g_variant_new ("(s)", name), - &error) == FALSE) { - g_debug ("Error emitting signal: %s", error->message); - g_error_free (error); - } - -} - -static void -on_plugin_activated (GnomeSettingsPluginInfo *info, - GnomeSettingsManager *manager) -{ - const char *name; - - name = gnome_settings_plugin_info_get_location (info); - g_debug ("GnomeSettingsManager: emitting plugin-activated %s", name); - emit_signal (manager, "PluginActivated", name); -} - -static void -on_plugin_deactivated (GnomeSettingsPluginInfo *info, - GnomeSettingsManager *manager) -{ - const char *name; - - name = gnome_settings_plugin_info_get_location (info); - g_debug ("GnomeSettingsManager: emitting plugin-deactivated %s", name); - emit_signal (manager, "PluginDeactivated", name); -} - -static gboolean -is_whitelisted (char **whitelist, - const char *plugin_name) -{ - if (whitelist == NULL || - whitelist[0] == NULL || - g_strcmp0 (whitelist[0], "all") == 0) - return TRUE; - - return g_strv_contains ((const gchar * const *)whitelist, plugin_name); -} - -static void -_load_file (GnomeSettingsManager *manager, - const char *filename) -{ - GnomeSettingsPluginInfo *info; - char *key_name; - GSList *l; - - g_debug ("Loading plugin: %s", filename); - gnome_settings_profile_start ("%s", filename); - - info = gnome_settings_plugin_info_new_from_file (filename); - if (info == NULL) { - goto out; - } - - l = g_slist_find_custom (manager->priv->plugins, - info, - (GCompareFunc) compare_location); - if (l != NULL) { - goto out; - } - - if (!is_whitelisted (manager->priv->whitelist, - gnome_settings_plugin_info_get_location (info))) { - g_debug ("Plugin %s ignored as it's not whitelisted", - gnome_settings_plugin_info_get_location (info)); - goto out; - } - - key_name = g_strdup_printf ("%s.plugins.%s", - DEFAULT_SETTINGS_PREFIX, - gnome_settings_plugin_info_get_location (info)); - - /* Ignore unknown schemas or else we'll assert */ - manager->priv->plugins = g_slist_prepend (manager->priv->plugins, - g_object_ref (info)); - - g_signal_connect (info, "activated", - G_CALLBACK (on_plugin_activated), manager); - g_signal_connect (info, "deactivated", - G_CALLBACK (on_plugin_deactivated), manager); - - /* Priority is set in the call above */ - g_free (key_name); - - out: - if (info != NULL) { - g_object_unref (info); - } - - gnome_settings_profile_end ("%s", filename); -} - -static void -_load_dir (GnomeSettingsManager *manager, - const char *path) -{ - GError *error; - GDir *d; - const char *name; - - g_debug ("Loading settings plugins from dir: %s", path); - gnome_settings_profile_start (NULL); - - error = NULL; - d = g_dir_open (path, 0, &error); - if (d == NULL) { - g_warning ("%s", error->message); - g_error_free (error); - return; - } - - while ((name = g_dir_read_name (d))) { - char *filename; - - if (!g_str_has_suffix (name, PLUGIN_EXT)) { - continue; - } - - filename = g_build_filename (path, name, NULL); - if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { - _load_file (manager, filename); - } - g_free (filename); - } - - g_dir_close (d); - - gnome_settings_profile_end (NULL); -} - -static void -_load_all (GnomeSettingsManager *manager) -{ - gnome_settings_profile_start (NULL); - - /* load system plugins */ - _load_dir (manager, GNOME_SETTINGS_PLUGINDIR G_DIR_SEPARATOR_S); - - manager->priv->plugins = g_slist_sort (manager->priv->plugins, (GCompareFunc) compare_priority); - g_slist_foreach (manager->priv->plugins, (GFunc) activate_plugin, NULL); - gnome_settings_profile_end (NULL); -} - -static void -_unload_plugin (GnomeSettingsPluginInfo *info, gpointer user_data) -{ - gnome_settings_plugin_info_deactivate (info); - g_object_unref (info); -} - -static void -_unload_all (GnomeSettingsManager *manager) -{ - g_slist_foreach (manager->priv->plugins, (GFunc) _unload_plugin, NULL); - g_slist_free (manager->priv->plugins); - manager->priv->plugins = NULL; -} - -static void -on_bus_gotten (GObject *source_object, - GAsyncResult *res, - GnomeSettingsManager *manager) -{ - GDBusConnection *connection; - GError *error = NULL; - - connection = g_bus_get_finish (res, &error); - if (connection == NULL) { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("Could not get session bus: %s", error->message); - g_error_free (error); - return; - } - manager->priv->connection = connection; - - manager->priv->dbus_register_object_id = g_dbus_connection_register_object (connection, - GSD_DBUS_PATH, - manager->priv->introspection_data->interfaces[0], - NULL, - NULL, - NULL, - NULL); - g_assert (manager->priv->dbus_register_object_id > 0); -} - -static void -register_manager (GnomeSettingsManager *manager) -{ - manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); - g_assert (manager->priv->introspection_data != NULL); - - manager->priv->cancellable = g_cancellable_new (); - - g_bus_get (G_BUS_TYPE_SESSION, - manager->priv->cancellable, - (GAsyncReadyCallback) on_bus_gotten, - manager); -} - -gboolean -gnome_settings_manager_start (GnomeSettingsManager *manager, - GError **error) -{ - gboolean ret; - - g_debug ("Starting settings manager"); - - ret = FALSE; - - gnome_settings_profile_start (NULL); - - if (!g_module_supported ()) { - g_warning ("gnome-settings-daemon is not able to initialize the plugins."); - g_set_error (error, - GNOME_SETTINGS_MANAGER_ERROR, - GNOME_SETTINGS_MANAGER_ERROR_GENERAL, - "Plugins not supported"); - - goto out; - } - - g_debug ("loading PNPIDs"); - manager->priv->pnp_ids = gnome_pnp_ids_new (); - - gnome_settings_profile_start ("initializing plugins"); - manager->priv->settings = g_settings_new (DEFAULT_SETTINGS_PREFIX ".plugins"); - manager->priv->whitelist = g_settings_get_strv (manager->priv->settings, "whitelisted-plugins"); - - _load_all (manager); - gnome_settings_profile_end ("initializing plugins"); - - ret = TRUE; - out: - gnome_settings_profile_end (NULL); - - return ret; -} - -static void -gnome_settings_manager_dispose (GObject *object) -{ - GnomeSettingsManager *manager; - - manager = GNOME_SETTINGS_MANAGER (object); - - g_debug ("Stopping settings manager"); - - _unload_all (manager); - - if (manager->priv->cancellable) { - g_cancellable_cancel (manager->priv->cancellable); - g_clear_object (&manager->priv->cancellable); - } - if (manager->priv->owner_id > 0) { - g_bus_unown_name (manager->priv->owner_id); - manager->priv->owner_id = 0; - } - if (manager->priv->dbus_register_object_id > 0) { - g_dbus_connection_unregister_object (manager->priv->connection, - manager->priv->dbus_register_object_id); - manager->priv->dbus_register_object_id = 0; - } - - g_clear_pointer (&manager->priv->whitelist, g_strfreev); - g_clear_object (&manager->priv->settings); - g_clear_object (&manager->priv->pnp_ids); - g_clear_object (&manager->priv->connection); - - G_OBJECT_CLASS (gnome_settings_manager_parent_class)->dispose (object); -} - -static void -gnome_settings_manager_class_init (GnomeSettingsManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->dispose = gnome_settings_manager_dispose; - - g_type_class_add_private (klass, sizeof (GnomeSettingsManagerPrivate)); -} - -static void -gnome_settings_manager_init (GnomeSettingsManager *manager) -{ - - manager->priv = GNOME_SETTINGS_MANAGER_GET_PRIVATE (manager); -} - -GnomeSettingsManager * -gnome_settings_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (GNOME_TYPE_SETTINGS_MANAGER, - NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - register_manager (manager_object); - } - - return GNOME_SETTINGS_MANAGER (manager_object); -} diff --git a/gnome-settings-daemon/gnome-settings-manager.h b/gnome-settings-daemon/gnome-settings-manager.h deleted file mode 100644 index d2f80225..00000000 --- a/gnome-settings-daemon/gnome-settings-manager.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef __GNOME_SETTINGS_MANAGER_H -#define __GNOME_SETTINGS_MANAGER_H - -#include <glib-object.h> - -G_BEGIN_DECLS - -#define GNOME_TYPE_SETTINGS_MANAGER (gnome_settings_manager_get_type ()) -#define GNOME_SETTINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GNOME_TYPE_SETTINGS_MANAGER, GnomeSettingsManager)) -#define GNOME_SETTINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GNOME_TYPE_SETTINGS_MANAGER, GnomeSettingsManagerClass)) -#define GNOME_IS_SETTINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNOME_TYPE_SETTINGS_MANAGER)) -#define GNOME_IS_SETTINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GNOME_TYPE_SETTINGS_MANAGER)) -#define GNOME_SETTINGS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GNOME_TYPE_SETTINGS_MANAGER, GnomeSettingsManagerClass)) - -typedef struct GnomeSettingsManagerPrivate GnomeSettingsManagerPrivate; - -typedef struct -{ - GObject parent; - GnomeSettingsManagerPrivate *priv; -} GnomeSettingsManager; - -typedef struct -{ - GObjectClass parent_class; - - void (* plugin_activated) (GnomeSettingsManager *manager, - const char *name); - void (* plugin_deactivated) (GnomeSettingsManager *manager, - const char *name); -} GnomeSettingsManagerClass; - -typedef enum -{ - GNOME_SETTINGS_MANAGER_ERROR_GENERAL -} GnomeSettingsManagerError; - -#define GNOME_SETTINGS_MANAGER_ERROR gnome_settings_manager_error_quark () - -GQuark gnome_settings_manager_error_quark (void); -GType gnome_settings_manager_get_type (void); - -GnomeSettingsManager * gnome_settings_manager_new (void); -gboolean gnome_settings_manager_start (GnomeSettingsManager *manager, - GError **error); - -G_END_DECLS - -#endif /* __GNOME_SETTINGS_MANAGER_H */ diff --git a/gnome-settings-daemon/main.c b/gnome-settings-daemon/main.c deleted file mode 100644 index 48d4bad4..00000000 --- a/gnome-settings-daemon/main.c +++ /dev/null @@ -1,449 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include <stdlib.h> -#include <unistd.h> -#include <libintl.h> -#include <errno.h> -#include <locale.h> -#include <signal.h> -#include <fcntl.h> -#include <sys/wait.h> - -#include <glib/gi18n.h> -#include <glib/gstdio.h> -#include <glib-unix.h> -#include <gtk/gtk.h> -#include <libnotify/notify.h> - -#include "gnome-settings-manager.h" -#include "gnome-settings-plugin.h" -#include "gnome-settings-profile.h" -#include "gnome-settings-bus.h" - -#define GNOME_SESSION_DBUS_NAME "org.gnome.SessionManager" -#define GNOME_SESSION_CLIENT_PRIVATE_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate" - -static gboolean replace = FALSE; -static gboolean debug = FALSE; -static gboolean do_timed_exit = FALSE; -static gboolean ignore_name_lost = FALSE; -static guint name_id = 0; -static GnomeSettingsManager *manager = NULL; - -static GOptionEntry entries[] = { - {"debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debugging code"), NULL }, - { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, N_("Replace existing daemon"), NULL }, - { "timed-exit", 0, 0, G_OPTION_ARG_NONE, &do_timed_exit, N_("Exit after a time (for debugging)"), NULL }, - {NULL} -}; - -static gboolean -timed_exit_cb (void) -{ - g_debug ("Doing timed exit"); - gtk_main_quit (); - return FALSE; -} - -static void -respond_to_end_session (GDBusProxy *proxy) -{ - /* we must answer with "EndSessionResponse" */ - g_dbus_proxy_call (proxy, "EndSessionResponse", - g_variant_new ("(bs)", - TRUE, ""), - G_DBUS_CALL_FLAGS_NONE, - -1, NULL, NULL, NULL); -} - -static void -do_stop (void) -{ - /* We don't want to quit yet because if we do, gnome-shell - * and still mapped windows lose their theme and icons. But - * we have to unown our DBus name otherwise gnome-session - * will hang waiting for us. - * - * This only works due to a bug in gnome-session where it - * handles any client name being unowned as if the client has - * disconnected. Will need to be revisited when that bug is - * fixed in gnome-session. */ - ignore_name_lost = TRUE; - g_bus_unown_name (name_id); - name_id = 0; -} - -static void -client_proxy_signal_cb (GDBusProxy *proxy, - gchar *sender_name, - gchar *signal_name, - GVariant *parameters, - gpointer user_data) -{ - if (g_strcmp0 (signal_name, "QueryEndSession") == 0) { - g_debug ("Got QueryEndSession signal"); - respond_to_end_session (proxy); - } else if (g_strcmp0 (signal_name, "EndSession") == 0) { - g_debug ("Got EndSession signal"); - respond_to_end_session (proxy); - } else if (g_strcmp0 (signal_name, "Stop") == 0) { - g_debug ("Got Stop signal"); - do_stop (); - } -} - -static void -got_client_proxy (GObject *object, - GAsyncResult *res, - gpointer user_data) -{ - GDBusProxy *client_proxy; - GError *error = NULL; - - client_proxy = g_dbus_proxy_new_for_bus_finish (res, &error); - - if (error != NULL) { - g_debug ("Unable to get the session client proxy: %s", error->message); - g_error_free (error); - return; - } - - g_signal_connect (client_proxy, "g-signal", - G_CALLBACK (client_proxy_signal_cb), manager); -} - -static void -start_settings_manager (void) -{ - gboolean res; - GError *error; - - gnome_settings_profile_start ("gnome_settings_manager_new"); - manager = gnome_settings_manager_new (); - gnome_settings_profile_end ("gnome_settings_manager_new"); - if (manager == NULL) { - g_warning ("Unable to register object"); - gtk_main_quit (); - } - - error = NULL; - res = gnome_settings_manager_start (manager, &error); - if (! res) { - g_warning ("Unable to start: %s", error->message); - g_error_free (error); - gtk_main_quit (); - } -} - -static void -on_client_registered (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - GVariant *variant; - GError *error = NULL; - gchar *object_path = NULL; - - variant = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); - if (error != NULL) { - g_warning ("Unable to register client: %s", error->message); - g_error_free (error); - } else { - g_variant_get (variant, "(o)", &object_path); - - g_debug ("Registered client at path %s", object_path); - - g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, 0, NULL, - GNOME_SESSION_DBUS_NAME, - object_path, - GNOME_SESSION_CLIENT_PRIVATE_DBUS_INTERFACE, - NULL, - got_client_proxy, - manager); - - g_free (object_path); - g_variant_unref (variant); - } -} - -static void -session_env_done (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - GVariant *result; - GError *error = NULL; - - result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); - if (result == NULL) { - g_debug ("Failed to set the environment: %s", error->message); - g_error_free (error); - return; - } - - g_variant_unref (result); -} - -static void -set_session_env (GDBusProxy *proxy, - const gchar *name, - const gchar *value) -{ - g_dbus_proxy_call (proxy, - "Setenv", - g_variant_new ("(ss)", name, value), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - (GAsyncReadyCallback) session_env_done, - NULL); -} - -static void -set_locale (GDBusProxy *proxy) -{ - GSettings *locale_settings; - gchar *region; - - /* Set locale environment */ - locale_settings = g_settings_new ("org.gnome.system.locale"); - region = g_settings_get_string (locale_settings, "region"); - if (region[0]) { - /* Only set the locale settings if the user has ever customized them */ - set_session_env (proxy, "LC_TIME", region); - set_session_env (proxy, "LC_NUMERIC", region); - set_session_env (proxy, "LC_MONETARY", region); - set_session_env (proxy, "LC_MEASUREMENT", region); - set_session_env (proxy, "LC_PAPER", region); - } - g_free (region); - - g_object_unref (locale_settings); -} - -static gboolean -is_program_in_path (const char *binary) -{ - char *path; - - path = g_find_program_in_path (binary); - if (path == NULL) - return FALSE; - g_free (path); - return TRUE; -} - -static void -set_legacy_ibus_env_vars (GDBusProxy *proxy) -{ - const char *p; - if (is_program_in_path ("ibus-daemon")) { - p = getenv ("QT_IM_MODULE"); - if (!p || !*p) - p = "ibus"; - set_session_env (proxy, "QT_IM_MODULE", p); - p = getenv ("XMODIFIERS"); - if (!p || !*p) - p = "@im=ibus"; - set_session_env (proxy, "XMODIFIERS", p); - } -} - -static void -register_with_gnome_session (GDBusProxy *proxy) -{ - const char *startup_id; - - startup_id = g_getenv ("DESKTOP_AUTOSTART_ID"); - g_dbus_proxy_call (proxy, - "RegisterClient", - g_variant_new ("(ss)", "gnome-settings-daemon", startup_id ? startup_id : ""), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - (GAsyncReadyCallback) on_client_registered, - manager); -} - -static gboolean -on_term_signal (gpointer user_data) -{ - g_debug ("Received SIGTERM - shutting down"); - /* Got SIGTERM, time to clean up and get out - */ - gtk_main_quit (); - - return FALSE; -} - -static void -name_acquired_handler (GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - GDBusProxy *proxy; - - proxy = G_DBUS_PROXY (gnome_settings_bus_get_session_proxy ()); - /* Always call this first, as Setenv can only be called before - any client registers */ - set_locale (proxy); - set_legacy_ibus_env_vars (proxy); - - start_settings_manager (); - register_with_gnome_session (proxy); - g_unix_signal_add (SIGTERM, on_term_signal, manager); -} - -static void -name_lost_handler (GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - if (ignore_name_lost) - return; - - /* Name was already taken, or the bus went away */ - - g_warning ("Name taken or bus went away - shutting down"); - - gtk_main_quit (); - -} - -static void -bus_register (void) -{ - GBusNameOwnerFlags flags; - - flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; - - if (replace) - flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; - - name_id = g_bus_own_name (G_BUS_TYPE_SESSION, - GSD_DBUS_NAME, - flags, - NULL, - (GBusNameAcquiredCallback) name_acquired_handler, - (GBusNameLostCallback) name_lost_handler, - NULL, - NULL); -} - -static void -gsd_log_default_handler (const gchar *log_domain, - GLogLevelFlags log_level, - const gchar *message, - gpointer unused_data) -{ - /* filter out DEBUG messages if debug isn't set */ - if ((log_level & G_LOG_LEVEL_MASK) == G_LOG_LEVEL_DEBUG - && ! debug) { - return; - } - - g_log_default_handler (log_domain, - log_level, - message, - unused_data); -} - -static void -parse_args (int *argc, char ***argv) -{ - GError *error; - GOptionContext *context; - - gnome_settings_profile_start (NULL); - - - context = g_option_context_new (NULL); - - g_option_context_add_main_entries (context, entries, NULL); - g_option_context_add_group (context, gtk_get_option_group (FALSE)); - - error = NULL; - if (!g_option_context_parse (context, argc, argv, &error)) { - if (error != NULL) { - g_warning ("%s", error->message); - g_error_free (error); - } else { - g_warning ("Unable to initialize GTK+"); - } - exit (EXIT_FAILURE); - } - - g_option_context_free (context); - - gnome_settings_profile_end (NULL); - - if (debug) - g_setenv ("G_MESSAGES_DEBUG", "all", FALSE); -} - -int -main (int argc, char *argv[]) -{ - gnome_settings_profile_start (NULL); - - bindtextdomain (GETTEXT_PACKAGE, GNOME_SETTINGS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - setlocale (LC_ALL, ""); - - parse_args (&argc, &argv); - - gdk_set_allowed_backends ("x11"); - - gnome_settings_profile_start ("opening gtk display"); - if (! gtk_init_check (NULL, NULL)) { - g_warning ("Unable to initialize GTK+"); - exit (EXIT_FAILURE); - } - gnome_settings_profile_end ("opening gtk display"); - - g_log_set_default_handler (gsd_log_default_handler, NULL); - - notify_init ("gnome-settings-daemon"); - - bus_register (); - - if (do_timed_exit) { - g_timeout_add_seconds (30, (GSourceFunc) timed_exit_cb, NULL); - } - - gtk_main (); - - g_debug ("Shutting down"); - - if (name_id > 0) { - g_bus_unown_name (name_id); - name_id = 0; - } - - g_clear_object (&manager); - - g_debug ("SettingsDaemon finished"); - gnome_settings_profile_end (NULL); - - return 0; -} |