UI refactoring (part 1) #1092

Merged
g1itch merged 20 commits from ui-refactoring into v0.6 2018-01-30 17:32:38 +01:00
4 changed files with 191 additions and 212 deletions
Showing only changes of commit 8109fa7ece - Show all commits

View File

@ -29,7 +29,6 @@ from migrationwizard import *
from foldertree import *
from newchandialog import *
from safehtmlparser import *
from emailgateway import *
from settings import *
import settingsmixin
import support
@ -2155,20 +2154,22 @@ class MyForm(settingsmixin.SMainWindow):
# whether it's in current message list or not
self.indicatorUpdate(True, to_label=acct.toLabel)
# cannot find item to pass here ):
if hasattr(acct, "feedback") and acct.feedback != GatewayAccount.ALL_OK:
if hasattr(acct, "feedback") \
and acct.feedback != GatewayAccount.ALL_OK:
if acct.feedback == GatewayAccount.REGISTRATION_DENIED:
self.dialog = EmailGatewayRegistrationDialog(self, _translate("EmailGatewayRegistrationDialog", "Registration failed:"),
_translate("EmailGatewayRegistrationDialog", "The requested email address is not available, please try a new one. Fill out the new desired email address (including @mailchuck.com) below:")
)
if self.dialog.exec_():
email = str(self.dialog.ui.lineEditEmail.text().toUtf8())
# register resets address variables
acct.register(email)
BMConfigParser().set(acct.fromAddress, 'label', email)
BMConfigParser().set(acct.fromAddress, 'gateway', 'mailchuck')
BMConfigParser().save()
self.statusBar().showMessage(_translate(
"MainWindow", "Sending email gateway registration request"), 10000)
dialog = dialogs.EmailGatewayDialog(
self,
_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):
if not dialog:
@ -2488,56 +2489,31 @@ class MyForm(settingsmixin.SMainWindow):
dialogs.SpecialAddressBehaviorDialog(self, BMConfigParser())
def on_action_EmailGatewayDialog(self):
self.dialog = EmailGatewayDialog(self)
dialog = dialogs.EmailGatewayDialog(self, config=BMConfigParser())
# For Modal dialogs
if self.dialog.exec_():
addressAtCurrentRow = self.getCurrentAccount()
acct = accountClass(addressAtCurrentRow)
# no chans / mailinglists
if acct.type != AccountMixin.NORMAL:
return
if self.dialog.ui.radioButtonUnregister.isChecked() and isinstance(acct, GatewayAccount):
acct.unregister()
BMConfigParser().remove_option(addressAtCurrentRow, 'gateway')
BMConfigParser().save()
self.statusBar().showMessage(_translate(
"MainWindow", "Sending email gateway unregistration request"), 10000)
elif self.dialog.ui.radioButtonStatus.isChecked() and isinstance(acct, GatewayAccount):
acct.status()
self.statusBar().showMessage(_translate(
"MainWindow", "Sending email gateway status request"), 10000)
elif self.dialog.ui.radioButtonSettings.isChecked() and isinstance(acct, GatewayAccount):
acct.settings()
listOfAddressesInComboBoxSendFrom = [str(self.ui.comboBoxSendFrom.itemData(i).toPyObject()) for i in range(self.ui.comboBoxSendFrom.count())]
if acct.fromAddress in listOfAddressesInComboBoxSendFrom:
currentIndex = listOfAddressesInComboBoxSendFrom.index(acct.fromAddress)
self.ui.comboBoxSendFrom.setCurrentIndex(currentIndex)
else:
self.ui.comboBoxSendFrom.setCurrentIndex(0)
self.ui.lineEditTo.setText(acct.toAddress)
self.ui.lineEditSubject.setText(acct.subject)
self.ui.textEditMessage.setText(acct.message)
self.ui.tabWidgetSend.setCurrentIndex(
self.ui.tabWidgetSend.indexOf(self.ui.sendDirect)
)
self.ui.tabWidget.setCurrentIndex(
self.ui.tabWidget.indexOf(self.ui.send)
)
self.ui.textEditMessage.setFocus()
elif self.dialog.ui.radioButtonRegister.isChecked():
email = str(self.dialog.ui.lineEditEmail.text().toUtf8())
acct = MailchuckAccount(addressAtCurrentRow)
acct.register(email)
BMConfigParser().set(addressAtCurrentRow, 'label', email)
BMConfigParser().set(addressAtCurrentRow, 'gateway', 'mailchuck')
BMConfigParser().save()
self.statusBar().showMessage(_translate(
"MainWindow", "Sending email gateway registration request"), 10000)
acct = dialog.exec_()
# Only settings ramain here
if acct:
acct.settings()
for i in range(self.ui.comboBoxSendFrom.count()):
if str(self.ui.comboBoxSendFrom.itemData(i).toPyObject()) \
== acct.fromAddress:
self.ui.comboBoxSendFrom.setCurrentIndex(i)
break
else:
pass
#print "well nothing"
# shared.writeKeysFile()
# self.rerenderInboxToLabels()
self.ui.comboBoxSendFrom.setCurrentIndex(0)
self.ui.lineEditTo.setText(acct.toAddress)
self.ui.lineEditSubject.setText(acct.subject)
self.ui.textEditMessage.setText(acct.message)
self.ui.tabWidgetSend.setCurrentIndex(
self.ui.tabWidgetSend.indexOf(self.ui.sendDirect)
)
self.ui.tabWidget.setCurrentIndex(
self.ui.tabWidget.indexOf(self.ui.send)
)
self.ui.textEditMessage.setFocus()
def on_action_MarkAllRead(self):
if QtGui.QMessageBox.question(
@ -4210,44 +4186,6 @@ class settingsDialog(QtGui.QDialog):
self.parent.ui.pushButtonFetchNamecoinID.show()
class EmailGatewayDialog(QtGui.QDialog):
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_EmailGatewayDialog()
self.ui.setupUi(self)
self.parent = parent
addressAtCurrentRow = parent.getCurrentAccount()
acct = accountClass(addressAtCurrentRow)
if isinstance(acct, GatewayAccount):
self.ui.radioButtonUnregister.setEnabled(True)
self.ui.radioButtonStatus.setEnabled(True)
self.ui.radioButtonStatus.setChecked(True)
self.ui.radioButtonSettings.setEnabled(True)
else:
self.ui.radioButtonStatus.setEnabled(False)
self.ui.radioButtonSettings.setEnabled(False)
self.ui.radioButtonUnregister.setEnabled(False)
label = BMConfigParser().get(addressAtCurrentRow, 'label')
if label.find("@mailchuck.com") > -1:
self.ui.lineEditEmail.setText(label)
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
class EmailGatewayRegistrationDialog(QtGui.QDialog):
def __init__(self, parent, title, label):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_EmailGatewayRegistrationDialog()
self.ui.setupUi(self)
self.parent = parent
self.setWindowTitle(title)
self.ui.label.setText(label)
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
class NewAddressDialog(QtGui.QDialog):
def __init__(self, parent):

View File

@ -1,5 +1,6 @@
from PyQt4 import QtCore, QtGui
from addresses import decodeAddress, encodeVarint
from account import GatewayAccount, MailchuckAccount, AccountMixin, accountClass
from tr import _translate
from retranslateui import RetranslateMixin
import widgets
@ -235,3 +236,79 @@ class SpecialAddressBehaviorDialog(QtGui.QDialog, RetranslateMixin):
self.parent.rerenderComboBoxSendFromBroadcast()
self.config.save()
self.parent.rerenderMessagelistToLabels()
class EmailGatewayDialog(QtGui.QDialog, RetranslateMixin):
def __init__(self, parent, title=None, label=None, config=None):
super(EmailGatewayDialog, self).__init__(parent)
widgets.load('emailgateway.ui', self)
self.parent = parent
self.config = config
if title and label:
self.setWindowTitle(title)
self.label.setText(label)
self.radioButtonRegister.hide()
self.radioButtonStatus.hide()
self.radioButtonSettings.hide()
self.radioButtonUnregister.hide()
else:
address = parent.getCurrentAccount()
self.acct = accountClass(address)
try:
label = config.get(address, 'label')
except AttributeError:
pass
else:
if "@" in label:
self.lineEditEmail.setText(label)
if isinstance(self.acct, GatewayAccount):
self.radioButtonUnregister.setEnabled(True)
self.radioButtonStatus.setEnabled(True)
self.radioButtonStatus.setChecked(True)
self.radioButtonSettings.setEnabled(True)
self.lineEditEmail.setEnabled(False)
else:
self.acct = MailchuckAccount(address)
self.lineEditEmail.setFocus()
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().showMessage(_translate(
"MainWindow",
"Sending email gateway registration request"
), 10000)
def accept(self):
self.hide()
# no chans / mailinglists
if self.acct.type != AccountMixin.NORMAL:
return
if not isinstance(self.acct, GatewayAccount):
return
if self.radioButtonRegister.isChecked():
self.register()
elif self.radioButtonUnregister.isChecked():
self.acct.unregister()
self.config.remove_option(self.acct.fromAddress, 'gateway')
self.config.save()
self.parent.statusBar().showMessage(_translate(
"MainWindow",
"Sending email gateway unregistration request"
), 10000)
elif self.radioButtonStatus.isChecked():
self.acct.status()
self.parent.statusBar().showMessage(_translate(
"MainWindow",
"Sending email gateway status request"
), 10000)
elif self.radioButtonSettings.isChecked():
return self.acct

View File

@ -1,103 +0,0 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'emailgateway.ui'
#
# Created: Fri Apr 26 17:43:31 2013
# by: PyQt4 UI code generator 4.9.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_EmailGatewayDialog(object):
def setupUi(self, EmailGatewayDialog):
EmailGatewayDialog.setObjectName(_fromUtf8("EmailGatewayDialog"))
EmailGatewayDialog.resize(386, 172)
self.gridLayout = QtGui.QGridLayout(EmailGatewayDialog)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.radioButtonRegister = QtGui.QRadioButton(EmailGatewayDialog)
self.radioButtonRegister.setChecked(True)
self.radioButtonRegister.setObjectName(_fromUtf8("radioButtonRegister"))
self.gridLayout.addWidget(self.radioButtonRegister, 1, 0, 1, 1)
self.radioButtonStatus = QtGui.QRadioButton(EmailGatewayDialog)
self.radioButtonStatus.setObjectName(_fromUtf8("radioButtonStatus"))
self.gridLayout.addWidget(self.radioButtonStatus, 4, 0, 1, 1)
self.radioButtonSettings = QtGui.QRadioButton(EmailGatewayDialog)
self.radioButtonSettings.setObjectName(_fromUtf8("radioButtonSettings"))
self.gridLayout.addWidget(self.radioButtonSettings, 5, 0, 1, 1)
self.radioButtonUnregister = QtGui.QRadioButton(EmailGatewayDialog)
self.radioButtonUnregister.setObjectName(_fromUtf8("radioButtonUnregister"))
self.gridLayout.addWidget(self.radioButtonUnregister, 6, 0, 1, 1)
self.label = QtGui.QLabel(EmailGatewayDialog)
self.label.setWordWrap(True)
self.label.setObjectName(_fromUtf8("label"))
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.label_2 = QtGui.QLabel(EmailGatewayDialog)
self.label_2.setObjectName(_fromUtf8("label_2"))
self.gridLayout.addWidget(self.label_2, 2, 0, 1, 1)
self.lineEditEmail = QtGui.QLineEdit(EmailGatewayDialog)
self.lineEditEmail.setEnabled(True)
self.lineEditEmail.setObjectName(_fromUtf8("lineEditEmail"))
self.gridLayout.addWidget(self.lineEditEmail, 3, 0, 1, 1)
self.buttonBox = QtGui.QDialogButtonBox(EmailGatewayDialog)
self.buttonBox.setMinimumSize(QtCore.QSize(368, 0))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.gridLayout.addWidget(self.buttonBox, 7, 0, 1, 1)
self.retranslateUi(EmailGatewayDialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), EmailGatewayDialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), EmailGatewayDialog.reject)
QtCore.QObject.connect(self.radioButtonRegister, QtCore.SIGNAL(_fromUtf8("clicked(bool)")), self.lineEditEmail.setEnabled)
QtCore.QObject.connect(self.radioButtonStatus, QtCore.SIGNAL(_fromUtf8("clicked(bool)")), self.lineEditEmail.setDisabled)
QtCore.QObject.connect(self.radioButtonSettings, QtCore.SIGNAL(_fromUtf8("clicked(bool)")), self.lineEditEmail.setDisabled)
QtCore.QObject.connect(self.radioButtonUnregister, QtCore.SIGNAL(_fromUtf8("clicked(bool)")), self.lineEditEmail.setDisabled)
QtCore.QMetaObject.connectSlotsByName(EmailGatewayDialog)
EmailGatewayDialog.setTabOrder(self.radioButtonRegister, self.lineEditEmail)
EmailGatewayDialog.setTabOrder(self.lineEditEmail, self.radioButtonUnregister)
EmailGatewayDialog.setTabOrder(self.radioButtonUnregister, self.buttonBox)
def retranslateUi(self, EmailGatewayDialog):
EmailGatewayDialog.setWindowTitle(QtGui.QApplication.translate("EmailGatewayDialog", "Email gateway", None, QtGui.QApplication.UnicodeUTF8))
self.radioButtonRegister.setText(QtGui.QApplication.translate("EmailGatewayDialog", "Register on email gateway", None, QtGui.QApplication.UnicodeUTF8))
self.radioButtonStatus.setText(QtGui.QApplication.translate("EmailGatewayDialog", "Account status at email gateway", None, QtGui.QApplication.UnicodeUTF8))
self.radioButtonSettings.setText(QtGui.QApplication.translate("EmailGatewayDialog", "Change account settings at email gateway", None, QtGui.QApplication.UnicodeUTF8))
self.radioButtonUnregister.setText(QtGui.QApplication.translate("EmailGatewayDialog", "Unregister from email gateway", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("EmailGatewayDialog", "Email gateway allows you to communicate with email users. Currently, only the Mailchuck email gateway (@mailchuck.com) is available.", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("EmailGatewayDialog", "Desired email address (including @mailchuck.com):", None, QtGui.QApplication.UnicodeUTF8))
class Ui_EmailGatewayRegistrationDialog(object):
def setupUi(self, EmailGatewayRegistrationDialog):
EmailGatewayRegistrationDialog.setObjectName(_fromUtf8("EmailGatewayRegistrationDialog"))
EmailGatewayRegistrationDialog.resize(386, 172)
self.gridLayout = QtGui.QGridLayout(EmailGatewayRegistrationDialog)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.label = QtGui.QLabel(EmailGatewayRegistrationDialog)
self.label.setWordWrap(True)
self.label.setObjectName(_fromUtf8("label"))
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.lineEditEmail = QtGui.QLineEdit(EmailGatewayRegistrationDialog)
self.lineEditEmail.setObjectName(_fromUtf8("lineEditEmail"))
self.gridLayout.addWidget(self.lineEditEmail, 1, 0, 1, 1)
self.buttonBox = QtGui.QDialogButtonBox(EmailGatewayRegistrationDialog)
self.buttonBox.setMinimumSize(QtCore.QSize(368, 0))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.gridLayout.addWidget(self.buttonBox, 7, 0, 1, 1)
self.retranslateUi(EmailGatewayRegistrationDialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), EmailGatewayRegistrationDialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), EmailGatewayRegistrationDialog.reject)
QtCore.QMetaObject.connectSlotsByName(EmailGatewayRegistrationDialog)
def retranslateUi(self, EmailGatewayRegistrationDialog):
EmailGatewayRegistrationDialog.setWindowTitle(QtGui.QApplication.translate("EmailGatewayRegistrationDialog", "Email gateway registration", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("EmailGatewayRegistrationDialog", "Email gateway allows you to communicate with email users. Currently, only the Mailchuck email gateway (@mailchuck.com) is available.\nPlease type the desired email address (including @mailchuck.com) below:", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -7,20 +7,20 @@
<x>0</x>
<y>0</y>
<width>386</width>
<height>172</height>
<height>240</height>
</rect>
</property>
<property name="windowTitle">
<string>Email gateway</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Desired email address (including @mailchuck.com)</string>
<string>Desired email address (including @mailchuck.com):</string>
</property>
</widget>
</item>
@ -50,28 +50,60 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLineEdit" name="lineEditEmailAddress">
<item row="4" column="0">
<widget class="QLineEdit" name="lineEditEmail">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>@mailchuck.com</string>
</property>
<property name="cursorPosition">
<number>0</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Email gateway alows you to communicate with email users. Currently, only the Mailchuck email gateway (@mailchuck.com) is available.</string>
<string>Email gateway allows you to communicate with email users. Currently, only the Mailchuck email gateway (@mailchuck.com) is available.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QRadioButton" name="radioButtonStatus">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Account status at email gateway</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QRadioButton" name="radioButtonSettings">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Change account settings at email gateway</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QRadioButton" name="radioButtonUnregister">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Unregister from email gateway</string>
</property>
@ -84,7 +116,10 @@
</widget>
<tabstops>
<tabstop>radioButtonRegister</tabstop>
<tabstop>lineEditEmailAddress</tabstop>
<tabstop>lineEditEmail</tabstop>
<tabstop>radioButtonStatus</tabstop>
<tabstop>radioButtonSettings</tabstop>
<tabstop>radioButtonUnregister</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
@ -124,7 +159,7 @@
<connection>
<sender>radioButtonRegister</sender>
<signal>clicked(bool)</signal>
<receiver>lineEditEmailAddress</receiver>
<receiver>lineEditEmail</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
@ -140,7 +175,7 @@
<connection>
<sender>radioButtonUnregister</sender>
<signal>clicked(bool)</signal>
<receiver>lineEditEmailAddress</receiver>
<receiver>lineEditEmail</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
@ -153,5 +188,37 @@
</hint>
</hints>
</connection>
<connection>
<sender>radioButtonStatus</sender>
<signal>clicked(bool)</signal>
<receiver>lineEditEmail</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioButtonSettings</sender>
<signal>clicked(bool)</signal>
<receiver>lineEditEmail</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections>
</ui>