#include <libhal.h>
#include <dbus/dbus.h>
+#include <libosso.h>
+
#include "flashlight_applet.h"
#include "flashlight_lib.h"
#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))
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)
}
}
+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,
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);
}
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);
}