conduit r1834 - in trunk: . conduit/modules/BansheeModule scripts



Author: jstowers
Date: Fri Jan 23 10:17:49 2009
New Revision: 1834
URL: http://svn.gnome.org/viewvc/conduit?rev=1834&view=rev

Log:
2009-01-23  John Stowers  <john stowers gmail com>

	* scripts/update-3rdparty-libs.sh: Add updater for pyrtm

	* conduit/modules/BansheeModule/BansheeModule.py:
	Support Banshee 1.0. Fixes #549177 (Andrew Stormont)



Modified:
   trunk/ChangeLog
   trunk/conduit/modules/BansheeModule/BansheeModule.py
   trunk/scripts/update-3rdparty-libs.sh

Modified: trunk/conduit/modules/BansheeModule/BansheeModule.py
==============================================================================
--- trunk/conduit/modules/BansheeModule/BansheeModule.py	(original)
+++ trunk/conduit/modules/BansheeModule/BansheeModule.py	Fri Jan 23 10:17:49 2009
@@ -1,3 +1,9 @@
+# Banshee-1 support added by Andrew Stormont <andyjstormont googlemail com>
+# I've tried to keep compatability for Banshee < 1, it should work fine.
+# Saved playlists should also be remebered, this all needs testing though.
+
+# FIXME: This doesn't handle folders and never did, should it?
+
 import os
 import gobject
 import logging
@@ -19,14 +25,26 @@
 from gettext import gettext as _
 
 if Utils.program_installed("banshee"):
+    BANSHEE_INSTALLED = True
+    BANSHEE_VERSION_1 = False
+    BANSHEE_BASE_LOCATION = ""
+elif Utils.program_installed("banshee-1"):
+    BANSHEE_INSTALLED = True
+    BANSHEE_VERSION_1 = True
+    import gconf
+    BANSHEE_BASE_LOCATION = "file://%s/" % gconf.Client().get_string( "/apps/banshee-1/library/base_location" )
+else:
+    BANSHEE_INSTALLED = False
+
+if BANSHEE_INSTALLED:
     MODULES = {
     	"BansheeSource" : { "type": "dataprovider" }
     }
 else:
     MODULES = {}
 
-ID_IDX = 0
-NAME_IDX = 1
+(ID_IDX, NAME_IDX, CHECKED_IDX, TYPE_IDX) = range( 4 )
+(SMART_PLAYLIST, NORMAL_PLAYLIST, VIDEO_PLAYLIST) = range( 1, 4 ) # FIXME should these be hard coded?
 
 class BansheeSource(DataProvider.DataSource):
 
@@ -39,16 +57,24 @@
     _icon_ = "media-player-banshee"
     _configurable_ = True
 
-    MUSIC_DB = os.path.join(os.path.expanduser("~"),".config", "banshee", "banshee.db")
+    if BANSHEE_VERSION_1:
+        MUSIC_DB = os.path.join(os.path.expanduser("~"),".config", "banshee-1", "banshee.db")
+    else:
+        MUSIC_DB = os.path.join(os.path.expanduser("~"),".config", "banshee", "banshee.db")
 
     def __init__(self, *args):
         DataProvider.DataSource.__init__(self)
         #Names of the playlists we know
         self.allPlaylists = []
-        #Names we wish to sync
+        #Playlist Ids we wish to sync
         self.playlists = []
+        self.smart_playlists = []
+        self.video_playlists = []
         self.tracks = []
 
+    def _get_full_uri(self, uri):
+        if not uri.startswith("file://"):
+            return BANSHEE_BASE_LOCATION + uri
 
     def _get_all_playlists(self):
         allPlaylists = []
@@ -57,18 +83,45 @@
             con = sqlite.connect(BansheeSource.MUSIC_DB)
             cur = con.cursor()
             #Get a list of all playlists for the config dialog
-            cur.execute("SELECT PlaylistID, Name FROM Playlists")
-            for playlistid, playlistname in cur:
-                allPlaylists.append( (playlistid,playlistname) )
+            #If we don't convert all the id's to strings Settings.py will spazz
+            if BANSHEE_VERSION_1:
+                cur.execute("SELECT PlaylistID, Name FROM CorePlaylists where PrimarySourceID NOT NULL") # NULL = "Play Queue"
+                for playlistid, playlistname in cur:
+                    allPlaylists.append( {
+                        "id"   : str( playlistid ),
+                        "name" : playlistname,
+                        "type" : NORMAL_PLAYLIST
+                    } )
+                cur.execute("SELECT SmartPlaylistID, Name FROM CoreSmartPlaylists where PrimarySourceID=%s" % SMART_PLAYLIST)
+                for playlistid, playlistname in cur:
+                    allPlaylists.append( {
+                        "id"   : str( playlistid ),
+                        "name" : playlistname,
+                        "type" : SMART_PLAYLIST
+                    } )
+                cur.execute("SELECT SmartPlaylistID, Name FROM CoreSmartPlaylists where PrimarySourceID=%s" % VIDEO_PLAYLIST)
+                for playlistid, playlistname in cur:
+                    allPlaylists.append( {
+                        "id"   : str( playlistid ),
+                        "name" : playlistname,
+                        "type" : VIDEO_PLAYLIST
+                    } )
+            else:
+                cur.execute("SELECT PlaylistID, Name FROM Playlists")
+                for playlistid, playlistname in cur:
+                    allPlaylists.append( { 
+                        "id"   : str( playlistid ), 
+                        "name" : playlistname,
+                        "type" : NORMAL_PLAYLIST 
+                    } )
             con.close()
-
         return allPlaylists
 
     def initialize(self):
         return True
 
     def is_configured(self, isSource, isTwoWay):
-        return len(self.playlists) > 0
+        return len(self.playlists+self.smart_playlists+self.video_playlists) > 0
         
     def refresh(self):
         DataProvider.DataSource.refresh(self)
@@ -83,10 +136,17 @@
         cur = con.cursor()
 
         for playlistid in self.playlists:
-            cur.execute("select Uri from Tracks INNER JOIN PlaylistEntries ON PlaylistEntries.TrackID=Tracks.TrackID where PlaylistID=%s" % (playlistid))
+            if BANSHEE_VERSION_1:
+                cur.execute("select Uri from CoreTracks INNER JOIN CorePlaylistEntries ON CorePlaylistEntries.TrackID=CoreTracks.TrackID where PlaylistID=%s" % (playlistid))
+            else:
+                cur.execute("select Uri from Tracks INNER JOIN PlaylistEntries ON PlaylistEntries.TrackID=Tracks.TrackID where PlaylistID=%s" % (playlistid))
             for Uri in cur:
-                self.tracks.append(Uri[0])
+                self.tracks.append( self._get_full_uri( Uri[0] ) )
 
+        for playlistid in self.smart_playlists + self.video_playlists:
+            cur.execute("select Uri from CoreTracks INNER JOIN CoreSmartPlaylistEntries ON CoreSmartPlaylistEntries.TrackID where PlaylistID=%s" % (playlistid))
+            for Uri in cur:
+                self.tracks.append( self._get_full_uri( Uri[0] ) )
         con.close()
 
     def get_all(self):
@@ -97,48 +157,64 @@
         f = Audio.Audio(URI=LUID)
         f.set_UID(LUID)
         f.set_open_URI(LUID)
-
         return f
-    
-    def finish(self, aborted, error, conflict):
-        DataProvider.DataSource.finish(self)
-        self.playlists = []
 
     def configure(self, window):
         import gtk
         def col1_toggled_cb(cell, path, model ):
             #not because we get this cb before change state
             checked = not cell.get_active()
-            model[path][2] = checked
-            val = model[path][ID_IDX]
-            if checked and val not in self.playlists:
-                self.playlists.append(val)
-            elif not checked and val in self.playlists:
-                self.playlists.remove(val)
-
-            log.debug("Toggle '%s'(%s) to: %s" % (model[path][NAME_IDX], val, checked))
+            model[path][CHECKED_IDX] = checked
+            ( Name, Id, Type ) = ( model[path][NAME_IDX], model[path][ID_IDX], model[path][TYPE_IDX] )
+            if Type == NORMAL_PLAYLIST:
+                if checked and Name not in self.playlists:
+                    self.playlists.append(Id)
+                elif not checked and Name in self.playlists:
+                    self.playlists.remove(Id)
+            elif Type == SMART_PLAYLIST:
+                if checked and Name not in self.smart_playlists:
+                    self.smart_playlists.append(Id)
+                elif not checked and Name in self.smart_playlists:
+                    self.smart_playlists.remove(Id)
+            elif Type == VIDEO_PLAYLIST:
+                if checked and Name not in self.video_playlists:
+                    self.video_playlists.append(Id)
+                elif not checked and Name in self.video_playlists:
+                    self.video_playlists.remove(Id)
+            log.debug("Toggle name: '%s', type: '%s', id: '%s' to: %s" % (Name, Type, Id, checked))
             return
 
         tree = Utils.dataprovider_glade_get_widget(
                         __file__, 
                         "config.glade",
-						"BansheeConfigDialog"
-						)
+                        "BansheeConfigDialog"
+        )
         tagtreeview = tree.get_widget("tagtreeview")
         #Build a list of all the tags
-        list_store = gtk.ListStore( gobject.TYPE_INT,       #ID_IDX
-                                    gobject.TYPE_STRING,    #NAME_IDX
-                                    gobject.TYPE_BOOLEAN,   #active
+        list_store = gtk.ListStore( gobject.TYPE_STRING,    #ID_IDX      - 0
+                                    gobject.TYPE_STRING,    #NAME_IDX    - 1
+                                    gobject.TYPE_BOOLEAN,   #CHECKED_IDX - 2
+                                    gobject.TYPE_INT,       #TYPE_IDX    - 3
                                     )
         #Fill the list store
-        i = 0
-        for t in self._get_all_playlists():
-            list_store.append((t[ID_IDX],t[NAME_IDX],t[ID_IDX] in self.playlists))
-            i += 1
+        for playlist in self._get_all_playlists():
+            if playlist["type"] == NORMAL_PLAYLIST and playlist["id"] in self.playlists:
+                checked = True
+            elif playlist["type"] == SMART_PLAYLIST and playlist["id"] in self.smart_playlists:
+                checked = True
+            elif playlist["type"] == VIDEO_PLAYLIST and playlist["id"] in self.video_playlists:
+                checked = True
+            else:
+                checked = False
+            # Make video playlists more obvious
+            if playlist["type"] == VIDEO_PLAYLIST:
+                playlist["name"] += " (Video)"
+            list_store.append( ( playlist["id"], playlist["name"], checked, playlist["type"] ) )
+                     
         #Set up the treeview
         tagtreeview.set_model(list_store)
         #column 1 is the tag name
-        tagtreeview.append_column(  gtk.TreeViewColumn(_("Tag Name"), 
+        tagtreeview.append_column(  gtk.TreeViewColumn(_("Playlist Name"), # Tag name is confusing?
                                     gtk.CellRendererText(), 
                                     text=NAME_IDX)
                                     )
@@ -148,7 +224,7 @@
         renderer1.connect( 'toggled', col1_toggled_cb, list_store )
         tagtreeview.append_column(  gtk.TreeViewColumn(_("Enabled"), 
                                     renderer1, 
-                                    active=2)
+                                    active=CHECKED_IDX)
                                     )
 
         dlg = tree.get_widget("BansheeConfigDialog")
@@ -158,11 +234,20 @@
 
     def set_configuration(self, config):
         self.playlists = []
-        for playlist in config.get("playlists", []):
-            self.playlists.append(playlist)
+        self.smart_playlists = []
+        self.video_playlist = []
+        for playlistid in config.get("playlists", []):
+            self.playlists.append( playlistid )
+        for playlistid in config.get("smart_playlists", []):
+            self.smart_playlists.append( playlistid )
+        for playlistid in config.get("video_playlists", []):
+            self.video_playlists.append( playlistid )
             
     def get_configuration(self):
-        return { "playlists" : self.playlists }
+        return { "playlists"       : self.playlists,
+                 "smart_playlists" : self.smart_playlists,
+                 "video_playlists" : self.video_playlists
+        }
 
     def get_UID(self):
         return Utils.get_user_string()

Modified: trunk/scripts/update-3rdparty-libs.sh
==============================================================================
--- trunk/scripts/update-3rdparty-libs.sh	(original)
+++ trunk/scripts/update-3rdparty-libs.sh	Fri Jan 23 10:17:49 2009
@@ -20,5 +20,7 @@
     wget -qO conduit/modules/BackpackModule/backpack/${i} http://github.com/dustin/py-backpack/tree/master%2F${i}?raw=true
 done
 
-
+#update pyrtm
+echo "Updating pyrtm"
+wget -qO conduit/modules/RTMModule/rtm.py "http://repo.or.cz/w/pyrtm.git?a=blob_plain;f=rtm.py;hb=HEAD
 



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