def __setFileName(self, fileName): """ Private method to set the file name to save the download into. @param fileName name of the file to save into @type str """ fileInfo = QFileInfo(fileName) WebBrowserWindow.downloadManager().setDownloadDirectory( fileInfo.absoluteDir().absolutePath()) self.filenameLabel.setText(fileInfo.fileName()) self.__fileName = fileName # check file path for saving saveDirPath = QFileInfo(self.__fileName).dir() if not saveDirPath.exists(): if 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())
def __init__(self, parent=None): """ Constructor @param parent reference to the parent widget @type QWidget """ super(DownloadManagerButton, self).__init__(parent) self.__manager = WebBrowserWindow.downloadManager() self.setObjectName("navigation_download_manager_button") self.setIcon(UI.PixmapCache.getIcon("downloads.png")) self.setToolTip(self.tr("Open Download Manager")) self.setToolButtonStyle(Qt.ToolButtonIconOnly) self.setFocusPolicy(Qt.NoFocus) self.setAutoRaise(True) self.clicked.connect(self.__buttonClicked) self.__manager.downloadsCountChanged.connect(self.__updateState) self.__updateState()
def __getFileName(self): """ Private method to get the file name to save to from the user. """ if self.__gettingFileName: return savePage = self.__downloadItem.type() == ( QWebEngineDownloadItem.SavePage) documentLocation = QStandardPaths.writableLocation( QStandardPaths.DocumentsLocation) downloadDirectory = ( WebBrowserWindow.downloadManager().downloadDirectory()) if self.__fileName: fileName = self.__fileName originalFileName = self.__originalFileName self.__toDownload = True ask = False else: defaultFileName, originalFileName = self.__saveFileName( documentLocation if savePage else downloadDirectory) fileName = defaultFileName self.__originalFileName = originalFileName ask = True self.__autoOpen = False if not savePage: from .DownloadAskActionDialog import DownloadAskActionDialog url = self.__downloadItem.url() mimetype = Utilities.MimeTypes.mimeType(originalFileName) dlg = DownloadAskActionDialog( QFileInfo(originalFileName).fileName(), mimetype, "{0}://{1}".format(url.scheme(), url.authority()), self) if dlg.exec_() == QDialog.Rejected or dlg.getAction() == "cancel": self.progressBar.setVisible(False) self.on_stopButton_clicked() self.filenameLabel.setText( self.tr("Download canceled: {0}").format( QFileInfo(defaultFileName).fileName())) self.__canceledFileSelect = True self.__setDateTime() return if dlg.getAction() == "scan": self.__mainWindow.requestVirusTotalScan(url) self.progressBar.setVisible(False) self.on_stopButton_clicked() self.filenameLabel.setText( self.tr("VirusTotal scan scheduled: {0}").format( QFileInfo(defaultFileName).fileName())) self.__canceledFileSelect = True return self.__autoOpen = dlg.getAction() == "open" tempLocation = QStandardPaths.writableLocation( QStandardPaths.TempLocation) fileName = (tempLocation + '/' + QFileInfo(fileName).completeBaseName()) if ask and not self.__autoOpen: self.__gettingFileName = True fileName = E5FileDialog.getSaveFileName( None, self.tr("Save File"), defaultFileName, "") self.__gettingFileName = False if not fileName: self.progressBar.setVisible(False) self.on_stopButton_clicked() self.filenameLabel.setText( self.tr("Download canceled: {0}").format( QFileInfo(defaultFileName).fileName())) self.__canceledFileSelect = True self.__setDateTime() return self.__setFileName(fileName)