diff options
-rw-r--r-- | configure.in | 1 | ||||
-rw-r--r-- | etc/suggest | 1 | ||||
-rw-r--r-- | plugins/Makefile.am | 1 | ||||
-rw-r--r-- | plugins/acadapter/ohm-plugin-acadapter.c | 12 | ||||
-rw-r--r-- | plugins/backlight/backlight | 2 | ||||
-rw-r--r-- | plugins/battery/.gitignore | 8 | ||||
-rw-r--r-- | plugins/battery/Makefile.am | 21 | ||||
-rw-r--r-- | plugins/battery/README | 1 | ||||
-rw-r--r-- | plugins/battery/battery | 1 | ||||
-rw-r--r-- | plugins/battery/ohm-plugin-battery.c | 131 |
10 files changed, 171 insertions, 8 deletions
diff --git a/configure.in b/configure.in index c5a4e60..4466333 100644 --- a/configure.in +++ b/configure.in @@ -156,6 +156,7 @@ plugins/idle/Makefile plugins/powerstatus/Makefile plugins/timeremaining/Makefile plugins/backlight/Makefile +plugins/battery/Makefile ohmd/Makefile po/Makefile.in docs/Makefile diff --git a/etc/suggest b/etc/suggest index f0c83d9..655abd4 100644 --- a/etc/suggest +++ b/etc/suggest @@ -2,5 +2,6 @@ acadapter backlight battery +timeremaining idle powerstatus diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 47f7ab2..91b9fa6 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,5 +1,6 @@ SUBDIRS = \ idle \ + battery \ acadapter \ timeremaining \ powerstatus \ diff --git a/plugins/acadapter/ohm-plugin-acadapter.c b/plugins/acadapter/ohm-plugin-acadapter.c index c54bc54..0ba8a10 100644 --- a/plugins/acadapter/ohm-plugin-acadapter.c +++ b/plugins/acadapter/ohm-plugin-acadapter.c @@ -21,13 +21,10 @@ #include <gmodule.h> #include <glib.h> #include <libhal.h> +#include <string.h> #include <ohm-plugin.h> -enum { - CONF_LAST -}; - typedef struct { LibHalContext *ctx; gchar *udi; @@ -75,10 +72,11 @@ hal_property_changed_cb (LibHalContext *ctx, dbus_bool_t is_removed, dbus_bool_t is_added) { - /* safe to assume this is always acadapter.state as only one device watched */ gboolean state; - state = libhal_device_get_property_bool (ctx, udi, key, NULL); - ohm_plugin_conf_set_key (plugin_global, "acadapter.state", state); + if (strcmp (key, "ac_adapter.present") == 0) { + state = libhal_device_get_property_bool (ctx, udi, key, NULL); + ohm_plugin_conf_set_key (plugin_global, "acadapter.state", state); + } } /** diff --git a/plugins/backlight/backlight b/plugins/backlight/backlight index 7b665ec..ea81817 100644 --- a/plugins/backlight/backlight +++ b/plugins/backlight/backlight @@ -3,4 +3,4 @@ backlight.value_ac 100 public backlight.value_battery 70 public backlight.value_idle 40 public backlight.time_idle 200 public -backlight.time_off 400 +backlight.time_off 400 public diff --git a/plugins/battery/.gitignore b/plugins/battery/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/battery/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/battery/Makefile.am b/plugins/battery/Makefile.am new file mode 100644 index 0000000..53b06e9 --- /dev/null +++ b/plugins/battery/Makefile.am @@ -0,0 +1,21 @@ +INCLUDES = \ + -I$(top_srcdir)/ohmd \ + $(HAL_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(GMODULE_CFLAGS) \ + -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ + -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" + +EXTRA_DIST = $(Data_DATA) +Datadir = $(sysconfdir)/ohm/plugins +Data_DATA = battery + +lib_LTLIBRARIES = libohm_battery.la +libohm_batteryincludedir = $(includedir)/ohm +libohm_battery_la_SOURCES = ohm-plugin-battery.c +libohm_battery_la_LIBADD = @HAL_LIBS@ @DBUS_LIBS@ $(INTLLIBS) +libohm_battery_la_LDFLAGS = -module -avoid-version + +clean-local: + rm -f *~ diff --git a/plugins/battery/README b/plugins/battery/README new file mode 100644 index 0000000..0db68d7 --- /dev/null +++ b/plugins/battery/README @@ -0,0 +1 @@ +Todo diff --git a/plugins/battery/battery b/plugins/battery/battery new file mode 100644 index 0000000..1d9aadc --- /dev/null +++ b/plugins/battery/battery @@ -0,0 +1 @@ +# battery values diff --git a/plugins/battery/ohm-plugin-battery.c b/plugins/battery/ohm-plugin-battery.c new file mode 100644 index 0000000..8b4d768 --- /dev/null +++ b/plugins/battery/ohm-plugin-battery.c @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2007 Richard Hughes <richard@hughsie.com> + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <gmodule.h> +#include <glib.h> +#include <libhal.h> +#include <string.h> + +#include <ohm-plugin.h> + +typedef struct { + LibHalContext *ctx; + gchar *udi; +} OhmPluginCacheData; + +OhmPluginCacheData data; +OhmPlugin *plugin_global; /* ick, needed as there is no userdata with libhal */ + +/** + * plugin_load: + * @plugin: This class instance + * + * Called before the plugin is coldplg. + * Define any modules that the plugin depends on, but do not do coldplug here + * as some of the modules may not have loaded yet. + */ +static void +plugin_load (OhmPlugin *plugin) +{ + /* tell ohmd what keys we are going to provide - don't set keys + * unless you provide them */ + ohm_plugin_conf_provide (plugin, "battery.percentage"); + plugin_global = plugin; +} + +/** + * plugin_unload: + * @plugin: This class instance + * + * Called just before the plugin module is unloaded, and gives the plugin + * a chance to free private memory. + */ +static void +plugin_unload (OhmPlugin *plugin) +{ + if (data.udi != NULL) { + libhal_device_remove_property_watch (data.ctx, data.udi, NULL); + g_free (data.udi); + } + libhal_ctx_shutdown (data.ctx, NULL); +} + +static void +hal_property_changed_cb (LibHalContext *ctx, + const char *udi, + const char *key, + dbus_bool_t is_removed, + dbus_bool_t is_added) +{ + gboolean state; + if (strcmp (key, "battery.charge_level.percentage") == 0) { + state = libhal_device_get_property_int (ctx, udi, key, NULL); + ohm_plugin_conf_set_key (plugin_global, "battery.percentage", state); + } +} + +/** + * plugin_coldplug: + * @plugin: This class instance + * + * Coldplug, i.e. read and set the initial state of the plugin. + * We can assume all the required modules have been loaded, although it's + * dangerous to assume the key values are anything other than the defaults. + */ +static void +plugin_coldplug (OhmPlugin *plugin) +{ + char **devices; + int num_devices; + int state; + DBusConnection *conn; + + conn = dbus_bus_get (DBUS_BUS_SYSTEM, NULL); + + data.ctx = libhal_ctx_new (); + libhal_ctx_set_dbus_connection (data.ctx, conn); + libhal_ctx_init (data.ctx, NULL); + libhal_ctx_set_device_property_modified (data.ctx, hal_property_changed_cb); + + devices = libhal_find_device_by_capability (data.ctx, "battery", &num_devices, NULL); + if (num_devices == 1) { + data.udi = g_strdup (devices[0]); + libhal_device_add_property_watch (data.ctx, data.udi, NULL); + state = libhal_device_get_property_int (data.ctx, data.udi, "battery.charge_level.percentage", NULL); + ohm_plugin_conf_set_key (plugin, "battery.percentage", state); + } else { + data.udi = NULL; + ohm_plugin_conf_set_key (plugin, "battery.percentage", 100); + g_error ("not tested with not one battery"); + } + libhal_free_string_array (devices); +} + +static OhmPluginInfo plugin_info = { + "OHM HAL Battery", /* description */ + "0.0.1", /* version */ + "richard@hughsie.com", /* author */ + plugin_load, /* load */ + plugin_unload, /* unload */ + plugin_coldplug, /* coldplug */ + NULL, /* conf_notify */ +}; + +OHM_INIT_PLUGIN (plugin_info); |