[rhythmbox] re-add the encoder destination size parameter



commit e282e7d2cc2031b9620564ae35dd2e2d2b1b1d0d
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sun Dec 27 18:23:50 2009 +1000

    re-add the encoder destination size parameter
    
    Turns out we need this for the ipod plugin, so it can set the file size
    field correctly in the ipod database.

 backends/gstreamer/rb-encoder-gst.c |   23 +++++++++++++++++++++--
 backends/rb-encoder.c               |    8 ++++----
 backends/rb-encoder.h               |    4 ++--
 bindings/python/rb.defs             |    2 ++
 plugins/ipod/rb-ipod-source.c       |    8 +++++---
 plugins/mtpdevice/rb-mtp-source.c   |    2 ++
 shell/rb-removable-media-manager.c  |   24 ++++++++++++++++++++++--
 shell/rb-removable-media-manager.h  |    1 +
 sources/rb-library-source.c         |    2 +-
 sources/rb-removable-media-source.c |    7 ++++---
 sources/rb-removable-media-source.h |    2 ++
 11 files changed, 66 insertions(+), 17 deletions(-)
---
diff --git a/backends/gstreamer/rb-encoder-gst.c b/backends/gstreamer/rb-encoder-gst.c
index 0db8115..4168d51 100644
--- a/backends/gstreamer/rb-encoder-gst.c
+++ b/backends/gstreamer/rb-encoder-gst.c
@@ -185,6 +185,9 @@ static void
 rb_encoder_gst_emit_completed (RBEncoderGst *encoder)
 {
 	GError *error = NULL;
+	guint64 dest_size;
+	GFile *file;
+	GFileInfo *file_info;
 
 	g_return_if_fail (encoder->priv->completion_emitted == FALSE);
 
@@ -206,8 +209,24 @@ rb_encoder_gst_emit_completed (RBEncoderGst *encoder)
 		g_error_free (error);
 	}
 
+	/* find the size of the output file, assuming we can get at it with gio */
+	dest_size = 0;
+	file = g_file_new_for_uri (encoder->priv->dest_uri);
+	file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &error);
+	if (error != NULL) {
+		rb_debug ("couldn't get size of destination %s: %s",
+			  encoder->priv->dest_uri,
+			  error->message);
+		g_clear_error (&error);
+	} else {
+		dest_size = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_STANDARD_SIZE);
+		rb_debug ("destination file size: %" G_GUINT64_FORMAT, dest_size);
+		g_object_unref (file_info);
+	}
+	g_object_unref (file);
+
 	encoder->priv->completion_emitted = TRUE;
-	_rb_encoder_emit_completed (RB_ENCODER (encoder));
+	_rb_encoder_emit_completed (RB_ENCODER (encoder), dest_size);
 }
 
 static void
@@ -1023,7 +1042,7 @@ rb_encoder_gst_encode (RBEncoder *encoder,
 					     error->message);		/* I guess */
 
 		_rb_encoder_emit_error (encoder, error);
-		_rb_encoder_emit_completed (encoder);
+		_rb_encoder_emit_completed (encoder, 0);
 		g_error_free (error);
 		return FALSE;
 	}
diff --git a/backends/rb-encoder.c b/backends/rb-encoder.c
index ec957b1..60d483b 100644
--- a/backends/rb-encoder.c
+++ b/backends/rb-encoder.c
@@ -150,9 +150,9 @@ rb_encoder_interface_init (RBEncoderIface *iface)
 			      G_SIGNAL_RUN_LAST,
 			      G_STRUCT_OFFSET (RBEncoderIface, completed),
 			      NULL, NULL,
-			      g_cclosure_marshal_VOID__VOID,
+			      rb_marshal_VOID__UINT64,
 			      G_TYPE_NONE,
-			      0);
+			      1, G_TYPE_UINT64);
 	/**
 	 * RBEncoder::error:
 	 * @encoder: the #RBEncoder instance
@@ -299,9 +299,9 @@ _rb_encoder_emit_progress (RBEncoder *encoder, double fraction)
 }
 
 void
-_rb_encoder_emit_completed (RBEncoder *encoder)
+_rb_encoder_emit_completed (RBEncoder *encoder, guint64 dest_size)
 {
-	g_signal_emit (encoder, signals[COMPLETED], 0);
+	g_signal_emit (encoder, signals[COMPLETED], 0, dest_size);
 }
 
 void
diff --git a/backends/rb-encoder.h b/backends/rb-encoder.h
index 7cc5637..d8e4b61 100644
--- a/backends/rb-encoder.h
+++ b/backends/rb-encoder.h
@@ -80,7 +80,7 @@ struct _RBEncoderIface
 
 	/* signals */
 	void (*progress) (RBEncoder *encoder,  double fraction);
-	void (*completed) (RBEncoder *encoder);
+	void (*completed) (RBEncoder *encoder, guint64 dest_size);
 	void (*error) (RBEncoder *encoder, GError *error);
 };
 
@@ -118,7 +118,7 @@ gboolean	rb_encoder_get_preferred_mimetype (RBEncoder *encoder,
 
 /* only to be used by subclasses */
 void	_rb_encoder_emit_progress (RBEncoder *encoder, double fraction);
-void	_rb_encoder_emit_completed (RBEncoder *encoder);
+void	_rb_encoder_emit_completed (RBEncoder *encoder, guint64 dest_size);
 void	_rb_encoder_emit_error (RBEncoder *encoder, GError *error);
 
 void	_rb_encoder_emit_prepare_source (RBEncoder *encoder, const char *uri, GObject *source);
diff --git a/bindings/python/rb.defs b/bindings/python/rb.defs
index d2f3c2b..66e4fc5 100644
--- a/bindings/python/rb.defs
+++ b/bindings/python/rb.defs
@@ -1862,6 +1862,7 @@
   (parameters
     '("RhythmDBEntry*" "entry")
     '("const-char*" "uri")
+    '("guint64" "filesize")
     '("const-char*" "mimetype")
   )
 )
@@ -1888,6 +1889,7 @@
   (parameters
     '("RhythmDBEntry*" "entry")
     '("const-char*" "uri")
+    '("guint64" "track_added")
     '("const-char*" "mimetype")
   )
 )
diff --git a/plugins/ipod/rb-ipod-source.c b/plugins/ipod/rb-ipod-source.c
index 6618f6d..ebd4cb0 100644
--- a/plugins/ipod/rb-ipod-source.c
+++ b/plugins/ipod/rb-ipod-source.c
@@ -73,6 +73,7 @@ static GList * impl_get_mime_types (RBRemovableMediaSource *source);
 static gboolean impl_track_added (RBRemovableMediaSource *source,
 				  RhythmDBEntry *entry,
 				  const char *dest,
+				  guint64 filesize,
 				  const char *mimetype);
 static char* impl_build_dest_uri (RBRemovableMediaSource *source,
 				  RhythmDBEntry *entry,
@@ -535,7 +536,7 @@ load_ipod_playlists (RBiPodSource *source)
 #define MEDIATYPE_PODCAST       0x0004
 
 static Itdb_Track *
-create_ipod_song_from_entry (RhythmDBEntry *entry, const char *mimetype)
+create_ipod_song_from_entry (RhythmDBEntry *entry, guint64 filesize, const char *mimetype)
 {
 	Itdb_Track *track;
 
@@ -550,7 +551,7 @@ create_ipod_song_from_entry (RhythmDBEntry *entry, const char *mimetype)
 	                                                RHYTHMDB_PROP_ALBUM_SORTNAME);
 	track->genre = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_GENRE);
 	track->filetype = g_strdup (mimetype);
-	track->size = rhythmdb_entry_get_uint64 (entry, RHYTHMDB_PROP_FILE_SIZE);
+	track->size = filesize;
 	track->tracklen = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DURATION);
 	track->tracklen *= 1000;
 	track->cd_nr = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DISC_NUMBER);
@@ -1306,6 +1307,7 @@ static gboolean
 impl_track_added (RBRemovableMediaSource *source,
 		  RhythmDBEntry *entry,
 		  const char *dest,
+		  guint64 filesize,
 		  const char *mimetype)
 {
 	RBiPodSource *isource = RB_IPOD_SOURCE (source);
@@ -1314,7 +1316,7 @@ impl_track_added (RBRemovableMediaSource *source,
 
 	db = get_db_for_source (isource);
 
-	song = create_ipod_song_from_entry (entry, mimetype);
+	song = create_ipod_song_from_entry (entry, filesize, mimetype);
 	if (song != NULL) {
 		RBiPodSourcePrivate *priv = IPOD_SOURCE_GET_PRIVATE (source);
 		char *filename;
diff --git a/plugins/mtpdevice/rb-mtp-source.c b/plugins/mtpdevice/rb-mtp-source.c
index 619fe45..672bd48 100644
--- a/plugins/mtpdevice/rb-mtp-source.c
+++ b/plugins/mtpdevice/rb-mtp-source.c
@@ -77,6 +77,7 @@ static GList * impl_get_mime_types (RBRemovableMediaSource *source);
 static gboolean impl_track_added (RBRemovableMediaSource *source,
 				  RhythmDBEntry *entry,
 				  const char *dest,
+				  guint64 filesize,
 				  const char *mimetype);
 static gboolean impl_track_add_error (RBRemovableMediaSource *source,
 				      RhythmDBEntry *entry,
@@ -933,6 +934,7 @@ static gboolean
 impl_track_added (RBRemovableMediaSource *source,
 		  RhythmDBEntry *entry,
 		  const char *dest,
+		  guint64 filesize,
 		  const char *mimetype)
 {
 	LIBMTP_track_t *track = NULL;
diff --git a/shell/rb-removable-media-manager.c b/shell/rb-removable-media-manager.c
index a70825b..9745ca0 100644
--- a/shell/rb-removable-media-manager.c
+++ b/shell/rb-removable-media-manager.c
@@ -897,7 +897,11 @@ rb_removable_media_manager_unmount_cb (GObject *object,
 	GError *error = NULL;
 
 	rb_debug ("finishing unmount of mount");
+#if GLIB_CHECK_VERSION(2,22,0)
+	g_mount_unmount_with_operation_finish (mount, finish, &error);
+#else
 	g_mount_unmount_finish (mount, result, &error);
+#endif
 	if (error != NULL) {
 		if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED)) {
 			rb_error_dialog (NULL, _("Unable to unmount"), "%s", error->message);
@@ -981,12 +985,28 @@ rb_removable_media_manager_cmd_eject_medium (GtkAction *action, RBRemovableMedia
 				       (GAsyncReadyCallback) rb_removable_media_manager_eject_cb,
 				       g_object_ref (mgr));
 		} else if (g_mount_can_unmount (mount)) {
+#if GLIB_CHECK_VERSION(2,22,0)
+			GMountOperation *op;
+			GtkWindow *window;
+			g_object_get (mgr->priv->shell, "window", &window, NULL);
+			op = gtk_mount_operation_new (window);
+			g_object_unref (window);
+
+			rb_debug ("unmounting mount");
+			g_mount_unmount_with_operation (mount,
+							G_MOUNT_UNMOUNT_NONE,
+							op,
+							NULL,
+							(GAsyncReadyCallback) rb_removable_media_manager_unmount_cb,
+							g_object_ref (mgr));
+#else
 			rb_debug ("unmounting mount");
 			g_mount_unmount (mount,
 					 G_MOUNT_UNMOUNT_NONE,
 					 NULL,
 					 (GAsyncReadyCallback) rb_removable_media_manager_unmount_cb,
 					 g_object_ref (mgr));
+#endif
 		} else {
 			/* this should never happen; the eject command will be
 			 * insensitive if the selected source cannot be ejected.
@@ -1120,12 +1140,12 @@ progress_cb (RBEncoder *encoder, double fraction, TransferData *data)
 }
 
 static void
-completed_cb (RBEncoder *encoder, TransferData *data)
+completed_cb (RBEncoder *encoder, guint64 dest_size, TransferData *data)
 {
 	RBRemovableMediaManagerPrivate *priv = GET_PRIVATE (data->manager);
 
 	rb_debug ("completed transferring track to %s", data->dest);
-	(data->callback) (data->entry, data->dest, data->error, data->userdata);
+	(data->callback) (data->entry, data->dest, dest_size, data->error, data->userdata);
 
 	priv->transfer_running = FALSE;
 	priv->transfer_done++;
diff --git a/shell/rb-removable-media-manager.h b/shell/rb-removable-media-manager.h
index 6e831fe..3a77502 100644
--- a/shell/rb-removable-media-manager.h
+++ b/shell/rb-removable-media-manager.h
@@ -47,6 +47,7 @@ G_BEGIN_DECLS
 
 typedef void (*RBTransferCompleteCallback) (RhythmDBEntry *entry,
 					    const char *dest,
+					    guint64 dest_size,
 					    GError *error,
 					    gpointer userdata);
 
diff --git a/sources/rb-library-source.c b/sources/rb-library-source.c
index 787a7dc..6d261d9 100644
--- a/sources/rb-library-source.c
+++ b/sources/rb-library-source.c
@@ -1198,7 +1198,7 @@ impl_can_paste (RBSource *asource)
 }
 
 static void
-completed_cb (RhythmDBEntry *entry, const char *dest, GError *error, RBLibrarySource *source)
+completed_cb (RhythmDBEntry *entry, const char *dest, guint64 dest_size, GError *error, RBLibrarySource *source)
 {
 	if (error == NULL) {
 		rhythmdb_add_uri (source->priv->db, dest);
diff --git a/sources/rb-removable-media-source.c b/sources/rb-removable-media-source.c
index 09c6670..4effe92 100644
--- a/sources/rb-removable-media-source.c
+++ b/sources/rb-removable-media-source.c
@@ -304,10 +304,10 @@ struct _TrackAddedData {
 };
 
 static void
-_track_added_cb (RhythmDBEntry *entry, const char *uri, GError *error, struct _TrackAddedData *data)
+_track_added_cb (RhythmDBEntry *entry, const char *uri, guint64 dest_size, GError *error, struct _TrackAddedData *data)
 {
 	if (error == NULL) {
-		rb_removable_media_source_track_added (data->source, entry, uri, data->mimetype);
+		rb_removable_media_source_track_added (data->source, entry, uri, dest_size, data->mimetype);
 	} else {
 		rb_removable_media_source_track_add_error (data->source, entry, uri, error);
 	}
@@ -694,13 +694,14 @@ void
 rb_removable_media_source_track_added (RBRemovableMediaSource *source,
 				       RhythmDBEntry *entry,
 				       const char *uri,
+				       guint64 filesize,
 				       const char *mimetype)
 {
 	RBRemovableMediaSourceClass *klass = RB_REMOVABLE_MEDIA_SOURCE_GET_CLASS (source);
 	gboolean add_to_db = TRUE;
 
 	if (klass->impl_track_added)
-		add_to_db = klass->impl_track_added (source, entry, uri, mimetype);
+		add_to_db = klass->impl_track_added (source, entry, uri, filesize, mimetype);
 
 	if (add_to_db) {
 		RhythmDBEntryType entry_type;
diff --git a/sources/rb-removable-media-source.h b/sources/rb-removable-media-source.h
index 2210a2d..b85a0b6 100644
--- a/sources/rb-removable-media-source.h
+++ b/sources/rb-removable-media-source.h
@@ -58,6 +58,7 @@ typedef struct
 	gboolean	(*impl_track_added)	(RBRemovableMediaSource *source,
 						 RhythmDBEntry *entry,
 						 const char *uri,
+						 guint64 dest_size,
 						 const char *mimetype);
 	gboolean	(*impl_track_add_error) (RBRemovableMediaSource *source,
 						 RhythmDBEntry *entry,
@@ -79,6 +80,7 @@ char*		rb_removable_media_source_build_dest_uri 	(RBRemovableMediaSource *source
 void		rb_removable_media_source_track_added		(RBRemovableMediaSource *source,
 								 RhythmDBEntry *entry,
 								 const char *uri,
+								 guint64 dest_size,
 								 const char *mimetype);
 void		rb_removable_media_source_track_add_error	(RBRemovableMediaSource *source,
 								 RhythmDBEntry *entry,



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