2 * lenscover reminder statusbar plugin.
3 * Copyright (C) 2010 Nicolai Hess
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <hildon/hildon.h>
23 #include <mce/dbus-names.h>
24 #include <mce/mode-names.h>
26 #include "lens-cover-reminder-sp.h"
28 #define LENS_COVER_STATUS_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
29 TYPE_LENS_COVER_STATUS_PLUGIN, LensCoverStatusPluginPrivate))
32 struct _LensCoverStatusPluginPrivate
34 DBusGConnection *dbus_conn;
35 DBusGProxy *dbus_proxy_cover;
36 DBusGProxy *dbus_proxy_lock;
39 HD_DEFINE_PLUGIN_MODULE(LensCoverStatusPlugin, lens_cover_status_plugin, HD_TYPE_STATUS_MENU_ITEM);
42 lens_cover_status_plugin_cover_is_open()
46 fd = open("/sys/devices/platform/gpio-switch/cam_shutter/state", O_RDONLY);
50 if(!g_str_has_prefix(state, "closed"))
60 lens_cover_status_plugin_show_icon(LensCoverStatusPlugin* plugin)
62 GdkPixbuf* pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), "statusarea_lens_cover_reminder", 18, 0, NULL);
65 hd_status_plugin_item_set_status_area_icon(HD_STATUS_PLUGIN_ITEM(plugin), pixbuf);
66 g_object_unref(pixbuf);
71 lens_cover_status_plugin_hide_icon(LensCoverStatusPlugin* plugin)
73 hd_status_plugin_item_set_status_area_icon(HD_STATUS_PLUGIN_ITEM(plugin), NULL);
77 lens_cover_status_plugin_vibrate(LensCoverStatusPlugin* plugin,
80 static gchar* pattern = "PatternIncomingMessage";
81 const gchar* method = (activate) ? MCE_ACTIVATE_VIBRATOR_PATTERN : MCE_DEACTIVATE_VIBRATOR_PATTERN;
82 if(plugin->priv->dbus_conn)
84 DBusGProxy* proxy = dbus_g_proxy_new_for_name(plugin->priv->dbus_conn,
90 dbus_g_proxy_call_no_reply(proxy,
92 G_TYPE_STRING, pattern,
94 g_object_unref(proxy);
100 handle_lock_mode_changed(DBusGProxy* object,
101 const gchar* tklock_mode,
102 LensCoverStatusPlugin* plugin)
104 if(lens_cover_status_plugin_cover_is_open())
106 if(g_str_has_prefix(tklock_mode, MCE_TK_LOCKED))
107 lens_cover_status_plugin_vibrate(plugin, TRUE);
109 lens_cover_status_plugin_vibrate(plugin, FALSE);
114 handle_cover_switch_changed(DBusGProxy* object,
117 LensCoverStatusPlugin* plugin)
119 if(lens_cover_status_plugin_cover_is_open())
121 lens_cover_status_plugin_show_icon(plugin);
125 lens_cover_status_plugin_hide_icon(plugin);
130 lens_cover_status_plugin_finalize(GObject* object)
132 LensCoverStatusPlugin* plugin = LENS_COVER_STATUS_PLUGIN(object);
133 if(plugin->priv->dbus_proxy_cover)
135 dbus_g_proxy_disconnect_signal(plugin->priv->dbus_proxy_cover,
137 G_CALLBACK(handle_cover_switch_changed),
140 if(plugin->priv->dbus_proxy_lock)
142 dbus_g_proxy_disconnect_signal(plugin->priv->dbus_proxy_lock,
144 G_CALLBACK(handle_lock_mode_changed),
150 register_dbus_signal_on_cover_switch(LensCoverStatusPlugin* plugin)
152 plugin->priv->dbus_conn = NULL;
153 plugin->priv->dbus_proxy_cover = NULL;
154 plugin->priv->dbus_proxy_lock = NULL;
155 plugin->priv->dbus_conn = hd_status_plugin_item_get_dbus_g_connection(HD_STATUS_PLUGIN_ITEM(&plugin->parent),
159 if(plugin->priv->dbus_conn)
161 plugin->priv->dbus_proxy_cover = dbus_g_proxy_new_for_name(plugin->priv->dbus_conn,
162 "org.freedesktop.Hal",
163 "/org/freedesktop/Hal/devices/platform_cam_shutter",
164 "org.freedesktop.Hal.Device");
165 dbus_g_proxy_add_signal(plugin->priv->dbus_proxy_cover,
170 dbus_g_proxy_connect_signal(plugin->priv->dbus_proxy_cover,
172 G_CALLBACK(handle_cover_switch_changed), plugin, NULL);
174 plugin->priv->dbus_proxy_lock = dbus_g_proxy_new_for_name(plugin->priv->dbus_conn,
178 dbus_g_proxy_add_signal(plugin->priv->dbus_proxy_lock,
182 dbus_g_proxy_connect_signal(plugin->priv->dbus_proxy_lock,
184 G_CALLBACK(handle_lock_mode_changed), plugin, NULL);
191 lens_cover_status_plugin_class_finalize(LensCoverStatusPluginClass *klass)
196 lens_cover_status_plugin_class_init(LensCoverStatusPluginClass *klass)
198 g_type_class_add_private(klass, sizeof(LensCoverStatusPluginPrivate));
199 G_OBJECT_CLASS(klass)->finalize = (GObjectFinalizeFunc)lens_cover_status_plugin_finalize;
203 lens_cover_status_plugin_init(LensCoverStatusPlugin* plugin)
205 plugin->priv = LENS_COVER_STATUS_PLUGIN_GET_PRIVATE(plugin);
206 register_dbus_signal_on_cover_switch(plugin);
207 if(lens_cover_status_plugin_cover_is_open())
209 lens_cover_status_plugin_show_icon(plugin);
213 lens_cover_status_plugin_hide_icon(plugin);