2
* kmail: KDE mail client
3
* Copyright (C) 2000 Espen Sand, espen@kde.org
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.
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.
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.
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"
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"
44
#include <KGlobalSettings>
45
#include <KFileDialog>
48
#include <KMessageBox>
51
#include <KProtocolInfo>
52
#include <KIconLoader>
55
#include <QButtonGroup>
58
#include <QRadioButton>
61
#include <QPushButton>
62
#include <QToolButton>
64
#include <QGridLayout>
65
#include <QVBoxLayout>
66
#include <QHBoxLayout>
70
class BusyCursorHelper : public QObject
73
inline BusyCursorHelper( QObject *parent )
76
qApp->setOverrideCursor( Qt::BusyCursor );
79
inline ~BusyCursorHelper()
81
qApp->restoreOverrideCursor();
90
AccountDialog::AccountDialog( const QString & caption, KMAccount *account,
95
mSieveConfigEditor( 0 )
97
setCaption( caption );
98
setButtons( Ok|Cancel|Help );
99
mValidator = new QRegExpValidator( QRegExp( "[A-Za-z0-9-_:.]*" ), this );
100
setHelp("receiving-mail");
102
KAccount::Type accountType = mAccount->type();
104
if( accountType == KAccount::Local )
106
makeLocalAccountPage();
108
else if( accountType == KAccount::Maildir )
110
makeMaildirAccountPage();
112
else if( accountType == KAccount::Pop )
114
makePopAccountPage();
116
else if( accountType == KAccount::Imap )
118
makeImapAccountPage();
120
else if( accountType == KAccount::DImap )
122
makeImapAccountPage(true);
126
QString msg = i18n( "Account type is not supported." );
127
KMessageBox::information( topLevelWidget(),msg,i18n("Configure Account") );
132
connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
135
AccountDialog::~AccountDialog()
141
void AccountDialog::makeLocalAccountPage()
143
QWidget *page = new QWidget( this );
144
mLocal.ui.setupUi( page );
145
setMainWidget( page );
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 );
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()) );
162
void AccountDialog::makeMaildirAccountPage()
164
QWidget *page = new QWidget( this );
165
mMaildir.ui.setupUi( page );
166
setMainWidget( page );
167
ProcmailRCParser procmailrcParser;
169
mMaildir.ui.locationEdit->addItems( procmailrcParser.getSpoolFilesList() );
170
mMaildir.ui.choose->setAutoDefault( false );
171
mMaildir.ui.intervalSpin->setRange( GlobalSettings::self()->minimumCheckInterval(), 10000, 1 );
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()) );
182
void AccountDialog::makePopAccountPage()
184
QWidget *page = new QWidget( this );
185
mPop.ui.setupUi( page );
186
setMainWidget( page );
188
connect( mPop.ui.passwordEdit, SIGNAL( textEdited( const QString& ) ),
189
this, SLOT( slotPopPasswordChanged( const QString& ) ) );
191
// only letters, digits, '-', '.', ':' (IPv6) and '_' (for Windows
192
// compatibility) are allowed
193
mPop.ui.hostEdit->setValidator( mValidator );
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)) );
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() ) );
215
connect( mPop.ui.intervalCheck, SIGNAL(toggled(bool)),
216
this, SLOT(slotEnablePopInterval(bool)) );
217
mPop.ui.intervalSpin->setRange( GlobalSettings::self()->minimumCheckInterval(),
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 );
231
connect( mPop.encryptionButtonGroup, SIGNAL(buttonClicked(int)),
232
SLOT(slotPopEncryptionChanged(int)) );
234
if ( KProtocolInfo::capabilities("pop3").contains("SASL") == 0 )
236
mPop.ui.authNTLM->hide();
237
mPop.ui.authGSSAPI->hide();
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 );
249
connect( mPop.ui.usePipeliningCheck, SIGNAL(clicked()),
250
SLOT(slotPipeliningClicked()) );
252
connect(KGlobalSettings::self(),SIGNAL(kdisplayFontChanged()),
253
SLOT(slotFontChanged()));
257
void AccountDialog::makeImapAccountPage( bool connected )
259
QWidget *page = new QWidget( this );
260
mImap.ui.setupUi( page );
261
setMainWidget( page );
263
mImap.ui.titleLabel->setText( i18n("Account Type: Disconnected IMAP Account") );
265
mImap.ui.titleLabel->setText( i18n("Account Type: IMAP Account") );
267
// only letters, digits, '-', '.', ':' (IPv6) and '_' (for Windows
268
// compatibility) are allowed
269
mImap.ui.hostEdit->setValidator( mValidator );
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 );
282
mImap.ui.intervalSpin->setRange( GlobalSettings::self()->minimumCheckInterval(), 10000, 1 );
285
// not implemented for disconnected yet
286
mImap.ui.autoExpungeCheck->hide();
287
mImap.ui.loadOnDemandCheck->hide();
288
mImap.ui.listOnlyOpenCheck->hide();
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 );
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 );
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 );
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 );
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& ) ) );
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") );
340
connect( KGlobalSettings::self(),SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged()) );
344
void AccountDialog::setupSettings()
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
352
KAccount::Type accountType = mAccount->type();
353
if( accountType == KAccount::Local )
355
ProcmailRCParser procmailrcParser;
356
KMAcctLocal *acctLocal = static_cast<KMAcctLocal*>(mAccount);
358
if ( acctLocal->location().isEmpty() )
359
acctLocal->setLocation( procmailrcParser.getSpoolFilesList().first() );
361
mLocal.ui.locationEdit->addItem( acctLocal->location() );
363
if ( acctLocal->procmailLockFileName().isEmpty() )
364
acctLocal->setProcmailLockFileName( procmailrcParser.getLockFilesList().first() );
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);
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() );
386
slotEnableLocalInterval( intervalCheckingEnabled );
387
folderCombo = mLocal.ui.folderCombo;
389
else if( accountType == KAccount::Pop )
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() );
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 );
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;
449
else if( accountType == KAccount::Imap )
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);
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() );
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() );
500
else if( accountType == KAccount::DImap )
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() );
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() );
547
else if( accountType == KAccount::Maildir )
549
KMAcctMaildir *acctMaildir = dynamic_cast<KMAcctMaildir*>(mAccount);
551
mMaildir.ui.nameEdit->setText( mAccount->name() );
552
mMaildir.ui.nameEdit->setFocus();
553
mMaildir.ui.locationEdit->setEditText( acctMaildir->location() );
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;
562
else // Unknown account type
565
if ( accountType == KAccount::Imap ||
566
accountType == KAccount::DImap )
568
// settings for imap in general
569
ImapAccountBase &ai = *(ImapAccountBase*)mAccount;
571
if ( ( ai.namespaces().isEmpty() || ai.namespaceToDelimiter().isEmpty() ) &&
572
!ai.login().isEmpty() && !ai.passwd().isEmpty() && !ai.host().isEmpty() )
574
slotReloadNamespaces();
576
slotSetupNamespaces( ai.namespacesWithDelimiter() );
580
if (!folderCombo) return;
582
KMFolderDir *fdir = (KMFolderDir*)&kmkernel->folderMgr()->dir();
583
KMFolder *acctFolder = mAccount->folder();
584
if( acctFolder == 0 )
586
acctFolder = (KMFolder*)fdir->first();
588
if( acctFolder == 0 )
590
folderCombo->addItem( i18nc("Placeholder for the case that there is no folder."
591
, "<placeholder>none</placeholder>") );
597
kmkernel->folderMgr()->createI18nFolderList(&mFolderNames, &mFolderList);
598
while (i < mFolderNames.count())
600
//QList<QPointer<KMFolder> >::Iterator it = mFolderList.at(i);
601
KMFolder *folder = mFolderList.at(i);
602
if (folder->isSystemFolder())
604
mFolderList.removeAll(folder);
605
mFolderNames.removeAt(i);
607
if (folder == acctFolder) curIndex = i;
611
mFolderNames.prepend(i18n("inbox"));
612
mFolderList.prepend(kmkernel->inboxFolder());
613
folderCombo->addItems(mFolderNames);
614
folderCombo->setCurrentIndex(curIndex + 1);
616
// -sanders hack for startup users. Must investigate this properly
617
if (folderCombo->count() == 0)
618
folderCombo->addItem( i18n("inbox") );
622
void AccountDialog::slotLeaveOnServerClicked()
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 );
629
if ( mPop.ui.leaveOnServerDaysCheck->isChecked() ) {
630
slotEnableLeaveOnServerDays( state );
632
if ( mPop.ui.leaveOnServerCountCheck->isChecked() ) {
633
slotEnableLeaveOnServerCount( state );
635
if ( mPop.ui.leaveOnServerSizeCheck->isChecked() ) {
636
slotEnableLeaveOnServerSize( state );
639
slotEnableLeaveOnServerDays( state );
640
slotEnableLeaveOnServerCount( state );
641
slotEnableLeaveOnServerSize( state );
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 "
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.") );
657
void AccountDialog::slotFilterOnServerClicked()
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 "
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.") );
673
void AccountDialog::slotPipeliningClicked()
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(),
690
void AccountDialog::slotPopEncryptionChanged( int id )
692
kDebug() << "ID:" << id;
694
if ( id == Transport::EnumEncryption::SSL || mPop.ui.portEdit->value() == 995 )
695
mPop.ui.portEdit->setValue( ( id == Transport::EnumEncryption::SSL ) ? 995 : 110 );
698
const QAbstractButton *old = mPop.authButtonGroup->checkedButton();
699
if ( old && !old->isEnabled() )
700
checkHighest( mPop.authButtonGroup );
703
void AccountDialog::slotPopPasswordChanged( const QString& text )
705
if ( text.isEmpty() )
706
mPop.ui.storePasswordCheck->setCheckState( Qt::Unchecked );
708
mPop.ui.storePasswordCheck->setCheckState( Qt::Checked );
711
void AccountDialog::slotImapPasswordChanged( const QString& text )
713
if ( text.isEmpty() )
714
mImap.ui.storePasswordCheck->setCheckState( Qt::Unchecked );
716
mImap.ui.storePasswordCheck->setCheckState( Qt::Checked );
719
void AccountDialog::slotImapEncryptionChanged( int id )
723
if ( id == Transport::EnumEncryption::SSL || mImap.ui.portEdit->value() == 993 )
724
mImap.ui.portEdit->setValue( ( id == Transport::EnumEncryption::SSL ) ? 993 : 143 );
726
enableImapAuthMethods();
727
QAbstractButton *old = mImap.authButtonGroup->checkedButton();
728
if ( !old->isEnabled() )
729
checkHighest( mImap.authButtonGroup );
733
void AccountDialog::slotCheckPopCapabilities()
735
if ( mPop.ui.hostEdit->text().isEmpty() )
737
KMessageBox::sorry( this, i18n( "Please specify a server and port on "
738
"the General tab first." ) );
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;
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;
763
void AccountDialog::slotCheckImapCapabilities()
765
if ( mImap.ui.hostEdit->text().isEmpty() )
767
KMessageBox::sorry( this, i18n( "Please specify a server and port on "
768
"the General tab first." ) );
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;
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;
792
void AccountDialog::slotPopCapabilities( QList<int> encryptionTypes )
794
mPop.ui.checkCapabilitiesStack->setCurrentIndex( 0 );
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;
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 );
810
void AccountDialog::enablePopFeatures()
813
if ( !mServerTest || mServerTestFailed )
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();
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 ) );
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 "
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 "
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 "
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.") );
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 "
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.") );
884
void AccountDialog::slotImapCapabilities( QList<int> encryptionTypes )
886
mImap.ui.checkCapabilitiesStack->setCurrentIndex( 0 );
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;
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 );
901
void AccountDialog::slotLeaveOnServerDaysChanged ( int value )
903
mPop.ui.leaveOnServerDaysSpin->setSuffix( i18np(" day", " days", value) );
907
void AccountDialog::slotLeaveOnServerCountChanged ( int value )
909
mPop.ui.leaveOnServerCountSpin->setSuffix( i18np(" message", " messages", value) );
913
void AccountDialog::slotFilterOnServerSizeChanged ( int value )
915
mPop.ui.filterOnServerSizeSpin->setSuffix( i18np(" byte", " bytes", value) );
918
void AccountDialog::slotIdentityCheckboxChanged()
920
if ( mAccount->type() == KAccount::Imap ||
921
mAccount->type() == KAccount::DImap ) {
922
mImap.identityCombo->setEnabled( !mImap.ui.useDefaultIdentityCheck->isChecked() );
928
void AccountDialog::enableImapAuthMethods()
931
if ( !mServerTest || mServerTestFailed )
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();
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 ) );
952
void AccountDialog::checkHighest( QButtonGroup *btnGroup )
954
kDebug() << btnGroup;
955
QListIterator<QAbstractButton*> it( btnGroup->buttons() );
957
while ( it.hasPrevious() ) {
958
QAbstractButton *btn = it.previous();
959
if ( btn && btn->isEnabled() ) {
967
void AccountDialog::slotOk()
974
void AccountDialog::saveSettings()
976
KAccount::Type accountType = mAccount->type();
977
if( accountType == KAccount::Local )
979
KMAcctLocal *acctLocal = dynamic_cast<KMAcctLocal*>(mAccount);
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());
992
else if (mLocal.ui.lockNone->isChecked())
993
acctLocal->setLockType(lock_none);
994
else acctLocal->setLockType(FCNTL);
997
mAccount->setCheckInterval( mLocal.ui.intervalCheck->isChecked() ?
998
mLocal.ui.intervalSpin->value() : 0 );
999
mAccount->setCheckExclude( !mLocal.ui.includeInCheck->isChecked() );
1001
mAccount->setPrecommand( mLocal.ui.precommand->text() );
1003
mAccount->setFolder( mFolderList.at(mLocal.ui.folderCombo->currentIndex()) );
1005
else if( accountType == KAccount::Pop )
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() );
1012
mAccount->setFolder( mFolderList.at(mPop.ui.folderCombo->currentIndex()) );
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() );
1032
else if( accountType == KAccount::Imap )
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()) );
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();
1052
epa.setTrash( mImap.trashCombo->folder()->idString() );
1054
epa.setTrash( kmkernel->trashFolder()->idString() );
1055
epa.setCheckExclude( !mImap.ui.includeInCheck->isChecked() );
1056
if ( mSieveConfigEditor )
1057
epa.setSieveConfig( mSieveConfigEditor->config() );
1059
else if( accountType == KAccount::DImap )
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();
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();
1080
epa.setTrash( mImap.trashCombo->folder()->idString() );
1082
epa.setTrash( kmkernel->trashFolder()->idString() );
1083
epa.setCheckExclude( !mImap.ui.includeInCheck->isChecked() );
1084
if ( mSieveConfigEditor )
1085
epa.setSieveConfig( mSieveConfigEditor->config() );
1087
else if( accountType == KAccount::Maildir )
1089
KMAcctMaildir *acctMaildir = dynamic_cast<KMAcctMaildir*>(mAccount);
1092
mAccount->setName( mMaildir.ui.nameEdit->text() );
1093
acctMaildir->setLocation( mMaildir.ui.locationEdit->currentText() );
1095
KMFolder *targetFolder = mFolderList.at(mMaildir.ui.folderCombo->currentIndex());
1096
if ( targetFolder->location() == acctMaildir->location() ) {
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
1102
targetFolder = kmkernel->inboxFolder();
1104
mAccount->setFolder( targetFolder );
1106
mAccount->setCheckInterval( mMaildir.ui.intervalCheck->isChecked() ?
1107
mMaildir.ui.intervalSpin->value() : 0 );
1108
mAccount->setCheckExclude( !mMaildir.ui.includeInCheck->isChecked() );
1110
mAccount->setPrecommand( mMaildir.ui.precommand->text() );
1113
if ( accountType == KAccount::Imap ||
1114
accountType == KAccount::DImap )
1116
// settings for imap in general
1117
ImapAccountBase &ai = *(ImapAccountBase*)mAccount;
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 ) {
1125
for ( it2 = it.value().begin(); it2 != it.value().end(); ++it2 ) {
1127
delimMap[it2.key()] = it2.value();
1129
map[it.key()] = list;
1131
ai.setNamespaces( map );
1132
ai.setNamespaceToDelimiter( delimMap );
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());
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 );
1157
void AccountDialog::slotLocationChooser()
1159
static QString directory( QDir::rootPath() );
1161
AutoQPointer<KFileDialog> dialog( new KFileDialog( directory, QString(), this ) );
1162
dialog->setCaption( i18n("Choose Location") );
1163
dialog->setMode( KFile::LocalOnly );
1165
if( dialog->exec() != QDialog::Accepted || !dialog )
1170
KUrl url = dialog->selectedUrl();
1175
if( url.isLocalFile() == false )
1177
KMessageBox::sorry( 0, i18n( "Only local files are currently supported." ) );
1181
mLocal.ui.locationEdit->setEditText( url.toLocalFile() );
1182
directory = url.directory();
1185
void AccountDialog::slotMaildirChooser()
1187
static QString directory( QDir::rootPath() );
1189
QString dir = KFileDialog::getExistingDirectory(directory, this, i18n("Choose Location"));
1194
mMaildir.ui.locationEdit->setEditText( dir );
1198
void AccountDialog::slotEnableLeaveOnServerDays( bool state )
1200
if ( state && !mPop.ui.leaveOnServerDaysCheck->isEnabled()) return;
1201
mPop.ui.leaveOnServerDaysSpin->setEnabled( state );
1204
void AccountDialog::slotEnableLeaveOnServerCount( bool state )
1206
if ( state && !mPop.ui.leaveOnServerCountCheck->isEnabled()) return;
1207
mPop.ui.leaveOnServerCountSpin->setEnabled( state );
1211
void AccountDialog::slotEnableLeaveOnServerSize( bool state )
1213
if ( state && !mPop.ui.leaveOnServerSizeCheck->isEnabled()) return;
1214
mPop.ui.leaveOnServerSizeSpin->setEnabled( state );
1218
void AccountDialog::slotEnablePopInterval( bool state )
1220
mPop.ui.intervalSpin->setEnabled( state );
1221
mPop.ui.intervalLabel->setEnabled( state );
1224
void AccountDialog::slotEnableImapInterval( bool state )
1226
mImap.ui.intervalSpin->setEnabled( state );
1227
mImap.ui.intervalLabel->setEnabled( state );
1230
void AccountDialog::slotEnableLocalInterval( bool state )
1232
mLocal.ui.intervalSpin->setEnabled( state );
1233
mLocal.ui.intervalLabel->setEnabled( state );
1236
void AccountDialog::slotEnableMaildirInterval( bool state )
1238
mMaildir.ui.intervalSpin->setEnabled( state );
1239
mMaildir.ui.intervalLabel->setEnabled( state );
1242
void AccountDialog::slotFontChanged( void )
1244
KAccount::Type accountType = mAccount->type();
1245
if( accountType == KAccount::Local )
1247
QFont titleFont( mLocal.ui.titleLabel->font() );
1248
titleFont.setBold( true );
1249
mLocal.ui.titleLabel->setFont(titleFont);
1251
else if( accountType == KAccount::Pop )
1253
QFont titleFont( mPop.ui.titleLabel->font() );
1254
titleFont.setBold( true );
1255
mPop.ui.titleLabel->setFont(titleFont);
1257
else if( accountType == KAccount::Imap )
1259
QFont titleFont( mImap.ui.titleLabel->font() );
1260
titleFont.setBold( true );
1261
mImap.ui.titleLabel->setFont(titleFont);
1265
void AccountDialog::slotReloadNamespaces()
1267
if ( mAccount->type() == KAccount::Imap ||
1268
mAccount->type() == KAccount::DImap )
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();
1283
void AccountDialog::slotConnectionResult( int errorCode, const QString& )
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() );
1295
void AccountDialog::slotSetupNamespaces( const ImapAccountBase::nsDelimMap& map )
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() );
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 );
1309
mImap.ui.editPNS->setEnabled( false );
1310
mImap.ui.personalNS->setEnabled( false );
1312
ns = map[ImapAccountBase::OtherUsersNS];
1313
if ( !ns.isEmpty() ) {
1314
mImap.ui.otherUsersNS->setText( namespaceListToString( ns.keys() ) );
1315
mImap.ui.editONS->setEnabled( true );
1317
mImap.ui.editONS->setEnabled( false );
1318
mImap.ui.otherUsersNS->setEnabled( false );
1320
ns = map[ImapAccountBase::SharedNS];
1321
if ( !ns.isEmpty() ) {
1322
mImap.ui.sharedNS->setText( namespaceListToString( ns.keys() ) );
1323
mImap.ui.editSNS->setEnabled( true );
1325
mImap.ui.editSNS->setEnabled( false );
1326
mImap.ui.sharedNS->setEnabled( false );
1330
const QString AccountDialog::namespaceListToString( const QStringList& list )
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") + '>';
1338
return myList.join(",");
1341
void AccountDialog::initAccountForConnect()
1343
KAccount::Type type = mAccount->type();
1344
if ( type == KAccount::Local )
1347
NetworkAccount &na = *(NetworkAccount*)mAccount;
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())
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())
1369
else if (mPop.ui.authGSSAPI->isChecked())
1370
na.setAuth("GSSAPI");
1371
else if (mPop.ui.authAPOP->isChecked())
1373
else na.setAuth("AUTO");
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())
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("*");
1402
void AccountDialog::slotEditPersonalNamespace()
1404
AutoQPointer<NamespaceEditDialog> dialog( new NamespaceEditDialog( this,
1405
ImapAccountBase::PersonalNS,
1407
if ( dialog->exec() == QDialog::Accepted ) {
1408
slotSetupNamespaces( mImap.nsMap );
1412
void AccountDialog::slotEditOtherUsersNamespace()
1414
AutoQPointer<NamespaceEditDialog> dialog( new NamespaceEditDialog( this,
1415
ImapAccountBase::OtherUsersNS,
1417
if ( dialog->exec() == QDialog::Accepted ) {
1418
slotSetupNamespaces( mImap.nsMap );
1422
void AccountDialog::slotEditSharedNamespace()
1424
AutoQPointer<NamespaceEditDialog> dialog( new NamespaceEditDialog( this,
1425
ImapAccountBase::SharedNS,
1427
if ( dialog->exec() == QDialog::Accepted ) {
1428
slotSetupNamespaces( mImap.nsMap );
1432
NamespaceLineEdit::NamespaceLineEdit( QWidget* parent )
1433
: KLineEdit( parent )
1437
void NamespaceLineEdit::setText( const QString& text )
1440
KLineEdit::setText( text );
1443
NamespaceEditDialog::NamespaceEditDialog( QWidget *parent,
1444
ImapAccountBase::imapNamespace type, ImapAccountBase::nsDelimMap* map )
1445
: KDialog( parent ), mType( type ), mNamespaceMap( map )
1447
setButtons( Ok|Cancel );
1448
setObjectName( "edit_namespace" );
1450
QWidget *page = new QWidget( this );
1451
setMainWidget( page );
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");
1459
ns = i18n("Shared");
1461
setCaption( i18n("Edit Namespace '%1'", ns) );
1462
QGridLayout *layout = new QGridLayout;
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;
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;
1481
layout->addWidget( edit, row, 0 );
1482
layout->addWidget( button, row, 1 );
1486
page->setLayout( layout );
1489
void NamespaceEditDialog::slotRemoveEntry( int id )
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() );
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() );
1503
mLineEditMap.remove( id );
1504
mainWidget()->layout()->removeWidget( edit );
1507
if ( mBg->button( id ) ) {
1508
mainWidget()->layout()->removeWidget( mBg->button( id ) );
1509
mBg->button( id )->close();
1514
void NamespaceEditDialog::slotOk()
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() );
1525
mNamespaceMap->insert( mType, mDelimMap );
1528
} // namespace KMail
1530
#include "accountdialog.moc"