[rhythmbox] transfer-target: add prepare and upload methods
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] transfer-target: add prepare and upload methods
- Date: Thu, 21 Oct 2021 05:30:04 +0000 (UTC)
commit 14c9fbbbfe87cda73205f8501372339a7de94180
Author: Jonathan Matthew <jonathan d14n org>
Date: Thu Oct 21 14:58:42 2021 +1000
transfer-target: add prepare and upload methods
These are called from task threads (using the signals just added
to RBTrackTransferBatch). If the target has an upload method,
always use a temporary file as the destination for the transfer,
so the target doesn't need to have a build_dest_uri method.
sources/rb-transfer-target.c | 85 ++++++++++++++++++++++++++++++++++++++++++++
sources/rb-transfer-target.h | 20 +++++++++++
2 files changed, 105 insertions(+)
---
diff --git a/sources/rb-transfer-target.c b/sources/rb-transfer-target.c
index 0692576e3..41228710d 100644
--- a/sources/rb-transfer-target.c
+++ b/sources/rb-transfer-target.c
@@ -88,6 +88,10 @@ rb_transfer_target_build_dest_uri (RBTransferTarget *target,
RBTransferTargetInterface *iface = RB_TRANSFER_TARGET_GET_IFACE (target);
char *uri;
+ /* if we require a separate upload step, always transfer to a temporary file */
+ if (iface->track_upload)
+ return g_strdup (RB_ENCODER_DEST_TEMPFILE);
+
uri = iface->build_dest_uri (target, entry, media_type, extension);
if (uri != NULL) {
rb_debug ("built dest uri for media type '%s', extension '%s': %s",
@@ -100,6 +104,54 @@ rb_transfer_target_build_dest_uri (RBTransferTarget *target,
return uri;
}
+/**
+ * rb_transfer_target_track_prepare:
+ * @target: an #RBTransferTarget
+ * @entry: the source #RhythmDBEntry for the transfer
+ * @uri: the destination URI
+ * @error: returns error information
+ *
+ * Performs any preparation necessary before starting the transfer.
+ * This is called on a task thread, so no UI interaction is possible.
+ *
+ */
+void
+rb_transfer_target_track_prepare (RBTransferTarget *target,
+ RhythmDBEntry *entry,
+ const char *uri,
+ GError **error)
+{
+ RBTransferTargetInterface *iface = RB_TRANSFER_TARGET_GET_IFACE (target);
+ if (iface->track_prepare)
+ iface->track_prepare (target, entry, uri, error);
+}
+
+/**
+ * rb_transfer_target_track_upload:
+ * @target: an #RBTransferTarget
+ * @entry: the source #RhythmDBEntry for the transfer
+ * @uri: the destination URI
+ * @dest_size: the size of the destination file
+ * @media_type: the media type of the destination file
+ * @error: returns error information
+ *
+ * This is called after a transfer to a temporary file has finished,
+ * allowing the transfer target to upload the file to a device or a
+ * remote service.
+ */
+void
+rb_transfer_target_track_upload (RBTransferTarget *target,
+ RhythmDBEntry *entry,
+ const char *uri,
+ guint64 dest_size,
+ const char *media_type,
+ GError **error)
+{
+ RBTransferTargetInterface *iface = RB_TRANSFER_TARGET_GET_IFACE (target);
+ g_assert (iface->track_upload != NULL);
+ iface->track_upload (target, entry, uri, dest_size, media_type, error);
+}
+
/**
* rb_transfer_target_track_added:
* @target: an #RBTransferTarget
@@ -344,6 +396,35 @@ get_dest_uri_cb (RBTrackTransferBatch *batch,
return uri;
}
+static void
+track_prepare_cb (RBTrackTransferBatch *batch,
+ GTask *task,
+ RhythmDBEntry *entry,
+ const char *uri,
+ RBTransferTarget *target)
+{
+ GError *error = NULL;
+ rb_transfer_target_track_prepare (target, entry, uri, &error);
+ if (error != NULL)
+ g_task_return_error (task, error);
+}
+
+static void
+track_postprocess_cb (RBTrackTransferBatch *batch,
+ GTask *task,
+ RhythmDBEntry *entry,
+ const char *uri,
+ guint64 dest_size,
+ const char *media_type,
+ RBTransferTarget *target)
+{
+ GError *error = NULL;
+
+ rb_transfer_target_track_upload (target, entry, uri, dest_size, media_type, &error);
+ if (error != NULL)
+ g_task_return_error (task, error);
+}
+
static void
track_done_cb (RBTrackTransferBatch *batch,
RhythmDBEntry *entry,
@@ -382,6 +463,7 @@ track_done_cb (RBTrackTransferBatch *batch,
RBTrackTransferBatch *
rb_transfer_target_transfer (RBTransferTarget *target, GSettings *settings, GList *entries, gboolean defer)
{
+ RBTransferTargetInterface *iface = RB_TRANSFER_TARGET_GET_IFACE (target);
RBTrackTransferQueue *xferq;
RBTaskList *tasklist;
RBShell *shell;
@@ -406,6 +488,9 @@ rb_transfer_target_transfer (RBTransferTarget *target, GSettings *settings, GLis
batch = rb_track_transfer_batch_new (NULL, settings, NULL, G_OBJECT (target), G_OBJECT
(xferq));
g_signal_connect_object (batch, "get-dest-uri", G_CALLBACK (get_dest_uri_cb), target, 0);
+ g_signal_connect_object (batch, "track-prepare", G_CALLBACK (track_prepare_cb), target, 0);
+ if (iface->track_upload)
+ g_signal_connect_object (batch, "track-postprocess", G_CALLBACK
(track_postprocess_cb), target, 0);
g_signal_connect_object (batch, "track-done", G_CALLBACK (track_done_cb), target, 0);
} else {
start_batch = TRUE;
diff --git a/sources/rb-transfer-target.h b/sources/rb-transfer-target.h
index 15f2adc4b..6331eb980 100644
--- a/sources/rb-transfer-target.h
+++ b/sources/rb-transfer-target.h
@@ -49,6 +49,16 @@ struct _RBTransferTargetInterface
RhythmDBEntry *entry,
const char *media_type,
const char *extension);
+ void (*track_prepare) (RBTransferTarget *target,
+ RhythmDBEntry *entry,
+ const char *uri,
+ GError **error);
+ void (*track_upload) (RBTransferTarget *target,
+ RhythmDBEntry *entry,
+ const char *uri,
+ guint64 dest_size,
+ const char *media_type,
+ GError **error);
gboolean (*track_added) (RBTransferTarget *target,
RhythmDBEntry *entry,
const char *uri,
@@ -68,6 +78,16 @@ char* rb_transfer_target_build_dest_uri (RBTransferTarget *target,
RhythmDBEntry *entry,
const char *media_type,
const char *extension);
+void rb_transfer_target_track_prepare (RBTransferTarget *target,
+ RhythmDBEntry *entry,
+ const char *uri,
+ GError **error);
+void rb_transfer_target_track_upload (RBTransferTarget *target,
+ RhythmDBEntry *entry,
+ const char *uri,
+ guint64 dest_size,
+ const char *media_type,
+ GError **error);
void rb_transfer_target_track_added (RBTransferTarget *target,
RhythmDBEntry *entry,
const char *uri,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]