aboutsummaryrefslogtreecommitdiff
path: root/src/service.c
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-09-11 19:15:14 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-09-11 19:15:14 -0500
commit54fd6bfd6642b5820536f78e9913f2e1dc46a45a (patch)
tree0a7f1e459797b74c705ce442e274ea5e86dc5831 /src/service.c
parentd5d306583034954d99baf1515aea29b036eacbb8 (diff)
downloadayatana-indicator-power-54fd6bfd6642b5820536f78e9913f2e1dc46a45a.tar.gz
ayatana-indicator-power-54fd6bfd6642b5820536f78e9913f2e1dc46a45a.tar.bz2
ayatana-indicator-power-54fd6bfd6642b5820536f78e9913f2e1dc46a45a.zip
add an 'auto brightness' checkbox
Diffstat (limited to 'src/service.c')
-rw-r--r--src/service.c87
1 files changed, 72 insertions, 15 deletions
diff --git a/src/service.c b/src/service.c
index 0415881..665151c 100644
--- a/src/service.c
+++ b/src/service.c
@@ -522,6 +522,7 @@ create_phone_settings_section(IndicatorPowerService * self)
{
GMenu * section;
GMenuItem * item;
+ gboolean ab_supported;
section = g_menu_new();
@@ -530,6 +531,18 @@ create_phone_settings_section(IndicatorPowerService * self)
update_brightness_action_state(self);
g_object_unref(item);
+ g_object_get(self->priv->brightness,
+ "auto-brightness-supported", &ab_supported,
+ NULL);
+
+ if (ab_supported)
+ {
+ item = g_menu_item_new(_("Adjust brightness automatically"), "indicator.auto-brightness");
+ g_menu_item_set_attribute(item, "x-canonical-type", "s", "com.canonical.indicator.switch");
+ g_menu_append_item(section, item);
+ g_object_unref(item);
+ }
+
g_menu_append(section, _("Battery settingsā€¦"), "indicator.activate-phone-settings");
return G_MENU_MODEL(section);
@@ -579,7 +592,7 @@ rebuild_now (IndicatorPowerService * self, guint sections)
if (sections & SECTION_SETTINGS)
{
rebuild_section (desktop->submenu, 1, create_desktop_settings_section (self));
- rebuild_section (phone->submenu, 1, create_desktop_settings_section (self));
+ rebuild_section (phone->submenu, 1, create_phone_settings_section (self));
}
}
@@ -719,6 +732,28 @@ on_phone_settings_activated (GSimpleAction * a G_GNUC_UNUSED,
****
***/
+static gboolean
+convert_auto_prop_to_state(GBinding * binding G_GNUC_UNUSED,
+ const GValue * from_value,
+ GValue * to_value,
+ gpointer user_data G_GNUC_UNUSED)
+{
+ const gboolean b = g_value_get_boolean(from_value);
+ g_value_set_variant(to_value, g_variant_new_boolean(b));
+ return TRUE;
+}
+
+static gboolean
+convert_auto_state_to_prop(GBinding * binding G_GNUC_UNUSED,
+ const GValue * from_value,
+ GValue * to_value,
+ gpointer user_data G_GNUC_UNUSED)
+{
+ GVariant * v = g_value_get_variant(from_value);
+ g_value_set_boolean(to_value, g_variant_get_boolean(v));
+ return TRUE;
+}
+
static void
init_gactions (IndicatorPowerService * self)
{
@@ -751,6 +786,16 @@ init_gactions (IndicatorPowerService * self)
g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a));
p->battery_level_action = a;
+ /* add the auto-brightness action */
+ a = g_simple_action_new_stateful("auto-brightness", NULL, g_variant_new_boolean(FALSE));
+ g_object_bind_property_full(p->brightness, "auto-brightness",
+ a, "state",
+ G_BINDING_SYNC_CREATE|G_BINDING_BIDIRECTIONAL,
+ convert_auto_prop_to_state,
+ convert_auto_state_to_prop,
+ NULL, NULL);
+ g_action_map_add_action(G_ACTION_MAP(p->actions), G_ACTION(a));
+
/* add the brightness action */
a = g_simple_action_new_stateful ("brightness", NULL, action_state_for_brightness (self));
g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a));
@@ -815,9 +860,6 @@ on_bus_acquired (GDBusConnection * connection,
g_string_printf (path, "%s/%s", BUS_PATH, menu_names[i]);
- if (menu->menu == NULL)
- create_menu (self, i);
-
if ((id = g_dbus_connection_export_menu_model (connection,
path->str,
G_MENU_MODEL (menu->menu),
@@ -909,6 +951,12 @@ on_devices_changed (IndicatorPowerService * self)
rebuild_now (self, SECTION_HEADER | SECTION_DEVICES);
}
+static void
+on_auto_brightness_supported_changed(IndicatorPowerService * self)
+{
+ rebuild_now(self, SECTION_SETTINGS);
+}
+
/***
**** GObject virtual functions
@@ -1001,9 +1049,12 @@ my_dispose (GObject * o)
static void
indicator_power_service_init (IndicatorPowerService * self)
{
- priv_t * p = G_TYPE_INSTANCE_GET_PRIVATE (self,
- INDICATOR_TYPE_POWER_SERVICE,
- IndicatorPowerServicePrivate);
+ priv_t * p;
+ int i;
+
+ p = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ INDICATOR_TYPE_POWER_SERVICE,
+ IndicatorPowerServicePrivate);
self->priv = p;
p->cancellable = g_cancellable_new ();
@@ -1020,14 +1071,20 @@ indicator_power_service_init (IndicatorPowerService * 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,
- G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
- on_bus_acquired,
- NULL,
- on_name_lost,
- self,
- NULL);
+ for (i=0; i<N_PROFILES; ++i)
+ create_menu(self, i);
+
+ g_signal_connect_swapped(p->brightness, "notify::auto-brightness-supported",
+ G_CALLBACK(on_auto_brightness_supported_changed), self);
+
+ p->own_id = g_bus_own_name(G_BUS_TYPE_SESSION,
+ BUS_NAME,
+ G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
+ on_bus_acquired,
+ NULL,
+ on_name_lost,
+ self,
+ NULL);
}
static void