[rhythmbox] track-transfer-batch: add RBTaskProgress interface
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] track-transfer-batch: add RBTaskProgress interface
- Date: Tue, 14 May 2013 12:41:55 +0000 (UTC)
commit 835db7ef88b4105ba6ef5030bd74f88e7b10ad75
Author: Jonathan Matthew <jonathan d14n org>
Date: Tue May 14 22:29:58 2013 +1000
track-transfer-batch: add RBTaskProgress interface
and make things that use transfer batches report progress through
the task list.
shell/rb-track-transfer-batch.c | 100 ++++++++++++++++++++++++++++++++++++--
sources/rb-library-source.c | 9 +++-
sources/rb-media-player-source.c | 10 ++++
sources/rb-transfer-target.c | 19 +++++++-
4 files changed, 132 insertions(+), 6 deletions(-)
---
diff --git a/shell/rb-track-transfer-batch.c b/shell/rb-track-transfer-batch.c
index 7c9459f..38bb1f7 100644
--- a/shell/rb-track-transfer-batch.c
+++ b/shell/rb-track-transfer-batch.c
@@ -40,6 +40,7 @@
#include "rb-debug.h"
#include "rb-util.h"
#include "rb-gst-media-types.h"
+#include "rb-task-progress.h"
enum
{
@@ -64,11 +65,18 @@ enum
PROP_TOTAL_ENTRIES,
PROP_DONE_ENTRIES,
PROP_PROGRESS,
- PROP_ENTRY_LIST
+ PROP_ENTRY_LIST,
+ PROP_TASK_LABEL,
+ PROP_TASK_DETAIL,
+ PROP_TASK_PROGRESS,
+ PROP_TASK_OUTCOME,
+ PROP_TASK_NOTIFY,
+ PROP_TASK_CANCELLABLE
};
static void rb_track_transfer_batch_class_init (RBTrackTransferBatchClass *klass);
static void rb_track_transfer_batch_init (RBTrackTransferBatch *batch);
+static void rb_track_transfer_batch_task_progress_init (RBTaskProgressInterface *iface);
static gboolean start_next (RBTrackTransferBatch *batch);
static void start_encoding (RBTrackTransferBatch *batch, gboolean overwrite);
@@ -104,9 +112,16 @@ struct _RBTrackTransferBatchPrivate
RBEncoder *current_encoder;
GstEncodingProfile *current_profile;
gboolean cancelled;
+
+ char *task_label;
+ gboolean task_notify;
};
-G_DEFINE_TYPE (RBTrackTransferBatch, rb_track_transfer_batch, G_TYPE_OBJECT)
+G_DEFINE_TYPE_EXTENDED (RBTrackTransferBatch,
+ rb_track_transfer_batch,
+ G_TYPE_OBJECT,
+ 0,
+ G_IMPLEMENT_INTERFACE (RB_TYPE_TASK_PROGRESS,
rb_track_transfer_batch_task_progress_init));
/**
* SECTION:rb-track-transfer-batch
@@ -315,6 +330,12 @@ rb_track_transfer_batch_cancel (RBTrackTransferBatch *batch)
rb_track_transfer_queue_cancel_batch (batch->priv->queue, batch);
}
+static void
+task_progress_cancel (RBTaskProgress *progress)
+{
+ rb_track_transfer_batch_cancel (RB_TRACK_TRANSFER_BATCH (progress));
+}
+
/**
* _rb_track_transfer_batch_start:
* @batch: a #RBTrackTransferBatch
@@ -387,6 +408,8 @@ _rb_track_transfer_batch_start (RBTrackTransferBatch *batch, GObject *queue)
batch->priv->total_fraction = 0.0;
g_signal_emit (batch, signals[STARTED], 0);
+ g_object_notify (G_OBJECT (batch), "task-progress");
+ g_object_notify (G_OBJECT (batch), "task-detail");
start_next (batch);
}
@@ -410,6 +433,7 @@ _rb_track_transfer_batch_cancel (RBTrackTransferBatch *batch)
}
g_signal_emit (batch, signals[CANCELLED], 0);
+ g_object_notify (G_OBJECT (batch), "task-outcome");
/* anything else? */
}
@@ -450,6 +474,7 @@ emit_progress (RBTrackTransferBatch *batch)
done,
total,
fraction);
+ g_object_notify (G_OBJECT (batch), "task-progress");
}
static void
@@ -576,6 +601,7 @@ start_next (RBTrackTransferBatch *batch)
if (batch->priv->entries == NULL) {
/* guess we must be done.. */
g_signal_emit (batch, signals[COMPLETE], 0);
+ g_object_notify (G_OBJECT (batch), "task-outcome");
return FALSE;
}
@@ -666,6 +692,7 @@ start_next (RBTrackTransferBatch *batch)
batch->priv->current,
batch->priv->current_dest_uri);
start_encoding (batch, FALSE);
+ g_object_notify (G_OBJECT (batch), "task-detail");
}
return TRUE;
@@ -698,6 +725,24 @@ impl_set_property (GObject *object,
case PROP_DESTINATION:
batch->priv->destination = g_value_dup_object (value);
break;
+ case PROP_TASK_LABEL:
+ batch->priv->task_label = g_value_dup_string (value);
+ break;
+ case PROP_TASK_DETAIL:
+ /* ignore */
+ break;
+ case PROP_TASK_PROGRESS:
+ /* ignore */
+ break;
+ case PROP_TASK_OUTCOME:
+ /* ignore */
+ break;
+ case PROP_TASK_NOTIFY:
+ batch->priv->task_notify = g_value_get_boolean (value);
+ break;
+ case PROP_TASK_CANCELLABLE:
+ /* ignore */
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -735,7 +780,8 @@ impl_get_property (GObject *object,
case PROP_DONE_ENTRIES:
g_value_set_int (value, g_list_length (batch->priv->done_entries));
break;
- case PROP_PROGRESS:
+ case PROP_TASK_PROGRESS:
+ case PROP_PROGRESS: /* needed? */
{
double p = batch->priv->total_fraction;
if (batch->priv->current != NULL) {
@@ -756,6 +802,39 @@ impl_get_property (GObject *object,
g_value_set_pointer (value, l);
}
break;
+ case PROP_TASK_LABEL:
+ g_value_set_string (value, batch->priv->task_label);
+ break;
+ case PROP_TASK_DETAIL:
+ {
+ int done;
+ int total;
+
+ done = g_list_length (batch->priv->done_entries);
+ total = done + g_list_length (batch->priv->entries);
+ if (batch->priv->current) {
+ total++;
+ done++;
+ }
+ g_value_take_string (value, g_strdup_printf (_("%d of %d"), done, total));
+ }
+ break;
+ case PROP_TASK_OUTCOME:
+ if (batch->priv->cancelled) {
+ g_value_set_enum (value, RB_TASK_OUTCOME_CANCELLED);
+ } else if ((batch->priv->entries == NULL) && (batch->priv->done_entries != NULL)) {
+ g_value_set_enum (value, RB_TASK_OUTCOME_COMPLETE);
+ } else {
+ g_value_set_enum (value, RB_TASK_OUTCOME_NONE);
+ }
+ break;
+ case PROP_TASK_NOTIFY:
+ /* we might want to notify sometimes, but we never did before */
+ g_value_set_boolean (value, FALSE);
+ break;
+ case PROP_TASK_CANCELLABLE:
+ g_value_set_boolean (value, TRUE);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -795,11 +874,18 @@ impl_finalize (GObject *object)
if (batch->priv->current != NULL) {
rhythmdb_entry_unref (batch->priv->current);
}
+ g_free (batch->priv->task_label);
G_OBJECT_CLASS (rb_track_transfer_batch_parent_class)->finalize (object);
}
static void
+rb_track_transfer_batch_task_progress_init (RBTaskProgressInterface *interface)
+{
+ interface->cancel = task_progress_cancel;
+}
+
+static void
rb_track_transfer_batch_class_init (RBTrackTransferBatchClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -896,6 +982,13 @@ rb_track_transfer_batch_class_init (RBTrackTransferBatchClass *klass)
"list of all entries in the batch",
G_PARAM_READABLE));
+ g_object_class_override_property (object_class, PROP_TASK_LABEL, "task-label");
+ g_object_class_override_property (object_class, PROP_TASK_DETAIL, "task-detail");
+ g_object_class_override_property (object_class, PROP_TASK_PROGRESS, "task-progress");
+ g_object_class_override_property (object_class, PROP_TASK_OUTCOME, "task-outcome");
+ g_object_class_override_property (object_class, PROP_TASK_NOTIFY, "task-notify");
+ g_object_class_override_property (object_class, PROP_TASK_CANCELLABLE, "task-cancellable");
+
/**
* RBTrackTransferBatch::started:
* @batch: the #RBTrackTransferBatch
@@ -1077,4 +1170,3 @@ rb_track_transfer_batch_class_init (RBTrackTransferBatchClass *klass)
g_type_class_add_private (klass, sizeof (RBTrackTransferBatchPrivate));
}
-
diff --git a/sources/rb-library-source.c b/sources/rb-library-source.c
index a4d5e79..6fa7376 100644
--- a/sources/rb-library-source.c
+++ b/sources/rb-library-source.c
@@ -1689,7 +1689,6 @@ impl_paste (RBSource *asource, GList *entries)
"entry-type", &source_entry_type,
NULL);
g_object_get (shell, "track-transfer-queue", &xferq, NULL);
- g_object_unref (shell);
target = gst_encoding_target_new ("rhythmbox-library", "device", "", NULL);
@@ -1740,13 +1739,21 @@ impl_paste (RBSource *asource, GList *entries)
g_object_unref (source_entry_type);
if (start_batch) {
+ RBTaskList *tasklist;
+
+ g_object_set (batch, "task-label", _("Copying tracks to the library"), NULL);
rb_track_transfer_queue_start_batch (xferq, batch);
+
+ g_object_get (shell, "task-list", &tasklist, NULL);
+ rb_task_list_add_task (tasklist, RB_TASK_PROGRESS (batch));
+ g_object_unref (tasklist);
} else {
g_object_unref (batch);
batch = NULL;
}
g_object_unref (xferq);
+ g_object_unref (shell);
return batch;
}
diff --git a/sources/rb-media-player-source.c b/sources/rb-media-player-source.c
index 2e0273b..58dba0d 100644
--- a/sources/rb-media-player-source.c
+++ b/sources/rb-media-player-source.c
@@ -607,6 +607,16 @@ sync_delete_done_cb (RBMediaPlayerSource *source, gpointer dontcare)
rb_debug ("transferring %d files to media player", priv->sync_state->sync_add_count);
batch = rb_source_paste (RB_SOURCE (source), priv->sync_state->sync_to_add);
if (batch != NULL) {
+ char *name;
+ char *label;
+
+ g_object_get (source, "name", &name, NULL);
+ label = g_strdup_printf (_("Syncing tracks to %s"), name);
+ g_free (name);
+
+ g_object_set (batch, "task-label", label, NULL);
+ g_free (label);
+
g_signal_connect_object (batch, "complete", G_CALLBACK (transfer_batch_complete_cb),
source, 0);
g_signal_connect_object (batch, "cancelled", G_CALLBACK
(transfer_batch_cancelled_cb), source, 0);
} else {
diff --git a/sources/rb-transfer-target.c b/sources/rb-transfer-target.c
index 698286d..4f184fa 100644
--- a/sources/rb-transfer-target.c
+++ b/sources/rb-transfer-target.c
@@ -41,6 +41,7 @@
#include <lib/rb-debug.h>
#include <lib/rb-file-helpers.h>
#include <widgets/rb-dialog.h>
+#include <shell/rb-task-list.h>
/* arbitrary length limit for file extensions */
#define EXTENSION_LENGTH_LIMIT 8
@@ -389,6 +390,7 @@ RBTrackTransferBatch *
rb_transfer_target_transfer (RBTransferTarget *target, GList *entries, gboolean defer)
{
RBTrackTransferQueue *xferq;
+ RBTaskList *tasklist;
RBShell *shell;
GList *l;
RhythmDBEntryType *our_entry_type;
@@ -399,7 +401,10 @@ rb_transfer_target_transfer (RBTransferTarget *target, GList *entries, gboolean
"shell", &shell,
"entry-type", &our_entry_type,
NULL);
- g_object_get (shell, "track-transfer-queue", &xferq, NULL);
+ g_object_get (shell,
+ "track-transfer-queue", &xferq,
+ "task-list", &tasklist,
+ NULL);
g_object_unref (shell);
batch = g_object_steal_data (G_OBJECT (target), "transfer-target-batch");
@@ -441,10 +446,21 @@ rb_transfer_target_transfer (RBTransferTarget *target, GList *entries, gboolean
g_object_set_data_full (G_OBJECT (target), "transfer-target-batch", g_object_ref
(batch), g_object_unref);
} else {
GstEncodingTarget *encoding_target;
+ char *name;
+ char *label;
+
g_object_get (target, "encoding-target", &encoding_target, NULL);
g_object_set (batch, "encoding-target", encoding_target, NULL);
gst_encoding_target_unref (encoding_target);
+ g_object_get (target, "name", &name, NULL);
+ label = g_strdup_printf (_("Transferring tracks to %s"), name);
+ g_object_set (batch, "task-label", label, NULL);
+ g_free (name);
+ g_free (label);
+
+ rb_task_list_add_task (tasklist, RB_TASK_PROGRESS (batch));
+
rb_track_transfer_queue_start_batch (xferq, batch);
}
} else {
@@ -452,6 +468,7 @@ rb_transfer_target_transfer (RBTransferTarget *target, GList *entries, gboolean
batch = NULL;
}
g_object_unref (xferq);
+ g_object_unref (tasklist);
return batch;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]