From kde-usability Fri Jul 12 18:54:09 2002 From: Dave Corrie Date: Fri, 12 Jul 2002 18:54:09 +0000 To: kde-usability Subject: Re: [PATCH] Improving the KSCD configuration dialog X-MARC-Message: https://marc.info/?l=kde-usability&m=102650023028318 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--------------Boundary-00=_9IG56FG6PZZWTUQ266WU" --------------Boundary-00=_9IG56FG6PZZWTUQ266WU Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit On Friday 12 July 2002 1:27 am, Aaron J. Seigo wrote: > On Thursday 11 July 2002 06:14, Dave Corrie wrote: > > 1) Add a checkbox to the kscd config page to optionally use the > > email address settings from Control Centre. > > this is probably the most flexible and can be presented in a decently > obvious way. Attached is a patch which implements this. It works well when the "Use global email settings" checkbox is unchecked, but there's some odd behavioural quirks when it is checked. This is because the settings aren't entirely global: a) The SMTP server address cannot be configured in the KDE Control Centre so this entry box must be writable. b) There is no mechanism in KEMailSettings to save/retrieve the SMTP server port. Previously kscd hardcoded this to 25 and so this edit box is disabled. (I didn't much like the idea of updating the global email addresses from this config page, (see my other mail for my reasoning), so both email edit boxes are disabled. ) Screenshot (~40k): http://davecorrie.com/kscd_global.png This is still an improvement on the original config page, because the edit boxes are clearly disabled rather than merely read-only and because the label of the new checkbox draws attention to the fact that the settings are linked to the global settings found in the KDE Control Centre. I considered the use of two radio buttons instead of a checkbox to select whether or not the global settings should be used (the idea is from Simon Edwards' earlier post), but I could not find a nice way to make this work, given that we still have to provide a way to configure the SMTP server address even when the global settings are to be used. Finally, if anyone would prefer different spacing/alignment/whatever than that which I've chosen, please say. Cheers, Dave --------------Boundary-00=_9IG56FG6PZZWTUQ266WU Content-Type: text/x-diff; charset="iso-8859-1"; name="emailsettings.patch2" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="emailsettings.patch2" Index: smtpconfig.h =================================================================== RCS file: /home/kde/kdemultimedia/kscd/smtpconfig.h,v retrieving revision 1.6 diff -u -3 -p -r1.6 smtpconfig.h --- smtpconfig.h 2002/01/11 03:27:02 1.6 +++ smtpconfig.h 2002/07/12 18:00:04 @@ -37,11 +37,16 @@ struct SMTPConfigData { //public: bool enabled; + bool useGlobalSettings; + QString serverHost; QString serverPort; QString senderAddress; QString senderReplyTo; - QString mailProfile; + + bool isValid() const; + void loadGlobalSettings(); + void saveGlobalSettings() const; }; class SMTPConfig:public QWidget @@ -55,24 +60,25 @@ public: public slots: void commitData(); void enableClicked(); - void mailProfileChanged(const QString &name); + void globalSettingsClicked(); signals: protected: QGroupBox *mainBox; QCheckBox *enableCB; - QLabel *mailProfileLabel; - KComboBox *mailProfileCombo; + QLabel *serverHostLabel; QLineEdit *serverHostEdit; QLabel *serverPortLabel; QLineEdit *serverPortEdit; + + QCheckBox *globalSettingsCB; + QLabel *senderAddressLabel; QLineEdit *senderAddressEdit; QLabel *senderReplyToLabel; QLineEdit *senderReplyToEdit; - KEMailSettings *kes; private: SMTPConfigData *configData; Index: smtpconfig.cpp =================================================================== RCS file: /home/kde/kdemultimedia/kscd/smtpconfig.cpp,v retrieving revision 1.17 diff -u -3 -p -r1.17 smtpconfig.cpp --- smtpconfig.cpp 2002/07/07 21:02:28 1.17 +++ smtpconfig.cpp 2002/07/12 18:00:04 @@ -29,28 +29,49 @@ #include #include +#include #include #include +bool SMTPConfigData::isValid() const +{ + // simple validation + return !serverHost.isEmpty() && !serverPort.isEmpty() && + senderAddress.contains("@") && + (senderReplyTo.contains("@") || senderReplyTo.isEmpty()); +} + +void SMTPConfigData::loadGlobalSettings() +{ + KEMailSettings kes; + kes.setProfile( i18n("Default") ); + serverHost = kes.getSetting( KEMailSettings::OutServer ); + serverPort = "25"; + senderAddress = kes.getSetting( KEMailSettings::EmailAddress ); + senderReplyTo = kes.getSetting( KEMailSettings::ReplyToAddress ); +} + +void SMTPConfigData::saveGlobalSettings() const +{ + // We don't save senderAddress or senderReplyTo because they can be + // configured in the KDE Control Centre. + // We don't save serverPort because there is currently no mechanism + // to do this via KEMailSettings. + // We do save serverHost because there is currently no way to configure + // this in the KDE Control Centre. + + KEMailSettings kes; + kes.setProfile( i18n("Default") ); + kes.setSetting( KEMailSettings::OutServer, serverHost ); +} + + SMTPConfig::SMTPConfig(QWidget *parent, const char *name, struct SMTPConfigData *_configData) : QWidget(parent, name) { configData = _configData; QFontMetrics fm ( font() ); - kes = new KEMailSettings(); - - kes->setProfile( configData->mailProfile ); - configData->serverHost = kes->getSetting( KEMailSettings::OutServer ); - configData->serverPort = "25"; - configData->senderAddress = kes->getSetting( KEMailSettings::EmailAddress ); - configData->senderReplyTo = kes->getSetting( KEMailSettings::ReplyToAddress ); - // Don't accept obviously bogus settings. - if( (configData->serverHost == "") || (!configData->senderAddress.contains("@"))) - { - configData->enabled = false; - } - QBoxLayout * lay1 = new QVBoxLayout ( this ); mainBox = new QGroupBox(this, "mainBox"); @@ -62,102 +83,105 @@ SMTPConfig::SMTPConfig(QWidget *parent, enableCB->setChecked(configData->enabled); connect(enableCB, SIGNAL(clicked()), this, SLOT(enableClicked())); - QGridLayout * glay = new QGridLayout ( lay2, 2, 4, 5 ); + QGridLayout * glay = new QGridLayout ( lay2, 5, 4, 5 ); glay->setColStretch ( 1, 1 ); - mailProfileLabel = new QLabel(i18n("Current email profile:"), mainBox, "mailProfileLabel"); - glay->addWidget ( mailProfileLabel, 0, 0 ); - mailProfileCombo = new KComboBox( FALSE, mainBox, "mailProfileCombo" ); - glay->addMultiCellWidget( mailProfileCombo, 0,0, 1,3); - mailProfileCombo->insertStringList(kes->profiles()); - mailProfileCombo->setEnabled(configData->enabled); - connect(mailProfileCombo, SIGNAL(activated(const QString &)), this, SLOT(mailProfileChanged(const QString &))); - // *yuck* - int i = 0; - for( i=0; i < mailProfileCombo->count(); i++ ) - { - if( configData->mailProfile == mailProfileCombo->text(i) ) - { - mailProfileCombo->setCurrentItem( i ); - } - } + glay->addRowSpacing ( 0, 20 ); + globalSettingsCB = new QCheckBox(i18n("Use email settings from Control Centre"), mainBox, "globalSettingsCB"); + glay->addMultiCellWidget ( globalSettingsCB, 1,1, 0,3 ); + globalSettingsCB->setChecked(configData->useGlobalSettings); + connect(globalSettingsCB, SIGNAL(clicked()), this, SLOT(globalSettingsClicked())); - serverHostLabel = new QLabel(i18n("SMTP address:port :"), mainBox, "serverHostLabel"); - glay->addWidget ( serverHostLabel, 1, 0 ); + serverHostLabel = new QLabel(i18n("SMTP address:port:"), mainBox, "serverHostLabel"); + glay->addWidget ( serverHostLabel, 2, 0 ); serverHostEdit = new QLineEdit(mainBox, "serverHostEdit"); - glay->addWidget ( serverHostEdit, 1, 1 ); + glay->addWidget ( serverHostEdit, 2, 1 ); serverHostEdit->setText(configData->serverHost); - serverHostEdit->setEnabled(configData->enabled); serverPortLabel = new QLabel(":", mainBox, "serverPortLabel"); - glay->addWidget ( serverPortLabel, 1, 2 ); + glay->addWidget ( serverPortLabel, 2, 2 ); serverPortEdit = new QLineEdit(mainBox, "serverPortEdit"); serverPortEdit->setFixedWidth ( 5 * fm.maxWidth() ); - glay->addWidget ( serverPortEdit, 1, 3 ); + serverPortEdit->setValidator( new QIntValidator(this) ); + glay->addWidget ( serverPortEdit, 2, 3 ); serverPortEdit->setGeometry(475, 40, 45, 25); serverPortEdit->setText(configData->serverPort); - serverPortEdit->setEnabled(configData->enabled); - serverPortEdit->setReadOnly( true ); senderAddressLabel = new QLabel(i18n("Your email address:"), mainBox, "senderAddressLabel"); - glay->addWidget ( senderAddressLabel, 2, 0 ); + glay->addWidget ( senderAddressLabel, 3, 0 ); senderAddressEdit = new QLineEdit(mainBox, "senderAddressEdit"); - glay->addMultiCellWidget ( senderAddressEdit, 2,2, 1,3 ); + glay->addMultiCellWidget ( senderAddressEdit, 3,3, 1,3 ); senderAddressEdit->setText(configData->senderAddress); - senderAddressEdit->setEnabled(configData->enabled); - senderAddressEdit->setReadOnly( true ); senderReplyToLabel = new QLabel(i18n("Your reply address:"), mainBox, "senderReplyToLabel"); - glay->addWidget ( senderReplyToLabel, 3, 0 ); + glay->addWidget ( senderReplyToLabel, 4, 0 ); senderReplyToEdit = new QLineEdit(mainBox, "senderReplyToEdit"); - glay->addMultiCellWidget ( senderReplyToEdit, 3,3, 1,3 ); + glay->addMultiCellWidget ( senderReplyToEdit, 4,4, 1,3 ); senderReplyToEdit->setText(configData->senderReplyTo); - senderReplyToEdit->setEnabled(configData->enabled); - senderReplyToEdit->setReadOnly( true ); lay1->addStretch ( 1 ); + + enableClicked(); } void SMTPConfig::commitData(void) { configData->enabled = enableCB->isChecked(); + configData->useGlobalSettings = globalSettingsCB->isChecked(); configData->serverHost = serverHostEdit->text(); - kes->setSetting( KEMailSettings::OutServer, serverHostEdit->text() ); configData->serverPort = serverPortEdit->text(); configData->senderAddress = senderAddressEdit->text(); configData->senderReplyTo = senderReplyToEdit->text(); - configData->mailProfile = mailProfileCombo->currentText(); - if( configData->enabled && ( (configData->serverHost == "") || - (!configData->senderAddress.contains("@")) ) ) + + if(configData->useGlobalSettings) + configData->saveGlobalSettings(); + + if( configData->enabled && !configData->isValid() ) { KMessageBox::sorry(this, i18n("freedb submissions via SMTP have been disabled\n" - "because the email profile you selected is\n" + "because the email details you have entered are\n" "incomplete. Please review your email settings\n" "and try again."), i18n("Freedb Submissions Disabled")); configData->enabled = false; + enableCB->setChecked(false); + enableClicked(); } } // commitData void SMTPConfig::enableClicked(void) { - bool c; + bool enable = enableCB->isChecked(); + globalSettingsCB->setEnabled(enable); - c = enableCB->isChecked(); - mailProfileCombo->setEnabled(c); - serverHostEdit->setEnabled(c); - serverPortEdit->setEnabled(c); - senderAddressEdit->setEnabled(c); - senderReplyToEdit->setEnabled(c); + // serverHost is enabled even when the global settings are used because + // there is currently no way to configure this in the KDE Control Centre. + serverHostEdit->setEnabled(enable); + + enable = enable && !globalSettingsCB->isChecked(); + + // serverPort is disabled when the global settings are used because there + // is currently no mechanism to save it globally. is is hardcoded to "25". + serverPortEdit->setEnabled(enable); + + // senderAddress and senderReplyTo are disabled when the global settings + // are used because they can be configured in the KDE Control Centre. + senderAddressEdit->setEnabled(enable); + senderReplyToEdit->setEnabled(enable); } // enableClicked -void SMTPConfig::mailProfileChanged( const QString &name ) +void SMTPConfig::globalSettingsClicked(void) { - kes->setProfile( name ); - configData->serverHost = kes->getSetting( KEMailSettings::OutServer ); - configData->senderAddress = kes->getSetting( KEMailSettings::EmailAddress ); - configData->senderReplyTo = kes->getSetting( KEMailSettings::ReplyToAddress ); - serverHostEdit->setText( configData->serverHost ); - senderAddressEdit->setText( configData->senderAddress ); - senderReplyToEdit->setText( configData->senderReplyTo ); -} // mailProfileChanged + if(globalSettingsCB->isChecked()) + { + // We use a local SMTPConfigData variable to load the global settings + // because we cannot write to configData until commitData() is called. + SMTPConfigData d; + d.loadGlobalSettings(); + serverHostEdit->setText(d.serverHost); + serverPortEdit->setText(d.serverPort); + senderAddressEdit->setText(d.senderAddress); + senderReplyToEdit->setText(d.senderReplyTo); + } + enableClicked(); +} // globalSettingsClicked #include Index: kscd.cpp =================================================================== RCS file: /home/kde/kdemultimedia/kscd/kscd.cpp,v retrieving revision 1.158 diff -u -3 -p -r1.158 kscd.cpp --- kscd.cpp 2002/07/07 10:25:07 1.158 +++ kscd.cpp 2002/07/12 18:00:06 @@ -1708,21 +1708,24 @@ KSCD::readSettings() config->setGroup("SMTP"); smtpConfigData->enabled = config->readBoolEntry("enabled", true); - smtpConfigData->mailProfile = config->readEntry("mailProfile", i18n("Default")); + smtpConfigData->useGlobalSettings = config->readBoolEntry("useGlobalSettings", true); - // Same as follows happens in smtpconfig.cpp. Try to remove one. - KEMailSettings kes; - kes.setProfile( smtpConfigData->mailProfile ); - smtpConfigData->serverHost = kes.getSetting( KEMailSettings::OutServer ); - smtpConfigData->serverPort = "25"; - smtpConfigData->senderAddress = kes.getSetting( KEMailSettings::EmailAddress ); - smtpConfigData->senderReplyTo = kes.getSetting( KEMailSettings::ReplyToAddress ); - // Don't accept obviously bogus settings. - if( (smtpConfigData->serverHost == "") || (!smtpConfigData->senderAddress.contains("@")) ) + if(smtpConfigData->useGlobalSettings) { - smtpConfigData->enabled = false; + smtpConfigData->loadGlobalSettings(); } + else + { + smtpConfigData->serverHost = config->readEntry("serverHost"); + smtpConfigData->serverPort = config->readEntry("serverPort"); + smtpConfigData->senderAddress = config->readEntry("senderAddress"); + smtpConfigData->senderReplyTo = config->readEntry("senderReplyTo"); + } + // Don't accept obviously bogus settings. + if(!smtpConfigData->isValid()) + smtpConfigData->enabled = false; + config->setGroup("CDDB"); cddb.setTimeout(config->readNumEntry("CDDBTimeout",60)); @@ -1828,7 +1831,23 @@ KSCD::writeSettings() config->setGroup("SMTP"); config->writeEntry("enabled", smtpConfigData->enabled); - config->writeEntry("mailProfile", smtpConfigData->mailProfile); + config->writeEntry("useGlobalSettings", smtpConfigData->useGlobalSettings); + if(smtpConfigData->useGlobalSettings) + { + config->writeEntry("serverHost", ""); + config->writeEntry("serverPort", ""); + config->writeEntry("senderAddress", ""); + config->writeEntry("senderReplyTo", ""); + } + else + { + config->writeEntry("serverHost", smtpConfigData->serverHost); + config->writeEntry("serverPort", smtpConfigData->serverPort); + config->writeEntry("senderAddress", smtpConfigData->senderAddress); + config->writeEntry("senderReplyTo", smtpConfigData->senderReplyTo); + } + // delete legacy mailProfile option + config->deleteEntry("mailProfile"); config->setGroup("CDDB"); config->writeEntry("CDDBRemoteEnabled",cddb_remote_enabled); --------------Boundary-00=_9IG56FG6PZZWTUQ266WU-- _______________________________________________ kde-usability mailing list kde-usability@mail.kde.org http://mail.kde.org/mailman/listinfo/kde-usability