From 6a069a0208dba8a5056387f2f426f073c9df011b Mon Sep 17 00:00:00 2001 From: Nicolai Date: Tue, 18 May 2010 01:14:00 +0200 Subject: [PATCH] initial git release --- Makefile | 33 +++++ data/lens-cover-reminder-sp.desktop | 7 + data/statusarea_lens_cover_reminder.png | Bin 0 -> 283 bytes debian/README | 6 + debian/README.Debian | 6 + debian/changelog | 18 +++ debian/compat | 1 + debian/control | 25 ++++ debian/copyright | 26 ++++ debian/dirs | 2 + debian/rules | 105 +++++++++++++++ src/Makefile | 22 ++++ src/lens-cover-reminder-sp.c | 216 +++++++++++++++++++++++++++++++ src/lens-cover-reminder-sp.h | 59 +++++++++ 14 files changed, 526 insertions(+) create mode 100644 Makefile create mode 100644 data/lens-cover-reminder-sp.desktop create mode 100644 data/statusarea_lens_cover_reminder.png create mode 100644 debian/README create mode 100644 debian/README.Debian create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/dirs create mode 100644 debian/docs create mode 100755 debian/rules create mode 100644 src/Makefile create mode 100644 src/lens-cover-reminder-sp.c create mode 100644 src/lens-cover-reminder-sp.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..473f5b5 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +SUBDIRS = src +HILDON_STATUS_PANEL_LIB_DIR=$(shell pkg-config libhildondesktop-1 --variable=hildondesktoplibdir) +HILDON_STATUS_PANEL_DATA_DIR=$(shell pkg-config libhildondesktop-1 --variable=hildonstatusmenudesktopentrydir) +BUILDDIR=build +SP_LIB=lens-cover-reminder-sp.so +DATA_FILE_SP=lens-cover-reminder-sp.desktop +IMAGE_PATH=/usr/share/icons/hicolor/18x18/hildon/ + +all: create_builddir subdirs + +install: all + install -d $(DESTDIR)/$(HILDON_STATUS_PANEL_LIB_DIR) + install -m 644 $(BUILDDIR)/$(SP_LIB) $(DESTDIR)/$(HILDON_STATUS_PANEL_LIB_DIR) + install -d $(DESTDIR)/$(HILDON_CONTROL_PANEL_DATA_DIR) + install -d $(DESTDIR)/$(HILDON_STATUS_PANEL_DATA_DIR) + install -m 644 data/$(DATA_FILE_SP) $(DESTDIR)/$(HILDON_STATUS_PANEL_DATA_DIR) + install -d $(DESTDIR)/$(IMAGE_PATH) + install -m 644 data/statusarea_lens_cover_reminder.png $(DESTDIR)/$(IMAGE_PATH) + + +subdirs: $(SUBDIRS) + +$(SUBDIRS): + $(MAKE) -C $@ + +create_builddir: + mkdir -p build + +.PHONY: all clean install $(SUBDIRS) + +clean: + rm -rf build + for d in $(SUBDIRS); do (cd $$d; $(MAKE) clean);done diff --git a/data/lens-cover-reminder-sp.desktop b/data/lens-cover-reminder-sp.desktop new file mode 100644 index 0000000..347f921 --- /dev/null +++ b/data/lens-cover-reminder-sp.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Name=Lens Cover Reminder +Comment=Reminds you for the open lens cover +Icon=general_email +Categories=conditional +Type=default +X-Path=lens-cover-reminder-sp.so diff --git a/data/statusarea_lens_cover_reminder.png b/data/statusarea_lens_cover_reminder.png new file mode 100644 index 0000000000000000000000000000000000000000..bc34c1f421f937dd5264e2011734e2742c067afc GIT binary patch literal 283 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+1|-AI^@Rf|#^NA%Cx&(BWL^R}Y)RhkE)4%c zaKYZ?lYt_f1s;*b3=G`DAk4@xYmNj^kiEpy*OmPiE4P>=@7%8G|A9iYJzX3_EKa|j zyqA~BkjE|FPshPq%6w+mEXD|iNSy-=S4?tRE-m5Im0hdp*Y5WxrbJP7eNm!)?WUX` z!G~tf+$x~UFsInw^UNA?#tk>8tM~1G>B9W_cj~2LrlNCerbRQX+s=Hinqk-VX97-t z`<@x7ys*699U>~osIatU)wNESCz?{1w_2UJ*%{;||JppTXXB2=>-8_a*(AL;T3T-9 XMcu42lX_F2GZ{Qx{an^LB{Ts51T$nf literal 0 HcmV?d00001 diff --git a/debian/README b/debian/README new file mode 100644 index 0000000..2f04b6d --- /dev/null +++ b/debian/README @@ -0,0 +1,6 @@ +The Debian Package lens-cover-reminder-sp +---------------------------- + +Comments regarding the Package + + -- Nicolai Hess Wed, 12 May 2010 00:09:23 +0200 diff --git a/debian/README.Debian b/debian/README.Debian new file mode 100644 index 0000000..59f210c --- /dev/null +++ b/debian/README.Debian @@ -0,0 +1,6 @@ +lens-cover-reminder-sp for Debian +--------------------------------- + + + + -- Nicolai Hess Wed, 12 May 2010 00:09:23 +0200 diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..e2dbeef --- /dev/null +++ b/debian/changelog @@ -0,0 +1,18 @@ +lens-cover-reminder-sp (0.3) unstable; urgency=low + + * changed the icon again + * changed bugtracker + + -- Nicolai Hess Tue, 18 May 2010 00:52:23 +0200 + +lens-cover-reminder-sp (0.2) unstable; urgency=low + + * changed the app-icon (XB-Maemo-Icon) + + -- Nicolai Hess Sun, 16 May 2010 22:18:02 +0200 + +lens-cover-reminder-sp (0.1) unstable; urgency=low + + * Initial Release. + + -- Nicolai Hess Wed, 12 May 2010 00:09:23 +0200 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..df9797d --- /dev/null +++ b/debian/control @@ -0,0 +1,25 @@ +Source: lens-cover-reminder-sp +Priority: extra +Maintainer: Nicolai Hess +Build-Depends: debhelper (>= 5), libgtk2.0-dev, libhildon1-dev, libhildondesktop1-dev, libdbus-1-dev, mce-dev +Standards-Version: 3.7.2 +Section: user/desktop + +Package: lens-cover-reminder-sp +Architecture: any +Depends: ${shlibs:Depends} +Description: Reminds you of the open lens + Shows a little statusbar icon while the lens + is open and vibrates on screen lock +XB-Maemo-Display-Name:Lens Cover Reminder +XSBC-Bugtracker: https://garage.maemo.org/tracker/?group_id=1611 +XB-Maemo-Icon-26: + iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c + 6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0 + SU1FB9oFERYoMtIVCosAAADcSURBVGje7Zi9CsIwFEZvpXPA1SlLyOriUwQh + u0/hk/gqBclTuLhqlkyuQgbXdguhDYJi1Kvfmb6S0PSS09sfIgAAAAAAwJZG + a91zLqAlIhJCsLz4GCPNuCvU5geH5foti66O+5edi/0O/JZCOZvbqdqi5yx3 + XZfyYr6dzL1cdylba6EQH4VylFIpe++xAyjgUYVqUuosoxlQCArdwxiTspRy + Mh5CSNk5B4Wg0Jhcm5JCeJChABTw5Tdx3uefGYdCLBSq+RFTej1AF+JEo7Xu + 8W8UCv17G40xEvgQA+gnLQnOJA+wAAAAAElFTkSuQmCC + ==== diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..15c92c7 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,26 @@ +This is lens-cover-reminder-sp, written and maintained by Nicolai Hess +on Wed, 12 May 2010 00:09:23 +0200. + +The original source can always be found at: + ftp://ftp.debian.org/dists/unstable/main/source/ + +Copyright Holder: Nicolai Hess + +License: + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this package; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +On Debian systems, the complete text of the GNU General +Public License can be found in `/usr/share/common-licenses/GPL'. diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..ca882bb --- /dev/null +++ b/debian/dirs @@ -0,0 +1,2 @@ +usr/bin +usr/sbin diff --git a/debian/docs b/debian/docs new file mode 100644 index 0000000..e69de29 diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..774819a --- /dev/null +++ b/debian/rules @@ -0,0 +1,105 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + + + + +CFLAGS = -Wall -g + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif + +# shared library versions, option 1 +version=2.0.5 +major=2 +# option 2, assuming the library is created as src/.libs/libfoo.so.2.0.5 or so +#version=`ls src/.libs/lib*.so.* | \ +# awk '{if (match($$0,/[0-9]+\.[0-9]+\.[0-9]+$$/)) print substr($$0,RSTART)}'` +#major=`ls src/.libs/lib*.so.* | \ +# awk '{if (match($$0,/\.so\.[0-9]+$$/)) print substr($$0,RSTART+4)}'` + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + + touch configure-stamp + + +build: build-stamp +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + $(MAKE) + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + -$(MAKE) clean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/tmp + $(MAKE) DESTDIR=$(CURDIR)/debian/lens-cover-reminder-sp install + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples +# dh_install +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link + dh_strip + dh_compress + dh_fixperms +# dh_perl +# dh_python +# dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..b6bc34b --- /dev/null +++ b/src/Makefile @@ -0,0 +1,22 @@ +OBJS=lens-cover-reminder-sp.o +SOURCES=lens-cover-reminder-sp.c +BUILDDIR=../build +LIB=$(BUILDDIR)/lens-cover-reminder-sp.so +PKG_FLAGS=$(shell pkg-config hildon-1 libhildondesktop-1 --libs --cflags) +CCFLAGS=-shared +CC=gcc + +all: $(LIB) + + +$(LIB): $(OBJS) + $(CC) $(CCFLAGS) $(PKG_FLAGS) $(OBJS) -o $(LIB) + +.c.o: + $(CC) $(CCFLAGS) $(PKG_FLAGS) -c $< -o $@ + + +.PHONY: clean all + +clean: + rm $(OBJS) \ No newline at end of file diff --git a/src/lens-cover-reminder-sp.c b/src/lens-cover-reminder-sp.c new file mode 100644 index 0000000..bdf4267 --- /dev/null +++ b/src/lens-cover-reminder-sp.c @@ -0,0 +1,216 @@ +/* + * lenscover reminder statusbar plugin. + * Copyright (C) 2010 Nicolai Hess + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include + +#include "lens-cover-reminder-sp.h" + +#define LENS_COVER_STATUS_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \ + TYPE_LENS_COVER_STATUS_PLUGIN, LensCoverStatusPluginPrivate)) + + +struct _LensCoverStatusPluginPrivate +{ + DBusGConnection *dbus_conn; + DBusGProxy *dbus_proxy_cover; + DBusGProxy *dbus_proxy_lock; +}; + +HD_DEFINE_PLUGIN_MODULE(LensCoverStatusPlugin, lens_cover_status_plugin, HD_TYPE_STATUS_MENU_ITEM); + +static gboolean +lens_cover_status_plugin_cover_is_open() +{ + int fd; + char state[7]; + fd = open("/sys/devices/platform/gpio-switch/cam_shutter/state", O_RDONLY); + if(fd) + { + read(fd, state, 7 ); + if(!g_str_has_prefix(state, "closed")) + { + return TRUE; + } + close( fd ); + } + return FALSE; +} + +static void +lens_cover_status_plugin_show_icon(LensCoverStatusPlugin* plugin) +{ + GdkPixbuf* pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), "statusarea_lens_cover_reminder", 18, 0, NULL); + if(pixbuf) + { + hd_status_plugin_item_set_status_area_icon(HD_STATUS_PLUGIN_ITEM(plugin), pixbuf); + g_object_unref(pixbuf); + } +} + +static void +lens_cover_status_plugin_hide_icon(LensCoverStatusPlugin* plugin) +{ + hd_status_plugin_item_set_status_area_icon(HD_STATUS_PLUGIN_ITEM(plugin), NULL); +} + +static void +lens_cover_status_plugin_vibrate(LensCoverStatusPlugin* plugin, + gboolean activate) +{ + static gchar* pattern = "PatternIncomingMessage"; + const gchar* method = (activate) ? MCE_ACTIVATE_VIBRATOR_PATTERN : MCE_DEACTIVATE_VIBRATOR_PATTERN; + if(plugin->priv->dbus_conn) + { + DBusGProxy* proxy = dbus_g_proxy_new_for_name(plugin->priv->dbus_conn, + MCE_SERVICE, + MCE_REQUEST_PATH, + MCE_REQUEST_IF); + if(proxy) + { + dbus_g_proxy_call_no_reply(proxy, + method, + G_TYPE_STRING, pattern, + G_TYPE_INVALID); + g_object_unref(proxy); + } + } +} + +static void +handle_lock_mode_changed(DBusGProxy* object, + const gchar* tklock_mode, + LensCoverStatusPlugin* plugin) +{ + if(lens_cover_status_plugin_cover_is_open()) + { + if(g_str_has_prefix(tklock_mode, MCE_TK_LOCKED)) + lens_cover_status_plugin_vibrate(plugin, TRUE); + else + lens_cover_status_plugin_vibrate(plugin, FALSE); + } +} + +static void +handle_cover_switch_changed(DBusGProxy* object, + const gchar* event, + const gchar* source, + LensCoverStatusPlugin* plugin) +{ + if(lens_cover_status_plugin_cover_is_open()) + { + lens_cover_status_plugin_show_icon(plugin); + } + else + { + lens_cover_status_plugin_hide_icon(plugin); + } +} + +static void +lens_cover_status_plugin_finalize(GObject* object) +{ + LensCoverStatusPlugin* plugin = LENS_COVER_STATUS_PLUGIN(object); + if(plugin->priv->dbus_proxy_cover) + { + dbus_g_proxy_disconnect_signal(plugin->priv->dbus_proxy_cover, + "Condition", + G_CALLBACK(handle_cover_switch_changed), + plugin); + } + if(plugin->priv->dbus_proxy_lock) + { + dbus_g_proxy_disconnect_signal(plugin->priv->dbus_proxy_lock, + MCE_TKLOCK_MODE_SIG, + G_CALLBACK(handle_lock_mode_changed), + plugin); + } +} + +static void +register_dbus_signal_on_cover_switch(LensCoverStatusPlugin* plugin) +{ + plugin->priv->dbus_conn = NULL; + plugin->priv->dbus_proxy_cover = NULL; + plugin->priv->dbus_proxy_lock = NULL; + plugin->priv->dbus_conn = hd_status_plugin_item_get_dbus_g_connection(HD_STATUS_PLUGIN_ITEM(&plugin->parent), + DBUS_BUS_SYSTEM, + NULL); + + if(plugin->priv->dbus_conn) + { + plugin->priv->dbus_proxy_cover = dbus_g_proxy_new_for_name(plugin->priv->dbus_conn, + "org.freedesktop.Hal", + "/org/freedesktop/Hal/devices/platform_cam_shutter", + "org.freedesktop.Hal.Device"); + dbus_g_proxy_add_signal(plugin->priv->dbus_proxy_cover, + "Condition", + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_INVALID); + dbus_g_proxy_connect_signal(plugin->priv->dbus_proxy_cover, + "Condition", + G_CALLBACK(handle_cover_switch_changed), plugin, NULL); + + plugin->priv->dbus_proxy_lock = dbus_g_proxy_new_for_name(plugin->priv->dbus_conn, + MCE_SERVICE, + MCE_SIGNAL_PATH, + MCE_SIGNAL_IF); + dbus_g_proxy_add_signal(plugin->priv->dbus_proxy_lock, + MCE_TKLOCK_MODE_SIG, + G_TYPE_STRING, + G_TYPE_INVALID); + dbus_g_proxy_connect_signal(plugin->priv->dbus_proxy_lock, + MCE_TKLOCK_MODE_SIG, + G_CALLBACK(handle_lock_mode_changed), plugin, NULL); + + } +} + + +static void +lens_cover_status_plugin_class_finalize(LensCoverStatusPluginClass *klass) +{ +} + +static void +lens_cover_status_plugin_class_init(LensCoverStatusPluginClass *klass) +{ + g_type_class_add_private(klass, sizeof(LensCoverStatusPluginPrivate)); + G_OBJECT_CLASS(klass)->finalize = (GObjectFinalizeFunc)lens_cover_status_plugin_finalize; +} + +static void +lens_cover_status_plugin_init(LensCoverStatusPlugin* plugin) +{ + plugin->priv = LENS_COVER_STATUS_PLUGIN_GET_PRIVATE(plugin); + register_dbus_signal_on_cover_switch(plugin); + if(lens_cover_status_plugin_cover_is_open()) + { + lens_cover_status_plugin_show_icon(plugin); + } + else + { + lens_cover_status_plugin_hide_icon(plugin); + } +} + diff --git a/src/lens-cover-reminder-sp.h b/src/lens-cover-reminder-sp.h new file mode 100644 index 0000000..1d37243 --- /dev/null +++ b/src/lens-cover-reminder-sp.h @@ -0,0 +1,59 @@ +/* + * lenscover reminder statusbar plugin. + * Copyright (C) 2010 Nicolai Hess + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _LENS_COVER_REMINDER_H +#define _LENS_COVER_REMINDER_H + +#include + +G_BEGIN_DECLS + +#define TYPE_LENS_COVER_STATUS_PLUGIN (lens_cover_status_plugin_get_type()) + +#define LENS_COVER_STATUS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + TYPE_LENS_COVER_STATUS_PLUGIN, LensCoverStatusPlugin)) + +#define LENS_COVER_STATUS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ + TYPE_LENS_COVER_STATUS_PLUGIN, StatusPluginClass)) + +#define IS_LENS_COVER_STATUS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + TYPE_LENS_COVER_STATUS_PLUGIN)) + +#define IS_LENS_COVER_STATUS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + TYPE_LENS_COVER_STATUS_PLUGIN)) + + +typedef struct _LensCoverStatusPlugin LensCoverStatusPlugin; +typedef struct _LensCoverStatusPluginClass LensCoverStatusPluginClass; +typedef struct _LensCoverStatusPluginPrivate LensCoverStatusPluginPrivate; + +struct _LensCoverStatusPlugin +{ + HDStatusMenuItem parent; + LensCoverStatusPluginPrivate* priv; +}; + +struct _LensCoverStatusPluginClass +{ + HDStatusMenuItemClass parent; +}; + +GType lens_cover_status_plugin_get_type(void); + +G_END_DECLS +#endif -- 1.7.9.5