korganizer Library API Documentation

exchangeconfig.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #include <qlayout.h>
00021 #include <qlabel.h>
00022 #include <qcombobox.h>
00023 
00024 #include <kapplication.h>
00025 #include <kconfig.h>
00026 #include <klocale.h>
00027 #include <kdebug.h>
00028 #include <kmessagebox.h>
00029 
00030 #include <exchangeaccount.h>
00031 
00032 #include "exchangeconfig.h"
00033 
00034 ExchangeConfig::ExchangeConfig( KPIM::ExchangeAccount* account, QWidget* parent )
00035   : KDialogBase(Plain,i18n("Exchange Plugin"),Ok|Cancel,Ok,parent)
00036 {
00037   mAccount = account;
00038 
00039   kdDebug() << "Creating ExchangeConfig with account: " << 
00040       account->host() << ":" << account->account() << endl;
00041 
00042   QFrame *topFrame = plainPage();
00043   QGridLayout *topLayout = new QGridLayout( topFrame, 5, 3, 3 );
00044 
00045   m_host = new KLineEdit( mAccount->host(), topFrame );
00046   topLayout->addWidget( new QLabel( i18n( "Exchange server:" ), topFrame ), 0, 0 );
00047   topLayout->addWidget( m_host, 0, 1 );
00048 
00049   m_user = new KLineEdit( mAccount->account(), topFrame );
00050   topLayout->addWidget( new QLabel( i18n( "User:" ), topFrame ), 1, 0 );
00051   topLayout->addWidget( m_user, 1, 1 );
00052 
00053   m_password = new KLineEdit( mAccount->password(), topFrame );
00054   topLayout->addWidget( new QLabel( i18n( "Password:" ), topFrame ), 2, 0 );
00055   topLayout->addWidget( m_password, 2, 1 );
00056   m_password->setEchoMode( QLineEdit::Password );
00057 
00058   m_autoMailbox = new QCheckBox( i18n( "Determine mailbox automatically" ), topFrame );
00059   topLayout->addMultiCellWidget( m_autoMailbox, 3, 3, 0, 1 );
00060   connect( m_autoMailbox, SIGNAL(toggled(bool)), this, SLOT(slotToggleAuto(bool)) );
00061 
00062   m_mailbox= new KLineEdit( mAccount->mailbox(), topFrame );
00063   topLayout->addWidget( new QLabel( i18n( "Mailbox URL:" ), topFrame ), 4, 0 );
00064   topLayout->addWidget( m_mailbox, 4, 1 );
00065 
00066   m_tryFindMailbox = new QPushButton( "&Find", topFrame );
00067   topLayout->addWidget( m_tryFindMailbox, 4, 2 );
00068   connect( m_tryFindMailbox, SIGNAL(clicked()), this, SLOT(slotFindClicked()) );
00069 
00070   kapp->config()->setGroup( "Calendar/Exchange Plugin" );
00071   bool autoChecked = kapp->config()->readBoolEntry( "auto-mailbox", true );
00072   m_autoMailbox->setChecked( autoChecked );
00073 }
00074 
00075 ExchangeConfig::~ExchangeConfig()
00076 {
00077 }
00078 
00079 void ExchangeConfig::slotToggleAuto( bool on )
00080 {
00081   m_mailbox->setEnabled( ! on );
00082 }
00083 
00084 void ExchangeConfig::slotOk()
00085 {
00086   if ( m_autoMailbox->isChecked() ) {
00087     QString mailbox = mAccount->tryFindMailbox( m_host->text(), m_user->text(), m_password->text() );
00088     if ( mailbox.isNull() ) {
00089       kdWarning() << "Could not find Exchange mailbox URL, incomplete settings!"<< endl;
00090       KMessageBox::sorry( this, "Could not determine mailbox URL" );
00091       return; // Do not accept
00092     } else {
00093       mAccount->setMailbox( mailbox );
00094     }
00095   } else {
00096     mAccount->setMailbox( m_mailbox->text() );
00097   }
00098   mAccount->setHost( m_host->text() );
00099   mAccount->setAccount( m_user->text() );
00100   mAccount->setPassword( m_password->text() );
00101 
00102   kapp->config()->setGroup( "Calendar/Exchange Plugin" );
00103   kapp->config()->writeEntry( "auto-mailbox", m_autoMailbox->isChecked() );
00104   
00105   accept();
00106 }
00107 
00108 void ExchangeConfig::slotFindClicked()
00109 {
00110   QString mailbox = mAccount->tryFindMailbox( m_host->text(), m_user->text(), m_password->text() );
00111   if ( mailbox.isNull() ) {
00112     KMessageBox::sorry( this, "Could not determine mailbox URL" );
00113   } else {
00114     m_mailbox->setText( mailbox );
00115   }
00116 }
00117 
00118 #include "exchangeconfig.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:41:08 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001