[rhythmbox] audioscrobbler: add config dialog for choosing which services to enable
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] audioscrobbler: add config dialog for choosing which services to enable
- Date: Tue, 21 Sep 2010 10:55:18 +0000 (UTC)
commit 7c1784b08c72ab7c05470011004c0cf7f628dce2
Author: Jamie Nicol <jamie thenicols net>
Date: Fri Aug 13 23:24:39 2010 +0100
audioscrobbler: add config dialog for choosing which services to enable
.../audioscrobbler/audioscrobbler-preferences.ui | 137 +++++++++++++
plugins/audioscrobbler/rb-audioscrobbler-plugin.c | 211 ++++++++++++++++++--
2 files changed, 330 insertions(+), 18 deletions(-)
---
diff --git a/plugins/audioscrobbler/audioscrobbler-preferences.ui b/plugins/audioscrobbler/audioscrobbler-preferences.ui
new file mode 100644
index 0000000..43b1037
--- /dev/null
+++ b/plugins/audioscrobbler/audioscrobbler-preferences.ui
@@ -0,0 +1,137 @@
+<?xml version="1.0"?>
+<interface>
+ <requires lib="gtk+" version="2.16"/>
+ <!-- interface-naming-policy project-wide -->
+ <object class="GtkDialog" id="config_dialog">
+ <property name="border_width">5</property>
+ <property name="resizable">False</property>
+ <property name="destroy_with_parent">True</property>
+ <property name="type_hint">normal</property>
+ <property name="has_separator">False</property>
+ <signal name="response" handler="config_dialog_response_cb"/>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="dialog-vbox1">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">4</property>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Which Audioscrobbler services do you wish to use?</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="hbox1">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="xpad">8</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkVBox" id="vbox2">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkCheckButton" id="lastfm_enabled_check">
+ <property name="label" translatable="yes">Last.fm</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="image">lastfm_image</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="lastfm_enabled_check_toggled_cb"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="librefm_enabled_check">
+ <property name="label" translatable="yes">Libre.fm</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="image">librefm_image</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="librefm_enabled_check_toggled_cb"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox" id="dialog-action_area1">
+ <property name="visible">True</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="button1">
+ <property name="label">gtk-close</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">button1</action-widget>
+ </action-widgets>
+ </object>
+ <object class="GtkImage" id="lastfm_image">
+ <property name="visible">True</property>
+ <property name="pixbuf">Last.fm-icon.png</property>
+ </object>
+ <object class="GtkImage" id="librefm_image">
+ <property name="visible">True</property>
+ <property name="pixbuf">Libre.fm-icon.png</property>
+ </object>
+</interface>
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-plugin.c b/plugins/audioscrobbler/rb-audioscrobbler-plugin.c
index 4065367..c2821e0 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-plugin.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-plugin.c
@@ -30,9 +30,7 @@
#include <config.h>
#endif
-#include <string.h> /* For strlen */
#include <glib/gi18n-lib.h>
-#include <gmodule.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <glib-object.h>
@@ -40,9 +38,10 @@
#include "rb-audioscrobbler-service.h"
#include "rb-audioscrobbler-profile-source.h"
#include "rb-plugin.h"
+#include "rb-builder-helpers.h"
#include "rb-debug.h"
#include "rb-shell.h"
-#include "rb-dialog.h"
+#include "eel-gconf-extensions.h"
#define RB_TYPE_AUDIOSCROBBLER_PLUGIN (rb_audioscrobbler_plugin_get_type ())
@@ -52,11 +51,25 @@
#define RB_IS_AUDIOSCROBBLER_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), RB_TYPE_AUDIOSCROBBLER_PLUGIN))
#define RB_AUDIOSCROBBLER_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), RB_TYPE_AUDIOSCROBBLER_PLUGIN, RBAudioscrobblerPluginClass))
+#define CONF_AUDIOSCROBBLER_PREFIX CONF_PREFIX "/plugins/audioscrobbler"
+#define CONF_LASTFM_ENABLED CONF_AUDIOSCROBBLER_PREFIX "/Last.fm/enabled"
+#define CONF_LIBREFM_ENABLED CONF_AUDIOSCROBBLER_PREFIX "/Libre.fm/enabled"
+
typedef struct
{
RBPlugin parent;
+ RBShell *shell;
+
+ GtkWidget *config_dialog;
+ /* Last.fm */
+ GtkWidget *lastfm_enabled_check;
+ guint lastfm_enabled_notification_id;
RBSource *lastfm_source;
+
+ /* Libre.fm */
+ GtkWidget *librefm_enabled_check;
+ guint librefm_enabled_notification_id;
RBSource *librefm_source;
} RBAudioscrobblerPlugin;
@@ -74,6 +87,22 @@ static void rb_audioscrobbler_plugin_init (RBAudioscrobblerPlugin *plugin);
static void rb_audioscrobbler_plugin_finalize (GObject *object);
static void impl_activate (RBPlugin *plugin, RBShell *shell);
static void impl_deactivate (RBPlugin *plugin, RBShell *shell);
+static GtkWidget *impl_create_configure_dialog (RBPlugin *bplugin);
+static void init_config_dialog (RBAudioscrobblerPlugin *plugin);
+void config_dialog_response_cb (GtkWidget *dialog, gint response,
+ RBAudioscrobblerPlugin *plugin);
+void lastfm_enabled_check_toggled_cb (GtkToggleButton *togglebutton,
+ RBAudioscrobblerPlugin *plugin);
+static void lastfm_enabled_changed_cb (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ RBAudioscrobblerPlugin *plugin);
+void librefm_enabled_check_toggled_cb (GtkToggleButton *togglebutton,
+ RBAudioscrobblerPlugin *plugin);
+static void librefm_enabled_changed_cb (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ RBAudioscrobblerPlugin *plugin);
RB_PLUGIN_REGISTER(RBAudioscrobblerPlugin, rb_audioscrobbler_plugin)
@@ -87,6 +116,7 @@ rb_audioscrobbler_plugin_class_init (RBAudioscrobblerPluginClass *klass)
plugin_class->activate = impl_activate;
plugin_class->deactivate = impl_deactivate;
+ plugin_class->create_configure_dialog = impl_create_configure_dialog;
}
static void
@@ -103,26 +133,45 @@ rb_audioscrobbler_plugin_finalize (GObject *object)
G_OBJECT_CLASS (rb_audioscrobbler_plugin_parent_class)->finalize (object);
}
-
-
static void
impl_activate (RBPlugin *bplugin,
RBShell *shell)
{
RBAudioscrobblerPlugin *plugin;
- RBAudioscrobblerService *lastfm;
- RBAudioscrobblerService *librefm;
-
plugin = RB_AUDIOSCROBBLER_PLUGIN (bplugin);
- lastfm = rb_audioscrobbler_service_new_lastfm ();
- plugin->lastfm_source = rb_audioscrobbler_profile_source_new (shell, bplugin, lastfm);
+ plugin->shell = shell;
+ init_config_dialog (plugin);
- librefm = rb_audioscrobbler_service_new_librefm ();
- plugin->librefm_source = rb_audioscrobbler_profile_source_new (shell, bplugin, librefm);
+ plugin->lastfm_enabled_notification_id =
+ eel_gconf_notification_add (CONF_LASTFM_ENABLED,
+ (GConfClientNotifyFunc) lastfm_enabled_changed_cb,
+ plugin);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin->lastfm_enabled_check),
+ eel_gconf_get_boolean (CONF_LASTFM_ENABLED));
+ if (eel_gconf_get_boolean (CONF_LASTFM_ENABLED) == TRUE) {
+ RBAudioscrobblerService *lastfm;
+ lastfm = rb_audioscrobbler_service_new_lastfm ();
+ plugin->lastfm_source = rb_audioscrobbler_profile_source_new (plugin->shell,
+ RB_PLUGIN (plugin),
+ lastfm);
+ g_object_unref (lastfm);
+ }
- g_object_unref (lastfm);
- g_object_unref (librefm);
+ plugin->librefm_enabled_notification_id =
+ eel_gconf_notification_add (CONF_LIBREFM_ENABLED,
+ (GConfClientNotifyFunc) librefm_enabled_changed_cb,
+ plugin);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin->librefm_enabled_check),
+ eel_gconf_get_boolean (CONF_LIBREFM_ENABLED));
+ if (eel_gconf_get_boolean (CONF_LIBREFM_ENABLED) == TRUE) {
+ RBAudioscrobblerService *librefm;
+ librefm = rb_audioscrobbler_service_new_librefm ();
+ plugin->librefm_source = rb_audioscrobbler_profile_source_new (plugin->shell,
+ RB_PLUGIN (plugin),
+ librefm);
+ g_object_unref (librefm);
+ }
}
static void
@@ -131,9 +180,135 @@ impl_deactivate (RBPlugin *bplugin,
{
RBAudioscrobblerPlugin *plugin = RB_AUDIOSCROBBLER_PLUGIN (bplugin);
- rb_source_delete_thyself (plugin->lastfm_source);
- plugin->lastfm_source = NULL;
+ if (plugin->config_dialog != NULL) {
+ gtk_widget_destroy (plugin->config_dialog);
+ plugin->config_dialog = NULL;
+ }
+
+ if (plugin->lastfm_source != NULL) {
+ rb_source_delete_thyself (plugin->lastfm_source);
+ plugin->lastfm_source = NULL;
+ }
+
+ if (plugin->librefm_source != NULL) {
+ rb_source_delete_thyself (plugin->librefm_source);
+ plugin->librefm_source = NULL;
+ }
+}
+
+static GtkWidget *
+impl_create_configure_dialog (RBPlugin *bplugin)
+{
+ RBAudioscrobblerPlugin *plugin;
+ plugin = RB_AUDIOSCROBBLER_PLUGIN (bplugin);
+
+ if (plugin->config_dialog == NULL) {
+ init_config_dialog (plugin);
+ }
+
+ gtk_widget_show_all (plugin->config_dialog);
+ return plugin->config_dialog;
+}
+
+static void
+init_config_dialog (RBAudioscrobblerPlugin *plugin)
+{
+ char *builderfile;
+ GtkBuilder *builder;
+
+ if (plugin->config_dialog != NULL) {
+ return;
+ }
+
+ builderfile = rb_plugin_find_file (RB_PLUGIN (plugin), "audioscrobbler-preferences.ui");
+ if (builderfile == NULL) {
+ g_warning ("can't find audioscrobbler-preferences.ui");
+ return;
+ }
+
+ builder = rb_builder_load (builderfile, plugin);
+ g_free (builderfile);
+
+ plugin->config_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "config_dialog"));
+ gtk_widget_hide_on_delete (plugin->config_dialog);
+
+ plugin->lastfm_enabled_check = GTK_WIDGET (gtk_builder_get_object (builder, "lastfm_enabled_check"));
+ plugin->librefm_enabled_check = GTK_WIDGET (gtk_builder_get_object (builder, "librefm_enabled_check"));
+
+ g_object_unref (builder);
+}
+
+void
+config_dialog_response_cb (GtkWidget *dialog, gint response,
+ RBAudioscrobblerPlugin *plugin)
+{
+ gtk_widget_hide (dialog);
+}
+
+void
+lastfm_enabled_check_toggled_cb (GtkToggleButton *togglebutton,
+ RBAudioscrobblerPlugin *plugin)
+{
+ eel_gconf_set_boolean (CONF_LASTFM_ENABLED,
+ gtk_toggle_button_get_active (togglebutton));
+}
+
+static void
+lastfm_enabled_changed_cb (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ RBAudioscrobblerPlugin *plugin)
+{
+ gboolean enabled;
+ enabled = gconf_value_get_bool (entry->value);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin->lastfm_enabled_check),
+ enabled);
+ if (enabled == TRUE && plugin->lastfm_source == NULL) {
+ RBAudioscrobblerService *lastfm;
+ lastfm = rb_audioscrobbler_service_new_lastfm ();
+ plugin->lastfm_source = rb_audioscrobbler_profile_source_new (plugin->shell,
+ RB_PLUGIN (plugin),
+ lastfm);
+ g_object_unref (lastfm);
+ } else if (enabled == FALSE && plugin->lastfm_source != NULL) {
+ rb_source_delete_thyself (plugin->lastfm_source);
+ plugin->lastfm_source = NULL;
+ } else {
+ g_assert_not_reached ();
+ }
+}
+
+void
+librefm_enabled_check_toggled_cb (GtkToggleButton *togglebutton,
+ RBAudioscrobblerPlugin *plugin)
+{
+ eel_gconf_set_boolean (CONF_LIBREFM_ENABLED,
+ gtk_toggle_button_get_active (togglebutton));
+}
+
+static void
+librefm_enabled_changed_cb (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ RBAudioscrobblerPlugin *plugin)
+{
+ gboolean enabled;
+ enabled = gconf_value_get_bool (entry->value);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin->librefm_enabled_check),
+ enabled);
+
+ if (enabled == TRUE && plugin->librefm_source == NULL) {
+ RBAudioscrobblerService *librefm;
- rb_source_delete_thyself (plugin->librefm_source);
- plugin->librefm_source = NULL;
+ librefm = rb_audioscrobbler_service_new_librefm ();
+ plugin->librefm_source = rb_audioscrobbler_profile_source_new (plugin->shell,
+ RB_PLUGIN (plugin),
+ librefm);
+ g_object_unref (librefm);
+ } else if (enabled == FALSE && plugin->librefm_source != NULL) {
+ rb_source_delete_thyself (plugin->librefm_source);
+ plugin->librefm_source = NULL;
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]