1
# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
3
# Copyright (C) 2012 Jonathan Matthew <jonathan@d14n.org>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2, or (at your option)
10
# The Rhythmbox authors hereby grant permission for non-GPL compatible
11
# GStreamer plugins to be used and distributed together with GStreamer
12
# and Rhythmbox. This permission is above and beyond the permissions granted
13
# by the GPL license by which Rhythmbox is covered. If you modify this code
14
# you may extend this exception to your version of the code, but you are not
15
# obligated to do so. If you do not wish to do so, delete this exception
16
# statement from your version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program; if not, write to the Free Software
25
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27
from gi.repository import Gio, GnomeKeyring
33
if __instance is None:
34
__instance = MagnatuneAccount()
37
class MagnatuneAccount(object):
39
self.keyring_item = None
40
self.settings = Gio.Settings("org.gnome.rhythmbox.plugins.magnatune")
42
self.keyring_attributes = GnomeKeyring.attribute_list_new()
43
GnomeKeyring.attribute_list_append_string(self.keyring_attributes,
46
(result, items) = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET,
47
self.keyring_attributes)
48
if result == GnomeKeyring.Result.OK and len(items) != 0:
49
(result, item) = GnomeKeyring.item_get_info_sync(None, items[0].item_id)
50
if result == GnomeKeyring.Result.OK:
51
self.keyring_item = item
53
print "Couldn't get keyring item: " + GnomeKeyring.result_to_message(result)
55
print "couldn't search keyring items: " + GnomeKeyring.result_to_message(result)
58
if self.keyring_item is None:
59
return ('none', None, None)
61
account_type = self.settings['account-type']
63
(username, password) = self.keyring_item.get_secret().split("\n")
64
return (account_type, username, password)
66
return ('none', None, None)
68
def update(self, username, password):
69
secret = '\n'.join((username, password))
70
if self.keyring_item is not None:
71
if secret == self.keyring_item.get_secret():
72
print "account details not changed"
75
(result, id) = GnomeKeyring.item_create_sync(None,
76
GnomeKeyring.ItemType.GENERIC_SECRET,
77
"Rhythmbox: Magnatune account information",
78
self.keyring_attributes,
81
if result == GnomeKeyring.Result.OK:
82
if self.keyring_item is None:
83
(result, item) = GnomeKeyring.item_get_info_sync(None, id)
84
if result == GnomeKeyring.Result.OK:
85
self.keyring_item = item
87
print "couldn't fetch keyring itme: " + GnomeKeyring.result_to_message(result)
89
print "couldn't create keyring item: " + GnomeKeyring.result_to_message(result)