[rhythmbox] source: add helper method for setting status from an import job



commit 1e9ebb594391fb95c5066152121c218d4080d123
Author: Jonathan Matthew <jonathan d14n org>
Date:   Fri Feb 12 23:02:50 2010 +1000

    source: add helper method for setting status from an import job

 plugins/generic-player/rb-generic-player-source.c |   10 +-------
 sources/rb-source.c                               |   24 +++++++++++++++++++++
 sources/rb-source.h                               |    6 +++++
 3 files changed, 31 insertions(+), 9 deletions(-)
---
diff --git a/plugins/generic-player/rb-generic-player-source.c b/plugins/generic-player/rb-generic-player-source.c
index c61a2de..443d99d 100644
--- a/plugins/generic-player/rb-generic-player-source.c
+++ b/plugins/generic-player/rb-generic-player-source.c
@@ -556,15 +556,7 @@ impl_get_status (RBSource *source, char **text, char **progress_text, float *pro
 
 	/* override with bits of import status */
 	if (priv->import_job != NULL) {
-		int total;
-		int imported;
-
-		total = rhythmdb_import_job_get_total (priv->import_job);
-		imported = rhythmdb_import_job_get_imported (priv->import_job);
-
-		g_free (*progress_text);
-		*progress_text = g_strdup_printf (_("Importing (%d/%d)"), imported, total);
-		*progress = ((float)imported / (float)total);
+		_rb_source_set_import_status (source, priv->import_job, progress_text, progress);
 	}
 }
 
diff --git a/sources/rb-source.c b/sources/rb-source.c
index 78e1811..18ddac1 100644
--- a/sources/rb-source.c
+++ b/sources/rb-source.c
@@ -1861,6 +1861,30 @@ _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);
+}
+
 /* This should really be standard. */
 #define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
 
diff --git a/sources/rb-source.h b/sources/rb-source.h
index 16acb19..49604a9 100644
--- a/sources/rb-source.h
+++ b/sources/rb-source.h
@@ -35,6 +35,7 @@
 #include "rb-source-search.h"
 #include "rb-entry-view.h"
 #include "rb-shell-preferences.h"
+#include "rhythmdb-import-job.h"
 
 G_BEGIN_DECLS
 
@@ -233,6 +234,11 @@ void		_rb_action_group_add_source_actions (GtkActionGroup *group,
 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);
+
 G_END_DECLS
 
 #endif /* __RB_SOURCE_H */



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