[rhythmbox/gobject-introspection: 23/34] port magnatune plugin to gi, possibly
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox/gobject-introspection: 23/34] port magnatune plugin to gi, possibly
- Date: Wed, 14 Jul 2010 05:58:00 +0000 (UTC)
commit 1704df4ab908625e6bcf56c0c419d5012167013b
Author: Jonathan Matthew <jonathan d14n org>
Date: Tue Jul 13 15:31:18 2010 +1000
port magnatune plugin to gi, possibly
plugins/magnatune/magnatune/MagnatuneSource.py | 77 +++++++++++------------
plugins/magnatune/magnatune/TrackListHandler.py | 18 +++---
plugins/magnatune/magnatune/__init__.py | 58 +++++++++---------
3 files changed, 76 insertions(+), 77 deletions(-)
---
diff --git a/plugins/magnatune/magnatune/MagnatuneSource.py b/plugins/magnatune/magnatune/MagnatuneSource.py
index 00dbbff..f6a3836 100644
--- a/plugins/magnatune/magnatune/MagnatuneSource.py
+++ b/plugins/magnatune/magnatune/MagnatuneSource.py
@@ -25,21 +25,21 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-import rb, rhythmdb
-from TrackListHandler import TrackListHandler
-from BuyAlbumHandler import BuyAlbumHandler, MagnatunePurchaseError
+import rb
import os
import gobject, gio
-import gtk
-import gnome, gconf
-import gnomekeyring as keyring
import xml
import urllib
import urlparse
import threading
import zipfile
+from gi.repository import RB, RhythmDB
+from gi.repository import Gtk, GConf, GnomeKeyring
+
+from TrackListHandler import TrackListHandler
+from BuyAlbumHandler import BuyAlbumHandler, MagnatunePurchaseError
magnatune_partner_id = "rhythmbox"
@@ -48,27 +48,27 @@ magnatune_song_info_uri = gio.File(uri="http://magnatune.com/info/song_info_xml.
magnatune_buy_album_uri = "https://magnatune.com/buy/choose?"
magnatune_api_download_uri = "http://%s:%s download magnatune com/buy/membership_free_dl_xml?"
-magnatune_in_progress_dir = gio.File(path=rb.user_data_dir()).resolve_relative_path('magnatune')
-magnatune_cache_dir = gio.File(path=rb.user_cache_dir()).resolve_relative_path('magnatune')
+magnatune_in_progress_dir = gio.File(path=RB.user_data_dir()).resolve_relative_path('magnatune')
+magnatune_cache_dir = gio.File(path=RB.user_cache_dir()).resolve_relative_path('magnatune')
magnatune_song_info = os.path.join(magnatune_cache_dir.get_path(), 'song_info.xml')
magnatune_song_info_temp = os.path.join(magnatune_cache_dir.get_path(), 'song_info.zip.tmp')
-class MagnatuneSource(rb.BrowserSource):
+class MagnatuneSource(RB.BrowserSource):
__gproperties__ = {
- 'plugin': (rb.Plugin, 'plugin', 'plugin', gobject.PARAM_WRITABLE|gobject.PARAM_CONSTRUCT_ONLY),
+ 'plugin': (RB.Plugin, 'plugin', 'plugin', gobject.PARAM_WRITABLE|gobject.PARAM_CONSTRUCT_ONLY),
}
- __client = gconf.client_get_default()
+ __client = GConf.Client.get_default()
def __init__(self):
- rb.BrowserSource.__init__(self, name=_("Magnatune"))
+ RB.BrowserSource.__init__(self, name=_("Magnatune"))
# source state
self.__activated = False
- self.__db = None # rhythmdb
+ self.__db = None
self.__notify_id = 0 # gobject.idle_add id for status notifications
self.__info_screen = None # the loading screen
@@ -146,7 +146,7 @@ class MagnatuneSource(rb.BrowserSource):
self.get_entry_view().set_sorting_type(self.__client.get_string("/apps/rhythmbox/plugins/magnatune/sorting"))
- rb.BrowserSource.do_impl_activate(self)
+ RB.BrowserSource.do_impl_activate(self)
def do_impl_get_browser_key(self):
return "/apps/rhythmbox/plugins/magnatune/show_browser"
@@ -158,7 +158,7 @@ class MagnatuneSource(rb.BrowserSource):
return False
def do_impl_pack_paned(self, paned):
- self.__paned_box = gtk.VBox(False, 5)
+ self.__paned_box = Gtk.VBox(homogeneous=False, spacing=5)
self.pack_start(self.__paned_box)
self.__paned_box.pack_start(paned)
@@ -182,7 +182,7 @@ class MagnatuneSource(rb.BrowserSource):
self.__client.set_string("/apps/rhythmbox/plugins/magnatune/sorting", self.get_entry_view().get_sorting_type())
- rb.BrowserSource.do_impl_delete_thyself(self)
+ RB.BrowserSource.do_impl_delete_thyself(self)
#
# methods for use by plugin and UI
@@ -194,10 +194,10 @@ class MagnatuneSource(rb.BrowserSource):
urls = set([])
for tr in tracks:
- sku = self.__sku_dict[self.__db.entry_get(tr, rhythmdb.PROP_LOCATION)]
+ sku = self.__sku_dict[self.__db.entry_get(tr, RhythmDB.PropType.LOCATION)]
url = self.__home_dict[sku]
if url not in urls:
- gtk.show_uri(screen, url, gtk.gdk.CURRENT_TIME)
+ Gtk.show_uri(screen, url, Gdk.CURRENT_TIME)
urls.add(url)
def purchase_redirect(self):
@@ -206,10 +206,10 @@ class MagnatuneSource(rb.BrowserSource):
urls = set([])
for tr in tracks:
- sku = self.__sku_dict[self.__db.entry_get(tr, rhythmdb.PROP_LOCATION)]
+ sku = self.__sku_dict[self.__db.entry_get(tr, RhythmDB.PropType.LOCATION)]
url = magnatune_buy_album_uri + urllib.urlencode({ 'sku': sku, 'ref': magnatune_partner_id })
if url not in urls:
- gtk.show_uri(screen, url, gtk.gdk.CURRENT_TIME)
+ Gtk.show_uri(screen, url, Gdk.CURRENT_TIME)
urls.add(url)
def download_album(self):
@@ -219,9 +219,9 @@ class MagnatuneSource(rb.BrowserSource):
return
try:
- library_location = self.__client.get_list("/apps/rhythmbox/library_locations", gconf.VALUE_STRING)[0] # Just use the first library location
+ library_location = self.__client.get_list("/apps/rhythmbox/library_locations", GConf.ValueType.STRING)[0] # Just use the first library location
except IndexError, e:
- rb.error_dialog(title = _("Couldn't purchase album"),
+ RB.error_dialog(title = _("Couldn't purchase album"),
message = _("You must have a library location set to purchase an album."))
return
@@ -229,7 +229,7 @@ class MagnatuneSource(rb.BrowserSource):
skus = []
for track in tracks:
- sku = self.__sku_dict[self.__db.entry_get(track, rhythmdb.PROP_LOCATION)]
+ sku = self.__sku_dict[self.__db.entry_get(track, RhythmDB.PropType.LOCATION)]
if sku in skus:
continue
skus.append(sku)
@@ -272,7 +272,7 @@ class MagnatuneSource(rb.BrowserSource):
catalog = open(magnatune_song_info, 'w')
filename = find_song_info(catalog_zip)
if filename is None:
- rb.error_dialog(title=_("Unable to load catalog"),
+ RB.error_dialog(title=_("Unable to load catalog"),
message=_("Rhythmbox could not understand the Magnatune catalog, please file a bug."))
return
catalog.write(catalog_zip.read(filename))
@@ -310,7 +310,7 @@ class MagnatuneSource(rb.BrowserSource):
if account_type == 'none':
pass
elif result is not None or len(items) == 0:
- rb.error_dialog(title = _("Couldn't get account details"),
+ RB.error_dialog(title = _("Couldn't get account details"),
message = str(result))
return
else:
@@ -371,7 +371,7 @@ class MagnatuneSource(rb.BrowserSource):
self.__notify_status_changed()
load_size = {'size': 0}
- keyring.find_items(keyring.ITEM_GENERIC_SECRET, {'rhythmbox-plugin': 'magnatune'}, got_items)
+ keyring.find_items(GnomeKeyring.ItemType.GENERIC_SECRET, {'rhythmbox-plugin': 'magnatune'}, got_items)
self.__catalogue_check = rb.UpdateCheck()
@@ -381,7 +381,7 @@ class MagnatuneSource(rb.BrowserSource):
def __show_loading_screen(self, show):
if self.__info_screen is None:
# load the builder stuff
- builder = gtk.Builder()
+ builder = Gtk.Builder()
builder.add_from_file(self.__plugin.find_file("magnatune-loading.ui"))
self.__info_screen = builder.get_object("magnatune_loading_scrolledwindow")
self.pack_start(self.__info_screen)
@@ -407,7 +407,7 @@ class MagnatuneSource(rb.BrowserSource):
def __auth_download(self, sku): # http://magnatune.com/info/api
def got_items(result, items):
if result is not None or len(items) == 0:
- rb.error_dialog(title = _("Couldn't get account details"),
+ RB.error_dialog(title = _("Couldn't get account details"),
message = str(result))
return
@@ -456,14 +456,14 @@ class MagnatuneSource(rb.BrowserSource):
self.__download_album(gio.File(audio_dl_uri), sku)
except MagnatunePurchaseError, e:
- rb.error_dialog(title = _("Download Error"),
+ RB.error_dialog(title = _("Download Error"),
message = _("An error occurred while trying to authorize the download.\nThe Magnatune server returned:\n%s") % str(e))
except Exception, e:
- rb.error_dialog(title = _("Error"),
+ RB.error_dialog(title = _("Error"),
message = _("An error occurred while trying to download the album.\nThe error text is:\n%s") % str(e))
- keyring.find_items(keyring.ITEM_GENERIC_SECRET, {'rhythmbox-plugin': 'magnatune'}, got_items)
+ keyring.find_items(GnomeKeyring.ItemType.GENERIC_SECRET, {'rhythmbox-plugin': 'magnatune'}, got_items)
def __download_album(self, audio_dl_uri, sku):
def download_progress(current, total):
@@ -490,22 +490,22 @@ class MagnatuneSource(rb.BrowserSource):
manager = shell.get_player().get_property('ui-manager')
manager.get_action("/MagnatuneSourceViewPopup/MagnatuneCancelDownload").set_sensitive(False)
if success:
- width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR)
- icon = rb.try_load_icon(gtk.icon_theme_get_default(), "magnatune", width, 0)
+ width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR)
+ icon = RB.try_load_icon(Gtk.IconTheme.get_default(), "magnatune", width, 0)
shell.notify_custom(4000, _("Finished Downloading"), _("All Magnatune downloads have been completed."), icon, True)
self.__notify_status_changed()
def unzip_album():
# just use the first library location
- library_location = gio.File(uri=self.__client.get_list("/apps/rhythmbox/library_locations", gconf.VALUE_STRING)[0])
+ library_location = gio.File(uri=self.__client.get_list("/apps/rhythmbox/library_locations", GConf.ValueType.STRING)[0])
album = zipfile.ZipFile(dest.get_path())
for track in album.namelist():
track_uri = library_location.resolve_relative_path(track).get_uri()
- track_uri = rb.sanitize_uri_for_filesystem(track_uri)
- rb.uri_create_parent_dirs(track_uri)
+ track_uri = RB.sanitize_uri_for_filesystem(track_uri)
+ RB.uri_create_parent_dirs(track_uri)
track_out = gio.File(uri=track_uri).create()
if track_out is not None:
@@ -566,7 +566,7 @@ class MagnatuneSource(rb.BrowserSource):
gobject.idle_add(self.emit_cover_art_uri, entry)
def emit_cover_art_uri(self, entry):
- sku = self.__sku_dict[self.__db.entry_get(entry, rhythmdb.PROP_LOCATION)]
+ sku = self.__sku_dict[self.__db.entry_get(entry, RhythmDB.PropType.LOCATION)]
url = self.__art_dict[sku]
self.__db.emit_entry_extra_metadata_notify(entry, 'rb:coverArt-uri', url)
return False
@@ -582,7 +582,7 @@ class MagnatuneSource(rb.BrowserSource):
os.mkdir(magnatune_cache_path, 0700)
# move song info to cache dir
- old_magnatune_dir = os.path.join(rb.dot_dir(), 'magnatune')
+ old_magnatune_dir = os.path.join(RB.dot_dir(), 'magnatune')
if os.path.exists(old_magnatune_dir) is False:
print "old magnatune directory does not exist"
return
@@ -603,4 +603,3 @@ class MagnatuneSource(rb.BrowserSource):
gobject.type_register(MagnatuneSource)
-
diff --git a/plugins/magnatune/magnatune/TrackListHandler.py b/plugins/magnatune/magnatune/TrackListHandler.py
index afb2b1f..b4f78a4 100644
--- a/plugins/magnatune/magnatune/TrackListHandler.py
+++ b/plugins/magnatune/magnatune/TrackListHandler.py
@@ -25,11 +25,11 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-import rhythmdb
-import gnomekeyring as keyring
import xml.sax, xml.sax.handler
import datetime, re, urllib
+from gi.repository import RhythmDB
+
class TrackListHandler(xml.sax.handler.ContentHandler):
def __init__(self, db, entry_type, sku_dict, home_dict, art_dict, account_type, username, password):
xml.sax.handler.ContentHandler.__init__(self)
@@ -88,13 +88,13 @@ class TrackListHandler(xml.sax.handler.ContentHandler):
except ValueError:
duration = 0
- self.__db.set(entry, rhythmdb.PROP_ARTIST, self.__track['artist'])
- self.__db.set(entry, rhythmdb.PROP_ALBUM, self.__track['albumname'])
- self.__db.set(entry, rhythmdb.PROP_TITLE, self.__track['trackname'])
- self.__db.set(entry, rhythmdb.PROP_TRACK_NUMBER, tracknum)
- self.__db.set(entry, rhythmdb.PROP_DATE, date)
- self.__db.set(entry, rhythmdb.PROP_GENRE, self.__track['magnatunegenres'])
- self.__db.set(entry, rhythmdb.PROP_DURATION, duration)
+ self.__db.set(entry, RhythmDB.PropType.ARTIST, self.__track['artist'])
+ self.__db.set(entry, RhythmDB.PropType.ALBUM, self.__track['albumname'])
+ self.__db.set(entry, RhythmDB.PropType.TITLE, self.__track['trackname'])
+ self.__db.set(entry, RhythmDB.PropType.TRACK_NUMBER, tracknum)
+ self.__db.set(entry, RhythmDB.PropType.DATE, date)
+ self.__db.set(entry, RhythmDB.PropType.GENRE, self.__track['magnatunegenres'])
+ self.__db.set(entry, RhythmDB.PropType.DURATION, duration)
key = str(trackurl)
sku = intern(str(self.__track['albumsku']))
diff --git a/plugins/magnatune/magnatune/__init__.py b/plugins/magnatune/magnatune/__init__.py
index bb9e47f..4c72769 100644
--- a/plugins/magnatune/magnatune/__init__.py
+++ b/plugins/magnatune/magnatune/__init__.py
@@ -25,11 +25,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-import rhythmdb, rb
+import rb
import gobject
-import gtk
-import gconf, gnome
-import gnomekeyring as keyring
import urllib
import zipfile
@@ -38,6 +35,9 @@ import xml
import datetime
import string
+from gi.repository import RhythmDB
+from gi.repository import GConf, GnomeKeyring, Gtk
+
from MagnatuneSource import MagnatuneSource
popup_ui = """
@@ -58,7 +58,7 @@ popup_ui = """
"""
class Magnatune(rb.Plugin):
- client = gconf.client_get_default()
+ client = GConf.Client.get_default()
format_list = ['ogg', 'flac', 'wav', 'mp3-vbr', 'mp3-cbr']
@@ -76,7 +76,7 @@ class Magnatune(rb.Plugin):
#
def __init__(self):
- rb.Plugin.__init__(self)
+ RB.Plugin.__init__(self)
def activate(self, shell):
self.shell = shell # so the source can update the progress bar
@@ -87,13 +87,13 @@ class Magnatune(rb.Plugin):
self.entry_type.can_sync_metadata = True
self.entry_type.sync_metadata = None
- theme = gtk.icon_theme_get_default()
+ theme = Gtk.IconTheme.get_default()
rb.append_plugin_source_path(theme, "/icons")
- width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR)
+ width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR)
icon = rb.try_load_icon(theme, "magnatune", width, 0)
- group = rb.rb_source_group_get_by_name("stores")
+ group = RB.rb_source_group_get_by_name("stores")
self.source = gobject.new(MagnatuneSource,
shell=shell,
entry_type=self.entry_type,
@@ -106,21 +106,21 @@ class Magnatune(rb.Plugin):
manager = shell.get_player().get_property('ui-manager')
# Add the popup menu actions
- self.action_group = gtk.ActionGroup('MagnatunePluginActions')
+ self.action_group = Gtk.ActionGroup(name='MagnatunePluginActions')
- action = gtk.Action('MagnatuneDownloadAlbum', _('Download Album'),
- _("Download this album from Magnatune"),
- 'gtk-save')
+ action = Gtk.Action(name='MagnatuneDownloadAlbum', label=_('Download Album'),
+ tooltip=_("Download this album from Magnatune"),
+ stock='gtk-save')
action.connect('activate', lambda a: self.shell.get_property("selected-source").download_album())
self.action_group.add_action(action)
- action = gtk.Action('MagnatuneArtistInfo', _('Artist Information'),
- _("Get information about this artist"),
- 'gtk-info')
+ action = Gtk.Action(name='MagnatuneArtistInfo', label=_('Artist Information'),
+ tooltip=_("Get information about this artist"),
+ stock='gtk-info')
action.connect('activate', lambda a: self.shell.get_property("selected-source").display_artist_info())
self.action_group.add_action(action)
- action = gtk.Action('MagnatuneCancelDownload', _('Cancel Downloads'),
- _("Stop downloading purchased albums"),
- 'gtk-stop')
+ action = Gtk.Action(name='MagnatuneCancelDownload', label=_('Cancel Downloads'),
+ tooltip=_("Stop downloading purchased albums"),
+ stock='gtk-stop')
action.connect('activate', lambda a: self.shell.get_property("selected-source").cancel_downloads())
action.set_sensitive(False)
self.action_group.add_action(action)
@@ -161,7 +161,7 @@ class Magnatune(rb.Plugin):
def created_item(result, id):
if result is None: # Item successfully created
keyring_data['id'] = id
- keyring.item_get_info(None, id, got_item)
+ GnomeKeyring.item_get_info(None, id, got_item)
else:
print "Couldn't create keyring item: " + str(result)
fill_account_details()
@@ -177,10 +177,10 @@ class Magnatune(rb.Plugin):
if result is None and len(items) != 0: # Got list of search results
keyring_data['id'] = items[0].item_id
- keyring.item_get_info(None, keyring_data['id'], got_item)
+ GnomeKeyring.item_get_info(None, keyring_data['id'], got_item)
elif result == keyring.NoMatchError or len(items) == 0: # No items were found, so we'll create one
- keyring.item_create(None,
- keyring.ITEM_GENERIC_SECRET,
+ GnomeKeyring.item_create(None,
+ GnomeKeyring.ItemType.GENERIC_SECRET,
"Rhythmbox: Magnatune account information",
{'rhythmbox-plugin': 'magnatune'},
"", # Empty secret for now
@@ -245,13 +245,13 @@ class Magnatune(rb.Plugin):
def close_button_pressed(x, y):
try:
if keyring_data['id'] and keyring_data['item']:
- # The async version is not in the python bindings, grr...
- keyring.item_set_info_sync(None, keyring_data['id'], keyring_data['item'])
+ # FIXME try to use item_set_info (async)
+ GnomeKeyring.item_set_info_sync(None, keyring_data['id'], keyring_data['item'])
else:
- rb.error_dialog(title = _("Couldn't store account information"),
+ RB.error_dialog(title = _("Couldn't store account information"),
message = _("There was a problem accessing the keyring. Check the debug output for more information."))
except Exception, e:
- rb.error_dialog(title = _("Couldn't store account information"),
+ RB.error_dialog(title = _("Couldn't store account information"),
message = str(e))
dialog.hide()
@@ -264,7 +264,7 @@ class Magnatune(rb.Plugin):
"rb_magnatune_password_changed_cb" : account_details_changed
}
- builder = gtk.Builder()
+ builder = Gtk.Builder()
builder.add_from_file(self.find_file("magnatune-prefs.ui"))
# FIXME this bit should be in builder too (what?)
@@ -279,5 +279,5 @@ class Magnatune(rb.Plugin):
builder.connect_signals(self.configure_callback_dic)
dialog.connect("response", close_button_pressed)
- keyring.find_items(keyring.ITEM_GENERIC_SECRET, {'rhythmbox-plugin': 'magnatune'}, got_items)
+ GnomeKeyring.find_items(GnomeKeyring.ItemType.GENERIC_SECRET, {'rhythmbox-plugin': 'magnatune'}, got_items)
return dialog
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]