[gnome-applets/wip/gnome-3.10+: 20/29] mixer: port to GSettings



commit 77f745dad6e328cab2b7d58c32c2c9703097b43f
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Thu Jul 10 00:08:06 2014 +0300

    mixer: port to GSettings

 mixer/Makefile.am                                  |   20 ++++-
 mixer/applet.c                                     |   93 ++++++++------------
 mixer/applet.h                                     |    7 +-
 mixer/dock.c                                       |    2 -
 mixer/keys.h                                       |   35 --------
 mixer/mixer.schemas.in                             |   36 --------
 ...org.gnome.gnome-applets.mixer.gschema.xml.in.in |   10 ++
 mixer/preferences.c                                |   37 +++-----
 mixer/preferences.h                                |    3 +-
 po/POTFILES.in                                     |    1 +
 po/POTFILES.skip                                   |    1 +
 11 files changed, 83 insertions(+), 162 deletions(-)
---
diff --git a/mixer/Makefile.am b/mixer/Makefile.am
index b6e9baa..252806a 100644
--- a/mixer/Makefile.am
+++ b/mixer/Makefile.am
@@ -17,7 +17,6 @@ mixer_applet2_SOURCES = \
 noinst_HEADERS = \
        applet.h \
        dock.h \
-       keys.h \
        preferences.h
 
 mixer_applet2_LDADD =                                  \
@@ -48,13 +47,30 @@ org.gnome.panel.applet.MixerAppletFactory.service: $(service_in_files)
 uidir   = $(pkgdatadir)/ui
 ui_DATA = mixer-applet-menu.xml
 
+gsettings_schemas_in_in = \
+       org.gnome.gnome-applets.mixer.gschema.xml.in.in
+
+ INTLTOOL_XML_NOMERGE_RULE@
+
+gsettings_schemas_in = $(gsettings_schemas_in_in:.xml.in.in=.xml.in)
+gsettings_SCHEMAS = $(gsettings_schemas_in:.xml.in=.xml)
+
+%.gschema.xml.in: %.gschema.xml.in.in Makefile
+       $(AM_V_GEN) $(SED) -e 's^\ GETTEXT_PACKAGE\@^$(GETTEXT_PACKAGE)^g' < $< > $@
+
+ GSETTINGS_RULES@
+
 EXTRA_DIST =                                                   \
+       $(gsettings_schemas_in_in) \
        org.gnome.applets.MixerApplet.panel-applet.in.in        \
        $(service_in_files)                                     \
        $(ui_DATA)
 
 CLEANFILES = $(applet_DATA) \
        $(applet_DATA).in \
-       $(service_DATA)
+       $(service_DATA) \
+       $(gsettings_SCHEMAS_in) \
+       $(gsettings_SCHEMAS) \
+       *.gschema.valid
 
 -include $(top_srcdir)/git.mk
diff --git a/mixer/applet.c b/mixer/applet.c
index 057f289..ffe9fb5 100644
--- a/mixer/applet.c
+++ b/mixer/applet.c
@@ -34,14 +34,11 @@
 
 #include <gtk/gtk.h>
 
-#include <gconf/gconf-client.h>
-
 #include "applet.h"
-#include "keys.h"
 #include "preferences.h"
 
-#define IS_PANEL_HORIZONTAL(o) \
-  (o == PANEL_APPLET_ORIENT_UP || o == PANEL_APPLET_ORIENT_DOWN)
+#define IS_STRING_EMPTY(s)     ((s) == NULL || (s)[0] == '\0')
+#define IS_PANEL_HORIZONTAL(o) (o == PANEL_APPLET_ORIENT_UP || o == PANEL_APPLET_ORIENT_DOWN)
 
 /* This is defined is load.c, we're doing this instead of creating a load.h file
  * because nothing else is exported. */
@@ -83,10 +80,9 @@ static gboolean      cb_check                        (gpointer   data);
 static void    cb_volume                       (GtkAdjustment *adj,
                                                 gpointer   data);
 
-static void    cb_gconf                        (GConfClient     *client,
-                                                guint            connection_id,
-                                                GConfEntry      *entry,
-                                                gpointer         data);
+static void    cb_gsettings                    (GSettings   *settings,
+                                                const gchar *key,
+                                                gpointer     user_data);
 
 static void    cb_verb                         (GSimpleAction *action,
                                                  GVariant      *parameter,
@@ -167,7 +163,7 @@ gnome_volume_applet_init (GnomeVolumeApplet *applet)
 
   applet->timeout = 0;
   applet->elements = NULL;
-  applet->client = gconf_client_get_default ();
+  applet->settings = NULL;
   applet->mixer = NULL;
   applet->tracks = NULL;
   applet->lock = FALSE;
@@ -206,9 +202,6 @@ gnome_volume_applet_init (GnomeVolumeApplet *applet)
                    applet);
 
   /* other stuff */
-  panel_applet_add_preferences (PANEL_APPLET (applet),
-                               "/schemas/apps/mixer_applet/prefs",
-                               NULL);
   panel_applet_set_flags (PANEL_APPLET (applet),
                          PANEL_APPLET_EXPAND_MINOR);
 
@@ -224,7 +217,7 @@ gnome_volume_applet_init (GnomeVolumeApplet *applet)
 
 }
 
-/* Parse the list of tracks that are stored in GConf */
+/* Parse the list of tracks that are stored in GSettings */
 
 static char **
 parse_track_list (const char *track_list)
@@ -256,7 +249,7 @@ select_tracks (GstElement *element,
   }
 
   tracks = gst_mixer_list_tracks (GST_MIXER (element));
-  if (active_track_names)
+  if (!IS_STRING_EMPTY (active_track_names))
     active_track_name_list = parse_track_list (active_track_names);
 
   for (l = tracks; l; l = l->next) {
@@ -310,7 +303,7 @@ select_element_and_track (GnomeVolumeApplet *applet,
   active_element = NULL;
   active_tracks = NULL;
 
-  if (active_element_name) {
+  if (!IS_STRING_EMPTY (active_element_name)) {
     for (l = elements; l; l = l->next) {
       GstElement *element = l->data;
       const char *element_name;
@@ -393,20 +386,17 @@ gnome_volume_applet_setup (GnomeVolumeApplet *applet,
     { "about",       cb_verb,     NULL, NULL,    NULL }
   };
 
-  gchar *key;
   gchar *active_element_name;
   gchar *active_track_name;
   gchar *ui_path;
   GstMixerTrack *first_track;
   gboolean res;
 
-  active_element_name = panel_applet_gconf_get_string (PANEL_APPLET (applet),
-                                                      GNOME_VOLUME_APPLET_KEY_ACTIVE_ELEMENT,
-                                                      NULL);
+  applet->settings = panel_applet_settings_new (PANEL_APPLET (applet),
+                                                "org.gnome.gnome-applets.mixer");
 
-  active_track_name = panel_applet_gconf_get_string (PANEL_APPLET (applet),
-                                                    GNOME_VOLUME_APPLET_KEY_ACTIVE_TRACK,
-                                                    NULL);
+  active_element_name = g_settings_get_string (applet->settings, "active-element");
+  active_track_name = g_settings_get_string (applet->settings, "active-tracks");
 
   res = select_element_and_track (applet, elements, active_element_name,
                                  active_track_name);
@@ -451,17 +441,11 @@ gnome_volume_applet_setup (GnomeVolumeApplet *applet,
   if (res) {
     gnome_volume_applet_setup_timeout (applet);
 
-    /* gconf */
-    key = panel_applet_gconf_get_full_key (PANEL_APPLET (applet),
-                               GNOME_VOLUME_APPLET_KEY_ACTIVE_ELEMENT);
-    gconf_client_notify_add (applet->client, key,
-                            cb_gconf, applet, NULL, NULL);
-    g_free (key);
-    key = panel_applet_gconf_get_full_key (PANEL_APPLET (applet),
-                               GNOME_VOLUME_APPLET_KEY_ACTIVE_TRACK);
-    gconf_client_notify_add (applet->client, key,
-                            cb_gconf, applet, NULL, NULL);
-    g_free (key);
+    /* GSettings */
+    g_signal_connect (applet->settings, "changed::active-element",
+                      G_CALLBACK (cb_gsettings), applet);
+    g_signal_connect (applet->settings, "changed::active-tracks",
+                      G_CALLBACK (cb_gsettings), applet);
   }
 
   gtk_widget_show (GTK_WIDGET (applet));
@@ -482,6 +466,11 @@ gnome_volume_applet_dispose (GObject *object)
     applet->action_group = NULL;
   }
 
+  if (applet->settings) {
+    g_object_unref (applet->settings);
+    applet->settings = NULL;
+  }
+
   if (applet->elements) {
     GList *item;
 
@@ -1270,41 +1259,29 @@ cb_check (gpointer data)
 }
 
 /*
- * GConf callback.
+ * GSettings callback.
  */
 
 static void
-cb_gconf (GConfClient *client,
-         guint        connection_id,
-         GConfEntry  *entry,
-         gpointer     data)
+cb_gsettings (GSettings   *settings,
+              const gchar *key,
+              gpointer     user_data)
 {
-  GnomeVolumeApplet *applet = data;
-  GConfValue *value;
-  const gchar *str, *key;
+  GnomeVolumeApplet *applet = (GnomeVolumeApplet *) user_data;
+  gchar *str;
   const GList *item;
   gboolean newdevice = FALSE;
-  gchar *keyroot;
   GList *active_tracks;
 
   active_tracks = NULL;
 
-  keyroot = panel_applet_gconf_get_full_key (PANEL_APPLET (applet), "");
-  key = gconf_entry_get_key (entry);
-  if (strncmp (key, keyroot, strlen (keyroot))) {
-    g_free (keyroot);
-    return;
-  }
-  key += strlen (keyroot);
-  g_free (keyroot);
-
   g_list_free(applet->elements);
   applet->elements = gnome_volume_applet_create_mixer_collection ();
 
-  if ((value = gconf_entry_get_value (entry)) != NULL &&
-      (value->type == GCONF_VALUE_STRING) &&
-      (str = gconf_value_get_string (value)) != NULL) {
-    if (!strcmp (key, GNOME_VOLUME_APPLET_KEY_ACTIVE_ELEMENT)) {
+  str = g_settings_get_string (settings, key);
+
+  if (!IS_STRING_EMPTY (str)) {
+    if (!strcmp (key, "active-element")) {
       for (item = applet->elements; item != NULL; item = item->next) {
         gchar *cur_el_str = g_object_get_data (item->data,
                                               "gnome-volume-applet-name");
@@ -1330,7 +1307,7 @@ cb_gconf (GConfClient *client,
       }
     }
 
-    if (!strcmp (key, GNOME_VOLUME_APPLET_KEY_ACTIVE_TRACK) || newdevice) {
+    if (!strcmp (key, "active-tracks") || newdevice) {
       if (!active_tracks) {
         active_tracks = select_tracks (GST_ELEMENT (applet->mixer), str, FALSE);
       }
@@ -1360,6 +1337,8 @@ cb_gconf (GConfClient *client,
       }
     }
   }
+
+  g_free (str);
 }
 
 /*
diff --git a/mixer/applet.h b/mixer/applet.h
index 110dadd..c7cda6b 100644
--- a/mixer/applet.h
+++ b/mixer/applet.h
@@ -27,8 +27,7 @@
 #include <glib/gi18n.h>
 
 #include <gtk/gtk.h>
-#include <gconf/gconf-client.h>
-#include <panel-applet-gconf.h>
+#include <panel-applet.h>
 #include <gst/gst.h>
 #include <gst/interfaces/mixer.h>
 
@@ -67,8 +66,8 @@ struct _GnomeVolumeApplet {
   /* list of volume control elements */
   GList *elements;
 
-  /* gconf */
-  GConfClient *client;
+  /* GSettings */
+  GSettings *settings;
 
   /* element */
   GstMixer *mixer;
diff --git a/mixer/dock.c b/mixer/dock.c
index a9fc33c..520e3cf 100644
--- a/mixer/dock.c
+++ b/mixer/dock.c
@@ -235,8 +235,6 @@ gnome_volume_applet_dock_new (GtkOrientation orientation,
   g_signal_connect (more, "clicked", G_CALLBACK (launch_mixer_cb), dock);
   gtk_box_pack_end (GTK_BOX (innerline), more, TRUE, TRUE, 0);
 
-  gtk_container_add (GTK_CONTAINER (dock), frame);
-
   return GTK_WIDGET (dock);
 }
 
diff --git a/mixer/org.gnome.gnome-applets.mixer.gschema.xml.in.in 
b/mixer/org.gnome.gnome-applets.mixer.gschema.xml.in.in
new file mode 100644
index 0000000..2d25dcc
--- /dev/null
+++ b/mixer/org.gnome.gnome-applets.mixer.gschema.xml.in.in
@@ -0,0 +1,10 @@
+<schemalist gettext-domain="@GETTEXT_PACKAGE@">
+       <schema id="org.gnome.gnome-applets.mixer">
+               <key name="active-element" type="s">
+                       <default>''</default>
+               </key>
+               <key name="active-tracks" type="s">
+                       <default>''</default>
+               </key>
+       </schema>
+</schemalist>
diff --git a/mixer/preferences.c b/mixer/preferences.c
index fb717e2..03ce947 100644
--- a/mixer/preferences.c
+++ b/mixer/preferences.c
@@ -34,7 +34,6 @@
 
 #include "applet.h"
 #include "preferences.h"
-#include "keys.h"
 
 enum {
   COL_LABEL,
@@ -313,24 +312,19 @@ cb_dev_selected (GtkComboBox *box,
                 gpointer    data)
 {
   GnomeVolumeAppletPreferences *prefs = data;
-  /* GnomeVolumeApplet *applet = (GnomeVolumeApplet *) prefs->applet; */
+  GnomeVolumeApplet *applet = (GnomeVolumeApplet *) prefs->applet;
   GtkTreeIter iter;
 
   if (gtk_combo_box_get_active_iter (box, &iter)) {
     gchar *label;
-    GConfValue *value;
 
     gtk_tree_model_get (gtk_combo_box_get_model (box),
                        &iter, COL_LABEL, &label, -1);
 
-    /* write to gconf */
-    value = gconf_value_new (GCONF_VALUE_STRING);
-    gconf_value_set_string (value, label);
-    panel_applet_gconf_set_value (PANEL_APPLET (prefs->applet),
-                     GNOME_VOLUME_APPLET_KEY_ACTIVE_ELEMENT,
-                     value, NULL);
+    /* write to GSettings */
+    g_settings_set_string (applet->settings, "active-element", label);
+
     g_free (label);
-    gconf_value_free (value);
   }
 }
 
@@ -366,9 +360,8 @@ cb_track_select (GtkTreeSelection *selection,
   GnomeVolumeAppletPreferences *prefs = data;
   GtkTreeIter iter;
   gchar *label;
-  GConfValue *value;
   GtkTreeSelection *sel;
-  GString *gconf_string;
+  GString *track_string;
   GstMixerTrack *selected_track; /* the track just selected */
   GnomeVolumeApplet *applet = (GnomeVolumeApplet*) prefs->applet; /* required to update the track settings */
   int volume_percent;
@@ -376,7 +369,7 @@ cb_track_select (GtkTreeSelection *selection,
   if (prefs->track_lock)
     return TRUE;
 
-  gconf_string = g_string_new ("");
+  track_string = g_string_new ("");
 
   /* get value */
   gtk_tree_model_get_iter (model, &iter, path);
@@ -408,9 +401,9 @@ cb_track_select (GtkTreeSelection *selection,
        applet->tracks = g_list_append (applet->tracks, curr);
 
        if (!path_selected) {
-         g_string_append_printf (gconf_string, "%s:", curr->label);
+         g_string_append_printf (track_string, "%s:", curr->label);
        } else {
-         gconf_string = g_string_append (gconf_string, curr->label);
+         track_string = g_string_append (track_string, curr->label);
        }
       }
     }
@@ -425,7 +418,7 @@ cb_track_select (GtkTreeSelection *selection,
 
     gtk_tree_model_get_iter (model, &iter, path);
     gtk_tree_model_get (model, &iter, COL_TRACK, &curr, -1);
-    gconf_string = g_string_append (gconf_string, curr->label);
+    track_string = g_string_append (track_string, curr->label);
 
     applet->tracks = g_list_append (applet->tracks, curr);
 
@@ -435,15 +428,11 @@ cb_track_select (GtkTreeSelection *selection,
     }
   }
 
-  /* write to gconf */
-  value = gconf_value_new (GCONF_VALUE_STRING);
-  gconf_value_set_string (value, gconf_string->str);
-  panel_applet_gconf_set_value (PANEL_APPLET (prefs->applet),
-                               GNOME_VOLUME_APPLET_KEY_ACTIVE_TRACK,
-                               value, NULL);
+  /* write to GSettings */
+  g_settings_set_string (applet->settings, "active-tracks", track_string->str);
+
   g_free (label);
-  g_string_free (gconf_string, TRUE);
-  gconf_value_free (value);
+  g_string_free (track_string, TRUE);
   
   return TRUE;
 }
diff --git a/mixer/preferences.h b/mixer/preferences.h
index f4faadb..c82af2c 100644
--- a/mixer/preferences.h
+++ b/mixer/preferences.h
@@ -25,7 +25,6 @@
 #include <glib.h>
 #include <gtk/gtk.h>
 #include <panel-applet.h>
-#include <panel-applet-gconf.h>
 #include <gst/interfaces/mixer.h>
 
 G_BEGIN_DECLS
@@ -55,7 +54,7 @@ typedef struct _GnomeVolumeAppletPreferences {
   /* is the track list currently locked */
   gboolean track_lock;
 
-  /* for gconf */
+  /* for GSettings */
   PanelApplet *applet;
 
   /* treeview inside us */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c9f8c08..a5e4a1c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -69,6 +69,7 @@ mixer/dock.c
 mixer/load.c
 mixer/mixer.schemas.in
 [type: gettext/ini]mixer/org.gnome.applets.MixerApplet.panel-applet.in.in
+mixer/org.gnome.gnome-applets.mixer.gschema.xml.in.in
 mixer/preferences.c
 modemlights/modem-applet.c
 [type: gettext/glade]modemlights/modemlights.ui
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index c876a3f..f910ab3 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -20,6 +20,7 @@ invest-applet/data/Invest_Applet.server.in
 mini-commander/src/org.gnome.applets.MiniCommanderApplet.panel-applet.in
 mini-commander/src/org.gnome.gnome-applets.mini-commander.gschema.xml.in
 mixer/org.gnome.applets.MixerApplet.panel-applet.in
+mixer/org.gnome.gnome-applets.mixer.gschema.xml.in
 modemlights/org.gnome.applets.ModemApplet.panel-applet.in
 multiload/org.gnome.applets.MultiLoadApplet.panel-applet.in
 multiload/org.gnome.gnome-applets.multiload.gschema.xml.in


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]