kpilot

mal-setup.cc

Go to the documentation of this file.
00001 /* MAL-setup.cc                      KPilot
00002 **
00003 ** Copyright (C) 2002 by Reinhold Kainhofer
00004 **
00005 ** This file defines the setup dialog for the MAL-conduit plugin.
00006 */
00007 
00008 /*
00009 ** This program is free software; you can redistribute it and/or modify
00010 ** it under the terms of the GNU General Public License as published by
00011 ** the Free Software Foundation; either version 2 of the License, or
00012 ** (at your option) any later version.
00013 **
00014 ** This program is distributed in the hope that it will be useful,
00015 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017 ** GNU General Public License for more details.
00018 **
00019 ** You should have received a copy of the GNU General Public License
00020 ** along with this program in a file called COPYING; if not, write to
00021 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00022 ** MA 02110-1301, USA.
00023 **
00024 **
00025 ** Specific permission is granted for this code to be linked to libmal
00026 ** (this is necessary because the libmal license is not GPL-compatible).
00027 */
00028 
00029 /*
00030 ** Bug reports and questions can be sent to kde-pim@kde.org
00031 */
00032 
00033 #include "options.h"
00034 
00035 #include <qtabwidget.h>
00036 #include <qradiobutton.h>
00037 #include <qbuttongroup.h>
00038 #include <qlineedit.h>
00039 #include <qcheckbox.h>
00040 
00041 #include <kcombobox.h>
00042 #include <knuminput.h>
00043 #include <kpassdlg.h>
00044 
00045 #include <kapplication.h>
00046 #include <kconfig.h>
00047 
00048 
00049 #include "mal-setup_dialog.h"
00050 
00051 #include "mal-factory.h"
00052 #include "mal-setup.moc"
00053 #include "malconduitSettings.h"
00054 
00055 
00056 MALWidgetSetup::MALWidgetSetup(QWidget *w, const char *n) :
00057     ConduitConfigBase(w,n),
00058     fConfigWidget(new MALWidget(w))
00059 {
00060     FUNCTIONSETUP;
00061 
00062     fConduitName=i18n("MAL");
00063     ConduitConfigBase::addAboutPage(fConfigWidget->tabWidget,MALConduitFactory::about());
00064     fWidget = fConfigWidget;
00065 
00066     fConfigWidget->tabWidget->adjustSize();
00067     fConfigWidget->resize(fConfigWidget->tabWidget->size());
00068 #define CM(a,b) connect(fConfigWidget->a,b,this,SLOT(modified()));
00069     CM( syncTime, SIGNAL(clicked(int)) );
00070     CM( proxyType, SIGNAL(clicked(int)) );
00071 
00072     CM( proxyServerName, SIGNAL(textChanged(const QString &)) );
00073     CM( proxyCustomPortCheck, SIGNAL(clicked()) );
00074     CM( proxyCustomPort, SIGNAL(valueChanged(int)) );
00075     CM( proxyUserName, SIGNAL(textChanged(const QString &)) );
00076     CM( proxyPassword, SIGNAL(textChanged(const QString &)) );
00077 
00078     CM( malServerName, SIGNAL(textChanged(const QString &)) );
00079     CM( malCustomPortCheck, SIGNAL(clicked()) );
00080     CM( malCustomPort, SIGNAL(valueChanged(int)) );
00081     CM( malUserName, SIGNAL(textChanged(const QString &)) );
00082     CM( malPassword, SIGNAL(textChanged(const QString &)) );
00083 #undef CM
00084 }
00085 
00086 MALWidgetSetup::~MALWidgetSetup()
00087 {
00088     FUNCTIONSETUP;
00089 }
00090 
00091 /* virtual */ void MALWidgetSetup::commit()
00092 {
00093     FUNCTIONSETUP;
00094 
00095     MALConduitSettings::setSyncFrequency(
00096         fConfigWidget->syncTime->id(fConfigWidget->syncTime->selected()));
00097 
00098     // Proxy settings
00099     MALConduitSettings::setProxyType(
00100         fConfigWidget->proxyType->id(fConfigWidget->proxyType->selected()));
00101     MALConduitSettings::setProxyServer( fConfigWidget->proxyServerName->currentText() );
00102 
00103     if (fConfigWidget->proxyCustomPortCheck->isChecked() )
00104     {
00105         MALConduitSettings::setProxyPort( fConfigWidget->proxyCustomPort->value());
00106     }
00107     else
00108     {
00109         MALConduitSettings::setProxyPort(0);
00110     }
00111     MALConduitSettings::setProxyUser( fConfigWidget->proxyUserName->text() );
00112     MALConduitSettings::setProxyPassword( fConfigWidget->proxyPassword->password() );
00113 
00114     // MAL Server settings (not yet possible!!!)
00115     MALConduitSettings::setMALServer( fConfigWidget->malServerName->currentText() );
00116 
00117     if (fConfigWidget->malCustomPortCheck->isChecked() )
00118     {
00119         MALConduitSettings::setMALPort( fConfigWidget->malCustomPort->value());
00120     }
00121     else
00122     {
00123         MALConduitSettings::setMALPort(0);
00124     }
00125     MALConduitSettings::setMALUser( fConfigWidget->malUserName->text() );
00126     MALConduitSettings::setMALPassword( fConfigWidget->malPassword->text() );
00127 
00128     MALConduitSettings::self()->writeConfig();
00129     unmodified();
00130 }
00131 
00132 
00133 
00134 /* virtual */ void MALWidgetSetup::load()
00135 {
00136     FUNCTIONSETUP;
00137     MALConduitSettings::self()->readConfig();
00138 
00139     fConfigWidget->syncTime->setButton( MALConduitSettings::syncFrequency() );
00140 
00141     // Proxy settings
00142     fConfigWidget->proxyType->setButton(MALConduitSettings::proxyType());
00143     fConfigWidget->proxyServerName->setEditText(MALConduitSettings::proxyServer());
00144 
00145     int proxyPortNr=MALConduitSettings::proxyPort();
00146     if (proxyPortNr>0 && proxyPortNr<65536)
00147     {
00148         fConfigWidget->proxyCustomPortCheck->setChecked(true);
00149         fConfigWidget->proxyCustomPort->setEnabled(true);
00150         fConfigWidget->proxyCustomPort->setValue(proxyPortNr);
00151     }
00152     fConfigWidget->proxyUserName->setText(MALConduitSettings::proxyUser());
00153     fConfigWidget->proxyPassword->setText(QString::null);
00154     fConfigWidget->proxyPassword->insert(MALConduitSettings::proxyPassword());
00155 
00156 #ifdef DEBUG
00157     DEBUGKPILOT << fname << ": Got proxy password <"
00158         << MALConduitSettings::proxyPassword()
00159         << "> set Text <"
00160         << fConfigWidget->proxyPassword->text()
00161         << "> and Pwd <"
00162         << fConfigWidget->proxyPassword->password()
00163         << ">" << endl;
00164 #endif
00165 
00166     // MAL Server settings (not yet possible!!!)
00167     fConfigWidget->malServerName->setEditText(MALConduitSettings::mALServer());
00168 
00169     int malPortNr=MALConduitSettings::mALPort();
00170     if (malPortNr>0 && malPortNr<65536)
00171     {
00172         fConfigWidget->malCustomPortCheck->setChecked(true);
00173         fConfigWidget->malCustomPort->setEnabled(true);
00174         fConfigWidget->malCustomPort->setValue(proxyPortNr);
00175     }
00176     fConfigWidget->malUserName->setText(MALConduitSettings::mALUser());
00177     fConfigWidget->malPassword->setText(MALConduitSettings::mALPassword());
00178     unmodified();
00179 }
00180 
00181 /* static */ ConduitConfigBase *MALWidgetSetup::create(QWidget *w, const char *n)
00182 {
00183     return new MALWidgetSetup(w,n);
00184 }
00185