From d2c7965aa092cecb857bd0301b7c9ff2dc10f9f8 Mon Sep 17 00:00:00 2001 From: Stefano Karapetsas Date: Mon, 1 Oct 2012 22:58:54 +0200 Subject: migrate to gsettings --- plugins/media-keys/acme.h | 43 +++-- .../cut-n-paste/gvc-gstreamer-acme-vol.c | 41 ++-- plugins/media-keys/msd-media-keys-manager.c | 206 +++++++-------------- 3 files changed, 115 insertions(+), 175 deletions(-) (limited to 'plugins/media-keys') diff --git a/plugins/media-keys/acme.h b/plugins/media-keys/acme.h index 41228e0..b911c13 100644 --- a/plugins/media-keys/acme.h +++ b/plugins/media-keys/acme.h @@ -23,8 +23,7 @@ #include "msd-keygrab.h" -#define MATECONF_BINDING_DIR "/apps/mate_settings_daemon/keybindings" -#define MATECONF_MISC_DIR "/apps/mate_settings_daemon" +#define BINDING_SCHEMA "org.mate.SettingsDaemon.plugins.media-keys" enum { TOUCHPAD_KEY, @@ -51,28 +50,28 @@ enum { static struct { int key_type; - const char *mateconf_key; + const char *settings_key; Key *key; } keys[HANDLED_KEYS] = { - { TOUCHPAD_KEY, MATECONF_BINDING_DIR "/touchpad", NULL }, - { MUTE_KEY, MATECONF_BINDING_DIR "/volume_mute",NULL }, - { VOLUME_DOWN_KEY, MATECONF_BINDING_DIR "/volume_down", NULL }, - { VOLUME_UP_KEY, MATECONF_BINDING_DIR "/volume_up", NULL }, - { POWER_KEY, MATECONF_BINDING_DIR "/power", NULL }, - { EJECT_KEY, MATECONF_BINDING_DIR "/eject", NULL }, - { HOME_KEY, MATECONF_BINDING_DIR "/home", NULL }, - { MEDIA_KEY, MATECONF_BINDING_DIR "/media", NULL }, - { CALCULATOR_KEY, MATECONF_BINDING_DIR "/calculator", NULL }, - { SEARCH_KEY, MATECONF_BINDING_DIR "/search", NULL }, - { EMAIL_KEY, MATECONF_BINDING_DIR "/email", NULL }, - { SCREENSAVER_KEY, MATECONF_BINDING_DIR "/screensaver", NULL }, - { HELP_KEY, MATECONF_BINDING_DIR "/help", NULL }, - { WWW_KEY, MATECONF_BINDING_DIR "/www", NULL }, - { PLAY_KEY, MATECONF_BINDING_DIR "/play", NULL }, - { PAUSE_KEY, MATECONF_BINDING_DIR "/pause", NULL }, - { STOP_KEY, MATECONF_BINDING_DIR "/stop", NULL }, - { PREVIOUS_KEY, MATECONF_BINDING_DIR "/previous", NULL }, - { NEXT_KEY, MATECONF_BINDING_DIR "/next", NULL }, + { TOUCHPAD_KEY, "touchpad", NULL }, + { MUTE_KEY, "volume-mute",NULL }, + { VOLUME_DOWN_KEY, "volume-down", NULL }, + { VOLUME_UP_KEY, "volume-up", NULL }, + { POWER_KEY, "power", NULL }, + { EJECT_KEY, "eject", NULL }, + { HOME_KEY, "home", NULL }, + { MEDIA_KEY, "media", NULL }, + { CALCULATOR_KEY, "calculator", NULL }, + { SEARCH_KEY, "search", NULL }, + { EMAIL_KEY, "email", NULL }, + { SCREENSAVER_KEY, "screensaver", NULL }, + { HELP_KEY, "help", NULL }, + { WWW_KEY, "www", NULL }, + { PLAY_KEY, "play", NULL }, + { PAUSE_KEY, "pause", NULL }, + { STOP_KEY, "stop", NULL }, + { PREVIOUS_KEY, "previous", NULL }, + { NEXT_KEY, "next", NULL }, }; #endif /* __ACME_H__ */ diff --git a/plugins/media-keys/cut-n-paste/gvc-gstreamer-acme-vol.c b/plugins/media-keys/cut-n-paste/gvc-gstreamer-acme-vol.c index d0ef380..3fc4d1f 100644 --- a/plugins/media-keys/cut-n-paste/gvc-gstreamer-acme-vol.c +++ b/plugins/media-keys/cut-n-paste/gvc-gstreamer-acme-vol.c @@ -34,14 +34,15 @@ #include #include -#include +#include #include #define TIMEOUT 4 -#define DEFAULT_MIXER_DEVICE_KEY "/desktop/mate/sound/default_mixer_device" -#define DEFAULT_MIXER_TRACKS_KEY "/desktop/mate/sound/default_mixer_tracks" +#define MATE_SOUND_SCHEMA "org.mate.sound" +#define DEFAULT_MIXER_DEVICE_KEY "default-mixer-device" +#define DEFAULT_MIXER_TRACKS_KEY "default-mixer-tracks" #define ACME_VOLUME_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ACME_TYPE_VOLUME, AcmeVolumePrivate)) @@ -51,7 +52,7 @@ struct AcmeVolumePrivate { guint timer_id; gdouble volume; gboolean mute; - MateConfClient *mateconf_client; + GSettings *settings; }; G_DEFINE_TYPE (AcmeVolume, acme_volume, G_TYPE_OBJECT) @@ -76,9 +77,9 @@ acme_volume_finalize (GObject *object) g_source_remove (self->_priv->timer_id); acme_volume_close_real (self); - if (self->_priv->mateconf_client != NULL) { - g_object_unref (self->_priv->mateconf_client); - self->_priv->mateconf_client = NULL; + if (self->_priv->settings != NULL) { + g_object_unref (self->_priv->settings); + self->_priv->settings = NULL; } G_OBJECT_CLASS (acme_volume_parent_class)->finalize (object); @@ -266,7 +267,7 @@ acme_volume_open (AcmeVolume *self) return TRUE; } - mixer_device = mateconf_client_get_string (self->_priv->mateconf_client, DEFAULT_MIXER_DEVICE_KEY, NULL); + mixer_device = g_settings_get_string (self->_priv->settings, DEFAULT_MIXER_DEVICE_KEY); if (mixer_device != NULL) factory_and_device = g_strsplit (mixer_device, ":", 2); @@ -296,19 +297,21 @@ acme_volume_open (AcmeVolume *self) if (self->_priv->mixer != NULL) { const GList *m; GSList *tracks, *t; - GError *error = NULL; - /* Try to use tracks saved in MateConf + /* Try to use tracks saved in GSettings Note: errors need to be treated , for example if the user set a non type list for this key or if the elements type_list are not "matched" */ - tracks = mateconf_client_get_list (self->_priv->mateconf_client, DEFAULT_MIXER_TRACKS_KEY, - MATECONF_VALUE_STRING, &error); - - if (error) { - g_warning("ERROR: %s\n", error->message); - g_error_free(error); + gchar **settings_list; + settings_list = g_settings_get_strv (self->_priv->settings, DEFAULT_MIXER_TRACKS_KEY); + if (settings_list != NULL) { + gint i; + for (i = 0; i < G_N_ELEMENTS (settings_list); i++) { + if (settings_list[i] != NULL) + tracks = g_slist_append (tracks, g_strdup (settings_list[i])); + } + g_strfreev (settings_list); } - + /* We use these tracks ONLY if they are supported on the system with the following mixer */ for (m = gst_mixer_list_tracks (self->_priv->mixer); m != NULL; m = m->next) { GstMixerTrack *track = GST_MIXER_TRACK (m->data); @@ -322,7 +325,7 @@ acme_volume_open (AcmeVolume *self) g_slist_foreach (tracks, (GFunc)g_free, NULL); g_slist_free (tracks); - /* If no track stored in MateConf is avaiable try to use Master track */ + /* If no track stored in GSettings is avaiable try to use Master track */ if (self->_priv->mixer_tracks == NULL) { for (m = gst_mixer_list_tracks (self->_priv->mixer); m != NULL; m = m->next) { GstMixerTrack *track = GST_MIXER_TRACK (m->data); @@ -374,7 +377,7 @@ static void acme_volume_init (AcmeVolume *self) { self->_priv = ACME_VOLUME_GET_PRIVATE (self); - self->_priv->mateconf_client = mateconf_client_get_default (); + self->_priv->settings = g_settings_new (MATE_SOUND_SCHEMA); } static void diff --git a/plugins/media-keys/msd-media-keys-manager.c b/plugins/media-keys/msd-media-keys-manager.c index d75c031..7ee48dc 100644 --- a/plugins/media-keys/msd-media-keys-manager.c +++ b/plugins/media-keys/msd-media-keys-manager.c @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include @@ -62,7 +62,8 @@ #define MSD_MEDIA_KEYS_DBUS_PATH MSD_DBUS_PATH "/MediaKeys" #define MSD_MEDIA_KEYS_DBUS_NAME MSD_DBUS_NAME ".MediaKeys" -#define TOUCHPAD_ENABLED_KEY "/desktop/mate/peripherals/touchpad/touchpad_enabled" +#define TOUCHPAD_SCHEMA "org.mate.peripherals-touchpad" +#define TOUCHPAD_ENABLED_KEY "touchpad-enabled" #define VOLUME_STEP 6 /* percents for one volume button press */ #define MAX_VOLUME 65536.0 @@ -84,7 +85,7 @@ struct MsdMediaKeysManagerPrivate AcmeVolume *volume; #endif /* HAVE_PULSE */ GtkWidget *dialog; - MateConfClient *conf_client; + GSettings *settings; GVolumeMonitor *volume_monitor; /* Multihead stuff */ @@ -159,12 +160,13 @@ get_term_command (MsdMediaKeysManager *manager) char *cmd_term; char *cmd = NULL; - cmd_term = mateconf_client_get_string (manager->priv->conf_client, - "/desktop/mate/applications/terminal/exec", NULL); + GSettings *settings_terminal; + settings_terminal = g_settings_new ("org.mate.applications-terminal"); + + cmd_term = g_settings_get_string (settings_terminal, "exec"); if ((cmd_term != NULL) && (strcmp (cmd_term, "") != 0)) { char *cmd_args; - cmd_args = mateconf_client_get_string (manager->priv->conf_client, - "/desktop/mate/applications/terminal/exec_arg", NULL); + cmd_args = g_settings_get_string (settings_terminal, "exec_arg"); if ((cmd_args != NULL) && (strcmp (cmd_term, "") != 0)) { cmd = g_strdup_printf ("%s %s -e", cmd_term, cmd_args); } else { @@ -176,6 +178,8 @@ get_term_command (MsdMediaKeysManager *manager) g_free (cmd_term); + g_object_unref (settings_terminal); + return cmd; } @@ -274,21 +278,20 @@ is_valid_shortcut (const char *string) } static void -update_kbd_cb (MateConfClient *client, - guint id, - MateConfEntry *entry, +update_kbd_cb (GSettings *settings, + gchar *settings_key, MsdMediaKeysManager *manager) { int i; gboolean need_flush = TRUE; - g_return_if_fail (entry->key != NULL); + g_return_if_fail (settings_key != NULL); gdk_error_trap_push (); /* Find the key that was modified */ for (i = 0; i < HANDLED_KEYS; i++) { - if (strcmp (entry->key, keys[i].mateconf_key) == 0) { + if (g_strcmp0 (settings_key, keys[i].settings_key) == 0) { char *tmp; Key *key; @@ -300,8 +303,8 @@ update_kbd_cb (MateConfClient *client, g_free (keys[i].key); keys[i].key = NULL; - tmp = mateconf_client_get_string (manager->priv->conf_client, - keys[i].mateconf_key, NULL); + tmp = g_settings_get_string (settings, + keys[i].settings_key); if (is_valid_shortcut (tmp) == FALSE) { g_free (tmp); @@ -345,16 +348,16 @@ static void init_kbd(MsdMediaKeysManager* manager) char* tmp; Key* key; - manager->priv->notify[i] = mateconf_client_notify_add(manager->priv->conf_client, - keys[i].mateconf_key, - (MateConfClientNotifyFunc) update_kbd_cb, - manager, - NULL, - NULL); + gchar* signal_name; + signal_name = g_strdup_printf ("changed::%s", keys[i].settings_key); + g_signal_connect (manager->priv->settings, + signal_name, + G_CALLBACK (update_kbd_cb), + manager); + g_free (signal_name); - tmp = mateconf_client_get_string(manager->priv->conf_client, - keys[i].mateconf_key, - NULL); + tmp = g_settings_get_string (manager->priv->settings, + keys[i].settings_key); if (!is_valid_shortcut(tmp)) { @@ -463,115 +466,67 @@ dialog_show (MsdMediaKeysManager *manager) } static void -do_unknown_action (MsdMediaKeysManager *manager, - const char *url) +do_uri_action (MsdMediaKeysManager *manager, gchar *uri) { - char *string; - - g_return_if_fail (url != NULL); + GError *error = NULL; + GAppInfo *app_info; - string = mateconf_client_get_string (manager->priv->conf_client, - "/desktop/mate/url-handlers/unknown/command", - NULL); + app_info = g_app_info_get_default_for_uri_scheme (uri); - if ((string != NULL) && (strcmp (string, "") != 0)) { - char *cmd; - cmd = g_strdup_printf (string, url); - execute (manager, cmd, FALSE, FALSE); - g_free (cmd); + if (app_info != NULL) { + if (!g_app_info_launch (app_info, NULL, NULL, &error)) { + g_warning ("Could not launch '%s': %s", + g_app_info_get_commandline (app_info), + error->message); + g_error_free (error); + } + } + else { + g_warning ("Could not find default application for '%s' scheme", uri); } - g_free (string); } static void do_help_action (MsdMediaKeysManager *manager) { - char *string; - - string = mateconf_client_get_string (manager->priv->conf_client, - "/desktop/mate/url-handlers/ghelp/command", - NULL); - - if ((string != NULL) && (strcmp (string, "") != 0)) { - char *cmd; - cmd = g_strdup_printf (string, ""); - execute (manager, cmd, FALSE, FALSE); - g_free (cmd); - } else { - do_unknown_action (manager, "ghelp:"); + GError *error = NULL; + if (!g_app_info_launch_default_for_uri ("http://wiki.mate-desktop.org/docs", NULL, &error)) { + g_warning ("Could not launch help application: %s", error->message); + g_error_free (error); } - - g_free (string); } static void do_mail_action (MsdMediaKeysManager *manager) { - char *string; - - string = mateconf_client_get_string (manager->priv->conf_client, - "/desktop/mate/url-handlers/mailto/command", - NULL); - - if ((string != NULL) && (strcmp (string, "") != 0)) { - char *cmd; - cmd = g_strdup_printf (string, ""); - execute (manager, - cmd, - FALSE, - mateconf_client_get_bool (manager->priv->conf_client, - "/desktop/mate/url-handlers/mailto/needs_terminal", NULL)); - g_free (cmd); - } - g_free (string); + do_uri_action (manager, "mailto"); } static void do_media_action (MsdMediaKeysManager *manager) { - char *command; - - command = mateconf_client_get_string (manager->priv->conf_client, - "/desktop/mate/applications/media/exec", NULL); - if ((command != NULL) && (strcmp (command, "") != 0)) { - execute (manager, - command, - FALSE, - mateconf_client_get_bool (manager->priv->conf_client, - "/desktop/mate/applications/media/needs_term", NULL)); + GError *error = NULL; + GAppInfo *app_info; + + app_info = g_app_info_get_default_for_type ("audio/x-vorbis+ogg", FALSE); + + if (app_info != NULL) { + if (!g_app_info_launch (app_info, NULL, NULL, &error)) { + g_warning ("Could not launch '%s': %s", + g_app_info_get_commandline (app_info), + error->message); + g_error_free (error); + } + } + else { + g_warning ("Could not find default application for '%s' mime-type", "audio/x-vorbis+ogg"); } - g_free (command); } static void -do_www_action (MsdMediaKeysManager *manager, - const char *url) +do_www_action (MsdMediaKeysManager *manager) { - char *string; - - string = mateconf_client_get_string (manager->priv->conf_client, - "/desktop/mate/url-handlers/http/command", - NULL); - - if ((string != NULL) && (strcmp (string, "") != 0)) { - gchar *cmd; - - if (url == NULL) { - cmd = g_strdup_printf (string, ""); - } else { - cmd = g_strdup_printf (string, url); - } - - execute (manager, - cmd, - FALSE, - mateconf_client_get_bool (manager->priv->conf_client, - "/desktop/mate/url-handlers/http/needs_terminal", NULL)); - g_free (cmd); - } else { - do_unknown_action (manager, url ? url : ""); - } - g_free (string); + do_uri_action (manager, "http"); } static void @@ -649,8 +604,8 @@ do_eject_action (MsdMediaKeysManager *manager) static void do_touchpad_action (MsdMediaKeysManager *manager) { - MateConfClient *client = manager->priv->conf_client; - gboolean state = mateconf_client_get_bool (client, TOUCHPAD_ENABLED_KEY, NULL); + GSettings *settings = g_settings_new (TOUCHPAD_SCHEMA); + gboolean state = g_settings_get_boolean (settings, TOUCHPAD_ENABLED_KEY); dialog_init (manager); msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), @@ -658,7 +613,8 @@ do_touchpad_action (MsdMediaKeysManager *manager) FALSE); dialog_show (manager); - mateconf_client_set_bool (client, TOUCHPAD_ENABLED_KEY, !state, NULL); + g_settings_set_boolean (settings, TOUCHPAD_ENABLED_KEY, !state); + g_object_unref (settings); } #ifdef HAVE_PULSE @@ -706,9 +662,7 @@ do_sound_action (MsdMediaKeysManager *manager, return; #endif - vol_step = mateconf_client_get_int (manager->priv->conf_client, - MATECONF_MISC_DIR "/volume_step", - NULL); + vol_step = g_settings_get_int (manager->priv->settings, "volume-step"); if (vol_step <= 0 || vol_step > 100) vol_step = VOLUME_STEP; @@ -1044,7 +998,7 @@ do_action (MsdMediaKeysManager *manager, do_help_action (manager); break; case WWW_KEY: - do_www_action (manager, NULL); + do_www_action (manager); break; case MEDIA_KEY: do_media_action (manager); @@ -1152,12 +1106,7 @@ start_media_keys_idle_cb (MsdMediaKeysManager *manager) g_debug ("Starting media_keys manager"); mate_settings_profile_start (NULL); manager->priv->volume_monitor = g_volume_monitor_get (); - manager->priv->conf_client = mateconf_client_get_default (); - - mateconf_client_add_dir (manager->priv->conf_client, - MATECONF_BINDING_DIR, - MATECONF_CLIENT_PRELOAD_ONELEVEL, - NULL); + manager->priv->settings = g_settings_new (BINDING_SCHEMA); init_screens (manager); init_kbd (manager); @@ -1242,20 +1191,9 @@ msd_media_keys_manager_stop (MsdMediaKeysManager *manager) manager); } - if (priv->conf_client) { - mateconf_client_remove_dir (priv->conf_client, - MATECONF_BINDING_DIR, - NULL); - - for (i = 0; i < HANDLED_KEYS; ++i) { - if (priv->notify[i] != 0) { - mateconf_client_notify_remove (priv->conf_client, priv->notify[i]); - priv->notify[i] = 0; - } - } - - g_object_unref (priv->conf_client); - priv->conf_client = NULL; + if (priv->settings) { + g_object_unref (priv->settings); + priv->settings = NULL; } if (priv->volume_monitor != NULL) { -- cgit v1.2.1