From 4940c1e037627200b47d497fbc3f8cbc58d62d2e Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Mon, 28 Apr 2008 21:17:25 +0000 Subject: [PATCH] Start using tracker for fetching the metadata. svn path=/trunk/; revision=135 --- ChangeLog | 8 +++ configure.ac | 2 + src/Makefile.am | 8 ++- src/gupnp-media-tracker.c | 144 ++++++++++++++++++++++++++++++++++++---------- 4 files changed, 131 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index e193951..6b4301c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-04-29 Zeeshan Ali Khattak + + * configure.ac: + * src/Makefile.am: + * src/gupnp-media-tracker.c: + + Start using tracker for fetching the metadata. + 2008-04-28 Zeeshan Ali Khattak * src/Makefile.am: diff --git a/configure.ac b/configure.ac index 88cbcec..470c8ed 100644 --- a/configure.ac +++ b/configure.ac @@ -14,10 +14,12 @@ AC_FUNC_MMAP GUPNP_REQUIRED=0.6 GUPNP_AV_REQUIRED=0.1 GCONF_REQUIRED=2.22 +DBUS_GLIB_REQUIRED=0.74 PKG_CHECK_MODULES(LIBGUPNP, gupnp-1.0 >= $GUPNP_REQUIRED) PKG_CHECK_MODULES(LIBGUPNP_AV, gupnp-av-1.0 >= $GUPNP_AV_REQUIRED) PKG_CHECK_MODULES(LIBGCONF, gconf-2.0 >= $GCONF_REQUIRED) +PKG_CHECK_MODULES(LIBDBUS_GLIB, dbus-glib-1 >= $DBUS_GLIB_REQUIRED) # glib-genmarshal GLIB_GENMARSHAL=`pkg-config --variable=glib_genmarshal glib-2.0` diff --git a/src/Makefile.am b/src/Makefile.am index 948d231..0448ca4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,7 +4,10 @@ else shareddir = $(datadir)/gupnp-media-server endif -AM_CFLAGS = $(LIBGUPNP_CFLAGS) $(LIBGUPNP_AV_CFLAGS) $(LIBGCONF_CFLAGS) \ +AM_CFLAGS = $(LIBGUPNP_CFLAGS) \ + $(LIBGUPNP_AV_CFLAGS) \ + $(LIBGCONF_CFLAGS) \ + $(LIBDBUS_GLIB_CFLAGS) \ -I$(top_srcdir) -DDATA_DIR='"$(shareddir)"' bin_PROGRAMS = gupnp-media-server @@ -16,7 +19,8 @@ gupnp_media_server_SOURCES = main.c \ gupnp-media-tracker.c gupnp_media_server_LDADD = $(LIBGUPNP_LIBS) \ $(LIBGUPNP_AV_LIBS) \ - $(LIBGCONF_LIBS) + $(LIBGCONF_LIBS) \ + $(LIBDBUS_GLIB_LIBS) gupnp_media_server_LDFLAGS = -export-dynamic MAINTAINERCLEANFILES = Makefile.in diff --git a/src/gupnp-media-tracker.c b/src/gupnp-media-tracker.c index c4c0779..dac3509 100644 --- a/src/gupnp-media-tracker.c +++ b/src/gupnp-media-tracker.c @@ -27,11 +27,17 @@ #include #include #include +#include #include "gupnp-media-tracker.h" #define HOME_DIR_ALIAS "/media" +#define TRACKER_SERVICE "org.freedesktop.Tracker" +#define TRACKER_PATH "/org/freedesktop/tracker" + +#define METADATA_IFACE "org.freedesktop.Tracker.Metadata" + G_DEFINE_TYPE (GUPnPMediaTracker, gupnp_media_tracker, G_TYPE_OBJECT); @@ -41,6 +47,8 @@ struct _GUPnPMediaTrackerPrivate { GUPnPContext *context; + DBusGProxy *metadata_proxy; + GUPnPDIDLLiteWriter *didl_writer; GUPnPSearchCriteriaParser *search_parser; }; @@ -51,20 +59,11 @@ enum { PROP_CONTEXT }; -/* Hard-coded items (mime, title, path) - * - * paths are relative to home directory +/* Hard-coded item paths, relative to home directory. * */ -static char *items[3][4] = { - { "4000", - "audio/mpeg", - "Maa", - "entertainment/songs/Maa.mp3" }, - { "4001", - "audio/mpeg", - "Hoo", - "entertainment/songs/Ho.mp3" }, - { NULL } +static char *items[] = { + "entertainment/songs/Maa.mp3", + "entertainment/songs/Ho.mp3" }; /* GObject stuff */ @@ -97,6 +96,11 @@ gupnp_media_tracker_dispose (GObject *object) tracker->priv->root_id = NULL; } + if (tracker->priv->metadata_proxy) { + g_object_unref (tracker->priv->metadata_proxy); + tracker->priv->metadata_proxy = NULL; + } + /* Call super */ object_class = G_OBJECT_CLASS (gupnp_media_tracker_parent_class); object_class->dispose (object); @@ -124,6 +128,8 @@ gupnp_media_tracker_constructor (GType type, GObject *object; GObjectClass *object_class; GUPnPMediaTracker *tracker; + DBusGConnection *connection; + GError *error; object_class = G_OBJECT_CLASS (gupnp_media_tracker_parent_class); object = object_class->constructor (type, @@ -135,12 +141,42 @@ gupnp_media_tracker_constructor (GType type, tracker = GUPNP_MEDIA_TRACKER (object); + /* Connect to session bus */ + error = NULL; + connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + if (connection == NULL) { + g_critical ("Failed to connect to tracker: %s\n", + error->message); + + g_error_free (error); + + goto error_case; + } + + /* Create proxy to metadata interface of tracker object */ + tracker->priv->metadata_proxy = + dbus_g_proxy_new_for_name (connection, + TRACKER_SERVICE, + TRACKER_PATH, + METADATA_IFACE); + if (tracker->priv->metadata_proxy == NULL) { + g_critical ("Failed to create proxy for '%s' object\n", + TRACKER_PATH); + + goto error_case; + } + /* Host user's home dir */ gupnp_context_host_path (tracker->priv->context, g_get_home_dir (), HOME_DIR_ALIAS); return object; + +error_case: + g_object_unref (object); + + return NULL; } static void @@ -328,6 +364,62 @@ add_item (GUPnPContext *context, gupnp_didl_lite_writer_end_item (didl_writer); } +static void +add_item_from_db (GUPnPMediaTracker *tracker, + const char *category, + const char *path, + const char *parent_id) +{ + char *keys[] = {"File:Name", + "File:Mime", + NULL}; + char **values; + char *full_path; + gboolean success; + GError *error; + + full_path = g_build_filename (g_get_home_dir (), + path, + NULL); + + values = NULL; + error = NULL; + /* TODO: make this async */ + success = dbus_g_proxy_call (tracker->priv->metadata_proxy, + "Get", + &error, + G_TYPE_STRING, category, + G_TYPE_STRING, full_path, + G_TYPE_STRV, keys, + G_TYPE_INVALID, + G_TYPE_STRV, &values, + G_TYPE_INVALID); + g_free (full_path); + + if (!success || + values == NULL || + values[0] == NULL || + values[1] == NULL) { + g_critical ("failed to get metadata for %s.", path); + + if (error) { + g_critical ("Reason: %s\n", error->message); + + g_error_free (error); + } + + return; + } + + add_item (tracker->priv->context, + tracker->priv->didl_writer, + path, + parent_id, + values[1], + values[0], + path); +} + GUPnPMediaTracker * gupnp_media_tracker_new (const char *root_id, GUPnPContext *context) @@ -366,14 +458,11 @@ gupnp_media_tracker_browse (GUPnPMediaTracker *tracker, NULL, TRUE); /* Add items */ - for (i = 0; items[i][0]; i++) - add_item (tracker->priv->context, - tracker->priv->didl_writer, - items[i][0], - tracker->priv->root_id, - items[i][1], - items[i][2], - items[i][3]); + for (i = 0; items[i]; i++) + add_item_from_db (tracker, + "Music", + items[i], + tracker->priv->root_id); /* End DIDL-Lite fragment */ gupnp_didl_lite_writer_end_didl_lite (tracker->priv->didl_writer); @@ -417,14 +506,11 @@ gupnp_media_tracker_get_metadata (GUPnPMediaTracker *tracker, } else { /* Find and add the item */ for (i = 0; items[i][0]; i++) { - if (strcmp (object_id, items[i][0]) == 0) { - add_item (tracker->priv->context, - tracker->priv->didl_writer, - items[i][0], - tracker->priv->root_id, - items[i][1], - items[i][2], - items[i][3]); + if (strcmp (object_id, items[i]) == 0) { + add_item_from_db (tracker, + "Music", + items[i], + tracker->priv->root_id); found = TRUE; -- 2.7.4