Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/bitmessageqt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import textwrap
import threading
import time
import base64
from datetime import datetime, timedelta
from sqlite3 import register_adapter

Expand Down Expand Up @@ -161,6 +162,8 @@ def init_file_menu(self):
"clicked()"), self.click_pushButtonTTL)
QtCore.QObject.connect(self.ui.pushButtonClear, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonClear)
QtCore.QObject.connect(self.ui.pushButtonAttach, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonAttach)
QtCore.QObject.connect(self.ui.pushButtonSend, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonSend)
QtCore.QObject.connect(self.ui.pushButtonFetchNamecoinID, QtCore.SIGNAL(
Expand Down Expand Up @@ -1951,6 +1954,23 @@ def click_pushButtonClear(self):
self.ui.textEditMessage.reset()
self.ui.comboBoxSendFrom.setCurrentIndex(0)

def click_pushButtonAttach(self):
"""Launch a file picker and append to the current message the base64-encoded contents of the chosen file."""
filename = QtGui.QFileDialog.getOpenFileName(self, "Attach File")
if filename:
f = open(filename, 'rb')
data = f.read()
f.close()
data_b64 = base64.b64encode(data)
html_data = '<a href="data:application/octet-stream;base64,' + data_b64 + '">' \
+ os.path.basename(unicode(filename)) + '</a>'
if self.ui.tabWidgetSend.currentIndex() == self.ui.tabWidgetSend.indexOf(self.ui.sendDirect):
# send direct message
self.ui.textEditMessage.insertPlainText(html_data)
else:
# send broadcast message
self.ui.textEditMessageBroadcast.insertPlainText(html_data)

def click_pushButtonSend(self):
encoding = 3 if QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier else 2

Expand Down
4 changes: 4 additions & 0 deletions src/bitmessageqt/bitmessageui.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ def setupUi(self, MainWindow):
self.pushButtonClear = QtGui.QPushButton(self.send)
self.pushButtonClear.setObjectName(_fromUtf8("pushButtonClear"))
self.horizontalLayout_5.addWidget(self.pushButtonClear, 0, QtCore.Qt.AlignRight)
self.pushButtonAttach = QtGui.QPushButton(self.send)
self.pushButtonAttach.setObjectName(_fromUtf8("pushButtonAttach"))
self.horizontalLayout_5.addWidget(self.pushButtonAttach, 0, QtCore.Qt.AlignRight)
self.pushButtonSend = QtGui.QPushButton(self.send)
self.pushButtonSend.setObjectName(_fromUtf8("pushButtonSend"))
self.horizontalLayout_5.addWidget(self.pushButtonSend, 0, QtCore.Qt.AlignRight)
Expand Down Expand Up @@ -713,6 +716,7 @@ def retranslateUi(self, MainWindow):
pass
self.labelHumanFriendlyTTLDescription.setText(_translate("MainWindow", "%n hour(s)", None, QtCore.QCoreApplication.CodecForTr, hours))
self.pushButtonClear.setText(_translate("MainWindow", "Clear", None))
self.pushButtonAttach.setText(_translate("MainWindow", "Attach File", None))
self.pushButtonSend.setText(_translate("MainWindow", "Send", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.send), _translate("MainWindow", "Send", None))
self.treeWidgetSubscriptions.headerItem().setText(0, _translate("MainWindow", "Subscriptions", None))
Expand Down
13 changes: 13 additions & 0 deletions src/bitmessageqt/bitmessageui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,19 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonAttach">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Attach File</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down
41 changes: 28 additions & 13 deletions src/bitmessageqt/messageview.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""

from PyQt4 import QtCore, QtGui
import re
import base64

from safehtmlparser import SafeHTMLParser

Expand Down Expand Up @@ -64,6 +66,9 @@ def setWrappingWidth(self, width=None):

def confirmURL(self, link):
"""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":
window = QtGui.QApplication.activeWindow()
window.ui.lineEditTo.setText(link.path())
Expand All @@ -80,19 +85,29 @@ def confirmURL(self, link):
)
window.ui.textEditMessage.setFocus()
return
reply = QtGui.QMessageBox.warning(
self,
QtGui.QApplication.translate(
"MessageView",
"Follow external link"),
QtGui.QApplication.translate(
"MessageView",
"The link \"%1\" will open in a browser. It may be a security risk, it could de-anonymise you"
" or download malicious data. Are you sure?").arg(unicode(link.toString())),
QtGui.QMessageBox.Yes,
QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
QtGui.QDesktopServices.openUrl(link)
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(
self,
QtGui.QApplication.translate(
"MessageView",
"Follow external link"),
QtGui.QApplication.translate(
"MessageView",
"The link \"%1\" will open in a browser. It may be a security risk, it could de-anonymise you"
" or download malicious data. Are you sure?").arg(unicode(link.toString())),
QtGui.QMessageBox.Yes,
QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
QtGui.QDesktopServices.openUrl(link)

def loadResource(self, restype, name):
"""
Expand Down