From c4a85b1a1ee2ef71524b2566c9047cb4817e84ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 8 Nov 2011 22:38:58 +0100 Subject: Add name-hint. Using the defined PACKAGE_NAME value. --- src/indicator-power.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/indicator-power.c b/src/indicator-power.c index cb684f5..8dc2788 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -97,6 +97,7 @@ static GtkLabel* get_label (IndicatorObject * io); static GtkImage* get_image (IndicatorObject * io); static GtkMenu* get_menu (IndicatorObject * io); static const gchar* get_accessible_desc (IndicatorObject * io); +static const gchar* get_name_hint (IndicatorObject * io); G_DEFINE_TYPE (IndicatorPower, indicator_power, INDICATOR_OBJECT_TYPE); @@ -120,6 +121,7 @@ indicator_power_class_init (IndicatorPowerClass *klass) io_class->get_image = get_image; io_class->get_menu = get_menu; io_class->get_accessible_desc = get_accessible_desc; + io_class->get_name_hint = get_name_hint; g_type_class_add_private (klass, sizeof (IndicatorPowerPrivate)); } @@ -966,3 +968,9 @@ get_accessible_desc (IndicatorObject *io) return priv->accessible_desc; } + +static const gchar * +get_name_hint (IndicatorObject *io) +{ + return PACKAGE_NAME; +} -- cgit v1.2.3 From b93d786ba481f09aa56e4666b378c6ac66d6850d Mon Sep 17 00:00:00 2001 From: Allan LeSage Date: Tue, 6 Dec 2011 19:04:27 -0600 Subject: Added coverage reporting via gcov config and targets. --- Makefile.am | 38 ++++++++++++++++++++++++++++ configure.ac | 11 ++++++++ m4/gcov.m4 | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 m4/gcov.m4 diff --git a/Makefile.am b/Makefile.am index 0d4d34b..fbd9e6b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,12 +20,14 @@ libpower_la_SOURCES = \ libpower_la_CFLAGS = \ $(UPOWER_CFLAGS) \ $(INDICATOR_CFLAGS) \ + $(COVERAGE_CFLAGS) \ -Wall -Werror \ -DG_LOG_DOMAIN=\"Indicator-Power\" libpower_la_LIBADD = \ $(UPOWER_LIBS) \ $(INDICATOR_LIBS) libpower_la_LDFLAGS = \ + $(COVERAGE_LDFLAGS) \ -module \ -avoid-version @@ -73,3 +75,39 @@ dist-hook: else \ echo Failed to generate AUTHORS: not a branch >&2; \ fi + + +# Coverage targets + +.PHONY: clean-gcda +clean-gcda: + @echo Removing old coverage results + -find -name '*.gcda' -print | xargs -r rm + +.PHONY: coverage-html generate-coverage-html clean-coverage-html +coverage-html: clean-gcda + -$(MAKE) $(AM_MAKEFLAGS) -k check + $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html + +generate-coverage-html: + @echo Collecting coverage data + $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool + LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info + +clean-coverage-html: clean-gcda + -$(LCOV) --directory $(top_builddir) -z + -rm -rf coverage.info coveragereport + +.PHONY: coverage-xml generate-coverage-xml clean-coverage-xml +coverage-xml: clean-gcda + -$(MAKE) $(AM_MAKEFLAGS) -k check + $(MAKE) $(AM_MAKEFLAGS) generate-coverage-xml + +generate-coverage-xml: + @echo Generating coverage XML report + $(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml + +clean-coverage-xml: clean-gcda + -rm -rf $(top_builddir)/coverage.xml + +clean-local: clean-coverage-html clean-coverage-xml diff --git a/configure.ac b/configure.ac index 2d42c3c..0177f3b 100644 --- a/configure.ac +++ b/configure.ac @@ -47,6 +47,16 @@ PKG_CHECK_MODULES([GSD],[gnome-settings-daemon >= $GSD_REQUIRED_VERSION]) ########################### GLIB_GSETTINGS +########################### +# gcov coverage reporting +########################### + +m4_include([m4/gcov.m4]) +AC_TDD_GCOV +AC_SUBST(COVERAGE_CFLAGS) +AC_SUBST(COVERAGE_CXXFLAGS) +AC_SUBST(COVERAGE_LDFLAGS) + ########################### # Check to see if we're local ########################### @@ -118,4 +128,5 @@ Power Indicator Configuration: Prefix: $prefix Local Install: $with_localinstall + gcov: $use_gcov ]) diff --git a/m4/gcov.m4 b/m4/gcov.m4 new file mode 100644 index 0000000..1169573 --- /dev/null +++ b/m4/gcov.m4 @@ -0,0 +1,83 @@ +# Checks for existence of coverage tools: +# * gcov +# * lcov +# * genhtml +# * gcovr +# +# Sets ac_cv_check_gcov to yes if tooling is present +# and reports the executables to the variables LCOV, GCOVR and GENHTML. +AC_DEFUN([AC_TDD_GCOV], +[AC_CACHE_CHECK([whether code coverage tools are available], ac_cv_check_gcov, +[ +AC_ARG_ENABLE(gcov, + AS_HELP_STRING([--enable-gcov], + [enable coverage testing with gcov]), + [use_gcov=$enableval], [use_gcov=no]) + + if test "x$use_gcov" = "xyes"; then + # we need gcc: + if test "$GCC" != "yes"; then + AC_MSG_ERROR([GCC is required for --enable-gcov]) + fi + + # Check if ccache is being used + AC_CHECK_PROG(SHTOOL, shtool, shtool) + case `$SHTOOL path $CC` in + *ccache*[)] gcc_ccache=yes;; + *[)] gcc_ccache=no;; + esac + + if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then + AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.]) + fi + + lcov_version_list="1.6 1.7 1.8 1.9" + AC_CHECK_PROG(LCOV, lcov, lcov) + AC_CHECK_PROG(GENHTML, genhtml, genhtml) + AC_CHECK_PROG(GCOVR, gcovr, gcovr) + + if test "$LCOV"; then + AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [ + glib_cv_lcov_version=invalid + lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'` + for lcov_check_version in $lcov_version_list; do + if test "$lcov_version" = "$lcov_check_version"; then + glib_cv_lcov_version="$lcov_check_version (ok)" + fi + done + ]) + else + lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list" + AC_MSG_ERROR([$lcov_msg]) + fi + + case $glib_cv_lcov_version in + ""|invalid[)] + lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)." + AC_MSG_ERROR([$lcov_msg]) + LCOV="exit 0;" + ;; + esac + + if test -z "$GENHTML"; then + AC_MSG_ERROR([Could not find genhtml from the lcov package]) + fi + + if test -z "$GCOVR"; then + AC_MSG_ERROR([Could not find gcovr; easy_install (or pip) gcovr]) + fi + + + # Remove all optimization flags from CFLAGS + changequote({,}) + CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'` + changequote([,]) + + # Add the special gcc flags + COVERAGE_CFLAGS="-O0 -fprofile-arcs -ftest-coverage" + COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage" + COVERAGE_LDFLAGS="-lgcov" + +fi +])]) # AC_TDD_GCOV + -- cgit v1.2.3 From aa089d4d002ae4c93a1d1d3757f408ba2cd7c28c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 1 Feb 2012 18:46:00 -0600 Subject: remove redundant prototypes --- src/indicator-power.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index 8dc2788..9287f0b 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -88,8 +88,6 @@ struct _IndicatorPowerPrivate }; /* Prototypes */ -static void indicator_power_class_init (IndicatorPowerClass *klass); -static void indicator_power_init (IndicatorPower *self); static void indicator_power_dispose (GObject *object); static void indicator_power_finalize (GObject *object); -- cgit v1.2.3 From c63e1db05b4063b6d7b1d78e7e52e5d8176cfd67 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 1 Feb 2012 18:50:19 -0600 Subject: don't leak priv->accessible_desc --- src/indicator-power.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index 9287f0b..dcd5db0 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -352,7 +352,7 @@ set_accessible_desc (IndicatorPower *self, { IndicatorPowerPrivate *priv = self->priv; - if (desc == NULL || strlen(desc) == 0) + if (desc == NULL || desc[0] == '\0') return; g_free (priv->accessible_desc); @@ -905,6 +905,10 @@ indicator_power_dispose (GObject *object) static void indicator_power_finalize (GObject *object) { + IndicatorPowerPrivate *priv = INDICATOR_POWER(object)->priv; + + g_free (priv->accessible_desc); + G_OBJECT_CLASS (indicator_power_parent_class)->finalize (object); } -- cgit v1.2.3 From 17626e17645023a17e843bedac589d6218ac38bf Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 1 Feb 2012 18:51:17 -0600 Subject: don't leak priv->settings --- src/indicator-power.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/indicator-power.c b/src/indicator-power.c index dcd5db0..6b95b4c 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -899,6 +899,10 @@ indicator_power_init (IndicatorPower *self) static void indicator_power_dispose (GObject *object) { + IndicatorPowerPrivate *priv = INDICATOR_POWER(object)->priv; + + g_clear_object (&priv->settings); + G_OBJECT_CLASS (indicator_power_parent_class)->dispose (object); } -- cgit v1.2.3 From 85a04b44e3e4f77db07c52ab8667195c6c98cedf Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 1 Feb 2012 18:55:19 -0600 Subject: unref+clear Priv's variant fields in _dispose() --- src/indicator-power.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index 6b95b4c..4eebf3a 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -50,6 +50,11 @@ with this program. If not, see . #define IS_INDICATOR_POWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_POWER_TYPE)) #define INDICATOR_POWER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_POWER_TYPE, IndicatorPowerClass)) +GType indicator_power_get_type (void); + +INDICATOR_SET_VERSION +INDICATOR_SET_TYPE (INDICATOR_POWER_TYPE) + typedef struct _IndicatorPower IndicatorPower; typedef struct _IndicatorPowerClass IndicatorPowerClass; typedef struct _IndicatorPowerPrivate IndicatorPowerPrivate; @@ -66,8 +71,6 @@ struct _IndicatorPowerClass IndicatorObjectClass parent_class; }; -GType indicator_power_get_type (void) G_GNUC_CONST; - struct _IndicatorPowerPrivate { @@ -101,10 +104,6 @@ static const gchar* get_name_hint (IndicatorObject * io); G_DEFINE_TYPE (IndicatorPower, indicator_power, INDICATOR_OBJECT_TYPE); -/* Indicator stuff */ -INDICATOR_SET_VERSION -INDICATOR_SET_TYPE (INDICATOR_POWER_TYPE) - static void indicator_power_class_init (IndicatorPowerClass *klass) @@ -901,6 +900,16 @@ indicator_power_dispose (GObject *object) { IndicatorPowerPrivate *priv = INDICATOR_POWER(object)->priv; + if (priv->devices != NULL) { + g_variant_unref (priv->devices); + priv->devices = NULL; + } + + if (priv->device != NULL) { + g_variant_unref (priv->device); + priv->device = NULL; + } + g_clear_object (&priv->settings); G_OBJECT_CLASS (indicator_power_parent_class)->dispose (object); -- cgit v1.2.3 From 7c8371d127b16cd2fe2893605b6cdf61a94b2451 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 1 Feb 2012 18:58:48 -0600 Subject: group the indicator_power lifecycle funcs together --- src/indicator-power.c | 120 +++++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index 4eebf3a..27202cb 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -100,11 +100,10 @@ static GtkMenu* get_menu (IndicatorObject * io); static const gchar* get_accessible_desc (IndicatorObject * io); static const gchar* get_name_hint (IndicatorObject * io); +static void gsd_appeared_callback (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data); G_DEFINE_TYPE (IndicatorPower, indicator_power, INDICATOR_OBJECT_TYPE); - - static void indicator_power_class_init (IndicatorPowerClass *klass) { @@ -123,6 +122,66 @@ indicator_power_class_init (IndicatorPowerClass *klass) g_type_class_add_private (klass, sizeof (IndicatorPowerPrivate)); } +static void +indicator_power_init (IndicatorPower *self) +{ + IndicatorPowerPrivate *priv; + + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + INDICATOR_POWER_TYPE, + IndicatorPowerPrivate); + priv = self->priv; + + /* Init variables */ + priv->menu = NULL; + priv->accessible_desc = NULL; + + + priv->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION, + DBUS_SERVICE, + G_BUS_NAME_WATCHER_FLAGS_NONE, + gsd_appeared_callback, + NULL, + self, + NULL); + + priv->settings = g_settings_new ("com.canonical.indicator.power"); +} + +static void +indicator_power_dispose (GObject *object) +{ + IndicatorPowerPrivate *priv = INDICATOR_POWER(object)->priv; + + if (priv->devices != NULL) { + g_variant_unref (priv->devices); + priv->devices = NULL; + } + + if (priv->device != NULL) { + g_variant_unref (priv->device); + priv->device = NULL; + } + + g_clear_object (&priv->settings); + + G_OBJECT_CLASS (indicator_power_parent_class)->dispose (object); +} + +static void +indicator_power_finalize (GObject *object) +{ + IndicatorPowerPrivate *priv = INDICATOR_POWER(object)->priv; + + g_free (priv->accessible_desc); + + G_OBJECT_CLASS (indicator_power_parent_class)->finalize (object); +} + +/*** +**** +***/ + static void show_info_cb (GtkMenuItem *item, gpointer data) @@ -868,63 +927,6 @@ gsd_appeared_callback (GDBusConnection *connection, self); } -static void -indicator_power_init (IndicatorPower *self) -{ - IndicatorPowerPrivate *priv; - - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - INDICATOR_POWER_TYPE, - IndicatorPowerPrivate); - priv = self->priv; - - /* Init variables */ - priv->menu = NULL; - priv->accessible_desc = NULL; - - - priv->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION, - DBUS_SERVICE, - G_BUS_NAME_WATCHER_FLAGS_NONE, - gsd_appeared_callback, - NULL, - self, - NULL); - - /* GSettings */ - priv->settings = g_settings_new ("com.canonical.indicator.power"); -} - -static void -indicator_power_dispose (GObject *object) -{ - IndicatorPowerPrivate *priv = INDICATOR_POWER(object)->priv; - - if (priv->devices != NULL) { - g_variant_unref (priv->devices); - priv->devices = NULL; - } - - if (priv->device != NULL) { - g_variant_unref (priv->device); - priv->device = NULL; - } - - g_clear_object (&priv->settings); - - G_OBJECT_CLASS (indicator_power_parent_class)->dispose (object); -} - -static void -indicator_power_finalize (GObject *object) -{ - IndicatorPowerPrivate *priv = INDICATOR_POWER(object)->priv; - - g_free (priv->accessible_desc); - - G_OBJECT_CLASS (indicator_power_parent_class)->finalize (object); -} - -- cgit v1.2.3 From 7cc07d1db1a5bf36479a3db7594e39d6b9d80c30 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 1 Feb 2012 19:05:08 -0600 Subject: remove unused struct names --- src/indicator-power.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index 27202cb..5858b71 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -55,25 +55,12 @@ GType indicator_power_get_type (void); INDICATOR_SET_VERSION INDICATOR_SET_TYPE (INDICATOR_POWER_TYPE) -typedef struct _IndicatorPower IndicatorPower; -typedef struct _IndicatorPowerClass IndicatorPowerClass; -typedef struct _IndicatorPowerPrivate IndicatorPowerPrivate; - -struct _IndicatorPower -{ - IndicatorObject parent_instance; - - IndicatorPowerPrivate *priv; -}; - -struct _IndicatorPowerClass -{ +typedef struct { IndicatorObjectClass parent_class; -}; - +} +IndicatorPowerClass; -struct _IndicatorPowerPrivate -{ +typedef struct { GtkMenu *menu; GtkLabel *label; @@ -88,7 +75,15 @@ struct _IndicatorPowerPrivate GVariant *device; GSettings *settings; -}; +} +IndicatorPowerPrivate; + +typedef struct { + IndicatorObject parent_instance; + + IndicatorPowerPrivate *priv; +} +IndicatorPower; /* Prototypes */ static void indicator_power_dispose (GObject *object); @@ -136,7 +131,6 @@ indicator_power_init (IndicatorPower *self) priv->menu = NULL; priv->accessible_desc = NULL; - priv->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION, DBUS_SERVICE, G_BUS_NAME_WATCHER_FLAGS_NONE, -- cgit v1.2.3 From 4a6c62934fa66ade8842ffc9e0075291c11952dd Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 1 Feb 2012 19:24:34 -0600 Subject: remove unnecessary Priv struct -- the =entire class= is private --- src/indicator-power.c | 140 ++++++++++++++++++++------------------------------ 1 file changed, 56 insertions(+), 84 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index 5858b71..c833673 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -61,6 +61,8 @@ typedef struct { IndicatorPowerClass; typedef struct { + IndicatorObject parent_instance; + GtkMenu *menu; GtkLabel *label; @@ -76,13 +78,6 @@ typedef struct { GSettings *settings; } -IndicatorPowerPrivate; - -typedef struct { - IndicatorObject parent_instance; - - IndicatorPowerPrivate *priv; -} IndicatorPower; /* Prototypes */ @@ -113,25 +108,15 @@ indicator_power_class_init (IndicatorPowerClass *klass) io_class->get_menu = get_menu; io_class->get_accessible_desc = get_accessible_desc; io_class->get_name_hint = get_name_hint; - - g_type_class_add_private (klass, sizeof (IndicatorPowerPrivate)); } static void indicator_power_init (IndicatorPower *self) { - IndicatorPowerPrivate *priv; - - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - INDICATOR_POWER_TYPE, - IndicatorPowerPrivate); - priv = self->priv; + self->menu = NULL; + self->accessible_desc = NULL; - /* Init variables */ - priv->menu = NULL; - priv->accessible_desc = NULL; - - priv->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION, + self->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION, DBUS_SERVICE, G_BUS_NAME_WATCHER_FLAGS_NONE, gsd_appeared_callback, @@ -139,25 +124,25 @@ indicator_power_init (IndicatorPower *self) self, NULL); - priv->settings = g_settings_new ("com.canonical.indicator.power"); + self->settings = g_settings_new ("com.canonical.indicator.power"); } static void indicator_power_dispose (GObject *object) { - IndicatorPowerPrivate *priv = INDICATOR_POWER(object)->priv; + IndicatorPower *self = INDICATOR_POWER(object); - if (priv->devices != NULL) { - g_variant_unref (priv->devices); - priv->devices = NULL; + if (self->devices != NULL) { + g_variant_unref (self->devices); + self->devices = NULL; } - if (priv->device != NULL) { - g_variant_unref (priv->device); - priv->device = NULL; + if (self->device != NULL) { + g_variant_unref (self->device); + self->device = NULL; } - g_clear_object (&priv->settings); + g_clear_object (&self->settings); G_OBJECT_CLASS (indicator_power_parent_class)->dispose (object); } @@ -165,9 +150,9 @@ indicator_power_dispose (GObject *object) static void indicator_power_finalize (GObject *object) { - IndicatorPowerPrivate *priv = INDICATOR_POWER(object)->priv; + IndicatorPower *self = INDICATOR_POWER(object); - g_free (priv->accessible_desc); + g_free (self->accessible_desc); G_OBJECT_CLASS (indicator_power_parent_class)->finalize (object); } @@ -192,15 +177,14 @@ option_toggled_cb (GtkCheckMenuItem *item, gpointer user_data) { 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_widget_set_visible (GTK_WIDGET (self->label), visible); - g_settings_set_boolean (priv->settings, "show-time", + g_settings_set_boolean (self->settings, "show-time", visible); } @@ -402,14 +386,12 @@ static void set_accessible_desc (IndicatorPower *self, const gchar *desc) { - IndicatorPowerPrivate *priv = self->priv; - if (desc == NULL || desc[0] == '\0') return; - g_free (priv->accessible_desc); + g_free (self->accessible_desc); - priv->accessible_desc = g_strdup (desc); + self->accessible_desc = g_strdup (desc); } static const gchar * @@ -609,38 +591,37 @@ get_greeter_mode (void) static void build_menu (IndicatorPower *self) { - IndicatorPowerPrivate *priv = self->priv; GtkWidget *item; GtkWidget *image; GList *children; gsize n_devices = 0; gboolean visible; - if (priv->menu == NULL) - priv->menu = GTK_MENU (gtk_menu_new ()); + if (self->menu == NULL) + self->menu = GTK_MENU (gtk_menu_new ()); - children = gtk_container_get_children (GTK_CONTAINER (priv->menu)); + children = gtk_container_get_children (GTK_CONTAINER (self->menu)); g_list_foreach (children, (GFunc) gtk_widget_destroy, NULL); g_list_free (children); /* devices */ - n_devices = menu_add_devices (priv->menu, priv->devices); + n_devices = menu_add_devices (self->menu, self->devices); if (!get_greeter_mode ()) { /* only do the separator if we have at least one device */ if (n_devices != 0) { item = gtk_separator_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), item); + gtk_menu_shell_append (GTK_MENU_SHELL (self->menu), item); } /* options */ 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"); + visible = g_settings_get_boolean (self->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); + gtk_menu_shell_append (GTK_MENU_SHELL (self->menu), item); /* preferences */ item = gtk_image_menu_item_new_with_label (_("Power Settings...")); @@ -648,11 +629,11 @@ build_menu (IndicatorPower *self) gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (show_preferences_cb), NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), item); + gtk_menu_shell_append (GTK_MENU_SHELL (self->menu), item); } /* show the menu */ - gtk_widget_show_all (GTK_WIDGET (priv->menu)); + gtk_widget_show_all (GTK_WIDGET (self->menu)); } static GVariant * @@ -749,7 +730,6 @@ static void put_primary_device (IndicatorPower *self, GVariant *device) { - IndicatorPowerPrivate *priv = self->priv; UpDeviceKind kind; UpDeviceState state; GIcon *device_gicons; @@ -776,10 +756,10 @@ put_primary_device (IndicatorPower *self, /* set icon */ device_gicons = get_device_icon (kind, state, time, device_icon); - gtk_image_set_from_gicon (priv->status_image, + gtk_image_set_from_gicon (self->status_image, device_gicons, GTK_ICON_SIZE_LARGE_TOOLBAR); - gtk_widget_show (GTK_WIDGET (priv->status_image)); + gtk_widget_show (GTK_WIDGET (self->status_image)); /* get the device name */ @@ -788,7 +768,7 @@ put_primary_device (IndicatorPower *self, /* get the description */ build_device_time_details (device_name, time, state, percentage, &short_details, &details, &accesible_name); - gtk_label_set_label (GTK_LABEL (priv->label), + gtk_label_set_label (GTK_LABEL (self->label), short_details); set_accessible_desc (self, accesible_name); @@ -805,7 +785,6 @@ get_devices_cb (GObject *source_object, gpointer user_data) { IndicatorPower *self = INDICATOR_POWER (user_data); - IndicatorPowerPrivate *priv = self->priv; GVariant *devices_container; GError *error = NULL; @@ -817,18 +796,18 @@ get_devices_cb (GObject *source_object, return; } - priv->devices = g_variant_get_child_value (devices_container, 0); + self->devices = g_variant_get_child_value (devices_container, 0); g_variant_unref (devices_container); - priv->device = get_primary_device (priv->devices); - if (priv->device == NULL) + self->device = get_primary_device (self->devices); + if (self->device == NULL) { g_printerr ("Error getting primary device"); return; } - put_primary_device (self, priv->device); + put_primary_device (self, self->device); build_menu (self); } @@ -841,17 +820,16 @@ receive_signal (GDBusProxy *proxy, gpointer user_data) { IndicatorPower *self = INDICATOR_POWER (user_data); - IndicatorPowerPrivate *priv = self->priv; if (g_strcmp0 (signal_name, "Changed") == 0) { /* get the new state */ - g_dbus_proxy_call (priv->proxy, + g_dbus_proxy_call (self->proxy, "GetDevices", NULL, G_DBUS_CALL_FLAGS_NONE, -1, - priv->proxy_cancel, + self->proxy_cancel, get_devices_cb, user_data); } @@ -863,15 +841,14 @@ service_proxy_cb (GObject *object, gpointer user_data) { IndicatorPower *self = INDICATOR_POWER (user_data); - IndicatorPowerPrivate *priv = self->priv; GError *error = NULL; - priv->proxy = g_dbus_proxy_new_for_bus_finish (res, &error); + self->proxy = g_dbus_proxy_new_for_bus_finish (res, &error); - if (priv->proxy_cancel != NULL) + if (self->proxy_cancel != NULL) { - g_object_unref (priv->proxy_cancel); - priv->proxy_cancel = NULL; + g_object_unref (self->proxy_cancel); + self->proxy_cancel = NULL; } if (error != NULL) @@ -883,18 +860,18 @@ service_proxy_cb (GObject *object, } /* we want to change the primary device changes */ - g_signal_connect (priv->proxy, + g_signal_connect (self->proxy, "g-signal", G_CALLBACK (receive_signal), user_data); /* get the initial state */ - g_dbus_proxy_call (priv->proxy, + g_dbus_proxy_call (self->proxy, "GetDevices", NULL, G_DBUS_CALL_FLAGS_NONE, -1, - priv->proxy_cancel, + self->proxy_cancel, get_devices_cb, user_data); } @@ -906,9 +883,8 @@ gsd_appeared_callback (GDBusConnection *connection, gpointer user_data) { IndicatorPower *self = INDICATOR_POWER (user_data); - IndicatorPowerPrivate *priv = self->priv; - priv->proxy_cancel = g_cancellable_new (); + self->proxy_cancel = g_cancellable_new (); g_dbus_proxy_new (connection, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, @@ -916,7 +892,7 @@ gsd_appeared_callback (GDBusConnection *connection, name, POWER_DBUS_PATH, POWER_DBUS_INTERFACE, - priv->proxy_cancel, + self->proxy_cancel, service_proxy_cb, self); } @@ -930,54 +906,50 @@ static GtkLabel * get_label (IndicatorObject *io) { IndicatorPower *self = INDICATOR_POWER (io); - IndicatorPowerPrivate *priv = self->priv; - if (priv->label == NULL) + if (self->label == NULL) { /* Create the label if it doesn't exist already */ - priv->label = GTK_LABEL (gtk_label_new ("")); - gtk_widget_set_visible (GTK_WIDGET (priv->label), FALSE); + self->label = GTK_LABEL (gtk_label_new ("")); + gtk_widget_set_visible (GTK_WIDGET (self->label), FALSE); } - return priv->label; + return self->label; } static GtkImage * get_image (IndicatorObject *io) { IndicatorPower *self = INDICATOR_POWER (io); - IndicatorPowerPrivate *priv = self->priv; GIcon *gicon; - if (priv->status_image == NULL) + if (self->status_image == NULL) { /* Will create the status icon if it doesn't exist already */ gicon = g_themed_icon_new (DEFAULT_ICON); - priv->status_image = GTK_IMAGE (gtk_image_new_from_gicon (gicon, + self->status_image = GTK_IMAGE (gtk_image_new_from_gicon (gicon, GTK_ICON_SIZE_LARGE_TOOLBAR)); } - return priv->status_image; + return self->status_image; } static GtkMenu * get_menu (IndicatorObject *io) { IndicatorPower *self = INDICATOR_POWER (io); - IndicatorPowerPrivate *priv = self->priv; build_menu (self); - return GTK_MENU (priv->menu); + return GTK_MENU (self->menu); } static const gchar * get_accessible_desc (IndicatorObject *io) { IndicatorPower *self = INDICATOR_POWER (io); - IndicatorPowerPrivate *priv = self->priv; - return priv->accessible_desc; + return self->accessible_desc; } static const gchar * -- cgit v1.2.3 From aacad61c29de5f9d702f84fc425a60561425ebac Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 1 Feb 2012 19:26:30 -0600 Subject: use g_clear_object() on the proxy_cancel field --- src/indicator-power.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index c833673..6280d4c 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -845,11 +845,7 @@ service_proxy_cb (GObject *object, self->proxy = g_dbus_proxy_new_for_bus_finish (res, &error); - if (self->proxy_cancel != NULL) - { - g_object_unref (self->proxy_cancel); - self->proxy_cancel = NULL; - } + g_clear_object (&self->proxy_cancel); if (error != NULL) { -- cgit v1.2.3 From 98a2abe1e732fb0110dbf7785569f3a5c0455dca Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 1 Feb 2012 19:28:39 -0600 Subject: remove redundant #include of glib.h --- src/indicator-power.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index 6280d4c..4bf9a6f 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -24,7 +24,6 @@ with this program. If not, see . #endif /* GStuff */ -#include #include #include #include -- cgit v1.2.3 From da453ec039c78d60ebad64226367780037621197 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 1 Feb 2012 19:33:47 -0600 Subject: better error reporting if g_spawn_command_line_async() fails --- src/indicator-power.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index 4bf9a6f..dc1007d 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -160,15 +160,21 @@ indicator_power_finalize (GObject *object) **** ***/ +static void +spawn_command_line_async (const char * command) +{ + GError * err = NULL; + if (!g_spawn_command_line_async (command, &err)) + g_warning ("Couldn't execute command \"%s\": %s", command, err->message); + g_clear_error (&err); +} + static void show_info_cb (GtkMenuItem *item, gpointer data) { /*TODO: show the statistics of the specific device*/ - const gchar *command = "gnome-power-statistics"; - - if (g_spawn_command_line_async (command, NULL) == FALSE) - g_warning ("Couldn't execute command: %s", command); + spawn_command_line_async ("gnome-power-statistics"); } static void @@ -191,10 +197,7 @@ static void show_preferences_cb (GtkMenuItem *item, gpointer data) { - const gchar *command = "gnome-control-center power"; - - if (g_spawn_command_line_async (command, NULL) == FALSE) - g_warning ("Couldn't execute command: %s", command); + spawn_command_line_async ("gnome-control-center power"); } static void -- cgit v1.2.3 From 33beea08d1a833a3517b1a7a858d14ecc438017c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 1 Feb 2012 22:51:26 -0600 Subject: use g_settings_bind() for the show-time checkbox --- src/indicator-power.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index dc1007d..f91119d 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -178,19 +178,10 @@ show_info_cb (GtkMenuItem *item, } static void -option_toggled_cb (GtkCheckMenuItem *item, - gpointer user_data) +option_toggled_cb (GtkCheckMenuItem *item, IndicatorPower * self) { - IndicatorPower *self = INDICATOR_POWER (user_data); - gboolean visible; - - visible = gtk_check_menu_item_get_active (item); - gtk_widget_set_visible (GTK_WIDGET (self->label), - visible); - - g_settings_set_boolean (self->settings, "show-time", - visible); + gtk_check_menu_item_get_active(item)); } static void @@ -597,7 +588,6 @@ build_menu (IndicatorPower *self) GtkWidget *image; GList *children; gsize n_devices = 0; - gboolean visible; if (self->menu == NULL) self->menu = GTK_MENU (gtk_menu_new ()); @@ -619,10 +609,8 @@ build_menu (IndicatorPower *self) /* options */ 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 (self->settings, "show-time"); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), visible); + g_signal_connect (item, "toggled", G_CALLBACK(option_toggled_cb), self); + g_settings_bind (self->settings, "show-time", item, "active", G_SETTINGS_BIND_DEFAULT); gtk_menu_shell_append (GTK_MENU_SHELL (self->menu), item); /* preferences */ -- cgit v1.2.3 From f9dc8cc28aa8dcffbec8f010d71234119d6d889d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 1 Feb 2012 22:53:16 -0600 Subject: create the menu at init time s.t. we don't have to keep checking to see if it exists --- src/indicator-power.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index f91119d..e359a03 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -112,7 +112,8 @@ indicator_power_class_init (IndicatorPowerClass *klass) static void indicator_power_init (IndicatorPower *self) { - self->menu = NULL; + self->menu = GTK_MENU(gtk_menu_new()); + self->accessible_desc = NULL; self->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION, @@ -589,9 +590,7 @@ build_menu (IndicatorPower *self) GList *children; gsize n_devices = 0; - if (self->menu == NULL) - self->menu = GTK_MENU (gtk_menu_new ()); - + /* remove the existing menuitems */ children = gtk_container_get_children (GTK_CONTAINER (self->menu)); g_list_foreach (children, (GFunc) gtk_widget_destroy, NULL); g_list_free (children); -- cgit v1.2.3 From 4b5ec3d0baaf4bb377ad1cb05a88e62408e14a28 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 1 Feb 2012 23:00:03 -0600 Subject: add support for icon-policy setting --- data/com.canonical.indicator.power.gschema.xml.in | 12 +- src/indicator-power.c | 129 +++++++++++++++++++--- 2 files changed, 127 insertions(+), 14 deletions(-) diff --git a/data/com.canonical.indicator.power.gschema.xml.in b/data/com.canonical.indicator.power.gschema.xml.in index bf4368f..3fb065f 100644 --- a/data/com.canonical.indicator.power.gschema.xml.in +++ b/data/com.canonical.indicator.power.gschema.xml.in @@ -1,9 +1,19 @@ + + + + + false <_summary>Show time in Menu Bar - <_description>Whether show the time in the menu bar. + <_description>Whether or not to show the time in the menu bar. + + + "present" + <_summary>When to show the battery status in the menu bar. + <_description>Options for when to show battery status. Valid options are "present", "charge", and "never". diff --git a/src/indicator-power.c b/src/indicator-power.c index e359a03..4b84b26 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -35,6 +35,8 @@ with this program. If not, see . #include #include +#define ICON_POLICY_KEY "icon-policy" + #define DEFAULT_ICON "gpm-battery-missing" #define DBUS_SERVICE "org.gnome.SettingsDaemon" @@ -76,6 +78,8 @@ typedef struct { GVariant *device; GSettings *settings; + + gboolean visible; } IndicatorPower; @@ -89,6 +93,9 @@ static GtkMenu* get_menu (IndicatorObject * io); static const gchar* get_accessible_desc (IndicatorObject * io); static const gchar* get_name_hint (IndicatorObject * io); +static void update_visibility (IndicatorPower * self); +static gboolean should_be_visible (IndicatorPower * self); + static void gsd_appeared_callback (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data); G_DEFINE_TYPE (IndicatorPower, indicator_power, INDICATOR_OBJECT_TYPE); @@ -116,6 +123,8 @@ indicator_power_init (IndicatorPower *self) self->accessible_desc = NULL; + self->visible = FALSE; + self->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION, DBUS_SERVICE, G_BUS_NAME_WATCHER_FLAGS_NONE, @@ -125,6 +134,11 @@ indicator_power_init (IndicatorPower *self) NULL); self->settings = g_settings_new ("com.canonical.indicator.power"); + g_signal_connect_swapped (G_OBJECT(self->settings), "changed::" ICON_POLICY_KEY, + G_CALLBACK(update_visibility), self); + g_object_set (G_OBJECT(self), + INDICATOR_OBJECT_DEFAULT_VISIBILITY, self->visible, + NULL); } static void @@ -645,7 +659,7 @@ get_primary_device (GVariant *devices) gsize n_devices; guint i; - n_devices = g_variant_n_children (devices); + n_devices = devices ? g_variant_n_children (devices) : 0; g_debug ("Num devices: '%" G_GSIZE_FORMAT "'\n", n_devices); for (i = 0; i < n_devices; i++) @@ -780,25 +794,46 @@ get_devices_cb (GObject *source_object, devices_container = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); if (devices_container == NULL) { - g_printerr ("Error getting devices: %s\n", error->message); + g_message ("Couldn't get devices: %s\n", error->message); g_error_free (error); - - return; } - self->devices = g_variant_get_child_value (devices_container, 0); - g_variant_unref (devices_container); - - self->device = get_primary_device (self->devices); - if (self->device == NULL) + else /* update 'devices' */ { - g_printerr ("Error getting primary device"); + if (self->devices != NULL) + g_variant_unref (self->devices); + self->devices = g_variant_get_child_value (devices_container, 0); - return; - } + g_variant_unref (devices_container); - put_primary_device (self, self->device); + if (self->device != NULL) + g_variant_unref (self->device); + self->device = get_primary_device (self->devices); + + if (self->device == NULL) + { + g_message ("Couldn't find primary device"); + } + else + { + put_primary_device (self, self->device); + } + } build_menu (self); + + update_visibility (self); +} + +static void +update_visibility (IndicatorPower * self) +{ + const gboolean visible = should_be_visible (self); + + if (self->visible != visible) + { + self->visible = visible; + indicator_object_set_visible (INDICATOR_OBJECT (self), visible); + } } static void @@ -942,3 +977,71 @@ get_name_hint (IndicatorObject *io) { return PACKAGE_NAME; } + +/*** +**** +***/ + +static void +count_batteries(GVariant *devices, int *total, int *inuse) +{ + const int n_devices = devices ? g_variant_n_children (devices) : 0; + + int i; + for (i=0; isettings, "icon-policy"); + + g_debug ("icon_policy is: %d (present==0, charge==1, never==2)", icon_policy); + + if (icon_policy == POWER_INDICATOR_ICON_POLICY_NEVER) + { + visible = FALSE; + } + else + { + int batteries=0, inuse=0; + count_batteries (self->devices, &batteries, &inuse); + + if (icon_policy == POWER_INDICATOR_ICON_POLICY_PRESENT) + { + visible = batteries > 0; + } + else if (icon_policy == POWER_INDICATOR_ICON_POLICY_CHARGE) + { + visible = inuse > 0; + } + } + + g_debug ("should_be_visible: %s", visible?"yes":"no"); + return visible; +} -- cgit v1.2.3 From 695ba1e2dba25a8974e618b58c4d200cd1b6e8f3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 13 Feb 2012 14:10:22 -0600 Subject: make prototypes for update_visibility() and should_be_visible() align with the neighboring forward declarations --- src/indicator-power.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index 4b84b26..bdec98e 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -93,8 +93,8 @@ static GtkMenu* get_menu (IndicatorObject * io); static const gchar* get_accessible_desc (IndicatorObject * io); static const gchar* get_name_hint (IndicatorObject * io); -static void update_visibility (IndicatorPower * self); -static gboolean should_be_visible (IndicatorPower * self); +static void update_visibility (IndicatorPower * self); +static gboolean should_be_visible (IndicatorPower * self); static void gsd_appeared_callback (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data); -- cgit v1.2.3 From f7d828a76741af2dd2652bff7d17e5b9d6764ced Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 13 Feb 2012 14:14:09 -0600 Subject: remove unnecessary G_OBJECT() cast --- src/indicator-power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index bdec98e..d000365 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -134,7 +134,7 @@ indicator_power_init (IndicatorPower *self) NULL); self->settings = g_settings_new ("com.canonical.indicator.power"); - g_signal_connect_swapped (G_OBJECT(self->settings), "changed::" ICON_POLICY_KEY, + g_signal_connect_swapped (self->settings, "changed::" ICON_POLICY_KEY, G_CALLBACK(update_visibility), self); g_object_set (G_OBJECT(self), INDICATOR_OBJECT_DEFAULT_VISIBILITY, self->visible, -- cgit v1.2.3 From cb4bd9d9338e07504365491c1b45bf7918fdc8bc Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 13 Feb 2012 14:15:28 -0600 Subject: consistent use of ICON_POLICY_KEY --- src/indicator-power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index d000365..90db2f9 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -1019,7 +1019,7 @@ should_be_visible (IndicatorPower * self) { gboolean visible = TRUE; - const int icon_policy = g_settings_get_enum (self->settings, "icon-policy"); + const int icon_policy = g_settings_get_enum (self->settings, ICON_POLICY_KEY); g_debug ("icon_policy is: %d (present==0, charge==1, never==2)", icon_policy); -- cgit v1.2.3 From 0c1e774b428c6ccb76e6ad9e0de9e809b56790fa Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 13 Feb 2012 14:18:56 -0600 Subject: remove unncessary private field 'visible' --- src/indicator-power.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index 90db2f9..bbd00d8 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -78,8 +78,6 @@ typedef struct { GVariant *device; GSettings *settings; - - gboolean visible; } IndicatorPower; @@ -123,8 +121,6 @@ indicator_power_init (IndicatorPower *self) self->accessible_desc = NULL; - self->visible = FALSE; - self->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION, DBUS_SERVICE, G_BUS_NAME_WATCHER_FLAGS_NONE, @@ -137,7 +133,7 @@ indicator_power_init (IndicatorPower *self) g_signal_connect_swapped (self->settings, "changed::" ICON_POLICY_KEY, G_CALLBACK(update_visibility), self); g_object_set (G_OBJECT(self), - INDICATOR_OBJECT_DEFAULT_VISIBILITY, self->visible, + INDICATOR_OBJECT_DEFAULT_VISIBILITY, FALSE, NULL); } @@ -827,13 +823,8 @@ get_devices_cb (GObject *source_object, static void update_visibility (IndicatorPower * self) { - const gboolean visible = should_be_visible (self); - - if (self->visible != visible) - { - self->visible = visible; - indicator_object_set_visible (INDICATOR_OBJECT (self), visible); - } + indicator_object_set_visible (INDICATOR_OBJECT (self), + should_be_visible (self)); } static void -- cgit v1.2.3 From 8be6c2d51d4927d524370b4f5bab39b6e72bbc0d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 13 Feb 2012 14:20:34 -0600 Subject: move POWER_INDICATOR_ICON_POLICY_* enum to the top of the file --- src/indicator-power.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index bbd00d8..ee20362 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -51,6 +51,12 @@ with this program. If not, see . #define IS_INDICATOR_POWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_POWER_TYPE)) #define INDICATOR_POWER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_POWER_TYPE, IndicatorPowerClass)) +enum { + POWER_INDICATOR_ICON_POLICY_PRESENT, + POWER_INDICATOR_ICON_POLICY_CHARGE, + POWER_INDICATOR_ICON_POLICY_NEVER +}; + GType indicator_power_get_type (void); INDICATOR_SET_VERSION @@ -999,12 +1005,6 @@ count_batteries(GVariant *devices, int *total, int *inuse) g_debug("count_batteries found %d batteries (%d are charging/discharging)", *total, *inuse); } -enum { - POWER_INDICATOR_ICON_POLICY_PRESENT, - POWER_INDICATOR_ICON_POLICY_CHARGE, - POWER_INDICATOR_ICON_POLICY_NEVER -}; - static gboolean should_be_visible (IndicatorPower * self) { -- cgit v1.2.3 From aee1300b7e026c7724859c019599ea3739721c78 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 13 Feb 2012 14:26:23 -0600 Subject: ensure that we don't have a reference to the proxy or proxy_cancel fields in indicator_power_dispose(). --- src/indicator-power.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/indicator-power.c b/src/indicator-power.c index ee20362..f7de038 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -158,6 +158,9 @@ indicator_power_dispose (GObject *object) self->device = NULL; } + g_clear_object (&self->proxy); + g_clear_object (&self->proxy_cancel); + g_clear_object (&self->settings); G_OBJECT_CLASS (indicator_power_parent_class)->dispose (object); -- cgit v1.2.3 From 4a60cd5e9ad0384e5bed98a2d70e9c02832a4286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Tue, 14 Feb 2012 13:05:41 +0000 Subject: Code style fixes --- src/indicator-power.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index f7de038..84bd4c1 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -44,6 +44,12 @@ with this program. If not, see . #define POWER_DBUS_PATH DBUS_PATH "/Power" #define POWER_DBUS_INTERFACE "org.gnome.SettingsDaemon.Power" +enum { + POWER_INDICATOR_ICON_POLICY_PRESENT, + POWER_INDICATOR_ICON_POLICY_CHARGE, + POWER_INDICATOR_ICON_POLICY_NEVER +}; + #define INDICATOR_POWER_TYPE (indicator_power_get_type ()) #define INDICATOR_POWER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_POWER_TYPE, IndicatorPower)) #define INDICATOR_POWER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_POWER_TYPE, IndicatorPowerClass)) @@ -51,23 +57,16 @@ with this program. If not, see . #define IS_INDICATOR_POWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_POWER_TYPE)) #define INDICATOR_POWER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_POWER_TYPE, IndicatorPowerClass)) -enum { - POWER_INDICATOR_ICON_POLICY_PRESENT, - POWER_INDICATOR_ICON_POLICY_CHARGE, - POWER_INDICATOR_ICON_POLICY_NEVER -}; - -GType indicator_power_get_type (void); +typedef struct _IndicatorPowerClass IndicatorPowerClass; +typedef struct _IndicatorPower IndicatorPower; -INDICATOR_SET_VERSION -INDICATOR_SET_TYPE (INDICATOR_POWER_TYPE) - -typedef struct { +struct _IndicatorPowerClass +{ IndicatorObjectClass parent_class; -} -IndicatorPowerClass; +}; -typedef struct { +struct _IndicatorPower +{ IndicatorObject parent_instance; GtkMenu *menu; @@ -84,8 +83,12 @@ typedef struct { GVariant *device; GSettings *settings; -} -IndicatorPower; +}; + +GType indicator_power_get_type (void); + +INDICATOR_SET_VERSION +INDICATOR_SET_TYPE (INDICATOR_POWER_TYPE) /* Prototypes */ static void indicator_power_dispose (GObject *object); -- cgit v1.2.3 From 207267adc55aad9810afb4eb2e04ca86c4289f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Tue, 14 Feb 2012 13:06:16 +0000 Subject: Use G_GNUC_CONST for indicator_power_get_type() to improve performance --- src/indicator-power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index 84bd4c1..3980988 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -85,7 +85,7 @@ struct _IndicatorPower GSettings *settings; }; -GType indicator_power_get_type (void); +GType indicator_power_get_type (void) G_GNUC_CONST; INDICATOR_SET_VERSION INDICATOR_SET_TYPE (INDICATOR_POWER_TYPE) -- cgit v1.2.3 From 612662f401ef931eea0d5e8c25319c4326cd2c2d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Feb 2012 16:06:04 -0600 Subject: Make data have it's own makefile so the GSettings rules work properly on distcheck --- Makefile.am | 21 +++------------------ configure.ac | 1 + data/Makefile.am | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 data/Makefile.am diff --git a/Makefile.am b/Makefile.am index fbd9e6b..0ef4362 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,13 +1,8 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} -SUBDIRS = po - -gsettings_in_file = data/com.canonical.indicator.power.gschema.xml.in -gsettings_SCHEMAS = $(gsettings_in_file:.xml.in=.xml) - -@INTLTOOL_XML_NOMERGE_RULE@ - -@GSETTINGS_RULES@ +SUBDIRS = \ + po \ + data ################### # Indicator Stuff @@ -36,16 +31,6 @@ libpower_la_LDFLAGS = \ dist_noinst_SCRIPTS = \ autogen.sh -dist_noinst_DATA = \ - data/com.canonical.indicator.power.gschema.xml \ - $(gsettings_in_file) - -CLEANFILES = \ - $(gsettings_SCHEMAS) - -MAINTAINERCLEANFILES = \ - $(gsettings_SCHEMAS:.xml=.valid) - DISTCHECK_CONFIGURE_FLAGS = --enable-localinstall ############################################################ diff --git a/configure.ac b/configure.ac index 0177f3b..2d519d6 100644 --- a/configure.ac +++ b/configure.ac @@ -115,6 +115,7 @@ AC_DEFINE([GETTEXT_PACKAGE],[PACKAGE_TARNAME],[Define to the gettext package nam AC_CONFIG_FILES([ Makefile po/Makefile.in +data/Makefile ]) AC_OUTPUT diff --git a/data/Makefile.am b/data/Makefile.am new file mode 100644 index 0000000..375c7ca --- /dev/null +++ b/data/Makefile.am @@ -0,0 +1,17 @@ + +gsettings_in_file = com.canonical.indicator.power.gschema.xml.in +gsettings_SCHEMAS = $(gsettings_in_file:.xml.in=.xml) + +@INTLTOOL_XML_NOMERGE_RULE@ + +@GSETTINGS_RULES@ + +dist_noinst_DATA = \ + com.canonical.indicator.power.gschema.xml \ + $(gsettings_in_file) + +CLEANFILES = \ + $(gsettings_SCHEMAS) + +MAINTAINERCLEANFILES = \ + $(gsettings_SCHEMAS:.xml=.valid) -- cgit v1.2.3 From 1651ec12b187309fbf8934d37540e38a515409dd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Feb 2012 16:11:20 -0600 Subject: 1.90 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 2d519d6..406a93c 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_INIT([indicator-power], - [0.10], + [1.90], [http://bugs.launchpad.net/indicator-power], [indicator-power], [http://launchpad.net/indicator-power]) -- cgit v1.2.3 From b33fcf3e703f9c6ed8e0be1aae92263e8697c551 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Feb 2012 16:26:51 -0600 Subject: releasing version 1.90-0ubuntu1~ppa1 --- debian/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 7764666..149d222 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,10 +1,10 @@ -indicator-power (1.90-0ubuntu1~ppa1) UNRELEASED; urgency=low +indicator-power (1.90-0ubuntu1~ppa1) precise; urgency=low * New upstream release. * Support for hiding of icon and settings for it as well * Adding a name hint - -- Ted Gould Tue, 14 Feb 2012 16:26:02 -0600 + -- Ted Gould Tue, 14 Feb 2012 16:26:48 -0600 indicator-power (0.10-0ubuntu2) precise; urgency=low -- cgit v1.2.3