G'day everyone, After noticing a small problem with watching for changed files the other day (bug 316910), I realised how close we were to having proper "Watched Directories" done (which is bug 160159). Attached is a small patch which lets Rhythmbox monitor directories for new tracks. However there are several caveats: * There is no UI for it yet. Set the gconf key /apps/rhythmbox/library_locations to be a list of strings, which are the URIs of the director(y/ies) you want to watch. NOTE: these are uris with trailing slashes, not path names - e.g. "file:///media/music/" not "/media/music". * Rhythmbox will not monitor tracks in the library for changes, if they are not in a watched directory. This is currently half-broken anyway (due to bug 316910), and should be easy enough to fix. Hopefully I'll get around to fixing those two soonish, but I though I'd post it anyway so that people can take a look. Cheers, James "Doc" Livingston -- "I know gcc suggest just an extra set of parenthesis, but I'm personally convinced that is just because some gcc people have been damaged by too much LISP." -- Linus Torvalds
Index: data/rhythmbox.schemas
===================================================================
RCS file: /cvs/gnome/rhythmbox/data/rhythmbox.schemas,v
retrieving revision 1.50
diff -u -r1.50 rhythmbox.schemas
--- data/rhythmbox.schemas 24 Sep 2005 14:19:15 -0000 1.50
+++ data/rhythmbox.schemas 5 Oct 2005 13:53:27 -0000
@@ -25,6 +25,17 @@
<long>When Rhythmbox's database contains a song stored on a mount point that is no longer available, Rhythmbox won't remove it from its XML file immedialty, but will keep it for a number of days defined by this key. Setting it to a negative number makes Rhythmbox keep the songs forever.</long>
</locale>
</schema>
+ <schema>
+ <key>/schemas/apps/rhythmbox/library_locations</key>
+ <applyto>/apps/rhythmbox/library_locations</applyto>
+ <owner>rhythmbox</owner>
+ <type>list</type>
+ <default></default>
+ <locale name="C">
+ <short>Directories that Rhythmbox should monitor</short>
+ <long>A list of directory URIs that Rhythmbox should monitor for changes and new tracks.</long>
+ </locale>
+ </schema>
<schema>
<key>/schemas/apps/rhythmbox/state/paned_position</key>
Index: lib/rb-preferences.h
===================================================================
RCS file: /cvs/gnome/rhythmbox/lib/rb-preferences.h,v
retrieving revision 1.17
diff -u -r1.17 rb-preferences.h
--- lib/rb-preferences.h 24 Sep 2005 14:19:16 -0000 1.17
+++ lib/rb-preferences.h 5 Oct 2005 13:53:27 -0000
@@ -29,6 +29,7 @@
#define CONF_FIRST_TIME CONF_PREFIX "/first_time_flag"
#define CONF_GRACE_PERIOD CONF_PREFIX "/grace_period"
+#define CONF_LIBRARY_LOCATION CONF_PREFIX "/library_locations"
#define CONF_UI_DIR CONF_PREFIX "/ui"
#define CONF_UI_STATUSBAR_HIDDEN CONF_PREFIX "/ui/statusbar_hidden"
#define CONF_UI_SOURCELIST_HIDDEN CONF_PREFIX "/ui/sourcelist_hidden"
Index: rhythmdb/rhythmdb.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/rhythmdb/rhythmdb.c,v
retrieving revision 1.118
diff -u -r1.118 rhythmdb.c
--- rhythmdb/rhythmdb.c 28 Sep 2005 14:28:25 -0000 1.118
+++ rhythmdb/rhythmdb.c 5 Oct 2005 13:53:31 -0000
@@ -47,6 +47,7 @@
#include "rb-util.h"
#include "rb-cut-and-paste-code.h"
#include "rb-preferences.h"
+#include "widgets/eel-gconf-extensions.h"
#define RB_PARSE_CONJ (xmlChar *) "conjunction"
#define RB_PARSE_SUBQUERY (xmlChar *) "subquery"
@@ -86,6 +87,8 @@
GAsyncQueue *restored_queue;
GHashTable *monitored_directories;
+ guint library_location_notify_id;
+ GSList *library_locations;
gboolean dry_run;
gboolean no_update;
@@ -200,6 +203,11 @@
static gboolean free_entry_changes (RhythmDBEntry *entry,
GSList *changes,
RhythmDB *db);
+static void library_location_changed_cb (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ RhythmDB *db);
+static void rhythmdb_sync_library_location (RhythmDB *db);
enum
{
@@ -615,8 +623,12 @@
db->priv->exiting = TRUE;
+ eel_gconf_notification_remove (db->priv->library_location_notify_id);
g_hash_table_foreach (db->priv->monitored_directories, (GHFunc) rhythmdb_unmonitor_directories,
db);
+ g_slist_foreach (db->priv->library_locations, (GFunc) g_free, NULL);
+ g_slist_free (db->priv->library_locations);
+ db->priv->library_locations = NULL;
while ((action = g_async_queue_try_pop (db->priv->action_queue)) != NULL)
rhythmdb_action_free (db, action);
@@ -1371,9 +1383,6 @@
/* Remember the mount point of the volume the song is on */
rhythmdb_entry_set_mount_point (db, entry, event->real_uri);
- if (event->vfsinfo->flags & GNOME_VFS_FILE_FLAGS_LOCAL)
- rhythmdb_monitor_uri_path (db, entry->location, NULL /* FIXME */);
-
rhythmdb_commit_internal (db, FALSE);
return TRUE;
@@ -1804,6 +1813,13 @@
klass->impl_load (db, &db->priv->exiting);
+ /* begin monitoring the for new tracks */
+ db->priv->library_location_notify_id =
+ eel_gconf_notification_add (CONF_LIBRARY_LOCATION,
+ (GConfClientNotifyFunc) library_location_changed_cb,
+ db);
+ rhythmdb_sync_library_location (db);
+
rb_debug ("queuing db load complete signal");
result = g_new0 (struct RhythmDBEvent, 1);
result->type = RHYTHMDB_EVENT_DB_LOAD;
@@ -3077,3 +3093,51 @@
}
}
}
+
+static void
+monitor_library_directory (char *uri, RhythmDB *db)
+{
+ GError *error = NULL;
+
+ rb_debug ("beginning monitor of the library directory");
+ rhythmdb_monitor_uri_path (db, uri, &error);
+
+ if (error) {
+ /* FIXME: should we complain to the user? */
+ rb_debug ("error while attempting to monitor the library directory: %s", error->message);
+ } else {
+ /* load any new tracks */
+ rb_debug ("loading new tracks from library directory");
+ rhythmdb_add_uri (db, uri);
+ }
+}
+
+static void
+rhythmdb_sync_library_location (RhythmDB *db)
+{
+ if (db->priv->library_locations) {
+ rb_debug ("ending monitor of the library directory");
+
+ g_hash_table_foreach (db->priv->monitored_directories,
+ (GHFunc) rhythmdb_unmonitor_directories,
+ db);
+ g_slist_foreach (db->priv->library_locations, (GFunc) g_free, NULL);
+ g_slist_free (db->priv->library_locations);
+ }
+
+ db->priv->library_locations = eel_gconf_get_string_list (CONF_LIBRARY_LOCATION);
+
+ if (db->priv->library_locations) {
+ g_slist_foreach (db->priv->library_locations, (GFunc) monitor_library_directory, db);
+ }
+}
+
+static void
+library_location_changed_cb (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ RhythmDB *db)
+{
+ rhythmdb_sync_library_location (db);
+}
+
Attachment:
signature.asc
Description: This is a digitally signed message part