Extend bmconfigparser.BMConfigParser.addresses() by a sort kwarg,
remove getSortedAccounts() in bitmessageqt.account.
This commit is contained in:
parent
79dc722072
commit
a28eb6898b
|
@ -22,6 +22,9 @@ import shared
|
||||||
import state
|
import state
|
||||||
from debug import logger
|
from debug import logger
|
||||||
from tr import _translate
|
from tr import _translate
|
||||||
|
from account import (
|
||||||
|
accountClass, getSortedSubscriptions,
|
||||||
|
BMAccount, GatewayAccount, MailchuckAccount, AccountColor)
|
||||||
from addresses import decodeAddress, addBMIfNotPresent
|
from addresses import decodeAddress, addBMIfNotPresent
|
||||||
from bitmessageui import Ui_MainWindow
|
from bitmessageui import Ui_MainWindow
|
||||||
from bmconfigparser import config
|
from bmconfigparser import config
|
||||||
|
@ -40,9 +43,6 @@ import helper_addressbook
|
||||||
import helper_search
|
import helper_search
|
||||||
import l10n
|
import l10n
|
||||||
from utils import str_broadcast_subscribers, avatarize
|
from utils import str_broadcast_subscribers, avatarize
|
||||||
from account import (
|
|
||||||
getSortedAccounts, getSortedSubscriptions, accountClass, BMAccount,
|
|
||||||
GatewayAccount, MailchuckAccount, AccountColor)
|
|
||||||
import dialogs
|
import dialogs
|
||||||
from network.stats import pendingDownload, pendingUpload
|
from network.stats import pendingDownload, pendingUpload
|
||||||
from uisignaler import UISignaler
|
from uisignaler import UISignaler
|
||||||
|
@ -522,7 +522,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
db = {}
|
db = {}
|
||||||
enabled = {}
|
enabled = {}
|
||||||
|
|
||||||
for toAddress in getSortedAccounts():
|
for toAddress in config.addresses(True):
|
||||||
isEnabled = config.getboolean(
|
isEnabled = config.getboolean(
|
||||||
toAddress, 'enabled')
|
toAddress, 'enabled')
|
||||||
isChan = config.safeGetBoolean(
|
isChan = config.safeGetBoolean(
|
||||||
|
@ -640,7 +640,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
|
|
||||||
# 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.
|
||||||
for addressInKeysFile in getSortedAccounts():
|
for addressInKeysFile in config.addresses():
|
||||||
status, addressVersionNumber, streamNumber, hash = decodeAddress(
|
status, addressVersionNumber, streamNumber, hash = decodeAddress(
|
||||||
addressInKeysFile)
|
addressInKeysFile)
|
||||||
if addressVersionNumber == 1:
|
if addressVersionNumber == 1:
|
||||||
|
@ -2020,8 +2020,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
label, address = row
|
label, address = row
|
||||||
newRows[address] = [label, AccountMixin.SUBSCRIPTION]
|
newRows[address] = [label, AccountMixin.SUBSCRIPTION]
|
||||||
# chans
|
# chans
|
||||||
addresses = getSortedAccounts()
|
for address in config.addresses(True):
|
||||||
for address in addresses:
|
|
||||||
account = accountClass(address)
|
account = accountClass(address)
|
||||||
if (account.type == AccountMixin.CHAN and config.safeGetBoolean(address, 'enabled')):
|
if (account.type == AccountMixin.CHAN and config.safeGetBoolean(address, 'enabled')):
|
||||||
newRows[address] = [account.getLabel(), AccountMixin.CHAN]
|
newRows[address] = [account.getLabel(), AccountMixin.CHAN]
|
||||||
|
@ -2365,7 +2364,9 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
|
|
||||||
def rerenderComboBoxSendFrom(self):
|
def rerenderComboBoxSendFrom(self):
|
||||||
self.ui.comboBoxSendFrom.clear()
|
self.ui.comboBoxSendFrom.clear()
|
||||||
for addressInKeysFile in getSortedAccounts():
|
for addressInKeysFile in config.addresses(True):
|
||||||
|
# I realize that this is poor programming practice but I don't care.
|
||||||
|
# It's easier for others to read.
|
||||||
isEnabled = config.getboolean(
|
isEnabled = config.getboolean(
|
||||||
addressInKeysFile, 'enabled')
|
addressInKeysFile, 'enabled')
|
||||||
isMaillinglist = config.safeGetBoolean(addressInKeysFile, 'mailinglist')
|
isMaillinglist = config.safeGetBoolean(addressInKeysFile, 'mailinglist')
|
||||||
|
@ -2389,7 +2390,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
|
|
||||||
def rerenderComboBoxSendFromBroadcast(self):
|
def rerenderComboBoxSendFromBroadcast(self):
|
||||||
self.ui.comboBoxSendFromBroadcast.clear()
|
self.ui.comboBoxSendFromBroadcast.clear()
|
||||||
for addressInKeysFile in getSortedAccounts():
|
for addressInKeysFile in config.addresses(True):
|
||||||
isEnabled = config.getboolean(
|
isEnabled = config.getboolean(
|
||||||
addressInKeysFile, 'enabled')
|
addressInKeysFile, 'enabled')
|
||||||
isChan = config.safeGetBoolean(addressInKeysFile, 'chan')
|
isChan = config.safeGetBoolean(addressInKeysFile, 'chan')
|
||||||
|
|
|
@ -25,25 +25,6 @@ from .foldertree import AccountMixin
|
||||||
from .utils import str_broadcast_subscribers
|
from .utils import str_broadcast_subscribers
|
||||||
|
|
||||||
|
|
||||||
def getSortedAccounts():
|
|
||||||
"""Get a sorted list of configSections"""
|
|
||||||
|
|
||||||
configSections = config.addresses()
|
|
||||||
configSections.sort(
|
|
||||||
cmp=lambda x, y: cmp(
|
|
||||||
unicode(
|
|
||||||
config.get(
|
|
||||||
x,
|
|
||||||
'label'),
|
|
||||||
'utf-8').lower(),
|
|
||||||
unicode(
|
|
||||||
config.get(
|
|
||||||
y,
|
|
||||||
'label'),
|
|
||||||
'utf-8').lower()))
|
|
||||||
return configSections
|
|
||||||
|
|
||||||
|
|
||||||
def getSortedSubscriptions(count=False):
|
def getSortedSubscriptions(count=False):
|
||||||
"""
|
"""
|
||||||
Actually return a grouped dictionary rather than a sorted list
|
Actually return a grouped dictionary rather than a sorted list
|
||||||
|
|
|
@ -9,8 +9,9 @@ from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
import queues
|
import queues
|
||||||
import widgets
|
import widgets
|
||||||
from account import AccountMixin, GatewayAccount, MailchuckAccount, accountClass, getSortedAccounts
|
from account import AccountMixin, GatewayAccount, MailchuckAccount, accountClass
|
||||||
from addresses import addBMIfNotPresent, decodeAddress, encodeVarint
|
from addresses import addBMIfNotPresent, decodeAddress, encodeVarint
|
||||||
|
from bmconfigparser import config
|
||||||
from inventory import Inventory
|
from inventory import Inventory
|
||||||
from tr import _translate
|
from tr import _translate
|
||||||
|
|
||||||
|
@ -120,7 +121,7 @@ class NewAddressDialog(QtGui.QDialog):
|
||||||
|
|
||||||
# Let's fill out the 'existing address' combo box with addresses
|
# Let's fill out the 'existing address' combo box with addresses
|
||||||
# from the 'Your Identities' tab.
|
# from the 'Your Identities' tab.
|
||||||
for address in getSortedAccounts():
|
for address in config.addresses(True):
|
||||||
self.radioButtonExisting.click()
|
self.radioButtonExisting.click()
|
||||||
self.comboBoxExisting.addItem(address)
|
self.comboBoxExisting.addItem(address)
|
||||||
self.groupBoxDeterministic.setHidden(True)
|
self.groupBoxDeterministic.setHidden(True)
|
||||||
|
|
|
@ -3,11 +3,12 @@ Address validator module.
|
||||||
"""
|
"""
|
||||||
# pylint: disable=too-many-branches,too-many-arguments
|
# pylint: disable=too-many-branches,too-many-arguments
|
||||||
|
|
||||||
from PyQt4 import QtGui
|
|
||||||
from Queue import Empty
|
from Queue import Empty
|
||||||
|
|
||||||
from account import getSortedAccounts
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
from addresses import decodeAddress, addBMIfNotPresent
|
from addresses import decodeAddress, addBMIfNotPresent
|
||||||
|
from bmconfigparser import config
|
||||||
from queues import apiAddressGeneratorReturnQueue, addressGeneratorQueue
|
from queues import apiAddressGeneratorReturnQueue, addressGeneratorQueue
|
||||||
from tr import _translate
|
from tr import _translate
|
||||||
from utils import str_chan
|
from utils import str_chan
|
||||||
|
@ -124,7 +125,7 @@ class AddressPassPhraseValidatorMixin(object):
|
||||||
|
|
||||||
if self.addressMandatory or address is not None:
|
if self.addressMandatory or address is not None:
|
||||||
# check if address already exists:
|
# check if address already exists:
|
||||||
if address in getSortedAccounts():
|
if address in config.addresses():
|
||||||
self.setError(_translate("AddressValidator", "Address already present as one of your identities."))
|
self.setError(_translate("AddressValidator", "Address already present as one of your identities."))
|
||||||
return (QtGui.QValidator.Intermediate, pos)
|
return (QtGui.QValidator.Intermediate, pos)
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ def checkAddressBook(myapp):
|
||||||
|
|
||||||
|
|
||||||
def checkHasNormalAddress():
|
def checkHasNormalAddress():
|
||||||
for address in account.getSortedAccounts():
|
for address in config.addresses():
|
||||||
acct = account.accountClass(address)
|
acct = account.accountClass(address)
|
||||||
if acct.type == AccountMixin.NORMAL and config.safeGetBoolean(address, 'enabled'):
|
if acct.type == AccountMixin.NORMAL and config.safeGetBoolean(address, 'enabled'):
|
||||||
return address
|
return address
|
||||||
|
|
|
@ -110,9 +110,12 @@ class BMConfigParser(SafeConfigParser):
|
||||||
if filenames:
|
if filenames:
|
||||||
SafeConfigParser.read(self, filenames)
|
SafeConfigParser.read(self, filenames)
|
||||||
|
|
||||||
def addresses(self):
|
def addresses(self, sort=False):
|
||||||
"""Return a list of local bitmessage addresses (from section labels)"""
|
"""Return a list of local bitmessage addresses (from section labels)"""
|
||||||
return [x for x in self.sections() if x.startswith('BM-')]
|
sections = [x for x in self.sections() if x.startswith('BM-')]
|
||||||
|
if sort:
|
||||||
|
sections.sort(key=lambda item: self.get(item, 'label').lower())
|
||||||
|
return sections
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""Save the runtime config onto the filesystem"""
|
"""Save the runtime config onto the filesystem"""
|
||||||
|
|
Reference in New Issue
Block a user