[rhythmbox] audioscrobbler: add option to disable/enable scrobbling submissions



commit 93af5bd36439b031d3b908e807b8961084512b6e
Author: Jamie Nicol <jamie thenicols net>
Date:   Fri Jun 25 20:53:46 2010 +0100

    audioscrobbler: add option to disable/enable scrobbling submissions

 plugins/audioscrobbler/audioscrobbler-profile.ui   |   25 +++++-
 .../rb-audioscrobbler-profile-source.c             |   89 +++++++++++++++++---
 plugins/audioscrobbler/rb-audioscrobbler.c         |   11 +++
 3 files changed, 112 insertions(+), 13 deletions(-)
---
diff --git a/plugins/audioscrobbler/audioscrobbler-profile.ui b/plugins/audioscrobbler/audioscrobbler-profile.ui
index 2dafe10..cd5fe62 100644
--- a/plugins/audioscrobbler/audioscrobbler-profile.ui
+++ b/plugins/audioscrobbler/audioscrobbler-profile.ui
@@ -88,6 +88,29 @@
                 <property name="visible">True</property>
                 <property name="xalign">0</property>
                 <property name="xscale">0</property>
+                <property name="left_padding">4</property>
+                <child>
+                  <object class="GtkCheckButton" id="scrobbling_enabled_check">
+                    <property name="label" translatable="yes">Submit listening data</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="draw_indicator">True</property>
+                    <signal name="toggled" handler="rb_audioscrobbler_profile_source_scrobbling_enabled_check_toggled_cb"/>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkAlignment" id="alignment3">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="xscale">0</property>
                 <child>
                   <object class="GtkLinkButton" id="view_profile_link">
                     <property name="label" translatable="yes">View your profile</property>
@@ -101,7 +124,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">2</property>
+                <property name="position">3</property>
               </packing>
             </child>
             <child>
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c b/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
index ea991cb..1ec475c 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
@@ -31,6 +31,8 @@
 #include <gdk/gdk.h>
 #include <math.h>
 
+#include "eel-gconf-extensions.h"
+
 #include "rb-audioscrobbler-profile-source.h"
 #include "rb-audioscrobbler.h"
 #include "rb-audioscrobbler-account.h"
@@ -38,8 +40,11 @@
 #include "rb-debug.h"
 #include "rb-builder-helpers.h"
 #include "rb-file-helpers.h"
+#include "rb-preferences.h"
 #include "rb-util.h"
 
+#define CONF_AUDIOSCROBBLER_ENABLE_SCROBBLING CONF_PLUGINS_PREFIX "/audioscrobbler/%s/scrobbling_enabled"
+
 struct _RBAudioscrobblerProfileSourcePrivate {
 	RBAudioscrobblerService *service;
 	RBAudioscrobblerAccount *account;
@@ -47,6 +52,8 @@ struct _RBAudioscrobblerProfileSourcePrivate {
 
 	RBAudioscrobblerUser *user;
 
+	guint scrobbling_enabled_notification_id;
+
 	GtkWidget *main_vbox;
 
 	GtkWidget *login_bar;
@@ -59,6 +66,7 @@ struct _RBAudioscrobblerProfileSourcePrivate {
 	GtkWidget *profile_image;
 	GtkWidget *username_label;
 	GtkWidget *playcount_label;
+	GtkWidget *scrobbling_enabled_check;
 	GtkWidget *view_profile_link;
 
 	GtkWidget *recent_tracks_area;
@@ -97,6 +105,12 @@ static void rb_audioscrobbler_profile_source_login_bar_response (GtkInfoBar *inf
                                                                  gpointer user_data);
 void rb_audioscrobbler_profile_source_logout_button_clicked_cb (GtkButton *button,
                                                                 gpointer user_data);
+void rb_audioscrobbler_profile_source_scrobbling_enabled_check_toggled_cb (GtkToggleButton *togglebutton,
+                                                                           gpointer user_data);
+static void rb_audioscrobbler_profile_source_scrobbling_enabled_changed_cb (GConfClient *client,
+                                                                            guint cnxn_id,
+                                                                            GConfEntry *entry,
+                                                                            RBAudioscrobblerProfileSource *source);
 
 static void rb_audioscrobbler_profile_source_login_status_change_cb (RBAudioscrobblerAccount *account,
                                                                      RBAudioscrobblerAccountLoginStatus status,
@@ -217,6 +231,7 @@ rb_audioscrobbler_profile_source_constructed (GObject *object)
 {
 	RBAudioscrobblerProfileSource *source;
 	RBShell *shell;
+	char *scrobbling_enabled_conf_key;
 
 	RB_CHAIN_GOBJECT_METHOD (rb_audioscrobbler_profile_source_parent_class, constructed, object);
 
@@ -231,15 +246,6 @@ rb_audioscrobbler_profile_source_constructed (GObject *object)
 	rb_audioscrobbler_profile_source_init_login_ui (source);
 	rb_audioscrobbler_profile_source_init_profile_ui (source);
 
-	/* create the scrobbler - submits listening data */
-	source->priv->audioscrobbler =
-		rb_audioscrobbler_new (source->priv->service,
-		                       RB_SHELL_PLAYER (rb_shell_get_player (shell)));
-	g_signal_connect (source->priv->audioscrobbler,
-	                  "authentication-error",
-	                  (GCallback)rb_audioscrobbler_profile_source_scrobbler_authentication_error_cb,
-	                  source);
-
 	/* create the user */
 	source->priv->user = rb_audioscrobbler_user_new (source->priv->service);
 	g_signal_connect (source->priv->user,
@@ -277,7 +283,18 @@ rb_audioscrobbler_profile_source_constructed (GObject *object)
 	                                                         rb_audioscrobbler_account_get_login_status (source->priv->account),
 	                                                         source);
 
+	/* create the scrobbler, if it is enabled */
+	scrobbling_enabled_conf_key = g_strdup_printf (CONF_AUDIOSCROBBLER_ENABLE_SCROBBLING,
+	                                               rb_audioscrobbler_service_get_name (source->priv->service));
+	source->priv->scrobbling_enabled_notification_id =
+		eel_gconf_notification_add (scrobbling_enabled_conf_key,
+				            (GConfClientNotifyFunc) rb_audioscrobbler_profile_source_scrobbling_enabled_changed_cb,
+				            source);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (source->priv->scrobbling_enabled_check),
+	                              eel_gconf_get_boolean (scrobbling_enabled_conf_key));
+
 	g_object_unref (shell);
+	g_free (scrobbling_enabled_conf_key);
 }
 
 static void
@@ -390,6 +407,7 @@ rb_audioscrobbler_profile_source_init_profile_ui (RBAudioscrobblerProfileSource
 	source->priv->profile_image = GTK_WIDGET (gtk_builder_get_object (builder, "profile_image"));
 	source->priv->username_label = GTK_WIDGET (gtk_builder_get_object (builder, "username_label"));
 	source->priv->playcount_label = GTK_WIDGET (gtk_builder_get_object (builder, "playcount_label"));
+	source->priv->scrobbling_enabled_check = GTK_WIDGET (gtk_builder_get_object (builder, "scrobbling_enabled_check"));
 	source->priv->view_profile_link = GTK_WIDGET (gtk_builder_get_object (builder, "view_profile_link"));
 
 	source->priv->recent_tracks_area = GTK_WIDGET (gtk_builder_get_object (builder, "recent_tracks_area"));
@@ -461,6 +479,51 @@ rb_audioscrobbler_profile_source_logout_button_clicked_cb (GtkButton *button,
 	rb_audioscrobbler_account_logout (source->priv->account);
 }
 
+void
+rb_audioscrobbler_profile_source_scrobbling_enabled_check_toggled_cb (GtkToggleButton *togglebutton,
+                                                                      gpointer user_data)
+{
+	RBAudioscrobblerProfileSource *source;
+	char *conf_key;
+
+	source = RB_AUDIOSCROBBLER_PROFILE_SOURCE (user_data);
+	conf_key = g_strdup_printf (CONF_AUDIOSCROBBLER_ENABLE_SCROBBLING,
+	                            rb_audioscrobbler_service_get_name (source->priv->service));
+	eel_gconf_set_boolean (conf_key,
+			       gtk_toggle_button_get_active (togglebutton));
+	g_free (conf_key);
+}
+
+static void
+rb_audioscrobbler_profile_source_scrobbling_enabled_changed_cb (GConfClient *client,
+                                                                guint cnxn_id,
+                                                                GConfEntry *entry,
+                                                                RBAudioscrobblerProfileSource *source)
+{
+	gboolean enabled = gconf_value_get_bool (entry->value);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (source->priv->scrobbling_enabled_check),
+	                              enabled);
+
+	if (source->priv->audioscrobbler != NULL && enabled == FALSE) {
+		g_object_unref (source->priv->audioscrobbler);
+		source->priv->audioscrobbler = NULL;
+	} else if (source->priv->audioscrobbler == NULL && enabled == TRUE) {
+		RBShell *shell;
+		g_object_get (source, "shell", &shell, NULL);
+		source->priv->audioscrobbler =
+			rb_audioscrobbler_new (source->priv->service,
+				               RB_SHELL_PLAYER (rb_shell_get_player (shell)));
+		rb_audioscrobbler_set_authentication_details (source->priv->audioscrobbler,
+			                                      rb_audioscrobbler_account_get_username (source->priv->account),
+			                                      rb_audioscrobbler_account_get_session_key (source->priv->account));
+		g_signal_connect (source->priv->audioscrobbler,
+			          "authentication-error",
+			          (GCallback)rb_audioscrobbler_profile_source_scrobbler_authentication_error_cb,
+			          source);
+		g_object_unref (shell);
+	}
+}
+
 static void
 rb_audioscrobbler_profile_source_login_status_change_cb (RBAudioscrobblerAccount *account,
                                                          RBAudioscrobblerAccountLoginStatus status,
@@ -480,9 +543,11 @@ rb_audioscrobbler_profile_source_login_status_change_cb (RBAudioscrobblerAccount
 	session_key = rb_audioscrobbler_account_get_session_key (source->priv->account);
 
 	/* update the audioscrobbler with new authentication */
-	rb_audioscrobbler_set_authentication_details (source->priv->audioscrobbler,
-	                                              username,
-	                                              session_key);
+	if (source->priv->audioscrobbler != NULL) {
+		rb_audioscrobbler_set_authentication_details (source->priv->audioscrobbler,
+			                                      username,
+			                                      session_key);
+	}
 
 	/* set the new user details */
 	rb_audioscrobbler_user_set_authentication_details (source->priv->user, username, session_key);
diff --git a/plugins/audioscrobbler/rb-audioscrobbler.c b/plugins/audioscrobbler/rb-audioscrobbler.c
index 20848e1..5760fbd 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler.c
@@ -206,6 +206,7 @@ rb_audioscrobbler_constructed (GObject *object)
 {
 	RBAudioscrobbler *audioscrobbler;
 	RhythmDB *db;
+	RhythmDBEntry *playing_entry;
 
 	RB_CHAIN_GOBJECT_METHOD (rb_audioscrobbler_parent_class, constructed, object);
 	audioscrobbler = RB_AUDIOSCROBBLER (object);
@@ -216,6 +217,16 @@ rb_audioscrobbler_constructed (GObject *object)
 					 "entry-extra-metadata-notify::rb:offlinePlay",
 					 (GCallback)rb_audioscrobbler_offline_play_notify_cb, 
 					 audioscrobbler, 0);
+
+	/* if an entry is currently being played then handle it */
+	playing_entry = rb_shell_player_get_playing_entry (audioscrobbler->priv->shell_player);
+	if (playing_entry != NULL) {
+		rb_audioscrobbler_song_changed_cb (audioscrobbler->priv->shell_player,
+		                                   playing_entry,
+		                                   audioscrobbler);
+		rhythmdb_entry_unref (playing_entry);
+	}
+
 	g_object_unref (db);
 }
 



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