[gnome-applets/wip/gnome-3.10+: 6/29] battstat: port to GSettings



commit f8e68647923251ab468de3cee17b73612906d4c9
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Jul 6 16:53:30 2014 +0300

    battstat: port to GSettings

 battstat/Makefile.am                               |   24 +++--
 battstat/apmlib/Makefile.am                        |    2 +
 battstat/battstat.h                                |   15 +++-
 battstat/battstat.schemas.in                       |  104 --------------------
 battstat/battstat_applet.c                         |   29 +++---
 ....gnome.gnome-applets.battstat.gschema.xml.in.in |   52 ++++++++++
 battstat/properties.c                              |   66 +++----------
 po/POTFILES.in                                     |    1 +
 po/POTFILES.skip                                   |    1 +
 9 files changed, 113 insertions(+), 181 deletions(-)
---
diff --git a/battstat/Makefile.am b/battstat/Makefile.am
index 9f99fa1..a75c706 100644
--- a/battstat/Makefile.am
+++ b/battstat/Makefile.am
@@ -58,16 +58,18 @@ battstat_applet_2_LDADD = \
                     $(LIBM) \
                     $(APMLIB)
 
-schemasdir   = @GCONF_SCHEMA_FILE_DIR@
-schemas_in_files = battstat.schemas.in
-schemas_DATA = $(schemas_in_files:.schemas.in=.schemas)
+gsettings_schemas_in_in = \
+       org.gnome.gnome-applets.battstat.gschema.xml.in.in
 
- INTLTOOL_SCHEMAS_RULE@
+ INTLTOOL_XML_NOMERGE_RULE@
 
-if GCONF_SCHEMAS_INSTALL
-install-data-local:
-       GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule 
$(schemas_DATA) ;
-endif
+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@
 
 appletdir       = $(LIBPANEL_APPLET_DIR)
 applet_in_files = org.gnome.applets.BattstatApplet.panel-applet.in
@@ -90,12 +92,16 @@ org.gnome.panel.applet.BattstatAppletFactory.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
 
 uidir = $(pkgdatadir)/ui
 ui_DATA = battstat-applet-menu.xml
 
 EXTRA_DIST =                                                   \
+       $(gsettings_schemas_in_in) \
        $(builder_DATA)                                         \
        $(ui_DATA)                                              \
        org.gnome.applets.BattstatApplet.panel-applet.in.in     \
diff --git a/battstat/apmlib/Makefile.am b/battstat/apmlib/Makefile.am
index 3844990..b554f0d 100644
--- a/battstat/apmlib/Makefile.am
+++ b/battstat/apmlib/Makefile.am
@@ -14,5 +14,7 @@ noinst_LIBRARIES = libapm.a
 
 libapm_a_SOURCES = apmlib.c apm.h
 
+CLEANFILES = \
+       libapm.a
 
 -include $(top_srcdir)/git.mk
diff --git a/battstat/battstat.h b/battstat/battstat.h
index ccf2f82..c19b668 100644
--- a/battstat/battstat.h
+++ b/battstat/battstat.h
@@ -26,7 +26,6 @@
 #include <gtk/gtk.h>
 
 #include <panel-applet.h>
-#include <panel-applet-gconf.h>
 
 #define DEBUG 0
 
@@ -38,6 +37,17 @@
 #define ORANGE_MULTIPLIER 1.5
 #define YELLOW_MULTIPLIER 2.5
 
+#define BATTSTAT_GSCHEMA              "org.gnome.gnome-applets.battstat"
+#define KEY_RED_VALUE                 "red-value"
+#define KEY_RED_VALUE_IS_TIME         "red-value-is-time"
+#define KEY_LOW_BATTERY_NOTIFICATION  "low-battery-notification"
+#define KEY_FULL_BATTERY_NOTIFICATION "full-battery-notification"
+#define KEY_BEEP                      "beep"
+#define KEY_DRAIN_FROM_TOP            "drain-from-top"
+#define KEY_SHOW_STATUS               "show-status"
+#define KEY_SHOW_BATTERY              "show-battery"
+#define KEY_SHOW_TEXT                 "show-text"
+
 typedef enum
 {
   APPLET_SHOW_NONE,
@@ -85,6 +95,7 @@ typedef struct
 
 typedef struct _ProgressData {
   GtkWidget *applet;
+  GSettings *settings;
 
   /* these are used by properties.c */
   GtkWidget *radio_ubuntu_battery;
@@ -96,7 +107,7 @@ typedef struct _ProgressData {
   GtkWidget *full_toggle;
   GtkWidget *hbox_ptr;
 
-  /* flags set from gconf or the properties dialog */
+  /* flags set from gsettings or the properties dialog */
   guint red_val;
   guint orange_val;
   guint yellow_val;
diff --git a/battstat/battstat_applet.c b/battstat/battstat_applet.c
index bace1d0..2938146 100644
--- a/battstat/battstat_applet.c
+++ b/battstat/battstat_applet.c
@@ -38,7 +38,6 @@
 #include <gtk/gtk.h>
 
 #include <panel-applet.h>
-#include <panel-applet-gconf.h>
 
 #ifdef HAVE_LIBNOTIFY
 #include <libnotify/notify.h>
@@ -51,8 +50,6 @@
 #define gettext_noop(String) (String)
 #endif
 
-#define GCONF_PATH ""
-
 static gboolean check_for_updates (gpointer data);
 static void about_cb( GSimpleAction *, GVariant *, gpointer );
 static void help_cb( GSimpleAction *, GVariant *, gpointer );
@@ -1107,6 +1104,9 @@ destroy_applet( GtkWidget *widget, ProgressData *battstat )
   if (battstat->timeout_id)
     g_source_remove (battstat->timeout_id);
 
+  if (battstat->settings)
+    g_object_unref (battstat->settings);
+
   g_object_unref( G_OBJECT(battstat->status) );
   g_object_unref( G_OBJECT(battstat->percent) );
   g_object_unref( G_OBJECT(battstat->battery) );
@@ -1270,7 +1270,7 @@ size_allocate( PanelApplet *applet, GtkAllocation *allocation,
   reconfigure_layout( battstat );
 }
 
-/* Get our settings out of gconf.
+/* Get our settings out of GSettings.
  */
 static void
 load_preferences(ProgressData *battstat)
@@ -1279,11 +1279,9 @@ load_preferences(ProgressData *battstat)
 
   if (DEBUG) g_print("load_preferences()\n");
   
-  battstat->red_val = panel_applet_gconf_get_int (applet, GCONF_PATH "red_value", NULL);
+  battstat->red_val = g_settings_get_int (battstat->settings, KEY_RED_VALUE);
   battstat->red_val = CLAMP (battstat->red_val, 0, 100);
-  battstat->red_value_is_time = panel_applet_gconf_get_bool (applet,
-                 GCONF_PATH "red_value_is_time",
-                 NULL);
+  battstat->red_value_is_time = g_settings_get_boolean (battstat->settings, KEY_RED_VALUE_IS_TIME);
 
   /* automatically calculate orangle and yellow values from the red value */
   battstat->orange_val = battstat->red_val * ORANGE_MULTIPLIER;
@@ -1292,19 +1290,19 @@ load_preferences(ProgressData *battstat)
   battstat->yellow_val = battstat->red_val * YELLOW_MULTIPLIER;
   battstat->yellow_val = CLAMP (battstat->yellow_val, 0, 100);
 
-  battstat->lowbattnotification = panel_applet_gconf_get_bool (applet, GCONF_PATH 
"low_battery_notification", NULL);
-  battstat->fullbattnot = panel_applet_gconf_get_bool (applet, GCONF_PATH "full_battery_notification", NULL);
-  battstat->beep = panel_applet_gconf_get_bool (applet, GCONF_PATH "beep", NULL);
-  battstat->draintop = panel_applet_gconf_get_bool (applet, GCONF_PATH "drain_from_top", NULL);
+  battstat->lowbattnotification = g_settings_get_boolean (battstat->settings, KEY_LOW_BATTERY_NOTIFICATION);
+  battstat->fullbattnot = g_settings_get_boolean (battstat->settings, KEY_FULL_BATTERY_NOTIFICATION);
+  battstat->beep = g_settings_get_boolean (battstat->settings, KEY_BEEP);
+  battstat->draintop = g_settings_get_boolean (battstat->settings, KEY_DRAIN_FROM_TOP);
   
-  battstat->showstatus = panel_applet_gconf_get_bool (applet, GCONF_PATH "show_status", NULL);
-  battstat->showbattery = panel_applet_gconf_get_bool (applet, GCONF_PATH "show_battery", NULL);
+  battstat->showstatus = g_settings_get_boolean (battstat->settings, KEY_SHOW_STATUS);
+  battstat->showbattery = g_settings_get_boolean (battstat->settings, KEY_SHOW_BATTERY);
 
   /* for miagration from older versions */
   if (battstat->showstatus && battstat->showbattery)
          battstat->showbattery = FALSE;
   
-  battstat->showtext = panel_applet_gconf_get_int (applet, GCONF_PATH "show_text", NULL);
+  battstat->showtext = g_settings_get_int (battstat->settings, KEY_SHOW_TEXT);
 }
 
 /* Convenience function to attach a child widget to a GtkTable in the
@@ -1579,6 +1577,7 @@ battstat_applet_fill (PanelApplet *applet)
 
   /* Some starting values... */
   battstat->applet = GTK_WIDGET (applet);
+  battstat->settings = panel_applet_settings_new (applet, BATTSTAT_GSCHEMA);
   battstat->refresh_label = TRUE;
   battstat->last_batt_life = 1000;
   battstat->last_acline_status = 1000;
diff --git a/battstat/org.gnome.gnome-applets.battstat.gschema.xml.in.in 
b/battstat/org.gnome.gnome-applets.battstat.gschema.xml.in.in
new file mode 100644
index 0000000..b6cfb2c
--- /dev/null
+++ b/battstat/org.gnome.gnome-applets.battstat.gschema.xml.in.in
@@ -0,0 +1,52 @@
+<schemalist gettext-domain="@GETTEXT_PACKAGE@">
+       <schema id="org.gnome.gnome-applets.battstat">
+               <key name="red-value" type="i">
+                       <default>15</default>
+                       <_summary>Red value level</_summary>
+                       <_description>The battery level below which the battery is displayed as red. Also the 
value at which the low battery warning is displayed.</_description>
+               </key>
+               <key name="red-value-is-time" type="b">
+                       <default>false</default>
+                       <_summary>Warn on low time rather than low percentage</_summary>
+                       <_description>Use the value defined in red-value as a time remaining to show the 
warning dialog rather than a percentage.</_description>
+               </key>
+               <key name="low-battery-notification" type="b">
+                       <default>true</default>
+                       <_summary>Low Battery Notification</_summary>
+                       <_description>Notify user when the battery is low.</_description>
+               </key>
+               <key name="full-battery-notification" type="b">
+                       <default>false</default>
+                       <_summary>Full Battery Notification</_summary>
+                       <_description>Notify user when the battery is full.</_description>
+               </key>
+               <key name="beep" type="b">
+                       <default>false</default>
+                       <_summary>Beep for warnings</_summary>
+                       <_description>Beep when displaying a warning.</_description>
+               </key>
+               <key name="drain-from-top" type="b">
+                       <default>false</default>
+                       <_summary>Drain from top</_summary>
+                       <_description>Show the battery meter draining from the top of the battery. Only 
implemented for traditional battery view.</_description>
+               </key>
+               <key name="show-status" type="b">
+                       <default>true</default>
+                       <_summary>Upright (small) battery</_summary>
+                       <_description>Show the upright, smaller battery on the panel.</_description>
+               </key>
+               <key name="show-battery" type="b">
+                       <default>false</default>
+                       <_summary>Show the horizontal battery</_summary>
+                       <_description>Show the traditional, horizontal battery on the panel.</_description>
+               </key>
+               <key name="show-text" type="i">
+                       <default>0</default>
+                       <_summary>Show the time/percent label</_summary>
+                       <_description>0 for no label, 1 for percentage and 2 for time 
remaining.</_description>
+               </key>
+               <key name="no-hal" type="b">
+                       <default>false</default>
+               </key>
+       </schema>
+</schemalist>
diff --git a/battstat/properties.c b/battstat/properties.c
index 4e11bf6..659b5a1 100644
--- a/battstat/properties.c
+++ b/battstat/properties.c
@@ -42,10 +42,7 @@
 
 #include <gtk/gtk.h>
 
-#include <gconf/gconf-client.h>
-
 #include <panel-applet.h>
-#include <panel-applet-gconf.h>
 
 #include "battstat.h"
 
@@ -86,11 +83,8 @@ combo_ptr_cb (GtkWidget *combo_ptr, gpointer data)
                battstat->red_value_is_time = TRUE;
        else
                battstat->red_value_is_time = FALSE;
-       
-       panel_applet_gconf_set_bool (PANEL_APPLET (battstat->applet),
-                       "red_value_is_time",
-                       battstat->red_value_is_time,
-                       NULL);
+
+       g_settings_set_boolean (battstat->settings, KEY_RED_VALUE_IS_TIME, battstat->red_value_is_time);
 }
 
 static void
@@ -108,29 +102,8 @@ spin_ptr_cb (GtkWidget *spin_ptr, gpointer data)
 
        battstat->yellow_val = battstat->red_val * YELLOW_MULTIPLIER;
        battstat->yellow_val = CLAMP (battstat->yellow_val, 0, 100);
-       
-       panel_applet_gconf_set_int (PANEL_APPLET (battstat->applet),
-                       "red_value",
-                       battstat->red_val,
-                       NULL);
-}
-
-static 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;
+       g_settings_set_int (battstat->settings, KEY_RED_VALUE, battstat->red_val);
 }
 
 static void
@@ -150,9 +123,7 @@ radio_traditional_toggled (GtkToggleButton *button, gpointer data)
   battstat->showbattery = toggled;
   reconfigure_layout( battstat );
 
-  panel_applet_gconf_set_bool   (applet, "show_battery", 
-                                battstat->showbattery, NULL);
-                                
+  g_settings_set_boolean (battstat->settings, KEY_SHOW_BATTERY, battstat->showbattery);
 }
 
 static void
@@ -171,10 +142,8 @@ radio_ubuntu_toggled (GtkToggleButton *button, gpointer data)
   
   battstat->showstatus = toggled;
   reconfigure_layout( battstat );
-  
-  panel_applet_gconf_set_bool   (applet, "show_status", 
-                                battstat->showstatus, NULL);
-                                
+
+  g_settings_set_boolean (battstat->settings, KEY_SHOW_STATUS, battstat->showstatus);
 }
 
 static void
@@ -202,9 +171,8 @@ show_text_toggled (GtkToggleButton *button, gpointer data)
                  battstat->showtext);
   gtk_widget_set_sensitive (GTK_WIDGET (battstat->radio_text_2),
                  battstat->showtext);
-       
-  panel_applet_gconf_set_int   (applet, "show_text", 
-                                battstat->showtext, NULL);
+
+  g_settings_set_int (battstat->settings, KEY_SHOW_TEXT, battstat->showtext);
 }
 
 static void
@@ -214,8 +182,7 @@ lowbatt_toggled (GtkToggleButton *button, gpointer data)
   PanelApplet *applet = PANEL_APPLET (battstat->applet);
   
   battstat->lowbattnotification = gtk_toggle_button_get_active (button);
-  panel_applet_gconf_set_bool   (applet,"low_battery_notification", 
-                                battstat->lowbattnotification, NULL);  
+  g_settings_set_boolean (battstat->settings, KEY_LOW_BATTERY_NOTIFICATION, battstat->lowbattnotification);  
 
   hard_set_sensitive (battstat->hbox_ptr, battstat->lowbattnotification);
 }
@@ -227,8 +194,7 @@ full_toggled (GtkToggleButton *button, gpointer data)
   PanelApplet *applet = PANEL_APPLET (battstat->applet);
   
   battstat->fullbattnot = gtk_toggle_button_get_active (button);
-  panel_applet_gconf_set_bool   (applet,"full_battery_notification", 
-                                battstat->fullbattnot, NULL);  
+  g_settings_set_boolean (battstat->settings, KEY_FULL_BATTERY_NOTIFICATION, battstat->fullbattnot);  
 }
 
 static void
@@ -280,8 +246,7 @@ prop_cb (GSimpleAction *action,
   g_signal_connect (G_OBJECT (battstat->lowbatt_toggle), "toggled",
                    G_CALLBACK (lowbatt_toggled), battstat);
 
-  if (!key_writable (PANEL_APPLET (battstat->applet),
-                         "low_battery_notification"))
+  if (!g_settings_is_writable (battstat->settings, KEY_LOW_BATTERY_NOTIFICATION))
   {
          hard_set_sensitive (battstat->lowbatt_toggle, FALSE);
   }
@@ -332,8 +297,7 @@ prop_cb (GSimpleAction *action,
   g_signal_connect (G_OBJECT (battstat->full_toggle), "toggled",
                    G_CALLBACK (full_toggled), battstat);
 
-  if (!key_writable (PANEL_APPLET (battstat->applet),
-                         "full_battery_notification"))
+  if (!g_settings_is_writable (battstat->settings, KEY_FULL_BATTERY_NOTIFICATION))
   {
          hard_set_sensitive (battstat->full_toggle, FALSE);
   }
@@ -353,7 +317,7 @@ prop_cb (GSimpleAction *action,
   g_signal_connect (G_OBJECT (battstat->radio_traditional_battery), "toggled",
                    G_CALLBACK (radio_traditional_toggled), battstat);
 
-  if (!key_writable (PANEL_APPLET (battstat->applet), "show_battery"))
+  if (!g_settings_is_writable (battstat->settings, KEY_SHOW_BATTERY))
          hard_set_sensitive (battstat->radio_traditional_battery, FALSE);
   
   if (battstat->showbattery)
@@ -368,7 +332,7 @@ prop_cb (GSimpleAction *action,
   g_signal_connect (G_OBJECT (battstat->radio_ubuntu_battery), "toggled",
                    G_CALLBACK (radio_ubuntu_toggled), battstat);
 
-  if (!key_writable (PANEL_APPLET (battstat->applet), "show_status"))
+  if (!g_settings_is_writable (battstat->settings, KEY_SHOW_STATUS))
          hard_set_sensitive (battstat->radio_ubuntu_battery, FALSE);
        
   if (battstat->showstatus)
@@ -392,7 +356,7 @@ prop_cb (GSimpleAction *action,
   g_signal_connect (G_OBJECT (battstat->check_text), "toggled",
                  G_CALLBACK (show_text_toggled), battstat);
   
-  if (!key_writable (PANEL_APPLET (battstat->applet), "show_text"))
+  if (!g_settings_is_writable (battstat->settings, KEY_SHOW_TEXT))
   {
          hard_set_sensitive (battstat->check_text, FALSE);
          hard_set_sensitive (battstat->radio_text_1, FALSE);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 230cc47..875b890 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -8,6 +8,7 @@ battstat/battstat_applet.c
 [type: gettext/glade]battstat/battstat_applet.ui
 battstat/battstat.schemas.in
 [type: gettext/ini]battstat/org.gnome.applets.BattstatApplet.panel-applet.in.in
+battstat/org.gnome.gnome-applets.battstat.gschema.xml.in.in
 battstat/properties.c
 battstat/sounds/battstat_applet.soundlist.in
 charpick/charpick.c
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 9aca018..2f5ab2f 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -5,6 +5,7 @@
 #
 accessx-status/org.gnome.applets.AccessxStatusApplet.panel-applet.in
 battstat/org.gnome.applets.BattstatApplet.panel-applet.in
+battstat/org.gnome.gnome-applets.battstat.gschema.xml.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


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