From 84735ec5056e864684245f90a0116ce09cc42b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Mon, 22 Aug 2011 20:38:36 +0100 Subject: Use gsettings to store the status of "Show time in Menu Bar" option Fixes https://bugs.launchpad.net/indicator-power/+bug/829853 --- Makefile.am | 14 +++++++++++++- configure.ac | 8 +++++++- data/org.ubuntu.indicator-power.gschema.xml.in | 9 +++++++++ src/indicator-power.c | 16 +++++++++++++++- 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 data/org.ubuntu.indicator-power.gschema.xml.in diff --git a/Makefile.am b/Makefile.am index 932775f..70af9f5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,13 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} SUBDIRS = po +gsettingsschema_in_files = data/org.ubuntu.indicator-power.gschema.xml.in +gsettings_SCHEMAS = $(gsettingsschema_in_files:.xml.in=.xml) + +@INTLTOOL_XML_NOMERGE_RULE@ + +@GSETTINGS_RULES@ + ################### # Indicator Stuff ################### @@ -24,7 +31,12 @@ libpower_la_LDFLAGS = \ ############################################################ -EXTRA_DIST = autogen.sh +EXTRA_DIST = \ + $(gsettingsschema_in_files) \ + autogen.sh + +CLEANFILES = \ + $(gsettings_SCHEMAS) DISTCHECK_CONFIGURE_FLAGS = --enable-localinstall diff --git a/configure.ac b/configure.ac index 19ca570..94a94bc 100644 --- a/configure.ac +++ b/configure.ac @@ -28,7 +28,7 @@ LT_INIT ########################### # Dependencies ########################### - +GIO_REQUIRED_VERSION=2.26 GTK_REQUIRED_VERSION=3.0 INDICATOR_REQUIRED_VERSION=0.3.90 UPOWER_REQUIRED_VERSION=0.9.5 @@ -36,11 +36,17 @@ GSD_REQUIRED_VERSION=3.1.4 PKG_CHECK_MODULES([UPOWER],[upower-glib >= UPOWER_REQUIRED_VERSION]) PKG_CHECK_MODULES([INDICATOR],[ + gio-2.0 >= $GIO_REQUIRED_VERSION gtk+-3.0 >= $GTK_REQUIRED_VERSION indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION ]) PKG_CHECK_MODULES([GSD],[gnome-settings-daemon >= $GSD_REQUIRED_VERSION]) +########################### +# GSETTINGS +########################### +GLIB_GSETTINGS + ########################### # Check to see if we're local ########################### diff --git a/data/org.ubuntu.indicator-power.gschema.xml.in b/data/org.ubuntu.indicator-power.gschema.xml.in new file mode 100644 index 0000000..a961794 --- /dev/null +++ b/data/org.ubuntu.indicator-power.gschema.xml.in @@ -0,0 +1,9 @@ + + + + false + <_summary>Show time in Menu Bar + <_description>Whether show the time in the menu bar. + + + diff --git a/src/indicator-power.c b/src/indicator-power.c index 24b2b72..7f9e479 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -82,6 +82,8 @@ struct _IndicatorPowerPrivate GVariant *devices; GVariant *device; + + GSettings *settings; }; /* Prototypes */ @@ -138,9 +140,15 @@ option_toggled_cb (GtkCheckMenuItem *item, { IndicatorPower *self = INDICATOR_POWER (user_data); IndicatorPowerPrivate *priv = self->priv; + gboolean visible; + + visible = gtk_check_menu_item_get_active (item); gtk_widget_set_visible (GTK_WIDGET (priv->label), - gtk_check_menu_item_get_active (item)); + visible); + + g_settings_set_boolean (priv->settings, "show-time", + visible); } static void @@ -459,6 +467,7 @@ build_menu (IndicatorPower *self) GtkWidget *image; GList *children; gsize n_devices = 0; + gboolean visible; if (priv->menu == NULL) priv->menu = GTK_MENU (gtk_menu_new ()); @@ -482,6 +491,8 @@ build_menu (IndicatorPower *self) item = gtk_check_menu_item_new_with_label (_("Show Time in Menu Bar")); g_signal_connect (G_OBJECT (item), "toggled", G_CALLBACK (option_toggled_cb), self); + visible = g_settings_get_boolean (priv->settings, "show-time"); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), visible); gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), item); /* preferences */ @@ -755,6 +766,9 @@ indicator_power_init (IndicatorPower *self) priv->proxy_cancel, service_proxy_cb, self); + + /* GSettings */ + priv->settings = g_settings_new ("org.ubuntu.indicator-power"); } static void -- cgit v1.2.3