From 8ea3054c1e05445f990c98db033754cf190d2a7a Mon Sep 17 00:00:00 2001 From: Stefano Karapetsas Date: Sat, 24 Nov 2012 18:16:24 +0100 Subject: battstat: migrate to gsettings --- battstat/Makefile.am | 22 ++--- battstat/battstat.h | 6 +- battstat/battstat.schemas.in | 104 --------------------- battstat/battstat_applet.c | 32 +++---- battstat/docs/C/mate-battstat.xml | 2 +- ...rg.mate.panel.applet.battstat.gschema.xml.in.in | 54 +++++++++++ battstat/properties.c | 75 +++++---------- 7 files changed, 107 insertions(+), 188 deletions(-) delete mode 100644 battstat/battstat.schemas.in create mode 100644 battstat/org.mate.panel.applet.battstat.gschema.xml.in.in diff --git a/battstat/Makefile.am b/battstat/Makefile.am index 10f40af0..cd01741f 100644 --- a/battstat/Makefile.am +++ b/battstat/Makefile.am @@ -24,7 +24,7 @@ SUBDIRS = docs sounds $(APMDIR) DIST_SUBDIRS = docs sounds apmlib INCLUDES = \ - $(MATE_APPLETS3_CFLAGS) \ + $(MATE_APPLETS4_CFLAGS) \ $(LIBMATENOTIFY_CFLAGS) \ $(HAL_CFLAGS) \ $(UPOWER_CFLAGS) \ @@ -54,23 +54,19 @@ battstat_applet_2_SOURCES = \ battstat_applet_2_LDADD = \ - $(MATE_APPLETS3_LIBS) \ + $(MATE_APPLETS4_LIBS) \ $(LIBMATENOTIFY_LIBS) \ $(HAL_LIBS) \ $(APMLIB) \ $(UPOWER_LIBS) \ -lm -schemasdir = @MATECONF_SCHEMA_FILE_DIR@ -schemas_in_files = battstat.schemas.in -schemas_DATA = $(schemas_in_files:.schemas.in=.schemas) +@INTLTOOL_XML_NOMERGE_RULE@ +gsettings_SCHEMAS = org.mate.panel.applet.battstat.gschema.xml +@GSETTINGS_RULES@ -@INTLTOOL_SCHEMAS_RULE@ - -if MATECONF_SCHEMAS_INSTALL -install-data-local: - MATECONF_CONFIG_SOURCE=$(MATECONF_SCHEMA_CONFIG_SOURCE) $(MATECONFTOOL) --makefile-install-rule $(schemas_DATA) ; -endif +%.gschema.xml.in: %.gschema.xml.in.in Makefile + $(AM_V_GEN) $(SED) -e 's^\@GETTEXT_PACKAGE\@^$(GETTEXT_PACKAGE)^g' < $< > $@ appletdir = $(datadir)/mate-panel/applets applet_in_files = org.mate.applets.BattstatApplet.mate-panel-applet.in @@ -93,7 +89,7 @@ org.mate.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 = $(datadir)/mate-2.0/ui ui_DATA = battstat-applet-menu.xml @@ -103,7 +99,7 @@ EXTRA_DIST = \ $(ui_DATA) \ org.mate.applets.BattstatApplet.mate-panel-applet.in.in \ $(service_in_files) \ - $(schemas_in_files) + $(gsettings_SCHEMAS_in_in) -include $(top_srcdir)/git.mk diff --git a/battstat/battstat.h b/battstat/battstat.h index 1c591bce..a48dd121 100644 --- a/battstat/battstat.h +++ b/battstat/battstat.h @@ -24,9 +24,10 @@ #include #include #include +#include #include -#include +#include #define DEBUG 0 @@ -96,7 +97,8 @@ typedef struct _ProgressData { GtkWidget *full_toggle; GtkWidget *hbox_ptr; - /* flags set from mateconf or the properties dialog */ + /* flags set from gsettings or the properties dialog */ + GSettings *settings; guint red_val; guint orange_val; guint yellow_val; diff --git a/battstat/battstat.schemas.in b/battstat/battstat.schemas.in deleted file mode 100644 index b356c11a..00000000 --- a/battstat/battstat.schemas.in +++ /dev/null @@ -1,104 +0,0 @@ - - - - - /schemas/apps/battstat-applet/prefs/red_value - battstat-applet - int - 15 - - Red value level - The battery level below which the battery is displayed as red. Also the value at which the low battery warning is displayed. - - - - - /schemas/apps/battstat-applet/prefs/red_value_is_time - battstat-applet - bool - - Warn on low time rather than low percentage - Use the value defined in red_value as a time remaining to show the warning dialog rather than a percentage. - - - - - /schemas/apps/battstat-applet/prefs/low_battery_notification - battstat-applet - bool - true - - Low Battery Notification - Notify user when the battery is low. - - - - - /schemas/apps/battstat-applet/prefs/full_battery_notification - battstat-applet - bool - false - - Full Battery Notification - Notify user when the battery is full. - - - - - /schemas/apps/battstat-applet/prefs/beep - battstat-applet - bool - false - - Beep for warnings - Beep when displaying a warning. - - - - - /schemas/apps/battstat-applet/prefs/drain_from_top - battstat-applet - bool - false - - Drain from top - Show the battery meter draining from the top of the battery. Only implemented for traditional battery view. - - - - - /schemas/apps/battstat-applet/prefs/show_status - battstat-applet - bool - true - - Upright (small) battery - Show the upright, smaller battery on the panel. - - - - - /schemas/apps/battstat-applet/prefs/show_battery - battstat-applet - bool - false - - Show the horizontal battery - Show the traditional, horizontal battery on the panel. - - - - - /schemas/apps/battstat-applet/prefs/show_text - battstat-applet - int - 0 - - Show the time/percent label - 0 for no label, 1 for percentage and 2 for time remaining. - - - - - - diff --git a/battstat/battstat_applet.c b/battstat/battstat_applet.c index 53c9e034..3fd76401 100644 --- a/battstat/battstat_applet.c +++ b/battstat/battstat_applet.c @@ -38,7 +38,7 @@ #include #include -#include +#include #ifdef HAVE_LIBMATENOTIFY #include @@ -51,7 +51,7 @@ #define gettext_noop(String) (String) #endif -#define MATECONF_PATH "" +#define BATTSTAT_SCHEMA "org.mate.panel.applet.battstat" static gboolean check_for_updates (gpointer data); static void about_cb( GtkAction *, ProgressData * ); @@ -1329,20 +1329,19 @@ size_allocate( MatePanelApplet *applet, GtkAllocation *allocation, reconfigure_layout( battstat ); } -/* Get our settings out of mateconf. +/* Get our settings out of gsettings. */ static void load_preferences(ProgressData *battstat) { MatePanelApplet *applet = MATE_PANEL_APPLET (battstat->applet); + GSettings *settings = battstat->settings; if (DEBUG) g_print("load_preferences()\n"); - battstat->red_val = mate_panel_applet_mateconf_get_int (applet, MATECONF_PATH "red_value", NULL); + battstat->red_val = g_settings_get_int (settings, "red-value"); battstat->red_val = CLAMP (battstat->red_val, 0, 100); - battstat->red_value_is_time = mate_panel_applet_mateconf_get_bool (applet, - MATECONF_PATH "red_value_is_time", - NULL); + battstat->red_value_is_time = g_settings_get_boolean (settings, "red-value-is-time"); /* automatically calculate orangle and yellow values from the red value */ battstat->orange_val = battstat->red_val * ORANGE_MULTIPLIER; @@ -1351,19 +1350,19 @@ load_preferences(ProgressData *battstat) battstat->yellow_val = battstat->red_val * YELLOW_MULTIPLIER; battstat->yellow_val = CLAMP (battstat->yellow_val, 0, 100); - battstat->lowbattnotification = mate_panel_applet_mateconf_get_bool (applet, MATECONF_PATH "low_battery_notification", NULL); - battstat->fullbattnot = mate_panel_applet_mateconf_get_bool (applet, MATECONF_PATH "full_battery_notification", NULL); - battstat->beep = mate_panel_applet_mateconf_get_bool (applet, MATECONF_PATH "beep", NULL); - battstat->draintop = mate_panel_applet_mateconf_get_bool (applet, MATECONF_PATH "drain_from_top", NULL); + battstat->lowbattnotification = g_settings_get_boolean (settings, "low-battery-notification"); + battstat->fullbattnot = g_settings_get_boolean (settings, "full-battery-notification"); + battstat->beep = g_settings_get_boolean (settings, "beep"); + battstat->draintop = g_settings_get_boolean (settings, "drain-from-top"); - battstat->showstatus = mate_panel_applet_mateconf_get_bool (applet, MATECONF_PATH "show_status", NULL); - battstat->showbattery = mate_panel_applet_mateconf_get_bool (applet, MATECONF_PATH "show_battery", NULL); + battstat->showstatus = g_settings_get_boolean (settings, "show-status"); + battstat->showbattery = g_settings_get_boolean (settings, "show-battery"); /* for miagration from older versions */ if (battstat->showstatus && battstat->showbattery) battstat->showbattery = FALSE; - battstat->showtext = mate_panel_applet_mateconf_get_int (applet, MATECONF_PATH "show_text", NULL); + battstat->showtext = g_settings_get_int (settings, "show-text"); } /* Convenience function to attach a child widget to a GtkTable in the @@ -1630,11 +1629,10 @@ battstat_applet_fill (MatePanelApplet *applet) gtk_window_set_default_icon_name ("battery"); - mate_panel_applet_add_preferences (applet, "/schemas/apps/battstat-applet/prefs", - NULL); mate_panel_applet_set_flags (applet, MATE_PANEL_APPLET_EXPAND_MINOR); battstat = g_new0 (ProgressData, 1); + battstat->settings = mate_panel_applet_settings_new (applet, BATTSTAT_SCHEMA); /* Some starting values... */ battstat->applet = GTK_WIDGET (applet); @@ -1684,7 +1682,7 @@ battstat_applet_fill (MatePanelApplet *applet) atk_object_set_description(atk_widget, _("Monitor a laptop's remaining power")); } - no_hal = mate_panel_applet_mateconf_get_bool( applet, "no_hal", NULL ); + no_hal = g_settings_get_boolean (battstat->settings, "no-hal"); if ((err = static_global_initialisation (no_hal, battstat))) battstat_error_dialog (GTK_WIDGET (applet), err); diff --git a/battstat/docs/C/mate-battstat.xml b/battstat/docs/C/mate-battstat.xml index 2ba2273a..281be3ad 100644 --- a/battstat/docs/C/mate-battstat.xml +++ b/battstat/docs/C/mate-battstat.xml @@ -487,7 +487,7 @@ present voltage: 11400 mV You can check that your battery is detected by HAL using the command hal-device-manager. If your battery is not detected by HAL or the wrong information is being reported, you can attempt to - disable the HAL backend by setting a MateConf key. + disable the HAL backend by setting a GSettings key. Select Configuration Editor from the diff --git a/battstat/org.mate.panel.applet.battstat.gschema.xml.in.in b/battstat/org.mate.panel.applet.battstat.gschema.xml.in.in new file mode 100644 index 00000000..f35103a1 --- /dev/null +++ b/battstat/org.mate.panel.applet.battstat.gschema.xml.in.in @@ -0,0 +1,54 @@ + + + + 15 + <_summary>Red value level + <_description>The battery level below which the battery is displayed as red. Also the value at which the low battery warning is displayed. + + + false + <_summary>Warn on low time rather than low percentage + <_description>Use the value defined in red_value as a time remaining to show the warning dialog rather than a percentage. + + + true + <_summary>Low Battery Notification + <_description>Notify user when the battery is low. + + + false + <_summary>Full Battery Notification + <_description>Notify user when the battery is full. + + + false + <_summary>Beep for warnings + <_description>Beep when displaying a warning. + + + false + <_summary>Drain from top + <_description>Show the battery meter draining from the top of the battery. Only implemented for traditional battery view. + + + true + <_summary>Upright (small) battery + <_description>Show the upright, smaller battery on the panel. + + + false + <_summary>Show the horizontal battery + <_description>Show the traditional, horizontal battery on the panel. + + + 0 + <_summary>Show the time/percent label + <_description>0 for no label, 1 for percentage and 2 for time remaining. + + + false + <_summary>Disable HAL + <_description>Disable HAL if true + + + diff --git a/battstat/properties.c b/battstat/properties.c index bcca19a2..8242ccee 100644 --- a/battstat/properties.c +++ b/battstat/properties.c @@ -42,10 +42,10 @@ #include -#include +#include #include -#include +#include #include "battstat.h" @@ -87,10 +87,9 @@ combo_ptr_cb (GtkWidget *combo_ptr, gpointer data) else battstat->red_value_is_time = FALSE; - mate_panel_applet_mateconf_set_bool (MATE_PANEL_APPLET (battstat->applet), - "red_value_is_time", - battstat->red_value_is_time, - NULL); + g_settings_set_boolean (battstat->settings, + "red-value-is-time", + battstat->red_value_is_time); } static void @@ -109,28 +108,9 @@ 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); - mate_panel_applet_mateconf_set_int (MATE_PANEL_APPLET (battstat->applet), - "red_value", - battstat->red_val, - NULL); -} - -static gboolean -key_writable (MatePanelApplet *applet, const char *key) -{ - gboolean writable; - char *fullkey; - static MateConfClient *client = NULL; - if (client == NULL) - client = mateconf_client_get_default (); - - fullkey = mate_panel_applet_mateconf_get_full_key (applet, key); - - writable = mateconf_client_key_is_writable (client, fullkey, NULL); - - g_free (fullkey); - - return writable; + g_settings_set_int (battstat->settings, + "red-value", + battstat->red_val); } static void @@ -150,8 +130,8 @@ radio_traditional_toggled (GtkToggleButton *button, gpointer data) battstat->showbattery = toggled; reconfigure_layout( battstat ); - mate_panel_applet_mateconf_set_bool (applet, "show_battery", - battstat->showbattery, NULL); + g_settings_set_boolean (battstat->settings, "show-battery", + battstat->showbattery); } @@ -172,8 +152,8 @@ radio_ubuntu_toggled (GtkToggleButton *button, gpointer data) battstat->showstatus = toggled; reconfigure_layout( battstat ); - mate_panel_applet_mateconf_set_bool (applet, "show_status", - battstat->showstatus, NULL); + g_settings_set_boolean (battstat->settings, "show-status", + battstat->showstatus); } @@ -203,8 +183,7 @@ show_text_toggled (GtkToggleButton *button, gpointer data) gtk_widget_set_sensitive (GTK_WIDGET (battstat->radio_text_2), battstat->showtext); - mate_panel_applet_mateconf_set_int (applet, "show_text", - battstat->showtext, NULL); + g_settings_set_int (battstat->settings, "show-text", battstat->showtext); } static void @@ -214,8 +193,8 @@ lowbatt_toggled (GtkToggleButton *button, gpointer data) MatePanelApplet *applet = MATE_PANEL_APPLET (battstat->applet); battstat->lowbattnotification = gtk_toggle_button_get_active (button); - mate_panel_applet_mateconf_set_bool (applet,"low_battery_notification", - battstat->lowbattnotification, NULL); + g_settings_set_boolean (battstat->settings, "low-battery-notification", + battstat->lowbattnotification); hard_set_sensitive (battstat->hbox_ptr, battstat->lowbattnotification); } @@ -227,8 +206,8 @@ full_toggled (GtkToggleButton *button, gpointer data) MatePanelApplet *applet = MATE_PANEL_APPLET (battstat->applet); battstat->fullbattnot = gtk_toggle_button_get_active (button); - mate_panel_applet_mateconf_set_bool (applet,"full_battery_notification", - battstat->fullbattnot, NULL); + g_settings_set_boolean (battstat->settings, "full-battery-notification", + battstat->fullbattnot); } static void @@ -248,15 +227,9 @@ prop_cb (GtkAction *action, { GtkBuilder *builder; GtkWidget *combo_ptr, *spin_ptr; - MateConfClient *client; GtkListStore *liststore; GtkCellRenderer *renderer; GtkTreeIter iter; - /* Shouldn't this be used for something later on? */ - gboolean inhibit_command_line; - - client = mateconf_client_get_default (); - inhibit_command_line = mateconf_client_get_bool (client, "/desktop/mate/lockdown/inhibit_command_line", NULL); if (DEBUG) g_print("prop_cb()\n"); @@ -282,8 +255,8 @@ prop_cb (GtkAction *action, g_signal_connect (G_OBJECT (battstat->lowbatt_toggle), "toggled", G_CALLBACK (lowbatt_toggled), battstat); - if (!key_writable (MATE_PANEL_APPLET (battstat->applet), - "low_battery_notification")) + if (!g_settings_is_writable (battstat->settings, + "low-battery-notification")) { hard_set_sensitive (battstat->lowbatt_toggle, FALSE); } @@ -334,8 +307,8 @@ prop_cb (GtkAction *action, g_signal_connect (G_OBJECT (battstat->full_toggle), "toggled", G_CALLBACK (full_toggled), battstat); - if (!key_writable (MATE_PANEL_APPLET (battstat->applet), - "full_battery_notification")) + if (!g_settings_is_writable (battstat->settings, + "full-battery-notification")) { hard_set_sensitive (battstat->full_toggle, FALSE); } @@ -355,7 +328,7 @@ prop_cb (GtkAction *action, g_signal_connect (G_OBJECT (battstat->radio_traditional_battery), "toggled", G_CALLBACK (radio_traditional_toggled), battstat); - if (!key_writable (MATE_PANEL_APPLET (battstat->applet), "show_battery")) + if (!g_settings_is_writable (battstat->settings, "show-battery")) hard_set_sensitive (battstat->radio_traditional_battery, FALSE); if (battstat->showbattery) @@ -370,7 +343,7 @@ prop_cb (GtkAction *action, g_signal_connect (G_OBJECT (battstat->radio_ubuntu_battery), "toggled", G_CALLBACK (radio_ubuntu_toggled), battstat); - if (!key_writable (MATE_PANEL_APPLET (battstat->applet), "show_status")) + if (!g_settings_is_writable (battstat->settings, "show-status")) hard_set_sensitive (battstat->radio_ubuntu_battery, FALSE); if (battstat->showstatus) @@ -394,7 +367,7 @@ prop_cb (GtkAction *action, g_signal_connect (G_OBJECT (battstat->check_text), "toggled", G_CALLBACK (show_text_toggled), battstat); - if (!key_writable (MATE_PANEL_APPLET (battstat->applet), "show_text")) + if (!g_settings_is_writable (battstat->settings, "show-text")) { hard_set_sensitive (battstat->check_text, FALSE); hard_set_sensitive (battstat->radio_text_1, FALSE); -- cgit v1.2.1