This is probably the right way to handle modal dialogs
This commit is contained in:
parent
41155406d6
commit
afcd83a434
|
@ -2225,44 +2225,31 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
if hasattr(acct, "feedback") \
|
if hasattr(acct, "feedback") \
|
||||||
and acct.feedback != GatewayAccount.ALL_OK:
|
and acct.feedback != GatewayAccount.ALL_OK:
|
||||||
if acct.feedback == GatewayAccount.REGISTRATION_DENIED:
|
if acct.feedback == GatewayAccount.REGISTRATION_DENIED:
|
||||||
dialog = dialogs.EmailGatewayDialog(
|
dialogs.EmailGatewayDialog(
|
||||||
self,
|
self, BMConfigParser(), acct).exec_()
|
||||||
_translate(
|
|
||||||
"EmailGatewayRegistrationDialog",
|
|
||||||
"Registration failed:"),
|
|
||||||
_translate(
|
|
||||||
"EmailGatewayRegistrationDialog",
|
|
||||||
"The requested email address is not available,"
|
|
||||||
" please try a new one."),
|
|
||||||
config=BMConfigParser()
|
|
||||||
)
|
|
||||||
if dialog.exec_():
|
|
||||||
dialog.register(acct)
|
|
||||||
|
|
||||||
def click_pushButtonAddAddressBook(self, dialog=None):
|
def click_pushButtonAddAddressBook(self, dialog=None):
|
||||||
if not dialog:
|
if not dialog:
|
||||||
dialog = dialogs.AddAddressDialog(self)
|
dialog = dialogs.AddAddressDialog(self)
|
||||||
if dialog.exec_():
|
dialog.exec_()
|
||||||
if not dialog.valid:
|
try:
|
||||||
self.updateStatusBar(_translate(
|
address, label = dialog.data
|
||||||
"MainWindow",
|
except AttributeError:
|
||||||
"The address you entered was invalid. Ignoring it."
|
return
|
||||||
))
|
|
||||||
return
|
# First we must check to see if the address is already in the
|
||||||
address = addBMIfNotPresent(str(dialog.lineEditAddress.text()))
|
# address book. The user cannot add it again or else it will
|
||||||
# First we must check to see if the address is already in the
|
# cause problems when updating and deleting the entry.
|
||||||
# address book. The user cannot add it again or else it will
|
if shared.isAddressInMyAddressBook(address):
|
||||||
# cause problems when updating and deleting the entry.
|
self.updateStatusBar(_translate(
|
||||||
if shared.isAddressInMyAddressBook(address):
|
"MainWindow",
|
||||||
self.updateStatusBar(_translate(
|
"Error: You cannot add the same address to your"
|
||||||
"MainWindow",
|
" address book twice. Try renaming the existing one"
|
||||||
"Error: You cannot add the same address to your"
|
" if you want."
|
||||||
" address book twice. Try renaming the existing one"
|
))
|
||||||
" if you want."
|
return
|
||||||
))
|
|
||||||
return
|
self.addEntryToAddressBook(address, label)
|
||||||
label = str(dialog.lineEditLabel.text().toUtf8())
|
|
||||||
self.addEntryToAddressBook(address, label)
|
|
||||||
|
|
||||||
def addEntryToAddressBook(self, address, label):
|
def addEntryToAddressBook(self, address, label):
|
||||||
if shared.isAddressInMyAddressBook(address):
|
if shared.isAddressInMyAddressBook(address):
|
||||||
|
@ -2289,35 +2276,33 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
|
|
||||||
def click_pushButtonAddSubscription(self):
|
def click_pushButtonAddSubscription(self):
|
||||||
dialog = dialogs.NewSubscriptionDialog(self)
|
dialog = dialogs.NewSubscriptionDialog(self)
|
||||||
if dialog.exec_():
|
dialog.exec_()
|
||||||
if not dialog.valid:
|
try:
|
||||||
self.updateStatusBar(_translate(
|
address, label = dialog.data
|
||||||
"MainWindow",
|
except AttributeError:
|
||||||
"The address you entered was invalid. Ignoring it."
|
return
|
||||||
|
|
||||||
|
# We must check to see if the address is already in the
|
||||||
|
# subscriptions list. The user cannot add it again or else it
|
||||||
|
# will cause problems when updating and deleting the entry.
|
||||||
|
if shared.isAddressInMySubscriptionsList(address):
|
||||||
|
self.updateStatusBar(_translate(
|
||||||
|
"MainWindow",
|
||||||
|
"Error: You cannot add the same address to your"
|
||||||
|
" subscriptions twice. Perhaps rename the existing one"
|
||||||
|
" if you want."
|
||||||
|
))
|
||||||
|
return
|
||||||
|
|
||||||
|
self.addSubscription(address, label)
|
||||||
|
# Now, if the user wants to display old broadcasts, let's get
|
||||||
|
# them out of the inventory and put them
|
||||||
|
# to the objectProcessorQueue to be processed
|
||||||
|
if dialog.checkBoxDisplayMessagesAlreadyInInventory.isChecked():
|
||||||
|
for value in dialog.recent:
|
||||||
|
queues.objectProcessorQueue.put((
|
||||||
|
value.type, value.payload
|
||||||
))
|
))
|
||||||
return
|
|
||||||
address = addBMIfNotPresent(str(dialog.lineEditAddress.text()))
|
|
||||||
# We must check to see if the address is already in the
|
|
||||||
# subscriptions list. The user cannot add it again or else it
|
|
||||||
# will cause problems when updating and deleting the entry.
|
|
||||||
if shared.isAddressInMySubscriptionsList(address):
|
|
||||||
self.updateStatusBar(_translate(
|
|
||||||
"MainWindow",
|
|
||||||
"Error: You cannot add the same address to your"
|
|
||||||
" subscriptions twice. Perhaps rename the existing one"
|
|
||||||
" if you want."
|
|
||||||
))
|
|
||||||
return
|
|
||||||
label = str(dialog.lineEditLabel.text().toUtf8())
|
|
||||||
self.addSubscription(address, label)
|
|
||||||
# Now, if the user wants to display old broadcasts, let's get
|
|
||||||
# them out of the inventory and put them
|
|
||||||
# to the objectProcessorQueue to be processed
|
|
||||||
if dialog.checkBoxDisplayMessagesAlreadyInInventory.isChecked():
|
|
||||||
for value in dialog.recent:
|
|
||||||
queues.objectProcessorQueue.put((
|
|
||||||
value.type, value.payload
|
|
||||||
))
|
|
||||||
|
|
||||||
def click_pushButtonStatusIcon(self):
|
def click_pushButtonStatusIcon(self):
|
||||||
dialogs.IconGlossaryDialog(self, config=BMConfigParser()).exec_()
|
dialogs.IconGlossaryDialog(self, config=BMConfigParser()).exec_()
|
||||||
|
@ -2557,29 +2542,32 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
def on_action_EmailGatewayDialog(self):
|
def on_action_EmailGatewayDialog(self):
|
||||||
dialog = dialogs.EmailGatewayDialog(self, config=BMConfigParser())
|
dialog = dialogs.EmailGatewayDialog(self, config=BMConfigParser())
|
||||||
# For Modal dialogs
|
# For Modal dialogs
|
||||||
acct = dialog.exec_()
|
dialog.exec_()
|
||||||
|
try:
|
||||||
|
acct = dialog.data
|
||||||
|
except AttributeError:
|
||||||
|
return
|
||||||
|
|
||||||
# Only settings ramain here
|
# Only settings remain here
|
||||||
if acct:
|
acct.settings()
|
||||||
acct.settings()
|
for i in range(self.ui.comboBoxSendFrom.count()):
|
||||||
for i in range(self.ui.comboBoxSendFrom.count()):
|
if str(self.ui.comboBoxSendFrom.itemData(i).toPyObject()) \
|
||||||
if str(self.ui.comboBoxSendFrom.itemData(i).toPyObject()) \
|
== acct.fromAddress:
|
||||||
== acct.fromAddress:
|
self.ui.comboBoxSendFrom.setCurrentIndex(i)
|
||||||
self.ui.comboBoxSendFrom.setCurrentIndex(i)
|
break
|
||||||
break
|
else:
|
||||||
else:
|
self.ui.comboBoxSendFrom.setCurrentIndex(0)
|
||||||
self.ui.comboBoxSendFrom.setCurrentIndex(0)
|
|
||||||
|
|
||||||
self.ui.lineEditTo.setText(acct.toAddress)
|
self.ui.lineEditTo.setText(acct.toAddress)
|
||||||
self.ui.lineEditSubject.setText(acct.subject)
|
self.ui.lineEditSubject.setText(acct.subject)
|
||||||
self.ui.textEditMessage.setText(acct.message)
|
self.ui.textEditMessage.setText(acct.message)
|
||||||
self.ui.tabWidgetSend.setCurrentIndex(
|
self.ui.tabWidgetSend.setCurrentIndex(
|
||||||
self.ui.tabWidgetSend.indexOf(self.ui.sendDirect)
|
self.ui.tabWidgetSend.indexOf(self.ui.sendDirect)
|
||||||
)
|
)
|
||||||
self.ui.tabWidget.setCurrentIndex(
|
self.ui.tabWidget.setCurrentIndex(
|
||||||
self.ui.tabWidget.indexOf(self.ui.send)
|
self.ui.tabWidget.indexOf(self.ui.send)
|
||||||
)
|
)
|
||||||
self.ui.textEditMessage.setFocus()
|
self.ui.textEditMessage.setFocus()
|
||||||
|
|
||||||
def on_action_MarkAllRead(self):
|
def on_action_MarkAllRead(self):
|
||||||
if QtGui.QMessageBox.question(
|
if QtGui.QMessageBox.question(
|
||||||
|
@ -2621,53 +2609,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
addressAtCurrentRow, self.getCurrentFolder(), None, 0)
|
addressAtCurrentRow, self.getCurrentFolder(), None, 0)
|
||||||
|
|
||||||
def click_NewAddressDialog(self):
|
def click_NewAddressDialog(self):
|
||||||
dialog = dialogs.NewAddressDialog(self)
|
dialogs.NewAddressDialog(self)
|
||||||
# For Modal dialogs
|
|
||||||
if not dialog.exec_():
|
|
||||||
logger.debug('new address dialog box rejected')
|
|
||||||
return
|
|
||||||
|
|
||||||
# dialog.buttonBox.enabled = False
|
|
||||||
if dialog.radioButtonRandomAddress.isChecked():
|
|
||||||
if dialog.radioButtonMostAvailable.isChecked():
|
|
||||||
streamNumberForAddress = 1
|
|
||||||
else:
|
|
||||||
# User selected 'Use the same stream as an existing
|
|
||||||
# address.'
|
|
||||||
streamNumberForAddress = decodeAddress(
|
|
||||||
dialog.comboBoxExisting.currentText())[2]
|
|
||||||
queues.addressGeneratorQueue.put((
|
|
||||||
'createRandomAddress', 4, streamNumberForAddress,
|
|
||||||
str(dialog.newaddresslabel.text().toUtf8()), 1, "",
|
|
||||||
dialog.checkBoxEighteenByteRipe.isChecked()
|
|
||||||
))
|
|
||||||
else:
|
|
||||||
if dialog.lineEditPassphrase.text() != \
|
|
||||||
dialog.lineEditPassphraseAgain.text():
|
|
||||||
QtGui.QMessageBox.about(
|
|
||||||
self, _translate("MainWindow", "Passphrase mismatch"),
|
|
||||||
_translate(
|
|
||||||
"MainWindow",
|
|
||||||
"The passphrase you entered twice doesn\'t"
|
|
||||||
" match. Try again.")
|
|
||||||
)
|
|
||||||
elif dialog.lineEditPassphrase.text() == "":
|
|
||||||
QtGui.QMessageBox.about(
|
|
||||||
self, _translate("MainWindow", "Choose a passphrase"),
|
|
||||||
_translate(
|
|
||||||
"MainWindow", "You really do need a passphrase.")
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# this will eventually have to be replaced by logic
|
|
||||||
# to determine the most available stream number.
|
|
||||||
streamNumberForAddress = 1
|
|
||||||
queues.addressGeneratorQueue.put((
|
|
||||||
'createDeterministicAddresses', 4, streamNumberForAddress,
|
|
||||||
"unused deterministic address",
|
|
||||||
dialog.spinBoxNumberOfAddressesToMake.value(),
|
|
||||||
dialog.lineEditPassphrase.text().toUtf8(),
|
|
||||||
dialog.checkBoxEighteenByteRipe.isChecked()
|
|
||||||
))
|
|
||||||
|
|
||||||
def network_switch(self):
|
def network_switch(self):
|
||||||
dontconnect_option = not BMConfigParser().safeGetBoolean(
|
dontconnect_option = not BMConfigParser().safeGetBoolean(
|
||||||
|
@ -3063,9 +3005,8 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
self.ui.tabWidget.setCurrentIndex(
|
self.ui.tabWidget.setCurrentIndex(
|
||||||
self.ui.tabWidget.indexOf(self.ui.send)
|
self.ui.tabWidget.indexOf(self.ui.send)
|
||||||
)
|
)
|
||||||
dialog = dialogs.AddAddressDialog(self)
|
self.click_pushButtonAddAddressBook(
|
||||||
dialog.lineEditAddress.setText(addressAtCurrentInboxRow)
|
dialogs.AddAddressDialog(self, addressAtCurrentInboxRow))
|
||||||
self.click_pushButtonAddAddressBook(dialog)
|
|
||||||
|
|
||||||
def on_action_InboxAddSenderToBlackList(self):
|
def on_action_InboxAddSenderToBlackList(self):
|
||||||
tableWidget = self.getCurrentMessagelist()
|
tableWidget = self.getCurrentMessagelist()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
from addresses import decodeAddress, encodeVarint
|
from addresses import decodeAddress, encodeVarint, addBMIfNotPresent
|
||||||
from account import (
|
from account import (
|
||||||
GatewayAccount, MailchuckAccount, AccountMixin, accountClass,
|
GatewayAccount, MailchuckAccount, AccountMixin, accountClass,
|
||||||
getSortedAccounts
|
getSortedAccounts
|
||||||
|
@ -70,12 +70,33 @@ class AddressCheckMixin(object):
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
class AddAddressDialog(QtGui.QDialog, RetranslateMixin, AddressCheckMixin):
|
class AddressDataDialog(QtGui.QDialog, AddressCheckMixin):
|
||||||
|
def __init__(self, parent):
|
||||||
|
super(AddressDataDialog, self).__init__(parent)
|
||||||
|
self.parent = parent
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def accept(self):
|
||||||
|
if self.valid:
|
||||||
|
self.data = (
|
||||||
|
addBMIfNotPresent(str(self.lineEditAddress.text())),
|
||||||
|
str(self.lineEditLabel.text().toUtf8())
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
queues.UISignalQueue.put(('updateStatusBar', _translate(
|
||||||
|
"MainWindow",
|
||||||
|
"The address you entered was invalid. Ignoring it."
|
||||||
|
)))
|
||||||
|
super(AddressDataDialog, self).accept()
|
||||||
|
|
||||||
|
|
||||||
|
class AddAddressDialog(AddressDataDialog, RetranslateMixin):
|
||||||
|
|
||||||
|
def __init__(self, parent=None, address=None):
|
||||||
super(AddAddressDialog, self).__init__(parent)
|
super(AddAddressDialog, self).__init__(parent)
|
||||||
widgets.load('addaddressdialog.ui', self)
|
widgets.load('addaddressdialog.ui', self)
|
||||||
AddressCheckMixin.__init__(self)
|
AddressCheckMixin.__init__(self)
|
||||||
|
if address:
|
||||||
|
self.lineEditAddress.setText(address)
|
||||||
|
|
||||||
|
|
||||||
class NewAddressDialog(QtGui.QDialog, RetranslateMixin):
|
class NewAddressDialog(QtGui.QDialog, RetranslateMixin):
|
||||||
|
@ -91,10 +112,54 @@ class NewAddressDialog(QtGui.QDialog, RetranslateMixin):
|
||||||
self.comboBoxExisting.addItem(address)
|
self.comboBoxExisting.addItem(address)
|
||||||
self.groupBoxDeterministic.setHidden(True)
|
self.groupBoxDeterministic.setHidden(True)
|
||||||
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
|
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
|
||||||
|
self.show()
|
||||||
|
|
||||||
|
def accept(self):
|
||||||
|
self.hide()
|
||||||
|
# self.buttonBox.enabled = False
|
||||||
|
if self.radioButtonRandomAddress.isChecked():
|
||||||
|
if self.radioButtonMostAvailable.isChecked():
|
||||||
|
streamNumberForAddress = 1
|
||||||
|
else:
|
||||||
|
# User selected 'Use the same stream as an existing
|
||||||
|
# address.'
|
||||||
|
streamNumberForAddress = decodeAddress(
|
||||||
|
self.comboBoxExisting.currentText())[2]
|
||||||
|
queues.addressGeneratorQueue.put((
|
||||||
|
'createRandomAddress', 4, streamNumberForAddress,
|
||||||
|
str(self.newaddresslabel.text().toUtf8()), 1, "",
|
||||||
|
self.checkBoxEighteenByteRipe.isChecked()
|
||||||
|
))
|
||||||
|
else:
|
||||||
|
if self.lineEditPassphrase.text() != \
|
||||||
|
self.lineEditPassphraseAgain.text():
|
||||||
|
QtGui.QMessageBox.about(
|
||||||
|
self, _translate("MainWindow", "Passphrase mismatch"),
|
||||||
|
_translate(
|
||||||
|
"MainWindow",
|
||||||
|
"The passphrase you entered twice doesn\'t"
|
||||||
|
" match. Try again.")
|
||||||
|
)
|
||||||
|
elif self.lineEditPassphrase.text() == "":
|
||||||
|
QtGui.QMessageBox.about(
|
||||||
|
self, _translate("MainWindow", "Choose a passphrase"),
|
||||||
|
_translate(
|
||||||
|
"MainWindow", "You really do need a passphrase.")
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# this will eventually have to be replaced by logic
|
||||||
|
# to determine the most available stream number.
|
||||||
|
streamNumberForAddress = 1
|
||||||
|
queues.addressGeneratorQueue.put((
|
||||||
|
'createDeterministicAddresses', 4, streamNumberForAddress,
|
||||||
|
"unused deterministic address",
|
||||||
|
self.spinBoxNumberOfAddressesToMake.value(),
|
||||||
|
self.lineEditPassphrase.text().toUtf8(),
|
||||||
|
self.checkBoxEighteenByteRipe.isChecked()
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
class NewSubscriptionDialog(
|
class NewSubscriptionDialog(AddressDataDialog, RetranslateMixin):
|
||||||
QtGui.QDialog, RetranslateMixin, AddressCheckMixin):
|
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super(NewSubscriptionDialog, self).__init__(parent)
|
super(NewSubscriptionDialog, self).__init__(parent)
|
||||||
|
@ -206,14 +271,20 @@ class SpecialAddressBehaviorDialog(QtGui.QDialog, RetranslateMixin):
|
||||||
|
|
||||||
|
|
||||||
class EmailGatewayDialog(QtGui.QDialog, RetranslateMixin):
|
class EmailGatewayDialog(QtGui.QDialog, RetranslateMixin):
|
||||||
def __init__(self, parent, title=None, label=None, config=None):
|
def __init__(self, parent, config=None, account=None):
|
||||||
super(EmailGatewayDialog, self).__init__(parent)
|
super(EmailGatewayDialog, self).__init__(parent)
|
||||||
widgets.load('emailgateway.ui', self)
|
widgets.load('emailgateway.ui', self)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.config = config
|
self.config = config
|
||||||
if title and label:
|
if account:
|
||||||
self.setWindowTitle(title)
|
self.acct = account
|
||||||
self.label.setText(label)
|
self.setWindowTitle(_translate(
|
||||||
|
"EmailGatewayDialog", "Registration failed:"))
|
||||||
|
self.label.setText(_translate(
|
||||||
|
"EmailGatewayDialog",
|
||||||
|
"The requested email address is not available,"
|
||||||
|
" please try a new one."
|
||||||
|
))
|
||||||
self.radioButtonRegister.hide()
|
self.radioButtonRegister.hide()
|
||||||
self.radioButtonStatus.hide()
|
self.radioButtonStatus.hide()
|
||||||
self.radioButtonSettings.hide()
|
self.radioButtonSettings.hide()
|
||||||
|
@ -239,17 +310,6 @@ class EmailGatewayDialog(QtGui.QDialog, RetranslateMixin):
|
||||||
self.lineEditEmail.setFocus()
|
self.lineEditEmail.setFocus()
|
||||||
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
|
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
|
||||||
|
|
||||||
def register(self, acct=None):
|
|
||||||
email = str(self.lineEditEmail.text().toUtf8())
|
|
||||||
if acct is None:
|
|
||||||
acct = self.acct
|
|
||||||
acct.register(email)
|
|
||||||
self.config.set(acct.fromAddress, 'label', email)
|
|
||||||
self.config.set(acct.fromAddress, 'gateway', 'mailchuck')
|
|
||||||
self.config.save()
|
|
||||||
self.parent.statusbar_message(
|
|
||||||
"Sending email gateway registration request")
|
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
self.hide()
|
self.hide()
|
||||||
# no chans / mailinglists
|
# no chans / mailinglists
|
||||||
|
@ -259,8 +319,17 @@ class EmailGatewayDialog(QtGui.QDialog, RetranslateMixin):
|
||||||
if not isinstance(self.acct, GatewayAccount):
|
if not isinstance(self.acct, GatewayAccount):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.radioButtonRegister.isChecked():
|
if self.radioButtonRegister.isChecked() \
|
||||||
self.register()
|
or self.radioButtonRegister.isHidden():
|
||||||
|
email = str(self.lineEditEmail.text().toUtf8())
|
||||||
|
self.acct.register(email)
|
||||||
|
self.config.set(self.acct.fromAddress, 'label', email)
|
||||||
|
self.config.set(self.acct.fromAddress, 'gateway', 'mailchuck')
|
||||||
|
self.config.save()
|
||||||
|
queues.UISignalQueue.put(('updateStatusBar', _translate(
|
||||||
|
"EmailGatewayDialog",
|
||||||
|
"Sending email gateway registration request"
|
||||||
|
)))
|
||||||
elif self.radioButtonUnregister.isChecked():
|
elif self.radioButtonUnregister.isChecked():
|
||||||
self.acct.unregister()
|
self.acct.unregister()
|
||||||
self.config.remove_option(self.acct.fromAddress, 'gateway')
|
self.config.remove_option(self.acct.fromAddress, 'gateway')
|
||||||
|
@ -276,4 +345,6 @@ class EmailGatewayDialog(QtGui.QDialog, RetranslateMixin):
|
||||||
"Sending email gateway status request"
|
"Sending email gateway status request"
|
||||||
)))
|
)))
|
||||||
elif self.radioButtonSettings.isChecked():
|
elif self.radioButtonSettings.isChecked():
|
||||||
return self.acct
|
self.data = self.acct
|
||||||
|
|
||||||
|
super(EmailGatewayDialog, self).accept()
|
||||||
|
|
Reference in New Issue
Block a user