summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/gui
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2016-05-03 12:18:25 -0400
committerKali Kaneko <kali@leap.se>2016-05-03 12:59:23 -0400
commit54560623ac5c325bebbe627582b3895c3354368a (patch)
tree03e653f6853ec169ec676c5fe53fc565dda6098a /src/leap/bitmask/gui
parent2a802378a6ffd1c1c677e4fa035ee3b8f932dfbe (diff)
[feature] enable to download attachments from within webkit
- Resolves: #8069 - Releases: 0.9.2
Diffstat (limited to 'src/leap/bitmask/gui')
-rw-r--r--src/leap/bitmask/gui/qt_browser.py30
1 files changed, 29 insertions, 1 deletions
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()