[maemo-commits] [maemo-commits] r16243 - in projects/haf/branches/hildon-thumbnail/daemonize: . daemon
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Fri Sep 26 15:57:37 EEST 2008
- Previous message: [maemo-commits] r16241 - projects/haf/branches/hildon-thumbnail/daemonize/daemon
- Next message: [maemo-commits] r16244 - projects/haf/branches/hildon-thumbnail/daemonize/daemon
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: pvanhoof Date: 2008-09-26 15:57:34 +0300 (Fri, 26 Sep 2008) New Revision: 16243 Added: projects/haf/branches/hildon-thumbnail/daemonize/daemon/albumart-manager.c projects/haf/branches/hildon-thumbnail/daemonize/daemon/albumart-manager.h Modified: projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog projects/haf/branches/hildon-thumbnail/daemonize/daemon/Makefile.am projects/haf/branches/hildon-thumbnail/daemonize/daemon/albumart.c projects/haf/branches/hildon-thumbnail/daemonize/daemon/albumart.h projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-daemon.c Log: 2008-09-26 Philip Van Hoof <pvanhoof at gnome.org> * daemon/hildon-thumbnail-daemon.c * daemon/albumart.c * daemon/albumart.h * daemon/albumart-manager.c * daemon/albumart-manager.h * daemon/Makefile.am: Added a manager for albumart providers Modified: projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog 2008-09-26 12:21:32 UTC (rev 16242) +++ projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog 2008-09-26 12:57:34 UTC (rev 16243) @@ -1,6 +1,15 @@ 2008-09-26 Philip Van Hoof <pvanhoof at gnome.org> * daemon/hildon-thumbnail-daemon.c + * daemon/albumart.c + * daemon/albumart.h + * daemon/albumart-manager.c + * daemon/albumart-manager.h + * daemon/Makefile.am: Added a manager for albumart providers + +2008-09-26 Philip Van Hoof <pvanhoof at gnome.org> + + * daemon/hildon-thumbnail-daemon.c * daemon/thumbnail-manager.h * daemon/albumart.c * daemon/thumbnailer.c Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/Makefile.am =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/Makefile.am 2008-09-26 12:21:32 UTC (rev 16242) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/Makefile.am 2008-09-26 12:57:34 UTC (rev 16243) @@ -6,6 +6,7 @@ $(GMODULE_CFLAGS) \ $(GIO_CFLAGS) \ -DTHUMBNAILERS_DIR=\""/usr/share/thumbnailers"\" \ + -DALBUMARTERS_DIR=\""/usr/share/albumart-providers"\" \ -DPLUGINS_DIR=\""$(libdir)/hildon-thumbnailer/plugins"\" @@ -53,7 +54,9 @@ albumart.c \ albumart.h \ albumart-marshal.c \ - albumart-marshal.h + albumart-marshal.h \ + albumart-manager.c \ + albumart-manager.h hildon_thumbnailerd_LDADD = \ $(top_builddir)/daemon/libshared.la \ Copied: projects/haf/branches/hildon-thumbnail/daemonize/daemon/albumart-manager.c (from rev 16242, projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnail-manager.c) =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnail-manager.c 2008-09-26 12:21:32 UTC (rev 16242) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/albumart-manager.c 2008-09-26 12:57:34 UTC (rev 16243) @@ -0,0 +1,393 @@ +/* + * This file is part of hildon-albumart package + * + * Copyright (C) 2005 Nokia Corporation. All Rights reserved. + * + * Contact: Marius Vollmer <marius.vollmer at nokia.com> + * Author: Philip Van Hoof <pvanhoof at gnome.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#include <string.h> +#include <glib.h> +#include <gio/gio.h> +#include <dbus/dbus-glib-bindings.h> + +#include "albumart-manager.h" +#include "albumart.h" + +static GFile *artdir; +static GFileMonitor *artmon; + +#define ALBUMART_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_ALBUMART_MANAGER, AlbumartManagerPrivate)) + +G_DEFINE_TYPE (AlbumartManager, albumart_manager, G_TYPE_OBJECT) + + +void keep_alive (void); + +typedef struct { + DBusGConnection *connection; + GHashTable *handlers; + GMutex *mutex; +} AlbumartManagerPrivate; + +enum { + PROP_0, + PROP_CONNECTION +}; + +GList* +albumart_manager_get_handlers (AlbumartManager *object) +{ + AlbumartManagerPrivate *priv = ALBUMART_MANAGER_GET_PRIVATE (object); + GList *retval; + + g_mutex_lock (priv->mutex); + retval = g_hash_table_get_values (priv->handlers); + g_mutex_unlock (priv->mutex); + + return retval; +} + +static void +albumart_manager_add (AlbumartManager *object, gchar *insignificant_key, gchar *name) +{ + AlbumartManagerPrivate *priv = ALBUMART_MANAGER_GET_PRIVATE (object); + DBusGProxy *proxy; + gchar *path = g_strdup_printf ("/%s", name); + guint len = strlen (path); + guint i; + + /* Not sure if this path stuff makes any sense ... but it works */ + + for (i = 0; i< len; i++) { + if (path[i] == '.') + path[i] = '/'; + } + + proxy = dbus_g_proxy_new_for_name (priv->connection, name, + path, + PROVIDER_INTERFACE); + + g_hash_table_replace (priv->handlers, + g_strdup (path), + g_object_ref (proxy)); + + g_free (path); + +} + +typedef struct { + gchar *name; + guint64 mtime; + gboolean prio; +} ValueInfo; + +static void +free_valueinfo (ValueInfo *info) { + g_slice_free (ValueInfo, info); +} + +static void +albumart_manager_check_dir (AlbumartManager *object, gchar *path, gboolean override) +{ + AlbumartManagerPrivate *priv = ALBUMART_MANAGER_GET_PRIVATE (object); + const gchar *filen; + GDir *dir; + GHashTableIter iter; + GHashTable *pre; + gpointer pkey, pvalue; + gboolean has_override = FALSE; + + dir = g_dir_open (path, 0, NULL); + + if (!dir) + return; + + pre = g_hash_table_new_full (g_str_hash, g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) free_valueinfo); + + for (filen = g_dir_read_name (dir); filen; filen = g_dir_read_name (dir)) { + GKeyFile *keyfile; + gchar *fullfilen; + gchar *value; + GError *error = NULL; + guint i = 0; + guint64 mtime; + GFileInfo *info; + GFile *file; + ValueInfo *v_info; + + fullfilen = g_build_filename (path, filen, NULL); + keyfile = g_key_file_new (); + + /* If we can't parse it as a key-value file, skip */ + + if (!g_key_file_load_from_file (keyfile, fullfilen, G_KEY_FILE_NONE, NULL)) { + g_free (fullfilen); + continue; + } + + value = g_key_file_get_string (keyfile, "D-BUS Album art provider", "Name", NULL); + + /* If it doesn't have the required things, skip */ + + if (!value) { + g_free (fullfilen); + g_key_file_free (keyfile); + continue; + } + + /* Else, get the modificiation time, we'll need it later */ + + file = g_file_new_for_path (fullfilen); + + g_free (fullfilen); + + info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, + G_FILE_QUERY_INFO_NONE, + NULL, &error); + + /* If that didn't work out, skip */ + + if (error) { + if (info) + g_object_unref (info); + if (file) + g_object_unref (file); + g_free (value); + g_key_file_free (keyfile); + continue; + } + + mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); + + /* And register it in the temporary hashtable that is being formed */ + + v_info = g_slice_new (ValueInfo); + v_info->name = g_strdup (value); + + /* The modification time of the albumarter-service file is + * used, as specified, to determine the priority. We simply + * override older-ones with newer-ones in the hashtable (using + * replace). */ + + v_info->mtime = mtime; + + /* Only items in overrides are prioritized. */ + + v_info->prio = FALSE; + + g_hash_table_replace (pre, + g_strdup (path), + v_info); + + if (info) + g_object_unref (info); + if (file) + g_object_unref (file); + + g_free (value); + g_key_file_free (keyfile); + } + + g_dir_close (dir); + + g_hash_table_iter_init (&iter, pre); + + while (g_hash_table_iter_next (&iter, &pkey, &pvalue)) { + gchar *k = pkey; + ValueInfo *v = pvalue; + gchar *oname = NULL; + + /* If this is a prioritized one, we'll always override the older. If we + * are in overriding mode, we'll also override. We override by looking + * up the service-name for the MIME-type and we put that in oname, which + * stands for original-name. */ + + if (!v->prio && !override) { + DBusGProxy *proxy = g_hash_table_lookup (priv->handlers, k); + if (proxy) + oname = (gchar *) dbus_g_proxy_get_bus_name (proxy); + } + + /* Now if the original name is set (we'll override) and if the new name + * is different than the original-name (else there's no point in + * overriding anything, als the proxy will point to the same thing + * anyway), we add it (adding here means overriding, as replace is used + * on the hashtable). */ + + if (!oname || g_ascii_strcasecmp (v->name, oname) != 0) + albumart_manager_add (object, k, v->name); + } + + g_hash_table_unref (pre); +} + + +static void +on_dir_changed (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) +{ + switch (event_type) + { + case G_FILE_MONITOR_EVENT_CHANGED: + case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: + case G_FILE_MONITOR_EVENT_DELETED: + case G_FILE_MONITOR_EVENT_CREATED: { + gchar *path = g_file_get_path (file); + gboolean override = (strcmp (ALBUMARTERS_DIR, path) == 0); + + /* We override when it's the dir in the user's homedir*/ + albumart_manager_check_dir (ALBUMART_MANAGER (user_data), path, override); + + g_free (path); + } + break; + default: + break; + } +} + +static void +albumart_manager_check (AlbumartManager *object) +{ + AlbumartManagerPrivate *priv = ALBUMART_MANAGER_GET_PRIVATE (object); + GFileMonitor *monitor; + + g_mutex_lock (priv->mutex); + + /* We override when it's the one in the user's homedir*/ + albumart_manager_check_dir (object, ALBUMARTERS_DIR, FALSE); + + /* Monitor the dir for changes */ + artdir = g_file_new_for_path (ALBUMARTERS_DIR); + artmon = g_file_monitor_directory (artdir, G_FILE_MONITOR_NONE, NULL, NULL); + g_signal_connect (G_OBJECT (artmon), "changed", + G_CALLBACK (on_dir_changed), NULL); + + g_mutex_unlock (priv->mutex); +} + + +static void +albumart_manager_finalize (GObject *object) +{ + AlbumartManagerPrivate *priv = ALBUMART_MANAGER_GET_PRIVATE (object); + + g_hash_table_unref (priv->handlers); + g_mutex_free (priv->mutex); + + G_OBJECT_CLASS (albumart_manager_parent_class)->finalize (object); +} + +static void +albumart_manager_set_connection (AlbumartManager *object, DBusGConnection *connection) +{ + AlbumartManagerPrivate *priv = ALBUMART_MANAGER_GET_PRIVATE (object); + priv->connection = connection; +} + + +static void +albumart_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { + case PROP_CONNECTION: + albumart_manager_set_connection (ALBUMART_MANAGER (object), + g_value_get_pointer (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + + +static void +albumart_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + AlbumartManagerPrivate *priv; + + priv = ALBUMART_MANAGER_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_CONNECTION: + g_value_set_pointer (value, priv->connection); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +albumart_manager_class_init (AlbumartManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = albumart_manager_finalize; + object_class->set_property = albumart_manager_set_property; + object_class->get_property = albumart_manager_get_property; + + g_object_class_install_property (object_class, + PROP_CONNECTION, + g_param_spec_pointer ("connection", + "DBus connection", + "DBus connection", + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_type_class_add_private (object_class, sizeof (AlbumartManagerPrivate)); +} + +static void +albumart_manager_init (AlbumartManager *object) +{ + AlbumartManagerPrivate *priv = ALBUMART_MANAGER_GET_PRIVATE (object); + + priv->mutex = g_mutex_new (); + priv->handlers = g_hash_table_new_full (g_str_hash, g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) g_object_unref); +} + +void +albumart_manager_do_stop (void) +{ + g_object_unref (artdir); + g_object_unref (artdir); +} + +void +albumart_manager_do_init (DBusGConnection *connection, AlbumartManager **albumart_manager, GError **error) +{ + GObject *object; + + object = g_object_new (TYPE_ALBUMART_MANAGER, + "connection", connection, + NULL); + + albumart_manager_check (ALBUMART_MANAGER (object)); + + *albumart_manager = ALBUMART_MANAGER (object); +} Copied: projects/haf/branches/hildon-thumbnail/daemonize/daemon/albumart-manager.h (from rev 16242, projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnail-manager.h) =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnail-manager.h 2008-09-26 12:21:32 UTC (rev 16242) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/albumart-manager.h 2008-09-26 12:57:34 UTC (rev 16243) @@ -0,0 +1,52 @@ +#ifndef __ALBUMART_MANAGER_H__ +#define __ALBUMART_MANAGER_H__ + +/* + * This file is part of hildon-albumart package + * + * Copyright (C) 2005 Nokia Corporation. All Rights reserved. + * + * Contact: Marius Vollmer <marius.vollmer at nokia.com> + * Author: Philip Van Hoof <pvanhoof at gnome.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#define TYPE_ALBUMART_MANAGER (albumart_manager_get_type()) +#define ALBUMART_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_ALBUMART_MANAGER, AlbumartManager)) +#define ALBUMART_MANAGER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), TYPE_ALBUMART_MANAGER, AlbumartManagerClass)) +#define ALBUMART_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_ALBUMART_MANAGER, AlbumartManagerClass)) + +typedef struct AlbumartManager AlbumartManager; +typedef struct AlbumartManagerClass AlbumartManagerClass; + +struct AlbumartManager { + GObject parent; +}; + +struct AlbumartManagerClass { + GObjectClass parent; +}; + +GType albumart_manager_get_type (void); + +GList* albumart_manager_get_handlers (AlbumartManager *object); + +void albumart_manager_do_stop (void); +void albumart_manager_do_init (DBusGConnection *connection, AlbumartManager **albumart_manager, GError **error); + + +#endif Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/albumart.c =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/albumart.c 2008-09-26 12:21:32 UTC (rev 16242) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/albumart.c 2008-09-26 12:57:34 UTC (rev 16243) @@ -48,6 +48,7 @@ typedef struct { + AlbumartManager *manager; GThreadPool *normal_pool; GMutex *mutex; GList *tasks; @@ -170,7 +171,7 @@ if (!g_file_test (path, G_FILE_TEST_EXISTS)) { /* TODO */ - GList *proxies = NULL; + GList *proxies = albumart_manager_get_handlers (priv->manager); GList *copy = proxies; while (copy) { @@ -241,12 +242,21 @@ AlbumartPrivate *priv = ALBUMART_GET_PRIVATE (object); g_thread_pool_free (priv->normal_pool, TRUE, TRUE); - + g_object_unref (priv->manager); g_mutex_free (priv->mutex); G_OBJECT_CLASS (albumart_parent_class)->finalize (object); } +static void +albumart_set_manager (Albumart *object, AlbumartManager *manager) +{ + AlbumartPrivate *priv = ALBUMART_GET_PRIVATE (object); + if (priv->manager) + g_object_unref (priv->manager); + priv->manager = g_object_ref (manager); +} + static void albumart_set_property (GObject *object, guint prop_id, @@ -254,6 +264,10 @@ GParamSpec *pspec) { switch (prop_id) { + case PROP_MANAGER: + albumart_set_manager (ALBUMART (object), + g_value_get_object (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -271,6 +285,9 @@ priv = ALBUMART_GET_PRIVATE (object); switch (prop_id) { + case PROP_MANAGER: + g_value_set_object (value, priv->manager); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -285,6 +302,15 @@ object_class->set_property = albumart_set_property; object_class->get_property = albumart_get_property; + g_object_class_install_property (object_class, + PROP_MANAGER, + g_param_spec_object ("manager", + "Manager", + "Manager", + TYPE_ALBUMART_MANAGER, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + signals[READY_SIGNAL] = g_signal_new ("ready", G_OBJECT_CLASS_TYPE (object_class), @@ -362,7 +388,7 @@ void -albumart_do_init (DBusGConnection *connection, Albumart **albumart, GError **error) +albumart_do_init (DBusGConnection *connection, AlbumartManager *manager, Albumart **albumart, GError **error) { guint result; DBusGProxy *proxy; @@ -378,6 +404,7 @@ &result, error); object = g_object_new (TYPE_ALBUMART, + "manager", manager, NULL); dbus_g_object_type_install_info (G_OBJECT_TYPE (object), Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/albumart.h =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/albumart.h 2008-09-26 12:21:32 UTC (rev 16242) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/albumart.h 2008-09-26 12:57:34 UTC (rev 16243) @@ -27,6 +27,7 @@ #include <gmodule.h> +#include "albumart-manager.h" #define ALBUMART_SERVICE "com.nokia.albumart" #define ALBUMART_PATH "/com/nokia/albumart/Requester" @@ -61,6 +62,6 @@ void albumart_delete (Albumart *object, gchar *albumartist, gchar *uri, DBusGMethodInvocation *context); void albumart_do_stop (void); -void albumart_do_init (DBusGConnection *connection, Albumart **albumart, GError **error); +void albumart_do_init (DBusGConnection *connection, AlbumartManager *manager, Albumart **albumart, GError **error); #endif Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-daemon.c =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-daemon.c 2008-09-26 12:21:32 UTC (rev 16242) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-daemon.c 2008-09-26 12:57:34 UTC (rev 16243) @@ -32,6 +32,7 @@ #include "thumbnailer.h" #include "albumart.h" #include "thumbnail-manager.h" +#include "albumart-manager.h" static GHashTable *registrations; static gboolean do_shut_down_next_time = TRUE; @@ -184,6 +185,7 @@ GMainLoop *main_loop; GError *error = NULL; ThumbnailManager *manager; + AlbumartManager *a_manager; Thumbnailer *thumbnailer; Albumart *arter; DBusGProxy *manager_proxy; @@ -192,8 +194,10 @@ thumbnail_manager_do_init (connection, &manager, &error); thumbnailer_do_init (connection, manager, &thumbnailer, &error); - albumart_do_init (connection, &arter, &error); + albumart_manager_do_init (connection, &a_manager, &error); + albumart_do_init (connection, a_manager, &arter, &error); + manager_proxy = dbus_g_proxy_new_for_name (connection, MANAGER_SERVICE, MANAGER_PATH, @@ -224,10 +228,12 @@ albumart_do_stop (); thumbnailer_do_stop (); thumbnail_manager_do_stop (); + albumart_manager_do_stop (); g_object_unref (thumbnailer); g_object_unref (manager); g_object_unref (arter); + g_object_unref (a_manager); g_main_loop_unref (main_loop); }
- Previous message: [maemo-commits] r16241 - projects/haf/branches/hildon-thumbnail/daemonize/daemon
- Next message: [maemo-commits] r16244 - projects/haf/branches/hildon-thumbnail/daemonize/daemon
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]