From 186139654c917b59c7c3153cf72df5f78c7edc21 Mon Sep 17 00:00:00 2001 From: George McCandless <5fk7echy8@riseup.net> Date: Mon, 30 Sep 2019 08:25:43 +0000 Subject: [PATCH] Add "Attach File" button to message composition. --- src/bitmessageqt/__init__.py | 18 ++++++++++++++++++ src/bitmessageqt/bitmessageui.py | 4 ++++ src/bitmessageqt/bitmessageui.ui | 13 +++++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 440d36b2..93adcd28 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -11,6 +11,7 @@ import sys import textwrap import threading import time +import base64 from datetime import datetime, timedelta from sqlite3 import register_adapter @@ -161,6 +162,8 @@ class MyForm(settingsmixin.SMainWindow): "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( @@ -1951,6 +1954,21 @@ class MyForm(settingsmixin.SMainWindow): self.ui.textEditMessage.reset() self.ui.comboBoxSendFrom.setCurrentIndex(0) + def click_pushButtonAttach(self): + 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 = '' + os.path.basename(unicode(filename)) + '' + 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 diff --git a/src/bitmessageqt/bitmessageui.py b/src/bitmessageqt/bitmessageui.py index 30d054d0..ca103dd5 100644 --- a/src/bitmessageqt/bitmessageui.py +++ b/src/bitmessageqt/bitmessageui.py @@ -340,6 +340,9 @@ class Ui_MainWindow(object): 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) @@ -713,6 +716,7 @@ class Ui_MainWindow(object): 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)) diff --git a/src/bitmessageqt/bitmessageui.ui b/src/bitmessageqt/bitmessageui.ui index fef40be6..b8b92b68 100644 --- a/src/bitmessageqt/bitmessageui.ui +++ b/src/bitmessageqt/bitmessageui.ui @@ -594,6 +594,19 @@ p, li { white-space: pre-wrap; } + + + + + 16777215 + 16777215 + + + + Attach File + + +