[rhythmbox] audioscrobbler: replace Plugin's audioscrobbler with account
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] audioscrobbler: replace Plugin's audioscrobbler with account
- Date: Tue, 21 Sep 2010 10:47:20 +0000 (UTC)
commit 86d3d0d5e3b4d705879b15d138938dc7ba042081
Author: Jamie Nicol <jamie thenicols net>
Date: Mon May 24 18:11:37 2010 +0100
audioscrobbler: replace Plugin's audioscrobbler with account
New class RBAudioscrobblerAccount loads preferences dialog instead
of RBAudioscrobbler.
plugins/audioscrobbler/Makefile.am | 2 +
plugins/audioscrobbler/rb-audioscrobbler-account.c | 181 ++++++++++++++++++++
plugins/audioscrobbler/rb-audioscrobbler-account.h | 70 ++++++++
plugins/audioscrobbler/rb-audioscrobbler-plugin.c | 79 ++++-----
4 files changed, 291 insertions(+), 41 deletions(-)
---
diff --git a/plugins/audioscrobbler/Makefile.am b/plugins/audioscrobbler/Makefile.am
index d7ebc57..9b1071a 100644
--- a/plugins/audioscrobbler/Makefile.am
+++ b/plugins/audioscrobbler/Makefile.am
@@ -7,6 +7,8 @@ libaudioscrobbler_la_SOURCES = \
rb-audioscrobbler-plugin.c \
rb-audioscrobbler-entry.h \
rb-audioscrobbler-entry.c \
+ rb-audioscrobbler-account.h \
+ rb-audioscrobbler-account.c \
rb-audioscrobbler.c \
rb-audioscrobbler.h \
rb-lastfm-source.c \
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-account.c b/plugins/audioscrobbler/rb-audioscrobbler-account.c
new file mode 100644
index 0000000..ebb4047
--- /dev/null
+++ b/plugins/audioscrobbler/rb-audioscrobbler-account.c
@@ -0,0 +1,181 @@
+/*
+ * rb-audioscrobbler-account.c
+ *
+ * Copyright (C) 2010 Jamie Nicol <jamie thenicols net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * The Rhythmbox authors hereby grant permission for non-GPL compatible
+ * GStreamer plugins to be used and distributed together with GStreamer
+ * and Rhythmbox. This permission is above and beyond the permissions granted
+ * by the GPL license by which Rhythmbox is covered. If you modify this code
+ * you may extend this exception to your version of the code, but you are not
+ * obligated to do so. If you do not wish to do so, delete this exception
+ * statement from your version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "rb-audioscrobbler-account.h"
+#include "rb-builder-helpers.h"
+#include "rb-debug.h"
+#include "rb-util.h"
+
+
+struct _RBAudioscrobblerAccountPrivate
+{
+ RBShell *shell;
+
+ /* Widgets for the prefs pane */
+ GtkWidget *config_widget;
+ GtkWidget *username_entry;
+ GtkWidget *username_label;
+ GtkWidget *auth_link;
+};
+
+#define RB_AUDIOSCROBBLER_ACCOUNT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_AUDIOSCROBBLER_ACCOUNT, RBAudioscrobblerAccountPrivate))
+
+static void rb_audioscrobbler_account_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void rb_audioscrobbler_account_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void rb_audioscrobbler_account_dispose (GObject *object);
+static void rb_audioscrobbler_account_finalize (GObject *object);
+
+enum
+{
+ PROP_0,
+ PROP_SHELL,
+};
+
+G_DEFINE_TYPE (RBAudioscrobblerAccount, rb_audioscrobbler_account, G_TYPE_OBJECT)
+
+static void
+rb_audioscrobbler_account_constructed (GObject *object)
+{
+ RB_CHAIN_GOBJECT_METHOD (rb_audioscrobbler_account_parent_class, constructed, object);
+}
+
+static void
+rb_audioscrobbler_account_class_init (RBAudioscrobblerAccountClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->constructed = rb_audioscrobbler_account_constructed;
+ object_class->dispose = rb_audioscrobbler_account_dispose;
+ object_class->finalize = rb_audioscrobbler_account_finalize;
+
+ object_class->get_property = rb_audioscrobbler_account_get_property;
+ object_class->set_property = rb_audioscrobbler_account_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_SHELL,
+ g_param_spec_object ("shell",
+ "RBShell",
+ "RBShell object",
+ RB_TYPE_SHELL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ g_type_class_add_private (klass, sizeof (RBAudioscrobblerAccountPrivate));
+}
+
+static void
+rb_audioscrobbler_account_init (RBAudioscrobblerAccount *account)
+{
+ account->priv = RB_AUDIOSCROBBLER_ACCOUNT_GET_PRIVATE (account);
+}
+
+static void
+rb_audioscrobbler_account_dispose (GObject *object)
+{
+ G_OBJECT_CLASS (rb_audioscrobbler_account_parent_class)->dispose (object);
+}
+
+static void
+rb_audioscrobbler_account_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (rb_audioscrobbler_account_parent_class)->finalize (object);
+}
+
+RBAudioscrobblerAccount *
+rb_audioscrobbler_account_new (RBShell *shell)
+{
+ return g_object_new (RB_TYPE_AUDIOSCROBBLER_ACCOUNT,
+ "shell", shell,
+ NULL);
+}
+
+static void
+rb_audioscrobbler_account_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ RBAudioscrobblerAccount *account = RB_AUDIOSCROBBLER_ACCOUNT (object);
+
+ switch (prop_id) {
+ case PROP_SHELL:
+ g_value_set_object (value, account->priv->shell);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+rb_audioscrobbler_account_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ RBAudioscrobblerAccount *account = RB_AUDIOSCROBBLER_ACCOUNT (object);
+
+ switch (prop_id) {
+ case PROP_SHELL:
+ account->priv->shell = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+GtkWidget *
+rb_audioscrobbler_account_get_config_widget (RBAudioscrobblerAccount *account,
+ RBPlugin *plugin)
+{
+ GtkBuilder *builder;
+ char *builder_file;
+
+ if (account->priv->config_widget)
+ return account->priv->config_widget;
+
+ builder_file = rb_plugin_find_file (plugin, "audioscrobbler-prefs.ui");
+ g_assert (builder_file != NULL);
+ builder = rb_builder_load (builder_file, account);
+ g_free (builder_file);
+
+ account->priv->config_widget = GTK_WIDGET (gtk_builder_get_object (builder, "audioscrobbler_vbox"));
+ account->priv->username_entry = GTK_WIDGET (gtk_builder_get_object (builder, "username_entry"));
+ account->priv->username_label = GTK_WIDGET (gtk_builder_get_object (builder, "username_label"));
+ account->priv->auth_link = GTK_WIDGET (gtk_builder_get_object (builder, "auth_link"));
+
+ rb_builder_boldify_label (builder, "audioscrobbler_label");
+
+ return account->priv->config_widget;
+}
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-account.h b/plugins/audioscrobbler/rb-audioscrobbler-account.h
new file mode 100644
index 0000000..e958724
--- /dev/null
+++ b/plugins/audioscrobbler/rb-audioscrobbler-account.h
@@ -0,0 +1,70 @@
+/*
+ * rb-audioscrobbler-account.h
+ *
+ * Copyright (C) 2010 Jamie Nicol <jamie thenicols net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * The Rhythmbox authors hereby grant permission for non-GPL compatible
+ * GStreamer plugins to be used and distributed together with GStreamer
+ * and Rhythmbox. This permission is above and beyond the permissions granted
+ * by the GPL license by which Rhythmbox is covered. If you modify this code
+ * you may extend this exception to your version of the code, but you are not
+ * obligated to do so. If you do not wish to do so, delete this exception
+ * statement from your version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __RB_AUDIOSCROBBLER_ACCOUNT_H
+#define __RB_AUDIOSCROBBLER_ACCOUNT_H
+
+#include <gtk/gtk.h>
+#include <glib.h>
+
+#include "rb-plugin.h"
+#include "rb-shell.h"
+
+G_BEGIN_DECLS
+
+#define RB_TYPE_AUDIOSCROBBLER_ACCOUNT (rb_audioscrobbler_account_get_type ())
+#define RB_AUDIOSCROBBLER_ACCOUNT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), RB_TYPE_AUDIOSCROBBLER_ACCOUNT, RBAudioscrobblerAccount))
+#define RB_AUDIOSCROBBLER_ACCOUNT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), RB_TYPE_AUDIOSCROBBLER_ACCOUNT, RBAudioscrobblerAccountClass))
+#define RB_IS_AUDIOSCROBBLER_ACCOUNT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), RB_TYPE_AUDIOSCROBBLER_ACCOUNT))
+#define RB_IS_AUDIOSCROBBLER_ACCOUNT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), RB_TYPE_AUDIOSCROBBLER_ACCOUNT))
+#define RB_AUDIOSCROBBLER_ACCOUNT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), RB_TYPE_AUDIOSCROBBLER_ACCOUNT, RBAudioscrobblerAccountClass))
+
+typedef struct _RBAudioscrobblerAccountPrivate RBAudioscrobblerAccountPrivate;
+
+typedef struct
+{
+ GObject parent;
+
+ RBAudioscrobblerAccountPrivate *priv;
+} RBAudioscrobblerAccount;
+
+typedef struct
+{
+ GObjectClass parent_class;
+} RBAudioscrobblerAccountClass;
+
+GType rb_audioscrobbler_account_get_type (void);
+
+RBAudioscrobblerAccount * rb_audioscrobbler_account_new (RBShell *shell);
+
+GtkWidget * rb_audioscrobbler_account_get_config_widget (RBAudioscrobblerAccount *account,
+ RBPlugin *plugin);
+
+G_END_DECLS
+
+#endif /* __RB_AUDIOSCROBBLER_ACCOUNT_H */
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-plugin.c b/plugins/audioscrobbler/rb-audioscrobbler-plugin.c
index aa5756d..95f8654 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-plugin.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-plugin.c
@@ -37,7 +37,7 @@
#include <glib.h>
#include <glib-object.h>
-#include "rb-audioscrobbler.h"
+#include "rb-audioscrobbler-account.h"
#include "rb-plugin.h"
#include "rb-debug.h"
#include "rb-shell.h"
@@ -53,9 +53,15 @@
typedef struct
{
- RBPlugin parent;
- RBAudioscrobbler *audioscrobbler;
+ RBAudioscrobblerAccount *account;
GtkWidget *preferences;
+} RBAudioscrobblerPluginPrivate;
+
+typedef struct
+{
+ RBPlugin parent;
+
+ RBAudioscrobblerPluginPrivate *priv;
} RBAudioscrobblerPlugin;
typedef struct
@@ -63,6 +69,7 @@ typedef struct
RBPluginClass parent_class;
} RBAudioscrobblerPluginClass;
+#define RB_AUDIOSCROBBLER_PLUGIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_AUDIOSCROBBLER_PLUGIN, RBAudioscrobblerPluginPrivate))
G_MODULE_EXPORT GType register_rb_plugin (GTypeModule *module);
GType rb_audioscrobbler_plugin_get_type (void) G_GNUC_CONST;
@@ -88,12 +95,16 @@ 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;
+
+ g_type_class_add_private (klass, sizeof (RBAudioscrobblerPluginPrivate));
}
static void
rb_audioscrobbler_plugin_init (RBAudioscrobblerPlugin *plugin)
{
rb_debug ("RBAudioscrobblerPlugin initialising");
+
+ plugin->priv = RB_AUDIOSCROBBLER_PLUGIN_GET_PRIVATE (plugin);
}
static void
@@ -103,10 +114,10 @@ rb_audioscrobbler_plugin_finalize (GObject *object)
rb_debug ("RBAudioscrobblerPlugin finalising");
- g_assert (plugin->audioscrobbler == NULL);
+ g_assert (plugin->priv->account == NULL);
- if (plugin->preferences)
- gtk_widget_destroy (plugin->preferences);
+ if (plugin->priv->preferences)
+ gtk_widget_destroy (plugin->priv->preferences);
G_OBJECT_CLASS (rb_audioscrobbler_plugin_parent_class)->finalize (object);
}
@@ -118,21 +129,9 @@ impl_activate (RBPlugin *bplugin,
RBShell *shell)
{
RBAudioscrobblerPlugin *plugin = RB_AUDIOSCROBBLER_PLUGIN (bplugin);
- gboolean no_registration;
-
- g_assert (plugin->audioscrobbler == NULL);
- g_object_get (G_OBJECT (shell),
- "no-registration", &no_registration,
- NULL);
-
- /*
- * Don't use audioscrobbler when the no-registration flag is set.
- * This flag is only used to run multiple instances at the same time, and
- * last.fm only allows one active client per user.
- */
- if (!no_registration) {
- plugin->audioscrobbler = rb_audioscrobbler_new (RB_SHELL_PLAYER (rb_shell_get_player (shell)));
- }
+
+ g_assert (plugin->priv->account == NULL);
+ plugin->priv->account = rb_audioscrobbler_account_new (shell);
}
static void
@@ -141,10 +140,8 @@ impl_deactivate (RBPlugin *bplugin,
{
RBAudioscrobblerPlugin *plugin = RB_AUDIOSCROBBLER_PLUGIN (bplugin);
- if (plugin->audioscrobbler) {
- g_object_unref (plugin->audioscrobbler);
- plugin->audioscrobbler = NULL;
- }
+ g_object_unref (plugin->priv->account);
+ plugin->priv->account = NULL;
}
static void
@@ -157,34 +154,34 @@ static GtkWidget*
impl_create_configure_dialog (RBPlugin *bplugin)
{
RBAudioscrobblerPlugin *plugin = RB_AUDIOSCROBBLER_PLUGIN (bplugin);
- if (plugin->audioscrobbler == NULL)
+ if (plugin->priv->account == NULL)
return NULL;
- if (plugin->preferences == NULL) {
+ if (plugin->priv->preferences == NULL) {
GtkWidget *widget;
- widget = rb_audioscrobbler_get_config_widget (plugin->audioscrobbler, bplugin);
+ widget = rb_audioscrobbler_account_get_config_widget (plugin->priv->account, bplugin);
- plugin->preferences = gtk_dialog_new_with_buttons (_("Last.fm Preferences"),
- NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
- NULL);
- gtk_dialog_set_has_separator (GTK_DIALOG (plugin->preferences), FALSE);
- gtk_container_set_border_width (GTK_CONTAINER (plugin->preferences), 5);
- gtk_window_set_resizable (GTK_WINDOW (plugin->preferences), FALSE);
+ plugin->priv->preferences = gtk_dialog_new_with_buttons (_("Last.fm Preferences"),
+ NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
+ NULL);
+ gtk_dialog_set_has_separator (GTK_DIALOG (plugin->priv->preferences), FALSE);
+ gtk_container_set_border_width (GTK_CONTAINER (plugin->priv->preferences), 5);
+ gtk_window_set_resizable (GTK_WINDOW (plugin->priv->preferences), FALSE);
- g_signal_connect (G_OBJECT (plugin->preferences),
+ g_signal_connect (G_OBJECT (plugin->priv->preferences),
"response",
G_CALLBACK (preferences_response_cb),
plugin);
- gtk_widget_hide_on_delete (plugin->preferences);
+ gtk_widget_hide_on_delete (plugin->priv->preferences);
- gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (plugin->preferences))),
+ gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (plugin->priv->preferences))),
widget);
}
- gtk_widget_show_all (plugin->preferences);
- return plugin->preferences;
+ gtk_widget_show_all (plugin->priv->preferences);
+ return plugin->priv->preferences;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]