Commits

Damián Nohales committed b9aede7

Check on the downloads list if a download will be overwrited additionally to check the disk.

Comments (0)

Files changed (4)

data/overwrite_dialog.ui

           <object class="GtkLabel" id="label">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="label" translatable="yes">The file '%s' already exists, maybe you are downloading a file that you downloaded before.
+            <property name="label" translatable="yes">The file '%s' already exists, maybe you are downloading a file that you downloaded before or you are currently downloading the same song.
 
 What do you want to do?</property>
             <property name="wrap">True</property>

lib/DownloadList.py

 import gobject
 import gtk
 import os
+import traceback
     
 class DownloadList(AbstractSongList):
     """
         return gtk.ListStore(object, str, str, int, str, str)
     
     def __append_song_to_model(self, song):
-        # Change song local ID to fix the search by song
-        # song = Song(song.get_data())
-        # The above line cause problems, I don't know why :( .
+        song = song.clone()
         
         if self.find_song(song) != None:
             raise Exception()
     def on_search_text_changed(self, widget, data = None):
         t = GroovesharkInitThread()
         t.start()
-
+    
+    def query_download_exists(self, filename):
+        # Check on downloaded files
+        if os.path.exists(filename) == True:
+            return True
+        
+        # Check on the downloads list
+        for i in self.downloads.range():
+            if filename == self.downloads.get_song(i).get_filename():
+                return True
+            
+        return False
+    
     def get_overwritten_filename(self, filename, use_response = None):
         """
         Gets the file name depending on whether user want to overwrite the file,
         not overwrite it or not save it. Returns the same filename if user want
         to overwrite, the renamed filename or None if the user cancel Download.
         """
-        if os.path.exists(filename) == True:
+        if self.query_download_exists(filename) == True:
             if use_response == None:
                 builder = gtk.Builder()
                 builder.set_translation_domain(env().APP)
             self.download_thread.pause()
             self.download_thread.join()
             
-    def cancel_download_sync(self):
-        """
-        Cancel the current download and wait until it stops altogether.
-        """
-        if self.is_downloading():
-            self.download_thread.cancel()
-            self.download_thread.join()
-            
     def get_download_progress(self):
         """
         Returns the current download progress in bytes or None if