exchangeconfig.cpp
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18*/
19
20#include <tqlayout.h>
21#include <tqlabel.h>
22#include <tqcombobox.h>
23
24#include <tdeapplication.h>
25#include <tdeconfig.h>
26#include <tdelocale.h>
27#include <kdebug.h>
28#include <tdemessagebox.h>
29
30#include <exchangeaccount.h>
31
32#include "exchangeconfig.h"
33
34ExchangeConfig::ExchangeConfig( KPIM::ExchangeAccount* account, TQWidget* parent )
35 : KDialogBase(Plain,i18n("Exchange Plugin"),Ok|Cancel,Ok,parent)
36{
37 mAccount = account;
38
39 kdDebug(5850) << "Creating ExchangeConfig with account: " <<
40 account->host() << ":" << account->account() << endl;
41
42 TQFrame *topFrame = plainPage();
43 TQGridLayout *topLayout = new TQGridLayout( topFrame, 5, 3, 3 );
44
45 m_host = new KLineEdit( mAccount->host(), topFrame );
46 topLayout->addWidget( new TQLabel( i18n( "Exchange server:" ), topFrame ), 0, 0 );
47 topLayout->addWidget( m_host, 0, 1 );
48
49 m_port = new KLineEdit( mAccount->port(), topFrame );
50 topLayout->addWidget( new TQLabel( i18n( "Port:" ), topFrame ), 1, 0 );
51 topLayout->addWidget( m_port, 1, 1 );
52
53 m_user = new KLineEdit( mAccount->account(), topFrame );
54 topLayout->addWidget( new TQLabel( i18n( "User:" ), topFrame ), 2, 0 );
55 topLayout->addWidget( m_user, 2, 1 );
56 connect( m_user, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(slotUserChanged(const TQString&)) );
57
58 m_password = new KLineEdit( mAccount->password(), topFrame );
59 topLayout->addWidget( new TQLabel( i18n( "Password:" ), topFrame ), 3, 0 );
60 topLayout->addWidget( m_password, 3, 1 );
61 m_password->setEchoMode( TQLineEdit::Password );
62
63 m_autoMailbox = new TQCheckBox( i18n( "Determine mailbox automatically" ), topFrame );
64 topLayout->addMultiCellWidget( m_autoMailbox, 4, 4, 0, 1 );
65 connect( m_autoMailbox, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(slotToggleAuto(bool)) );
66
67 m_mailbox= new KLineEdit( mAccount->mailbox(), topFrame );
68 topLayout->addWidget( new TQLabel( i18n( "Mailbox URL:" ), topFrame ), 5, 0 );
69 topLayout->addWidget( m_mailbox, 5, 1 );
70
71 m_tryFindMailbox = new TQPushButton( "&Find", topFrame );
72 topLayout->addWidget( m_tryFindMailbox, 5, 2 );
73 connect( m_tryFindMailbox, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotFindClicked()) );
74
75 tdeApp->config()->setGroup( "Calendar/Exchange Plugin" );
76 bool autoChecked = tdeApp->config()->readBoolEntry( "auto-mailbox", true );
77 m_autoMailbox->setChecked( autoChecked );
78}
79
80ExchangeConfig::~ExchangeConfig()
81{
82}
83
84void ExchangeConfig::slotToggleAuto( bool on )
85{
86 m_mailbox->setEnabled( ! on );
87// m_tryFindMailbox->setEnabled( ! on );
88// if ( on ) {
89// m_mailbox->setText( "webdav://" + m_host->text() + "/exchange/" + m_user->text() );
90// }
91}
92
93void ExchangeConfig::slotUserChanged( const TQString& /*text*/ )
94{
95// if ( m_mailboxEqualsUser->isChecked() ) {
96// m_mailbox->setText( "webdav://" + m_host->text() + "/exchange/" + text );
97// }
98}
99
100void ExchangeConfig::slotOk()
101{
102 if ( m_autoMailbox->isChecked() ) {
103 TQString mailbox = mAccount->tryFindMailbox( m_host->text(), m_port->text(), m_user->text(), m_password->text() );
104 if ( mailbox.isNull() ) {
105 kdWarning() << "Could not find Exchange mailbox URL, incomplete settings!"<< endl;
106 KMessageBox::sorry( this, "Could not determine mailbox URL" );
107 return; // Do not accept
108 } else {
109 mAccount->setMailbox( mailbox );
110 }
111 } else {
112 mAccount->setMailbox( m_mailbox->text() );
113 }
114 mAccount->setHost( m_host->text() );
115 mAccount->setPort( m_port->text() );
116 mAccount->setAccount( m_user->text() );
117 mAccount->setPassword( m_password->text() );
118
119 tdeApp->config()->setGroup( "Calendar/Exchange Plugin" );
120 tdeApp->config()->writeEntry( "auto-mailbox", m_autoMailbox->isChecked() );
121
122 accept();
123}
124
125void ExchangeConfig::slotFindClicked()
126{
127 TQString mailbox = mAccount->tryFindMailbox( m_host->text(), m_port->text(), m_user->text(), m_password->text() );
128 if ( mailbox.isNull() ) {
129 KMessageBox::sorry( this, "Could not determine mailbox URL" );
130 } else {
131 m_mailbox->setText( mailbox );
132 }
133}
134
135#include "exchangeconfig.moc"