From 9a2157321bd8fab40cf419b97f1f84af7c1a2fcf Mon Sep 17 00:00:00 2001 From: Roman Moravcik Date: Sat, 3 Apr 2010 08:58:35 +0200 Subject: [PATCH] Added simple DBus interface for enabling/disabling flashlight. --- configure.ac | 2 +- debian/control | 2 +- src/flashlight_applet.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 38452fb..19db998 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,7 @@ AM_GLIB_GNU_GETTEXT() # Dependancy checks: # libhildondesktop-1 is provided by the libbhildondesktop1-dev package. -PKG_CHECK_MODULES([HILDONDESKTOP], [libhildondesktop-1 >= 2.1.16 hal]) +PKG_CHECK_MODULES([HILDONDESKTOP], [libhildondesktop-1 >= 2.1.16 hal libosso >= 2.0]) AC_SUBST([HILDONDESKTOP_CFLAGS]) AC_SUBST([HILDONDESKTOP_LIBS]) diff --git a/debian/control b/debian/control index 0e9b098..6de8f0b 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: flashlight-applet Section: user/desktop Priority: optional Maintainer: Roman Moravcik -Build-Depends: cdbs (>= 0.4.48), libhildondesktop1-dev (>= 2.1.16), libhal-dev (>= 0.5.10), maemo-optify +Build-Depends: cdbs (>= 0.4.48), libhildondesktop1-dev (>= 2.1.16), libhal-dev (>= 0.5.10), libosso-dev (>= 2.0), maemo-optify Standards-Version: 3.7.2 Homepage: http://flashlight-appl.garage.maemo.org/ Vcs-Browser: https://garage.maemo.org/plugins/ggit/browse.php/?p=flashlight-appl diff --git a/src/flashlight_applet.c b/src/flashlight_applet.c index 240ab28..8e6ba00 100644 --- a/src/flashlight_applet.c +++ b/src/flashlight_applet.c @@ -30,6 +30,8 @@ #include #include +#include + #include "flashlight_applet.h" #include "flashlight_lib.h" @@ -42,6 +44,15 @@ #define CAM_COVER_UDI "/org/freedesktop/Hal/devices/platform_cam_shutter" #define CAM_COVER_STATE "button.state.value" +#define FLASHLIGHT_APPLET_SERVICE "org.maemo.flashlight_applet" +#define FLASHLIGHT_APPLET_OBJECT "/org/maemo/flashlight_applet" +#define FLASHLIGHT_APPLET_IFACE "org.maemo.flashlight_applet" + +#define FLASHLIGHT_APPLET_METHOD_ENABLE "enable" +#define FLASHLIGHT_APPLET_METHOD_DISABLE "disable" + +#define _CAMERAUI(str) dgettext("osso-camera-ui",str) + #define FLASHLIGHT_STATUS_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE (obj, \ TYPE_FLASHLIGHT_STATUS_PLUGIN, FlashlightPluginPrivate)) @@ -53,6 +64,7 @@ struct _FlashlightPluginPrivate FlashlightContext_t *flashlight; DBusConnection *dbus_connection; LibHalContext *hal; + osso_context_t *osso_context; }; HD_DEFINE_PLUGIN_MODULE (FlashlightPlugin, flashlight_status_plugin, HD_TYPE_STATUS_MENU_ITEM) @@ -128,6 +140,53 @@ flashlight_status_plugin_enable (FlashlightPlugin *plugin, } } +static gint +flashlight_applet_dbus_request_handler (const gchar *interface, + const gchar *method, + GArray *arguments, + gpointer data, + osso_rpc_t *retval) +{ + FlashlightPlugin *plugin = data; + FlashlightPluginPrivate *priv = FLASHLIGHT_STATUS_PLUGIN_GET_PRIVATE (plugin); + gboolean is_open = FALSE; + + g_return_val_if_fail (interface, OSSO_ERROR); + g_return_val_if_fail (method, OSSO_ERROR); + + g_return_val_if_fail (priv, OSSO_ERROR); + g_return_val_if_fail (priv->hal, OSSO_ERROR); + g_return_val_if_fail (priv->button, OSSO_ERROR); + + if (strcmp (interface, FLASHLIGHT_APPLET_IFACE)) + return OSSO_ERROR; + + is_open = !libhal_device_get_property_bool (priv->hal, CAM_COVER_UDI, CAM_COVER_STATE, NULL); + + if (!strcmp (method, FLASHLIGHT_APPLET_METHOD_ENABLE)) { + /* check if cover is open */ + if (is_open) { + /* try to enable flashlight, only if it's disabled */ + if (!strcmp (hildon_button_get_value (HILDON_BUTTON (priv->button)), MSG_FLASHLIGHT_OFF)) { + flashlight_status_plugin_enable (plugin, TRUE); + } + } else { + flashlight_status_plugin_show_notification (plugin, _CAMERAUI ("camera_ia_open_lens_cover")); + } + } else if (!strcmp (method, FLASHLIGHT_APPLET_METHOD_DISABLE)) { + if (is_open) { + /* try to disable flashlight, only if it's enabled */ + if (!strcmp (hildon_button_get_value (HILDON_BUTTON (priv->button)), MSG_FLASHLIGHT_ON)) { + flashlight_status_plugin_enable (plugin, FALSE); + } + } + } else { + return OSSO_ERROR; + } + + return OSSO_OK; +} + static void flashlight_status_plugin_on_hal_property_modified (LibHalContext *ctx, const char *udi, @@ -260,6 +319,22 @@ flashlight_status_plugin_init (FlashlightPlugin *plugin) FlashlightPluginPrivate *priv = FLASHLIGHT_STATUS_PLUGIN_GET_PRIVATE (plugin); DBusError error; + /* initialize osso */ + priv->osso_context = osso_initialize (PACKAGE, VERSION, TRUE, NULL); + if (!priv->osso_context) { + g_critical ("flashlight_status_plugin_init: Could not initialize OSSO\n"); + return; + } + + if (osso_rpc_set_cb_f (priv->osso_context, + FLASHLIGHT_APPLET_SERVICE, + FLASHLIGHT_APPLET_OBJECT, + FLASHLIGHT_APPLET_IFACE, + flashlight_applet_dbus_request_handler, plugin) != OSSO_OK) { + g_critical ("flashlight_status_plugin_init: Unable to register D-BUS request handler\n"); + return; + } + /* initialize dbus */ dbus_error_init (&error); priv->dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error); @@ -350,5 +425,11 @@ flashlight_status_plugin_finalize (GObject *object) } priv->flashlight = NULL; + /* deinitialize osso */ + if (priv->osso_context) { + osso_deinitialize (priv->osso_context); + } + priv->osso_context = NULL; + G_OBJECT_CLASS (flashlight_status_plugin_parent_class)->finalize (object); } -- 1.7.9.5