OSDN Git Service

audio/player: Add support for MediaItem.Metadata property
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 23 May 2013 22:55:55 +0000 (15:55 -0700)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 17 Jun 2013 15:13:53 +0000 (18:13 +0300)
profiles/audio/player.c

index 69e8cd5..d56640f 100644 (file)
@@ -66,6 +66,7 @@ struct media_item {
        player_folder_type_t    folder_type;    /* Folder type */
        bool                    playable;       /* Item playable flag */
        uint64_t                uid;            /* Item uid */
+       GHashTable              *metadata;      /* Item metadata */
 };
 
 struct media_folder {
@@ -771,6 +772,9 @@ static DBusMessage *media_folder_list_items(DBusConnection *conn,
 
 static void media_item_free(struct media_item *item)
 {
+       if (item->metadata != NULL)
+               g_hash_table_unref(item->metadata);
+
        g_free(item->path);
        g_free(item->name);
        g_free(item);
@@ -1446,6 +1450,37 @@ static gboolean get_folder_type(const GDBusPropertyTable *property,
        return TRUE;
 }
 
+static gboolean metadata_exists(const GDBusPropertyTable *property, void *data)
+{
+       struct media_item *item = data;
+
+       return item->metadata != NULL;
+}
+
+static gboolean get_metadata(const GDBusPropertyTable *property,
+                                       DBusMessageIter *iter, void *data)
+{
+       struct media_item *item = data;
+       DBusMessageIter dict;
+
+       dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+                                       DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+                                       DBUS_TYPE_STRING_AS_STRING
+                                       DBUS_TYPE_VARIANT_AS_STRING
+                                       DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+                                       &dict);
+
+       if (g_hash_table_size(item->metadata) > 0)
+               g_hash_table_foreach(item->metadata, append_metadata, &dict);
+       else if (item->name != NULL)
+               dict_append_entry(&dict, "Title", DBUS_TYPE_STRING,
+                                                               &item->name);
+
+       dbus_message_iter_close_container(iter, &dict);
+
+       return TRUE;
+}
+
 static const GDBusMethodTable media_item_methods[] = {
        { GDBUS_EXPERIMENTAL_METHOD("Play", NULL, NULL,
                                        media_item_play) },
@@ -1463,6 +1498,8 @@ static const GDBusPropertyTable media_item_properties[] = {
                                        G_DBUS_PROPERTY_FLAG_EXPERIMENTAL },
        { "Playable", "b", get_playable, NULL, NULL,
                                        G_DBUS_PROPERTY_FLAG_EXPERIMENTAL },
+       { "Metadata", "a{sv}", get_metadata, NULL, metadata_exists,
+                                       G_DBUS_PROPERTY_FLAG_EXPERIMENTAL },
        { }
 };
 
@@ -1521,8 +1558,11 @@ struct media_item *media_player_create_item(struct media_player *mp,
                return NULL;
        }
 
-       if (type != PLAYER_ITEM_TYPE_FOLDER)
+       if (type != PLAYER_ITEM_TYPE_FOLDER) {
                folder->items = g_slist_prepend(folder->items, item);
+               item->metadata = g_hash_table_new_full(g_str_hash, g_str_equal,
+                                                       g_free, g_free);
+       }
 
        DBG("%s", item->path);