[gnome-applets/wip/gnome-3.10+: 4/29] charpick: port to GSettings



commit a57ffc110c9e29710ba63965f7f8e15ae8ea0032
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Jul 6 09:53:14 2014 +0300

    charpick: port to GSettings

 charpick/Makefile.am                               |   30 ++++---
 charpick/charpick.c                                |   82 ++++++--------------
 charpick/charpick.h                                |    9 +-
 charpick/charpick.schemas.in                       |   36 ---------
 ....gnome.gnome-applets.charpick.gschema.xml.in.in |   14 ++++
 charpick/properties.c                              |   16 ++--
 po/POTFILES.in                                     |    2 +-
 po/POTFILES.skip                                   |    1 +
 8 files changed, 69 insertions(+), 121 deletions(-)
---
diff --git a/charpick/Makefile.am b/charpick/Makefile.am
index 742a417..991642a 100644
--- a/charpick/Makefile.am
+++ b/charpick/Makefile.am
@@ -38,25 +38,31 @@ org.gnome.panel.applet.CharpickerAppletFactory.service: $(service_in_files)
             -e "s|\ LIBEXECDIR\@|$(libexecdir)|" \
             $< > $@
 
-CLEANFILES = $(applet_DATA) $(applet_DATA).in $(service_DATA) $(schemas_DATA)
+CLEANFILES = $(applet_DATA) $(applet_DATA).in $(service_DATA) \
+       $(gsettings_SCHEMAS_in) \
+       $(gsettings_SCHEMAS)    \
+       *.gschema.valid 
 
-schemasdir   = @GCONF_SCHEMA_FILE_DIR@
-schemas_in_files = charpick.schemas.in
-schemas_DATA = $(schemas_in_files:.schemas.in=.schemas)
+gsettings_schemas_in_in = \
+       org.gnome.gnome-applets.charpick.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@
 
- INTLTOOL_SCHEMAS_RULE@
 uidir = $(pkgdatadir)/ui
 ui_DATA = charpick-applet-menu.xml
 
 EXTRA_DIST =                                                   \
+       $(gsettings_schemas_in_in) \
        org.gnome.applets.CharpickerApplet.panel-applet.in.in   \
        $(service_in_files)                                     \
-       $(ui_DATA)                                              \
-       $(schemas_in_files)
-
-if GCONF_SCHEMAS_INSTALL
-install-data-local:
-       GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule 
$(schemas_DATA) ;
-endif
+       $(ui_DATA)
 
 -include $(top_srcdir)/git.mk
diff --git a/charpick/charpick.c b/charpick/charpick.c
index 628f3c0..c337f50 100644
--- a/charpick/charpick.c
+++ b/charpick/charpick.c
@@ -112,25 +112,6 @@ static const gunichar * const chartable[] = {
        af_ZA_code
 };
 
-gboolean
-key_writable (PanelApplet *applet, const char *key)
-{
-       gboolean writable;
-       char *fullkey;
-       static GConfClient *client = NULL;
-       if (client == NULL)
-               client = gconf_client_get_default ();
-
-       fullkey = panel_applet_gconf_get_full_key (applet, key);
-
-       writable = gconf_client_key_is_writable (client, fullkey, NULL);
-
-       g_free (fullkey);
-
-       return writable;
-}
-
-
 /* sets the picked character as the selection when it gets a request */
 static void
 charpick_selection_handler(GtkWidget *widget,
@@ -299,8 +280,8 @@ menuitem_activated (GtkMenuItem *menuitem, charpick_data *curr_data)
        
        curr_data->charlist = string;
        build_table (curr_data);
-       if (key_writable (applet, "current_list"))
-               panel_applet_gconf_set_string (applet, "current_list", curr_data->charlist, NULL);
+       if (g_settings_is_writable (curr_data->settings, KEY_CURRENT_LIST))
+               g_settings_set_string (curr_data->settings, KEY_CURRENT_LIST, curr_data->charlist);
 }
 
 void
@@ -655,6 +636,8 @@ applet_destroy (GtkWidget *widget, gpointer data)
     gtk_widget_destroy (curr_data->box);
   if (curr_data->menu)
     gtk_widget_destroy (curr_data->menu);
+  if (curr_data->settings)
+    g_object_unref (curr_data->settings);
   g_free (curr_data);
   
 }
@@ -662,48 +645,29 @@ applet_destroy (GtkWidget *widget, gpointer data)
 void 
 save_chartable (charpick_data *curr_data)
 {
-       PanelApplet *applet = PANEL_APPLET (curr_data->applet);
-       GConfValue *value;
        GList *list = curr_data->chartable;
-       GSList *slist = NULL;
-       
+       GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
+
        while (list) {
-               gchar *charlist = list->data;
-               GConfValue *v1;
-               v1 = gconf_value_new_from_string (GCONF_VALUE_STRING, charlist, NULL);
-               slist = g_slist_append (slist, v1);
-               list = g_list_next (list);
+               array = g_array_append_val (array, list->data);
+               list = list->next;
        }
-       
-       value = gconf_value_new (GCONF_VALUE_LIST);
-       gconf_value_set_list_type (value, GCONF_VALUE_STRING);
-       gconf_value_set_list_nocopy (value, slist);
-       panel_applet_gconf_set_value (applet, "chartable", value, NULL);
-       gconf_value_free (value);
+
+       g_settings_set_strv (curr_data->settings, KEY_CHARTABLE, (const gchar **) array->data);
+       g_array_free (array, TRUE);
 }
 
 static void
 get_chartable (charpick_data *curr_data)
 {
-       PanelApplet *applet = PANEL_APPLET (curr_data->applet);
-       GConfValue *value;
-       gint i, n;
-       
-       value = panel_applet_gconf_get_value (applet, "chartable", NULL);
-       if (value) {
-               GSList *slist = gconf_value_get_list (value);
-               while (slist) {
-                       GConfValue *v1 = slist->data;
-                       gchar *charlist;
-                       
-                       charlist = g_strdup (gconf_value_get_string (v1));
-                       curr_data->chartable = g_list_append (curr_data->chartable, charlist);
-                       
-                       slist = g_slist_next (slist);
+       gchar **value = g_settings_get_strv (curr_data->settings, KEY_CHARTABLE);
+       gint i, n = 0;
+
+       if (value[0]) {
+               for (i = 0; value[i] != NULL; i++) {
+                       curr_data->chartable = g_list_append (curr_data->chartable, g_strdup (value[i]));
                }
-               gconf_value_free (value);
-       }
-       else {
+       } else {
                n = G_N_ELEMENTS (chartable);
                for (i=0; i<n; i++) {
                        gchar *string;
@@ -712,11 +676,11 @@ get_chartable (charpick_data *curr_data)
                        curr_data->chartable = g_list_append (curr_data->chartable, string);
                
                }
-               if ( ! key_writable (PANEL_APPLET (curr_data->applet), "chartable"))
+               if (g_settings_is_writable (curr_data->settings, KEY_CHARTABLE))
                        save_chartable (curr_data);
        }
-       
 
+       g_strfreev (value);
 }
 
 static const GActionEntry charpick_applet_menu_actions [] = {
@@ -764,7 +728,6 @@ charpicker_applet_fill (PanelApplet *applet)
 
   panel_applet_set_background_widget (applet, GTK_WIDGET (applet));
 
-  panel_applet_add_preferences (applet, "/schemas/apps/charpick/prefs", NULL);
   panel_applet_set_flags (applet, PANEL_APPLET_EXPAND_MINOR);
    
   curr_data = g_new0 (charpick_data, 1);
@@ -772,11 +735,12 @@ charpicker_applet_fill (PanelApplet *applet)
   curr_data->applet = GTK_WIDGET (applet);
   curr_data->about_dialog = NULL;
   curr_data->add_edit_dialog = NULL;
+  curr_data->settings = panel_applet_settings_new (applet, CHARPICK_SCHEMA);
  
   get_chartable (curr_data);
   
-  string  = panel_applet_gconf_get_string (applet, "current_list", NULL);
-  if (string) {
+  string = g_settings_get_string (curr_data->settings, KEY_CURRENT_LIST);
+  if (string[0] != '\0') {
        list = curr_data->chartable;
        while (list) {
                if (g_ascii_strcasecmp (list->data, string) == 0)
diff --git a/charpick/charpick.h b/charpick/charpick.h
index 6e87153..e6d6785 100644
--- a/charpick/charpick.h
+++ b/charpick/charpick.h
@@ -3,12 +3,14 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#include <gconf/gconf-client.h>
 #include <panel-applet.h>
-#include <panel-applet-gconf.h>
 
 #define NO_LAST_INDEX -1
 
+#define CHARPICK_SCHEMA  "org.gnome.gnome-applets.charpick"
+#define KEY_CURRENT_LIST "current-list"
+#define KEY_CHARTABLE    "chartable"
+
 typedef struct _charpick_data charpick_data;
 /* this type has basically all data for this program */
 struct _charpick_data {
@@ -28,6 +30,7 @@ struct _charpick_data {
   GtkWidget *menu;
   GtkWidget *add_edit_dialog;
   GtkWidget *add_edit_entry;
+  GSettings *settings;
 };
 
 
@@ -57,5 +60,3 @@ void add_edit_dialog_create (charpick_data     *curr_data,
 void set_atk_name_description (GtkWidget         *widget,
                               const char        *name,
                               const char        *description);
-gboolean key_writable (PanelApplet *applet, const char *key);
-
diff --git a/charpick/org.gnome.gnome-applets.charpick.gschema.xml.in.in 
b/charpick/org.gnome.gnome-applets.charpick.gschema.xml.in.in
new file mode 100644
index 0000000..e889857
--- /dev/null
+++ b/charpick/org.gnome.gnome-applets.charpick.gschema.xml.in.in
@@ -0,0 +1,14 @@
+<schemalist gettext-domain="@GETTEXT_PACKAGE@">
+       <schema id="org.gnome.gnome-applets.charpick">
+               <key name="current-list" type="s">
+                       <default>''</default>
+                       <_summary>Characters shown on applet startup</_summary>
+                       <_description>The string that the user had selected when the applet was last used. 
This string will be displayed when the user starts the applet.</_description>
+               </key>
+               <key name="chartable" type="as">
+                       <default>[]</default>
+                       <_summary>List of available palettes</_summary>
+                       <_description>List of strings containing the available palettes.</_description>
+               </key>
+       </schema>
+</schemalist>
diff --git a/charpick/properties.c b/charpick/properties.c
index a6bcdf5..4395461 100644
--- a/charpick/properties.c
+++ b/charpick/properties.c
@@ -161,10 +161,8 @@ add_palette_cb (GtkDialog *dialog, int response_id, charpick_data *curr_data)
                curr_data->charlist = curr_data->chartable->data;
                build_table (curr_data);
 
-               if (key_writable (PANEL_APPLET (curr_data->applet), "current_list"))
-                       panel_applet_gconf_set_string (PANEL_APPLET (curr_data->applet),
-                                                     "current_list", 
-                                                      curr_data->charlist, NULL);
+               if (g_settings_is_writable (curr_data->settings, KEY_CURRENT_LIST))
+                       g_settings_set_string (curr_data->settings, KEY_CURRENT_LIST, curr_data->charlist);
        }
 
        save_chartable (curr_data);
@@ -225,8 +223,8 @@ edit_palette_cb (GtkDialog *dialog, int response_id, charpick_data *curr_data)
                curr_data->charlist = new;
                build_table (curr_data);
 
-               if (key_writable (PANEL_APPLET (curr_data->applet), "current_list"))
-                       panel_applet_gconf_set_string (PANEL_APPLET (curr_data->applet), "current_list", 
curr_data->charlist, NULL);
+               if (g_settings_is_writable (curr_data->settings, KEY_CURRENT_LIST))
+                       g_settings_set_string (curr_data->settings, KEY_CURRENT_LIST, curr_data->charlist);
        }
        
        g_free (charlist);
@@ -314,8 +312,8 @@ delete_palette (GtkButton *button, charpick_data *curr_data)
        if (g_ascii_strcasecmp (curr_data->charlist, charlist) == 0) {
                curr_data->charlist = curr_data->chartable != NULL ? 
                                      curr_data->chartable->data : "";
-               if (key_writable (PANEL_APPLET (curr_data->applet), "current_list"))
-                       panel_applet_gconf_set_string (PANEL_APPLET (curr_data->applet), "current_list", 
curr_data->charlist, NULL);
+               if (g_settings_is_writable (curr_data->settings, KEY_CURRENT_LIST))
+                       g_settings_set_string (curr_data->settings, KEY_CURRENT_LIST, curr_data->charlist);
        }
        g_free (charlist);
        
@@ -488,7 +486,7 @@ static void default_chars_frame_create(charpick_data *curr_data)
   set_access_namedesc (button, _("Delete button"),
                                         _("Click to delete the selected palette"));
 
-  if ( ! key_writable (PANEL_APPLET (curr_data->applet), "chartable"))
+  if (!g_settings_is_writable (curr_data->settings, KEY_CHARTABLE))
          gtk_widget_set_sensitive (vbox3, FALSE);
    
   return;
diff --git a/po/POTFILES.in b/po/POTFILES.in
index faf07ba..230cc47 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -11,8 +11,8 @@ battstat/battstat.schemas.in
 battstat/properties.c
 battstat/sounds/battstat_applet.soundlist.in
 charpick/charpick.c
-charpick/charpick.schemas.in
 [type: gettext/ini]charpick/org.gnome.applets.CharpickerApplet.panel-applet.in.in
+charpick/org.gnome.gnome-applets.charpick.gschema.xml.in.in
 charpick/properties.c
 cpufreq/cpufreq-applet.schemas.in
 [type: gettext/glade]cpufreq/cpufreq-preferences.ui
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 0c57bba..9aca018 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -6,6 +6,7 @@
 accessx-status/org.gnome.applets.AccessxStatusApplet.panel-applet.in
 battstat/org.gnome.applets.BattstatApplet.panel-applet.in
 charpick/org.gnome.applets.CharpickerApplet.panel-applet.in
+charpick/org.gnome.gnome-applets.charpick.gschema.xml.in
 cpufreq/org.gnome.applets.CPUFreqApplet.panel-applet.in
 drivemount/drivemount/org.gnome.applets.DriveMountApplet.panel-applet.in
 geyes/org.gnome.applets.GeyesApplet.panel-applet.in


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