[rhythmbox] Port daap and magnatune plugins to libsecret



commit 1fac0aa8c06f20244af4e5d20ca86ecd1a4fd64e
Author: Nirbheek Chauhan <nirbheek chauhan collabora co uk>
Date:   Wed Jan 23 02:29:10 2013 +0530

    Port daap and magnatune plugins to libsecret
    
    The Magnatune plugin currently falls back to not saving the password at all if
    libsecret isn't found. This fallback code should be removed once libsecret
    becomes as prevalent as gnome-keyring was.
    
    Audioscrobbler used gnome-keyring for the old API, which no longer works.
    Hence, that code was removed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=694981
    
    As a bonus, add cscope.out to .gitignore

 .gitignore                                         |    1 +
 configure.ac                                       |   40 ++-
 plugins/audioscrobbler/Makefile.am                 |    1 -
 .../rb-audioscrobbler-radio-source.c               |  383 ++------------------
 .../rb-audioscrobbler-radio-source.h               |    3 -
 plugins/daap/Makefile.am                           |    6 +-
 plugins/daap/rb-daap-source.c                      |   82 ++---
 plugins/magnatune/MagnatuneAccount.py              |   88 +++--
 8 files changed, 143 insertions(+), 461 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index a0a2751..d27c9c0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
 .libs
 *.pyc
 *.plugin
+cscope.out
 
 autom4te*.cache
 stamp-h
diff --git a/configure.ac b/configure.ac
index 3fb4232..146ea4f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -59,6 +59,8 @@ LIBMTP_REQS=0.3.0
 LIBPEAS_REQS=0.7.3
 GRILO_REQS=0.2.0
 LIBXML2_REQS=2.7.8
+# Needed for libsecret commit ddd9bdd2 for the Magnatune plugin
+LIBSECRET_REQS=0.14
 
 LIBNOTIFY_REQS=0.7.0
 BRASERO_MIN_REQS=2.31.5
@@ -223,26 +225,28 @@ fi
 AM_CONDITIONAL(USE_MTP, test x"$use_mtp" = xyes)
 
 
-dnl gnome-keyring support
+dnl libsecret keyring support
 
-AC_ARG_WITH(gnome-keyring,
-            AC_HELP_STRING([--with-gnome-keyring],
-                          [Enable gnome-keyring support]),,
-             with_gnome_keyring=auto)
-if test "x$with_gnome_keyring" != "xno"; then
+AC_ARG_WITH(libsecret,
+            AC_HELP_STRING([--with-libsecret],
+                          [Enable keyring support using libsecret]),,
+             with_libsecret=auto)
+if test "x$with_libsecret" != "xno"; then
 
-       PKG_CHECK_MODULES(GNOME_KEYRING, gnome-keyring-1, have_gnome_keyring=yes, have_gnome_keyring=no)
-       if test "x$have_gnome_keyring" = "xno" -a "x$with_gnome_keyring" = "xyes"; then
-         AC_MSG_ERROR([gnome-keyring support explicitly requested but gnome-keyring couldn't be found])
+       PKG_CHECK_MODULES(LIBSECRET, libsecret-1 >= $LIBSECRET_REQS,
+                         have_libsecret=yes, have_libsecret=no)
+       if test "x$have_libsecret" = "xno" -a "x$with_libsecret" = "xyes"; then
+         AC_MSG_ERROR([keyring support explicitly requested but libsecret
+                       could not be found])
        fi
-       if test "x$have_gnome_keyring" = "xyes"; then
-          AC_DEFINE(WITH_GNOME_KEYRING, 1, [Define if gnome-keyring support is enabled])
-          use_gnome_keyring=yes
-         AC_SUBST(GNOME_KEYRING_CFLAGS)
-         AC_SUBST(GNOME_KEYRING_LIBS)
+       if test "x$have_libsecret" = "xyes"; then
+          AC_DEFINE(WITH_LIBSECRET, 1, [Define if libsecret support is enabled])
+          use_libsecret=yes
+         AC_SUBST(LIBSECRET_CFLAGS)
+         AC_SUBST(LIBSECRET_LIBS)
        fi
 fi
-AM_CONDITIONAL(USE_GNOME_KEYRING, test x"$use_gnome_keyring" = xyes)
+AM_CONDITIONAL(USE_LIBSECRET, test x"$use_libsecret" = xyes)
 
 dnl Database
 AC_ARG_WITH(database,
@@ -919,10 +923,10 @@ if test x"$with_vala" = xyes; then
 else
        AC_MSG_NOTICE([   Vala plugin support disabled])
 fi
-if test x"$use_gnome_keyring" = xyes; then
-       AC_MSG_NOTICE([** gnome-keyring support enabled])
+if test x"$use_libsecret" = xyes; then
+       AC_MSG_NOTICE([** Libsecret keyring support enabled])
 else
-       AC_MSG_NOTICE([   gnome-keyring support disabled])
+       AC_MSG_NOTICE([   Libsecret keyring support disabled])
 fi
 if test "x$enable_fm_radio" != xno; then
        AC_MSG_NOTICE([** FM radio support enabled])
diff --git a/plugins/audioscrobbler/Makefile.am b/plugins/audioscrobbler/Makefile.am
index 913a6b3..ca332f1 100644
--- a/plugins/audioscrobbler/Makefile.am
+++ b/plugins/audioscrobbler/Makefile.am
@@ -53,7 +53,6 @@ INCLUDES =                                            \
        $(TOTEM_PLPARSER_CFLAGS)                        \
        $(JSON_GLIB_CFLAGS)                             \
        $(RHYTHMBOX_CFLAGS)                             \
-       $(GNOME_KEYRING_CFLAGS)                         \
        -D_BSD_SOURCE
 
 gtkbuilderdir = $(plugindatadir)
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c 
b/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c
index 6f5f3cf..b0ddd52 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c
@@ -35,10 +35,6 @@
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
 
-#ifdef WITH_GNOME_KEYRING
-#include <gnome-keyring.h>
-#endif
-
 #include <totem-pl-parser.h>
 
 #include "rb-audioscrobbler-radio-source.h"
@@ -170,9 +166,6 @@ struct _RBAudioscrobblerRadioSourcePrivate
        GtkWidget *error_info_bar;
        GtkWidget *error_info_bar_label;
 
-       GtkWidget *password_info_bar;
-       GtkWidget *password_info_bar_entry;
-
        RBEntryView *track_view;
        RhythmDBQueryModel *track_model;
 
@@ -184,13 +177,6 @@ struct _RBAudioscrobblerRadioSourcePrivate
        RhythmDBEntry *playing_entry;
 
        RBExtDB *art_store;
-
-       /* used when streaming radio using old api */
-       char *old_api_password;
-       char *old_api_session_id;
-       char *old_api_base_url;
-       char *old_api_base_path;
-       gboolean old_api_is_banned;
 };
 
 #define RB_AUDIOSCROBBLER_RADIO_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), 
RB_TYPE_AUDIOSCROBBLER_RADIO_SOURCE, RBAudioscrobblerRadioSourcePrivate))
@@ -225,24 +211,9 @@ static void xspf_entry_parsed (TotemPlParser *parser,
                                GHashTable *metadata,
                                RBAudioscrobblerRadioSource *source);
 
-/* old api */
-static void old_api_shake_hands (RBAudioscrobblerRadioSource *source);
-static void old_api_handshake_response_cb (SoupSession *session,
-                                           SoupMessage *msg,
-                                           gpointer user_data);
-static void old_api_tune (RBAudioscrobblerRadioSource *source);
-static void old_api_tune_response_cb (SoupSession *session,
-                                      SoupMessage *msg,
-                                      gpointer user_data);
-static void old_api_fetch_playlist (RBAudioscrobblerRadioSource *source);
-
 /* info bar related things */
 static void display_error_info_bar (RBAudioscrobblerRadioSource *source,
                                     const char *message);
-static void display_password_info_bar (RBAudioscrobblerRadioSource *source);
-static void password_info_bar_response_cb (GtkInfoBar *info_bar,
-                                           int response_id,
-                                           RBAudioscrobblerRadioSource *source);
 
 /* RBDisplayPage implementations */
 static void impl_selected (RBDisplayPage *page);
@@ -413,8 +384,6 @@ rb_audioscrobbler_radio_source_constructed (GObject *object)
        RhythmDB *db;
        GtkWidget *main_vbox;
        GtkWidget *error_info_bar_content_area;
-       GtkWidget *password_info_bar_label;
-       GtkWidget *password_info_bar_content_area;
        GtkAccelGroup *accel_group;
        RBSourceToolbar *toolbar;
 
@@ -446,23 +415,6 @@ rb_audioscrobbler_radio_source_constructed (GObject *object)
        gtk_container_add (GTK_CONTAINER (error_info_bar_content_area), source->priv->error_info_bar_label);
        gtk_box_pack_start (GTK_BOX (main_vbox), source->priv->error_info_bar, FALSE, FALSE, 0);
 
-       /* password info bar */
-       source->priv->password_info_bar = gtk_info_bar_new ();
-       password_info_bar_label = gtk_label_new (_("You must enter your password to listen to this station"));
-       password_info_bar_content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR 
(source->priv->password_info_bar));
-       gtk_container_add (GTK_CONTAINER (password_info_bar_content_area), password_info_bar_label);
-       source->priv->password_info_bar_entry = gtk_entry_new ();
-       gtk_entry_set_visibility (GTK_ENTRY (source->priv->password_info_bar_entry), FALSE);
-       gtk_info_bar_add_action_widget (GTK_INFO_BAR (source->priv->password_info_bar),
-                                       source->priv->password_info_bar_entry,
-                                       GTK_RESPONSE_NONE);
-       gtk_info_bar_add_button (GTK_INFO_BAR (source->priv->password_info_bar), GTK_STOCK_OK, 
GTK_RESPONSE_OK);
-       g_signal_connect (source->priv->password_info_bar,
-                         "response",
-                         G_CALLBACK (password_info_bar_response_cb),
-                         source);
-       gtk_box_pack_start (GTK_BOX (main_vbox), source->priv->password_info_bar, FALSE, FALSE, 0);
-
        /* entry view */
        source->priv->track_view = rb_entry_view_new (db, G_OBJECT (shell_player), FALSE, FALSE);
        rb_entry_view_append_column (source->priv->track_view, RB_ENTRY_VIEW_COL_TITLE, TRUE);
@@ -541,11 +493,6 @@ rb_audioscrobbler_radio_source_finalize (GObject *object)
        g_free (source->priv->session_key);
        g_free (source->priv->station_url);
 
-       g_free (source->priv->old_api_password);
-       g_free (source->priv->old_api_session_id);
-       g_free (source->priv->old_api_base_url);
-       g_free (source->priv->old_api_base_path);
-
        G_OBJECT_CLASS (rb_audioscrobbler_radio_source_parent_class)->finalize (object);
 }
 
@@ -691,7 +638,6 @@ tune (RBAudioscrobblerRadioSource *source)
 
        source->priv->is_busy = TRUE;
        gtk_widget_hide (source->priv->error_info_bar);
-       gtk_widget_hide (source->priv->password_info_bar);
 
        sig_arg = g_strdup_printf ("api_key%smethodradio.tunesk%sstation%s%s",
                                   rb_audioscrobbler_service_get_api_key (source->priv->service),
@@ -772,44 +718,38 @@ tune_response_cb (SoupSession *session,
 
                        rb_debug ("tune request responded with error: %s", message);
 
-                       if (code == 4) {
-                               /* Our API key only allows streaming of radio to subscribers */
-                               rb_debug ("attempting to use old API to tune radio");
-                               old_api_tune (source);
+                       /* show appropriate error message */
+                       char *error_message = NULL;
+
+                       if (code == 6) {
+                               /* Invalid station url */
+                               error_message = g_strdup (_("Invalid station URL"));
+                       } else if (code == 12) {
+                               /* Subscriber only station */
+                               /* Translators: %s is the name of the audioscrobbler service, for example 
"Last.fm".
+                                * This message indicates that to listen to this radio station the user needs 
to be
+                                * a paying subscriber to the service. */
+                               error_message = g_strdup_printf (_("This station is only available to %s 
subscribers"),
+                                                                rb_audioscrobbler_service_get_name 
(source->priv->service));
+                       } else if (code == 20) {
+                               /* Not enough content */
+                               error_message = g_strdup (_("Not enough content to play station"));
+                       } else if (code == 27) {
+                               /* Deprecated station */
+                               /* Translators: %s is the name of the audioscrobbler service, for example 
"Last.fm".
+                                * This message indicates that the service has deprecated this type of 
station. */
+                               error_message = g_strdup_printf (_("%s no longer supports this type of 
station"),
+                                                                rb_audioscrobbler_service_get_name 
(source->priv->service));
                        } else {
-                               /* show appropriate error message */
-                               char *error_message = NULL;
-
-                               if (code == 6) {
-                                       /* Invalid station url */
-                                       error_message = g_strdup (_("Invalid station URL"));
-                               } else if (code == 12) {
-                                       /* Subscriber only station */
-                                       /* Translators: %s is the name of the audioscrobbler service, for 
example "Last.fm".
-                                        * This message indicates that to listen to this radio station the 
user needs to be
-                                        * a paying subscriber to the service. */
-                                       error_message = g_strdup_printf (_("This station is only available to 
%s subscribers"),
-                                                                        rb_audioscrobbler_service_get_name 
(source->priv->service));
-                               } else if (code == 20) {
-                                       /* Not enough content */
-                                       error_message = g_strdup (_("Not enough content to play station"));
-                               } else if (code == 27) {
-                                       /* Deprecated station */
-                                       /* Translators: %s is the name of the audioscrobbler service, for 
example "Last.fm".
-                                        * This message indicates that the service has deprecated this type 
of station. */
-                                       error_message = g_strdup_printf (_("%s no longer supports this type 
of station"),
-                                                                        rb_audioscrobbler_service_get_name 
(source->priv->service));
-                               } else {
-                                       /* Other error */
-                                       error_message = g_strdup_printf (_("Error tuning station: %i - %s"), 
code, message);
-                               }
-
-                               display_error_info_bar (source, error_message);
-
-                               g_free (error_message);
-
-                               source->priv->is_busy = FALSE;
+                               /* Other error */
+                               error_message = g_strdup_printf (_("Error tuning station: %i - %s"), code, 
message);
                        }
+
+                       display_error_info_bar (source, error_message);
+
+                       g_free (error_message);
+
+                       source->priv->is_busy = FALSE;
                } else {
                        rb_debug ("unexpected response from tune request: %s", msg->response_body->data);
                        display_error_info_bar(source, _("Error tuning station: unexpected response"));
@@ -1030,229 +970,6 @@ xspf_entry_parsed (TotemPlParser *parser,
 }
 
 static void
-old_api_shake_hands (RBAudioscrobblerRadioSource *source)
-{
-       if (source->priv->old_api_password != NULL) {
-               char *password_hash;
-               char *msg_url;
-               SoupMessage *msg;
-
-               password_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, 
source->priv->old_api_password, -1);
-
-               msg_url = g_strdup_printf ("%sradio/handshake.php?username=%s&passwordmd5=%s",
-                                          rb_audioscrobbler_service_get_old_radio_api_url 
(source->priv->service),
-                                          source->priv->username,
-                                          password_hash);
-
-               rb_debug ("sending old api handshake request: %s", msg_url);
-               msg = soup_message_new ("GET", msg_url);
-               soup_session_queue_message (source->priv->soup_session,
-                                           msg,
-                                           old_api_handshake_response_cb,
-                                           source);
-
-               g_free (password_hash);
-               g_free (msg_url);
-       } else {
-#ifdef WITH_GNOME_KEYRING
-               GnomeKeyringResult result;
-               char *password;
-
-               rb_debug ("attempting to retrieve password from keyring");
-               result = gnome_keyring_find_password_sync (GNOME_KEYRING_NETWORK_PASSWORD,
-                                                          &password,
-                                                          "user", source->priv->username,
-                                                          "server", rb_audioscrobbler_service_get_name 
(source->priv->service),
-                                                          NULL);
-
-               if (result == GNOME_KEYRING_RESULT_OK) {
-                       source->priv->old_api_password = g_strdup (password);
-                       rb_debug ("password found. shaking hands");
-                       old_api_shake_hands (source);
-               } else {
-                       rb_debug ("no password found");
-#endif
-                       rb_debug ("cannot shake hands. asking user for password");
-                       display_password_info_bar (source);
-                       source->priv->is_busy = FALSE;
-#ifdef WITH_GNOME_KEYRING
-               }
-#endif
-       }
-}
-
-static void
-old_api_handshake_response_cb (SoupSession *session,
-                               SoupMessage *msg,
-                               gpointer user_data)
-{
-       RBAudioscrobblerRadioSource *source;
-
-       source = RB_AUDIOSCROBBLER_RADIO_SOURCE (user_data);
-
-       if (msg->response_body->data == NULL) {
-               g_free (source->priv->old_api_session_id);
-               source->priv->old_api_session_id = NULL;
-               rb_debug ("handshake failed: no response");
-               display_error_info_bar (source, _("Error tuning station: no response"));
-       } else {
-               char **pieces;
-               int i;
-
-               pieces = g_strsplit (msg->response_body->data, "\n", 0);
-               for (i = 0; pieces[i] != NULL; i++) {
-                       gchar **values = g_strsplit (pieces[i], "=", 2);
-
-                       if (values[0] == NULL) {
-                               rb_debug ("unexpected response content: %s", pieces[i]);
-                       } else if (strcmp (values[0], "session") == 0) {
-                               if (strcmp (values[1], "FAILED") == 0) {
-                                       g_free (source->priv->old_api_session_id);
-                                       source->priv->old_api_session_id = NULL;
-
-                                       rb_debug ("handshake failed: probably bad authentication. asking user 
for new password");
-                                       g_free (source->priv->old_api_password);
-                                       source->priv->old_api_password = NULL;
-                                       display_password_info_bar (source);
-                               } else {
-                                       g_free (source->priv->old_api_session_id);
-                                       source->priv->old_api_session_id = g_strdup (values[1]);
-                                       rb_debug ("session ID: %s", source->priv->old_api_session_id);
-                               }
-                       } else if (strcmp (values[0], "base_url") == 0) {
-                               g_free (source->priv->old_api_base_url);
-                               source->priv->old_api_base_url = g_strdup (values[1]);
-                               rb_debug ("base url: %s", source->priv->old_api_base_url);
-                       } else if (strcmp (values[0], "base_path") == 0) {
-                               g_free (source->priv->old_api_base_path);
-                               source->priv->old_api_base_path = g_strdup (values[1]);
-                               rb_debug ("base path: %s", source->priv->old_api_base_path);
-                       } else if (strcmp (values[0], "banned") == 0) {
-                               if (strcmp (values[1], "0") != 0) {
-                                       source->priv->old_api_is_banned = TRUE;
-                               } else {
-                                       source->priv->old_api_is_banned = FALSE;
-                               }
-                               rb_debug ("banned: %i", source->priv->old_api_is_banned);
-                       }
-
-                       g_strfreev (values);
-               }
-               g_strfreev (pieces);
-       }
-
-       /* if handshake was successful then tune */
-       if (source->priv->old_api_session_id != NULL) {
-               old_api_tune (source);
-       } else {
-               source->priv->is_busy = FALSE;
-       }
-}
-
-static void
-old_api_tune (RBAudioscrobblerRadioSource *source)
-{
-       /* get a handshake first if we don't have one */
-       if (source->priv->old_api_session_id == NULL) {
-               old_api_shake_hands (source);
-       } else {
-               char *escaped_station_url;
-               char *msg_url;
-               SoupMessage *msg;
-
-               escaped_station_url = g_uri_escape_string (source->priv->station_url, NULL, FALSE);
-
-               msg_url = g_strdup_printf("http://%s%s/adjust.php?session=%s&url=%s";,
-                                         source->priv->old_api_base_url,
-                                         source->priv->old_api_base_path,
-                                         source->priv->old_api_session_id,
-                                         escaped_station_url);
-
-               rb_debug ("sending old api tune request: %s", msg_url);
-               msg = soup_message_new ("GET", msg_url);
-               soup_session_queue_message (source->priv->soup_session,
-                                           msg,
-                                           old_api_tune_response_cb,
-                                           source);
-
-               g_free (escaped_station_url);
-               g_free (msg_url);
-       }
-}
-
-static void
-old_api_tune_response_cb (SoupSession *session,
-                          SoupMessage *msg,
-                          gpointer user_data)
-{
-       RBAudioscrobblerRadioSource *source;
-
-       source = RB_AUDIOSCROBBLER_RADIO_SOURCE (user_data);
-
-       if (msg->response_body->data != NULL) {
-               char **pieces;
-               int i;
-
-               pieces = g_strsplit (msg->response_body->data, "\n", 0);
-               for (i = 0; pieces[i] != NULL; i++) {
-                       gchar **values = g_strsplit (pieces[i], "=", 2);
-
-                       if (values[0] == NULL) {
-                               rb_debug ("unexpected response from old api tune request: %s", pieces[i]);
-                       } else if (strcmp (values[0], "response") == 0) {
-                               if (strcmp (values[1], "OK") == 0) {
-                                       rb_debug ("old api tune request was successful");
-                                       /* no problems tuning, get the playlist */
-                                       old_api_fetch_playlist (source);
-                               }
-                       } else if (strcmp (values[0], "error") == 0) {
-                               char *error_message;
-                               rb_debug ("old api tune request responded with error: %s", pieces[i]);
-
-                               error_message = g_strdup_printf (_("Error tuning station: %s"), values[1]);
-
-
-                               g_free (error_message);
-
-                               source->priv->is_busy = FALSE;
-                       }
-                       /* TODO: do something with other information given here */
-
-                       g_strfreev (values);
-               }
-
-               g_strfreev (pieces);
-       } else {
-               rb_debug ("no response from old api tune request");
-               display_error_info_bar (source, _("Error tuning station: no response"));
-               source->priv->is_busy = FALSE;
-       }
-}
-
-static void
-old_api_fetch_playlist (RBAudioscrobblerRadioSource *source)
-{
-       char *msg_url;
-       SoupMessage *msg;
-
-       msg_url = g_strdup_printf("http://%s%s/xspf.php?sk=%s&discovery=%i&desktop=%s";,
-                                 source->priv->old_api_base_url,
-                                 source->priv->old_api_base_path,
-                                 source->priv->old_api_session_id,
-                                 0,
-                                 "1.5");
-
-       rb_debug ("sending old api playlist request: %s", msg_url);
-       msg = soup_message_new ("GET", msg_url);
-       soup_session_queue_message (source->priv->soup_session,
-                                   msg,
-                                   fetch_playlist_response_cb,
-                                   source);
-
-       g_free (msg_url);
-}
-
-static void
 display_error_info_bar (RBAudioscrobblerRadioSource *source,
                         const char *message)
 {
@@ -1261,46 +978,6 @@ display_error_info_bar (RBAudioscrobblerRadioSource *source,
        gtk_widget_show_all (source->priv->error_info_bar);
 }
 
-static void
-display_password_info_bar (RBAudioscrobblerRadioSource *source)
-{
-       gtk_widget_show_all (source->priv->password_info_bar);
-}
-
-static void
-password_info_bar_response_cb (GtkInfoBar *info_bar,
-                               int response_id,
-                               RBAudioscrobblerRadioSource *source)
-{
-       gtk_widget_hide (source->priv->password_info_bar);
-
-       g_free (source->priv->old_api_password);
-       source->priv->old_api_password = g_strdup (gtk_entry_get_text (GTK_ENTRY 
(source->priv->password_info_bar_entry)));
-
-#ifdef WITH_GNOME_KEYRING
-       /* save the new password */
-       char *password_desc;
-
-       password_desc = g_strdup_printf (_("Password for streaming %s radio using the deprecated API"),
-                                        rb_audioscrobbler_service_get_name (source->priv->service));
-
-       rb_debug ("saving password to keyring");
-       gnome_keyring_store_password_sync (GNOME_KEYRING_NETWORK_PASSWORD,
-                                          GNOME_KEYRING_DEFAULT,
-                                          password_desc,
-                                          source->priv->old_api_password,
-                                          "user", source->priv->username,
-                                          "server", rb_audioscrobbler_service_get_name 
(source->priv->service),
-                                          NULL);
-
-       g_free (password_desc);
-#endif
-
-       gtk_entry_set_text (GTK_ENTRY (source->priv->password_info_bar_entry), "");
-
-       old_api_shake_hands (source);
-}
-
 static gboolean
 impl_can_remove (RBDisplayPage *page)
 {
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-radio-source.h 
b/plugins/audioscrobbler/rb-audioscrobbler-radio-source.h
index f38d857..08bb4a0 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-radio-source.h
+++ b/plugins/audioscrobbler/rb-audioscrobbler-radio-source.h
@@ -86,9 +86,6 @@ RBSource *rb_audioscrobbler_radio_source_new (RBAudioscrobblerProfilePage *paren
                                               const char *station_name,
                                               const char *station_url);
 
-void rb_audioscrobbler_radio_source_set_old_api_password (RBAudioscrobblerRadioSource *source,
-                                                          const char *password);
-
 G_END_DECLS
 
 #endif /* __RB_AUDIOSCROBBLER_RADIO_SOURCE_H */
diff --git a/plugins/daap/Makefile.am b/plugins/daap/Makefile.am
index b950bef..f4bb907 100644
--- a/plugins/daap/Makefile.am
+++ b/plugins/daap/Makefile.am
@@ -63,9 +63,9 @@ INCLUDES =                                            \
        $(RHYTHMBOX_CFLAGS)                             \
        -D_BSD_SOURCE
 
-if USE_GNOME_KEYRING
-libdaap_la_LIBADD += $(GNOME_KEYRING_LIBS)
-INCLUDES += $(GNOME_KEYRING_CFLAGS)
+if USE_LIBSECRET
+libdaap_la_LIBADD += $(LIBSECRET_LIBS)
+INCLUDES += $(LIBSECRET_CFLAGS)
 endif
 
 gtkbuilderdir = $(plugindatadir)
diff --git a/plugins/daap/rb-daap-source.c b/plugins/daap/rb-daap-source.c
index fb034f9..75e0dc4 100644
--- a/plugins/daap/rb-daap-source.c
+++ b/plugins/daap/rb-daap-source.c
@@ -35,8 +35,8 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
-#ifdef WITH_GNOME_KEYRING
-#include <gnome-keyring.h>
+#ifdef WITH_LIBSECRET
+#include <libsecret/secret.h>
 #endif
 
 #include "rhythmdb.h"
@@ -394,31 +394,36 @@ mount_op_reply_cb (GMountOperation *op,
                   AuthData *auth_data)
 {
        const char *password;
-       gchar *keyring;
-#ifdef WITH_GNOME_KEYRING
-       guint32 item_id;
+#ifdef WITH_LIBSECRET
+       gchar *label;
+       gchar *collection = NULL;
 #endif
 
        rb_debug ("mount op reply: %d", result);
        password = g_mount_operation_get_password (op);
 
-#ifdef WITH_GNOME_KEYRING
+#ifdef WITH_LIBSECRET
        switch (g_mount_operation_get_password_save (op)) {
        case G_PASSWORD_SAVE_NEVER:
                break;
 
        case G_PASSWORD_SAVE_FOR_SESSION:
-               keyring = "session";
+               collection = SECRET_COLLECTION_SESSION;
                /* fall through */
 
        case G_PASSWORD_SAVE_PERMANENTLY:
-               gnome_keyring_set_network_password_sync (keyring,
-                       NULL,
-                       "DAAP", auth_data->name,
-                       NULL, "daap",
-                       NULL, 0,
+               label = g_strdup_printf ("Rhythmbox DAAP password for %s", auth_data->name);
+               secret_password_store_sync (SECRET_SCHEMA_COMPAT_NETWORK,
+                       collection,
+                       label,
                        password,
-                       &item_id);
+                       NULL,
+                       NULL,
+                       "domain", "DAAP",
+                       "server", auth_data->name,
+                       "protocol", "daap",
+                       NULL);
+               g_free (label);
                break;
 
        default:
@@ -443,7 +448,11 @@ mount_op_reply_cb (GMountOperation *op,
 }
 
 static void
-ask_password (RBDAAPSource *source, const char *name, const char *keyring, SoupSession *session, SoupMessage 
*msg, SoupAuth *auth)
+ask_password (RBDAAPSource *source,
+             const char *name,
+             SoupSession *session,
+             SoupMessage *msg,
+             SoupAuth *auth)
 {
        GtkWindow *parent;
        GMountOperation *mount_op;
@@ -465,10 +474,8 @@ ask_password (RBDAAPSource *source, const char *name, const char *keyring, SoupS
        g_signal_connect (mount_op, "reply", G_CALLBACK (mount_op_reply_cb), auth_data);
 
        flags = G_ASK_PASSWORD_NEED_PASSWORD;
-#ifdef WITH_GNOME_KEYRING
-       if (gnome_keyring_is_available ()) {
-               flags |= G_ASK_PASSWORD_SAVING_SUPPORTED;
-       }
+#ifdef WITH_LIBSECRET
+       flags |= G_ASK_PASSWORD_SAVING_SUPPORTED;
 #endif
        message = g_strdup_printf (_("The music share '%s' requires a password to connect"), name);
        g_signal_emit_by_name (mount_op, "ask-password", message, NULL, "DAAP", flags);
@@ -485,44 +492,31 @@ connection_auth_cb (DMAPConnection *connection,
                    RBDAAPSource   *source)
 {
        gchar *password = NULL;
-#ifdef WITH_GNOME_KEYRING
-       GnomeKeyringResult keyringret;
-       gchar *keyring;
-       GList *list = NULL;
+#ifdef WITH_LIBSECRET
+       GError *error = NULL;
 
-       keyring = NULL;
        if (!source->priv->tried_password) {
-               gnome_keyring_get_default_keyring_sync (&keyring);
-               keyringret = gnome_keyring_find_network_password_sync (
-                               NULL,
-                               "DAAP", name,
-                               NULL, "daap",
-                               NULL, 0, &list);
-       } else {
-               keyringret = GNOME_KEYRING_RESULT_CANCELLED;
+               password = secret_password_lookup_sync (SECRET_SCHEMA_COMPAT_NETWORK,
+                               NULL, &error,
+                               "domain", "DAAP",
+                               "server", name,
+                               "protocol", "daap",
+                               NULL);
        }
 
-       if (keyringret == GNOME_KEYRING_RESULT_OK) {
-               GnomeKeyringNetworkPasswordData *pwd_data;
-
-               if (list != NULL) {
-                       pwd_data = (GnomeKeyringNetworkPasswordData*)list->data;
-                       password = g_strdup (pwd_data->password);
-               }
+       if (!error)
                source->priv->tried_password = TRUE;
-       }
+       else
+               g_error_free (error);
 
        if (password == NULL) {
-               ask_password (source, name, keyring, session, msg, auth);
+               ask_password (source, name, session, msg, auth);
        } else {
                dmap_connection_authenticate_message (connection, session, msg, auth, password);
        }
 
-       if (list)
-               gnome_keyring_network_password_list_free (list);
-       g_free (keyring);
 #else
-       ask_password (source, name, NULL, session, msg, auth);
+       ask_password (source, name, session, msg, auth);
 #endif
 }
 
diff --git a/plugins/magnatune/MagnatuneAccount.py b/plugins/magnatune/MagnatuneAccount.py
index f8cf81b..93b04c9 100644
--- a/plugins/magnatune/MagnatuneAccount.py
+++ b/plugins/magnatune/MagnatuneAccount.py
@@ -1,4 +1,5 @@
 # -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
+# vim: set sts=0 ts=8 sw=8 tw=0 noet :
 #
 # Copyright (C) 2012 Jonathan Matthew  <jonathan d14n org>
 #
@@ -24,10 +25,25 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 
-from gi.repository import Gio, GnomeKeyring
+from gi.repository import Gio
+
+# Till libsecret completely replaces gnome-keyring, we'll fall back to not
+# saving the password if libsecret can't be found. This code can be removed later.
+try:
+       from gi.repository import Secret, SecretUnstable
+       # We need to be able to fetch passwords stored by libgnome-keyring, so we use
+       # a schema with SECRET_SCHEMA_DONT_MATCH_NAME set.
+       # See: http://developer.gnome.org/libsecret/unstable/migrating-schemas.html
+       MAGNATUNE_SCHEMA = Secret.Schema.new("org.gnome.rhythmbox.plugins.magnatune",
+                                               Secret.SchemaFlags.DONT_MATCH_NAME,
+                                               {"rhythmbox-plugin": Secret.SchemaAttributeType.STRING})
+except ImportError:
+       Secret = None
+       print ("You need to install libsecret and its introspection files to store your Magnatune password")
 
 __instance = None
 
+
 def instance():
        global __instance
        if __instance is None:
@@ -36,54 +52,48 @@ def instance():
 
 class MagnatuneAccount(object):
        def __init__(self):
-               self.keyring_item = None
                self.settings = Gio.Settings("org.gnome.rhythmbox.plugins.magnatune")
-
-               self.keyring_attributes = GnomeKeyring.attribute_list_new()
-               GnomeKeyring.attribute_list_append_string(self.keyring_attributes,
-                                                         "rhythmbox-plugin",
-                                                         "magnatune")
-               (result, items) = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET,
-                                                              self.keyring_attributes)
-               if result == GnomeKeyring.Result.OK and len(items) != 0:
-                       (result, item) = GnomeKeyring.item_get_info_sync(None, items[0].item_id)
-                       if result == GnomeKeyring.Result.OK:
-                               self.keyring_item = item
-                       else:
-                               print "Couldn't get keyring item: " + GnomeKeyring.result_to_message(result)
-               else:
-                       print "couldn't search keyring items: " + GnomeKeyring.result_to_message(result)
+               self.secret = None
+               self.keyring_attributes = {"rhythmbox-plugin": "magnatune"}
+               if Secret is None:
+                       print ("Account details will not be saved because libsecret was not found")
+                       return
+                # Haha.
+                self.secret_service = 
SecretUnstable.Service.get_sync(SecretUnstable.ServiceFlags.OPEN_SESSION, None)
+               items = self.secret_service.search_sync(MAGNATUNE_SCHEMA,
+                                                       self.keyring_attributes,
+                                                       SecretUnstable.SearchFlags.LOAD_SECRETS,
+                                                       None)
+               if not items:
+                       # The Python API doesn't seem to have a way to differentiate between errors and no 
results.
+                       print ("Couldn't find an existing keyring entry")
+                       return
+               self.secret = items[0].get_secret().get()
 
        def get(self):
-               if self.keyring_item is None:
+               if self.secret is None:
                        return ('none', None, None)
 
                account_type = self.settings['account-type']
                try:
-                       (username, password) = self.keyring_item.get_secret().split("\n")
+                       (username, password) = self.secret.split("\n")
                        return (account_type, username, password)
                except ValueError:
                        return ('none', None, None)
 
        def update(self, username, password):
                secret = '\n'.join((username, password))
-               if self.keyring_item is not None:
-                       if secret == self.keyring_item.get_secret():
-                               print "account details not changed"
-                               return
-
-               (result, id) = GnomeKeyring.item_create_sync(None,
-                                                            GnomeKeyring.ItemType.GENERIC_SECRET,
-                                                            "Rhythmbox: Magnatune account information",
-                                                            self.keyring_attributes,
-                                                            secret,
-                                                            True)
-               if result == GnomeKeyring.Result.OK:
-                       if self.keyring_item is None:
-                               (result, item) = GnomeKeyring.item_get_info_sync(None, id)
-                               if result == GnomeKeyring.Result.OK:
-                                       self.keyring_item = item
-                               else:
-                                       print "couldn't fetch keyring itme: " + 
GnomeKeyring.result_to_message(result)
-               else:
-                       print "couldn't create keyring item: " + GnomeKeyring.result_to_message(result)
+               if secret == self.secret:
+                       print ("Account details not changed")
+                       return
+               self.secret = secret
+               if Secret is None:
+                       print ("Account details were not saved because libsecret was not found")
+                       return
+               result = Secret.password_store_sync(MAGNATUNE_SCHEMA,
+                                                       self.keyring_attributes,
+                                                       Secret.COLLECTION_DEFAULT,
+                                                       "Rhythmbox: Magnatune account information",
+                                                       secret, None)
+               if not result:
+                       print ("Couldn't create keyring item!")


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