[rhythmbox] audioscrobbler: add radio source popup with "Delete Station" option



commit 86fe51638c03f6ecb12a4fa27642bf513b51b0a2
Author: Jamie Nicol <jamie thenicols net>
Date:   Sat Jul 10 21:46:35 2010 +0100

    audioscrobbler: add radio source popup with "Delete Station" option

 plugins/audioscrobbler/audioscrobbler-ui.xml       |   13 +-----
 plugins/audioscrobbler/rb-audioscrobbler-plugin.c  |   17 ++++++++
 .../rb-audioscrobbler-profile-source.c             |   17 ++++++++-
 .../rb-audioscrobbler-profile-source.h             |    2 +
 .../rb-audioscrobbler-radio-source.c               |   41 ++++++++++++++++++++
 5 files changed, 78 insertions(+), 12 deletions(-)
---
diff --git a/plugins/audioscrobbler/audioscrobbler-ui.xml b/plugins/audioscrobbler/audioscrobbler-ui.xml
index 8fde975..89191b9 100644
--- a/plugins/audioscrobbler/audioscrobbler-ui.xml
+++ b/plugins/audioscrobbler/audioscrobbler-ui.xml
@@ -1,14 +1,5 @@
 <ui>
-  <popup name="LastfmStationViewPopup">
-    <menuitem name="DeleteLibraryPopup" action="LastfmStationDelete"/>
-  </popup>
-
-  <popup name="LastfmTrackVieWPopup">
-    <menuitem name="Ban" action="LastfmBanSong"/>
-    <menuitem name="Love" action="LastfmLoveSong"/>
-    <menuitem name="Download" action="LastfmDownloadSong"/>
-  </popup>
-
-  <popup name="LastfmSourcePopup">
+  <popup name="AudioscrobblerRadioSourcePopup">
+    <menuitem name="DeleteStation" action="AudioscrobblerRadioDeleteStation"/>
   </popup>
 </ui>
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-plugin.c b/plugins/audioscrobbler/rb-audioscrobbler-plugin.c
index 0bf64c6..93ede36 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-plugin.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-plugin.c
@@ -56,6 +56,7 @@ typedef struct
 {
 	RBPlugin parent;
 
+	guint ui_merge_id;
 	RBSource *source;
 } RBAudioscrobblerPlugin;
 
@@ -109,13 +110,23 @@ impl_activate (RBPlugin *bplugin,
 	       RBShell *shell)
 {
 	RBAudioscrobblerPlugin *plugin;
+	GtkUIManager *ui_manager;
+	char *file;
 	RBAudioscrobblerService *service;
 
 	plugin = RB_AUDIOSCROBBLER_PLUGIN (bplugin);
 
+	g_object_get (shell, "ui-manager", &ui_manager, NULL);
+	file = rb_plugin_find_file (bplugin, "audioscrobbler-ui.xml");
+	plugin->ui_merge_id = gtk_ui_manager_add_ui_from_file (ui_manager,
+							       file,
+							       NULL);
+	g_free (file);
+
 	service = rb_audioscrobbler_service_new ();
 	plugin->source = rb_audioscrobbler_profile_source_new (shell, bplugin, service);
 
+	g_object_unref (ui_manager);
 	g_object_unref (service);
 }
 
@@ -124,7 +135,13 @@ impl_deactivate	(RBPlugin *bplugin,
 		 RBShell *shell)
 {
 	RBAudioscrobblerPlugin *plugin = RB_AUDIOSCROBBLER_PLUGIN (bplugin);
+	GtkUIManager *ui_manager;
+
+	g_object_get (shell, "ui-manager", &ui_manager, NULL);
+	gtk_ui_manager_remove_ui (ui_manager, plugin->ui_merge_id);
 
 	rb_source_delete_thyself (plugin->source);
 	plugin->source = NULL;
+
+	g_object_unref (ui_manager);
 }
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c b/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
index e3d613b..a0baf13 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
@@ -812,7 +812,7 @@ rb_audioscrobbler_profile_source_playing_song_changed_cb (RBShellPlayer *player,
 	g_free (action_name);
 }
 
-/* remove old radio sources and load ones for new user */
+/* delete old user's radio sources and load ones for new user */
 static void
 rb_audioscrobbler_profile_source_load_radio_stations (RBAudioscrobblerProfileSource *source)
 {
@@ -884,6 +884,21 @@ rb_audioscrobbler_profile_source_add_radio_station (RBAudioscrobblerProfileSourc
 	return radio;
 }
 
+/* removes a station from user's list of radio stations, deletes the source */
+void
+rb_audioscrobbler_profile_source_remove_radio_station (RBAudioscrobblerProfileSource *source,
+                                                       RBSource *station)
+{
+	GList *i;
+
+	i = g_list_find (source->priv->radio_sources, station);
+
+	if (i != NULL) {
+		rb_source_delete_thyself (i->data);
+		source->priv->radio_sources = g_list_remove (source->priv->radio_sources, i->data);
+	}
+}
+
 static void
 rb_audioscrobbler_profile_source_user_info_updated_cb (RBAudioscrobblerUser *user,
                                                        RBAudioscrobblerUserData *data,
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-profile-source.h b/plugins/audioscrobbler/rb-audioscrobbler-profile-source.h
index a54c921..69a31f3 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-profile-source.h
+++ b/plugins/audioscrobbler/rb-audioscrobbler-profile-source.h
@@ -61,6 +61,8 @@ GType rb_audioscrobbler_profile_source_get_type (void);
 RBSource *rb_audioscrobbler_profile_source_new (RBShell *shell,
                                                 RBPlugin *plugin,
                                                 RBAudioscrobblerService *service);
+void rb_audioscrobbler_profile_source_remove_radio_station (RBAudioscrobblerProfileSource *source,
+                                                            RBSource *station);
 
 G_END_DECLS
 
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c b/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c
index 6ff334d..2d4479b 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c
@@ -123,6 +123,8 @@ struct _RBAudioscrobblerRadioSourcePrivate
 	RhythmDBEntry *playing_entry;
 
 	guint emit_coverart_id;
+
+	GtkActionGroup *action_group;
 };
 
 #define RB_AUDIOSCROBBLER_RADIO_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_AUDIOSCROBBLER_RADIO_SOURCE, RBAudioscrobblerRadioSourcePrivate))
@@ -155,6 +157,9 @@ static void rb_audioscrobbler_radio_source_playing_song_changed_cb (RBShellPlaye
                                                                     RhythmDBEntry *entry,
                                                                     RBAudioscrobblerRadioSource *source);
 
+static void rb_audioscrobbler_radio_source_delete_station_action_cb (GtkAction *action,
+                                                                     RBAudioscrobblerRadioSource *source);
+
 /* cover art */
 static GValue *coverart_uri_request (RhythmDB *db,
                                      RhythmDBEntry *entry,
@@ -171,6 +176,7 @@ static RBEntryView *impl_get_entry_view (RBSource *asource);
 static void impl_get_status (RBSource *asource, char **text, char **progress_text, float *progress);
 static RBSourceEOFType impl_handle_eos (RBSource *asource);
 static GList *impl_get_ui_actions (RBSource *asource);
+static gboolean impl_show_popup (RBSource *asource);
 static void impl_delete_thyself (RBSource *asource);
 
 enum {
@@ -183,6 +189,15 @@ enum {
 	PROP_PLAY_ORDER
 };
 
+#define AUDIOSCROBBLER_RADIO_SOURCE_POPUP_PATH "/AudioscrobblerRadioSourcePopup"
+
+static GtkActionEntry rb_audioscrobbler_radio_source_actions [] =
+{
+	{ "AudioscrobblerRadioDeleteStation", GTK_STOCK_DELETE, N_("Delete Station"), NULL,
+	  N_("Delete the selected station"),
+	  G_CALLBACK (rb_audioscrobbler_radio_source_delete_station_action_cb) }
+};
+
 G_DEFINE_TYPE (RBAudioscrobblerRadioSource, rb_audioscrobbler_radio_source, RB_TYPE_STREAMING_SOURCE)
 
 RBSource *
@@ -254,6 +269,7 @@ rb_audioscrobbler_radio_source_class_init (RBAudioscrobblerRadioSourceClass *kla
 	source_class->impl_get_status = impl_get_status;
 	source_class->impl_handle_eos = impl_handle_eos;
 	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;
 
 	g_object_class_install_property (object_class,
@@ -375,6 +391,16 @@ rb_audioscrobbler_radio_source_constructed (GObject *object)
 				 G_CALLBACK (extra_metadata_gather_cb),
 				 source, 0);
 
+	/* actions */
+	source->priv->action_group = _rb_source_register_action_group (RB_SOURCE (source),
+								       "AudioscrobblerRadioActions",
+								       NULL, 0,
+								       shell);
+	_rb_action_group_add_source_actions (source->priv->action_group,
+					     G_OBJECT (shell),
+					     rb_audioscrobbler_radio_source_actions,
+					     G_N_ELEMENTS (rb_audioscrobbler_radio_source_actions));
+
 	rb_shell_append_source (shell, RB_SOURCE (source), RB_SOURCE (source->priv->parent));
 
 	g_object_unref (shell);
@@ -878,6 +904,14 @@ rb_audioscrobbler_radio_source_playing_song_changed_cb (RBShellPlayer *player,
 	g_object_unref (db);
 }
 
+static void
+rb_audioscrobbler_radio_source_delete_station_action_cb (GtkAction *action,
+                                                         RBAudioscrobblerRadioSource *source)
+{
+	rb_debug ("deleting station %s", source->priv->station_url);
+	rb_audioscrobbler_profile_source_remove_radio_station (source->priv->parent, RB_SOURCE (source));
+}
+
 /* cover art */
 static const char *
 get_image_url_for_entry (RBAudioscrobblerRadioSource *source, RhythmDBEntry *entry)
@@ -1018,6 +1052,13 @@ impl_get_ui_actions (RBSource *asource)
 	return rb_source_get_ui_actions (RB_SOURCE (source->priv->parent));
 }
 
+static gboolean
+impl_show_popup (RBSource *asource)
+{
+	_rb_source_show_popup (asource, AUDIOSCROBBLER_RADIO_SOURCE_POPUP_PATH);
+	return TRUE;
+}
+
 static void
 impl_delete_thyself (RBSource *asource)
 {



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