aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-10-10 16:11:36 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-10-10 16:11:36 -0500
commit7eb00e86d2d9f25dbc62c5a4479e99ea5543d722 (patch)
treeede7fd97298675c81ec37fc6310149e992ea4952 /src/main.c
parent7251f3df13dc2503791fc7d1b485a48636a15884 (diff)
downloadayatana-indicator-power-7eb00e86d2d9f25dbc62c5a4479e99ea5543d722.tar.gz
ayatana-indicator-power-7eb00e86d2d9f25dbc62c5a4479e99ea5543d722.tar.bz2
ayatana-indicator-power-7eb00e86d2d9f25dbc62c5a4479e99ea5543d722.zip
add gsettings for a mock battery to make QA tester's lives easier
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c70
1 files changed, 65 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index d7953e6..112c31e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,10 +24,63 @@
#include <gio/gio.h>
#include "device.h"
+#include "device-provider-mock.h"
#include "device-provider-upower.h"
#include "service.h"
/***
+**** MOCK
+***/
+
+static IndicatorPowerDevice*
+get_mock_battery(GSettings * settings)
+{
+ const double percent = g_settings_get_int(settings, "mock-battery-level");
+
+ const UpDeviceState state = g_settings_get_boolean(settings, "mock-battery-charging")
+ ? UP_DEVICE_STATE_CHARGING
+ : UP_DEVICE_STATE_DISCHARGING;
+
+ const int seconds_left = g_settings_get_int(settings, "mock-battery-minutes-left") * 60;
+
+ return indicator_power_device_new ("/some/path",
+ UP_DEVICE_KIND_BATTERY,
+ percent,
+ state,
+ seconds_left);
+}
+
+static IndicatorPowerDeviceProvider*
+get_device_provider(GSettings * settings)
+{
+ IndicatorPowerDeviceProvider * provider = NULL;
+
+ if (g_settings_get_boolean(settings, "mock-battery-enabled"))
+ {
+ IndicatorPowerDevice * battery = get_mock_battery(settings);
+ provider = indicator_power_device_provider_mock_new ();
+ indicator_power_device_provider_add_device (INDICATOR_POWER_DEVICE_PROVIDER_MOCK(provider), battery);
+ g_object_unref (battery);
+ }
+ else
+ {
+ provider = indicator_power_device_provider_upower_new ();
+ }
+
+ return provider;
+}
+
+static void
+on_mock_settings_changed(GSettings* settings,
+ gchar * key G_GNUC_UNUSED,
+ gpointer service)
+{
+ IndicatorPowerDeviceProvider* provider = get_device_provider(settings);
+ indicator_power_service_set_device_provider (INDICATOR_POWER_SERVICE(service), provider);
+ g_object_unref(provider);
+}
+
+/***
****
***/
@@ -41,18 +94,25 @@ on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop)
int
main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED)
{
- IndicatorPowerDeviceProvider * device_provider;
- IndicatorPowerService * service;
+ GSettings * settings;
GMainLoop * loop;
+ IndicatorPowerService * service;
/* boilerplate i18n */
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
textdomain (GETTEXT_PACKAGE);
+ /* mock settings */
+ service = indicator_power_service_new (NULL);
+ settings = g_settings_new ("com.canonical.indicator.power");
+ g_signal_connect(settings, "changed::mock-battery-enabled", G_CALLBACK(on_mock_settings_changed), service);
+ g_signal_connect(settings, "changed::mock-battery-level", G_CALLBACK(on_mock_settings_changed), service);
+ g_signal_connect(settings, "changed::mock-battery-charging", G_CALLBACK(on_mock_settings_changed), service);
+ g_signal_connect(settings, "changed::mock-battery-minutes-left", G_CALLBACK(on_mock_settings_changed), service);
+ on_mock_settings_changed(settings, NULL, service);
+
/* run */
- device_provider = indicator_power_device_provider_upower_new ();
- service = indicator_power_service_new (device_provider);
loop = g_main_loop_new (NULL, FALSE);
g_signal_connect (service, INDICATOR_POWER_SERVICE_SIGNAL_NAME_LOST,
G_CALLBACK(on_name_lost), loop);
@@ -61,6 +121,6 @@ main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED)
/* cleanup */
g_main_loop_unref (loop);
g_clear_object (&service);
- g_clear_object (&device_provider);
+ g_clear_object (&settings);
return 0;
}