From 585873e4f39fefa4be02acc9df692816c75e4679 Mon Sep 17 00:00:00 2001 From: sbkaf Date: Thu, 19 Mar 2015 18:25:50 +0100 Subject: [PATCH] interface --- src/bitmessagemain.py | 2 +- src/bitmessageqt/__init__.py | 122 +++++++++++++++++++++++++++++-- src/bitmessageqt/bitmessageui.py | 6 +- 3 files changed, 121 insertions(+), 9 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index bf1d74f2..73f71cfb 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -197,7 +197,7 @@ class Main: singleAPIThread.daemon = True # close the main program even if there are threads left singleAPIThread.start() - connectToStream(1) + #connectToStream(1) singleListenerThread = singleListener() singleListenerThread.setup(selfInitiatedConnections) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 38087497..5c9e459e 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -557,10 +557,8 @@ class MyForm(QtGui.QMainWindow): newSubItem.setText(0, _translate("MainWindow", "trash")) # Load inbox from messages database file - self.loadInbox() - - # Load Sent items from database - self.loadSent() + #self.loadInbox() + self.loadMessagelist("BM-2cTxBr9RxjorkjvkgTkD1AgjhUJBwDnVKY"); # Initialize the address book self.rerenderAddressBook() @@ -903,6 +901,120 @@ class MyForm(QtGui.QMainWindow): self.ui.tableWidgetInbox.sortItems(3, Qt.DescendingOrder) self.ui.tableWidgetInbox.keyPressEvent = self.tableWidgetInboxKeyPressEvent + # Load inbox from messages database file + def loadMessagelist(self, account, folder="inbox", where="", what=""): + what = "%" + what + "%" + if where == "To": + where = "toaddress" + elif where == "From": + where = "fromaddress" + elif where == "Subject": + where = "subject" + elif where == "Message": + where = "message" + else: + where = "toaddress || fromaddress || subject || message" + + if folder == "sent": + accountaddress = "fromaddress" + else: + accountaddress = "toaddress" + + sqlStatement = ''' + SELECT msgid, toaddress, fromaddress, subject, received, read + FROM inbox WHERE %s=? AND folder=? AND %s LIKE ? + ORDER BY received + ''' % (accounttype, where) + + while self.ui.tableWidgetInbox.rowCount() > 0: + self.ui.tableWidgetInbox.removeRow(0) + + font = QFont() + font.setBold(True) + queryreturn = sqlQuery(sqlStatement, account, folder, what) + for row in queryreturn: + msgid, toAddress, fromAddress, subject, received, read = row + subject = shared.fixPotentiallyInvalidUTF8Data(subject) + try: + if toAddress == self.str_broadcast_subscribers: + toLabel = self.str_broadcast_subscribers + else: + toLabel = shared.config.get(toAddress, 'label') + except: + toLabel = '' + if toLabel == '': + toLabel = toAddress + + fromLabel = '' + if shared.config.has_section(fromAddress): + fromLabel = shared.config.get(fromAddress, 'label') + + if fromLabel == '': # If the fromAddress isn't one of our addresses and isn't a chan + queryreturn = sqlQuery( + '''select label from addressbook where address=?''', fromAddress) + if queryreturn != []: + for row in queryreturn: + fromLabel, = row + + if fromLabel == '': # If this address wasn't in our address book... + queryreturn = sqlQuery( + '''select label from subscriptions where address=?''', fromAddress) + if queryreturn != []: + for row in queryreturn: + fromLabel, = row + if fromLabel == '': + fromLabel = fromAddress + + # message row + self.ui.tableWidgetInbox.insertRow(0) + # to + to_item = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8')) + to_item.setToolTip(unicode(toLabel, 'utf-8')) + to_item.setFlags( + QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) + if not read: + to_item.setFont(font) + to_item.setData(Qt.UserRole, str(toAddress)) + if shared.safeConfigGetBoolean(toAddress, 'mailinglist'): + to_item.setTextColor(QtGui.QColor(137, 04, 177)) # magenta + if shared.safeConfigGetBoolean(str(toAddress), 'chan'): + to_item.setTextColor(QtGui.QColor(216, 119, 0)) # orange + to_item.setIcon(avatarize(toAddress)) + self.ui.tableWidgetInbox.setItem(0, 0, to_item) + # from + from_item = QtGui.QTableWidgetItem(unicode(fromLabel, 'utf-8')) + from_item.setToolTip(unicode(fromLabel, 'utf-8')) + from_item.setFlags( + QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) + if not read: + from_item.setFont(font) + from_item.setData(Qt.UserRole, str(fromAddress)) + if shared.safeConfigGetBoolean(str(fromAddress), 'chan'): + from_item.setTextColor(QtGui.QColor(216, 119, 0)) # orange + from_item.setIcon(avatarize(fromAddress)) + self.ui.tableWidgetInbox.setItem(0, 1, from_item) + # subject + subject_item = QtGui.QTableWidgetItem(unicode(subject, 'utf-8')) + subject_item.setToolTip(unicode(subject, 'utf-8')) + subject_item.setFlags( + QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) + if not read: + subject_item.setFont(font) + self.ui.tableWidgetInbox.setItem(0, 2, subject_item) + # time received + time_item = myTableWidgetItem(l10n.formatTimestamp(received)) + time_item.setToolTip(l10n.formatTimestamp(received)) + time_item.setData(Qt.UserRole, QByteArray(msgid)) + time_item.setData(33, int(received)) + time_item.setFlags( + QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) + if not read: + time_item.setFont(font) + self.ui.tableWidgetInbox.setItem(0, 3, time_item) + + self.ui.tableWidgetInbox.sortItems(3, Qt.DescendingOrder) + self.ui.tableWidgetInbox.keyPressEvent = self.tableWidgetInboxKeyPressEvent + # Load inbox from messages database file def loadInbox(self, where="", what=""): what = "%" + what + "%" @@ -3308,7 +3420,7 @@ more work your computer must do to send the message. A Time-To-Live of four or f else: message = "Error occurred: could not load message from disk." message = unicode(message, 'utf-8)') - self.ui.textEditSentMessage.setPlainText(message) + self.ui.textEditInboxMessage.setPlainText(message) def tableWidgetYourIdentitiesItemChanged(self): currentRow = self.ui.tableWidgetYourIdentities.currentRow() diff --git a/src/bitmessageqt/bitmessageui.py b/src/bitmessageqt/bitmessageui.py index f3a600f6..b4762f43 100644 --- a/src/bitmessageqt/bitmessageui.py +++ b/src/bitmessageqt/bitmessageui.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file 'bmail.ui' +# Form implementation generated from reading ui file 'bitmessageui.ui' # -# Created: Sun Mar 1 23:18:09 2015 +# Created: Wed Mar 4 00:11:02 2015 # by: PyQt4 UI code generator 4.10.4 # # WARNING! All changes made in this file will be lost! @@ -572,7 +572,7 @@ class Ui_MainWindow(object): MainWindow.setTabOrder(self.tableWidgetConnectionCount, self.pushButtonStatusIcon) def retranslateUi(self, MainWindow): - MainWindow.setWindowTitle(_translate("MainWindow", "B-Mail", None)) + MainWindow.setWindowTitle(_translate("MainWindow", "Bitmessage", None)) self.treeWidgetYourIdentities.headerItem().setText(0, _translate("MainWindow", "Identities", None)) self.pushButtonNewAddress.setText(_translate("MainWindow", "New Indentitiy", None)) self.inboxSearchLineEdit.setPlaceholderText(_translate("MainWindow", "Search", None))