compiles, packages, installs as daemon v0.1-1
authorTuomo Tanskanen <ext-tuomo.1.tanskanen@nokia.com>
Mon, 1 Mar 2010 11:45:12 +0000 (13:45 +0200)
committerTuomo Tanskanen <ext-tuomo.1.tanskanen@nokia.com>
Mon, 1 Mar 2010 11:45:12 +0000 (13:45 +0200)
COPYING [new file with mode: 0644]
README [new file with mode: 0644]
debian/changelog
debian/compat
debian/control
debian/nowplayingd.default.ex [deleted file]
debian/rules
nowplaying.c [new file with mode: 0644]
scripts/99nowplayingd [new file with mode: 0644]
src/nowplaying.c [deleted file]

diff --git a/COPYING b/COPYING
new file mode 100644 (file)
index 0000000..645f27f
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,2 @@
+Licensed under GPLv2, see debian/copyright for more information.
+
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..59bdd9a
--- /dev/null
+++ b/README
@@ -0,0 +1,13 @@
+Now Playing Notifications:
+--------------------------
+
+See "brainstorm" talk thread here:
+http://talk.maemo.org/showthread.php?p=550825
+
+Thanks to mottis for idea!
+Thanks to qwerty12 for his sample code!
+
+Beware:
+------
+This is currently alpha quality hack!
+
index a62e9e6..1ee4de0 100644 (file)
@@ -1,5 +1,5 @@
 nowplayingd (0.1-1) fremantle; urgency=low
 
-  * Initial release, barely compiles
+  * Initial release, compiles and installs as daemon, thats it
 
- -- Tuomo Tanskanen <tumi@tumi.fi>  Mon, 01 Mar 2010 12:31:48 +0200
+ -- Tuomo Tanskanen <tumi@tumi.fi>  Mon, 01 Mar 2010 13:43:51 +0200
index 7f8f011..7ed6ff8 100644 (file)
@@ -1 +1 @@
-7
+5
index 54192ed..fafbb25 100644 (file)
@@ -2,9 +2,9 @@ Source: nowplayingd
 Section: user/multimedia
 Priority: extra
 Maintainer: Tuomo Tanskanen <tumi@tumi.fi>
-Build-Depends: debhelper (>= 7), libhildonnotify-dev, libmafw0-dev, libmafw-shared0-dev, libglib2.0-dev
+Build-Depends: debhelper (>= 5), libhildonnotify-dev, libmafw0-dev, libmafw-shared0-dev, libglib2.0-dev
 Standards-Version: 3.8.1
-Homepage: http://nowplayingd.garage.maemo.org/
+XB-Homepage: http://nowplayingd.garage.maemo.org/
 
 Package: nowplayingd
 Architecture: any
@@ -13,5 +13,6 @@ Description: Shows "email like" notifications when song changes
  Shows clickable notifications when currently playing song changes.
  When notification is clicked, it opens "Now Playing" view in Media
  Player.
- App idea by mottis. Sample mafw code by qwerty12. Thanks guys!
-
+ Note: Requires reboot to complete install or removal!
+ App idea by mottis. Sample code by qwerty12. Thanks guys!
+XB-Maemo-Display-Name: Now Playing Notifications
diff --git a/debian/nowplayingd.default.ex b/debian/nowplayingd.default.ex
deleted file mode 100644 (file)
index 5d90b2f..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-# Defaults for nowplayingd initscript
-# sourced by /etc/init.d/nowplayingd
-# installed at /etc/default/nowplayingd by the maintainer scripts
-
-#
-# This is a POSIX shell fragment
-#
-
-# Additional options that are passed to the Daemon.
-DAEMON_OPTS=""
index 7059586..f0f20f9 100755 (executable)
@@ -27,9 +27,10 @@ build-stamp: configure-stamp
        dh_testdir
 
        # Add here commands to compile the package.
-       $(MAKE)
+       # $(MAKE)
        #docbook-to-man debian/nowplayingd.sgml > nowplayingd.1
-
+       gcc -Wall `pkg-config --cflags --libs hildon-notify glib-2.0 mafw mafw-shared` nowplaying.c -o nowplayingd
+       
        touch $@
 
 clean: 
@@ -38,18 +39,22 @@ clean:
        rm -f build-stamp configure-stamp
 
        # Add here commands to clean up after the build process.
-       $(MAKE) clean
+       # $(MAKE) clean
 
        dh_clean 
 
 install: build
        dh_testdir
        dh_testroot
-       dh_prep  
        dh_installdirs
 
        # Add here commands to install the package into debian/nowplayingd.
-       $(MAKE) DESTDIR=$(CURDIR)/debian/nowplayingd install
+       # $(MAKE) DESTDIR=$(CURDIR)/debian/nowplayingd install
+       mkdir -p $(CURDIR)/debian/nowplayingd/usr/bin
+       cp nowplayingd $(CURDIR)/debian/nowplayingd/usr/bin/
+
+       mkdir -p $(CURDIR)/debian/nowplayingd/etc/X11/Xsession.d
+       cp scripts/99nowplayingd $(CURDIR)/debian/nowplayingd/etc/X11/Xsession.d/
 
 
 # Build architecture-independent files here.
diff --git a/nowplaying.c b/nowplaying.c
new file mode 100644 (file)
index 0000000..8dfbe8d
--- /dev/null
@@ -0,0 +1,147 @@
+/** Code is released under GPLv2
+ *
+ * See debian/copyright for copyright info
+ */
+
+/** Compile binary only with:
+ * gcc -Wall `pkg-config --cflags --libs hildon-notify glib-2.0 mafw mafw-shared` nowplaying.c -o nowplayingd
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib.h>
+#include <libintl.h>
+#include <locale.h>
+#include <hildon/hildon-notification.h>
+#include <libmafw/mafw.h>
+#include <libmafw-shared/mafw-shared.h>
+
+#define WANTED_RENDERER "Mafw-Gst-Renderer"
+
+static GMainLoop *loop = NULL;
+static MafwRegistry *registry = NULL;
+
+static void sig_handler( int sig G_GNUC_UNUSED )
+{
+       if ( g_main_loop_is_running( loop ) ) {
+               g_main_loop_quit( loop );
+       }
+}
+
+static gboolean close_notification( gpointer n )
+{
+       notify_notification_close( NOTIFY_NOTIFICATION( n ), NULL );
+
+       return FALSE;
+}
+
+static void metadata_callback(
+       const MafwRenderer *self G_GNUC_UNUSED,
+       const gchar *object_id G_GNUC_UNUSED,
+       GHashTable *metadata,
+       gconstpointer user_data G_GNUC_UNUSED,
+       const GError *error G_GNUC_UNUSED )
+{
+       const gchar *artist = NULL;
+       const gchar *title = NULL;
+       HildonNotification *n = NULL;
+
+       artist = g_value_get_string( mafw_metadata_first( metadata, MAFW_METADATA_KEY_ARTIST ) );
+       title = g_value_get_string( mafw_metadata_first( metadata, MAFW_METADATA_KEY_TITLE ) );
+
+       if ( !artist || *artist == '\0' ) /* || !strcmp (artist, "")) */ {
+               artist = dgettext( "mediaplayer", "mp_li_unknown_artist" );
+       }
+
+       if ( !title || *title == '\0' ) /* || !strcmp (title, "")) */ {
+               title = dgettext( "mediaplayer", "mp_li_unknown_song" );
+       }
+
+       n = hildon_notification_new( artist, title, "tasklaunch_media_player", "media" );
+       hildon_notification_add_dbus_action( n, "default",
+               "tasklaunch_media_player",
+               "com.nokia.mediaplayer",
+               "/com/nokia/osso/mediaplayer",
+               "com.nokia.mediaplayer",
+               "open_mp_now_playing",
+               G_TYPE_NONE, NULL,
+               -1 );
+               
+       notify_notification_show( NOTIFY_NOTIFICATION( n ), NULL );
+       g_timeout_add_seconds( 5, close_notification, n );
+}
+
+static void state_changed_cb(
+       MafwRenderer *renderer,
+       const MafwPlayState state,
+       gconstpointer user_data G_GNUC_UNUSED)
+{
+       switch (state) {
+               case Playing:
+                       mafw_renderer_get_current_metadata( renderer,
+                               (MafwRendererMetadataResultCB) metadata_callback,
+                               NULL );
+                       break;
+
+               case Stopped:
+               default:
+                       break;
+  }
+}
+
+static void renderer_added_cb(
+       const MafwRegistry *registry2 G_GNUC_UNUSED,
+       GObject *renderer,
+       gconstpointer user_data G_GNUC_UNUSED)
+{
+       if ( MAFW_IS_RENDERER( renderer ) ) {
+               const gchar *name = mafw_extension_get_name( MAFW_EXTENSION( renderer ) );
+
+               if ( !strcmp( name, WANTED_RENDERER ) ) {
+                       g_signal_connect( renderer, "state-changed", G_CALLBACK (state_changed_cb), NULL );
+               }
+       }
+}
+
+static void mafw_init( void )
+{
+    GList *renderers = NULL;
+
+       g_signal_connect( registry, "renderer-added", G_CALLBACK( renderer_added_cb ), NULL );
+       renderers = mafw_registry_get_renderers( registry );
+       while ( renderers ) {
+               renderer_added_cb( registry, G_OBJECT( renderers->data ), NULL );
+               renderers = g_list_next( renderers );
+       }
+}
+
+int main (void)
+{
+       setlocale( LC_ALL, "" );
+
+       g_type_init();
+       notify_init("nowplayingd");
+
+       loop = g_main_loop_new( NULL, FALSE );
+       g_assert( loop );
+
+       registry = MAFW_REGISTRY( mafw_registry_get_instance() );
+       g_assert( registry );
+
+       signal( SIGINT, sig_handler );
+       signal( SIGQUIT, sig_handler );
+       signal( SIGTERM, sig_handler );
+
+       mafw_shared_init( registry, NULL );
+
+       mafw_init();
+
+       g_main_loop_run( loop );
+
+       g_main_loop_unref( loop );
+
+       mafw_shared_deinit();
+
+       return EXIT_SUCCESS;
+}
+
diff --git a/scripts/99nowplayingd b/scripts/99nowplayingd
new file mode 100644 (file)
index 0000000..b833d8a
--- /dev/null
@@ -0,0 +1,7 @@
+#! /bin/sh                                                                                                
+
+DAEMON=/usr/bin/nowplayingd
+DSMETOOL=/usr/sbin/dsmetool
+DSMETOOL_PARAMETERS="-t"
+
+$DSMETOOL $DSMETOOL_PARAMETERS $DAEMON
diff --git a/src/nowplaying.c b/src/nowplaying.c
deleted file mode 100644 (file)
index a0c17f1..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <glib.h>
-#include <libintl.h>
-#include <locale.h>
-#include <hildon/hildon-notification.h>
-#include <libmafw/mafw.h>
-#include <libmafw-shared/mafw-shared.h>
-
-#define WANTED_RENDERER "Mafw-Gst-Renderer"
-
-static GMainLoop *loop = NULL;
-static MafwRegistry *registry = NULL;
-
-static void sig_handler (int sig G_GNUC_UNUSED)
-{
-       if (g_main_loop_is_running (loop))
-               g_main_loop_quit (loop);
-}
-
-static void metadata_callback (const MafwRenderer *self G_GNUC_UNUSED, const gchar *object_id G_GNUC_UNUSED, GHashTable *metadata, gconstpointer user_data G_GNUC_UNUSED, const GError *error G_GNUC_UNUSED)
-{
-       const gchar *artist;
-       const gchar *title;
-       HildonNotification * n;
-
-       artist = g_value_get_string (mafw_metadata_first (metadata, MAFW_METADATA_KEY_ARTIST));
-       title = g_value_get_string (mafw_metadata_first (metadata, MAFW_METADATA_KEY_TITLE));
-
-       if (!artist || *artist == '\0') /* || !strcmp (artist, "")) */
-               artist = dgettext ("mediaplayer", "mp_li_unknown_artist");
-
-       if (!title || *title == '\0') /* || !strcmp (title, "")) */
-               title = dgettext ("mediaplayer", "mp_li_unknown_song");
-
-       n = hildon_notification_new (artist, title, "tasklaunch_media_player", "media");
-       hildon_notification_add_dbus_action (n, "default", "tasklaunch_media_player", "com.nokia.mediaplayer", "/com/nokia/osso/mediaplayer", "com.nokia.mediaplayer", "open_mp_now_playing", G_TYPE_NONE, NULL, -1);
-       notify_notification_show (NOTIFY_NOTIFICATION (n), NULL);
-}
-
-static void state_changed_cb (MafwRenderer *renderer, const MafwPlayState state, gconstpointer user_data G_GNUC_UNUSED)
-{
-       switch (state)
-       {
-               case Playing:
-                       mafw_renderer_get_current_metadata (renderer, (MafwRendererMetadataResultCB) metadata_callback, NULL);
-                       break;
-
-               case Stopped:
-               default:
-                       break;
-  }
-}
-
-static void renderer_added_cb (const MafwRegistry *registry2 G_GNUC_UNUSED, GObject *renderer, gconstpointer user_data G_GNUC_UNUSED)
-{
-       if (MAFW_IS_RENDERER (renderer))
-       {
-               const gchar *name = mafw_extension_get_name (MAFW_EXTENSION (renderer));
-
-               if (!strcmp (name, WANTED_RENDERER))
-               {
-                       g_signal_connect (renderer, "state-changed", G_CALLBACK (state_changed_cb), NULL);
-               }
-       }
-}
-
-static void mafw_init (void)
-{
-    GList *renderers;
-
-       g_signal_connect (registry, "renderer-added", G_CALLBACK (renderer_added_cb), NULL);
-       renderers = mafw_registry_get_renderers (registry);
-       while (renderers)
-       {
-               renderer_added_cb (registry, G_OBJECT (renderers->data), NULL);
-               renderers = g_list_next (renderers);
-       }
-}
-
-int main (void)
-{
-       setlocale (LC_ALL, "");
-
-       g_type_init ();
-       notify_init ("mediaplayershit");
-
-       loop = g_main_loop_new (NULL, FALSE);
-       g_assert (loop);
-
-       registry = MAFW_REGISTRY (mafw_registry_get_instance ());
-       g_assert (registry);
-
-       signal (SIGINT, sig_handler);
-       signal (SIGQUIT, sig_handler);
-       signal (SIGTERM, sig_handler);
-
-       mafw_shared_init (registry, NULL);
-
-       mafw_init ();
-
-       g_main_loop_run (loop);
-
-       g_main_loop_unref (loop);
-
-       mafw_shared_deinit ();
-
-       return EXIT_SUCCESS;
-}
-