gget r50 - trunk/gget



Author: johans
Date: Mon Aug  4 20:47:54 2008
New Revision: 50
URL: http://svn.gnome.org/viewvc/gget?rev=50&view=rev

Log:
Fixed paused downloads between sessions.

Modified:
   trunk/gget/DetailsDialog.py
   trunk/gget/Download.py
   trunk/gget/DownloadList.py
   trunk/gget/DownloadManager.py

Modified: trunk/gget/DetailsDialog.py
==============================================================================
--- trunk/gget/DetailsDialog.py	(original)
+++ trunk/gget/DetailsDialog.py	Mon Aug  4 20:47:54 2008
@@ -22,6 +22,7 @@
 
 import gtk
 
+import Download
 import GUI
 import Utils
 from gget import NAME
@@ -30,6 +31,7 @@
     def __init__(self, download):
         self.download = download
         download.connect("update", self.__download_update)
+        download.connect("status-changed", self.__download_status_changed)
 
         self.__get_widgets()
         self.__connect_widgets()
@@ -49,8 +51,8 @@
             (Utils.get_readable_size(download.total_size),
                 download.total_size))
         self.mime_type_label.set_text(download.mime_type)
-        self.date_started_label.set_text(str(download.get_date_str("started")))
-        self.date_completed_label.set_text(str(download.get_date_str("completed")))
+        self.date_started_label.set_text(download.get_date_str("started"))
+        self.date_completed_label.set_text(download.get_date_str("completed"))
 
         self.dialog.show()
 
@@ -89,6 +91,10 @@
                 (Utils.get_readable_size(download.current_size),
                     download.current_size))
 
+    def __download_status_changed(self, download, status):
+        if status == Download.COMPLETED:
+            self.date_completed_label.set_text(download.get_date_str("completed"))
+
     def __close_button_clicked(self, button):
         self.dialog.destroy()
 

Modified: trunk/gget/Download.py
==============================================================================
--- trunk/gget/Download.py	(original)
+++ trunk/gget/Download.py	Mon Aug  4 20:47:54 2008
@@ -36,15 +36,17 @@
 from gget import NAME
 
 CONNECTING = 0
-DOWNLOADING = 1
-CANCELED = 2
-PAUSED = 3
-COMPLETED = 4
-ERROR = 5
+VERIFYING = 1
+DOWNLOADING = 2
+CANCELED = 3
+PAUSED = 4
+COMPLETED = 5
+ERROR = 6
 
 # Need this to be able to get an untranslated status message. Would be nice if
 # get_status_string could be used, but doesn't seem like gettext can do that.
 STATUS_STRINGS = {CONNECTING:  "Connecting",
+                  VERIFYING:   "Verifying",
                   DOWNLOADING: "Downloading",
                   CANCELED:    "Canceled",
                   PAUSED:      "Paused",
@@ -81,11 +83,6 @@
 
         self.has_started = False
 
-        self.canceled = False
-        self.paused = False
-
-        self.block_count = 0
-        self.block_size = 0
         self.current_size = self.__get_current_size()
         self.total_size = 0
         self.old_total_size = 0
@@ -142,12 +139,12 @@
     def is_canceled(self):
         """Callback which returns True to cancel the download, False
         otherwise."""
-        return self.canceled
+        return self.status == CANCELED
 
     def is_paused(self):
         """Callback which returns True to pause the download and False to
         continue/resume."""
-        return self.paused
+        return self.status == PAUSED
 
     def update(self, block_count, block_size, total_size):
         """Callback with count of blocks transferred so far, block size in
@@ -155,16 +152,19 @@
         Utils.debug_print("Download.update called with block_count: %s \
                 block_size: %s total_size: %s" % (block_count, block_size,
                     total_size))
-        self.block_count = block_count
-        self.block_size = block_size
-        self.current_size = block_count * block_size
+        current_size = block_count * block_size
+        if current_size > self.current_size:
+            self.current_size = current_size
+
         self.old_total_size = self.total_size
         self.total_size = total_size
 
         current_bytes = float(block_count * block_size) / 1024 / 1024
         total_bytes = float(total_size) / 1024 / 1024
         try:
-            self.percent_complete = 100 * current_bytes / total_bytes
+            percent_complete = 100 * current_bytes / total_bytes
+            if percent_complete > self.percent_complete:
+                self.percent_complete = percent_complete
         except ZeroDivisionError:
             self.percent_complete = 0
 
@@ -199,7 +199,6 @@
                self.status != ERROR):
                    return False
 
-        self.canceled = canceled
         if canceled:
             self.set_status(CANCELED)
         else:
@@ -225,7 +224,6 @@
             if not (self.status != CONNECTING or self.status != DOWNLOADING):
                 return False
 
-        self.paused = paused
         if paused:
             self.set_status(PAUSED)
         else:
@@ -244,6 +242,8 @@
     def get_status_string(self):
         if self.status == CONNECTING:
             return _("Connecting")
+        elif self.status == VERIFYING:
+            return _("Verifying")
         elif self.status == DOWNLOADING:
             return _("Downloading")
         elif self.status == CANCELED:

Modified: trunk/gget/DownloadList.py
==============================================================================
--- trunk/gget/DownloadList.py	(original)
+++ trunk/gget/DownloadList.py	Mon Aug  4 20:47:54 2008
@@ -77,6 +77,8 @@
                 download.status = int(status)
                 if download.status == Download.COMPLETED:
                     download.percent_complete = 100
+                else:
+                    download.percent_complete = 100 * download.current_size / download.total_size
                 self.__append_download(download)
 
     def __create_xml(self):
@@ -172,7 +174,7 @@
 
     def remove_download(self, download):
         """Removes a download object from the list and xml tree."""
-        # If the download is not canceled when removed, cancel it
+        # Make sure the download is stopped before its removed
         if not download.is_canceled():
             download.cancel()
         self.downloads.remove(download)

Modified: trunk/gget/DownloadManager.py
==============================================================================
--- trunk/gget/DownloadManager.py	(original)
+++ trunk/gget/DownloadManager.py	Mon Aug  4 20:47:54 2008
@@ -117,7 +117,8 @@
         # in a thread, see http://spyced.blogspot.com/2007/06/workaround-for-sysexcepthook-bug.html
         # sys.excepthook(*sys.exc_info())
 
-        download.set_status(Download.CONNECTING)
+        if download.status in [-1, Download.DOWNLOADING]:
+            download.set_status(Download.CONNECTING)
         try:
             result = metalink.get(download.uri, download.path,
                     handlers={"status": download.update,



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