gget r30 - trunk/gget



Author: johans
Date: Sat Jul 12 00:35:58 2008
New Revision: 30
URL: http://svn.gnome.org/viewvc/gget?rev=30&view=rev

Log:
Dont verify/connect to downloads which has been completed in previous sessions.

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

Modified: trunk/gget/Download.py
==============================================================================
--- trunk/gget/Download.py	(original)
+++ trunk/gget/Download.py	Sat Jul 12 00:35:58 2008
@@ -68,6 +68,7 @@
         self.file = os.path.join(path, self.file_name)
 
         self.total_size = 0
+        self.old_total_size = 0
         self.block_count = 0
         self.block_size = 0
         self.percent_complete = 0
@@ -88,6 +89,7 @@
                     total_size))
         self.block_count = block_count
         self.block_size = block_size
+        self.old_total_size = self.total_size
         self.total_size = total_size
 
         current_bytes = float(block_count * block_size) / 1024 / 1024

Modified: trunk/gget/DownloadList.py
==============================================================================
--- trunk/gget/DownloadList.py	(original)
+++ trunk/gget/DownloadList.py	Sat Jul 12 00:35:58 2008
@@ -24,9 +24,9 @@
 
 import gobject
 
+import Download
 import Utils
 from Configuration import Configuration
-from Download import Download
 
 XML_HEADER = '<?xml version="1.0" encoding="UTF-8" ?>\n'
 DOWNLOADS_FILE = "downloads.xml"
@@ -62,9 +62,16 @@
             for download_element in list(downloads_element):
                 uri = download_element.findtext("uri")
                 path = download_element.findtext("path")
+                file_name = download_element.findtext("filename")
+                total_size = download_element.findtext("size")
                 status = download_element.findtext("status")
-                download = Download(uri, path)
-                download.status = status
+
+                download = Download.Download(uri, path)
+                download.file_name = file_name
+                download.total_size = int(total_size)
+                download.status = int(status)
+                if download.status == Download.COMPLETED:
+                    download.percent_complete = 100
                 self.__append_download(download)
 
     def __create_xml(self):
@@ -78,11 +85,14 @@
         if path is None:
             path = self.config.default_folder
 
-        download = Download(uri, path)
+        download = Download.Download(uri, path)
         self.__append_download(download)
         self.__add_download_to_xml(download)
 
     def __append_download(self, download):
+        """Connects to the download signals we are interested in before adding
+        the download object to the list of downloads."""
+        download.connect("update", self.__download_update)
         download.connect("status-changed", self.__download_status_changed)
         self.downloads.append(download)
         Utils.debug_print("Appended download %s to list of downloads." %
@@ -97,26 +107,44 @@
         uri_element.text = download.uri
         path_element = ET.SubElement(download_element, "path")
         path_element.text = download.path
-        # filename_element = ET.SubElement(download_element, "filename")
-        # filename_element.text = download.file_name
-        # size_element = ET.SubElement(download_element, "size")
-        # size_element.text = download.total_size
+        filename_element = ET.SubElement(download_element, "filename")
+        filename_element.text = download.file_name
+        size_element = ET.SubElement(download_element, "size")
+        size_element.text = download.total_size
         status_element = ET.SubElement(download_element, "status")
         status_element.text = str(download.status)
         self.__save_xml()
 
+    def __download_update(self, download, block_count, block_size,
+            total_size):
+        """If the total file size has changed (not likely happen) the download
+        element associated is found and the size updated."""
+        if download.old_total_size != total_size:
+            download_element = self.__get_download_element(download)
+            if download_element:
+                size_element = download_element.find("size")
+                size_element.text = str(total_size)
+                self.__save_xml()
+
     def __download_status_changed(self, download, status):
-        """Finds the download element which status changed and update
-        the xml tree."""
+        """Finds the download element which status was changed and updates the
+        xml tree."""
+        download_element = self.__get_download_element(download)
+        if download_element:
+            status_element = download_element.find("status")
+            status_element.text = str(status)
+            self.__save_xml()
+
+    def __get_download_element(self, download):
+        """Returns the download element in the xml tree associated with the
+        download object passed. If its not found None is returned."""
         downloads_element = self.tree.getroot()
         for download_element in list(downloads_element):
             uri = download_element.findtext("uri")
             path = download_element.findtext("path")
             if download.uri == uri and download.path == path:
-                status_element = download_element.find("status")
-                status_element.text = str(status)
-                break
-        self.__save_xml()
+                return download_element
+        return None
 
     def __save_xml(self):
         """Adds a header and indents the xml tree before saving it to disk."""

Modified: trunk/gget/DownloadManager.py
==============================================================================
--- trunk/gget/DownloadManager.py	(original)
+++ trunk/gget/DownloadManager.py	Sat Jul 12 00:35:58 2008
@@ -73,7 +73,8 @@
                 metalink.HTTP_PROXY = "http://%s:%s"; % (self.config.proxy_host, self.config.proxy_port)
 
     def download_added(self, download_list, download):
-        self.start_download(download)
+        if not download.status == Download.COMPLETED:
+            self.start_download(download)
 
     def start_download(self, download):
         Utils.debug_print("Starting download %s" % download)

Modified: trunk/gget/PreferencesDialog.py
==============================================================================
--- trunk/gget/PreferencesDialog.py	(original)
+++ trunk/gget/PreferencesDialog.py	Sat Jul 12 00:35:58 2008
@@ -46,6 +46,7 @@
         # Set widget states from configuration
         self.status_icon_checkbutton.set_active(self.config.show_status_icon)
         self.main_window_checkbutton.set_active(self.config.show_main_window)
+        self.notifications_checkbutton.set_active(self.config.show_notifications)
         self.autostart_checkbutton.set_active(self.config.autostart)
         self.autoresume_checkbutton.set_active(self.config.autoresume)
 



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