00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024
00025 #include <klocale.h>
00026 #include <kdebug.h>
00027 #include <kstandarddirs.h>
00028 #include <kmessagebox.h>
00029
00030 #include "exchangeaccount.h"
00031 #include "resourceexchangeconfig.h"
00032 #include "resourceexchange.h"
00033
00034 using namespace KCal;
00035
00036 ResourceExchangeConfig::ResourceExchangeConfig( QWidget* parent, const char* name )
00037 : KRES::ConfigWidget( parent, name )
00038 {
00039 resize( 245, 115 );
00040 QGridLayout *mainLayout = new QGridLayout( this, 8, 3 );
00041
00042 QLabel *label = new QLabel( i18n( "Host:" ), this );
00043 mHostEdit = new KLineEdit( this );
00044 mainLayout->addWidget( label, 1, 0 );
00045 mainLayout->addWidget( mHostEdit, 1, 1 );
00046
00047 label = new QLabel( i18n( "Port:" ), this );
00048 mPortEdit = new KLineEdit( this );
00049 mainLayout->addWidget( label, 2, 0 );
00050 mainLayout->addWidget( mPortEdit, 2, 1 );
00051
00052 label = new QLabel( i18n( "Account:" ), this );
00053 mAccountEdit = new KLineEdit( this );
00054 mainLayout->addWidget( label, 3, 0 );
00055 mainLayout->addWidget( mAccountEdit, 3, 1 );
00056
00057 label = new QLabel( i18n( "Password:" ), this );
00058 mPasswordEdit = new KLineEdit( this );
00059 mPasswordEdit->setEchoMode( QLineEdit::Password );
00060 mainLayout->addWidget( label, 4, 0 );
00061 mainLayout->addWidget( mPasswordEdit, 4, 1 );
00062
00063 mAutoMailbox = new QCheckBox( i18n( "Determine mailbox &automatically" ), this );
00064 mainLayout->addMultiCellWidget( mAutoMailbox, 5, 5, 0, 1 );
00065 connect( mAutoMailbox, SIGNAL(toggled(bool)), this, SLOT(slotToggleAuto(bool)) );
00066
00067 mMailboxEdit = new KLineEdit( this );
00068 mainLayout->addWidget( new QLabel( i18n( "Mailbox URL:" ), this ), 6, 0 );
00069 mainLayout->addWidget( mMailboxEdit, 6, 1 );
00070
00071 mTryFindMailbox = new QPushButton( "&Find", this );
00072 mainLayout->addWidget( mTryFindMailbox, 6, 2 );
00073 connect( mTryFindMailbox, SIGNAL(clicked()), this, SLOT(slotFindClicked()) );
00074
00075 label = new QLabel( i18n( "Cache timeout:" ), this );
00076 mCacheEdit = new KIntNumInput( this );
00077 mCacheEdit->setMinValue( 0 );
00078 mCacheEdit->setSuffix( i18n(" seconds") );
00079 mainLayout->addWidget( label, 7, 0 );
00080 mainLayout->addWidget( mCacheEdit, 7, 1 );
00081 }
00082
00083 void ResourceExchangeConfig::loadSettings( KRES::Resource *resource )
00084 {
00085 ResourceExchange* res = dynamic_cast<ResourceExchange*>( resource );
00086 if (res) {
00087 mHostEdit->setText( res->mAccount->host() );
00088 mPortEdit->setText( res->mAccount->port() );
00089 mAccountEdit->setText( res->mAccount->account() );
00090 mPasswordEdit->setText( res->mAccount->password() );
00091 mAutoMailbox->setChecked( res->mAutoMailbox );
00092 mMailboxEdit->setText( res->mAccount->mailbox() );
00093 mCacheEdit->setValue( res->mCachedSeconds );
00094 } else
00095 kdDebug(5700) << "ERROR: ResourceExchangeConfig::loadSettings(): no ResourceExchange, cast failed" << endl;
00096 }
00097
00098 void ResourceExchangeConfig::saveSettings( KRES::Resource *resource )
00099 {
00100 kdDebug() << "Saving settings to resource " << resource->resourceName() << endl;
00101 ResourceExchange* res = dynamic_cast<ResourceExchange*>( resource );
00102 if (res) {
00103 if ( mAutoMailbox->isChecked() ) {
00104 mMailboxEdit->setText( QString::null );
00105 slotFindClicked();
00106 if ( mMailboxEdit->text().isNull() ) {
00107 kdWarning() << "Could not find Exchange mailbox URL, incomplete settings!" << endl;
00108 }
00109 }
00110 res->mAutoMailbox = mAutoMailbox->isChecked();
00111
00112 res->mAccount->setHost(mHostEdit->text());
00113 res->mAccount->setPort(mPortEdit->text());
00114 res->mAccount->setAccount(mAccountEdit->text());
00115 res->mAccount->setPassword(mPasswordEdit->text());
00116 res->mAccount->setMailbox( mMailboxEdit->text() );
00117 res->mCachedSeconds = mCacheEdit->value();
00118 } else
00119 kdDebug(5700) << "ERROR: ResourceExchangeConfig::saveSettings(): no ResourceExchange, cast failed" << endl;
00120 }
00121
00122 void ResourceExchangeConfig::slotToggleAuto( bool on )
00123 {
00124 mMailboxEdit->setEnabled( ! on );
00125
00126 }
00127
00128 void ResourceExchangeConfig::slotUserChanged( const QString& )
00129 {
00130
00131
00132
00133 }
00134
00135 void ResourceExchangeConfig::slotFindClicked()
00136 {
00137 QString mailbox = KPIM::ExchangeAccount::tryFindMailbox(
00138 mHostEdit->text(), mPortEdit->text(),
00139 mAccountEdit->text(), mPasswordEdit->text() );
00140
00141 if ( mailbox.isNull() ) {
00142 KMessageBox::sorry( this, i18n( "Could not determine mailbox URL, please check your account settings." ) );
00143 } else {
00144 mMailboxEdit->setText( mailbox );
00145 }
00146 }
00147
00148 #include "resourceexchangeconfig.moc"