From 8c8795cfa48718f82623ed179239a466390741ed Mon Sep 17 00:00:00 2001 From: mailchuck Date: Sun, 4 Oct 2015 10:47:51 +0200 Subject: [PATCH] Editable address labels Address labels can be edited now (F2 or double click) --- src/bitmessageqt/__init__.py | 22 +++++++++++++++++++++- src/bitmessageqt/foldertree.py | 8 +++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 8c64ae8e..5d2202a0 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -534,8 +534,11 @@ class MyForm(QtGui.QMainWindow): unread += db[toAddress][folder] j += 1 widget.setUnreadCount(unread) + if (tab == 'messages'): + print "setting %s editable" % (toAddress) + widget.setFlags (widget.flags() | QtCore.Qt.ItemIsEditable) i += 1 - + treeWidget.setSortingEnabled(True) def __init__(self, parent=None): @@ -645,6 +648,8 @@ class MyForm(QtGui.QMainWindow): # tree address lists QtCore.QObject.connect(self.ui.treeWidgetYourIdentities, QtCore.SIGNAL( "itemSelectionChanged ()"), self.treeWidgetItemClicked) + QtCore.QObject.connect(self.ui.treeWidgetYourIdentities, QtCore.SIGNAL( + "itemChanged (QTreeWidgetItem *, int)"), self.treeWidgetItemChanged) QtCore.QObject.connect(self.ui.treeWidgetSubscriptions, QtCore.SIGNAL( "itemSelectionChanged ()"), self.treeWidgetItemClicked) QtCore.QObject.connect(self.ui.treeWidgetChans, QtCore.SIGNAL( @@ -3461,6 +3466,21 @@ more work your computer must do to send the message. A Time-To-Live of four or f folder = self.getCurrentFolder() self.loadMessagelist(messagelist, account, folder) + def treeWidgetItemChanged(self, item, column): + widget = self.getCurrentTreeWidget() + if item.address == widget.currentItem().address: + newLabel = str(item.text(0)) + newLabel = newLabel.replace("(" + str(item.address) + ")", '') + newLabel = newLabel.rstrip() + oldLabel = shared.config.get(str(item.address), 'label') + oldLabel = oldLabel.replace("(" + str(item.address) + ")", '') + oldLabel = oldLabel.rstrip() + if newLabel == oldLabel: + return + shared.config.set(str(item.address), 'label', newLabel) + item.updateText() + shared.writeKeysFile() + def tableWidgetInboxItemClicked(self): folder = self.getCurrentFolder() messageTextedit = self.getCurrentMessageTextedit() diff --git a/src/bitmessageqt/foldertree.py b/src/bitmessageqt/foldertree.py index 41824b91..2a907711 100644 --- a/src/bitmessageqt/foldertree.py +++ b/src/bitmessageqt/foldertree.py @@ -80,9 +80,7 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem): self.updateText() def updateText(self): - text = QtGui.QApplication.translate("MainWindow", - unicode(shared.config.get(self.address, 'label'), 'utf-8)') - + ' (' + self.address + ')') + text = unicode(shared.config.get(self.address, 'label'), 'utf-8)') + ' (' + self.address + ')' font = QtGui.QFont() if self.unreadCount > 0: @@ -116,6 +114,10 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem): super(Ui_AddressWidget, self).setExpanded(expand) self.updateText() + def edit(self): + self.setText(0, shared.config.get(self.address, 'label')) + super(QtGui.QAbstractItemView, self).edit() + # label (or address) alphabetically, disabled at the end def __lt__(self, other): if (isinstance(other, Ui_AddressWidget)):