aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorY.C cheng <yc.cheng@canonical.com>2014-03-05 13:32:26 +0800
committerY.C cheng <yc.cheng@canonical.com>2014-03-05 13:32:26 +0800
commit6a577e1b2d6941af7eef77a7a6a8c4c064dcbcf4 (patch)
tree529d29099094a6cc4488df5c88b3fd8634ffefdf
parent18fd0fa741f818ed8a6d09b8a2a4623e85d6bbdf (diff)
downloadayatana-indicator-power-6a577e1b2d6941af7eef77a7a6a8c4c064dcbcf4.tar.gz
ayatana-indicator-power-6a577e1b2d6941af7eef77a7a6a8c4c064dcbcf4.tar.bz2
ayatana-indicator-power-6a577e1b2d6941af7eef77a7a6a8c4c064dcbcf4.zip
clean up / wrong code fix
-rw-r--r--src/ib-brightness-powerd-control.c27
-rw-r--r--src/service.c28
2 files changed, 31 insertions, 24 deletions
diff --git a/src/ib-brightness-powerd-control.c b/src/ib-brightness-powerd-control.c
index 3395bda..e7d4e0e 100644
--- a/src/ib-brightness-powerd-control.c
+++ b/src/ib-brightness-powerd-control.c
@@ -40,8 +40,8 @@ powerd_get_proxy(void)
&error);
if (error != NULL) {
- g_error_free (error);
g_debug ("could not connect to powerd: %s", error->message);
+ g_error_free (error);
return NULL;
}
return powerd_proxy;
@@ -109,11 +109,12 @@ static void ib_brightness_init(IbBrightnessPowerdControl *control)
{
gboolean ret = getBrightnessParams(control->powerd_proxy, &(control->min),
&(control->max), &(control->dflt), &(control->ab_supported));
- if (! ret) return;
-
- ib_brightness_powerd_control_set_value(control, control->max);
+ if (! ret)
+ return;
control->inited = TRUE;
+
+ ib_brightness_powerd_control_set_value(control, control->max * 8 / 10);
}
IbBrightnessPowerdControl*
@@ -134,8 +135,16 @@ void
ib_brightness_powerd_control_set_value (IbBrightnessPowerdControl* self, gint value)
{
gboolean ret;
- if (! self->inited) return;
- if (value > self->max || value < self->min) return;
+ if (! self->inited)
+ return;
+ if (value > self->max)
+ {
+ value = self->max;
+ }
+ else if (value < self->min)
+ {
+ value = self->min;
+ }
ret = setUserBrightness(self->powerd_proxy, value);
if (ret)
{
@@ -146,14 +155,16 @@ ib_brightness_powerd_control_set_value (IbBrightnessPowerdControl* self, gint va
gint
ib_brightness_powerd_control_get_value (IbBrightnessPowerdControl* self)
{
- if (! self->inited) return 0;
+ if (! self->inited)
+ return 0;
return self->current;
}
gint
ib_brightness_powerd_control_get_max_value (IbBrightnessPowerdControl* self)
{
- if (! self->inited) return 0;
+ if (! self->inited)
+ return 0;
return self->max;
}
diff --git a/src/service.c b/src/service.c
index 0f976d1..959e316 100644
--- a/src/service.c
+++ b/src/service.c
@@ -442,12 +442,16 @@ create_phone_devices_section (IndicatorPowerService * self G_GNUC_UNUSED)
static void
get_brightness_range (IndicatorPowerService * self, gint * low, gint * high)
{
+ priv_t * p = self->priv;
int max = 0;
- if (self->priv->brightness_control) {
- max = ib_brightness_control_get_max_value (self->priv->brightness_control);
- } else {
- max = ib_brightness_powerd_control_get_max_value (self->priv->brightness_powerd_control);
- }
+ if (p->brightness_control)
+ {
+ max = ib_brightness_control_get_max_value (self->priv->brightness_control);
+ }
+ else if (p->brightness_powerd_control)
+ {
+ max = ib_brightness_powerd_control_get_max_value (self->priv->brightness_powerd_control);
+ }
*low = max * 0.05; /* 5% minimum -- don't let the screen go completely dark */
*high = max;
}
@@ -1023,14 +1027,9 @@ my_dispose (GObject * o)
g_clear_object (&p->conn);
- if (p->brightness_control)
- {
- g_clear_pointer (&p->brightness_control, ib_brightness_control_free);
- }
- else if (p->brightness_powerd_control)
- {
- g_clear_pointer (&p->brightness_powerd_control, ib_brightness_powerd_control_free);
- }
+ // g_clear_pointer has NULL check inside.
+ g_clear_pointer (&p->brightness_control, ib_brightness_control_free);
+ g_clear_pointer (&p->brightness_powerd_control, ib_brightness_powerd_control_free);
indicator_power_service_set_device_provider (self, NULL);
@@ -1054,9 +1053,6 @@ indicator_power_service_init (IndicatorPowerService * self)
p->settings = g_settings_new ("com.canonical.indicator.power");
- p->brightness_control = NULL;
- p->brightness_powerd_control = NULL;
-
powerd_proxy = powerd_get_proxy();
if (powerd_proxy != NULL)
{