src/eric7/WebBrowser/Download/DownloadItem.py

branch
eric7
changeset 9566
d4986df5d2e4
parent 9482
a2bc06a54d9d
child 9576
be9f8e7e42e0
diff -r ed264631ab1e -r d4986df5d2e4 src/eric7/WebBrowser/Download/DownloadItem.py
--- a/src/eric7/WebBrowser/Download/DownloadItem.py	Mon Dec 05 11:58:39 2022 +0100
+++ b/src/eric7/WebBrowser/Download/DownloadItem.py	Mon Dec 05 15:08:18 2022 +0100
@@ -246,13 +246,15 @@
         @type str
         """
         fpath = pathlib.Path(fileName)
-        WebBrowserWindow.downloadManager().setDownloadDirectory(fpath.parent.resolve())
+        WebBrowserWindow.downloadManager().setDownloadDirectory(
+            str(fpath.parent.resolve())
+        )
         self.filenameLabel.setText(fpath.name)
 
         self.__fileName = str(fpath)
 
         # check file path for saving
-        saveDirPath = pathlib.Path(self.__fileName).parent()
+        saveDirPath = pathlib.Path(self.__fileName).parent
         if not saveDirPath.exists():
             saveDirPath.mkdir(parents=True)
 
@@ -316,14 +318,14 @@
         """
         Public slot to open the downloaded file.
         """
-        url = QUrl.fromLocalFile(pathlib.Path(self.__fileName).resolve())
+        url = QUrl.fromLocalFile(str(pathlib.Path(self.__fileName).resolve()))
         QDesktopServices.openUrl(url)
 
     def openFolder(self):
         """
         Public slot to open the folder containing the downloaded file.
         """
-        url = QUrl.fromLocalFile(pathlib.Path(self.__fileName).resolve())
+        url = QUrl.fromLocalFile(str(pathlib.Path(self.__fileName).resolve().parent))
         QDesktopServices.openUrl(url)
 
     @pyqtSlot()
@@ -527,7 +529,7 @@
 
         @return absolute path of the output file (string)
         """
-        return pathlib.Path(self.__fileName).resolve()
+        return str(pathlib.Path(self.__fileName).resolve())
 
     def getData(self):
         """
@@ -561,8 +563,11 @@
         self.__fileName = data["Location"]
         self.__pageUrl = data["PageURL"]
 
-        self.filenameLabel.setText(pathlib.Path(self.__fileName).name)
-        self.infoLabel.setText(self.__fileName)
+        self.__state = (
+            DownloadState.Successful
+            if data["Done"]
+            else DownloadState.Cancelled
+        )
 
         try:
             self.__setDateTime(data["Downloaded"])
@@ -573,16 +578,33 @@
         self.pauseButton.setVisible(False)
         self.stopButton.setEnabled(False)
         self.stopButton.setVisible(False)
-        self.openButton.setEnabled(data["Done"])
-        self.openButton.setVisible(data["Done"])
-        if data["Done"]:
-            self.__state = DownloadState.Successful
-        else:
-            self.__state = DownloadState.Cancelled
         self.progressBar.setVisible(False)
 
+        self.updateButtonsAndLabels()
+
         self.__adjustSize()
 
+    @pyqtSlot()
+    def __setFileLabels(self):
+        """
+        Private slot to set and format the info label.
+        """
+        self.infoLabel.setText(self.__fileName)
+        if self.downloadedSuccessfully() and not os.path.exists(self.__fileName):
+            self.filenameLabel.setText(
+                self.tr("{0} - deleted").format(pathlib.Path(self.__fileName).name)
+            )
+            font = self.filenameLabel.font()
+            font.setItalic(True)
+            self.filenameLabel.setFont(font)
+
+            font = self.infoLabel.font()
+            font.setItalic(True)
+            font.setStrikeOut(True)
+            self.infoLabel.setFont(font)
+        else:
+            self.filenameLabel.setText(pathlib.Path(self.__fileName).name)
+
     def getInfoData(self):
         """
         Public method to get the text of the info label.
@@ -626,3 +648,21 @@
         else:
             self.datetimeLabel.clear()
             self.datetimeLabel.hide()
+
+    def exists(self):
+        """
+        Public method to check, if the downloaded file exists.
+
+        @return flag indicating the existence of the downloaded file
+        @rtype bool
+        """
+        return self.downloadedSuccessfully() and os.path.exists(self.__fileName)
+
+    def updateButtonsAndLabels(self):
+        """
+        Public method to update the buttons.
+        """
+        self.openButton.setEnabled(self.exists())
+        self.openButton.setVisible(self.exists())
+
+        self.__setFileLabels()

eric ide

mercurial