aboutsummaryrefslogtreecommitdiff
path: root/src/service.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service.c')
-rw-r--r--src/service.c108
1 files changed, 33 insertions, 75 deletions
diff --git a/src/service.c b/src/service.c
index 0cd448b..35be231 100644
--- a/src/service.c
+++ b/src/service.c
@@ -22,12 +22,11 @@
#include <gio/gio.h>
#include <url-dispatcher.h>
+#include "brightness.h"
#include "dbus-shared.h"
#include "device.h"
#include "device-provider.h"
#include "notifier.h"
-#include "ib-brightness-control.h"
-#include "ib-brightness-uscreen-control.h"
#include "service.h"
#define BUS_NAME "com.canonical.indicator.power"
@@ -104,8 +103,7 @@ struct _IndicatorPowerServicePrivate
GSettings * settings;
- IbBrightnessControl * brightness_control;
- IbBrightnessUscreenControl * brightness_uscreen_control;
+ IndicatorPowerBrightness * brightness;
guint own_id;
guint actions_export_id;
@@ -459,53 +457,28 @@ create_phone_devices_section (IndicatorPowerService * self G_GNUC_UNUSED)
****
***/
-static void
-get_brightness_range (IndicatorPowerService * self, gint * low, gint * high)
+static GMenuItem *
+create_brightness_menu_item(void)
{
- priv_t * p = self->priv;
- int max = 0;
- if (p->brightness_control)
- {
- max = ib_brightness_control_get_max_value (self->priv->brightness_control);
- }
- else if (p->brightness_uscreen_control)
- {
- max = ib_brightness_uscreen_control_get_max_value (self->priv->brightness_uscreen_control);
- }
- *low = (gint)(max * 0.05); /* 5% minimum -- don't let the screen go completely dark */
- *high = max;
-}
+ GMenuItem * item;
-static gdouble
-brightness_to_percentage (IndicatorPowerService * self, int brightness)
-{
- int lo, hi;
- get_brightness_range (self, &lo, &hi);
- return (brightness-lo) / (double)(hi-lo);
-}
+ 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", 0.1);
+ g_menu_item_set_attribute(item, "max-value", "d", 1.0);
+ g_menu_item_set_attribute(item, "min-icon", "s", "torch-off" );
+ g_menu_item_set_attribute(item, "max-icon", "s", "torch-on" );
-static int
-percentage_to_brightness (IndicatorPowerService * self, double percentage)
-{
- int lo, hi;
- get_brightness_range (self, &lo, &hi);
- return (int)(lo + (percentage*(hi-lo)));
+ return item;
}
static GVariant *
action_state_for_brightness (IndicatorPowerService * self)
{
- priv_t * p = self->priv;
- gint brightness = 0;
- if (p->brightness_control)
- {
- brightness = ib_brightness_control_get_value (p->brightness_control);
- }
- else if (p->brightness_uscreen_control)
- {
- brightness = ib_brightness_uscreen_control_get_value (p->brightness_uscreen_control);
- }
- return g_variant_new_double (brightness_to_percentage (self, brightness));
+ IndicatorPowerBrightness * b = self->priv->brightness;
+ GVariant * v = g_variant_new_double(indicator_power_brightness_get_percentage(b));
+ g_message("new brightness action state: %s", g_variant_print(v, TRUE));
+ return v;
}
static void
@@ -521,19 +494,9 @@ on_brightness_change_requested (GSimpleAction * action G_GNUC_UNUSED,
gpointer gself)
{
IndicatorPowerService * self = INDICATOR_POWER_SERVICE (gself);
- const gdouble percentage = g_variant_get_double (parameter);
- const int brightness = percentage_to_brightness (self, percentage);
- if (self->priv->brightness_control)
- {
- ib_brightness_control_set_value (self->priv->brightness_control, brightness);
- }
- else if (self->priv->brightness_uscreen_control)
- {
- ib_brightness_uscreen_control_set_value (self->priv->brightness_uscreen_control, brightness);
- }
-
- update_brightness_action_state (self);
+ indicator_power_brightness_set_percentage(self->priv->brightness,
+ g_variant_get_double (parameter));
}
static GMenuModel *
@@ -557,15 +520,21 @@ create_desktop_settings_section (IndicatorPowerService * self G_GNUC_UNUSED)
}
static GMenuModel *
-create_phone_settings_section (IndicatorPowerService * self)
+create_phone_settings_section(IndicatorPowerService * self)
{
GMenu * section;
+ GMenuItem * item;
+
+ section = g_menu_new();
- section = g_menu_new ();
- update_brightness_action_state (self);
- g_menu_append (section, _("Battery settingsā€¦"), "indicator.activate-phone-settings");
+ item = create_brightness_menu_item();
+ g_menu_append_item(section, item);
+ update_brightness_action_state(self);
+ g_object_unref(item);
- return G_MENU_MODEL (section);
+ g_menu_append(section, _("Battery settingsā€¦"), "indicator.activate-phone-settings");
+
+ return G_MENU_MODEL(section);
}
/***
@@ -1015,16 +984,13 @@ my_dispose (GObject * o)
g_clear_object (&p->notifier);
g_clear_object (&p->brightness_action);
+ g_clear_object (&p->brightness);
g_clear_object (&p->battery_level_action);
g_clear_object (&p->header_action);
g_clear_object (&p->actions);
g_clear_object (&p->conn);
- // g_clear_pointer has NULL check inside.
- g_clear_pointer (&p->brightness_control, ib_brightness_control_free);
- g_clear_pointer (&p->brightness_uscreen_control, ib_brightness_uscreen_control_free);
-
indicator_power_service_set_device_provider (self, NULL);
G_OBJECT_CLASS (indicator_power_service_parent_class)->dispose (o);
@@ -1037,8 +1003,6 @@ my_dispose (GObject * o)
static void
indicator_power_service_init (IndicatorPowerService * self)
{
- GDBusProxy *uscreen_proxy;
- brightness_params_t brightness_params;
priv_t * p = G_TYPE_INSTANCE_GET_PRIVATE (self,
INDICATOR_TYPE_POWER_SERVICE,
IndicatorPowerServicePrivate);
@@ -1050,15 +1014,9 @@ indicator_power_service_init (IndicatorPowerService * self)
p->notifier = indicator_power_notifier_new ();
- uscreen_proxy = uscreen_get_proxy(&brightness_params);
- if (uscreen_proxy != NULL)
- {
- p->brightness_uscreen_control = ib_brightness_uscreen_control_new(uscreen_proxy, brightness_params);
- }
- else
- {
- p->brightness_control = ib_brightness_control_new ();
- }
+ p->brightness = indicator_power_brightness_new();
+ g_signal_connect_swapped(p->brightness, "notify::perentage",
+ G_CALLBACK(update_brightness_action_state), self);
init_gactions (self);