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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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(5850) << "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_port = new KLineEdit( mAccount->port(), topFrame );
00050   topLayout->addWidget( new QLabel( i18n( "Port:" ), topFrame ), 1, 0 );
00051   topLayout->addWidget( m_port, 1, 1 );
00052 
00053   m_user = new KLineEdit( mAccount->account(), topFrame );
00054   topLayout->addWidget( new QLabel( i18n( "User:" ), topFrame ), 2, 0 );
00055   topLayout->addWidget( m_user, 2, 1 );
00056   connect( m_user, SIGNAL(textChanged(const QString&)), this, SLOT(slotUserChanged(const QString&)) );
00057 
00058   m_password = new KLineEdit( mAccount->password(), topFrame );
00059   topLayout->addWidget( new QLabel( i18n( "Password:" ), topFrame ), 3, 0 );
00060   topLayout->addWidget( m_password, 3, 1 );
00061   m_password->setEchoMode( QLineEdit::Password );
00062 
00063   m_autoMailbox = new QCheckBox( i18n( "Determine mailbox automatically" ), topFrame );
00064   topLayout->addMultiCellWidget( m_autoMailbox, 4, 4, 0, 1 );
00065   connect( m_autoMailbox, SIGNAL(toggled(bool)), this, SLOT(slotToggleAuto(bool)) );
00066 
00067   m_mailbox= new KLineEdit( mAccount->mailbox(), topFrame );
00068   topLayout->addWidget( new QLabel( i18n( "Mailbox URL:" ), topFrame ), 5, 0 );
00069   topLayout->addWidget( m_mailbox, 5, 1 );
00070 
00071   m_tryFindMailbox = new QPushButton( "&Find", topFrame );
00072   topLayout->addWidget( m_tryFindMailbox, 5, 2 );
00073   connect( m_tryFindMailbox, SIGNAL(clicked()), this, SLOT(slotFindClicked()) );
00074 
00075   kapp->config()->setGroup( "Calendar/Exchange Plugin" );
00076   bool autoChecked = kapp->config()->readBoolEntry( "auto-mailbox", true );
00077   m_autoMailbox->setChecked( autoChecked );
00078 }
00079 
00080 ExchangeConfig::~ExchangeConfig()
00081 {
00082 }
00083 
00084 void ExchangeConfig::slotToggleAuto( bool on )
00085 {
00086   m_mailbox->setEnabled( ! on );
00087 //  m_tryFindMailbox->setEnabled( ! on );
00088 //  if ( on ) {
00089 //    m_mailbox->setText( "webdav://" + m_host->text() + "/exchange/" + m_user->text() );
00090 //  }
00091 }
00092 
00093 void ExchangeConfig::slotUserChanged( const QString& text )
00094 {
00095 //  if ( m_mailboxEqualsUser->isChecked() ) {
00096 //    m_mailbox->setText( "webdav://" + m_host->text() + "/exchange/" + text );
00097 //  }
00098 }
00099 
00100 void ExchangeConfig::slotOk()
00101 {
00102   if ( m_autoMailbox->isChecked() ) {
00103     QString mailbox = mAccount->tryFindMailbox( m_host->text(), m_port->text(), m_user->text(), m_password->text() );
00104     if ( mailbox.isNull() ) {
00105       kdWarning() << "Could not find Exchange mailbox URL, incomplete settings!"<< endl;
00106       KMessageBox::sorry( this, "Could not determine mailbox URL" );
00107       return; // Do not accept
00108     } else {
00109       mAccount->setMailbox( mailbox );
00110     }
00111   } else {
00112     mAccount->setMailbox( m_mailbox->text() );
00113   }
00114   mAccount->setHost( m_host->text() );
00115   mAccount->setPort( m_port->text() );
00116   mAccount->setAccount( m_user->text() );
00117   mAccount->setPassword( m_password->text() );
00118 
00119   kapp->config()->setGroup( "Calendar/Exchange Plugin" );
00120   kapp->config()->writeEntry( "auto-mailbox", m_autoMailbox->isChecked() );
00121   
00122   accept();
00123 }
00124 
00125 void ExchangeConfig::slotFindClicked()
00126 {
00127   QString mailbox = mAccount->tryFindMailbox( m_host->text(), m_port->text(), m_user->text(), m_password->text() );
00128   if ( mailbox.isNull() ) {
00129     KMessageBox::sorry( this, "Could not determine mailbox URL" );
00130   } else {
00131     m_mailbox->setText( mailbox );
00132   }
00133 }
00134 
00135 #include "exchangeconfig.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:27 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003