src/eric7/WebBrowser/Download/DownloadItem.py

branch
eric7
changeset 9566
d4986df5d2e4
parent 9482
a2bc06a54d9d
child 9576
be9f8e7e42e0
equal deleted inserted replaced
9565:ed264631ab1e 9566:d4986df5d2e4
244 244
245 @param fileName name of the file to save into 245 @param fileName name of the file to save into
246 @type str 246 @type str
247 """ 247 """
248 fpath = pathlib.Path(fileName) 248 fpath = pathlib.Path(fileName)
249 WebBrowserWindow.downloadManager().setDownloadDirectory(fpath.parent.resolve()) 249 WebBrowserWindow.downloadManager().setDownloadDirectory(
250 str(fpath.parent.resolve())
251 )
250 self.filenameLabel.setText(fpath.name) 252 self.filenameLabel.setText(fpath.name)
251 253
252 self.__fileName = str(fpath) 254 self.__fileName = str(fpath)
253 255
254 # check file path for saving 256 # check file path for saving
255 saveDirPath = pathlib.Path(self.__fileName).parent() 257 saveDirPath = pathlib.Path(self.__fileName).parent
256 if not saveDirPath.exists(): 258 if not saveDirPath.exists():
257 saveDirPath.mkdir(parents=True) 259 saveDirPath.mkdir(parents=True)
258 260
259 def __saveFileName(self, directory): 261 def __saveFileName(self, directory):
260 """ 262 """
314 316
315 def openFile(self): 317 def openFile(self):
316 """ 318 """
317 Public slot to open the downloaded file. 319 Public slot to open the downloaded file.
318 """ 320 """
319 url = QUrl.fromLocalFile(pathlib.Path(self.__fileName).resolve()) 321 url = QUrl.fromLocalFile(str(pathlib.Path(self.__fileName).resolve()))
320 QDesktopServices.openUrl(url) 322 QDesktopServices.openUrl(url)
321 323
322 def openFolder(self): 324 def openFolder(self):
323 """ 325 """
324 Public slot to open the folder containing the downloaded file. 326 Public slot to open the folder containing the downloaded file.
325 """ 327 """
326 url = QUrl.fromLocalFile(pathlib.Path(self.__fileName).resolve()) 328 url = QUrl.fromLocalFile(str(pathlib.Path(self.__fileName).resolve().parent))
327 QDesktopServices.openUrl(url) 329 QDesktopServices.openUrl(url)
328 330
329 @pyqtSlot() 331 @pyqtSlot()
330 def __downloadProgress(self): 332 def __downloadProgress(self):
331 """ 333 """
525 """ 527 """
526 Public method to get the absolute path of the output file. 528 Public method to get the absolute path of the output file.
527 529
528 @return absolute path of the output file (string) 530 @return absolute path of the output file (string)
529 """ 531 """
530 return pathlib.Path(self.__fileName).resolve() 532 return str(pathlib.Path(self.__fileName).resolve())
531 533
532 def getData(self): 534 def getData(self):
533 """ 535 """
534 Public method to get the relevant download data. 536 Public method to get the relevant download data.
535 537
559 """ 561 """
560 self.__url = data["URL"] 562 self.__url = data["URL"]
561 self.__fileName = data["Location"] 563 self.__fileName = data["Location"]
562 self.__pageUrl = data["PageURL"] 564 self.__pageUrl = data["PageURL"]
563 565
564 self.filenameLabel.setText(pathlib.Path(self.__fileName).name) 566 self.__state = (
565 self.infoLabel.setText(self.__fileName) 567 DownloadState.Successful
568 if data["Done"]
569 else DownloadState.Cancelled
570 )
566 571
567 try: 572 try:
568 self.__setDateTime(data["Downloaded"]) 573 self.__setDateTime(data["Downloaded"])
569 except KeyError: 574 except KeyError:
570 self.__setDateTime(QDateTime()) 575 self.__setDateTime(QDateTime())
571 576
572 self.pauseButton.setEnabled(False) 577 self.pauseButton.setEnabled(False)
573 self.pauseButton.setVisible(False) 578 self.pauseButton.setVisible(False)
574 self.stopButton.setEnabled(False) 579 self.stopButton.setEnabled(False)
575 self.stopButton.setVisible(False) 580 self.stopButton.setVisible(False)
576 self.openButton.setEnabled(data["Done"])
577 self.openButton.setVisible(data["Done"])
578 if data["Done"]:
579 self.__state = DownloadState.Successful
580 else:
581 self.__state = DownloadState.Cancelled
582 self.progressBar.setVisible(False) 581 self.progressBar.setVisible(False)
583 582
583 self.updateButtonsAndLabels()
584
584 self.__adjustSize() 585 self.__adjustSize()
586
587 @pyqtSlot()
588 def __setFileLabels(self):
589 """
590 Private slot to set and format the info label.
591 """
592 self.infoLabel.setText(self.__fileName)
593 if self.downloadedSuccessfully() and not os.path.exists(self.__fileName):
594 self.filenameLabel.setText(
595 self.tr("{0} - deleted").format(pathlib.Path(self.__fileName).name)
596 )
597 font = self.filenameLabel.font()
598 font.setItalic(True)
599 self.filenameLabel.setFont(font)
600
601 font = self.infoLabel.font()
602 font.setItalic(True)
603 font.setStrikeOut(True)
604 self.infoLabel.setFont(font)
605 else:
606 self.filenameLabel.setText(pathlib.Path(self.__fileName).name)
585 607
586 def getInfoData(self): 608 def getInfoData(self):
587 """ 609 """
588 Public method to get the text of the info label. 610 Public method to get the text of the info label.
589 611
624 self.datetimeLabel.setText(labelText) 646 self.datetimeLabel.setText(labelText)
625 self.datetimeLabel.show() 647 self.datetimeLabel.show()
626 else: 648 else:
627 self.datetimeLabel.clear() 649 self.datetimeLabel.clear()
628 self.datetimeLabel.hide() 650 self.datetimeLabel.hide()
651
652 def exists(self):
653 """
654 Public method to check, if the downloaded file exists.
655
656 @return flag indicating the existence of the downloaded file
657 @rtype bool
658 """
659 return self.downloadedSuccessfully() and os.path.exists(self.__fileName)
660
661 def updateButtonsAndLabels(self):
662 """
663 Public method to update the buttons.
664 """
665 self.openButton.setEnabled(self.exists())
666 self.openButton.setVisible(self.exists())
667
668 self.__setFileLabels()

eric ide

mercurial