[rhythmbox] rhythmdb: expose stat thread progress
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] rhythmdb: expose stat thread progress
- Date: Mon, 26 Apr 2010 11:57:13 +0000 (UTC)
commit 1ab43447c89554b3aaf48e57b07712d092b1a4cf
Author: Jonathan Matthew <jonathan d14n org>
Date: Mon Apr 26 21:36:05 2010 +1000
rhythmdb: expose stat thread progress
We're already polling to see when the stat thread finishes (more or
less) so we might as well poll for its progress too. Stat thread
progress is displayed in the progress bar widget in the status bar,
rather than just pulsing it while the database is busy.
rhythmdb/rhythmdb-private.h | 2 ++
rhythmdb/rhythmdb.c | 36 ++++++++++++++++++++++++++++++------
rhythmdb/rhythmdb.h | 1 +
shell/rb-statusbar.c | 16 +++++-----------
4 files changed, 38 insertions(+), 17 deletions(-)
---
diff --git a/rhythmdb/rhythmdb-private.h b/rhythmdb/rhythmdb-private.h
index 75a30e9..5a5b18d 100644
--- a/rhythmdb/rhythmdb-private.h
+++ b/rhythmdb/rhythmdb-private.h
@@ -140,6 +140,8 @@ struct _RhythmDBPrivate
GList *outstanding_stats;
GMutex *stat_mutex;
gboolean stat_thread_running;
+ int stat_thread_count;
+ int stat_thread_done;
GVolumeMonitor *volume_monitor;
GHashTable *monitored_directories;
diff --git a/rhythmdb/rhythmdb.c b/rhythmdb/rhythmdb.c
index 74d909c..95aa4f7 100644
--- a/rhythmdb/rhythmdb.c
+++ b/rhythmdb/rhythmdb.c
@@ -819,9 +819,11 @@ stat_thread_main (RhythmDBStatThreadData *data)
GList *i;
GError *error = NULL;
RhythmDBEvent *result;
- int count = 0;
- rb_debug ("entering stat thread: %d to process", g_list_length (data->stat_list));
+ data->db->priv->stat_thread_count = g_list_length (data->stat_list);
+ data->db->priv->stat_thread_done = 0;
+
+ rb_debug ("entering stat thread: %d to process", data->db->priv->stat_thread_count);
for (i = data->stat_list; i != NULL; i = i->next) {
RhythmDBEvent *event = (RhythmDBEvent *)i->data;
GFile *file;
@@ -831,12 +833,13 @@ stat_thread_main (RhythmDBStatThreadData *data)
*/
if (g_cancellable_is_cancelled (data->db->priv->exiting)) {
rhythmdb_event_free (data->db, event);
- count = 0;
continue;
}
- if (count > 0 && count % 1000 == 0) {
- rb_debug ("%d file info queries done", count);
+ if (data->db->priv->stat_thread_done > 0 &&
+ data->db->priv->stat_thread_done % 1000 == 0) {
+ rb_debug ("%d file info queries done",
+ data->db->priv->stat_thread_done);
}
file = g_file_new_for_uri (rb_refstring_get (event->uri));
@@ -912,7 +915,7 @@ stat_thread_main (RhythmDBStatThreadData *data)
g_async_queue_push (data->db->priv->event_queue, event);
g_object_unref (file);
- count++;
+ g_atomic_int_inc (&data->db->priv->stat_thread_done);
}
g_list_free (data->stat_list);
@@ -4666,6 +4669,27 @@ rhythmdb_is_busy (RhythmDB *db)
}
/**
+ * rhythmdb_get_progress_info:
+ * @db: a #RhythmDB.
+ * @text: used to return progress text
+ * @fraction: used to return progress fraction
+ *
+ * Provides progress information for rhythmdb operations, if any are running.
+ */
+void
+rhythmdb_get_progress_info (RhythmDB *db, char **text, float *fraction)
+{
+ if (db->priv->stat_thread_running && db->priv->stat_thread_count > 0) {
+ g_free (*text);
+ *text = g_strdup_printf (_("Checking (%d/%d)"),
+ db->priv->stat_thread_done,
+ db->priv->stat_thread_count);
+ *fraction = ((float)db->priv->stat_thread_done /
+ (float)db->priv->stat_thread_count);
+ }
+}
+
+/**
* rhythmdb_compute_status_normal:
* @n_songs: the number of tracks.
* @duration: the total duration of the tracks.
diff --git a/rhythmdb/rhythmdb.h b/rhythmdb/rhythmdb.h
index d7dc1e6..d12657a 100644
--- a/rhythmdb/rhythmdb.h
+++ b/rhythmdb/rhythmdb.h
@@ -495,6 +495,7 @@ RBStringValueMap* rhythmdb_entry_gather_metadata (RhythmDB *db, RhythmDBEntry *e
void rhythmdb_emit_entry_extra_metadata_notify (RhythmDB *db, RhythmDBEntry *entry, const gchar *property_name, const GValue *metadata);
gboolean rhythmdb_is_busy (RhythmDB *db);
+void rhythmdb_get_progress_info (RhythmDB *db, char **text, float *progress);
char * rhythmdb_compute_status_normal (gint n_songs, glong duration,
guint64 size,
const char *singular,
diff --git a/shell/rb-statusbar.c b/shell/rb-statusbar.c
index 9c8027a..b007c23 100644
--- a/shell/rb-statusbar.c
+++ b/shell/rb-statusbar.c
@@ -90,8 +90,6 @@ struct RBStatusbarPrivate
gboolean progress_changed;
gchar *progress_text;
- gchar *loading_text;
-
guint status_poll_id;
};
@@ -169,8 +167,6 @@ rb_statusbar_init (RBStatusbar *statusbar)
gtk_widget_set_size_request (statusbar->priv->progress, -1, 10);
statusbar->priv->progress_fraction = 1.0;
- statusbar->priv->loading_text = g_strdup (_("Loading..."));
-
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (statusbar->priv->progress), 1.0);
gtk_widget_hide (statusbar->priv->progress);
@@ -225,7 +221,6 @@ rb_statusbar_finalize (GObject *object)
g_return_if_fail (statusbar->priv != NULL);
- g_free (statusbar->priv->loading_text);
g_free (statusbar->priv->progress_text);
G_OBJECT_CLASS (rb_statusbar_parent_class)->finalize (object);
@@ -416,7 +411,6 @@ static void
rb_statusbar_sync_status (RBStatusbar *status)
{
gboolean changed = FALSE;
- gboolean show_progress = TRUE;
char *status_text = NULL;
char *progress_text = NULL;
float progress = 999;
@@ -431,9 +425,10 @@ rb_statusbar_sync_status (RBStatusbar *status)
/* library busy? */
if (rhythmdb_is_busy (status->priv->db)) {
- /*g_free (status_text);
- status_text = g_strdup (status->priv->loading_text); */
progress = -1.0f;
+
+ /* see if it wants to provide more details */
+ rhythmdb_get_progress_info (status->priv->db, &progress_text, &progress);
changed = TRUE;
}
@@ -451,7 +446,6 @@ rb_statusbar_sync_status (RBStatusbar *status)
progress = status->priv->progress_fraction;
status->priv->progress_changed = FALSE;
- show_progress = TRUE;
changed = TRUE;
}
@@ -463,12 +457,12 @@ rb_statusbar_sync_status (RBStatusbar *status)
}
/* set up the progress bar */
- if (progress > (1.0f - EPSILON) || !show_progress) {
+ if (progress > (1.0f - EPSILON)) {
gtk_widget_hide (status->priv->progress);
} else {
gtk_widget_show (status->priv->progress);
- if (progress < (0.0f - EPSILON)) {
+ if (progress < EPSILON) {
gtk_progress_bar_pulse (GTK_PROGRESS_BAR (status->priv->progress));
changed = TRUE;
} else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]