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 {
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);
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) },
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 },
{ }
};
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);