[rhythmbox] only load tracks from media player devices when first selected



commit 16c07b21061ff7ae4e3c4c1edd9ada76db2de8e1
Author: Jonathan Matthew <jonathan d14n org>
Date:   Tue Mar 6 21:54:37 2012 +1000

    only load tracks from media player devices when first selected
    
    This avoids lots of slow file access for generic players that
    don't end up getting selected, and grabbing single-access MTP
    devices when other things may be trying to talk to them.
    
    We can now reliably select the device source via the
    rhythmbox-device desktop file, so if the device mounter is
    configured to invoke that, everything will work fine, whether
    Rhythmbox is already running or not.

 plugins/generic-player/rb-generic-player-source.c |   18 +++++++-
 plugins/ipod/rb-ipod-source.c                     |   16 ++++++-
 plugins/mtpdevice/rb-mtp-source.c                 |   47 ++++++++++++++-------
 3 files changed, 60 insertions(+), 21 deletions(-)
---
diff --git a/plugins/generic-player/rb-generic-player-source.c b/plugins/generic-player/rb-generic-player-source.c
index 133b7df..6ae56d5 100644
--- a/plugins/generic-player/rb-generic-player-source.c
+++ b/plugins/generic-player/rb-generic-player-source.c
@@ -75,6 +75,7 @@ static void load_songs (RBGenericPlayerSource *source);
 static gboolean impl_show_popup (RBDisplayPage *page);
 static void impl_delete_thyself (RBDisplayPage *page);
 static void impl_get_status (RBDisplayPage *page, char **text, char **progress_text, float *progress);
+static void impl_selected (RBDisplayPage *page);
 
 static gboolean impl_can_paste (RBSource *source);
 static RBTrackTransferBatch *impl_paste (RBSource *source, GList *entries);
@@ -118,6 +119,7 @@ typedef struct
 {
 	RhythmDB *db;
 
+	gboolean loaded;
 	RhythmDBImportJob *import_job;
 	gint load_playlists_id;
 	GList *playlists;
@@ -163,6 +165,7 @@ rb_generic_player_source_class_init (RBGenericPlayerSourceClass *klass)
 	page_class->show_popup = impl_show_popup;
 	page_class->delete_thyself = impl_delete_thyself;
 	page_class->get_status = impl_get_status;
+	page_class->selected = impl_selected;
 
 	source_class->impl_can_delete = impl_can_delete;
 	source_class->impl_delete = impl_delete;
@@ -316,8 +319,6 @@ impl_constructed (GObject *object)
 	}
 	g_strfreev (output_formats);
 
-        rb_media_player_source_load (RB_MEDIA_PLAYER_SOURCE (source));
-	load_songs (source);
 }
 
 static void
@@ -510,6 +511,19 @@ impl_delete_thyself (RBDisplayPage *page)
 }
 
 static void
+impl_selected (RBDisplayPage *page)
+{
+	RBGenericPlayerSource *source = RB_GENERIC_PLAYER_SOURCE (page);
+	RBGenericPlayerSourcePrivate *priv = GET_PRIVATE (source);
+
+	if (priv->loaded == FALSE) {
+		priv->loaded = TRUE;
+		rb_media_player_source_load (RB_MEDIA_PLAYER_SOURCE (source));
+		load_songs (source);
+	}
+}
+
+static void
 import_complete_cb (RhythmDBImportJob *job, int total, RBGenericPlayerSource *source)
 {
 	RBGenericPlayerSourceClass *klass = RB_GENERIC_PLAYER_SOURCE_GET_CLASS (source);
diff --git a/plugins/ipod/rb-ipod-source.c b/plugins/ipod/rb-ipod-source.c
index 9ba212b..aea499e 100644
--- a/plugins/ipod/rb-ipod-source.c
+++ b/plugins/ipod/rb-ipod-source.c
@@ -71,6 +71,7 @@ static void rb_ipod_load_songs (RBiPodSource *source);
 
 static gboolean impl_show_popup (RBDisplayPage *page);
 static void impl_delete_thyself (RBDisplayPage *page);
+static void impl_selected (RBDisplayPage *page);
 
 static gboolean impl_track_added (RBTransferTarget *target,
 				  RhythmDBEntry *entry,
@@ -177,6 +178,7 @@ rb_ipod_source_class_init (RBiPodSourceClass *klass)
 
 	page_class->delete_thyself = impl_delete_thyself;
 	page_class->show_popup = impl_show_popup;
+	page_class->selected = impl_selected;
 
 	source_class->impl_can_move_to_trash = (RBSourceFeatureFunc) rb_false_function;
 	source_class->impl_can_rename = (RBSourceFeatureFunc) rb_true_function;
@@ -322,8 +324,6 @@ finish_construction (RBiPodSource *source)
 	rb_entry_view_append_column (songs, RB_ENTRY_VIEW_COL_LAST_PLAYED, FALSE);
         rb_entry_view_append_column (songs, RB_ENTRY_VIEW_COL_FIRST_SEEN, FALSE);
 
-	rb_ipod_load_songs (source);
-
 	priv->art_store = rb_ext_db_new ("album-art");
 
 	/* is there model-specific data we need to pay attention to here?
@@ -334,7 +334,6 @@ finish_construction (RBiPodSource *source)
 	gst_encoding_target_add_profile (target, rb_gst_get_encoding_profile ("audio/x-aac"));
 	g_object_set (source, "encoding-target", target, NULL);
 
-        rb_media_player_source_load (RB_MEDIA_PLAYER_SOURCE (source));
 }
 
 static void
@@ -1989,6 +1988,17 @@ ipod_path_from_unix_path (const gchar *mount_point, const gchar *unix_path)
 }
 
 static void
+impl_selected (RBDisplayPage *page)
+{
+	RBiPodSourcePrivate *priv = IPOD_SOURCE_GET_PRIVATE (page);
+	
+	if (priv->ipod_db == NULL) {
+		rb_ipod_load_songs (RB_IPOD_SOURCE (page));
+		rb_media_player_source_load (RB_MEDIA_PLAYER_SOURCE (page));
+	}
+}
+
+static void
 impl_delete_thyself (RBDisplayPage *page)
 {
 	RBiPodSourcePrivate *priv = IPOD_SOURCE_GET_PRIVATE (page);
diff --git a/plugins/mtpdevice/rb-mtp-source.c b/plugins/mtpdevice/rb-mtp-source.c
index 699ca18..cbf640f 100644
--- a/plugins/mtpdevice/rb-mtp-source.c
+++ b/plugins/mtpdevice/rb-mtp-source.c
@@ -101,6 +101,7 @@ static char *impl_build_dest_uri (RBTransferTarget *target,
 static void impl_eject (RBDeviceSource *source);
 static gboolean impl_can_eject (RBDeviceSource *source);
 
+static void impl_selected (RBDisplayPage *page);
 static void mtp_device_open_cb (LIBMTP_mtpdevice_t *device, RBMtpSource *source);
 static void mtp_tracklist_cb (LIBMTP_track_t *tracks, RBMtpSource *source);
 static RhythmDB * get_db_for_source (RBMtpSource *source);
@@ -133,6 +134,7 @@ static GMount *find_mount_for_device (GUdevDevice *device);
 
 typedef struct
 {
+	gboolean tried_open;
 	RBMtpThread *device_thread;
 	LIBMTP_raw_device_t raw_device;
 	GHashTable *entry_map;
@@ -191,6 +193,7 @@ rb_mtp_source_class_init (RBMtpSourceClass *klass)
 	object_class->get_property = rb_mtp_source_get_property;
 
 	page_class->show_popup = impl_show_popup;
+	page_class->selected = impl_selected;
 
 	source_class->impl_can_rename = (RBSourceFeatureFunc) rb_true_function;
 	source_class->impl_can_delete = (RBSourceFeatureFunc) rb_true_function;
@@ -329,24 +332,16 @@ unmount_done_cb (GObject *object, GAsyncResult *result, gpointer psource)
 #endif
 
 static void
-rb_mtp_source_constructed (GObject *object)
+impl_selected (RBDisplayPage *page)
 {
-	RBMtpSource *source;
-	RBMtpSourcePrivate *priv;
-	RBEntryView *tracks;
-	RBShell *shell;
-	RBShellPlayer *shell_player;
-	GObject *player_backend;
-	GtkIconTheme *theme;
-	GdkPixbuf *pixbuf;
+	RBMtpSourcePrivate *priv = MTP_SOURCE_GET_PRIVATE (page);
 #if defined(HAVE_GUDEV)
 	GMount *mount;
 #endif
-	gint size;
 
-	RB_CHAIN_GOBJECT_METHOD (rb_mtp_source_parent_class, constructed, object);
-	source = RB_MTP_SOURCE (object);
-	priv = MTP_SOURCE_GET_PRIVATE (source);
+	if (priv->tried_open)
+		return;
+	priv->tried_open = TRUE;
 
 	/* try to open the device.  if gvfs has mounted it, unmount it first */
 #if defined(HAVE_GUDEV)
@@ -358,11 +353,31 @@ rb_mtp_source_constructed (GObject *object)
 						NULL,
 						NULL,
 						unmount_done_cb,
-						g_object_ref (source));
+						g_object_ref (page));
 		/* mount gets unreffed in callback */
-	} else
+	} else {
+		rb_debug ("device isn't mounted");
+		open_device (RB_MTP_SOURCE (page));
+	}
+#else
+	open_device (RB_MTP_SOURCE (page));
 #endif
-	open_device (source);
+}
+
+static void
+rb_mtp_source_constructed (GObject *object)
+{
+	RBMtpSource *source;
+	RBEntryView *tracks;
+	RBShell *shell;
+	RBShellPlayer *shell_player;
+	GObject *player_backend;
+	GtkIconTheme *theme;
+	GdkPixbuf *pixbuf;
+	gint size;
+
+	RB_CHAIN_GOBJECT_METHOD (rb_mtp_source_parent_class, constructed, object);
+	source = RB_MTP_SOURCE (object);
 
 	tracks = rb_source_get_entry_view (RB_SOURCE (source));
 	rb_entry_view_append_column (tracks, RB_ENTRY_VIEW_COL_RATING, FALSE);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]