[rhythmbox] source: optionally return a transfer batch from rb_source_paste()



commit c3390eb027ab3681cde0667c0e3584b20db02728
Author: Jonathan Matthew <jonathan d14n org>
Date:   Tue Aug 3 15:34:48 2010 +1000

    source: optionally return a transfer batch from rb_source_paste()
    
    This allows the caller to easily track the transfer without having
    to watch the transfer queue's batch property.

 shell/rb-track-transfer-batch.c     |    5 +++--
 shell/rb-track-transfer-batch.h     |    5 ++---
 sources/rb-library-source.c         |   10 ++++++----
 sources/rb-removable-media-source.c |    8 +++++---
 sources/rb-source.c                 |   14 +++++++++++---
 sources/rb-source.h                 |    5 +++--
 sources/rb-static-playlist-source.c |    6 ++++--
 7 files changed, 34 insertions(+), 19 deletions(-)
---
diff --git a/shell/rb-track-transfer-batch.c b/shell/rb-track-transfer-batch.c
index e7acba7..9a75b6c 100644
--- a/shell/rb-track-transfer-batch.c
+++ b/shell/rb-track-transfer-batch.c
@@ -30,6 +30,7 @@
 
 #include <glib/gi18n.h>
 
+#include "rb-source.h"
 #include "rb-track-transfer-batch.h"
 #include "rb-track-transfer-queue.h"
 #include "rb-encoder.h"
@@ -121,8 +122,8 @@ G_DEFINE_TYPE (RBTrackTransferBatch, rb_track_transfer_batch, G_TYPE_OBJECT)
 RBTrackTransferBatch *
 rb_track_transfer_batch_new (GList *media_types,
 			     const char * const *media_types_strv,
-			     RBSource *source,
-			     RBSource *destination)
+			     GObject *source,
+			     GObject *destination)
 {
 	GObject *obj;
 
diff --git a/shell/rb-track-transfer-batch.h b/shell/rb-track-transfer-batch.h
index ef4f637..813da0b 100644
--- a/shell/rb-track-transfer-batch.h
+++ b/shell/rb-track-transfer-batch.h
@@ -29,7 +29,6 @@
 #define __RB_TRACK_TRANSFER_BATCH_H
 
 #include <rhythmdb/rhythmdb.h>
-#include <sources/rb-source.h>
 
 G_BEGIN_DECLS
 
@@ -85,8 +84,8 @@ GType			rb_track_transfer_batch_get_type	(void);
 
 RBTrackTransferBatch *	rb_track_transfer_batch_new		(GList *media_type_list,
 								 const char * const *media_types,
-								 RBSource *source,
-								 RBSource *destination);
+								 GObject *source,
+								 GObject *destination);
 void			rb_track_transfer_batch_add		(RBTrackTransferBatch *batch,
 								 RhythmDBEntry *entry);
 
diff --git a/sources/rb-library-source.c b/sources/rb-library-source.c
index 5139d95..6871b10 100644
--- a/sources/rb-library-source.c
+++ b/sources/rb-library-source.c
@@ -82,7 +82,7 @@ static char *impl_get_browser_key (RBSource *source);
 static char *impl_get_paned_key (RBBrowserSource *source);
 static gboolean impl_receive_drag (RBSource *source, GtkSelectionData *data);
 static gboolean impl_can_paste (RBSource *asource);
-static void impl_paste (RBSource *source, GList *entries);
+static RBTrackTransferBatch *impl_paste (RBSource *source, GList *entries);
 static guint impl_want_uri (RBSource *source, const char *uri);
 static gboolean impl_add_uri (RBSource *source, const char *uri, const char *title, const char *genre);
 static void impl_get_status (RBSource *source, char **text, char **progress_text, float *progress);
@@ -1279,7 +1279,7 @@ track_done_cb (RBTrackTransferBatch *batch,
 	}
 }
 
-static void
+static RBTrackTransferBatch *
 impl_paste (RBSource *asource, GList *entries)
 {
 	RBLibrarySource *source = RB_LIBRARY_SOURCE (asource);
@@ -1293,7 +1293,7 @@ impl_paste (RBSource *asource, GList *entries)
 
 	if (impl_can_paste (asource) == FALSE) {
 		g_warning ("RBLibrarySource impl_paste called when gconf keys unset");
-		return;
+		return NULL;
 	}
 
 	sl = eel_gconf_get_string_list (CONF_LIBRARY_LOCATION);
@@ -1305,7 +1305,7 @@ impl_paste (RBSource *asource, GList *entries)
 	g_object_get (shell, "track-transfer-queue", &xferq, NULL);
 	g_object_unref (shell);
 
-	batch = rb_track_transfer_batch_new (NULL, NULL, NULL, RB_SOURCE (source));
+	batch = rb_track_transfer_batch_new (NULL, NULL, NULL, G_OBJECT (source));
 	g_signal_connect_object (batch, "get-dest-uri", G_CALLBACK (get_dest_uri_cb), source, 0);
 	g_signal_connect_object (batch, "track-done", G_CALLBACK (track_done_cb), source, 0);
 
@@ -1338,9 +1338,11 @@ impl_paste (RBSource *asource, GList *entries)
 		rb_track_transfer_queue_start_batch (xferq, batch);
 	} else {
 		g_object_unref (batch);
+		batch = NULL;
 	}
 
 	g_object_unref (xferq);
+	return batch;
 }
 
 static guint
diff --git a/sources/rb-removable-media-source.c b/sources/rb-removable-media-source.c
index 77f1604..e162f07 100644
--- a/sources/rb-removable-media-source.c
+++ b/sources/rb-removable-media-source.c
@@ -85,7 +85,7 @@ static void rb_removable_media_source_get_property (GObject *object,
 			                  GParamSpec *pspec);
 
 static void impl_delete_thyself (RBSource *source);
-static void impl_paste (RBSource *source, GList *entries);
+static RBTrackTransferBatch *impl_paste (RBSource *source, GList *entries);
 static gboolean impl_receive_drag (RBSource *asource, GtkSelectionData *data);
 static gboolean impl_should_paste (RBRemovableMediaSource *source,
 				   RhythmDBEntry *entry);
@@ -385,7 +385,7 @@ track_done_cb (RBTrackTransferBatch *batch,
 	}
 }
 
-static void
+static RBTrackTransferBatch *
 impl_paste (RBSource *bsource, GList *entries)
 {
 	RBRemovableMediaSource *source = RB_REMOVABLE_MEDIA_SOURCE (bsource);
@@ -405,7 +405,7 @@ impl_paste (RBSource *bsource, GList *entries)
 	g_object_unref (shell);
 
 	mime_types = rb_removable_media_source_get_mime_types (source);
-	batch = rb_track_transfer_batch_new (mime_types, NULL, NULL, RB_SOURCE (source));
+	batch = rb_track_transfer_batch_new (mime_types, NULL, NULL, G_OBJECT (source));
 	rb_list_deep_free (mime_types);
 
 	g_signal_connect_object (batch, "get-dest-uri", G_CALLBACK (get_dest_uri_cb), source, 0);
@@ -442,8 +442,10 @@ impl_paste (RBSource *bsource, GList *entries)
 		rb_track_transfer_queue_start_batch (xferq, batch);
 	} else {
 		g_object_unref (batch);
+		batch = NULL;
 	}
 	g_object_unref (xferq);
+	return batch;
 }
 
 static guint
diff --git a/sources/rb-source.c b/sources/rb-source.c
index c7f4e42..66170be 100644
--- a/sources/rb-source.c
+++ b/sources/rb-source.c
@@ -1139,14 +1139,22 @@ rb_source_copy (RBSource *source)
  * @entries: a list of #RhythmDBEntry objects to paste in
  *
  * Adds a list of entries previously cut or copied from another
- * source.
+ * source.  If the entries are not of the type used by the source,
+ * the entries will be copied and possibly converted into an acceptable format.
+ * This can be used for transfers to and from devices and network shares.
+ *
+ * If the transfer is performed using an #RBTrackTransferBatch, the batch object
+ * is returned so the caller can monitor the transfer progress.  The caller does not
+ * own a reference on the batch object.
+ *
+ * Return value: the #RBTrackTransferBatch used to perform the transfer (if any)
  */
-void
+RBTrackTransferBatch *
 rb_source_paste (RBSource *source, GList *entries)
 {
 	RBSourceClass *klass = RB_SOURCE_GET_CLASS (source);
 
-	klass->impl_paste (source, entries);
+	return klass->impl_paste (source, entries);
 }
 
 /**
diff --git a/sources/rb-source.h b/sources/rb-source.h
index b1d3613..4bc33ce 100644
--- a/sources/rb-source.h
+++ b/sources/rb-source.h
@@ -35,6 +35,7 @@
 #include <sources/rb-source-search.h>
 #include <widgets/rb-entry-view.h>
 #include <shell/rb-shell-preferences.h>
+#include <shell/rb-track-transfer-batch.h>
 #include <rhythmdb/rhythmdb-import-job.h>
 
 G_BEGIN_DECLS
@@ -116,7 +117,7 @@ struct _RBSourceClass
 
 	GList *		(*impl_cut)		(RBSource *source);
 	GList *		(*impl_copy)		(RBSource *source);
-	void		(*impl_paste)		(RBSource *source, GList *entries);
+	RBTrackTransferBatch *(*impl_paste)	(RBSource *source, GList *entries);
 	void		(*impl_delete)		(RBSource *source);
 	void		(*impl_add_to_queue)	(RBSource *source, RBSource *queue);
 	void		(*impl_move_to_trash)	(RBSource *source);
@@ -185,7 +186,7 @@ gboolean	rb_source_can_show_properties	(RBSource *source);
 
 GList *		rb_source_cut			(RBSource *source);
 GList *		rb_source_copy			(RBSource *source);
-void		rb_source_paste			(RBSource *source, GList *entries);
+RBTrackTransferBatch *rb_source_paste			(RBSource *source, GList *entries);
 void		rb_source_delete		(RBSource *source);
 void		rb_source_add_to_queue		(RBSource *source, RBSource *queue);
 void		rb_source_move_to_trash		(RBSource *source);
diff --git a/sources/rb-static-playlist-source.c b/sources/rb-static-playlist-source.c
index 6310bba..347b4dd 100644
--- a/sources/rb-static-playlist-source.c
+++ b/sources/rb-static-playlist-source.c
@@ -73,7 +73,7 @@ static void rb_static_playlist_source_get_property (GObject *object,
 
 /* source methods */
 static GList * impl_cut (RBSource *source);
-static void impl_paste (RBSource *asource, GList *entries);
+static RBTrackTransferBatch *impl_paste (RBSource *asource, GList *entries);
 static void impl_delete (RBSource *source);
 static void impl_search (RBSource *asource, RBSourceSearch *search, const char *cur_text, const char *new_text);
 static void impl_browser_toggled (RBSource *source, gboolean enabled);
@@ -482,13 +482,15 @@ impl_cut (RBSource *asource)
 	return sel;
 }
 
-static void
+static RBTrackTransferBatch *
 impl_paste (RBSource *asource, GList *entries)
 {
 	RBStaticPlaylistSource *source = RB_STATIC_PLAYLIST_SOURCE (asource);
 
 	for (; entries; entries = g_list_next (entries))
 		rb_static_playlist_source_add_entry (source, entries->data, -1);
+
+	return NULL;
 }
 
 static void



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