From 2f874e41be7aaf54d84e4e4b6e3ec7fff420877e Mon Sep 17 00:00:00 2001 From: mailchuck Date: Fri, 13 Nov 2015 14:31:22 +0100 Subject: [PATCH] Fix adding/editing entries in addresbook It didn't sort correctly and didn't update the label correctly when changed. Fixes #95 --- src/bitmessageqt/__init__.py | 24 +++--------------------- src/bitmessageqt/foldertree.py | 6 ++++++ 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 8cd8cbda..67838836 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2431,17 +2431,8 @@ class MyForm(settingsmixin.SMainWindow): def addEntryToAddressBook(self,address,label): queryreturn = sqlQuery('''select * from addressbook where address=?''', address) if queryreturn == []: - self.ui.tableWidgetAddressBook.setSortingEnabled(False) - self.ui.tableWidgetAddressBook.insertRow(0) - newItem = QtGui.QTableWidgetItem(unicode(label, 'utf-8')) - newItem.setIcon(avatarize(address)) - self.ui.tableWidgetAddressBook.setItem(0, 0, newItem) - newItem = QtGui.QTableWidgetItem(address) - newItem.setFlags( - QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) - self.ui.tableWidgetAddressBook.setItem(0, 1, newItem) - self.ui.tableWidgetAddressBook.setSortingEnabled(True) sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', str(label), address) + self.rerenderAddressBook() self.rerenderInboxFromLabels() self.rerenderSentToLabels() else: @@ -3073,20 +3064,10 @@ class MyForm(settingsmixin.SMainWindow): queryreturn = sqlQuery('''select * from addressbook where address=?''', addressAtCurrentInboxRow) if queryreturn == []: - self.ui.tableWidgetAddressBook.insertRow(0) - newItem = QtGui.QTableWidgetItem( - '--New entry. Change label in Address Book.--') - self.ui.tableWidgetAddressBook.setItem(0, 0, newItem) - newItem.setIcon(avatarize(addressAtCurrentInboxRow)) - newItem = QtGui.QTableWidgetItem(addressAtCurrentInboxRow) - newItem.setFlags( - QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) - self.ui.tableWidgetAddressBook.setItem(0, 1, newItem) sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', '--New entry. Change label in Address Book.--', addressAtCurrentInboxRow) - self.ui.tabWidget.setCurrentIndex(1) - self.ui.tableWidgetAddressBook.setCurrentCell(0, 0) + self.rerenderAddressBook() self.statusBar().showMessage(_translate( "MainWindow", "Entry added to the Address Book. Edit the label to your liking.")) else: @@ -3928,6 +3909,7 @@ class MyForm(settingsmixin.SMainWindow): sqlExecute('''UPDATE addressbook set label=? WHERE address=?''', str(self.ui.tableWidgetAddressBook.item(currentRow, 0).text().toUtf8()), str(addressAtCurrentRow)) + self.ui.tableWidgetAddressBook.item(currentRow, 0).setLabel(str(self.ui.tableWidgetAddressBook.item(currentRow, 0).text().toUtf8())) self.rerenderInboxFromLabels() self.rerenderSentToLabels() diff --git a/src/bitmessageqt/foldertree.py b/src/bitmessageqt/foldertree.py index 59f16667..20291c5d 100644 --- a/src/bitmessageqt/foldertree.py +++ b/src/bitmessageqt/foldertree.py @@ -287,9 +287,15 @@ class Ui_AddressBookWidgetItem(QtGui.QTableWidgetItem, AccountMixin): class Ui_AddressBookWidgetItemLabel(Ui_AddressBookWidgetItem): def __init__ (self, address, label, type): Ui_AddressBookWidgetItem.__init__(self, label, type) + self.address = address + self.label = label self.setIcon(avatarize(address)) self.setToolTip(label + " (" + address + ")") + def setLabel(self, label): + self.label = label + self.setToolTip(self.label + " (" + self.address + ")") + class Ui_AddressBookWidgetItemAddress(Ui_AddressBookWidgetItem): def __init__ (self, address, label, type):