From 54560623ac5c325bebbe627582b3895c3354368a Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 3 May 2016 12:18:25 -0400 Subject: [feature] enable to download attachments from within webkit - Resolves: #8069 - Releases: 0.9.2 --- src/leap/bitmask/gui/qt_browser.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/leap/bitmask/gui') diff --git a/src/leap/bitmask/gui/qt_browser.py b/src/leap/bitmask/gui/qt_browser.py index c62e7770..2f7e6086 100644 --- a/src/leap/bitmask/gui/qt_browser.py +++ b/src/leap/bitmask/gui/qt_browser.py @@ -17,8 +17,10 @@ """ QtWebKit-based browser to display Pixelated User Agent """ +import os +import urlparse -from PySide import QtCore, QtWebKit, QtGui +from PySide import QtCore, QtWebKit, QtGui, QtNetwork PIXELATED_URI = 'http://localhost:9090' @@ -37,3 +39,29 @@ class PixelatedWindow(QtGui.QDialog): def load_app(self): self.view.load(QtCore.QUrl(PIXELATED_URI)) + self.view.page().setForwardUnsupportedContent(True) + self.view.page().unsupportedContent.connect(self.download) + + self.manager = QtNetwork.QNetworkAccessManager() + self.manager.finished.connect(self.finished) + + def download(self, reply): + self.request = QtNetwork.QNetworkRequest(reply.url()) + self.reply = self.manager.get(self.request) + + def finished(self): + url = self.reply.url().toString() + + filename = urlparse.parse_qs(url).get('filename', None) + if filename: + filename = filename[0] + name = filename or url + + path = os.path.expanduser(os.path.join( + '~', unicode(name).split('/')[-1])) + destination = QtGui.QFileDialog.getSaveFileName(self, "Save", path) + if destination: + filename = destination[0] + with open(filename, 'wb') as f: + f.write(str(self.reply.readAll())) + f.close() -- cgit v1.2.3