[rhythmbox] audioscrobbler: update profile periodically
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] audioscrobbler: update profile periodically
- Date: Tue, 21 Sep 2010 10:55:53 +0000 (UTC)
commit eca17444e8099ff612397c4516479d68014fb408
Author: Jamie Nicol <jamie thenicols net>
Date: Mon Sep 6 16:26:24 2010 +0100
audioscrobbler: update profile periodically
When source is activated, update profile and register a timeout callback
which every 5 minutes will update the profile. When source is deactivated
remove the callback.
Of course, these will only actually send update requests if the cached
responses are no longer valid.
.../rb-audioscrobbler-profile-source.c | 37 ++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c b/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
index 4bf755d..28221ba 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
@@ -56,6 +56,7 @@ struct _RBAudioscrobblerProfileSourcePrivate {
/* Used to request the user's profile data */
RBAudioscrobblerUser *user;
+ guint update_timeout_id;
/* List of radio stations owned by this source */
GList *radio_sources;
@@ -183,6 +184,9 @@ static void radio_station_name_changed_cb (RBAudioscrobblerRadioSource *radio,
GParamSpec *spec,
RBAudioscrobblerProfileSource *source);
+/* periodically attempts tp update the profile data */
+static gboolean update_timeout_cb (RBAudioscrobblerProfileSource *source);
+
/* callbacks from user profile data requests */
static void user_info_updated_cb (RBAudioscrobblerUser *user,
RBAudioscrobblerUserData *info,
@@ -229,6 +233,8 @@ static void list_item_listen_top_fans_activated_cb (GtkMenuItem *menuitem,
RBAudioscrobblerProfileSource *source);
/* RBSource implementations */
+static void impl_activate (RBSource *asource);
+static void impl_deactivate (RBSource *asource);
static GList *impl_get_ui_actions (RBSource *asource);
static gboolean impl_show_popup (RBSource *asource);
static void impl_delete_thyself (RBSource *asource);
@@ -300,6 +306,8 @@ rb_audioscrobbler_profile_source_class_init (RBAudioscrobblerProfileSourceClass
object_class->set_property = rb_audioscrobbler_profile_source_set_property;
source_class = RB_SOURCE_CLASS (klass);
+ source_class->impl_activate = impl_activate;
+ source_class->impl_deactivate = impl_deactivate;
source_class->impl_get_ui_actions = impl_get_ui_actions;
source_class->impl_show_popup = impl_show_popup;
source_class->impl_delete_thyself = impl_delete_thyself;
@@ -1328,6 +1336,14 @@ rb_audioscrobbler_profile_source_remove_radio_station (RBAudioscrobblerProfileSo
}
}
+static gboolean
+update_timeout_cb (RBAudioscrobblerProfileSource *source)
+{
+ rb_audioscrobbler_user_update (source->priv->user);
+
+ return TRUE;
+}
+
static void
user_info_updated_cb (RBAudioscrobblerUser *user,
RBAudioscrobblerUserData *data,
@@ -1859,6 +1875,27 @@ list_item_listen_top_fans_activated_cb (GtkMenuItem *menuitem,
g_object_unref (sourcelist);
}
+static void
+impl_activate (RBSource *asource)
+{
+ RBAudioscrobblerProfileSource *source = RB_AUDIOSCROBBLER_PROFILE_SOURCE (asource);
+
+ /* attempt to update now and again every 5 minutes */
+ rb_audioscrobbler_user_update (source->priv->user);
+ source->priv->update_timeout_id = g_timeout_add_seconds (300,
+ (GSourceFunc) update_timeout_cb,
+ source);
+}
+
+static void
+impl_deactivate (RBSource *asource)
+{
+ RBAudioscrobblerProfileSource *source = RB_AUDIOSCROBBLER_PROFILE_SOURCE (asource);
+
+ g_source_remove (source->priv->update_timeout_id);
+ source->priv->update_timeout_id = 0;
+}
+
static GList *
impl_get_ui_actions (RBSource *asource)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]