Exemple #1
0
    def chooseSaveFile(self, url):
        fileName = url.path().split("/")[-1]
        if len(self.path) != 0:
            fileName = QtCore.QDir(self.path).filePath(fileName)

        return QtGui.QFileDialog.getSaveFileName(self.parentWidget,
                                                 u"Save File", fileName)
Exemple #2
0
    def saveFile(self, reply):
        newPath = self.downloads.get(reply.url().toString())

        if not newPath:
            newPath = self.chooseSaveFile(reply.url())[0]
        if isinstance(newPath, tuple):
            newPath = newPath[0]
        if len(newPath) != 0:
            file = QtCore.QFile(newPath)
            if file.open(QtCore.QIODevice.WriteOnly):
                file.write(reply.readAll())
                file.close()
                path = QtCore.QDir(newPath).dirName()
                QtGui.QMessageBox.information(self.parentWidget,
                                              u"Download Completed",
                                              u"Saved '%s'." % newPath)
            else:
                QtGui.QMessageBox.warning(self.parentWidget,
                                          u"Download Failed",
                                          u"Failed to save the file.")