[rhythmbox] rb-client: use new dbus signals to wait for readiness
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] rb-client: use new dbus signals to wait for readiness
- Date: Tue, 10 Aug 2010 07:36:10 +0000 (UTC)
commit cae78c96be96e601e26f1c4b1e2037d84a3c2159
Author: Jonathan Matthew <jonathan d14n org>
Date: Tue Aug 10 17:32:31 2010 +1000
rb-client: use new dbus signals to wait for readiness
This makes things like 'rhythmbox-client --play' work when we're not already
running.
remote/dbus/rb-client.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/remote/dbus/rb-client.c b/remote/dbus/rb-client.c
index 5bb34a2..bbf914a 100644
--- a/remote/dbus/rb-client.c
+++ b/remote/dbus/rb-client.c
@@ -115,6 +115,9 @@ static GOptionEntry args[] = {
{ NULL }
};
+static gboolean db_load_complete = FALSE;
+static gboolean scan_finished = FALSE;
+
static gboolean
annoy (GError **error)
{
@@ -397,6 +400,8 @@ create_rb_shell_proxies (DBusGConnection *bus, DBusGProxy **shell_proxy, DBusGPr
*shell_proxy = NULL;
return ((*error)->code == DBUS_GERROR_NAME_HAS_NO_OWNER);
}
+ dbus_g_proxy_add_signal (sp, "removableMediaScanFinished", G_TYPE_INVALID);
+ dbus_g_proxy_add_signal (sp, "databaseLoadComplete", G_TYPE_INVALID);
rb_debug ("creating player proxy");
*player_proxy = dbus_g_proxy_new_from_proxy (sp,
@@ -518,6 +523,36 @@ rate_song (DBusGProxy *shell_proxy, DBusGProxy *player_proxy, gdouble song_ratin
g_free (playing_uri);
}
+static void
+maybe_unblock (GMainLoop *loop)
+{
+ if (db_load_complete && scan_finished) {
+ /* FIXME - we're not really ready to accept playback control just yet.
+ * the library (at least) needs to populate itself with the database contents,
+ * which takes some non-zero amount of time. this hack makes things work
+ * somewhat reliably.
+ */
+ g_usleep (G_USEC_PER_SEC);
+ g_main_loop_quit (loop);
+ }
+}
+
+static void
+scan_finished_cb (DBusGProxy *proxy, GMainLoop *loop)
+{
+ rb_debug ("removable media scan finished");
+ scan_finished = TRUE;
+ maybe_unblock (loop);
+}
+
+static void
+db_load_complete_cb (DBusGProxy *proxy, GMainLoop *loop)
+{
+ rb_debug ("database load complete");
+ db_load_complete = TRUE;
+ maybe_unblock (loop);
+}
+
int
main (int argc, char **argv)
{
@@ -573,6 +608,7 @@ main (int argc, char **argv)
}
if (shell_proxy == NULL) {
DBusGProxy *bus_proxy;
+ GMainLoop *loop;
guint start_service_reply;
if (no_start) {
@@ -602,6 +638,13 @@ main (int argc, char **argv)
exit (1);
}
g_clear_error (&error);
+
+ /* wait for it to load enough state to be useful */
+ rb_debug ("waiting for database load and removable media scan to finish");
+ loop = g_main_loop_new (NULL, FALSE);
+ dbus_g_proxy_connect_signal (shell_proxy, "removableMediaScanFinished", G_CALLBACK (scan_finished_cb), loop, NULL);
+ dbus_g_proxy_connect_signal (shell_proxy, "databaseLoadComplete", G_CALLBACK (db_load_complete_cb), loop, NULL);
+ g_main_loop_run (loop);
}
/* don't present if we're doing something else */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]