[rhythmbox] Port jamendo plugin to GI



commit 13fa861cece9cb5138743077fcc623d3bb589c24
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sun Feb 6 19:39:31 2011 +1000

    Port jamendo plugin to GI

 plugins/jamendo/jamendo/JamendoConfigureDialog.py |    9 ++--
 plugins/jamendo/jamendo/JamendoSaxHandler.py      |   26 ++++++----
 plugins/jamendo/jamendo/JamendoSource.py          |   58 ++++++++++----------
 plugins/jamendo/jamendo/__init__.py               |   40 ++++++++------
 4 files changed, 72 insertions(+), 61 deletions(-)
---
diff --git a/plugins/jamendo/jamendo/JamendoConfigureDialog.py b/plugins/jamendo/jamendo/JamendoConfigureDialog.py
index b6d160e..7bdb536 100644
--- a/plugins/jamendo/jamendo/JamendoConfigureDialog.py
+++ b/plugins/jamendo/jamendo/JamendoConfigureDialog.py
@@ -19,8 +19,9 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 import gobject
-import gtk
-import gconf, gnome
+
+import rb
+from gi.repository import Gtk, GConf
 
 gconf_keys = {	'format' : '/apps/rhythmbox/plugins/jamendo/format',
 		'sorting': '/apps/rhythmbox/plugins/jamendo/sorting'
@@ -29,9 +30,9 @@ format_list = ['ogg3', 'mp32']
 
 class JamendoConfigureDialog (object):
 	def __init__(self, builder_file):
-		self.gconf = gconf.client_get_default()
+		self.gconf = GConf.Client.get_default()
 
-		builder = gtk.Builder()
+		builder = Gtk.Builder()
 		builder.add_from_file(builder_file)
 
 		self.dialog = builder.get_object('preferences_dialog')
diff --git a/plugins/jamendo/jamendo/JamendoSaxHandler.py b/plugins/jamendo/jamendo/JamendoSaxHandler.py
index 5818965..307ceca 100644
--- a/plugins/jamendo/jamendo/JamendoSaxHandler.py
+++ b/plugins/jamendo/jamendo/JamendoSaxHandler.py
@@ -18,9 +18,12 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-import rhythmdb
 import xml.sax, xml.sax.handler
 import datetime
+import codecs
+
+import rb
+from gi.repository import RB
 
 data = {"artist" : ["name"],
         "album" : ["name","id","releasedate","id3genre"],
@@ -28,6 +31,9 @@ data = {"artist" : ["name"],
         
 stream_url = "http://api.jamendo.com/get2/stream/track/redirect/?id=%s&streamencoding=mp31";
 
+def utf8ise(s):
+	return codecs.utf_8_encode(s)[0]
+
 class JamendoSaxHandler(xml.sax.handler.ContentHandler):
 	def __init__(self,db,entry_type):
 		xml.sax.handler.ContentHandler.__init__(self)
@@ -73,18 +79,18 @@ class JamendoSaxHandler(xml.sax.handler.ContentHandler):
 			
 			entry = self.__db.entry_lookup_by_location (track_url)
 			if entry == None:
-				entry = self.__db.entry_new(self.__entry_type, track_url)
-			self.__db.set(entry, rhythmdb.PROP_ARTIST, self.__data["artist"]["name"])
-			self.__db.set(entry, rhythmdb.PROP_ALBUM, self.__data["album"]["name"])
-			self.__db.set(entry, rhythmdb.PROP_TITLE, self.__data["track"]["name"])
-			self.__db.set(entry, rhythmdb.PROP_TRACK_NUMBER, int(self.__data["track"]["numalbum"]))
-			self.__db.set(entry, rhythmdb.PROP_DATE, date)
-			self.__db.set(entry, rhythmdb.PROP_GENRE, albumgenre)
-			self.__db.set(entry, rhythmdb.PROP_DURATION, duration)
+				entry = RB.RhythmDBEntry.new(self.__db, self.__entry_type, track_url)
+			self.__db.entry_set(entry, RB.RhythmDBPropType.ARTIST, utf8ise(self.__data["artist"]["name"]))
+			self.__db.entry_set(entry, RB.RhythmDBPropType.ALBUM, utf8ise(self.__data["album"]["name"]))
+			self.__db.entry_set(entry, RB.RhythmDBPropType.TITLE, utf8ise(self.__data["track"]["name"]))
+			self.__db.entry_set(entry, RB.RhythmDBPropType.TRACK_NUMBER, int(self.__data["track"]["numalbum"]))
+			self.__db.entry_set(entry, RB.RhythmDBPropType.DATE, date)
+			self.__db.entry_set(entry, RB.RhythmDBPropType.GENRE, albumgenre)
+			self.__db.entry_set(entry, RB.RhythmDBPropType.DURATION, duration)
 
 			# slight misuse, but this is far more efficient than having a python dict
 			# containing this data.
-			self.__db.set(entry, rhythmdb.PROP_MUSICBRAINZ_ALBUMID, self.__data["album"]["id"])
+			self.__db.entry_set(entry, RB.RhythmDBPropType.MB_ALBUMID, utf8ise(self.__data["album"]["id"]))
 			
 			if self.__num_tracks % 1000 == 0:
 				self.__db.commit()
diff --git a/plugins/jamendo/jamendo/JamendoSource.py b/plugins/jamendo/jamendo/JamendoSource.py
index 9481962..3139374 100644
--- a/plugins/jamendo/jamendo/JamendoSource.py
+++ b/plugins/jamendo/jamendo/JamendoSource.py
@@ -21,18 +21,19 @@
 # Parts from "Magnatune Rhythmbox plugin" (stolen from rhythmbox's MagnatuneSource.py)
 #     Copyright (C), 2006 Adam Zimmerman <adam_zimmerman sfu ca>
 
-import rb, rhythmdb
-from JamendoSaxHandler import JamendoSaxHandler
-import JamendoConfigureDialog
-
 import os
 import gobject
-import gtk
-import gnome, gconf
 import xml
 import gzip
 import datetime
 
+import rb
+from gi.repository import Gtk, Gdk, GConf
+from gi.repository import RB
+
+from JamendoSaxHandler import JamendoSaxHandler
+import JamendoConfigureDialog
+
 # URIs
 
 jamendo_song_info_uri = "http://img.jamendo.com/data/dbdump_artistalbumtrack.xml.gz";
@@ -52,14 +53,14 @@ ogg3_uri = "http://api.jamendo.com/get2/bittorrent/file/plain/?type=archive&clas
 artwork_url = "http://api.jamendo.com/get2/image/album/redirect/?id=%s&imagesize=200";
 artist_url = "http://www.jamendo.com/get/artist/id/album/page/plain/";
 
-class JamendoSource(rb.BrowserSource):
+class JamendoSource(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),
 	}
 
 	def __init__(self):
 
-		rb.BrowserSource.__init__(self, name=_("Jamendo"))
+		RB.BrowserSource.__init__(self, name=_("Jamendo"))
 
 		# catalogue stuff
 		self.__db = None
@@ -76,7 +77,7 @@ class JamendoSource(rb.BrowserSource):
 		self.__catalogue_loader = None
 		self.__catalogue_check = None
 
-		self.__jamendo_dir = rb.find_user_cache_file("jamendo")
+		self.__jamendo_dir = RB.find_user_cache_file("jamendo")
 		if os.path.exists(self.__jamendo_dir) is False:
 			os.makedirs(self.__jamendo_dir, 0700)
 
@@ -99,9 +100,9 @@ class JamendoSource(rb.BrowserSource):
 		return False
 
 	def do_impl_pack_paned (self, paned):
-		self.__paned_box = gtk.VBox(False, 5)
-		self.pack_start(self.__paned_box)
-		self.__paned_box.pack_start(paned)
+		self.__paned_box = Gtk.VBox(homogeneous=False, spacing=5)
+		self.pack_start(self.__paned_box, True, True, 0)
+		self.__paned_box.pack_start(paned, True, True, 0)
 
 	#
 	# RBSource methods
@@ -114,7 +115,7 @@ class JamendoSource(rb.BrowserSource):
 		return ["JamendoDownloadAlbum","JamendoDonateArtist"]
 
 
-	def do_get_status(self):
+	def do_get_status(self, status, progress_text, progress):
 		if self.__updating:
 			if self.__load_total_size > 0:
 				progress = min (float(self.__load_current_size) / self.__load_total_size, 1.0)
@@ -138,7 +139,7 @@ class JamendoSource(rb.BrowserSource):
 			self.__update_id = gobject.timeout_add_seconds(6 * 60 * 60, self.__update_catalogue)
 			self.__update_catalogue()
 
-			sort_key = gconf.client_get_default().get_string(JamendoConfigureDialog.gconf_keys['sorting'])
+			sort_key = GConf.Client.get_default().get_string(JamendoConfigureDialog.gconf_keys['sorting'])
 			if not sort_key:
 				sort_key = "Artist,ascending"
 			self.get_entry_view().set_sorting_type(sort_key)
@@ -161,7 +162,7 @@ class JamendoSource(rb.BrowserSource):
 			self.__catalogue_check.cancel()
 			self.__catalogue_check = None
 
-		gconf.client_get_default().set_string(JamendoConfigureDialog.gconf_keys['sorting'], self.get_entry_view().get_sorting_type())
+		GConf.Client.get_default().set_string(JamendoConfigureDialog.gconf_keys['sorting'], self.get_entry_view().get_sorting_type())
 
 
 	#
@@ -256,11 +257,11 @@ class JamendoSource(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("jamendo-loading.ui"))
 
 			self.__info_screen = builder.get_object("jamendo_loading_scrolledwindow")
-			self.pack_start(self.__info_screen)
+			self.pack_start(self.__info_screen, True, True, 0)
 			self.get_entry_view().set_no_show_all (True)
 			self.__info_screen.set_no_show_all (True)
 
@@ -281,7 +282,7 @@ class JamendoSource(rb.BrowserSource):
 	# Download album
 	def download_album (self):
 		tracks = self.get_entry_view().get_selected_entries()
-		format = gconf.client_get_default().get_string(JamendoConfigureDialog.gconf_keys['format'])
+		format = GConf.Client.get_default().get_string(JamendoConfigureDialog.gconf_keys['format'])
 		if not format or format not in JamendoConfigureDialog.format_list:
 			format = 'ogg3'
 
@@ -289,7 +290,7 @@ class JamendoSource(rb.BrowserSource):
 		#without any track selected
 		if len(tracks) == 1:
 			track = tracks[0]
-			albumid = self.__db.entry_get(track, rhythmdb.PROP_MUSICBRAINZ_ALBUMID)
+			albumid = track.get_string(RB.RhythmDBPropType.MB_ALBUMID)
 
 			formats = {}
 			formats["mp32"] = mp32_uri + albumid
@@ -302,10 +303,10 @@ class JamendoSource(rb.BrowserSource):
 	def __download_p2plink (self, result, albumid):
 		if result is None:
 			emsg = _("Error looking up p2plink for album %s on jamendo.com") % (albumid)
-			gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, emsg).run()
+			Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, emsg).run()
 			return
 
-		gtk.show_uri(self.props.shell.props.window.get_screen(), result, gtk.gdk.CURRENT_TIME)
+		Gtk.show_uri(self.props.shell.props.window.get_screen(), result, Gdk.CURRENT_TIME)
 
 	# Donate to Artist
 	def launch_donate (self):
@@ -316,8 +317,8 @@ class JamendoSource(rb.BrowserSource):
 		if len(tracks) == 1:
 			track = tracks[0]
 			# The Album ID can be used to lookup the artist, and issue a clean redirect.
-			albumid = self.__db.entry_get(track, rhythmdb.PROP_MUSICBRAINZ_ALBUMID)
-			artist = self.__db.entry_get(track, rhythmdb.PROP_ARTIST)
+			albumid = track.get_string(RB.RhythmDBPropType.MB_ALBUMID)
+			artist = track.get_string(RB.RhythmDBPropType.ARTIST)
 			url = artist_url + albumid.__str__() + "/"
 
 			l = rb.Loader()
@@ -326,9 +327,9 @@ class JamendoSource(rb.BrowserSource):
 	def __open_donate (self, result, artist):
 		if result is None:
 			emsg = _("Error looking up artist %s on jamendo.com") % (artist)
-			gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, emsg).run()
+			Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, emsg).run()
 			return
-		gtk.show_uri(self.props.shell.props.window.get_screen(), result + "donate/", gtk.gdk.CURRENT_TIME)
+		Gtk.show_uri(self.props.shell.props.window.get_screen(), result + "donate/", Gdk.CURRENT_TIME)
 
 	def playing_entry_changed (self, entry):
 		if not self.__db or not entry:
@@ -340,12 +341,11 @@ class JamendoSource(rb.BrowserSource):
 		gobject.idle_add(self.emit_cover_art_uri, entry)
 
 	def emit_cover_art_uri (self, entry):
-		stream = self.__db.entry_get (entry, rhythmdb.PROP_LOCATION)
-		albumid = self.__db.entry_get (entry, rhythmdb.PROP_MUSICBRAINZ_ALBUMID)
+		stream = self.__db.entry_get_string (entry, RB.RhythmDBPropType.LOCATION)
+		albumid = self.__db.entry_get_string (entry, RB.RhythmDBPropType.MB_ALBUMID)
 		url = artwork_url % albumid
 
 		self.__db.emit_entry_extra_metadata_notify (entry, "rb:coverArt-uri", str(url))
 		return False
 
 gobject.type_register(JamendoSource)
-
diff --git a/plugins/jamendo/jamendo/__init__.py b/plugins/jamendo/jamendo/__init__.py
index ca590c8..318392d 100644
--- a/plugins/jamendo/jamendo/__init__.py
+++ b/plugins/jamendo/jamendo/__init__.py
@@ -29,13 +29,15 @@
 # Parts from "Magnatune Rhythmbox plugin" (stolen from rhythmbox's __init__.py)
 #     Copyright (C), 2006 Adam Zimmerman <adam_zimmerman sfu ca>
 
-import rhythmdb, rb
 import gobject
-import gtk
 
 from JamendoSource import JamendoSource
 from JamendoConfigureDialog import JamendoConfigureDialog
 
+import rb
+from gi.repository import Gtk
+from gi.repository import RB
+
 popup_ui = """
 <ui>
   <popup name="JamendoSourceViewPopup">
@@ -52,20 +54,23 @@ popup_ui = """
 </ui>
 """
 
-class JamendoEntryType(rhythmdb.EntryType):
+class JamendoEntryType(RB.RhythmDBEntryType):
 	def __init__(self):
-		rhythmdb.EntryType.__init__(self, name='jamendo')
+		RB.RhythmDBEntryType.__init__(self, name="jamendo")
 
-	def can_sync_metadata(self, entry):
+	def do_can_sync_metadata(self, entry):
 		return True
 
-class Jamendo(rb.Plugin):
+	def do_sync_metadata(self, entry, changes):
+		return
+
+class Jamendo(RB.Plugin):
 	#
 	# Core methods
 	#
 
 	def __init__(self):
-		rb.Plugin.__init__(self)
+		RB.Plugin.__init__(self)
 
 	def activate(self, shell):
 		self.db = shell.get_property("db")
@@ -73,13 +78,13 @@ class Jamendo(rb.Plugin):
 		self.entry_type = JamendoEntryType()
 		self.db.register_entry_type(self.entry_type)
 
-		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)
+		what, width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR)
 		icon = rb.try_load_icon(theme, "jamendo", width, 0)
 
-		group = rb.rb_display_page_group_get_by_id ("stores")
+		group = RB.DisplayPageGroup.get_by_id ("stores")
 		self.source = gobject.new (JamendoSource,
 					   shell=shell,
 					   entry_type=self.entry_type,
@@ -90,17 +95,17 @@ class Jamendo(rb.Plugin):
 
 		# Add button
 		manager = shell.get_player().get_property('ui-manager')
-		action = gtk.Action('JamendoDownloadAlbum', _('_Download Album'),
-				_("Download this album using BitTorrent"),
-				'gtk-save')
+		action = Gtk.Action(name='JamendoDownloadAlbum', label=_('_Download Album'),
+				tooltip=_("Download this album using BitTorrent"),
+				stock_id='gtk-save')
 		action.connect('activate', lambda a: shell.get_property("selected-page").download_album())
-		self.action_group = gtk.ActionGroup('JamendoPluginActions')
+		self.action_group = Gtk.ActionGroup('JamendoPluginActions')
 		self.action_group.add_action(action)
 		
 		# Add Button for Donate
-		action = gtk.Action('JamendoDonateArtist', _('_Donate to Artist'),
-				_("Donate Money to this Artist"),
-				'gtk-jump-to')
+		action = Gtk.Action(name='JamendoDonateArtist', label=_('_Donate to Artist'),
+				tooltip=_("Donate Money to this Artist"),
+				stock_id='gtk-jump-to')
 		action.connect('activate', lambda a: shell.get_property("selected-page").launch_donate())
 		self.action_group.add_action(action)
 
@@ -135,4 +140,3 @@ class Jamendo(rb.Plugin):
 
 	def playing_entry_changed (self, sp, entry):
 		self.source.playing_entry_changed (entry)
-



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