Enable seamless, if crude, file attachment capability #1544

Open
sgj3 wants to merge 3 commits from sgj3/attachments into v0.6
Showing only changes of commit 03fbadd3c4 - Show all commits

View File

@ -5,6 +5,7 @@ src/bitmessageqt/messageview.py
""" """
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
import re, base64
from safehtmlparser import SafeHTMLParser from safehtmlparser import SafeHTMLParser
@ -64,6 +65,9 @@ class MessageView(QtGui.QTextBrowser):
def confirmURL(self, link): def confirmURL(self, link):
"""Show a dialog requesting URL opening confirmation""" """Show a dialog requesting URL opening confirmation"""
link_str = link.toString()
datablob_re = r'^data:.*/.*;base64,.*'
datablob_match = re.match(datablob_re, link_str)
if link.scheme() == "mailto": if link.scheme() == "mailto":
window = QtGui.QApplication.activeWindow() window = QtGui.QApplication.activeWindow()
window.ui.lineEditTo.setText(link.path()) window.ui.lineEditTo.setText(link.path())
@ -80,6 +84,16 @@ class MessageView(QtGui.QTextBrowser):
) )
window.ui.textEditMessage.setFocus() window.ui.textEditMessage.setFocus()
return return
if datablob_match:
name = QtGui.QFileDialog.getSaveFileName(self, 'Save File')
if name:
f = open(name, 'wb')
data_begin_pos = re.finditer(";base64,", link_str).next()
data_b64 = link_str[data_begin_pos.span()[1]:]
data = base64.b64decode(data_b64)
f.write(data)
f.close()
else:
reply = QtGui.QMessageBox.warning( reply = QtGui.QMessageBox.warning(
self, self,
QtGui.QApplication.translate( QtGui.QApplication.translate(