libkpimexchange Library API Documentation

resourceexchangeconfig.cpp

00001 /*
00002     This file is part of libkpimexchange.
00003     Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
00004     Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA 02111-1307, USA.
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 //  mTryFindMailbox->setEnabled( ! on );
00126 }
00127 
00128 void ResourceExchangeConfig::slotUserChanged( const QString& /*text*/ )
00129 {
00130 //  if ( mMailboxEqualsUser->isChecked() ) {
00131 //    mMailboxEdit->setText( "webdav://" + mHostEdit->text() + "/exchange/" + text );
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"
KDE Logo
This file is part of the documentation for libkpimexchange Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:10 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003