diff options
Diffstat (limited to 'src/service.c')
-rw-r--r-- | src/service.c | 127 |
1 files changed, 38 insertions, 89 deletions
diff --git a/src/service.c b/src/service.c index 85ac263..2670a67 100644 --- a/src/service.c +++ b/src/service.c @@ -113,8 +113,6 @@ struct _IndicatorPowerServicePrivate GSimpleActionGroup * actions; GSimpleAction * header_action; - GSimpleAction * show_time_action; - GSimpleAction * show_percentage_action; GSimpleAction * battery_level_action; GSimpleAction * brightness_action; @@ -342,7 +340,13 @@ create_header_state (IndicatorPowerService * self) if (icon != NULL) { - g_variant_builder_add (&b, "{sv}", "icon", g_icon_serialize (icon)); + GVariant * v; + + if ((v = g_icon_serialize (icon))) + { + g_variant_builder_add (&b, "{sv}", "icon", v); + g_variant_unref (v); + } g_object_unref (icon); } @@ -367,28 +371,30 @@ append_device_to_menu (GMenu * menu, const IndicatorPowerDevice * device) if (kind != UP_DEVICE_KIND_LINE_POWER) { - GIcon * icon; char * label; - char * action; - GMenuItem * menu_item; + GMenuItem * item; + GIcon * icon; - icon = indicator_power_device_get_gicon (device); label = indicator_power_device_get_label (device); - action = g_strconcat ("indicator.activate-statistics::", - indicator_power_device_get_object_path (device), NULL); - menu_item = g_menu_item_new (label, action); - g_free (action); - - if (icon != NULL) - g_menu_item_set_attribute_value (menu_item, - G_MENU_ATTRIBUTE_ICON, - g_icon_serialize (icon)); - - g_menu_append_item (menu, menu_item); - g_object_unref (menu_item); - - g_clear_object (&icon); + item = g_menu_item_new (label, "indicator.activate-statistics"); g_free (label); + g_menu_item_set_action_and_target(item, "indicator.activate-statistics", "s", + indicator_power_device_get_object_path (device)); + + if ((icon = indicator_power_device_get_gicon (device))) + { + GVariant * v; + if ((v = g_icon_serialize (icon))) + { + g_menu_item_set_attribute_value (item, G_MENU_ATTRIBUTE_ICON, v); + g_variant_unref (v); + } + + g_object_unref (icon); + } + + g_menu_append_item (menu, item); + g_object_unref (item); } } @@ -463,7 +469,7 @@ create_brightness_menuitem (IndicatorPowerService * self) get_brightness_range (self, &lo, &hi); - item = g_menu_item_new ("Brightness", "indicator.brightness"); + item = g_menu_item_new (NULL, "indicator.brightness"); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.unity.slider"); g_menu_item_set_attribute (item, "min-value", "d", brightness_to_percentage (self, lo)); g_menu_item_set_attribute (item, "max-value", "d", brightness_to_percentage (self, hi)); @@ -712,39 +718,12 @@ on_phone_settings_activated (GSimpleAction * a G_GNUC_UNUSED, **** ***/ -/* toggles the state */ -static void -on_toggle_action_activated (GSimpleAction * simple, - GVariant * parameter G_GNUC_UNUSED, - gpointer unused G_GNUC_UNUSED) -{ - GVariant * v = g_action_get_state (G_ACTION (simple)); - gboolean flag = g_variant_get_boolean (v); - g_simple_action_set_state (simple, g_variant_new_boolean (!flag)); - g_variant_unref (v); -} - -static gboolean -settings_to_action_state (GValue * value, - GVariant * variant, - gpointer user_data G_GNUC_UNUSED) -{ - g_value_set_variant (value, variant); - return TRUE; -} - -static GVariant * -action_state_to_settings (const GValue * value, - const GVariantType * expected_type G_GNUC_UNUSED, - gpointer user_data G_GNUC_UNUSED) -{ - return g_value_dup_variant (value); -} - static void init_gactions (IndicatorPowerService * self) { GSimpleAction * a; + GAction * show_time_action; + GAction * show_percentage_action; priv_t * p = self->priv; GActionEntry entries[] = { @@ -778,32 +757,17 @@ init_gactions (IndicatorPowerService * self) p->brightness_action = a; /* add the show-time action */ - a = g_simple_action_new ("show-time", NULL); - g_settings_bind_with_mapping (p->settings, SETTINGS_SHOW_TIME_S, - a, "state", - G_SETTINGS_BIND_DEFAULT, - settings_to_action_state, - action_state_to_settings, - NULL, NULL); - g_signal_connect (a, "activate", G_CALLBACK(on_toggle_action_activated), self); - g_signal_connect_swapped (a, "notify", G_CALLBACK(rebuild_header_now), self); - g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a)); - p->show_time_action = a; + show_time_action = g_settings_create_action (p->settings, "show-time"); + g_action_map_add_action (G_ACTION_MAP(p->actions), show_time_action); /* add the show-percentage action */ - a = g_simple_action_new ("show-percentage", NULL); - g_settings_bind_with_mapping (p->settings, SETTINGS_SHOW_PERCENTAGE_S, - a, "state", - G_SETTINGS_BIND_DEFAULT, - settings_to_action_state, - action_state_to_settings, - NULL, NULL); - g_signal_connect (a, "activate", G_CALLBACK(on_toggle_action_activated), self); - g_signal_connect_swapped (a, "notify", G_CALLBACK(rebuild_header_now), self); - g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a)); - p->show_percentage_action = a; + show_percentage_action = g_settings_create_action (p->settings, "show-percentage"); + g_action_map_add_action (G_ACTION_MAP(p->actions), show_percentage_action); rebuild_header_now (self); + + g_object_unref (show_time_action); + g_object_unref (show_percentage_action); } /*** @@ -1006,20 +970,6 @@ my_dispose (GObject * o) g_clear_object (&p->settings); } - if (p->show_time_action != NULL) - { - g_signal_handlers_disconnect_by_data (p->show_time_action, self); - - g_clear_object (&p->show_time_action); - } - - if (p->show_percentage_action != NULL) - { - g_signal_handlers_disconnect_by_data (p->show_percentage_action, self); - - g_clear_object (&p->show_percentage_action); - } - g_clear_object (&p->brightness_action); g_clear_object (&p->battery_level_action); g_clear_object (&p->header_action); @@ -1054,8 +1004,7 @@ indicator_power_service_init (IndicatorPowerService * self) init_gactions (self); - g_signal_connect_swapped (p->settings, "changed::" SETTINGS_ICON_POLICY_S, - G_CALLBACK(rebuild_header_now), self); + g_signal_connect_swapped (p->settings, "changed", G_CALLBACK(rebuild_header_now), self); p->own_id = g_bus_own_name (G_BUS_TYPE_SESSION, BUS_NAME, |