Some fixes to the download manager.

Mon, 11 Oct 2010 11:05:38 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 11 Oct 2010 11:05:38 +0200
changeset 670
bb833c4bcf28
parent 669
d405dc3e2ed6
child 671
cc0471f53e74

Some fixes to the download manager.

Helpviewer/Download/DownloadItem.py file | annotate | diff | comparison | revisions
Helpviewer/Download/DownloadItem.ui file | annotate | diff | comparison | revisions
--- a/Helpviewer/Download/DownloadItem.py	Mon Oct 11 09:36:44 2010 +0200
+++ b/Helpviewer/Download/DownloadItem.py	Mon Oct 11 11:05:38 2010 +0200
@@ -10,7 +10,7 @@
 from PyQt4.QtCore import pyqtSlot, pyqtSignal, Qt, QTime, QFile, QFileInfo, QUrl, \
     QIODevice
 from PyQt4.QtGui import QWidget, QPalette, QStyle, QDesktopServices, QFileDialog
-from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest, QNetworkReply
+from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply
 
 from E5Gui import E5MessageBox
 
@@ -69,6 +69,7 @@
         self.__bytesReceived = 0
         self.__downloadTime = QTime()
         self.__output = QFile()
+        self.__fileName = ""
         self.__startedSaving = False
         self.__finishedDownloading = False
         self.__gettingFileName = False
@@ -95,6 +96,9 @@
         self.openButton.setEnabled(False)
         self.openButton.setVisible(False)
         
+        # start timer for the download estimation
+        self.__downloadTime.start()
+        
         # attach to the reply object
         self.__url = self.__reply.url()
         self.__reply.setParent(self)
@@ -109,9 +113,6 @@
         self.progressBar.setValue(0)
         self.__getFileName()
         
-        # start timer for the download estimation
-        self.__downloadTime.start()
-        
         if self.__reply.error() != QNetworkReply.NoError:
             self.__networkError()
             self.__finished()
@@ -128,8 +129,14 @@
         downloadDirectory = Helpviewer.HelpWindow.HelpWindow\
             .downloadManager().downloadDirectory()
         
-        defaultFileName = self.__saveFileName(downloadDirectory)
-        fileName = defaultFileName
+        if self.__fileName:
+            fileName = self.__fileName
+            self.__toDownload = True
+            ask = False
+        else:
+            defaultFileName = self.__saveFileName(downloadDirectory)
+            fileName = defaultFileName
+            ask = True
         self.__autoOpen = False
         if not self.__toDownload:
             res = E5MessageBox.question(self,
@@ -153,7 +160,7 @@
             fileName = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + \
                         '/' + QFileInfo(fileName).completeBaseName()
         
-        if not self.__autoOpen and self.__requestFilename:
+        if ask and not self.__autoOpen and self.__requestFilename:
             self.__gettingFileName = True
             fileName = QFileDialog.getSaveFileName(
                 None,
@@ -169,15 +176,17 @@
                     .format(QFileInfo(defaultFileName).fileName()))
                 self.__canceledFileSelect = True
                 return
-            fileInfo = QFileInfo(fileName)
-            Helpviewer.HelpWindow.HelpWindow.downloadManager().setDownloadDirectory(
-                fileInfo.absoluteDir().absolutePath())
-            self.filenameLabel.setText(fileInfo.fileName())
+        
+        fileInfo = QFileInfo(fileName)
+        Helpviewer.HelpWindow.HelpWindow.downloadManager().setDownloadDirectory(
+            fileInfo.absoluteDir().absolutePath())
+        self.filenameLabel.setText(fileInfo.fileName())
         
         self.__output.setFileName(fileName)
+        self.__fileName = fileName
         
         # check file path for saving
-        saveDirPath = QFileInfo(self.__output.fileName()).dir()
+        saveDirPath = QFileInfo(self.__fileName).dir()
         if not saveDirPath.exists():
             if not saveDirPath.mkpath(saveDirPath.absolutePath()):
                 self.progressBar.setVisible(False)
@@ -187,7 +196,7 @@
                     .format(saveDirPath.absolutePath()))
                 return
         
-        self.filenameLabel.setText(QFileInfo(self.__output.fileName()).fileName())
+        self.filenameLabel.setText(QFileInfo(self.__fileName).fileName())
         if self.__requestFilename:
             self.__readyRead()
     
@@ -252,6 +261,7 @@
         reply = nam.get(QNetworkRequest(self.__url))
         if self.__output.exists():
             self.__output.remove()
+        self.__output = QFile()
         self.__reply = reply
         self.__initialize(tryAgain = True)
         self.statusChanged.emit()
@@ -449,8 +459,6 @@
         """
         Private slot to handle the download finished.
         """
-        self.__readyRead()
-        
         self.__finishedDownloading = True
         if not self.__startedSaving:
             return
@@ -483,7 +491,6 @@
         
         @param icon reference to the icon to be set (QIcon)
         """
-        # TODO: adjust the size
         self.fileIcon.setPixmap(icon.pixmap(48, 48))
     
     def fileName(self):
@@ -492,7 +499,7 @@
         
         @return name of the output file (string)
         """
-        return self.__output.fileName()
+        return self.__fileName
     
     def absoluteFilePath(self):
         """
@@ -500,7 +507,7 @@
         
         @return absolute path of the output file (string)
         """
-        return QFileInfo(self.__output).absoluteFilePath()
+        return QFileInfo(self.__fileName).absoluteFilePath()
     
     def getData(self):
         """
@@ -509,7 +516,7 @@
         @return tuple of URL, save location and done flag
             (QUrl, string, boolean)
         """
-        return (self.__url, QFileInfo(self.__output).filePath(), 
+        return (self.__url, QFileInfo(self.__fileName).filePath(), 
                 self.downloadedSuccessfully())
     
     def setData(self, data):
@@ -520,9 +527,10 @@
             (QUrl, string, boolean)
         """
         self.__url = data[0]
-        self.__output.setFileName(data[1])
+        self.__fileName = data[1]
         
-        self.filenameLabel.setText(QFileInfo(self.__output.fileName()).fileName())
+        self.filenameLabel.setText(QFileInfo(self.__fileName).fileName())
+        self.infoLabel.setText(self.__fileName)
         
         self.stopButton.setEnabled(False)
         self.stopButton.setVisible(False)
--- a/Helpviewer/Download/DownloadItem.ui	Mon Oct 11 09:36:44 2010 +0200
+++ b/Helpviewer/Download/DownloadItem.ui	Mon Oct 11 11:05:38 2010 +0200
@@ -28,9 +28,18 @@
     <layout class="QVBoxLayout" name="verticalLayout">
      <item>
       <widget class="QLabel" name="filenameLabel">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
        <property name="text">
         <string>Filename</string>
        </property>
+       <property name="alignment">
+        <set>Qt::AlignCenter</set>
+       </property>
       </widget>
      </item>
      <item>
@@ -38,9 +47,21 @@
      </item>
      <item>
       <widget class="QLabel" name="infoLabel">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
        <property name="text">
         <string>Info</string>
        </property>
+       <property name="alignment">
+        <set>Qt::AlignCenter</set>
+       </property>
+       <property name="wordWrap">
+        <bool>true</bool>
+       </property>
       </widget>
      </item>
     </layout>

eric ide

mercurial