Account listing and sorting

- account listing and sorting has now a common function to reuse
- combobox send from is now sorted, Fixes #59
This commit is contained in:
mailchuck 2015-10-19 20:03:06 +02:00 committed by Peter Surda
parent afeadcf8d2
commit d51431b1dc
2 changed files with 37 additions and 43 deletions

View File

@ -467,9 +467,7 @@ class MyForm(QtGui.QMainWindow):
db = {} db = {}
enabled = {} enabled = {}
for toAddress in shared.config.sections(): for toAddress in getSortedAccounts():
if toAddress == 'bitmessagesettings':
continue
isEnabled = shared.config.getboolean( isEnabled = shared.config.getboolean(
toAddress, 'enabled') toAddress, 'enabled')
isChan = shared.safeConfigGetBoolean( isChan = shared.safeConfigGetBoolean(
@ -553,20 +551,18 @@ class MyForm(QtGui.QMainWindow):
# Ask the user if we may delete their old version 1 addresses if they # Ask the user if we may delete their old version 1 addresses if they
# have any. # have any.
configSections = shared.config.sections() for addressInKeysFile in getSortedAccounts():
for addressInKeysFile in configSections: status, addressVersionNumber, streamNumber, hash = decodeAddress(
if addressInKeysFile != 'bitmessagesettings': addressInKeysFile)
status, addressVersionNumber, streamNumber, hash = decodeAddress( if addressVersionNumber == 1:
addressInKeysFile) displayMsg = _translate(
if addressVersionNumber == 1: "MainWindow", "One of your addresses, %1, is an old version 1 address. Version 1 addresses are no longer supported. "
displayMsg = _translate( + "May we delete it now?").arg(addressInKeysFile)
"MainWindow", "One of your addresses, %1, is an old version 1 address. Version 1 addresses are no longer supported. " reply = QtGui.QMessageBox.question(
+ "May we delete it now?").arg(addressInKeysFile) self, 'Message', displayMsg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
reply = QtGui.QMessageBox.question( if reply == QtGui.QMessageBox.Yes:
self, 'Message', displayMsg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) shared.config.remove_section(addressInKeysFile)
if reply == QtGui.QMessageBox.Yes: shared.writeKeysFile()
shared.config.remove_section(addressInKeysFile)
shared.writeKeysFile()
# Configure Bitmessage to start on startup (or remove the # Configure Bitmessage to start on startup (or remove the
# configuration) based on the setting in the keys.dat file # configuration) based on the setting in the keys.dat file
@ -2184,15 +2180,14 @@ class MyForm(QtGui.QMainWindow):
def rerenderComboBoxSendFrom(self): def rerenderComboBoxSendFrom(self):
self.ui.comboBoxSendFrom.clear() self.ui.comboBoxSendFrom.clear()
configSections = shared.config.sections() for addressInKeysFile in getSortedAccounts():
for addressInKeysFile in configSections: isEnabled = shared.config.getboolean(
if addressInKeysFile != 'bitmessagesettings': addressInKeysFile, 'enabled') # I realize that this is poor programming practice but I don't care. It's easier for others to read.
isEnabled = shared.config.getboolean( isMaillinglist = shared.safeConfigGetBoolean(addressInKeysFile, 'mailinglist')
addressInKeysFile, 'enabled') # I realize that this is poor programming practice but I don't care. It's easier for others to read. if isEnabled and not isMaillinglist:
isMaillinglist = shared.safeConfigGetBoolean(addressInKeysFile, 'mailinglist') self.ui.comboBoxSendFrom.addItem(avatarize(addressInKeysFile), unicode(shared.config.get(
if isEnabled and not isMaillinglist: addressInKeysFile, 'label'), 'utf-8'), addressInKeysFile)
self.ui.comboBoxSendFrom.insertItem(0, avatarize(addressInKeysFile), unicode(shared.config.get( # self.ui.comboBoxSendFrom.model().sort(1, Qt.AscendingOrder)
addressInKeysFile, 'label'), 'utf-8'), addressInKeysFile)
self.ui.comboBoxSendFrom.insertItem(0, '', '') self.ui.comboBoxSendFrom.insertItem(0, '', '')
if(self.ui.comboBoxSendFrom.count() == 2): if(self.ui.comboBoxSendFrom.count() == 2):
self.ui.comboBoxSendFrom.setCurrentIndex(1) self.ui.comboBoxSendFrom.setCurrentIndex(1)
@ -2201,15 +2196,13 @@ class MyForm(QtGui.QMainWindow):
def rerenderComboBoxSendFromBroadcast(self): def rerenderComboBoxSendFromBroadcast(self):
self.ui.comboBoxSendFromBroadcast.clear() self.ui.comboBoxSendFromBroadcast.clear()
configSections = shared.config.sections() for addressInKeysFile in getSortedAccounts():
for addressInKeysFile in configSections: isEnabled = shared.config.getboolean(
if addressInKeysFile != 'bitmessagesettings': addressInKeysFile, 'enabled') # I realize that this is poor programming practice but I don't care. It's easier for others to read.
isEnabled = shared.config.getboolean( isMaillinglist = shared.safeConfigGetBoolean(addressInKeysFile, 'mailinglist')
addressInKeysFile, 'enabled') # I realize that this is poor programming practice but I don't care. It's easier for others to read. if isEnabled and isMaillinglist:
isMaillinglist = shared.safeConfigGetBoolean(addressInKeysFile, 'mailinglist') self.ui.comboBoxSendFromBroadcast.addItem(avatarize(addressInKeysFile), unicode(shared.config.get(
if isEnabled and isMaillinglist: addressInKeysFile, 'label'), 'utf-8'), addressInKeysFile)
self.ui.comboBoxSendFromBroadcast.insertItem(0, avatarize(addressInKeysFile), unicode(shared.config.get(
addressInKeysFile, 'label'), 'utf-8'), addressInKeysFile)
self.ui.comboBoxSendFromBroadcast.insertItem(0, '', '') self.ui.comboBoxSendFromBroadcast.insertItem(0, '', '')
if(self.ui.comboBoxSendFromBroadcast.count() == 2): if(self.ui.comboBoxSendFromBroadcast.count() == 2):
self.ui.comboBoxSendFromBroadcast.setCurrentIndex(1) self.ui.comboBoxSendFromBroadcast.setCurrentIndex(1)
@ -2713,10 +2706,7 @@ class MyForm(QtGui.QMainWindow):
def click_NewAddressDialog(self): def click_NewAddressDialog(self):
addresses = [] addresses = []
configSections = shared.config.sections() for addressInKeysFile in getSortedAccounts():
for addressInKeysFile in configSections:
if addressInKeysFile == 'bitmessagesettings':
continue
addresses.append(addressInKeysFile) addresses.append(addressInKeysFile)
# self.dialog = Ui_NewAddressWizard(addresses) # self.dialog = Ui_NewAddressWizard(addresses)
# self.dialog.exec_() # self.dialog.exec_()
@ -4056,10 +4046,7 @@ class NewAddressDialog(QtGui.QDialog):
row = 1 row = 1
# Let's fill out the 'existing address' combo box with addresses from # Let's fill out the 'existing address' combo box with addresses from
# the 'Your Identities' tab. # the 'Your Identities' tab.
configSections = shared.config.sections() for addressInKeysFile in getSortedAccounts():
for addressInKeysFile in configSections:
if addressInKeysFile == 'bitmessagesettings':
continue
self.ui.radioButtonExisting.click() self.ui.radioButtonExisting.click()
self.ui.comboBoxExisting.addItem( self.ui.comboBoxExisting.addItem(
addressInKeysFile) addressInKeysFile)

View File

@ -10,6 +10,13 @@ from pyelliptic.openssl import OpenSSL
from utils import str_broadcast_subscribers from utils import str_broadcast_subscribers
import time import time
def getSortedAccounts():
configSections = filter(lambda x: x != 'bitmessagesettings', shared.config.sections())
configSections.sort(cmp =
lambda x,y: cmp(unicode(shared.config.get(x, 'label'), 'utf-8').lower(), unicode(shared.config.get(y, 'label'), 'utf-8').lower())
)
return configSections
def accountClass(address): def accountClass(address):
if not shared.config.has_section(address): if not shared.config.has_section(address):
if address == str_broadcast_subscribers: if address == str_broadcast_subscribers: