summaryrefslogtreecommitdiffstats
path: root/korganizer/plugins/exchange/exchangeconfig.cpp
blob: fe01324ac3b3cfb7d3fe7e8b1702df4e73ab18bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
    This file is part of KOrganizer.
    Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include <tqlayout.h>
#include <tqlabel.h>
#include <tqcombobox.h>

#include <kapplication.h>
#include <kconfig.h>
#include <klocale.h>
#include <kdebug.h>
#include <kmessagebox.h>

#include <exchangeaccount.h>

#include "exchangeconfig.h"

ExchangeConfig::ExchangeConfig( KPIM::ExchangeAccount* account, TQWidget* parent )
  : KDialogBase(Plain,i18n("Exchange Plugin"),Ok|Cancel,Ok,parent)
{
  mAccount = account;

  kdDebug(5850) << "Creating ExchangeConfig with account: " << 
      account->host() << ":" << account->account() << endl;

  TQFrame *topFrame = plainPage();
  TQGridLayout *topLayout = new TQGridLayout( topFrame, 5, 3, 3 );

  m_host = new KLineEdit( mAccount->host(), topFrame );
  topLayout->addWidget( new TQLabel( i18n( "Exchange server:" ), topFrame ), 0, 0 );
  topLayout->addWidget( m_host, 0, 1 );

  m_port = new KLineEdit( mAccount->port(), topFrame );
  topLayout->addWidget( new TQLabel( i18n( "Port:" ), topFrame ), 1, 0 );
  topLayout->addWidget( m_port, 1, 1 );

  m_user = new KLineEdit( mAccount->account(), topFrame );
  topLayout->addWidget( new TQLabel( i18n( "User:" ), topFrame ), 2, 0 );
  topLayout->addWidget( m_user, 2, 1 );
  connect( m_user, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotUserChanged(const TQString&)) );

  m_password = new KLineEdit( mAccount->password(), topFrame );
  topLayout->addWidget( new TQLabel( i18n( "Password:" ), topFrame ), 3, 0 );
  topLayout->addWidget( m_password, 3, 1 );
  m_password->setEchoMode( TQLineEdit::Password );

  m_autoMailbox = new TQCheckBox( i18n( "Determine mailbox automatically" ), topFrame );
  topLayout->addMultiCellWidget( m_autoMailbox, 4, 4, 0, 1 );
  connect( m_autoMailbox, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotToggleAuto(bool)) );

  m_mailbox= new KLineEdit( mAccount->mailbox(), topFrame );
  topLayout->addWidget( new TQLabel( i18n( "Mailbox URL:" ), topFrame ), 5, 0 );
  topLayout->addWidget( m_mailbox, 5, 1 );

  m_tryFindMailbox = new TQPushButton( "&Find", topFrame );
  topLayout->addWidget( m_tryFindMailbox, 5, 2 );
  connect( m_tryFindMailbox, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotFindClicked()) );

  kapp->config()->setGroup( "Calendar/Exchange Plugin" );
  bool autoChecked = kapp->config()->readBoolEntry( "auto-mailbox", true );
  m_autoMailbox->setChecked( autoChecked );
}

ExchangeConfig::~ExchangeConfig()
{
}

void ExchangeConfig::slotToggleAuto( bool on )
{
  m_mailbox->setEnabled( ! on );
//  m_tryFindMailbox->setEnabled( ! on );
//  if ( on ) {
//    m_mailbox->setText( "webdav://" + m_host->text() + "/exchange/" + m_user->text() );
//  }
}

void ExchangeConfig::slotUserChanged( const TQString& /*text*/ )
{
//  if ( m_mailboxEqualsUser->isChecked() ) {
//    m_mailbox->setText( "webdav://" + m_host->text() + "/exchange/" + text );
//  }
}

void ExchangeConfig::slotOk()
{
  if ( m_autoMailbox->isChecked() ) {
    TQString mailbox = mAccount->tryFindMailbox( m_host->text(), m_port->text(), m_user->text(), m_password->text() );
    if ( mailbox.isNull() ) {
      kdWarning() << "Could not find Exchange mailbox URL, incomplete settings!"<< endl;
      KMessageBox::sorry( this, "Could not determine mailbox URL" );
      return; // Do not accept
    } else {
      mAccount->setMailbox( mailbox );
    }
  } else {
    mAccount->setMailbox( m_mailbox->text() );
  }
  mAccount->setHost( m_host->text() );
  mAccount->setPort( m_port->text() );
  mAccount->setAccount( m_user->text() );
  mAccount->setPassword( m_password->text() );

  kapp->config()->setGroup( "Calendar/Exchange Plugin" );
  kapp->config()->writeEntry( "auto-mailbox", m_autoMailbox->isChecked() );
  
  accept();
}

void ExchangeConfig::slotFindClicked()
{
  TQString mailbox = mAccount->tryFindMailbox( m_host->text(), m_port->text(), m_user->text(), m_password->text() );
  if ( mailbox.isNull() ) {
    KMessageBox::sorry( this, "Could not determine mailbox URL" );
  } else {
    m_mailbox->setText( mailbox );
  }
}

#include "exchangeconfig.moc"