--- a/eric7/WebBrowser/Download/DownloadItem.py Thu Jun 16 18:28:59 2022 +0200 +++ b/eric7/WebBrowser/Download/DownloadItem.py Fri Jun 17 16:36:14 2022 +0200 @@ -9,9 +9,10 @@ import enum import os +import pathlib from PyQt6.QtCore import ( - pyqtSlot, pyqtSignal, QTime, QUrl, QStandardPaths, QFileInfo, QDateTime + pyqtSlot, pyqtSignal, QTime, QUrl, QStandardPaths, QDateTime ) from PyQt6.QtGui import QDesktopServices from PyQt6.QtWidgets import QWidget, QStyle, QDialog @@ -180,7 +181,7 @@ url = self.__downloadRequest.url() mimetype = Utilities.MimeTypes.mimeType(originalFileName) dlg = DownloadAskActionDialog( - QFileInfo(originalFileName).fileName(), + pathlib.Path(originalFileName).name, mimetype, "{0}://{1}".format(url.scheme(), url.authority()), self) @@ -193,7 +194,7 @@ self.on_stopButton_clicked() self.filenameLabel.setText( self.tr("Download canceled: {0}").format( - QFileInfo(defaultFileName).fileName())) + pathlib.Path(defaultFileName).name)) self.__canceledFileSelect = True self.__setDateTime() return @@ -205,7 +206,7 @@ self.on_stopButton_clicked() self.filenameLabel.setText( self.tr("VirusTotal scan scheduled: {0}").format( - QFileInfo(defaultFileName).fileName())) + pathlib.Path(defaultFileName).name)) self.__canceledFileSelect = True return @@ -215,7 +216,7 @@ QStandardPaths.StandardLocation.TempLocation) fileName = ( tempLocation + '/' + - QFileInfo(fileName).completeBaseName() + pathlib.Path(fileName).stem ) if ask and not self.__autoOpen: @@ -232,7 +233,7 @@ self.on_stopButton_clicked() self.filenameLabel.setText( self.tr("Download canceled: {0}") - .format(QFileInfo(defaultFileName).fileName())) + .format(pathlib.Path(defaultFileName).name)) self.__canceledFileSelect = True self.__setDateTime() return @@ -246,28 +247,17 @@ @param fileName name of the file to save into @type str """ - fileInfo = QFileInfo(fileName) + fpath = pathlib.Path(fileName) WebBrowserWindow.downloadManager().setDownloadDirectory( - fileInfo.absoluteDir().absolutePath()) - self.filenameLabel.setText(fileInfo.fileName()) + fpath.parent.resolve()) + self.filenameLabel.setText(fpath.name) - self.__fileName = fileName + self.__fileName = str(fpath) # check file path for saving - saveDirPath = QFileInfo(self.__fileName).dir() - if ( - not saveDirPath.exists() and - not saveDirPath.mkpath(saveDirPath.absolutePath()) - ): - self.progressBar.setVisible(False) - self.on_stopButton_clicked() - self.infoLabel.setText(self.tr( - "Download directory ({0}) couldn't be created.") - .format(saveDirPath.absolutePath())) - self.__setDateTime() - return - - self.filenameLabel.setText(QFileInfo(self.__fileName).fileName()) + saveDirPath = pathlib.Path(self.__fileName).parent() + if not saveDirPath.exists(): + saveDirPath.mkdir(parents=True) def __saveFileName(self, directory): """ @@ -276,18 +266,9 @@ @param directory name of the directory to store the file into (string) @return proposed filename and original filename (string, string) """ - path = self.__downloadRequest.downloadFileName() - info = QFileInfo(path) - baseName = info.completeBaseName() - endName = info.suffix() - - origName = baseName - if endName: - origName += '.' + endName - - name = os.path.join(directory, baseName) - if endName: - name += '.' + endName + fpath = pathlib.Path(self.__downloadRequest.downloadFileName()) + origName = fpath.name + name = os.path.join(directory, origName) return name, origName @pyqtSlot(bool) @@ -338,16 +319,14 @@ """ Public slot to open the downloaded file. """ - info = QFileInfo(self.__fileName) - url = QUrl.fromLocalFile(info.absoluteFilePath()) + url = QUrl.fromLocalFile(pathlib.Path(self.__fileName).resolve()) QDesktopServices.openUrl(url) def openFolder(self): """ Public slot to open the folder containing the downloaded file. """ - info = QFileInfo(self.__fileName) - url = QUrl.fromLocalFile(info.absolutePath()) + url = QUrl.fromLocalFile(pathlib.Path(self.__fileName).resolve()) QDesktopServices.openUrl(url) @pyqtSlot() @@ -554,7 +533,7 @@ @return absolute path of the output file (string) """ - return QFileInfo(self.__fileName).absoluteFilePath() + return pathlib.Path(self.__fileName).resolve() def getData(self): """ @@ -568,7 +547,7 @@ """ return { "URL": self.__url, - "Location": QFileInfo(self.__fileName).filePath(), + "Location": self.__fileName, "Done": self.downloadedSuccessfully(), "PageURL": self.__pageUrl, "Downloaded": self.__downloadedDateTime @@ -588,7 +567,7 @@ self.__fileName = data["Location"] self.__pageUrl = data["PageURL"] - self.filenameLabel.setText(QFileInfo(self.__fileName).fileName()) + self.filenameLabel.setText(pathlib.Path(self.__fileName).name) self.infoLabel.setText(self.__fileName) try: