Commits

Damián Nohales committed 6d8686b

Use of a method to dinamically get the current playing row item.

This fix an issue when user drag and drop rows in the playlist and the current playing row position changes,
the "playing" attribute will no longer valid.

  • Participants
  • Parent commits 70db332

Comments (0)

Files changed (1)

                 self.check_for_update(None)
         self.window.show_all()
         self.hide_download_list()
-        
+    
+    def get_playing_iter(self):
+        iter = self.playlist.get_iter_first()
+        while iter != None:
+            if self.playlist[iter][4] > 400:
+                return iter
+            iter = self.playlist.iter_next(iter)
+            
+        return None
+    
+    def get_iter_last(self, model):
+        """
+        Get the last iter from a model
+        """
+        rows = model.iter_n_children(None);
+        return model.get_iter([rows-1]);
+    
     def result_song(self, index):
         return self.result[index][4]
     
         """
         othertext = _("To update to the latest version ")
         othertext += _("you can visit the <a href=\"http://https://bitbucket.org/vkolev/gsharkdown/downloads\"> ")
-        othertext += _("download site</a>. If you are using the latest version and whant to be")
+        othertext += _("download site</a>. If you are using the latest version and want to be ")
         othertext += _("informed about new versions, just enable the option in the <b>Preferences</b> dialog.")
         markup = _("<b>New version <span fgcolor=\"red\"><i>%s</i></span> is available</b>")
         nmarkup = _("<b>You are using the latest version!</b>")
         if select[1] != None:
             next = self.playlist.iter_next(select[1])
             self.playlist.remove(select[1])
-            if self.playlist.get_path(select[1])[0] == self.playing:
+            if select[1] == self.get_playing_iter():
                 self.stop_play()
             if next != None:
                 self.play_view.get_selection().select_iter(next)
         """
         Plays the next item from the playlist
         """
-        if self.playing == None:
+        if self.get_playing_iter() == None:
             self.play_by_index(0)
         else:
-            index = self.playing + 1
+            index = self.playlist.get_path(self.get_playing_iter())[0] + 1
             if int(CONFIG['shuffle_playlist']) == 1:
-                index = random.randint(0, len(self.playlist))
+                index = random.randint(0, len(self.playlist)-1)
 
             if index >= len(self.playlist):
                 if int(CONFIG['repeat_playlist']) == 1:
         """
         Plays the previous song from the playlist
         """
-        if self.playing == None:
+        if self.get_playing_iter() == None:
             self.play_by_index(0)
         else:
-            index = self.playing - 1
+            index = self.playlist.get_path(self.get_playing_iter())[0] - 1
             if int(CONFIG['shuffle_playlist']) == 1:
-                index = random.randint(0, len(self.playlist))
+                index = random.randint(0, len(self.playlist)-1)
 
             if index < 0:
                 if int(CONFIG['repeat_playlist']) == 1:
 
         if index >= len(self.playlist):
             index = len(self.playlist)-1
-
-        if index != self.playing:
+        
+        iter = self.playlist.get_iter((index,))
+        
+        if iter != self.get_playing_iter():
             self.scrobbled = 0
-            self.playing = index
             for item in self.playlist:
                 item[4] = 400
-            self.playlist[index][4] = 600
+            self.playlist[iter][4] = 600
+            self.play_button.set_stock_id(gtk.STOCK_MEDIA_STOP)
             self.player.set_state(gst.STATE_NULL)
             song = self.playlist_song(index)
             self.set_songinfos(song)
             item[4] = 400
         self.player.set_state(gst.STATE_NULL)
         self.play_button.set_stock_id(gtk.STOCK_MEDIA_PLAY)
-        self.playing = None
         self.set_songinfos()
 
     def on_volume_change(self, widget, data=0.5):
         """
         Starts the play thread
         """
-        if self.playing == None:
+        if self.get_playing_iter() == None:
             if self.playlist.iter_n_children(None) > 0:
                 self.play_by_index(0)
         else:
         Updates some labels and icons when a song is playing
         """
         if song != None:
-            if self.playing == None:
-                self.playing = 0
-            treerow = self.playlist.iter_nth_child(None, self.playing)
-            self.selector.select_iter(treerow)
+            playing = self.get_playing_iter()
+            if playing == None:
+                playing = self.playlist.get_iter_first()
+            self.selector.select_iter(playing)
             self.current_song = song
             self.staticon.set_from_file(
                 "%s/data/gsharkdown_16_playing.png" % BASEPATH