Improve notifications.
authorstephendenham <stephendenham@2dec19e3-eb1d-4749-8193-008c8bba0994>
Tue, 14 Dec 2010 16:51:39 +0000 (16:51 +0000)
committerstephendenham <stephendenham@2dec19e3-eb1d-4749-8193-008c8bba0994>
Tue, 14 Dec 2010 16:51:39 +0000 (16:51 +0000)
git-svn-id: svn://svn.code.sf.net/p/xbmc-groove/code@13 2dec19e3-eb1d-4749-8193-008c8bba0994

default.py

index 6688267..20c9173 100644 (file)
@@ -24,6 +24,8 @@ resDir = xbmc.translatePath(os.path.join(baseDir, 'resources'))
 libDir = xbmc.translatePath(os.path.join(resDir,  'lib'))
 imgDir = xbmc.translatePath(os.path.join(resDir,  'img'))
 thumbDir = os.path.join('special://masterprofile/addon_data/', os.path.join(os.path.basename(os.getcwd()), 'thumb'))
+playlistUrl = 'plugin://plugin.audio.groove/?mode=6'
+thumbDef = os.path.join(os.path.basename(os.getcwd()), 'default.tbn')
 
 sys.path.append (libDir)
 from GrooveAPI import *
@@ -161,6 +163,7 @@ class Groveshark:
         if (userid != 0):
             xbmc.log("Favorite song: " + str(songid))
             groovesharkApi.favoriteSong(songID = songid)
+            xbmc.executebuiltin('XBMC.Notification(Grooveshark, Added to favorites, 1000, ' + thumbDef + ')')
         else:
             dialog = xbmcgui.Dialog()
             dialog.ok('Grooveshark', 'You must be logged in', 'to add favorites.')
@@ -170,6 +173,7 @@ class Groveshark:
         if (userid != 0):
             xbmc.log("Unfavorite song: " + str(songid))
             groovesharkApi.unfavoriteSong(songID = songid)
+            xbmc.executebuiltin('XBMC.Notification(Grooveshark, Removed from favorites, 1000, ' + thumbDef + ')')
         else:
             dialog = xbmcgui.Dialog()
             dialog.ok('Grooveshark', 'You must be logged in', 'to remove favorites.')
@@ -180,6 +184,8 @@ class Groveshark:
             xbmc.log("Frown song: " + str(songid))
             if groovesharkApi.radioFrown(songId = songid) != True:
                 xbmc.log("Unable to frown song " + str(songid))
+            else:
+                xbmc.executebuiltin('XBMC.Notification(Grooveshark, Frowned, 1000, ' + thumbDef + ')')
         else:
             dialog = xbmcgui.Dialog()
             dialog.ok('Grooveshark', 'You must be logged in', 'to frown a song.')
@@ -196,17 +202,20 @@ class Groveshark:
     def makePlaylist(self, albumid, name):
         userid = self._get_login()
         if (userid != 0):
-            name_re = re.compile(r'[- ]')
-            nameTokens = name_re.split("- ")
-            name = self._get_keyboard(default=nameTokens[1], heading="Playlist name")
-            album = groovesharkApi.albumGetSongs(albumid, self.songsearchlimit)
-            songids = []
-            for song in album:
-                songids.append(song[1])
-            id = groovesharkApi.playlistCreateUnique(name, songids)
-            if id == 0:
-                dialog = xbmcgui.Dialog()
-                dialog.ok('Grooveshark', 'Cannot create playlist ', name)
+            re.split(' - ',name,1)
+            nameTokens = re.split(' - ',name,1)
+            name = self._get_keyboard(default=nameTokens[0], heading="Playlist name")
+            if name != '':
+                album = groovesharkApi.albumGetSongs(albumid, self.songsearchlimit)
+                songids = []
+                for song in album:
+                    songids.append(song[1])
+                id = groovesharkApi.playlistCreateUnique(name, songids)
+                if id == 0:
+                    dialog = xbmcgui.Dialog()
+                    dialog.ok('Grooveshark', 'Cannot create playlist ', name)
+                else:
+                    xbmc.executebuiltin('XBMC.Notification(Grooveshark, Playlist created, 1000, ' + thumbDef + ')')
         else:
             dialog = xbmcgui.Dialog()
             dialog.ok('Grooveshark', 'You must be logged in ', ' to create a playlist.')
@@ -217,7 +226,7 @@ class Groveshark:
             userid = self._get_login()
             if (userid != 0):
                 groovesharkApi.playlistDelete(playlistid)
-                xbmc.executebuiltin("Container.Refresh")
+                xbmc.executebuiltin("Container.Update(" + playlistUrl + ",replace)")
             else:
                 dialog = xbmcgui.Dialog()
                 dialog.ok('Grooveshark', 'You must be logged in ', ' to delete a playlist.')
@@ -226,7 +235,9 @@ class Groveshark:
         userid = self._get_login()
         if (userid != 0):
             newname = self._get_keyboard(default=name, heading="Playlist name")
-            if groovesharkApi.playlistRename(playlistid, newname) == 0:
+            if newname == '':
+                return
+            elif groovesharkApi.playlistRename(playlistid, newname) == 0:
                 dialog = xbmcgui.Dialog()
                 dialog.ok('Grooveshark', 'Cannot rename playlist ', name)
             else:
@@ -277,11 +288,11 @@ class Groveshark:
         return item
     
     def _get_keyboard(self, default="", heading="", hidden=False):
-            kb = xbmc.Keyboard(default, heading, hidden)
-            kb.doModal()
-            if (kb.isConfirmed()):
-                return unicode(kb.getText(), "utf-8")
-            return ''
+        kb = xbmc.Keyboard(default, heading, hidden)
+        kb.doModal()
+        if (kb.isConfirmed()):
+            return unicode(kb.getText(), "utf-8")
+        return ''
     
     def _get_login(self):
         if (self.username == "" or self.password == ""):