[rhythmbox] rhythmdb: add rhythmdb_import_job_get_processed



commit 308e23b948b0424689fbf30d5f4160454e56940e
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sun Sep 23 01:16:54 2012 +1000

    rhythmdb: add rhythmdb_import_job_get_processed
    
    It's useful to know the number of entries that were successfully
    imported, as well as the total number of files processed.
    rhythmdb_import_job_get_imported now reports the former,
    rhythmdb_import_job_get_processed the latter.

 rhythmdb/rhythmdb-import-job.c |   40 +++++++++++++++++++++++++++++++---------
 rhythmdb/rhythmdb-import-job.h |    1 +
 2 files changed, 32 insertions(+), 9 deletions(-)
---
diff --git a/rhythmdb/rhythmdb-import-job.c b/rhythmdb/rhythmdb-import-job.c
index fda8c2d..ccef14c 100644
--- a/rhythmdb/rhythmdb-import-job.c
+++ b/rhythmdb/rhythmdb-import-job.c
@@ -63,6 +63,7 @@ struct _RhythmDBImportJobPrivate
 {
 	int		total;
 	int		imported;
+	int		processed;
 	GHashTable	*outstanding;
 	RhythmDB	*db;
 	RhythmDBEntryType *entry_type;
@@ -161,7 +162,7 @@ missing_plugins_retry_cb (gpointer instance, gboolean installed, RhythmDBImportJ
 		/* reset the job state to just show the retry information */
 		job->priv->total = g_slist_length (job->priv->retry_entries);
 		rb_debug ("plugin installation was successful, retrying %d entries", job->priv->total);
-		job->priv->imported = 0;
+		job->priv->processed = 0;
 
 		/* remove the import error entries and build the list of URIs to retry */
 		for (i = job->priv->retry_entries; i != NULL; i = i->next) {
@@ -198,14 +199,14 @@ emit_status_changed (RhythmDBImportJob *job)
 	g_mutex_lock (&job->priv->lock);
 	job->priv->status_changed_id = 0;
 
-	rb_debug ("emitting status changed: %d/%d", job->priv->imported, job->priv->total);
-	g_signal_emit (job, signals[STATUS_CHANGED], 0, job->priv->total, job->priv->imported);
+	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);
 
 	/* temporary ref while emitting this signal as we're expecting the caller
 	 * to release the final reference there.
 	 */
 	g_object_ref (job);
-	if (job->priv->scan_complete && job->priv->imported >= job->priv->total) {
+	if (job->priv->scan_complete && job->priv->processed >= job->priv->total) {
 
 		if (job->priv->retry_entries != NULL && job->priv->retried == FALSE) {
 			gboolean processing = FALSE;
@@ -392,7 +393,7 @@ rhythmdb_import_job_get_total (RhythmDBImportJob *job)
  * rhythmdb_import_job_get_imported:
  * @job: the #RhythmDBImportJob
  *
- * Returns the number of files processed by the import job so far.
+ * Returns the number of files successfully imported by the import job so far.
  *
  * Return value: file count
  */
@@ -403,6 +404,20 @@ rhythmdb_import_job_get_imported (RhythmDBImportJob *job)
 }
 
 /**
+ * rhythmdb_import_job_get_processed:
+ * @job: the #RhythmDBImportJob
+ *
+ * Returns the number of files processed by the import job so far.
+ *
+ * Return value: file count
+ */
+int
+rhythmdb_import_job_get_processed (RhythmDBImportJob *job)
+{
+	return job->priv->processed;
+}
+
+/**
  * rhythmdb_import_job_scan_complete:
  * @job: the #RhythmDBImportJob
  *
@@ -462,14 +477,21 @@ entry_added_cb (RhythmDB *db,
 
 	if (ours) {
 		const char *details;
+		RhythmDBEntryType *entry_type;
 
-		job->priv->imported++;
-		rb_debug ("got entry %s; %d now imported", uri, job->priv->imported);
-		g_signal_emit (job, signals[ENTRY_ADDED], 0, entry);
+		entry_type = rhythmdb_entry_get_entry_type (entry);
+
+		job->priv->processed++;
+
+		if (entry_type == job->priv->entry_type) {
+			job->priv->imported++;
+			g_signal_emit (job, signals[ENTRY_ADDED], 0, entry);
+		}
+		rb_debug ("got entry %s; %d imported, %d processed", uri, job->priv->imported, job->priv->processed);
 
 		/* if it's an import error with missing plugins, add it to the retry list */
 		details = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_COMMENT);
-		if (rhythmdb_entry_get_entry_type (entry) == job->priv->error_type &&
+		if (entry_type == job->priv->error_type &&
 		    (details != NULL && details[0] != '\0')) {
 			rb_debug ("entry %s is an import error with missing plugin details: %s", uri, details);
 			job->priv->retry_entries = g_slist_prepend (job->priv->retry_entries, rhythmdb_entry_ref (entry));
diff --git a/rhythmdb/rhythmdb-import-job.h b/rhythmdb/rhythmdb-import-job.h
index a72ec96..72891f7 100644
--- a/rhythmdb/rhythmdb-import-job.h
+++ b/rhythmdb/rhythmdb-import-job.h
@@ -78,6 +78,7 @@ gboolean	rhythmdb_import_job_complete		(RhythmDBImportJob *job);
 gboolean	rhythmdb_import_job_scan_complete	(RhythmDBImportJob *job);
 int		rhythmdb_import_job_get_total		(RhythmDBImportJob *job);
 int		rhythmdb_import_job_get_imported	(RhythmDBImportJob *job);
+int		rhythmdb_import_job_get_processed	(RhythmDBImportJob *job);
 
 G_END_DECLS
 



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