~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to kmail/accountdialog.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *   kmail: KDE mail client
3
 
 *   Copyright (C) 2000 Espen Sand, espen@kde.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 along
16
 
 *   with this program; if not, write to the Free Software Foundation, Inc.,
17
 
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 
 *
19
 
 */
20
 
#include "accountdialog.h"
21
 
#include "sieveconfig.h"
22
 
#include "kmacctmaildir.h"
23
 
#include "kmacctlocal.h"
24
 
#include "accountmanager.h"
25
 
#include "popaccount.h"
26
 
#include "kmacctimap.h"
27
 
#include "kmacctcachedimap.h"
28
 
#include "kmfoldermgr.h"
29
 
#include "protocols.h"
30
 
#include "folderrequester.h"
31
 
#include "mainfolderview.h"
32
 
#include "kmmainwidget.h"
33
 
#include "kmfolder.h"
34
 
#include <kpimidentities/identitymanager.h>
35
 
#include <kpimidentities/identitycombo.h>
36
 
#include <kpimidentities/identity.h>
37
 
#include <mailtransport/servertest.h>
38
 
using namespace MailTransport;
39
 
#include "globalsettings.h"
40
 
#include "procmailparser.h"
41
 
#include "autoqpointer.h"
42
 
 
43
 
#include <KComboBox>
44
 
#include <KGlobalSettings>
45
 
#include <KFileDialog>
46
 
#include <KLocale>
47
 
#include <KDebug>
48
 
#include <KMessageBox>
49
 
#include <KNumInput>
50
 
#include <KSeparator>
51
 
#include <KProtocolInfo>
52
 
#include <KIconLoader>
53
 
#include <KMenu>
54
 
 
55
 
#include <QButtonGroup>
56
 
#include <QCheckBox>
57
 
#include <QLayout>
58
 
#include <QRadioButton>
59
 
#include <QValidator>
60
 
#include <QLabel>
61
 
#include <QPushButton>
62
 
#include <QToolButton>
63
 
#include <QGroupBox>
64
 
#include <QGridLayout>
65
 
#include <QVBoxLayout>
66
 
#include <QHBoxLayout>
67
 
 
68
 
namespace {
69
 
 
70
 
class BusyCursorHelper : public QObject
71
 
{
72
 
public:
73
 
  inline BusyCursorHelper( QObject *parent )
74
 
         : QObject( parent )
75
 
  {
76
 
    qApp->setOverrideCursor( Qt::BusyCursor );
77
 
  }
78
 
 
79
 
  inline ~BusyCursorHelper()
80
 
  {
81
 
    qApp->restoreOverrideCursor();
82
 
  }
83
 
};
84
 
 
85
 
}
86
 
 
87
 
namespace KMail {
88
 
 
89
 
 
90
 
AccountDialog::AccountDialog( const QString & caption, KMAccount *account,
91
 
                              QWidget *parent )
92
 
  : KDialog( parent ),
93
 
    mAccount( account ),
94
 
    mServerTest( 0 ),
95
 
    mSieveConfigEditor( 0 )
96
 
{
97
 
  setCaption( caption );
98
 
  setButtons( Ok|Cancel|Help );
99
 
  mValidator = new QRegExpValidator( QRegExp( "[A-Za-z0-9-_:.]*" ), this );
100
 
  setHelp("receiving-mail");
101
 
 
102
 
  KAccount::Type accountType = mAccount->type();
103
 
 
104
 
  if( accountType == KAccount::Local )
105
 
  {
106
 
    makeLocalAccountPage();
107
 
  }
108
 
  else if( accountType == KAccount::Maildir )
109
 
  {
110
 
    makeMaildirAccountPage();
111
 
  }
112
 
  else if( accountType == KAccount::Pop )
113
 
  {
114
 
    makePopAccountPage();
115
 
  }
116
 
  else if( accountType == KAccount::Imap )
117
 
  {
118
 
    makeImapAccountPage();
119
 
  }
120
 
  else if( accountType == KAccount::DImap )
121
 
  {
122
 
    makeImapAccountPage(true);
123
 
  }
124
 
  else
125
 
  {
126
 
    QString msg = i18n( "Account type is not supported." );
127
 
    KMessageBox::information( topLevelWidget(),msg,i18n("Configure Account") );
128
 
    return;
129
 
  }
130
 
 
131
 
  setupSettings();
132
 
  connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
133
 
}
134
 
 
135
 
AccountDialog::~AccountDialog()
136
 
{
137
 
  delete mServerTest;
138
 
  mServerTest = 0;
139
 
}
140
 
 
141
 
void AccountDialog::makeLocalAccountPage()
142
 
{
143
 
  QWidget *page = new QWidget( this );
144
 
  mLocal.ui.setupUi( page );
145
 
  setMainWidget( page );
146
 
 
147
 
  ProcmailRCParser procmailrcParser;
148
 
  mLocal.ui.locationEdit->addItems( procmailrcParser.getSpoolFilesList() );
149
 
  mLocal.ui.choose->setAutoDefault( false );
150
 
  mLocal.ui.procmailLockFileName->addItems( procmailrcParser.getLockFilesList() );
151
 
  mLocal.ui.intervalSpin->setRange( GlobalSettings::self()->minimumCheckInterval(), 10000, 1 );
152
 
 
153
 
  connect( mLocal.ui.choose, SIGNAL(clicked()), this, SLOT(slotLocationChooser()) );
154
 
  connect( mLocal.ui.lockProcmail, SIGNAL(toggled(bool)),
155
 
           mLocal.ui.procmailLockFileName, SLOT(setEnabled(bool)) );
156
 
  connect( mLocal.ui.intervalCheck, SIGNAL(toggled(bool)),
157
 
           this, SLOT(slotEnableLocalInterval(bool)) );
158
 
  connect( KGlobalSettings::self(),SIGNAL(kdisplayFontChanged()),
159
 
           SLOT(slotFontChanged()) );
160
 
}
161
 
 
162
 
void AccountDialog::makeMaildirAccountPage()
163
 
{
164
 
  QWidget *page = new QWidget( this );
165
 
  mMaildir.ui.setupUi( page );
166
 
  setMainWidget( page );
167
 
  ProcmailRCParser procmailrcParser;
168
 
 
169
 
  mMaildir.ui.locationEdit->addItems( procmailrcParser.getSpoolFilesList() );
170
 
  mMaildir.ui.choose->setAutoDefault( false );
171
 
  mMaildir.ui.intervalSpin->setRange( GlobalSettings::self()->minimumCheckInterval(), 10000, 1 );
172
 
 
173
 
  connect( mMaildir.ui.choose, SIGNAL(clicked()),
174
 
           this, SLOT(slotMaildirChooser()) );
175
 
  connect( mMaildir.ui.intervalCheck, SIGNAL(toggled(bool)),
176
 
           this, SLOT(slotEnableMaildirInterval(bool)) );
177
 
  connect( KGlobalSettings::self(),SIGNAL(kdisplayFontChanged()),
178
 
           SLOT(slotFontChanged()) );
179
 
}
180
 
 
181
 
 
182
 
void AccountDialog::makePopAccountPage()
183
 
{
184
 
  QWidget *page = new QWidget( this );
185
 
  mPop.ui.setupUi( page );
186
 
  setMainWidget( page );
187
 
 
188
 
  connect( mPop.ui.passwordEdit, SIGNAL( textEdited( const QString& ) ),
189
 
           this, SLOT( slotPopPasswordChanged( const QString& ) ) );
190
 
 
191
 
  // only letters, digits, '-', '.', ':' (IPv6) and '_' (for Windows
192
 
  // compatibility) are allowed
193
 
  mPop.ui.hostEdit->setValidator( mValidator );
194
 
 
195
 
  connect( mPop.ui.leaveOnServerCheck, SIGNAL( clicked() ),
196
 
           this, SLOT( slotLeaveOnServerClicked() ) );
197
 
  connect( mPop.ui.leaveOnServerDaysCheck, SIGNAL( toggled(bool) ),
198
 
           this, SLOT( slotEnableLeaveOnServerDays(bool)) );
199
 
  connect( mPop.ui.leaveOnServerDaysSpin, SIGNAL(valueChanged(int)),
200
 
           SLOT(slotLeaveOnServerDaysChanged(int)));
201
 
  connect( mPop.ui.leaveOnServerCountCheck, SIGNAL( toggled(bool) ),
202
 
           this, SLOT( slotEnableLeaveOnServerCount(bool)) );
203
 
  connect( mPop.ui.leaveOnServerCountSpin, SIGNAL(valueChanged(int)),
204
 
           SLOT(slotLeaveOnServerCountChanged(int)));
205
 
  connect( mPop.ui.leaveOnServerSizeCheck, SIGNAL( toggled(bool) ),
206
 
           this, SLOT( slotEnableLeaveOnServerSize(bool)) );
207
 
 
208
 
  connect(mPop.ui.filterOnServerSizeSpin, SIGNAL(valueChanged(int)),
209
 
          SLOT(slotFilterOnServerSizeChanged(int)));
210
 
  connect( mPop.ui.filterOnServerCheck, SIGNAL(toggled(bool)),
211
 
           mPop.ui.filterOnServerSizeSpin, SLOT(setEnabled(bool)) );
212
 
  connect( mPop.ui.filterOnServerCheck, SIGNAL( clicked() ),
213
 
           this, SLOT( slotFilterOnServerClicked() ) );
214
 
 
215
 
  connect( mPop.ui.intervalCheck, SIGNAL(toggled(bool)),
216
 
           this, SLOT(slotEnablePopInterval(bool)) );
217
 
  mPop.ui.intervalSpin->setRange( GlobalSettings::self()->minimumCheckInterval(),
218
 
                                  10000, 1 );
219
 
 
220
 
//  Page 2
221
 
  connect( mPop.ui.checkCapabilities, SIGNAL(clicked()),
222
 
           SLOT(slotCheckPopCapabilities()) );
223
 
  mPop.encryptionButtonGroup = new QButtonGroup();
224
 
  mPop.encryptionButtonGroup->addButton( mPop.ui.encryptionNone,
225
 
                                         Transport::EnumEncryption::None );
226
 
  mPop.encryptionButtonGroup->addButton( mPop.ui.encryptionSSL,
227
 
                                         Transport::EnumEncryption::SSL );
228
 
  mPop.encryptionButtonGroup->addButton( mPop.ui.encryptionTLS,
229
 
                                         Transport::EnumEncryption::TLS );
230
 
 
231
 
  connect( mPop.encryptionButtonGroup, SIGNAL(buttonClicked(int)),
232
 
           SLOT(slotPopEncryptionChanged(int)) );
233
 
 
234
 
  if ( KProtocolInfo::capabilities("pop3").contains("SASL") == 0 )
235
 
  {
236
 
    mPop.ui.authNTLM->hide();
237
 
    mPop.ui.authGSSAPI->hide();
238
 
  }
239
 
  mPop.authButtonGroup = new QButtonGroup();
240
 
  mPop.authButtonGroup->addButton( mPop.ui.authUser );
241
 
  mPop.authButtonGroup->addButton( mPop.ui.authLogin );
242
 
  mPop.authButtonGroup->addButton( mPop.ui.authPlain );
243
 
  mPop.authButtonGroup->addButton( mPop.ui.authCRAM_MD5 );
244
 
  mPop.authButtonGroup->addButton( mPop.ui.authDigestMd5 );
245
 
  mPop.authButtonGroup->addButton( mPop.ui.authNTLM );
246
 
  mPop.authButtonGroup->addButton( mPop.ui.authGSSAPI );
247
 
  mPop.authButtonGroup->addButton( mPop.ui.authAPOP );
248
 
 
249
 
  connect( mPop.ui.usePipeliningCheck, SIGNAL(clicked()),
250
 
           SLOT(slotPipeliningClicked()) );
251
 
 
252
 
  connect(KGlobalSettings::self(),SIGNAL(kdisplayFontChanged()),
253
 
          SLOT(slotFontChanged()));
254
 
}
255
 
 
256
 
 
257
 
void AccountDialog::makeImapAccountPage( bool connected )
258
 
{
259
 
  QWidget *page = new QWidget( this );
260
 
  mImap.ui.setupUi( page );
261
 
  setMainWidget( page );
262
 
  if( connected )
263
 
    mImap.ui.titleLabel->setText( i18n("Account Type: Disconnected IMAP Account") );
264
 
  else
265
 
    mImap.ui.titleLabel->setText( i18n("Account Type: IMAP Account") );
266
 
 
267
 
  // only letters, digits, '-', '.', ':' (IPv6) and '_' (for Windows
268
 
  // compatibility) are allowed
269
 
  mImap.ui.hostEdit->setValidator( mValidator );
270
 
 
271
 
  mImap.ui.button->setAutoRaise( true );
272
 
  mImap.ui.button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
273
 
  mImap.ui.button->setFixedSize( 22, 22 );
274
 
  mImap.ui.button->setIcon( KIcon("view-refresh") );
275
 
  mImap.ui.editPNS->setIcon( KIcon("document-properties") );
276
 
  mImap.ui.editPNS->setFixedSize( 22, 22 );
277
 
  mImap.ui.editONS->setIcon( KIcon("document-properties") );
278
 
  mImap.ui.editONS->setFixedSize( 22, 22 );
279
 
  mImap.ui.editSNS->setIcon( KIcon("document-properties") );
280
 
  mImap.ui.editSNS->setFixedSize( 22, 22 );
281
 
 
282
 
  mImap.ui.intervalSpin->setRange( GlobalSettings::self()->minimumCheckInterval(), 10000, 1 );
283
 
 
284
 
  if( connected ) {
285
 
    // not implemented for disconnected yet
286
 
    mImap.ui.autoExpungeCheck->hide();
287
 
    mImap.ui.loadOnDemandCheck->hide();
288
 
    mImap.ui.listOnlyOpenCheck->hide();
289
 
  }
290
 
 
291
 
  mImap.trashCombo = new FolderRequester( page );
292
 
  mImap.trashCombo->setFolderTree( kmkernel->getKMMainWidget()->mainFolderView() );
293
 
  mImap.trashCombo->setShowOutbox( false );
294
 
  mImap.ui.trashLabel->setBuddy( mImap.trashCombo );
295
 
  mImap.ui.trashLayout->addWidget( mImap.trashCombo, 1 );
296
 
  mImap.ui.trashLabel->setBuddy( mImap.trashCombo );
297
 
 
298
 
  mImap.identityCombo = new KPIMIdentities::IdentityCombo( kmkernel->identityManager(), page );
299
 
  mImap.ui.identityLabel->setBuddy( mImap.identityCombo );
300
 
  mImap.ui.identityLayout->addWidget( mImap.identityCombo, 1 );
301
 
  mImap.ui.identityLabel->setBuddy( mImap.identityCombo );
302
 
 
303
 
  mImap.encryptionButtonGroup = new QButtonGroup();
304
 
  mImap.encryptionButtonGroup->addButton( mImap.ui.encryptionNone,
305
 
                                          Transport::EnumEncryption::None );
306
 
  mImap.encryptionButtonGroup->addButton( mImap.ui.encryptionSSL,
307
 
                                          Transport::EnumEncryption::SSL );
308
 
  mImap.encryptionButtonGroup->addButton( mImap.ui.encryptionTLS,
309
 
                                          Transport::EnumEncryption::TLS );
310
 
 
311
 
  mImap.authButtonGroup = new QButtonGroup();
312
 
  mImap.authButtonGroup->addButton( mImap.ui.authUser );
313
 
  mImap.authButtonGroup->addButton( mImap.ui.authLogin );
314
 
  mImap.authButtonGroup->addButton( mImap.ui.authPlain );
315
 
  mImap.authButtonGroup->addButton( mImap.ui.authCramMd5 );
316
 
  mImap.authButtonGroup->addButton( mImap.ui.authDigestMd5 );
317
 
  mImap.authButtonGroup->addButton( mImap.ui.authNTLM );
318
 
  mImap.authButtonGroup->addButton( mImap.ui.authGSSAPI );
319
 
  mImap.authButtonGroup->addButton( mImap.ui.authAnonymous );
320
 
 
321
 
 
322
 
 
323
 
  // Connect all slots.
324
 
  connect( mImap.ui.button, SIGNAL(clicked()), this, SLOT(slotReloadNamespaces()) );
325
 
  connect( mImap.ui.editPNS, SIGNAL(clicked()), this, SLOT(slotEditPersonalNamespace()) );
326
 
  connect( mImap.ui.editONS, SIGNAL(clicked()), this, SLOT(slotEditOtherUsersNamespace()) );
327
 
  connect( mImap.ui.editSNS, SIGNAL(clicked()), this, SLOT(slotEditSharedNamespace()) );
328
 
  connect( mImap.ui.intervalCheck, SIGNAL(toggled(bool)), this, SLOT(slotEnableImapInterval(bool)) );
329
 
  connect( mImap.ui.useDefaultIdentityCheck, SIGNAL( toggled(bool) ), this, SLOT( slotIdentityCheckboxChanged() ) );
330
 
  connect( mImap.ui.checkCapabilities, SIGNAL(clicked()), SLOT(slotCheckImapCapabilities()));
331
 
  connect( mImap.encryptionButtonGroup, SIGNAL(buttonClicked(int)), SLOT(slotImapEncryptionChanged(int)) );
332
 
  connect( mImap.ui.passwordEdit, SIGNAL( textEdited( const QString& ) ),
333
 
           this, SLOT( slotImapPasswordChanged( const QString& ) ) );
334
 
 
335
 
  // TODO (marc/bo): Test this
336
 
  mSieveConfigEditor = new SieveConfigEditor( mImap.ui.tabWidget );
337
 
  mSieveConfigEditor->layout()->setMargin( KDialog::marginHint() );
338
 
  mImap.ui.tabWidget->addTab( mSieveConfigEditor, i18n("Filtering") );
339
 
 
340
 
  connect( KGlobalSettings::self(),SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged()) );
341
 
}
342
 
 
343
 
 
344
 
void AccountDialog::setupSettings()
345
 
{
346
 
  KComboBox *folderCombo = 0;
347
 
  bool intervalCheckingEnabled = ( mAccount->checkInterval() > 0 );
348
 
  int interval = mAccount->checkInterval();
349
 
  if ( !intervalCheckingEnabled ) // Default to 5 minutes when the user enables
350
 
    interval = 5;                 // interval checking for the first time
351
 
 
352
 
  KAccount::Type accountType = mAccount->type();
353
 
  if( accountType == KAccount::Local )
354
 
  {
355
 
    ProcmailRCParser procmailrcParser;
356
 
    KMAcctLocal *acctLocal = static_cast<KMAcctLocal*>(mAccount);
357
 
 
358
 
    if ( acctLocal->location().isEmpty() )
359
 
      acctLocal->setLocation( procmailrcParser.getSpoolFilesList().first() );
360
 
    else
361
 
      mLocal.ui.locationEdit->addItem( acctLocal->location() );
362
 
 
363
 
    if ( acctLocal->procmailLockFileName().isEmpty() )
364
 
      acctLocal->setProcmailLockFileName( procmailrcParser.getLockFilesList().first() );
365
 
 
366
 
    mLocal.ui.nameEdit->setText( mAccount->name() );
367
 
    mLocal.ui.nameEdit->setFocus();
368
 
    mLocal.ui.locationEdit->setEditText( acctLocal->location() );
369
 
    if (acctLocal->lockType() == mutt_dotlock)
370
 
      mLocal.ui.lockMutt->setChecked(true);
371
 
    else if (acctLocal->lockType() == mutt_dotlock_privileged)
372
 
      mLocal.ui.lockMuttPriv->setChecked(true);
373
 
    else if (acctLocal->lockType() == procmail_lockfile) {
374
 
      mLocal.ui.lockProcmail->setChecked(true);
375
 
      mLocal.ui.procmailLockFileName->setEditText(acctLocal->procmailLockFileName());
376
 
    } else if (acctLocal->lockType() == FCNTL)
377
 
      mLocal.ui.lockFcntl->setChecked(true);
378
 
    else if (acctLocal->lockType() == lock_none)
379
 
      mLocal.ui.lockNone->setChecked(true);
380
 
 
381
 
    mLocal.ui.intervalSpin->setValue( interval );
382
 
    mLocal.ui.intervalCheck->setChecked( intervalCheckingEnabled );
383
 
    mLocal.ui.includeInCheck->setChecked( !mAccount->checkExclude() );
384
 
    mLocal.ui.precommand->setText( mAccount->precommand() );
385
 
 
386
 
    slotEnableLocalInterval( intervalCheckingEnabled );
387
 
    folderCombo = mLocal.ui.folderCombo;
388
 
  }
389
 
  else if( accountType == KAccount::Pop )
390
 
  {
391
 
    PopAccount &ap = *(PopAccount*)mAccount;
392
 
    mPop.ui.nameEdit->setText( mAccount->name() );
393
 
    mPop.ui.nameEdit->setFocus();
394
 
    mPop.ui.loginEdit->setText( ap.login() );
395
 
    mPop.ui.passwordEdit->setText( ap.passwd());
396
 
    mPop.ui.hostEdit->setText( ap.host() );
397
 
    mPop.ui.portEdit->setValue( ap.port() );
398
 
    mPop.ui.usePipeliningCheck->setChecked( ap.usePipelining() );
399
 
    mPop.ui.storePasswordCheck->setChecked( ap.storePasswd() );
400
 
    mPop.ui.leaveOnServerCheck->setChecked( ap.leaveOnServer() );
401
 
    mPop.ui.leaveOnServerDaysCheck->setEnabled( ap.leaveOnServer() );
402
 
    mPop.ui.leaveOnServerDaysCheck->setChecked( ap.leaveOnServerDays() >= 1 );
403
 
    mPop.ui.leaveOnServerDaysSpin->setValue( ap.leaveOnServerDays() >= 1 ?
404
 
                                            ap.leaveOnServerDays() : 7 );
405
 
    mPop.ui.leaveOnServerCountCheck->setEnabled( ap.leaveOnServer() );
406
 
    mPop.ui.leaveOnServerCountCheck->setChecked( ap.leaveOnServerCount() >= 1 );
407
 
    mPop.ui.leaveOnServerCountSpin->setValue( ap.leaveOnServerCount() >= 1 ?
408
 
                                            ap.leaveOnServerCount() : 100 );
409
 
    mPop.ui.leaveOnServerSizeCheck->setEnabled( ap.leaveOnServer() );
410
 
    mPop.ui.leaveOnServerSizeCheck->setChecked( ap.leaveOnServerSize() >= 1 );
411
 
    mPop.ui.leaveOnServerSizeSpin->setValue( ap.leaveOnServerSize() >= 1 ?
412
 
                                            ap.leaveOnServerSize() : 10 );
413
 
    mPop.ui.filterOnServerCheck->setChecked( ap.filterOnServer() );
414
 
    mPop.ui.filterOnServerSizeSpin->setValue( ap.filterOnServerCheckSize() );
415
 
    mPop.ui.intervalCheck->setChecked( intervalCheckingEnabled );
416
 
    mPop.ui.intervalSpin->setValue( interval );
417
 
    mPop.ui.includeInCheck->setChecked( !mAccount->checkExclude() );
418
 
    mPop.ui.precommand->setText( ap.precommand() );
419
 
    if (ap.useSSL())
420
 
      mPop.ui.encryptionSSL->setChecked( true );
421
 
    else if (ap.useTLS())
422
 
      mPop.ui.encryptionTLS->setChecked( true );
423
 
    else mPop.ui.encryptionNone->setChecked( true );
424
 
    if (ap.auth() == "LOGIN")
425
 
      mPop.ui.authLogin->setChecked( true );
426
 
    else if (ap.auth() == "PLAIN")
427
 
      mPop.ui.authPlain->setChecked( true );
428
 
    else if (ap.auth() == "CRAM-MD5")
429
 
      mPop.ui.authCRAM_MD5->setChecked( true );
430
 
    else if (ap.auth() == "DIGEST-MD5")
431
 
      mPop.ui.authDigestMd5->setChecked( true );
432
 
    else if (ap.auth() == "NTLM")
433
 
      mPop.ui.authNTLM->setChecked( true );
434
 
    else if (ap.auth() == "GSSAPI")
435
 
      mPop.ui.authGSSAPI->setChecked( true );
436
 
    else if (ap.auth() == "APOP")
437
 
      mPop.ui.authAPOP->setChecked( true );
438
 
    else mPop.ui.authUser->setChecked( true );
439
 
 
440
 
    slotEnableLeaveOnServerDays( mPop.ui.leaveOnServerDaysCheck->isEnabled() ?
441
 
                                   ap.leaveOnServerDays() >= 1 : 0);
442
 
    slotEnableLeaveOnServerCount( mPop.ui.leaveOnServerCountCheck->isEnabled() ?
443
 
                                    ap.leaveOnServerCount() >= 1 : 0);
444
 
    slotEnableLeaveOnServerSize( mPop.ui.leaveOnServerSizeCheck->isEnabled() ?
445
 
                                    ap.leaveOnServerSize() >= 1 : 0);
446
 
    slotEnablePopInterval( intervalCheckingEnabled );
447
 
    folderCombo = mPop.ui.folderCombo;
448
 
  }
449
 
  else if( accountType == KAccount::Imap )
450
 
  {
451
 
    KMAcctImap &ai = *(KMAcctImap*)mAccount;
452
 
    mImap.ui.nameEdit->setText( mAccount->name() );
453
 
    mImap.ui.nameEdit->setFocus();
454
 
    mImap.ui.loginEdit->setText( ai.login() );
455
 
    mImap.ui.passwordEdit->setText( ai.passwd());
456
 
    mImap.ui.hostEdit->setText( ai.host() );
457
 
    mImap.ui.portEdit->setValue( ai.port() );
458
 
    mImap.ui.autoExpungeCheck->setChecked( ai.autoExpunge() );
459
 
    mImap.ui.hiddenFoldersCheck->setChecked( ai.hiddenFolders() );
460
 
    mImap.ui.subscribedFoldersCheck->setChecked( ai.onlySubscribedFolders() );
461
 
    mImap.ui.locallySubscribedFoldersCheck->setChecked( ai.onlyLocallySubscribedFolders() );
462
 
    mImap.ui.loadOnDemandCheck->setChecked( ai.loadOnDemand() );
463
 
    mImap.ui.listOnlyOpenCheck->setChecked( ai.listOnlyOpenFolders() );
464
 
    mImap.ui.storePasswordCheck->setChecked( ai.storePasswd() );
465
 
    mImap.ui.intervalCheck->setChecked( intervalCheckingEnabled );
466
 
    mImap.ui.intervalSpin->setValue( interval);
467
 
    
468
 
    mImap.ui.includeInCheck->setChecked( !ai.checkExclude() );
469
 
    QString trashfolder = ai.trash();
470
 
    if (trashfolder.isEmpty())
471
 
      trashfolder = kmkernel->trashFolder()->idString();
472
 
    mImap.trashCombo->setFolder( trashfolder );
473
 
    slotEnableImapInterval( intervalCheckingEnabled );
474
 
    mImap.identityCombo->setCurrentIdentity( mAccount->identityId() );
475
 
    mImap.ui.useDefaultIdentityCheck->setChecked( mAccount->useDefaultIdentity() );
476
 
    //mImap.identityCombo->insertStringList( kmkernel->identityManager()->shadowIdentities() );
477
 
    if (ai.useSSL())
478
 
      mImap.ui.encryptionSSL->setChecked( true );
479
 
    else if (ai.useTLS())
480
 
      mImap.ui.encryptionTLS->setChecked( true );
481
 
    else mImap.ui.encryptionNone->setChecked( true );
482
 
    if (ai.auth() == "CRAM-MD5")
483
 
      mImap.ui.authCramMd5->setChecked( true );
484
 
    else if (ai.auth() == "DIGEST-MD5")
485
 
      mImap.ui.authDigestMd5->setChecked( true );
486
 
    else if (ai.auth() == "NTLM")
487
 
      mImap.ui.authNTLM->setChecked( true );
488
 
    else if (ai.auth() == "GSSAPI")
489
 
      mImap.ui.authGSSAPI->setChecked( true );
490
 
    else if (ai.auth() == "ANONYMOUS")
491
 
      mImap.ui.authAnonymous->setChecked( true );
492
 
    else if (ai.auth() == "PLAIN")
493
 
      mImap.ui.authPlain->setChecked( true );
494
 
    else if (ai.auth() == "LOGIN")
495
 
      mImap.ui.authLogin->setChecked( true );
496
 
    else mImap.ui.authUser->setChecked( true );
497
 
    if ( mSieveConfigEditor )
498
 
      mSieveConfigEditor->setConfig( ai.sieveConfig() );
499
 
  }
500
 
  else if( accountType == KAccount::DImap )
501
 
  {
502
 
    KMAcctCachedImap &ai = *(KMAcctCachedImap*)mAccount;
503
 
    mImap.ui.nameEdit->setText( mAccount->name() );
504
 
    mImap.ui.nameEdit->setFocus();
505
 
    mImap.ui.loginEdit->setText( ai.login() );
506
 
    mImap.ui.passwordEdit->setText( ai.passwd());
507
 
    mImap.ui.hostEdit->setText( ai.host() );
508
 
    mImap.ui.portEdit->setValue( ai.port() );
509
 
    mImap.ui.hiddenFoldersCheck->setChecked( ai.hiddenFolders() );
510
 
    mImap.ui.subscribedFoldersCheck->setChecked( ai.onlySubscribedFolders() );
511
 
    mImap.ui.locallySubscribedFoldersCheck->setChecked( ai.onlyLocallySubscribedFolders() );
512
 
    mImap.ui.storePasswordCheck->setChecked( ai.storePasswd() );
513
 
    mImap.ui.intervalCheck->setChecked( intervalCheckingEnabled );
514
 
    mImap.ui.intervalSpin->setValue( interval );
515
 
    mImap.ui.includeInCheck->setChecked( !ai.checkExclude() );
516
 
    QString trashfolder = ai.trash();
517
 
    if (trashfolder.isEmpty())
518
 
      trashfolder = kmkernel->trashFolder()->idString();
519
 
    mImap.trashCombo->setFolder( trashfolder );
520
 
    slotEnableImapInterval( intervalCheckingEnabled );
521
 
    mImap.identityCombo->setCurrentIdentity( mAccount->identityId() );
522
 
    mImap.ui.useDefaultIdentityCheck->setChecked( mAccount->useDefaultIdentity() );
523
 
    //mImap.identityCombo->insertStringList( kmkernel->identityManager()->shadowIdentities() );
524
 
    if (ai.useSSL())
525
 
      mImap.ui.encryptionSSL->setChecked( true );
526
 
    else if (ai.useTLS())
527
 
      mImap.ui.encryptionTLS->setChecked( true );
528
 
    else mImap.ui.encryptionNone->setChecked( true );
529
 
    if (ai.auth() == "CRAM-MD5")
530
 
      mImap.ui.authCramMd5->setChecked( true );
531
 
    else if (ai.auth() == "DIGEST-MD5")
532
 
      mImap.ui.authDigestMd5->setChecked( true );
533
 
    else if (ai.auth() == "GSSAPI")
534
 
      mImap.ui.authGSSAPI->setChecked( true );
535
 
    else if (ai.auth() == "NTLM")
536
 
      mImap.ui.authNTLM->setChecked( true );
537
 
    else if (ai.auth() == "ANONYMOUS")
538
 
      mImap.ui.authAnonymous->setChecked( true );
539
 
    else if (ai.auth() == "PLAIN")
540
 
      mImap.ui.authPlain->setChecked( true );
541
 
    else if (ai.auth() == "LOGIN")
542
 
      mImap.ui.authLogin->setChecked( true );
543
 
    else mImap.ui.authUser->setChecked( true );
544
 
    if ( mSieveConfigEditor )
545
 
      mSieveConfigEditor->setConfig( ai.sieveConfig() );
546
 
  }
547
 
  else if( accountType == KAccount::Maildir )
548
 
  {
549
 
    KMAcctMaildir *acctMaildir = dynamic_cast<KMAcctMaildir*>(mAccount);
550
 
 
551
 
    mMaildir.ui.nameEdit->setText( mAccount->name() );
552
 
    mMaildir.ui.nameEdit->setFocus();
553
 
    mMaildir.ui.locationEdit->setEditText( acctMaildir->location() );
554
 
 
555
 
    mMaildir.ui.intervalSpin->setValue( interval );
556
 
    mMaildir.ui.intervalCheck->setChecked( intervalCheckingEnabled );
557
 
    mMaildir.ui.includeInCheck->setChecked( !mAccount->checkExclude() );
558
 
    mMaildir.ui.precommand->setText( mAccount->precommand() );
559
 
    slotEnableMaildirInterval( intervalCheckingEnabled );
560
 
    folderCombo = mMaildir.ui.folderCombo;
561
 
  }
562
 
  else // Unknown account type
563
 
    return;
564
 
 
565
 
  if ( accountType == KAccount::Imap ||
566
 
       accountType == KAccount::DImap )
567
 
  {
568
 
    // settings for imap in general
569
 
    ImapAccountBase &ai = *(ImapAccountBase*)mAccount;
570
 
    // namespaces
571
 
    if ( ( ai.namespaces().isEmpty() || ai.namespaceToDelimiter().isEmpty() ) &&
572
 
         !ai.login().isEmpty() && !ai.passwd().isEmpty() && !ai.host().isEmpty() )
573
 
    {
574
 
      slotReloadNamespaces();
575
 
    } else {
576
 
      slotSetupNamespaces( ai.namespacesWithDelimiter() );
577
 
    }
578
 
  }
579
 
 
580
 
  if (!folderCombo) return;
581
 
 
582
 
  KMFolderDir *fdir = (KMFolderDir*)&kmkernel->folderMgr()->dir();
583
 
  KMFolder *acctFolder = mAccount->folder();
584
 
  if( acctFolder == 0 )
585
 
  {
586
 
    acctFolder = (KMFolder*)fdir->first();
587
 
  }
588
 
  if( acctFolder == 0 )
589
 
  {
590
 
    folderCombo->addItem( i18nc("Placeholder for the case that there is no folder."
591
 
      , "<placeholder>none</placeholder>") );
592
 
  }
593
 
  else
594
 
  {
595
 
    int i = 0;
596
 
    int curIndex = -1;
597
 
    kmkernel->folderMgr()->createI18nFolderList(&mFolderNames, &mFolderList);
598
 
    while (i < mFolderNames.count())
599
 
    {
600
 
      //QList<QPointer<KMFolder> >::Iterator it = mFolderList.at(i);
601
 
      KMFolder *folder = mFolderList.at(i);
602
 
      if (folder->isSystemFolder())
603
 
      {
604
 
        mFolderList.removeAll(folder);
605
 
        mFolderNames.removeAt(i);
606
 
      } else {
607
 
        if (folder == acctFolder) curIndex = i;
608
 
        i++;
609
 
      }
610
 
    }
611
 
    mFolderNames.prepend(i18n("inbox"));
612
 
    mFolderList.prepend(kmkernel->inboxFolder());
613
 
    folderCombo->addItems(mFolderNames);
614
 
    folderCombo->setCurrentIndex(curIndex + 1);
615
 
 
616
 
    // -sanders hack for startup users. Must investigate this properly
617
 
    if (folderCombo->count() == 0)
618
 
      folderCombo->addItem( i18n("inbox") );
619
 
  }
620
 
}
621
 
 
622
 
void AccountDialog::slotLeaveOnServerClicked()
623
 
{
624
 
  bool state = mPop.ui.leaveOnServerCheck->isChecked();
625
 
  mPop.ui.leaveOnServerDaysCheck->setEnabled( state );
626
 
  mPop.ui.leaveOnServerCountCheck->setEnabled( state );
627
 
  mPop.ui.leaveOnServerSizeCheck->setEnabled( state );
628
 
  if ( state ) {
629
 
    if ( mPop.ui.leaveOnServerDaysCheck->isChecked() ) {
630
 
      slotEnableLeaveOnServerDays( state );
631
 
    }
632
 
    if ( mPop.ui.leaveOnServerCountCheck->isChecked() ) {
633
 
      slotEnableLeaveOnServerCount( state );
634
 
    }
635
 
    if ( mPop.ui.leaveOnServerSizeCheck->isChecked() ) {
636
 
      slotEnableLeaveOnServerSize( state );
637
 
    }
638
 
  } else {
639
 
    slotEnableLeaveOnServerDays( state );
640
 
    slotEnableLeaveOnServerCount( state );
641
 
    slotEnableLeaveOnServerSize( state );
642
 
  }
643
 
  if ( mServerTest && !mServerTest->capabilities().contains( ServerTest::UIDL ) &&
644
 
       mPop.ui.leaveOnServerCheck->isChecked() ) {
645
 
    KMessageBox::information( topLevelWidget(),
646
 
                              i18n("The server does not seem to support unique "
647
 
                                   "message numbers, but this is a "
648
 
                                   "requirement for leaving messages on the "
649
 
                                   "server.\n"
650
 
                                   "Since some servers do not correctly "
651
 
                                   "announce their capabilities you still "
652
 
                                   "have the possibility to turn leaving "
653
 
                                   "fetched messages on the server on.") );
654
 
  }
655
 
}
656
 
 
657
 
void AccountDialog::slotFilterOnServerClicked()
658
 
{
659
 
  if ( mServerTest && !mServerTest->capabilities().contains( ServerTest::Top ) &&
660
 
       mPop.ui.filterOnServerCheck->isChecked() ) {
661
 
    KMessageBox::information( topLevelWidget(),
662
 
                              i18n("The server does not seem to support "
663
 
                                   "fetching message headers, but this is a "
664
 
                                   "requirement for filtering messages on the "
665
 
                                   "server.\n"
666
 
                                   "Since some servers do not correctly "
667
 
                                   "announce their capabilities you still "
668
 
                                   "have the possibility to turn filtering "
669
 
                                   "messages on the server on.") );
670
 
  }
671
 
}
672
 
 
673
 
void AccountDialog::slotPipeliningClicked()
674
 
{
675
 
  if (mPop.ui.usePipeliningCheck->isChecked())
676
 
    KMessageBox::information( topLevelWidget(),
677
 
      i18n("Please note that this feature can cause some POP3 servers "
678
 
      "that do not support pipelining to send corrupted mail;\n"
679
 
      "this is configurable, though, because some servers support pipelining "
680
 
      "but do not announce their capabilities. To check whether your POP3 server "
681
 
      "announces pipelining support use the \"Check What the Server "
682
 
      "Supports\" button at the bottom of the Security tab in this dialog;\n"
683
 
      "if your server does not announce it, but you want more speed, then "
684
 
      "you should do some testing first by sending yourself a batch "
685
 
      "of mail and downloading it."), QString(),
686
 
      "pipelining");
687
 
}
688
 
 
689
 
 
690
 
void AccountDialog::slotPopEncryptionChanged( int id )
691
 
{
692
 
  kDebug() << "ID:" << id;
693
 
  // adjust port
694
 
  if ( id == Transport::EnumEncryption::SSL || mPop.ui.portEdit->value() == 995 )
695
 
    mPop.ui.portEdit->setValue( ( id == Transport::EnumEncryption::SSL ) ? 995 : 110 );
696
 
 
697
 
  enablePopFeatures();
698
 
  const QAbstractButton *old = mPop.authButtonGroup->checkedButton();
699
 
  if ( old && !old->isEnabled() )
700
 
    checkHighest( mPop.authButtonGroup );
701
 
}
702
 
 
703
 
void AccountDialog::slotPopPasswordChanged( const QString& text )
704
 
{
705
 
  if ( text.isEmpty() )
706
 
    mPop.ui.storePasswordCheck->setCheckState( Qt::Unchecked );
707
 
  else
708
 
    mPop.ui.storePasswordCheck->setCheckState( Qt::Checked );
709
 
}
710
 
 
711
 
void AccountDialog::slotImapPasswordChanged( const QString& text )
712
 
{
713
 
  if ( text.isEmpty() )
714
 
    mImap.ui.storePasswordCheck->setCheckState( Qt::Unchecked );
715
 
  else
716
 
    mImap.ui.storePasswordCheck->setCheckState( Qt::Checked );
717
 
}
718
 
 
719
 
void AccountDialog::slotImapEncryptionChanged( int id )
720
 
{
721
 
  kDebug() << id;
722
 
  // adjust port
723
 
  if ( id == Transport::EnumEncryption::SSL || mImap.ui.portEdit->value() == 993 )
724
 
    mImap.ui.portEdit->setValue( ( id == Transport::EnumEncryption::SSL ) ? 993 : 143 );
725
 
 
726
 
  enableImapAuthMethods();
727
 
  QAbstractButton *old = mImap.authButtonGroup->checkedButton();
728
 
  if ( !old->isEnabled() )
729
 
    checkHighest( mImap.authButtonGroup );
730
 
}
731
 
 
732
 
 
733
 
void AccountDialog::slotCheckPopCapabilities()
734
 
{
735
 
  if ( mPop.ui.hostEdit->text().isEmpty() )
736
 
  {
737
 
     KMessageBox::sorry( this, i18n( "Please specify a server and port on "
738
 
                                     "the General tab first." ) );
739
 
     return;
740
 
  }
741
 
  delete mServerTest;
742
 
  mServerTest = new ServerTest( this );
743
 
  BusyCursorHelper *busyCursorHelper = new BusyCursorHelper( mServerTest );
744
 
  mServerTest->setProgressBar( mPop.ui.checkCapabilitiesProgress );
745
 
  mPop.ui.checkCapabilitiesStack->setCurrentIndex( 1 );
746
 
  Transport::EnumEncryption::type encryptionType;
747
 
  if ( mPop.ui.encryptionSSL->isChecked() )
748
 
    encryptionType = Transport::EnumEncryption::SSL;
749
 
  else
750
 
    encryptionType = Transport::EnumEncryption::None;
751
 
  mServerTest->setPort( encryptionType, mPop.ui.portEdit->value() );
752
 
  mServerTest->setServer( mPop.ui.hostEdit->text() );
753
 
  mServerTest->setProtocol( "pop" );
754
 
  connect( mServerTest, SIGNAL( finished(QList<int>) ),
755
 
           this, SLOT( slotPopCapabilities(QList<int>) ) );
756
 
  connect( mServerTest, SIGNAL( finished(QList<int>) ),
757
 
           busyCursorHelper, SLOT( deleteLater() ) );
758
 
  mServerTest->start();
759
 
  mServerTestFailed = false;
760
 
}
761
 
 
762
 
 
763
 
void AccountDialog::slotCheckImapCapabilities()
764
 
{
765
 
  if ( mImap.ui.hostEdit->text().isEmpty() )
766
 
  {
767
 
     KMessageBox::sorry( this, i18n( "Please specify a server and port on "
768
 
              "the General tab first." ) );
769
 
     return;
770
 
  }
771
 
  delete mServerTest;
772
 
  mServerTest = new ServerTest( this );
773
 
  BusyCursorHelper *busyCursorHelper = new BusyCursorHelper( mServerTest );
774
 
  mServerTest->setProgressBar( mImap.ui.checkCapabilitiesProgress );
775
 
  mImap.ui.checkCapabilitiesStack->setCurrentIndex( 1 );
776
 
  Transport::EnumEncryption::type encryptionType;
777
 
  if ( mImap.ui.encryptionSSL->isChecked() )
778
 
    encryptionType = Transport::EnumEncryption::SSL;
779
 
  else
780
 
    encryptionType = Transport::EnumEncryption::None;
781
 
  mServerTest->setPort( encryptionType, mImap.ui.portEdit->value() );
782
 
  mServerTest->setServer( mImap.ui.hostEdit->text() );
783
 
  mServerTest->setProtocol( "imap" );
784
 
  connect( mServerTest, SIGNAL( finished(QList<int>) ),
785
 
           this, SLOT( slotImapCapabilities(QList<int>) ) );
786
 
  connect( mServerTest, SIGNAL( finished(QList<int>) ),
787
 
           busyCursorHelper, SLOT( deleteLater() ) );
788
 
  mServerTest->start();
789
 
  mServerTestFailed = false;
790
 
}
791
 
 
792
 
void AccountDialog::slotPopCapabilities( QList<int> encryptionTypes )
793
 
{
794
 
  mPop.ui.checkCapabilitiesStack->setCurrentIndex( 0 );
795
 
 
796
 
  // If the servertest did not find any useable authentication modes, assume the
797
 
  // connection failed and don't disable any of the radioboxes.
798
 
  if ( encryptionTypes.isEmpty() ) {
799
 
    mServerTestFailed = true;
800
 
    return;
801
 
  }
802
 
 
803
 
  mPop.ui.encryptionNone->setEnabled( encryptionTypes.contains( Transport::EnumEncryption::None ) );
804
 
  mPop.ui.encryptionSSL->setEnabled( encryptionTypes.contains( Transport::EnumEncryption::SSL ) );
805
 
  mPop.ui.encryptionTLS->setEnabled(  encryptionTypes.contains( Transport::EnumEncryption::TLS )  );
806
 
  checkHighest( mPop.encryptionButtonGroup );
807
 
}
808
 
 
809
 
 
810
 
void AccountDialog::enablePopFeatures()
811
 
{
812
 
  kDebug();
813
 
  if ( !mServerTest || mServerTestFailed )
814
 
    return;
815
 
 
816
 
  QList<int> supportedAuths;
817
 
  if ( mPop.encryptionButtonGroup->checkedId() == Transport::EnumEncryption::None )
818
 
    supportedAuths = mServerTest->normalProtocols();
819
 
  if ( mPop.encryptionButtonGroup->checkedId() == Transport::EnumEncryption::SSL )
820
 
    supportedAuths = mServerTest->secureProtocols();
821
 
  if ( mPop.encryptionButtonGroup->checkedId() == Transport::EnumEncryption::TLS )
822
 
    supportedAuths = mServerTest->tlsProtocols();
823
 
 
824
 
  mPop.ui.authPlain->setEnabled( supportedAuths.contains( Transport::EnumAuthenticationType::PLAIN ) );
825
 
  mPop.ui.authLogin->setEnabled( supportedAuths.contains( Transport::EnumAuthenticationType::LOGIN ) );
826
 
  mPop.ui.authCRAM_MD5->setEnabled( supportedAuths.contains( Transport::EnumAuthenticationType::CRAM_MD5 ) );
827
 
  mPop.ui.authDigestMd5->setEnabled( supportedAuths.contains( Transport::EnumAuthenticationType::DIGEST_MD5 ) );
828
 
  mPop.ui.authNTLM->setEnabled( supportedAuths.contains( Transport::EnumAuthenticationType::NTLM ) );
829
 
  mPop.ui.authGSSAPI->setEnabled( supportedAuths.contains( Transport::EnumAuthenticationType::GSSAPI ) );
830
 
  mPop.ui.authAPOP->setEnabled( supportedAuths.contains( Transport::EnumAuthenticationType::APOP ) );
831
 
 
832
 
  if ( mServerTest && !mServerTest->capabilities().contains( ServerTest::Pipelining ) &&
833
 
       mPop.ui.usePipeliningCheck->isChecked() ) {
834
 
    mPop.ui.usePipeliningCheck->setChecked( false );
835
 
    KMessageBox::information( topLevelWidget(),
836
 
                              i18n("The server does not seem to support "
837
 
                                   "pipelining; therefore, this option has "
838
 
                                   "been disabled.\n"
839
 
                                   "Since some servers do not correctly "
840
 
                                   "announce their capabilities you still "
841
 
                                   "have the possibility to turn pipelining "
842
 
                                   "on. But please note that this feature can "
843
 
                                   "cause some POP servers that do not "
844
 
                                   "support pipelining to send corrupt "
845
 
                                   "messages. So before using this feature "
846
 
                                   "with important mail you should first "
847
 
                                   "test it by sending yourself a larger "
848
 
                                   "number of test messages which you all "
849
 
                                   "download in one go from the POP "
850
 
                                   "server.") );
851
 
  }
852
 
 
853
 
  if ( mServerTest && !mServerTest->capabilities().contains( ServerTest::UIDL ) &&
854
 
       mPop.ui.leaveOnServerCheck->isChecked() ) {
855
 
    mPop.ui.leaveOnServerCheck->setChecked( false );
856
 
    KMessageBox::information( topLevelWidget(),
857
 
                              i18n("The server does not seem to support unique "
858
 
                                   "message numbers, but this is a "
859
 
                                   "requirement for leaving messages on the "
860
 
                                   "server; therefore, this option has been "
861
 
                                   "disabled.\n"
862
 
                                   "Since some servers do not correctly "
863
 
                                   "announce their capabilities you still "
864
 
                                   "have the possibility to turn leaving "
865
 
                                   "fetched messages on the server on.") );
866
 
  }
867
 
 
868
 
  if ( mServerTest && !mServerTest->capabilities().contains( ServerTest::Top ) &&
869
 
       mPop.ui.filterOnServerCheck->isChecked() ) {
870
 
    mPop.ui.filterOnServerCheck->setChecked( false );
871
 
    KMessageBox::information( topLevelWidget(),
872
 
                              i18n("The server does not seem to support "
873
 
                                   "fetching message headers, but this is a "
874
 
                                   "requirement for filtering messages on the "
875
 
                                   "server; therefore, this option has been "
876
 
                                   "disabled.\n"
877
 
                                   "Since some servers do not correctly "
878
 
                                   "announce their capabilities you still "
879
 
                                   "have the possibility to turn filtering "
880
 
                                   "messages on the server on.") );
881
 
  }
882
 
}
883
 
 
884
 
void AccountDialog::slotImapCapabilities( QList<int> encryptionTypes )
885
 
{
886
 
  mImap.ui.checkCapabilitiesStack->setCurrentIndex( 0 );
887
 
 
888
 
  // If the servertest did not find any useable authentication modes, assume the
889
 
  // connection failed and don't disable any of the radioboxes.
890
 
  if ( encryptionTypes.isEmpty() ) {
891
 
    mServerTestFailed = true;
892
 
    return;
893
 
  }
894
 
 
895
 
  mImap.ui.encryptionNone->setEnabled( encryptionTypes.contains( Transport::EnumEncryption::None ) );
896
 
  mImap.ui.encryptionSSL->setEnabled( encryptionTypes.contains( Transport::EnumEncryption::SSL ) );
897
 
  mImap.ui.encryptionTLS->setEnabled(  encryptionTypes.contains( Transport::EnumEncryption::TLS )  );
898
 
  checkHighest( mImap.encryptionButtonGroup );
899
 
}
900
 
 
901
 
void AccountDialog::slotLeaveOnServerDaysChanged ( int value )
902
 
{
903
 
  mPop.ui.leaveOnServerDaysSpin->setSuffix( i18np(" day", " days", value) );
904
 
}
905
 
 
906
 
 
907
 
void AccountDialog::slotLeaveOnServerCountChanged ( int value )
908
 
{
909
 
  mPop.ui.leaveOnServerCountSpin->setSuffix( i18np(" message", " messages", value) );
910
 
}
911
 
 
912
 
 
913
 
void AccountDialog::slotFilterOnServerSizeChanged ( int value )
914
 
{
915
 
  mPop.ui.filterOnServerSizeSpin->setSuffix( i18np(" byte", " bytes", value) );
916
 
}
917
 
 
918
 
void AccountDialog::slotIdentityCheckboxChanged()
919
 
{
920
 
  if ( mAccount->type() == KAccount::Imap ||
921
 
       mAccount->type() == KAccount::DImap  ) {
922
 
     mImap.identityCombo->setEnabled( !mImap.ui.useDefaultIdentityCheck->isChecked() );
923
 
   }
924
 
   else
925
 
     assert( false );
926
 
}
927
 
 
928
 
void AccountDialog::enableImapAuthMethods()
929
 
{
930
 
  kDebug();
931
 
  if ( !mServerTest || mServerTestFailed )
932
 
    return;
933
 
 
934
 
  QList<int> supportedAuths;
935
 
  if ( mImap.encryptionButtonGroup->checkedId() == Transport::EnumEncryption::None )
936
 
    supportedAuths = mServerTest->normalProtocols();
937
 
  if ( mImap.encryptionButtonGroup->checkedId() == Transport::EnumEncryption::SSL )
938
 
    supportedAuths = mServerTest->secureProtocols();
939
 
  if ( mImap.encryptionButtonGroup->checkedId() == Transport::EnumEncryption::TLS )
940
 
    supportedAuths = mServerTest->tlsProtocols();
941
 
 
942
 
  mImap.ui.authPlain->setEnabled( supportedAuths.contains( Transport::EnumAuthenticationType::PLAIN ) );
943
 
  mImap.ui.authLogin->setEnabled( supportedAuths.contains( Transport::EnumAuthenticationType::LOGIN ) );
944
 
  mImap.ui.authCramMd5->setEnabled( supportedAuths.contains( Transport::EnumAuthenticationType::CRAM_MD5 ) );
945
 
  mImap.ui.authDigestMd5->setEnabled( supportedAuths.contains( Transport::EnumAuthenticationType::DIGEST_MD5 ) );
946
 
  mImap.ui.authNTLM->setEnabled( supportedAuths.contains( Transport::EnumAuthenticationType::NTLM ) );
947
 
  mImap.ui.authGSSAPI->setEnabled( supportedAuths.contains( Transport::EnumAuthenticationType::GSSAPI ) );
948
 
  mImap.ui.authAnonymous->setEnabled( supportedAuths.contains( Transport::EnumAuthenticationType::ANONYMOUS ) );
949
 
}
950
 
 
951
 
 
952
 
void AccountDialog::checkHighest( QButtonGroup *btnGroup )
953
 
{
954
 
  kDebug() << btnGroup;
955
 
  QListIterator<QAbstractButton*> it( btnGroup->buttons() );
956
 
  it.toBack();
957
 
  while ( it.hasPrevious() ) {
958
 
    QAbstractButton *btn = it.previous();
959
 
    if ( btn && btn->isEnabled() ) {
960
 
      btn->animateClick();
961
 
      return;
962
 
    }
963
 
  }
964
 
}
965
 
 
966
 
 
967
 
void AccountDialog::slotOk()
968
 
{
969
 
  saveSettings();
970
 
  accept();
971
 
}
972
 
 
973
 
 
974
 
void AccountDialog::saveSettings()
975
 
{
976
 
  KAccount::Type accountType = mAccount->type();
977
 
  if( accountType == KAccount::Local )
978
 
  {
979
 
    KMAcctLocal *acctLocal = dynamic_cast<KMAcctLocal*>(mAccount);
980
 
 
981
 
    if (acctLocal) {
982
 
      mAccount->setName( mLocal.ui.nameEdit->text() );
983
 
      acctLocal->setLocation( mLocal.ui.locationEdit->currentText() );
984
 
      if (mLocal.ui.lockMutt->isChecked())
985
 
        acctLocal->setLockType(mutt_dotlock);
986
 
      else if (mLocal.ui.lockMuttPriv->isChecked())
987
 
        acctLocal->setLockType(mutt_dotlock_privileged);
988
 
      else if (mLocal.ui.lockProcmail->isChecked()) {
989
 
        acctLocal->setLockType(procmail_lockfile);
990
 
        acctLocal->setProcmailLockFileName(mLocal.ui.procmailLockFileName->currentText());
991
 
      }
992
 
      else if (mLocal.ui.lockNone->isChecked())
993
 
        acctLocal->setLockType(lock_none);
994
 
      else acctLocal->setLockType(FCNTL);
995
 
    }
996
 
 
997
 
    mAccount->setCheckInterval( mLocal.ui.intervalCheck->isChecked() ?
998
 
                                mLocal.ui.intervalSpin->value() : 0 );
999
 
    mAccount->setCheckExclude( !mLocal.ui.includeInCheck->isChecked() );
1000
 
 
1001
 
    mAccount->setPrecommand( mLocal.ui.precommand->text() );
1002
 
 
1003
 
    mAccount->setFolder( mFolderList.at(mLocal.ui.folderCombo->currentIndex()) );
1004
 
  }
1005
 
  else if( accountType == KAccount::Pop )
1006
 
  {
1007
 
    mAccount->setName( mPop.ui.nameEdit->text() );
1008
 
    mAccount->setCheckInterval( mPop.ui.intervalCheck->isChecked() ?
1009
 
                                mPop.ui.intervalSpin->value() : 0 );
1010
 
    mAccount->setCheckExclude( !mPop.ui.includeInCheck->isChecked() );
1011
 
 
1012
 
    mAccount->setFolder( mFolderList.at(mPop.ui.folderCombo->currentIndex()) );
1013
 
 
1014
 
    initAccountForConnect();
1015
 
    PopAccount &epa = *(PopAccount*)mAccount;
1016
 
    epa.setUsePipelining( mPop.ui.usePipeliningCheck->isChecked() );
1017
 
    epa.setLeaveOnServer( mPop.ui.leaveOnServerCheck->isChecked() );
1018
 
    epa.setLeaveOnServerDays( mPop.ui.leaveOnServerCheck->isChecked() ?
1019
 
                              ( mPop.ui.leaveOnServerDaysCheck->isChecked() ?
1020
 
                                mPop.ui.leaveOnServerDaysSpin->value() : -1 ) : 0);
1021
 
    epa.setLeaveOnServerCount( mPop.ui.leaveOnServerCheck->isChecked() ?
1022
 
                               ( mPop.ui.leaveOnServerCountCheck->isChecked() ?
1023
 
                                 mPop.ui.leaveOnServerCountSpin->value() : -1 ) : 0 );
1024
 
    epa.setLeaveOnServerSize( mPop.ui.leaveOnServerCheck->isChecked() ?
1025
 
                              ( mPop.ui.leaveOnServerSizeCheck->isChecked() ?
1026
 
                                mPop.ui.leaveOnServerSizeSpin->value() : -1 ) : 0 );
1027
 
    epa.setFilterOnServer( mPop.ui.filterOnServerCheck->isChecked() );
1028
 
    epa.setFilterOnServerCheckSize (mPop.ui.filterOnServerSizeSpin->value() );
1029
 
    epa.setPrecommand( mPop.ui.precommand->text() );
1030
 
 
1031
 
  }
1032
 
  else if( accountType == KAccount::Imap )
1033
 
  {
1034
 
    mAccount->setName( mImap.ui.nameEdit->text() );
1035
 
    mAccount->setCheckInterval( mImap.ui.intervalCheck->isChecked() ?
1036
 
                                mImap.ui.intervalSpin->value() : 0 );
1037
 
    mAccount->setIdentityId( mImap.identityCombo->currentIdentity() );
1038
 
    mAccount->setUseDefaultIdentity( mImap.ui.useDefaultIdentityCheck->isChecked() );
1039
 
    mAccount->setCheckExclude( !mImap.ui.includeInCheck->isChecked() );
1040
 
    mAccount->setFolder( kmkernel->imapFolderMgr()->findById(mAccount->id()) );
1041
 
 
1042
 
    initAccountForConnect();
1043
 
    KMAcctImap &epa = *(KMAcctImap*)mAccount;
1044
 
    epa.setAutoExpunge( mImap.ui.autoExpungeCheck->isChecked() );
1045
 
    epa.setHiddenFolders( mImap.ui.hiddenFoldersCheck->isChecked() );
1046
 
    epa.setOnlySubscribedFolders( mImap.ui.subscribedFoldersCheck->isChecked() );
1047
 
    epa.setOnlyLocallySubscribedFolders( mImap.ui.locallySubscribedFoldersCheck->isChecked() );
1048
 
    epa.setLoadOnDemand( mImap.ui.loadOnDemandCheck->isChecked() );
1049
 
    epa.setListOnlyOpenFolders( mImap.ui.listOnlyOpenCheck->isChecked() );
1050
 
    KMFolder *t = mImap.trashCombo->folder();
1051
 
    if ( t )
1052
 
      epa.setTrash( mImap.trashCombo->folder()->idString() );
1053
 
    else
1054
 
      epa.setTrash( kmkernel->trashFolder()->idString() );
1055
 
    epa.setCheckExclude( !mImap.ui.includeInCheck->isChecked() );
1056
 
    if ( mSieveConfigEditor )
1057
 
      epa.setSieveConfig( mSieveConfigEditor->config() );
1058
 
  }
1059
 
  else if( accountType == KAccount::DImap )
1060
 
  {
1061
 
    mAccount->setName( mImap.ui.nameEdit->text() );
1062
 
    mAccount->setCheckInterval( mImap.ui.intervalCheck->isChecked() ?
1063
 
                                mImap.ui.intervalSpin->value() : 0 );
1064
 
    mAccount->setIdentityId( mImap.identityCombo->currentIdentity() );
1065
 
    mAccount->setUseDefaultIdentity( mImap.ui.useDefaultIdentityCheck->isChecked() );
1066
 
    mAccount->setCheckExclude( !mImap.ui.includeInCheck->isChecked() );
1067
 
    //mAccount->setFolder( NULL );
1068
 
    mAccount->setFolder( kmkernel->dimapFolderMgr()->findById(mAccount->id()) );
1069
 
    //kDebug() << "account for folder" << mAccount->folder()->name();
1070
 
 
1071
 
    initAccountForConnect();
1072
 
    KMAcctCachedImap &epa = *(KMAcctCachedImap*)mAccount;
1073
 
    epa.setHiddenFolders( mImap.ui.hiddenFoldersCheck->isChecked() );
1074
 
    epa.setOnlySubscribedFolders( mImap.ui.subscribedFoldersCheck->isChecked() );
1075
 
    epa.setOnlyLocallySubscribedFolders( mImap.ui.locallySubscribedFoldersCheck->isChecked() );
1076
 
    epa.setStorePasswd( mImap.ui.storePasswordCheck->isChecked() );
1077
 
    epa.setPasswd( mImap.ui.passwordEdit->text(), epa.storePasswd() );
1078
 
    KMFolder *t = mImap.trashCombo->folder();
1079
 
    if ( t )
1080
 
      epa.setTrash( mImap.trashCombo->folder()->idString() );
1081
 
    else
1082
 
      epa.setTrash( kmkernel->trashFolder()->idString() );
1083
 
    epa.setCheckExclude( !mImap.ui.includeInCheck->isChecked() );
1084
 
    if ( mSieveConfigEditor )
1085
 
      epa.setSieveConfig( mSieveConfigEditor->config() );
1086
 
  }
1087
 
  else if( accountType == KAccount::Maildir )
1088
 
  {
1089
 
    KMAcctMaildir *acctMaildir = dynamic_cast<KMAcctMaildir*>(mAccount);
1090
 
 
1091
 
    if (acctMaildir) {
1092
 
        mAccount->setName( mMaildir.ui.nameEdit->text() );
1093
 
        acctMaildir->setLocation( mMaildir.ui.locationEdit->currentText() );
1094
 
 
1095
 
        KMFolder *targetFolder = mFolderList.at(mMaildir.ui.folderCombo->currentIndex());
1096
 
        if ( targetFolder->location()  == acctMaildir->location() ) {
1097
 
            /*
1098
 
               Prevent data loss if the user sets the destination folder to be the same as the
1099
 
               source account maildir folder by setting the target folder to the inbox.
1100
 
               ### FIXME post 3.2: show dialog and let the user chose another target folder
1101
 
            */
1102
 
            targetFolder = kmkernel->inboxFolder();
1103
 
        }
1104
 
        mAccount->setFolder( targetFolder );
1105
 
    }
1106
 
    mAccount->setCheckInterval( mMaildir.ui.intervalCheck->isChecked() ?
1107
 
                                mMaildir.ui.intervalSpin->value() : 0 );
1108
 
    mAccount->setCheckExclude( !mMaildir.ui.includeInCheck->isChecked() );
1109
 
 
1110
 
    mAccount->setPrecommand( mMaildir.ui.precommand->text() );
1111
 
  }
1112
 
 
1113
 
  if ( accountType == KAccount::Imap ||
1114
 
       accountType == KAccount::DImap )
1115
 
  {
1116
 
    // settings for imap in general
1117
 
    ImapAccountBase &ai = *(ImapAccountBase*)mAccount;
1118
 
    // namespace
1119
 
    ImapAccountBase::nsMap map;
1120
 
    ImapAccountBase::namespaceDelim delimMap;
1121
 
    ImapAccountBase::nsDelimMap::Iterator it;
1122
 
    ImapAccountBase::namespaceDelim::Iterator it2;
1123
 
    for ( it = mImap.nsMap.begin(); it != mImap.nsMap.end(); ++it ) {
1124
 
      QStringList list;
1125
 
      for ( it2 = it.value().begin(); it2 != it.value().end(); ++it2 ) {
1126
 
        list << it2.key();
1127
 
        delimMap[it2.key()] = it2.value();
1128
 
      }
1129
 
      map[it.key()] = list;
1130
 
    }
1131
 
    ai.setNamespaces( map );
1132
 
    ai.setNamespaceToDelimiter( delimMap );
1133
 
  }
1134
 
 
1135
 
  kmkernel->acctMgr()->writeConfig(true);
1136
 
  // get the new account and register the new destination folder
1137
 
  // this is the target folder for local or pop accounts and the root folder
1138
 
  // of the account for (d)imap
1139
 
  KMAccount* newAcct = kmkernel->acctMgr()->find(mAccount->id());
1140
 
  if (newAcct)
1141
 
  {
1142
 
    if( accountType == KAccount::Local ) {
1143
 
      newAcct->setFolder( mFolderList.at(mLocal.ui.folderCombo->currentIndex()), true );
1144
 
    } else if ( accountType == KAccount::Pop ) {
1145
 
      newAcct->setFolder( mFolderList.at(mPop.ui.folderCombo->currentIndex()), true );
1146
 
    } else if ( accountType == KAccount::Maildir ) {
1147
 
      newAcct->setFolder( mFolderList.at(mMaildir.ui.folderCombo->currentIndex()), true );
1148
 
    } else if ( accountType == KAccount::Imap ) {
1149
 
      newAcct->setFolder( kmkernel->imapFolderMgr()->findById(mAccount->id()), true );
1150
 
    } else if ( accountType == KAccount::DImap ) {
1151
 
      newAcct->setFolder( kmkernel->dimapFolderMgr()->findById(mAccount->id()), true );
1152
 
    }
1153
 
  }
1154
 
}
1155
 
 
1156
 
 
1157
 
void AccountDialog::slotLocationChooser()
1158
 
{
1159
 
  static QString directory( QDir::rootPath() );
1160
 
 
1161
 
  AutoQPointer<KFileDialog> dialog( new KFileDialog( directory, QString(), this ) );
1162
 
  dialog->setCaption( i18n("Choose Location") );
1163
 
  dialog->setMode( KFile::LocalOnly );
1164
 
 
1165
 
  if( dialog->exec() != QDialog::Accepted || !dialog )
1166
 
  {
1167
 
    return;
1168
 
  }
1169
 
 
1170
 
  KUrl url = dialog->selectedUrl();
1171
 
  if( url.isEmpty() )
1172
 
  {
1173
 
    return;
1174
 
  }
1175
 
  if( url.isLocalFile() == false )
1176
 
  {
1177
 
    KMessageBox::sorry( 0, i18n( "Only local files are currently supported." ) );
1178
 
    return;
1179
 
  }
1180
 
 
1181
 
  mLocal.ui.locationEdit->setEditText( url.toLocalFile() );
1182
 
  directory = url.directory();
1183
 
}
1184
 
 
1185
 
void AccountDialog::slotMaildirChooser()
1186
 
{
1187
 
  static QString directory( QDir::rootPath() );
1188
 
 
1189
 
  QString dir = KFileDialog::getExistingDirectory(directory, this, i18n("Choose Location"));
1190
 
 
1191
 
  if( dir.isEmpty() )
1192
 
    return;
1193
 
 
1194
 
  mMaildir.ui.locationEdit->setEditText( dir );
1195
 
  directory = dir;
1196
 
}
1197
 
 
1198
 
void AccountDialog::slotEnableLeaveOnServerDays( bool state )
1199
 
{
1200
 
  if ( state && !mPop.ui.leaveOnServerDaysCheck->isEnabled()) return;
1201
 
  mPop.ui.leaveOnServerDaysSpin->setEnabled( state );
1202
 
}
1203
 
 
1204
 
void AccountDialog::slotEnableLeaveOnServerCount( bool state )
1205
 
{
1206
 
  if ( state && !mPop.ui.leaveOnServerCountCheck->isEnabled()) return;
1207
 
  mPop.ui.leaveOnServerCountSpin->setEnabled( state );
1208
 
  return;
1209
 
}
1210
 
 
1211
 
void AccountDialog::slotEnableLeaveOnServerSize( bool state )
1212
 
{
1213
 
  if ( state && !mPop.ui.leaveOnServerSizeCheck->isEnabled()) return;
1214
 
  mPop.ui.leaveOnServerSizeSpin->setEnabled( state );
1215
 
  return;
1216
 
}
1217
 
 
1218
 
void AccountDialog::slotEnablePopInterval( bool state )
1219
 
{
1220
 
  mPop.ui.intervalSpin->setEnabled( state );
1221
 
  mPop.ui.intervalLabel->setEnabled( state );
1222
 
}
1223
 
 
1224
 
void AccountDialog::slotEnableImapInterval( bool state )
1225
 
{
1226
 
  mImap.ui.intervalSpin->setEnabled( state );
1227
 
  mImap.ui.intervalLabel->setEnabled( state );
1228
 
}
1229
 
 
1230
 
void AccountDialog::slotEnableLocalInterval( bool state )
1231
 
{
1232
 
  mLocal.ui.intervalSpin->setEnabled( state );
1233
 
  mLocal.ui.intervalLabel->setEnabled( state );
1234
 
}
1235
 
 
1236
 
void AccountDialog::slotEnableMaildirInterval( bool state )
1237
 
{
1238
 
  mMaildir.ui.intervalSpin->setEnabled( state );
1239
 
  mMaildir.ui.intervalLabel->setEnabled( state );
1240
 
}
1241
 
 
1242
 
void AccountDialog::slotFontChanged( void )
1243
 
{
1244
 
  KAccount::Type accountType = mAccount->type();
1245
 
  if( accountType == KAccount::Local )
1246
 
  {
1247
 
    QFont titleFont( mLocal.ui.titleLabel->font() );
1248
 
    titleFont.setBold( true );
1249
 
    mLocal.ui.titleLabel->setFont(titleFont);
1250
 
  }
1251
 
  else if( accountType == KAccount::Pop )
1252
 
  {
1253
 
    QFont titleFont( mPop.ui.titleLabel->font() );
1254
 
    titleFont.setBold( true );
1255
 
    mPop.ui.titleLabel->setFont(titleFont);
1256
 
  }
1257
 
  else if( accountType == KAccount::Imap )
1258
 
  {
1259
 
    QFont titleFont( mImap.ui.titleLabel->font() );
1260
 
    titleFont.setBold( true );
1261
 
    mImap.ui.titleLabel->setFont(titleFont);
1262
 
  }
1263
 
}
1264
 
 
1265
 
void AccountDialog::slotReloadNamespaces()
1266
 
{
1267
 
  if ( mAccount->type() == KAccount::Imap ||
1268
 
       mAccount->type() == KAccount::DImap )
1269
 
  {
1270
 
    initAccountForConnect();
1271
 
    mImap.ui.personalNS->setText( i18n("Fetching Namespaces...") );
1272
 
    mImap.ui.otherUsersNS->setText( QString() );
1273
 
    mImap.ui.sharedNS->setText( QString() );
1274
 
    ImapAccountBase* ai = static_cast<ImapAccountBase*>( mAccount );
1275
 
    connect( ai, SIGNAL( namespacesFetched( const ImapAccountBase::nsDelimMap& ) ),
1276
 
        this, SLOT( slotSetupNamespaces( const ImapAccountBase::nsDelimMap& ) ) );
1277
 
    connect( ai, SIGNAL( connectionResult(int, const QString&) ),
1278
 
          this, SLOT( slotConnectionResult(int, const QString&) ) );
1279
 
    ai->getNamespaces();
1280
 
  }
1281
 
}
1282
 
 
1283
 
void AccountDialog::slotConnectionResult( int errorCode, const QString& )
1284
 
{
1285
 
  if ( errorCode > 0 ) {
1286
 
    ImapAccountBase* ai = static_cast<ImapAccountBase*>( mAccount );
1287
 
    disconnect( ai, SIGNAL( namespacesFetched( const ImapAccountBase::nsDelimMap& ) ),
1288
 
        this, SLOT( slotSetupNamespaces( const ImapAccountBase::nsDelimMap& ) ) );
1289
 
    disconnect( ai, SIGNAL( connectionResult(int, const QString&) ),
1290
 
          this, SLOT( slotConnectionResult(int, const QString&) ) );
1291
 
    mImap.ui.personalNS->setText( QString() );
1292
 
  }
1293
 
}
1294
 
 
1295
 
void AccountDialog::slotSetupNamespaces( const ImapAccountBase::nsDelimMap& map )
1296
 
{
1297
 
  disconnect( this, SLOT( slotSetupNamespaces( const ImapAccountBase::nsDelimMap& ) ) );
1298
 
  mImap.ui.personalNS->setText( QString() );
1299
 
  mImap.ui.otherUsersNS->setText( QString() );
1300
 
  mImap.ui.sharedNS->setText( QString() );
1301
 
  mImap.nsMap = map;
1302
 
 
1303
 
  ImapAccountBase::namespaceDelim ns = map[ImapAccountBase::PersonalNS];
1304
 
  ImapAccountBase::namespaceDelim::ConstIterator it;
1305
 
  if ( !ns.isEmpty() ) {
1306
 
    mImap.ui.personalNS->setText( namespaceListToString( ns.keys() ) );
1307
 
    mImap.ui.editPNS->setEnabled( true );
1308
 
  } else {
1309
 
    mImap.ui.editPNS->setEnabled( false );
1310
 
    mImap.ui.personalNS->setEnabled( false );
1311
 
  }
1312
 
  ns = map[ImapAccountBase::OtherUsersNS];
1313
 
  if ( !ns.isEmpty() ) {
1314
 
    mImap.ui.otherUsersNS->setText( namespaceListToString( ns.keys() ) );
1315
 
    mImap.ui.editONS->setEnabled( true );
1316
 
  } else {
1317
 
    mImap.ui.editONS->setEnabled( false );
1318
 
    mImap.ui.otherUsersNS->setEnabled( false );
1319
 
  }
1320
 
  ns = map[ImapAccountBase::SharedNS];
1321
 
  if ( !ns.isEmpty() ) {
1322
 
    mImap.ui.sharedNS->setText( namespaceListToString( ns.keys() ) );
1323
 
    mImap.ui.editSNS->setEnabled( true );
1324
 
  } else {
1325
 
    mImap.ui.editSNS->setEnabled( false );
1326
 
    mImap.ui.sharedNS->setEnabled( false );
1327
 
  }
1328
 
}
1329
 
 
1330
 
const QString AccountDialog::namespaceListToString( const QStringList& list )
1331
 
{
1332
 
  QStringList myList = list;
1333
 
  for ( QStringList::Iterator it = myList.begin(); it != myList.end(); ++it ) {
1334
 
    if ( (*it).isEmpty() ) {
1335
 
      (*it) = '<' + i18nc("Empty namespace string.", "Empty") + '>';
1336
 
    }
1337
 
  }
1338
 
  return myList.join(",");
1339
 
}
1340
 
 
1341
 
void AccountDialog::initAccountForConnect()
1342
 
{
1343
 
  KAccount::Type type = mAccount->type();
1344
 
  if ( type == KAccount::Local )
1345
 
    return;
1346
 
 
1347
 
  NetworkAccount &na = *(NetworkAccount*)mAccount;
1348
 
 
1349
 
  if ( type == KAccount::Pop ) {
1350
 
    na.setHost( mPop.ui.hostEdit->text().trimmed() );
1351
 
    na.setPort( mPop.ui.portEdit->value() );
1352
 
    na.setLogin( mPop.ui.loginEdit->text().trimmed() );
1353
 
    na.setStorePasswd( mPop.ui.storePasswordCheck->isChecked() );
1354
 
    na.setPasswd( mPop.ui.passwordEdit->text(), na.storePasswd() );
1355
 
    na.setUseSSL( mPop.ui.encryptionSSL->isChecked() );
1356
 
    na.setUseTLS( mPop.ui.encryptionTLS->isChecked() );
1357
 
    if (mPop.ui.authUser->isChecked())
1358
 
      na.setAuth("USER");
1359
 
    else if (mPop.ui.authLogin->isChecked())
1360
 
      na.setAuth("LOGIN");
1361
 
    else if (mPop.ui.authPlain->isChecked())
1362
 
      na.setAuth("PLAIN");
1363
 
    else if (mPop.ui.authCRAM_MD5->isChecked())
1364
 
      na.setAuth("CRAM-MD5");
1365
 
    else if (mPop.ui.authDigestMd5->isChecked())
1366
 
      na.setAuth("DIGEST-MD5");
1367
 
    else if (mPop.ui.authNTLM->isChecked())
1368
 
      na.setAuth("NTLM");
1369
 
    else if (mPop.ui.authGSSAPI->isChecked())
1370
 
      na.setAuth("GSSAPI");
1371
 
    else if (mPop.ui.authAPOP->isChecked())
1372
 
      na.setAuth("APOP");
1373
 
    else na.setAuth("AUTO");
1374
 
  }
1375
 
  else if ( type == KAccount::Imap ||
1376
 
            type == KAccount::DImap ) {
1377
 
    na.setHost( mImap.ui.hostEdit->text().trimmed() );
1378
 
    na.setPort( mImap.ui.portEdit->value() );
1379
 
    na.setLogin( mImap.ui.loginEdit->text().trimmed() );
1380
 
    na.setStorePasswd( mImap.ui.storePasswordCheck->isChecked() );
1381
 
    na.setPasswd( mImap.ui.passwordEdit->text(), na.storePasswd() );
1382
 
    na.setUseSSL( mImap.ui.encryptionSSL->isChecked() );
1383
 
    na.setUseTLS( mImap.ui.encryptionTLS->isChecked() );
1384
 
    if (mImap.ui.authCramMd5->isChecked())
1385
 
      na.setAuth("CRAM-MD5");
1386
 
    else if (mImap.ui.authDigestMd5->isChecked())
1387
 
      na.setAuth("DIGEST-MD5");
1388
 
    else if (mImap.ui.authNTLM->isChecked())
1389
 
      na.setAuth("NTLM");
1390
 
    else if (mImap.ui.authGSSAPI->isChecked())
1391
 
      na.setAuth("GSSAPI");
1392
 
    else if (mImap.ui.authAnonymous->isChecked())
1393
 
      na.setAuth("ANONYMOUS");
1394
 
    else if (mImap.ui.authLogin->isChecked())
1395
 
      na.setAuth("LOGIN");
1396
 
    else if (mImap.ui.authPlain->isChecked())
1397
 
      na.setAuth("PLAIN");
1398
 
    else na.setAuth("*");
1399
 
  }
1400
 
}
1401
 
 
1402
 
void AccountDialog::slotEditPersonalNamespace()
1403
 
{
1404
 
  AutoQPointer<NamespaceEditDialog> dialog( new NamespaceEditDialog( this,
1405
 
                                                                     ImapAccountBase::PersonalNS,
1406
 
                                                                     &mImap.nsMap ) );
1407
 
  if ( dialog->exec() == QDialog::Accepted ) {
1408
 
    slotSetupNamespaces( mImap.nsMap );
1409
 
  }
1410
 
}
1411
 
 
1412
 
void AccountDialog::slotEditOtherUsersNamespace()
1413
 
{
1414
 
  AutoQPointer<NamespaceEditDialog> dialog( new NamespaceEditDialog( this,
1415
 
                                                                     ImapAccountBase::OtherUsersNS,
1416
 
                                                                     &mImap.nsMap ) );
1417
 
  if ( dialog->exec() == QDialog::Accepted ) {
1418
 
    slotSetupNamespaces( mImap.nsMap );
1419
 
  }
1420
 
}
1421
 
 
1422
 
void AccountDialog::slotEditSharedNamespace()
1423
 
{
1424
 
  AutoQPointer<NamespaceEditDialog> dialog( new NamespaceEditDialog( this,
1425
 
                                                                     ImapAccountBase::SharedNS,
1426
 
                                                                     &mImap.nsMap ) );
1427
 
  if ( dialog->exec() == QDialog::Accepted ) {
1428
 
    slotSetupNamespaces( mImap.nsMap );
1429
 
  }
1430
 
}
1431
 
 
1432
 
NamespaceLineEdit::NamespaceLineEdit( QWidget* parent )
1433
 
  : KLineEdit( parent )
1434
 
{
1435
 
}
1436
 
 
1437
 
void NamespaceLineEdit::setText( const QString& text )
1438
 
{
1439
 
  mLastText = text;
1440
 
  KLineEdit::setText( text );
1441
 
}
1442
 
 
1443
 
NamespaceEditDialog::NamespaceEditDialog( QWidget *parent,
1444
 
    ImapAccountBase::imapNamespace type, ImapAccountBase::nsDelimMap* map )
1445
 
  : KDialog( parent ), mType( type ), mNamespaceMap( map )
1446
 
{
1447
 
  setButtons( Ok|Cancel );
1448
 
  setObjectName( "edit_namespace" );
1449
 
  setModal( false );
1450
 
  QWidget *page = new QWidget( this );
1451
 
  setMainWidget( page );
1452
 
 
1453
 
  QString ns;
1454
 
  if ( mType == ImapAccountBase::PersonalNS ) {
1455
 
    ns = i18nc("Personal namespace", "Personal");
1456
 
  } else if ( mType == ImapAccountBase::OtherUsersNS ) {
1457
 
    ns = i18nc("Namespace accessible for others.", "Other Users");
1458
 
  } else {
1459
 
    ns = i18n("Shared");
1460
 
  }
1461
 
  setCaption( i18n("Edit Namespace '%1'", ns) );
1462
 
  QGridLayout *layout = new QGridLayout;
1463
 
 
1464
 
  mBg = new QButtonGroup( 0 );
1465
 
  connect( mBg, SIGNAL( buttonClicked( int ) ), this, SLOT( slotRemoveEntry( int ) ) );
1466
 
  connect( this, SIGNAL( okClicked() ), SLOT( slotOk() ) );
1467
 
  mDelimMap = mNamespaceMap->find( mType ).value();
1468
 
  ImapAccountBase::namespaceDelim::Iterator it;
1469
 
  int row = 0;
1470
 
  for ( it = mDelimMap.begin(); it != mDelimMap.end(); ++it ) {
1471
 
    NamespaceLineEdit* edit = new NamespaceLineEdit( page );
1472
 
    edit->setText( it.key() );
1473
 
    QToolButton* button = new QToolButton( page );
1474
 
    button->setIcon( KIcon("edit-delete") );
1475
 
    button->setAutoRaise( true );
1476
 
    button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
1477
 
    button->setFixedSize( 22, 22 );
1478
 
    mBg->addButton( button, row );
1479
 
    mLineEditMap[ mBg->id( button ) ] = edit;
1480
 
 
1481
 
    layout->addWidget( edit, row, 0 );
1482
 
    layout->addWidget( button, row, 1 );
1483
 
    ++row;
1484
 
  }
1485
 
 
1486
 
  page->setLayout( layout );
1487
 
}
1488
 
 
1489
 
void NamespaceEditDialog::slotRemoveEntry( int id )
1490
 
{
1491
 
  if ( mLineEditMap.contains( id ) ) {
1492
 
    // delete the lineedit and remove namespace from map
1493
 
    NamespaceLineEdit* edit = mLineEditMap[id];
1494
 
    mDelimMap.remove( edit->text() );
1495
 
    if ( edit->isModified() ) {
1496
 
      mDelimMap.remove( edit->lastText() );
1497
 
    }
1498
 
    if ( mDelimMap.isEmpty() ) {
1499
 
      // Make sure that old values get overwritten in the config when the map is
1500
 
      // empty. It is needed to add an empty item for that.
1501
 
      mDelimMap.insert( QString(), QString() );
1502
 
    }
1503
 
    mLineEditMap.remove( id );
1504
 
    mainWidget()->layout()->removeWidget( edit );
1505
 
    edit->close();
1506
 
  }
1507
 
  if ( mBg->button( id ) ) {
1508
 
    mainWidget()->layout()->removeWidget( mBg->button( id ) );
1509
 
    mBg->button( id )->close();
1510
 
  }
1511
 
  adjustSize();
1512
 
}
1513
 
 
1514
 
void NamespaceEditDialog::slotOk()
1515
 
{
1516
 
  QMap<int, NamespaceLineEdit*>::Iterator it;
1517
 
  for ( it = mLineEditMap.begin(); it != mLineEditMap.end(); ++it ) {
1518
 
    NamespaceLineEdit* edit = it.value();
1519
 
    if ( edit->isModified() ) {
1520
 
      // register delimiter for new namespace
1521
 
      mDelimMap[edit->text()] = mDelimMap[edit->lastText()];
1522
 
      mDelimMap.remove( edit->lastText() );
1523
 
    }
1524
 
  }
1525
 
  mNamespaceMap->insert( mType, mDelimMap );
1526
 
}
1527
 
 
1528
 
} // namespace KMail
1529
 
 
1530
 
#include "accountdialog.moc"