[rhythmbox] shell: switch to new track transfer queue
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] shell: switch to new track transfer queue
- Date: Sat, 22 May 2010 10:37:52 +0000 (UTC)
commit 2b442ff53aaf07615bd48bce48325fa27f3bdf69
Author: Jonathan Matthew <jonathan d14n org>
Date: Sat May 22 18:43:16 2010 +1000
shell: switch to new track transfer queue
The RBShell creates a single instance of the transfer queue and makes it
available through its 'track-transfer-queue' property.
The status bar reads the transfer status directly from the queue rather
than having the shell proxy it.
shell/rb-shell.c | 74 +++++++++++++------------------
shell/rb-statusbar.c | 119 +++++++++++++++++++++++++++++--------------------
shell/rb-statusbar.h | 8 +--
3 files changed, 105 insertions(+), 96 deletions(-)
---
diff --git a/shell/rb-shell.c b/shell/rb-shell.c
index 9469429..03c6eec 100644
--- a/shell/rb-shell.c
+++ b/shell/rb-shell.c
@@ -67,6 +67,7 @@
#include "rb-source.h"
#include "rb-playlist-manager.h"
#include "rb-removable-media-manager.h"
+#include "rb-track-transfer-queue.h"
#include "rb-preferences.h"
#include "rb-shell-clipboard.h"
#include "rb-shell-player.h"
@@ -148,11 +149,6 @@ static void rb_shell_db_entry_added_cb (RhythmDB *db,
static void rb_shell_playlist_added_cb (RBPlaylistManager *mgr, RBSource *source, RBShell *shell);
static void rb_shell_playlist_created_cb (RBPlaylistManager *mgr, RBSource *source, RBShell *shell);
static void rb_shell_medium_added_cb (RBRemovableMediaManager *mgr, RBSource *source, RBShell *shell);
-static void rb_shell_transfer_progress_cb (RBRemovableMediaManager *mgr,
- gint done,
- gint total,
- double fraction,
- RBShell *shell);
static void rb_shell_source_deleted_cb (RBSource *source, RBShell *shell);
static void rb_shell_set_window_title (RBShell *shell, const char *window_title);
static void rb_shell_player_window_title_changed_cb (RBShellPlayer *player,
@@ -263,6 +259,7 @@ enum
PROP_SOURCELIST,
PROP_SOURCE_HEADER,
PROP_VISIBILITY,
+ PROP_TRACK_TRANSFER_QUEUE,
};
/* prefs */
@@ -340,6 +337,7 @@ struct _RBShellPrivate
RBStatusbar *statusbar;
RBPlaylistManager *playlist_manager;
RBRemovableMediaManager *removable_media_manager;
+ RBTrackTransferQueue *track_transfer_queue;
RBLibrarySource *library_source;
RBPodcastSource *podcast_source;
@@ -711,6 +709,19 @@ rb_shell_class_init (RBShellClass *klass)
G_PARAM_READABLE));
/**
+ * RBShell:track-transfer-queue:
+ *
+ * The #RBTrackTransferQueue instance
+ */
+ g_object_class_install_property (object_class,
+ PROP_TRACK_TRANSFER_QUEUE,
+ g_param_spec_object ("track-transfer-queue",
+ "RBTrackTransferQueue",
+ "RBTrackTransferQueue object",
+ RB_TYPE_TRACK_TRANSFER_QUEUE,
+ G_PARAM_READABLE));
+
+ /**
* RBShell::visibility-changed:
* @shell: the #RBShell
* @visibile: new visibility
@@ -958,6 +969,9 @@ rb_shell_get_property (GObject *object,
case PROP_SOURCE_HEADER:
g_value_set_object (value, shell->priv->source_header);
break;
+ case PROP_TRACK_TRANSFER_QUEUE:
+ g_value_set_object (value, shell->priv->track_transfer_queue);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1057,13 +1071,14 @@ rb_shell_finalize (GObject *object)
rb_playlist_manager_shutdown (shell->priv->playlist_manager);
rb_debug ("unreffing playlist manager");
- g_object_unref (G_OBJECT (shell->priv->playlist_manager));
+ g_object_unref (shell->priv->playlist_manager);
rb_debug ("unreffing removable media manager");
- g_object_unref (G_OBJECT (shell->priv->removable_media_manager));
+ g_object_unref (shell->priv->removable_media_manager);
+ g_object_unref (shell->priv->track_transfer_queue);
rb_debug ("unreffing clipboard shell");
- g_object_unref (G_OBJECT (shell->priv->clipboard_shell));
+ g_object_unref (shell->priv->clipboard_shell);
rb_debug ("destroying prefs");
if (shell->priv->prefs != NULL)
@@ -1085,9 +1100,9 @@ rb_shell_finalize (GObject *object)
rhythmdb_shutdown (shell->priv->db);
rb_debug ("unreffing DB");
- g_object_unref (G_OBJECT (shell->priv->db));
+ g_object_unref (shell->priv->db);
- ((GObjectClass*)rb_shell_parent_class)->finalize (G_OBJECT (shell));
+ G_OBJECT_CLASS (rb_shell_parent_class)->finalize (object);
rb_debug ("shell shutdown complete");
}
@@ -1201,6 +1216,7 @@ construct_widgets (RBShell *shell)
rb_debug ("shell: initializing shell services");
+ shell->priv->track_transfer_queue = rb_track_transfer_queue_new (shell);
shell->priv->ui_manager = gtk_ui_manager_new ();
shell->priv->source_ui_merge_id = gtk_ui_manager_new_merge_id (shell->priv->ui_manager);
@@ -1236,7 +1252,8 @@ construct_widgets (RBShell *shell)
G_CALLBACK (rb_shell_show_popup_cb), shell, 0);
shell->priv->statusbar = rb_statusbar_new (shell->priv->db,
- shell->priv->ui_manager);
+ shell->priv->ui_manager,
+ shell->priv->track_transfer_queue);
g_object_set (shell->priv->player_shell, "statusbar", shell->priv->statusbar, NULL);
gtk_widget_show (GTK_WIDGET (shell->priv->statusbar));
@@ -1375,7 +1392,9 @@ construct_sources (RBShell *shell)
shell->priv->playlist_manager = rb_playlist_manager_new (shell,
RB_SOURCELIST (shell->priv->sourcelist), pathname);
- g_object_set (G_OBJECT(shell->priv->clipboard_shell), "playlist-manager", shell->priv->playlist_manager, NULL);
+ g_object_set (shell->priv->clipboard_shell,
+ "playlist-manager", shell->priv->playlist_manager,
+ NULL);
g_signal_connect_object (G_OBJECT (shell->priv->playlist_manager), "playlist_added",
G_CALLBACK (rb_shell_playlist_added_cb), shell, 0);
@@ -1388,8 +1407,7 @@ construct_sources (RBShell *shell)
g_signal_connect_object (G_OBJECT (shell->priv->removable_media_manager), "medium_added",
G_CALLBACK (rb_shell_medium_added_cb), shell, 0);
- g_signal_connect_object (G_OBJECT (shell->priv->removable_media_manager), "transfer-progress",
- G_CALLBACK (rb_shell_transfer_progress_cb), shell, 0);
+
g_free (pathname);
@@ -1979,34 +1997,6 @@ rb_shell_medium_added_cb (RBRemovableMediaManager *mgr,
}
static void
-rb_shell_transfer_progress_cb (RBRemovableMediaManager *mgr,
- gint done,
- gint total,
- double fraction,
- RBShell *shell)
-{
- rb_debug ("transferred %d tracks out of %d", done, total);
-
- if (total > 0) {
- char *s;
-
- if (fraction >= 0)
- s = g_strdup_printf (_("Transferring track %d out of %d (%.0f%%)"),
- done + 1, total, fraction * 100);
- else
- s = g_strdup_printf (_("Transferring track %d out of %d"),
- done + 1, total);
-
- rb_statusbar_set_progress (shell->priv->statusbar,
- (((double)(done) + fraction)/total),
- s);
- g_free (s);
- } else {
- rb_statusbar_set_progress (shell->priv->statusbar, -1, NULL);
- }
-}
-
-static void
rb_shell_source_deleted_cb (RBSource *source,
RBShell *shell)
{
diff --git a/shell/rb-statusbar.c b/shell/rb-statusbar.c
index b007c23..2792f2b 100644
--- a/shell/rb-statusbar.c
+++ b/shell/rb-statusbar.c
@@ -37,6 +37,7 @@
#include <gtk/gtk.h>
#include "rb-statusbar.h"
+#include "rb-track-transfer-queue.h"
#include "rb-debug.h"
/**
@@ -76,19 +77,23 @@ static gboolean poll_status (RBStatusbar *status);
static void rb_statusbar_sync_status (RBStatusbar *status);
static void rb_statusbar_source_status_changed_cb (RBSource *source,
RBStatusbar *statusbar);
+static void rb_statusbar_transfer_progress_cb (RBTrackTransferQueue *queue,
+ int done,
+ int total,
+ float fraction,
+ int time_left,
+ RBStatusbar *statusbar);
struct RBStatusbarPrivate
{
RBSource *selected_source;
+ RBTrackTransferQueue *transfer_queue;
RhythmDB *db;
GtkUIManager *ui_manager;
GtkWidget *progress;
- double progress_fraction;
- gboolean progress_changed;
- gchar *progress_text;
guint status_poll_id;
};
@@ -98,7 +103,8 @@ enum
PROP_0,
PROP_DB,
PROP_UI_MANAGER,
- PROP_SOURCE
+ PROP_SOURCE,
+ PROP_TRANSFER_QUEUE
};
G_DEFINE_TYPE (RBStatusbar, rb_statusbar, GTK_TYPE_STATUSBAR)
@@ -151,6 +157,19 @@ rb_statusbar_class_init (RBStatusbarClass *klass)
GTK_TYPE_UI_MANAGER,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ /**
+ * RBStatusbar::transfer-queue:
+ *
+ * The #RBTrackTransferQueue instance
+ */
+ g_object_class_install_property (object_class,
+ PROP_TRANSFER_QUEUE,
+ g_param_spec_object ("transfer-queue",
+ "RBTrackTransferQueue",
+ "RBTrackTransferQueue instance",
+ RB_TYPE_TRACK_TRANSFER_QUEUE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
g_type_class_add_private (klass, sizeof (RBStatusbarPrivate));
}
@@ -165,7 +184,6 @@ rb_statusbar_init (RBStatusbar *statusbar)
statusbar->priv->progress = gtk_progress_bar_new ();
gtk_widget_set_size_request (statusbar->priv->progress, -1, 10);
- statusbar->priv->progress_fraction = 1.0;
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (statusbar->priv->progress), 1.0);
gtk_widget_hide (statusbar->priv->progress);
@@ -206,6 +224,11 @@ rb_statusbar_dispose (GObject *object)
statusbar->priv->selected_source = NULL;
}
+ if (statusbar->priv->transfer_queue != NULL) {
+ g_object_unref (statusbar->priv->transfer_queue);
+ statusbar->priv->transfer_queue = NULL;
+ }
+
G_OBJECT_CLASS (rb_statusbar_parent_class)->dispose (object);
}
@@ -221,8 +244,6 @@ rb_statusbar_finalize (GObject *object)
g_return_if_fail (statusbar->priv != NULL);
- g_free (statusbar->priv->progress_text);
-
G_OBJECT_CLASS (rb_statusbar_parent_class)->finalize (object);
}
@@ -345,6 +366,14 @@ rb_statusbar_set_property (GObject *object,
statusbar,
G_CONNECT_SWAPPED);
break;
+ case PROP_TRANSFER_QUEUE:
+ statusbar->priv->transfer_queue = g_value_dup_object (value);
+ g_signal_connect_object (G_OBJECT (statusbar->priv->transfer_queue),
+ "transfer-progress",
+ G_CALLBACK (rb_statusbar_transfer_progress_cb),
+ statusbar,
+ 0);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -370,6 +399,9 @@ rb_statusbar_get_property (GObject *object,
case PROP_UI_MANAGER:
g_value_set_object (value, statusbar->priv->ui_manager);
break;
+ case PROP_TRANSFER_QUEUE:
+ g_value_set_object (value, statusbar->priv->transfer_queue);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -414,12 +446,13 @@ rb_statusbar_sync_status (RBStatusbar *status)
char *status_text = NULL;
char *progress_text = NULL;
float progress = 999;
+ int time_left = 0;
/*
* Behaviour of status bar:
* - use source's status text
- * - use source's progress value and text, unless internal progress value is set,
- * - if no source progress value or internal progress value and library is busy,
+ * - use source's progress value and text, unless transfer queue provides something
+ * - if no source progress value or transfer progress value and library is busy,
* pulse the progress bar
*/
@@ -439,15 +472,12 @@ rb_statusbar_sync_status (RBStatusbar *status)
status_text ? status_text : "", progress_text ? progress_text : "", progress);
}
- /* internal progress bar moving? */
- if (status->priv->progress_fraction < (1.0 - EPSILON) || status->priv->progress_changed) {
- g_free (progress_text);
- progress_text = g_strdup (status->priv->progress_text);
- progress = status->priv->progress_fraction;
-
- status->priv->progress_changed = FALSE;
- changed = TRUE;
- }
+ /* get transfer details */
+ rb_track_transfer_queue_get_status (status->priv->transfer_queue,
+ &status_text,
+ &progress_text,
+ &progress,
+ &time_left);
/* set up the status text */
if (status_text) {
@@ -483,6 +513,7 @@ rb_statusbar_sync_status (RBStatusbar *status)
* rb_statusbar_new:
* @db: the #RhythmDB instance
* @ui_manager: the #GtkUIManager
+ * @transfer_queue: the #RBTrackTransferQueue
*
* Creates the status bar widget.
*
@@ -490,11 +521,13 @@ rb_statusbar_sync_status (RBStatusbar *status)
*/
RBStatusbar *
rb_statusbar_new (RhythmDB *db,
- GtkUIManager *ui_manager)
+ GtkUIManager *ui_manager,
+ RBTrackTransferQueue *queue)
{
RBStatusbar *statusbar = g_object_new (RB_TYPE_STATUSBAR,
"db", db,
"ui-manager", ui_manager,
+ "transfer-queue", queue,
NULL);
g_return_val_if_fail (statusbar->priv != NULL, NULL);
@@ -502,41 +535,29 @@ rb_statusbar_new (RhythmDB *db,
return statusbar;
}
-/**
- * rb_statusbar_set_progress:
- * @statusbar: the #RBStatusbar
- * @progress: progress fraction
- * @text: text to display on the progress bar
- *
- * Updates the progress bar widget. If the progress fraction is less than zero,
- * the progress bar is hidden.
- */
-void
-rb_statusbar_set_progress (RBStatusbar *statusbar, double progress, const char *text)
+static void
+add_status_poll (RBStatusbar *statusbar)
{
- if (statusbar->priv->progress_text) {
- g_free (statusbar->priv->progress_text);
- statusbar->priv->progress_text = NULL;
- }
-
- if (progress > (0.0 - EPSILON)) {
- statusbar->priv->progress_fraction = progress;
- statusbar->priv->progress_changed = TRUE;
- if (text)
- statusbar->priv->progress_text = g_strdup (text);
- } else {
- /* trick sync_status into hiding it */
- statusbar->priv->progress_fraction = 1.0;
- statusbar->priv->progress_changed = FALSE;
- }
- rb_statusbar_sync_status (statusbar);
+ if (statusbar->priv->status_poll_id == 0)
+ statusbar->priv->status_poll_id =
+ g_idle_add ((GSourceFunc) poll_status, statusbar);
}
static void
rb_statusbar_source_status_changed_cb (RBSource *source, RBStatusbar *statusbar)
{
rb_debug ("source status changed");
- if (statusbar->priv->status_poll_id == 0)
- statusbar->priv->status_poll_id =
- g_idle_add ((GSourceFunc) poll_status, statusbar);
+ add_status_poll (statusbar);
+}
+
+static void
+rb_statusbar_transfer_progress_cb (RBTrackTransferQueue *queue,
+ int done,
+ int total,
+ float progress,
+ int time_left,
+ RBStatusbar *statusbar)
+{
+ rb_debug ("transfer progress changed");
+ add_status_poll (statusbar);
}
diff --git a/shell/rb-statusbar.h b/shell/rb-statusbar.h
index 33a20f1..ffda4a7 100644
--- a/shell/rb-statusbar.h
+++ b/shell/rb-statusbar.h
@@ -29,6 +29,7 @@
#include <sources/rb-source.h>
#include <rhythmdb/rhythmdb.h>
+#include <shell/rb-track-transfer-queue.h>
#ifndef __RB_STATUSBAR_H
#define __RB_STATUSBAR_H
@@ -62,15 +63,12 @@ struct _RBStatusbarClass
GType rb_statusbar_get_type (void);
RBStatusbar * rb_statusbar_new (RhythmDB *db,
- GtkUIManager *ui_manager);
+ GtkUIManager *ui_manager,
+ RBTrackTransferQueue *transfer_queue);
void rb_statusbar_set_source (RBStatusbar *statusbar,
RBSource *source);
-void rb_statusbar_set_progress(RBStatusbar *statusbar,
- double progress,
- const char *text);
-
G_END_DECLS
#endif /* __RB_STATUSBAR_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]