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,9 +551,7 @@ 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:
if addressInKeysFile != 'bitmessagesettings':
status, addressVersionNumber, streamNumber, hash = decodeAddress( status, addressVersionNumber, streamNumber, hash = decodeAddress(
addressInKeysFile) addressInKeysFile)
if addressVersionNumber == 1: if addressVersionNumber == 1:
@ -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:
if addressInKeysFile != 'bitmessagesettings':
isEnabled = shared.config.getboolean( isEnabled = shared.config.getboolean(
addressInKeysFile, 'enabled') # I realize that this is poor programming practice but I don't care. It's easier for others to read. addressInKeysFile, 'enabled') # I realize that this is poor programming practice but I don't care. It's easier for others to read.
isMaillinglist = shared.safeConfigGetBoolean(addressInKeysFile, 'mailinglist') isMaillinglist = shared.safeConfigGetBoolean(addressInKeysFile, 'mailinglist')
if isEnabled and not isMaillinglist: if isEnabled and not isMaillinglist:
self.ui.comboBoxSendFrom.insertItem(0, avatarize(addressInKeysFile), unicode(shared.config.get( self.ui.comboBoxSendFrom.addItem(avatarize(addressInKeysFile), unicode(shared.config.get(
addressInKeysFile, 'label'), 'utf-8'), addressInKeysFile) addressInKeysFile, 'label'), 'utf-8'), addressInKeysFile)
# self.ui.comboBoxSendFrom.model().sort(1, Qt.AscendingOrder)
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,14 +2196,12 @@ 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:
if addressInKeysFile != 'bitmessagesettings':
isEnabled = shared.config.getboolean( isEnabled = shared.config.getboolean(
addressInKeysFile, 'enabled') # I realize that this is poor programming practice but I don't care. It's easier for others to read. addressInKeysFile, 'enabled') # I realize that this is poor programming practice but I don't care. It's easier for others to read.
isMaillinglist = shared.safeConfigGetBoolean(addressInKeysFile, 'mailinglist') isMaillinglist = shared.safeConfigGetBoolean(addressInKeysFile, 'mailinglist')
if isEnabled and isMaillinglist: if isEnabled and isMaillinglist:
self.ui.comboBoxSendFromBroadcast.insertItem(0, avatarize(addressInKeysFile), unicode(shared.config.get( self.ui.comboBoxSendFromBroadcast.addItem(avatarize(addressInKeysFile), unicode(shared.config.get(
addressInKeysFile, 'label'), 'utf-8'), addressInKeysFile) 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):
@ -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: