From dd2f83ff4dc7e0bab85841487de1727cae287275 Mon Sep 17 00:00:00 2001 From: mailchuck Date: Tue, 27 Oct 2015 19:50:52 +0100 Subject: [PATCH] Make subscription/chan labels editable Fixes #67 --- src/bitmessageqt/__init__.py | 28 +++++++++++++++++++++------- src/bitmessageqt/foldertree.py | 4 ++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 6668e6a6..73c4c687 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -444,6 +444,8 @@ class MyForm(QtGui.QMainWindow): newSubItem = Ui_FolderWidget(newItem, 0, address, folder, 0) newItem.setUnreadCount(unread) + newItem.setFlags (newItem.flags() | QtCore.Qt.ItemIsEditable) + treeWidget.setSortingEnabled(True) def rerenderTabTreeMessages(self): @@ -537,8 +539,7 @@ class MyForm(QtGui.QMainWindow): unread += db[toAddress][folder] j += 1 widget.setUnreadCount(unread) - if (tab == 'messages'): - widget.setFlags (widget.flags() | QtCore.Qt.ItemIsEditable) + widget.setFlags (widget.flags() | QtCore.Qt.ItemIsEditable) i += 1 treeWidget.setSortingEnabled(True) @@ -658,8 +659,12 @@ class MyForm(QtGui.QMainWindow): "itemChanged (QTreeWidgetItem *, int)"), self.treeWidgetItemChanged) QtCore.QObject.connect(self.ui.treeWidgetSubscriptions, QtCore.SIGNAL( "itemSelectionChanged ()"), self.treeWidgetItemClicked) + QtCore.QObject.connect(self.ui.treeWidgetSubscriptions, QtCore.SIGNAL( + "itemChanged (QTreeWidgetItem *, int)"), self.treeWidgetItemChanged) QtCore.QObject.connect(self.ui.treeWidgetChans, QtCore.SIGNAL( "itemSelectionChanged ()"), self.treeWidgetItemClicked) + QtCore.QObject.connect(self.ui.treeWidgetChans, QtCore.SIGNAL( + "itemChanged (QTreeWidgetItem *, int)"), self.treeWidgetItemChanged) # Put the colored icon on the status bar # self.ui.pushButtonStatusIcon.setIcon(QIcon(":/newPrefix/images/yellowicon.png")) @@ -3613,7 +3618,7 @@ class MyForm(QtGui.QMainWindow): if column != 0: return # only account names of normal addresses (no chans/mailinglists) - if (not isinstance(item, Ui_AddressWidget)) or item.type != 'normal' or not self.getCurrentTreeWidget() or self.getCurrentTreeWidget().currentItem() is None: + if (not isinstance(item, Ui_AddressWidget)) or (not self.getCurrentTreeWidget()) or self.getCurrentTreeWidget().currentItem() is None: return # not visible if (not self.getCurrentItem()) or (not isinstance (self.getCurrentItem(), Ui_AddressWidget)): @@ -3625,7 +3630,10 @@ class MyForm(QtGui.QMainWindow): newLabel = str(item.text(0)) newLabel = newLabel.replace("(" + str(item.address) + ")", '') newLabel = newLabel.rstrip() - oldLabel = shared.config.get(str(item.address), 'label') + if item.type == "subscription": + oldLabel = item.label + else: + oldLabel = shared.config.get(str(item.address), 'label') oldLabel = oldLabel.replace("(" + str(item.address) + ")", '') oldLabel = oldLabel.rstrip() # unchanged, do not do anything either @@ -3637,12 +3645,18 @@ class MyForm(QtGui.QMainWindow): return self.recurDepth += 1 - shared.config.set(str(item.address), 'label', newLabel) + if item.type == "subscription": + sqlExecute( + '''UPDATE subscriptions SET label=? WHERE address=?''', + newLabel, item.address) + item.setLabel(newLabel) + else: + shared.config.set(str(item.address), 'label', newLabel) + shared.writeKeysFile() item.updateText() - shared.writeKeysFile() if item.type == 'mailinglist': self.rerenderComboBoxSendFromBroadcast() - else: + elif item.type != "subscription": self.rerenderComboBoxSendFrom() self.recurDepth -= 1 diff --git a/src/bitmessageqt/foldertree.py b/src/bitmessageqt/foldertree.py index fd4bb9e8..cb8b2c81 100644 --- a/src/bitmessageqt/foldertree.py +++ b/src/bitmessageqt/foldertree.py @@ -183,6 +183,10 @@ class Ui_SubscriptionWidget(Ui_AddressWidget, AccountMixin): def setType(self): self.type = "subscription" + + def edit(self): + self.setText(0, self.label) + super(QtGui.QAbstractItemView, self).edit() def updateText(self): if not self.initialised: