[rhythmbox] rhythmdb: add RBTaskProgress interface to RhythmDBImportJob



commit 207264fd7324e5a54b9879caa08fd74bdb172b78
Author: Jonathan Matthew <jonathan d14n org>
Date:   Tue May 14 22:25:00 2013 +1000

    rhythmdb: add RBTaskProgress interface to RhythmDBImportJob
    
    and convert things that used it to reporting progress through
    the task list.

 plugins/generic-player/rb-generic-player-source.c |   40 +++-----
 po/POTFILES.in                                    |    1 +
 rhythmdb/rhythmdb-import-job.c                    |  109 ++++++++++++++++++++-
 sources/rb-library-source.c                       |   32 +++----
 sources/rb-source.c                               |   24 -----
 sources/rb-source.h                               |    5 -
 widgets/rb-import-dialog.c                        |  112 ++++----------------
 7 files changed, 161 insertions(+), 162 deletions(-)
---
diff --git a/plugins/generic-player/rb-generic-player-source.c 
b/plugins/generic-player/rb-generic-player-source.c
index f3f5326..7b77ff9 100644
--- a/plugins/generic-player/rb-generic-player-source.c
+++ b/plugins/generic-player/rb-generic-player-source.c
@@ -57,6 +57,7 @@
 #include "rb-missing-plugins.h"
 #include "rb-application.h"
 #include "rb-display-page-menu.h"
+#include "rb-task-list.h"
 
 static void rb_generic_player_device_source_init (RBDeviceSourceInterface *interface);
 static void rb_generic_player_source_transfer_target_init (RBTransferTargetInterface *interface);
@@ -75,7 +76,6 @@ static void impl_get_property (GObject *object,
 static void load_songs (RBGenericPlayerSource *source);
 
 static void impl_delete_thyself (RBDisplayPage *page);
-static void impl_get_status (RBDisplayPage *page, char **text, char **progress_text, float *progress);
 static void impl_selected (RBDisplayPage *page);
 
 static gboolean impl_can_paste (RBSource *source);
@@ -169,7 +169,6 @@ rb_generic_player_source_class_init (RBGenericPlayerSourceClass *klass)
        object_class->dispose = impl_dispose;
 
        page_class->delete_thyself = impl_delete_thyself;
-       page_class->get_status = impl_get_status;
        page_class->selected = impl_selected;
 
        source_class->impl_can_delete = impl_can_delete;
@@ -607,7 +606,6 @@ import_complete_cb (RhythmDBImportJob *job, int total, RBGenericPlayerSource *so
        g_object_unref (priv->import_job);
        priv->import_job = NULL;
 
-       rb_display_page_notify_status_changed (RB_DISPLAY_PAGE (source));
        g_object_set (source, "load-status", RB_SOURCE_LOAD_STATUS_LOADED, NULL);
 
        rb_transfer_target_transfer (RB_TRANSFER_TARGET (source), NULL, FALSE);
@@ -616,18 +614,16 @@ import_complete_cb (RhythmDBImportJob *job, int total, RBGenericPlayerSource *so
 }
 
 static void
-import_status_changed_cb (RhythmDBImportJob *job, int total, int imported, RBGenericPlayerSource *source)
-{
-       rb_display_page_notify_status_changed (RB_DISPLAY_PAGE (source));
-}
-
-static void
 load_songs (RBGenericPlayerSource *source)
 {
        RBGenericPlayerSourcePrivate *priv = GET_PRIVATE (source);
        RhythmDBEntryType *entry_type;
        char **audio_folders;
        char *mount_path;
+       RBShell *shell;
+       RBTaskList *tasklist;
+       char *name;
+       char *label;
 
        mount_path = rb_generic_player_source_get_mount_path (source);
        g_object_get (source, "entry-type", &entry_type, NULL);
@@ -636,9 +632,13 @@ load_songs (RBGenericPlayerSource *source)
         * load only those folders, otherwise add the whole volume.
         */
        priv->import_job = rhythmdb_import_job_new (priv->db, entry_type, priv->ignore_type, 
priv->error_type);
+       g_object_get (source, "name", &name, NULL);
+       label = g_strdup_printf (_("Scanning %s"), name);
+       g_object_set (priv->import_job, "task-label", label, NULL);
+       g_free (label);
+       g_free (name);
 
        g_signal_connect_object (priv->import_job, "complete", G_CALLBACK (import_complete_cb), source, 0);
-       g_signal_connect_object (priv->import_job, "status-changed", G_CALLBACK (import_status_changed_cb), 
source, 0);
 
        g_object_get (priv->device_info, "audio-folders", &audio_folders, NULL);
        if (audio_folders != NULL && g_strv_length (audio_folders) > 0) {
@@ -658,6 +658,12 @@ load_songs (RBGenericPlayerSource *source)
 
        rhythmdb_import_job_start (priv->import_job);
 
+       g_object_get (source, "shell", &shell, NULL);
+       g_object_get (shell, "task-list", &tasklist, NULL);
+       rb_task_list_add_task (tasklist, RB_TASK_PROGRESS (priv->import_job));
+       g_object_unref (tasklist);
+       g_object_unref (shell);
+
        g_object_unref (entry_type);
        g_free (mount_path);
 }
@@ -710,20 +716,6 @@ rb_generic_player_is_mount_player (GMount *mount, MPIDDevice *device_info)
        return result;
 }
 
-static void
-impl_get_status (RBDisplayPage *page, char **text, char **progress_text, float *progress)
-{
-       RBGenericPlayerSourcePrivate *priv = GET_PRIVATE (page);
-
-       /* get default status text first */
-       RB_DISPLAY_PAGE_CLASS (rb_generic_player_source_parent_class)->get_status (page, text, progress_text, 
progress);
-
-       /* override with bits of import status */
-       if (priv->import_job != NULL) {
-               _rb_source_set_import_status (RB_SOURCE (page), priv->import_job, progress_text, progress);
-       }
-}
-
 /* code for playlist loading */
 
 static void
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 66b410d..a648edd 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -164,6 +164,7 @@ podcast/rb-podcast-properties-dialog.c
 podcast/rb-podcast-source.c
 remote/dbus/rb-client.c
 rhythmdb/rhythmdb.c
+rhythmdb/rhythmdb-import-job.c
 rhythmdb/rhythmdb-monitor.c
 rhythmdb/rhythmdb-property-model.c
 rhythmdb/rhythmdb-tree.c
diff --git a/rhythmdb/rhythmdb-import-job.c b/rhythmdb/rhythmdb-import-job.c
index 6b7dbcc..146a46b 100644
--- a/rhythmdb/rhythmdb-import-job.c
+++ b/rhythmdb/rhythmdb-import-job.c
@@ -28,6 +28,8 @@
 
 #include "config.h"
 
+#include <glib/gi18n.h>
+
 #include "rhythmdb-import-job.h"
 #include "rhythmdb-entry-type.h"
 #include "rb-util.h"
@@ -35,6 +37,7 @@
 #include "rb-marshal.h"
 #include "rb-debug.h"
 #include "rb-missing-plugins.h"
+#include "rb-task-progress.h"
 
 /* maximum number of new URIs in the rhythmdb action queue.
  * entries bounce around between different threads and processes a bit,
@@ -50,7 +53,13 @@ enum
        PROP_DB,
        PROP_ENTRY_TYPE,
        PROP_IGNORE_TYPE,
-       PROP_ERROR_TYPE
+       PROP_ERROR_TYPE,
+       PROP_TASK_LABEL,
+       PROP_TASK_DETAIL,
+       PROP_TASK_PROGRESS,
+       PROP_TASK_OUTCOME,
+       PROP_TASK_NOTIFY,
+       PROP_TASK_CANCELLABLE
 };
 
 enum
@@ -64,6 +73,7 @@ enum
 
 static void    rhythmdb_import_job_class_init (RhythmDBImportJobClass *klass);
 static void    rhythmdb_import_job_init (RhythmDBImportJob *job);
+static void    rhythmdb_import_job_task_progress_init (RBTaskProgressInterface *iface);
 
 static guint   signals[LAST_SIGNAL] = { 0 };
 
@@ -89,9 +99,16 @@ struct _RhythmDBImportJobPrivate
        int             status_changed_id;
        gboolean        scan_complete;
        gboolean        complete;
+
+       char            *task_label;
+       gboolean        task_notify;
 };
 
-G_DEFINE_TYPE (RhythmDBImportJob, rhythmdb_import_job, G_TYPE_OBJECT)
+G_DEFINE_TYPE_EXTENDED (RhythmDBImportJob,
+                       rhythmdb_import_job,
+                       G_TYPE_OBJECT,
+                       0,
+                       G_IMPLEMENT_INTERFACE (RB_TYPE_TASK_PROGRESS, 
rhythmdb_import_job_task_progress_init));
 
 /**
  * SECTION:rhythmdb-import-job
@@ -189,7 +206,9 @@ missing_plugins_retry_cb (gpointer instance, gboolean installed, RhythmDBImportJ
        g_assert (job->priv->retried == FALSE);
        if (installed == FALSE) {
                rb_debug ("plugin installation was not successful; job complete");
+               job->priv->complete = TRUE;
                g_signal_emit (job, signals[COMPLETE], 0, job->priv->total);
+               g_object_notify (G_OBJECT (job), "task-outcome");
        } else {
                job->priv->retried = TRUE;
 
@@ -224,6 +243,8 @@ emit_status_changed (RhythmDBImportJob *job)
 
        rb_debug ("emitting status changed: %d/%d", job->priv->processed, job->priv->total);
        g_signal_emit (job, signals[STATUS_CHANGED], 0, job->priv->total, job->priv->processed);
+       g_object_notify (G_OBJECT (job), "task-progress");
+       g_object_notify (G_OBJECT (job), "task-detail");
 
        /* temporary ref while emitting this signal as we're expecting the caller
         * to release the final reference there.
@@ -268,17 +289,23 @@ emit_status_changed (RhythmDBImportJob *job)
                                rb_debug ("plugin installation is in progress");
                        } else {
                                rb_debug ("no plugin installation attempted; job complete");
+                               job->priv->complete = TRUE;
                                g_signal_emit (job, signals[COMPLETE], 0, job->priv->total);
+                               g_object_notify (G_OBJECT (job), "task-outcome");
                        }
                        g_closure_sink (retry);
                } else {
                        rb_debug ("emitting job complete");
+                       job->priv->complete = TRUE;
                        g_signal_emit (job, signals[COMPLETE], 0, job->priv->total);
+                       g_object_notify (G_OBJECT (job), "task-outcome");
                }
        } else if (g_cancellable_is_cancelled (job->priv->cancel) &&
                   g_queue_is_empty (job->priv->processing)) {
                rb_debug ("cancelled job has no processing entries, emitting complete");
+               job->priv->complete = TRUE;
                g_signal_emit (job, signals[COMPLETE], 0, job->priv->total);
+               g_object_notify (G_OBJECT (job), "task-outcome");
        }
        g_mutex_unlock (&job->priv->lock);
        g_object_unref (job);
@@ -479,6 +506,14 @@ rhythmdb_import_job_cancel (RhythmDBImportJob *job)
        g_mutex_lock (&job->priv->lock);
        g_cancellable_cancel (job->priv->cancel);
        g_mutex_unlock (&job->priv->lock);
+
+       g_object_notify (G_OBJECT (job), "task-outcome");
+}
+
+static void
+task_progress_cancel (RBTaskProgress *progress)
+{
+       rhythmdb_import_job_cancel (RHYTHMDB_IMPORT_JOB (progress));
 }
 
 static void
@@ -565,6 +600,24 @@ impl_set_property (GObject *object,
        case PROP_ERROR_TYPE:
                job->priv->error_type = g_value_get_object (value);
                break;
+       case PROP_TASK_LABEL:
+               job->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:
+               job->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;
@@ -592,6 +645,43 @@ impl_get_property (GObject *object,
        case PROP_ERROR_TYPE:
                g_value_set_object (value, job->priv->error_type);
                break;
+       case PROP_TASK_LABEL:
+               g_value_set_string (value, job->priv->task_label);
+               break;
+       case PROP_TASK_DETAIL:
+               if (job->priv->scan_complete == FALSE) {
+                       g_value_set_string (value, _("Scanning"));
+               } else {
+                       g_value_take_string (value,
+                                            g_strdup_printf (_("%d of %d"),
+                                                             job->priv->processed,
+                                                             job->priv->total));
+               }
+               break;
+       case PROP_TASK_PROGRESS:
+               if (job->priv->scan_complete == FALSE) {
+                       g_value_set_double (value, -1.0);
+               } else if (job->priv->total == 0) {
+                       g_value_set_double (value, 0.0);
+               } else {
+                       g_value_set_double (value, ((float)job->priv->processed / (float)job->priv->total));
+               }
+               break;
+       case PROP_TASK_OUTCOME:
+               if (job->priv->complete) {
+                       g_value_set_enum (value, RB_TASK_OUTCOME_COMPLETE);
+               } else if (g_cancellable_is_cancelled (job->priv->cancel)) {
+                       g_value_set_enum (value, RB_TASK_OUTCOME_CANCELLED);
+               } else {
+                       g_value_set_enum (value, RB_TASK_OUTCOME_NONE);
+               }
+               break;
+       case PROP_TASK_NOTIFY:
+               g_value_set_boolean (value, job->priv->task_notify);
+               break;
+       case PROP_TASK_CANCELLABLE:
+               g_value_set_boolean (value, TRUE);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -625,10 +715,18 @@ impl_finalize (GObject *object)
 
        rb_slist_deep_free (job->priv->uri_list);
 
+       g_free (job->priv->task_label);
+
        G_OBJECT_CLASS (rhythmdb_import_job_parent_class)->finalize (object);
 }
 
 static void
+rhythmdb_import_job_task_progress_init (RBTaskProgressInterface *interface)
+{
+       interface->cancel = task_progress_cancel;
+}
+
+static void
 rhythmdb_import_job_class_init (RhythmDBImportJobClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -668,6 +766,13 @@ rhythmdb_import_job_class_init (RhythmDBImportJobClass *klass)
                                                              RHYTHMDB_TYPE_ENTRY_TYPE,
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
+       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");
+
        /**
         * RhythmDBImportJob::entry-added:
         * @job: the #RhythmDBImportJob
diff --git a/sources/rb-library-source.c b/sources/rb-library-source.c
index 33f3905..a4d5e79 100644
--- a/sources/rb-library-source.c
+++ b/sources/rb-library-source.c
@@ -73,6 +73,7 @@
 #include "rb-display-page-menu.h"
 #include "rb-display-page-group.h"
 #include "rb-static-playlist-source.h"
+#include "rb-task-list.h"
 
 #define SOURCE_PAGE            0
 #define IMPORT_DIALOG_PAGE     1
@@ -1763,15 +1764,6 @@ impl_want_uri (RBSource *source, const char *uri)
 }
 
 static void
-import_job_status_changed_cb (RhythmDBImportJob *job, int total, int imported, RBLibrarySource *source)
-{
-       RhythmDBImportJob *head = RHYTHMDB_IMPORT_JOB (source->priv->import_jobs->data);
-       if (job == head) {              /* it was inevitable */
-               rb_display_page_notify_status_changed (RB_DISPLAY_PAGE (source));
-       }
-}
-
-static void
 import_job_complete_cb (RhythmDBImportJob *job, int total, RBLibrarySource *source)
 {
        rb_debug ("import job complete");
@@ -1786,6 +1778,9 @@ static gboolean
 start_import_job (RBLibrarySource *source)
 {
        RhythmDBImportJob *job;
+       RBTaskList *tasklist;
+       RBShell *shell;
+
        source->priv->start_import_job_id = 0;
 
        rb_debug ("starting import job");
@@ -1793,6 +1788,12 @@ start_import_job (RBLibrarySource *source)
 
        rhythmdb_import_job_start (job);
 
+       g_object_get (source, "shell", &shell, NULL);
+       g_object_get (shell, "task-list", &tasklist, NULL);
+       rb_task_list_add_task (tasklist, RB_TASK_PROGRESS (job));
+       g_object_unref (tasklist);
+       g_object_unref (shell);
+
        return FALSE;
 }
 
@@ -1807,12 +1808,9 @@ maybe_create_import_job (RBLibrarySource *source)
                                               RHYTHMDB_ENTRY_TYPE_SONG,
                                               RHYTHMDB_ENTRY_TYPE_IGNORE,
                                               RHYTHMDB_ENTRY_TYPE_IMPORT_ERROR);
+               g_object_set (job, "task-label", _("Adding tracks to the library"), NULL);
 
                g_signal_connect_object (job,
-                                        "status-changed",
-                                        G_CALLBACK (import_job_status_changed_cb),
-                                        source, 0);
-               g_signal_connect_object (job,
                                         "complete",
                                         G_CALLBACK (import_job_complete_cb),
                                         source, 0);
@@ -1966,13 +1964,11 @@ rb_library_source_sync_child_sources (RBLibrarySource *source)
 static void
 impl_get_status (RBDisplayPage *source, char **text, char **progress_text, float *progress)
 {
-       RB_DISPLAY_PAGE_CLASS (rb_library_source_parent_class)->get_status (source, text, progress_text, 
progress);
        RBLibrarySource *lsource = RB_LIBRARY_SOURCE (source);
 
-       if (lsource->priv->import_jobs != NULL) {
-               RhythmDBImportJob *job = RHYTHMDB_IMPORT_JOB (lsource->priv->import_jobs->data);
-               _rb_source_set_import_status (RB_SOURCE (source), job, progress_text, progress);
-       } else if (gtk_notebook_get_current_page (GTK_NOTEBOOK (lsource->priv->notebook)) == 
IMPORT_DIALOG_PAGE) {
+       RB_DISPLAY_PAGE_CLASS (rb_library_source_parent_class)->get_status (source, text, progress_text, 
progress);
+
+       if (gtk_notebook_get_current_page (GTK_NOTEBOOK (lsource->priv->notebook)) == IMPORT_DIALOG_PAGE) {
                g_free (*text);
                g_object_get (lsource->priv->import_dialog, "status", text, NULL);
        }
diff --git a/sources/rb-source.c b/sources/rb-source.c
index f8f169a..a9500bb 100644
--- a/sources/rb-source.c
+++ b/sources/rb-source.c
@@ -1343,30 +1343,6 @@ _rb_source_check_entry_type (RBSource *source, RhythmDBEntry *entry)
        return ret;
 }
 
-/**
- * _rb_source_set_import_status:
- * @source: an #RBSource
- * @job: a #RhythmDBImportJob
- * @progress_text: used to return progress text
- * @progress: used to return progress fraction
- *
- * Used in implementations of the get_status method to provide source
- * status information based on a #RhythmDBImportJob.
- */
-void
-_rb_source_set_import_status (RBSource *source, RhythmDBImportJob *job, char **progress_text, float 
*progress)
-{
-       int total;
-       int imported;
-
-       total = rhythmdb_import_job_get_total (job);
-       imported = rhythmdb_import_job_get_imported (job);
-
-       g_free (*progress_text);
-       *progress_text = g_strdup_printf (_("Importing (%d/%d)"), imported, total);
-       *progress = ((float)imported / (float)total);
-}
-
 static gboolean
 sort_order_get_mapping (GValue *value, GVariant *variant, gpointer data)
 {
diff --git a/sources/rb-source.h b/sources/rb-source.h
index 81ac149..6e52587 100644
--- a/sources/rb-source.h
+++ b/sources/rb-source.h
@@ -37,7 +37,6 @@
 #include <widgets/rb-search-entry.h>
 #include <shell/rb-shell-preferences.h>
 #include <shell/rb-track-transfer-batch.h>
-#include <rhythmdb/rhythmdb-import-job.h>
 
 G_BEGIN_DECLS
 
@@ -201,10 +200,6 @@ void               rb_source_get_playback_status   (RBSource *source,
 gboolean       _rb_source_check_entry_type     (RBSource *source,
                                                 RhythmDBEntry *entry);
 
-void           _rb_source_set_import_status    (RBSource *source,
-                                                RhythmDBImportJob *job,
-                                                char **progress_text,
-                                                float *progress);
 void           rb_source_bind_settings         (RBSource *source,
                                                 GtkWidget *entry_view,
                                                 GtkWidget *paned,
diff --git a/widgets/rb-import-dialog.c b/widgets/rb-import-dialog.c
index 78dc603..fe8eeac 100644
--- a/widgets/rb-import-dialog.c
+++ b/widgets/rb-import-dialog.c
@@ -41,6 +41,7 @@
 #include "rhythmdb-entry-type.h"
 #include "rb-device-source.h"
 #include "rb-file-helpers.h"
+#include "rb-task-list.h"
 
 /* normal entries */
 typedef struct _RhythmDBEntryType RBImportDialogEntryType;
@@ -89,7 +90,6 @@ struct RBImportDialogPrivate
 
        GtkWidget *info_bar;
        GtkWidget *info_bar_container;
-       GtkWidget *import_progress;
        GtkWidget *file_chooser;
        GtkWidget *add_button;
        GtkWidget *copy_button;
@@ -107,7 +107,6 @@ struct RBImportDialogPrivate
        guint added_entries_id;
 
        char *current_uri;
-       guint pulse_id;
 };
 
 static guint signals[LAST_SIGNAL] = {0,};
@@ -142,8 +141,20 @@ sort_changed_cb (GObject *object, GParamSpec *pspec, RBImportDialog *dialog)
 }
 
 static void
+hide_import_job (RBImportDialog *dialog)
+{
+       if (dialog->priv->import_job) {
+               RBTaskList *tasklist;
+               g_object_get (dialog->priv->shell, "task-list", &tasklist, NULL);
+               rb_task_list_remove_task (tasklist, RB_TASK_PROGRESS (dialog->priv->import_job));
+               g_object_unref (tasklist);
+       }
+}
+
+static void
 impl_close (RBImportDialog *dialog)
 {
+       hide_import_job (dialog);
        g_signal_emit (dialog, signals[CLOSED], 0);
 }
 
@@ -197,6 +208,7 @@ add_entries_done (RBImportDialog *dialog)
 {
        /* if we added all the tracks, close the dialog */
        if (dialog->priv->entry_count == 0) {
+               hide_import_job (dialog);
                g_signal_emit (dialog, signals[CLOSED], 0);
        }
 
@@ -261,13 +273,6 @@ copy_track_done_cb (RBTrackTransferBatch *batch,
                    GError *error,
                    RBImportDialog *dialog)
 {
-       int total;
-       int done;
-
-       g_object_get (batch, "total-entries", &total, "done-entries", &done, NULL);
-       gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (dialog->priv->import_progress),
-                                      (float)done / total);
-
        rhythmdb_entry_delete (dialog->priv->db, entry);
        rhythmdb_commit (dialog->priv->db);
 }
@@ -275,10 +280,9 @@ copy_track_done_cb (RBTrackTransferBatch *batch,
 static void
 copy_complete_cb (RBTrackTransferBatch *batch, RBImportDialog *dialog)
 {
-       clear_info_bar (dialog);
-
        /* if we copied everything, close the dialog */
        if (dialog->priv->entry_count == 0) {
+               hide_import_job (dialog);
                g_signal_emit (dialog, signals[CLOSED], 0);
        }
 }
@@ -289,8 +293,6 @@ copy_clicked_cb (GtkButton *button, RBImportDialog *dialog)
        RBSource *library_source;
        RBTrackTransferBatch *batch;
        GList *entries;
-       GtkWidget *content;
-       GtkWidget *label;
        
        g_object_get (dialog->priv->shell, "library-source", &library_source, NULL);
 
@@ -302,24 +304,6 @@ copy_clicked_cb (GtkButton *button, RBImportDialog *dialog)
        /* delete source entries as they finish being copied */
        g_signal_connect (batch, "track-done", G_CALLBACK (copy_track_done_cb), dialog);
        g_signal_connect (batch, "complete", G_CALLBACK (copy_complete_cb), dialog);
-
-       /* set up info bar for copy progress */
-       clear_info_bar (dialog);
-
-       dialog->priv->info_bar = gtk_info_bar_new ();
-       g_object_set (dialog->priv->info_bar, "hexpand", TRUE, NULL);
-       gtk_info_bar_set_message_type (GTK_INFO_BAR (dialog->priv->info_bar), GTK_MESSAGE_INFO);
-       content = gtk_info_bar_get_content_area (GTK_INFO_BAR (dialog->priv->info_bar));
-
-       label = gtk_label_new (_("Copying..."));
-       gtk_container_add (GTK_CONTAINER (content), label);
-
-       dialog->priv->import_progress = gtk_progress_bar_new ();
-       content = gtk_info_bar_get_action_area (GTK_INFO_BAR (dialog->priv->info_bar));
-       gtk_container_add (GTK_CONTAINER (content), dialog->priv->import_progress);
-
-       gtk_container_add (GTK_CONTAINER (dialog->priv->info_bar_container), dialog->priv->info_bar);
-       gtk_widget_show_all (dialog->priv->info_bar);
 }
 
 static void
@@ -339,60 +323,35 @@ remove_clicked_cb (GtkButton *button, RBImportDialog *dialog)
 static void
 close_clicked_cb (GtkButton *button, RBImportDialog *dialog)
 {
+       hide_import_job (dialog);
        g_signal_emit (dialog, signals[CLOSED], 0);
 }
 
 static void
-import_status_changed_cb (RhythmDBImportJob *job, int total, int imported, RBImportDialog *dialog)
-{
-       if (dialog->priv->pulse_id == 0) {
-               gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (dialog->priv->import_progress),
-                                              (float)imported / total);
-       }
-}
-
-static void
-import_scan_complete_cb (RhythmDBImportJob *job, int total, RBImportDialog *dialog)
-{
-       if (dialog->priv->pulse_id != 0) {
-               g_source_remove (dialog->priv->pulse_id);
-               dialog->priv->pulse_id = 0;
-       }
-
-       gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (dialog->priv->import_progress), 0.0);
-}
-
-static void
 import_complete_cb (RhythmDBImportJob *job, int total, RBImportDialog *dialog)
 {
        g_object_unref (job);
        dialog->priv->import_job = NULL;
-
-       clear_info_bar (dialog);
-}
-
-static gboolean
-pulse_cb (RBImportDialog *dialog)
-{
-       gtk_progress_bar_pulse (GTK_PROGRESS_BAR (dialog->priv->import_progress));
-       return TRUE;
 }
 
 static void
 start_scanning (RBImportDialog *dialog)
 {
+       RBTaskList *tasklist;
+
        rb_debug ("starting %s", dialog->priv->current_uri);
        dialog->priv->import_job = rhythmdb_import_job_new (dialog->priv->db,
                                                            dialog->priv->entry_type,
                                                            dialog->priv->ignore_type,
                                                            dialog->priv->ignore_type);
-       g_signal_connect (dialog->priv->import_job, "status-changed", G_CALLBACK (import_status_changed_cb), 
dialog);
-       g_signal_connect (dialog->priv->import_job, "scan-complete", G_CALLBACK (import_scan_complete_cb), 
dialog);
+       g_object_set (dialog->priv->import_job, "task-label", _("Importing tracks"), NULL);
        g_signal_connect (dialog->priv->import_job, "complete", G_CALLBACK (import_complete_cb), dialog);
        rhythmdb_import_job_add_uri (dialog->priv->import_job, dialog->priv->current_uri);
        rhythmdb_import_job_start (dialog->priv->import_job);
 
-       dialog->priv->pulse_id = g_timeout_add (100, (GSourceFunc) pulse_cb, dialog);
+       g_object_get (dialog->priv->shell, "task-list", &tasklist, NULL);
+       rb_task_list_add_task (tasklist, RB_TASK_PROGRESS (dialog->priv->import_job));
+       g_object_unref (tasklist);
 }
 
 static void
@@ -408,6 +367,7 @@ info_bar_response_cb (GtkInfoBar *bar, gint response, RBImportDialog *dialog)
        RBSource *source;
        const char *uri;
 
+       hide_import_job (dialog);
        g_signal_emit (dialog, signals[CLOSED], 0);
        uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog->priv->file_chooser));
        source = rb_shell_guess_source_for_uri (dialog->priv->shell, uri);
@@ -433,15 +393,8 @@ current_folder_changed_cb (GtkFileChooser *chooser, RBImportDialog *dialog)
        dialog->priv->current_uri = g_strdup (uri);
 
        if (dialog->priv->import_job != NULL) {
-               g_signal_handlers_disconnect_by_func (dialog->priv->import_job, G_CALLBACK 
(import_status_changed_cb), dialog);
-               g_signal_handlers_disconnect_by_func (dialog->priv->import_job, G_CALLBACK 
(import_scan_complete_cb), dialog);
-               g_signal_handlers_disconnect_by_func (dialog->priv->import_job, G_CALLBACK 
(import_complete_cb), dialog);
                rhythmdb_import_job_cancel (dialog->priv->import_job);
        }
-       if (dialog->priv->pulse_id != 0) {
-               g_source_remove (dialog->priv->pulse_id);
-               dialog->priv->pulse_id = 0;
-       }
 
        rhythmdb_entry_delete_by_type (dialog->priv->db, dialog->priv->entry_type);
        rhythmdb_entry_delete_by_type (dialog->priv->db, dialog->priv->ignore_type);
@@ -494,21 +447,6 @@ current_folder_changed_cb (GtkFileChooser *chooser, RBImportDialog *dialog)
                }
        }
 
-       dialog->priv->info_bar = gtk_info_bar_new ();
-       g_object_set (dialog->priv->info_bar, "hexpand", TRUE, NULL);
-       gtk_info_bar_set_message_type (GTK_INFO_BAR (dialog->priv->info_bar), GTK_MESSAGE_INFO);
-       content = gtk_info_bar_get_content_area (GTK_INFO_BAR (dialog->priv->info_bar));
-
-       label = gtk_label_new (_("Scanning..."));
-       gtk_container_add (GTK_CONTAINER (content), label);
-
-       dialog->priv->import_progress = gtk_progress_bar_new ();
-       content = gtk_info_bar_get_action_area (GTK_INFO_BAR (dialog->priv->info_bar));
-       gtk_container_add (GTK_CONTAINER (content), dialog->priv->import_progress);
-
-       gtk_container_add (GTK_CONTAINER (dialog->priv->info_bar_container), dialog->priv->info_bar);
-       gtk_widget_show_all (dialog->priv->info_bar);
-
        if (dialog->priv->import_job != NULL) {
                /* wait for the previous job to finish up */
                rb_debug ("need to wait for previous import job to finish");
@@ -674,10 +612,6 @@ impl_dispose (GObject *object)
 {
        RBImportDialog *dialog = RB_IMPORT_DIALOG (object);
 
-       if (dialog->priv->pulse_id) {
-               g_source_remove (dialog->priv->pulse_id);
-               dialog->priv->pulse_id = 0;
-       }
        if (dialog->priv->add_entries_id) {
                g_source_remove (dialog->priv->add_entries_id);
                dialog->priv->add_entries_id = 0;


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