Handle dbus message indicating that song has stopped.
[cascardo/pubsub-bot.git] / status.c
index 6362b6d..30e7607 100644 (file)
--- a/status.c
+++ b/status.c
@@ -417,6 +417,28 @@ handler (GIOChannel *channel, GIOCondition cond, gpointer data)
   return TRUE;
 }
 
+struct
+  { char * key; char * val; } keymaps[] =
+{
+  { "artist", "artist" },
+  { "duration", "length" },
+  { "album", "source" },
+  { "title", "title" },
+  { "track-number", "track" },
+  { "location", "uri" },
+  { NULL, NULL }
+};
+
+static char *
+map_key (char *orig)
+{
+  int i;
+  for (i = 0; keymaps[i].key != NULL; i++)
+    if (strcmp (orig, keymaps[i].key) == 0)
+      return keymaps[i].val;
+  return NULL;
+}
+
 static void
 tune_add_dbus_arg (iks *tune, DBusMessageIter *args)
 {
@@ -440,6 +462,7 @@ tune_add_dbus_arg (iks *tune, DBusMessageIter *args)
     }
   else
     printf ("%c\n", dbus_message_iter_get_arg_type (&entry));
+  strkey = map_key (strkey);
   if (strkey && strval)
     {
       iks_insert_cdata (iks_insert (tune, strkey), strval, 0);
@@ -474,10 +497,19 @@ gettune (DBusConnection *conn, DBusMessage *msg, void *data)
   iks *tune;
   if (dbus_message_is_signal (msg, "org.MetaPlayer.tag", "playing"))
     {
+      printf("publishing tune\n");
       tune = tune_from_dbus (msg);
       pushtune (data, "http://jabber.org/protocol/tune", tune);
       return DBUS_HANDLER_RESULT_HANDLED;
     }
+  else if (dbus_message_is_signal (msg, "org.MetaPlayer.player", "stop"))
+    {
+      printf("tune stopped\n");
+      tune = iks_new ("tune");
+      iks_insert_attrib (tune, "xmlns", "http://jabber.org/protocol/tune");
+      pushtune (data, "http://jabber.org/protocol/tune", tune);
+      return DBUS_HANDLER_RESULT_HANDLED;
+    }
   else
     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }