kmail

accountdialog.cpp
1 /*
2  * kmail: KDE mail client
3  * This file: 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
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  */
20 #include <config.h>
21 
22 #include "accountdialog.h"
23 
24 #include <tqbuttongroup.h>
25 #include <tqcheckbox.h>
26 #include <tqlayout.h>
27 #include <tqtabwidget.h>
28 #include <tqradiobutton.h>
29 #include <tqvalidator.h>
30 #include <tqlabel.h>
31 #include <tqpushbutton.h>
32 #include <tqwhatsthis.h>
33 #include <tqhbox.h>
34 #include <tqcombobox.h>
35 #include <tqheader.h>
36 #include <tqtoolbutton.h>
37 #include <tqgrid.h>
38 
39 #include <tdefiledialog.h>
40 #include <tdelocale.h>
41 #include <kdebug.h>
42 #include <tdemessagebox.h>
43 #include <knuminput.h>
44 #include <kseparator.h>
45 #include <tdeapplication.h>
46 #include <tdemessagebox.h>
47 #include <kprotocolinfo.h>
48 #include <kiconloader.h>
49 #include <tdepopupmenu.h>
50 
51 #include <netdb.h>
52 #include <netinet/in.h>
53 
54 #include "sieveconfig.h"
55 #include "kmacctmaildir.h"
56 #include "kmacctlocal.h"
57 #include "accountmanager.h"
58 #include "popaccount.h"
59 #include "kmacctimap.h"
60 #include "kmacctcachedimap.h"
61 #include "kmfoldermgr.h"
62 #include "kmservertest.h"
63 #include "protocols.h"
64 #include "folderrequester.h"
65 #include "kmmainwidget.h"
66 #include "kmfolder.h"
67 #include <libkpimidentities/identitymanager.h>
68 #include <libkpimidentities/identitycombo.h>
69 #include <libkpimidentities/identity.h>
70 #include "globalsettings.h"
71 
72 #include <cassert>
73 #include <stdlib.h>
74 
75 #ifdef HAVE_PATHS_H
76 #include <paths.h> /* defines _PATH_MAILDIR */
77 #endif
78 
79 #ifndef _PATH_MAILDIR
80 #define _PATH_MAILDIR "/var/spool/mail"
81 #endif
82 
83 namespace KMail {
84 
85 class ProcmailRCParser
86 {
87 public:
88  ProcmailRCParser(TQString fileName = TQString());
89  ~ProcmailRCParser();
90 
91  TQStringList getLockFilesList() const { return mLockFiles; }
92  TQStringList getSpoolFilesList() const { return mSpoolFiles; }
93 
94 protected:
95  void processGlobalLock(const TQString&);
96  void processLocalLock(const TQString&);
97  void processVariableSetting(const TQString&, int);
98  TQString expandVars(const TQString&);
99 
100  TQFile mProcmailrc;
101  TQTextStream *mStream;
102  TQStringList mLockFiles;
103  TQStringList mSpoolFiles;
104  TQAsciiDict<TQString> mVars;
105 };
106 
107 ProcmailRCParser::ProcmailRCParser(TQString fname)
108  : mProcmailrc(fname),
109  mStream(new TQTextStream(&mProcmailrc))
110 {
111  mVars.setAutoDelete(true);
112 
113  // predefined
114  mVars.insert( "HOME", new TQString( TQDir::homeDirPath() ) );
115 
116  if( !fname || fname.isEmpty() ) {
117  fname = TQDir::homeDirPath() + "/.procmailrc";
118  mProcmailrc.setName(fname);
119  }
120 
121  TQRegExp lockFileGlobal("^LOCKFILE=", true);
122  TQRegExp lockFileLocal("^:0", true);
123 
124  if( mProcmailrc.open(IO_ReadOnly) ) {
125 
126  TQString s;
127 
128  while( !mStream->eof() ) {
129 
130  s = mStream->readLine().stripWhiteSpace();
131 
132  if( s[0] == '#' ) continue; // skip comments
133 
134  int commentPos = -1;
135 
136  if( (commentPos = s.find('#')) > -1 ) {
137  // get rid of trailing comment
138  s.truncate(commentPos);
139  s = s.stripWhiteSpace();
140  }
141 
142  if( lockFileGlobal.search(s) != -1 ) {
143  processGlobalLock(s);
144  } else if( lockFileLocal.search(s) != -1 ) {
145  processLocalLock(s);
146  } else if( int i = s.find('=') ) {
147  processVariableSetting(s,i);
148  }
149  }
150 
151  }
152  TQString default_Location = getenv("MAIL");
153 
154  if (default_Location.isNull()) {
155  default_Location = _PATH_MAILDIR;
156  default_Location += '/';
157  default_Location += getenv("USER");
158  }
159  if ( !mSpoolFiles.contains(default_Location) )
160  mSpoolFiles << default_Location;
161 
162  default_Location = default_Location + ".lock";
163  if ( !mLockFiles.contains(default_Location) )
164  mLockFiles << default_Location;
165 }
166 
167 ProcmailRCParser::~ProcmailRCParser()
168 {
169  delete mStream;
170 }
171 
172 void
173 ProcmailRCParser::processGlobalLock(const TQString &s)
174 {
175  TQString val = expandVars(s.mid(s.find('=') + 1).stripWhiteSpace());
176  if ( !mLockFiles.contains(val) )
177  mLockFiles << val;
178 }
179 
180 void
181 ProcmailRCParser::processLocalLock(const TQString &s)
182 {
183  TQString val;
184  int colonPos = s.findRev(':');
185 
186  if (colonPos > 0) { // we don't care about the leading one
187  val = s.mid(colonPos + 1).stripWhiteSpace();
188 
189  if ( val.length() ) {
190  // user specified a lockfile, so process it
191  //
192  val = expandVars(val);
193  if( val[0] != '/' && mVars.find("MAILDIR") )
194  val.insert(0, *(mVars["MAILDIR"]) + '/');
195  } // else we'll deduce the lockfile name one we
196  // get the spoolfile name
197  }
198 
199  // parse until we find the spoolfile
200  TQString line, prevLine;
201  do {
202  prevLine = line;
203  line = mStream->readLine().stripWhiteSpace();
204  } while ( !mStream->eof() && (line[0] == '*' ||
205  prevLine[prevLine.length() - 1] == '\\' ));
206 
207  if( line[0] != '!' && line[0] != '|' && line[0] != '{' ) {
208  // this is a filename, expand it
209  //
210  line = line.stripWhiteSpace();
211  line = expandVars(line);
212 
213  // prepend default MAILDIR if needed
214  if( line[0] != '/' && mVars.find("MAILDIR") )
215  line.insert(0, *(mVars["MAILDIR"]) + '/');
216 
217  // now we have the spoolfile name
218  if ( !mSpoolFiles.contains(line) )
219  mSpoolFiles << line;
220 
221  if( colonPos > 0 && (!val || val.isEmpty()) ) {
222  // there is a local lockfile, but the user didn't
223  // specify the name so compute it from the spoolfile's name
224  val = line;
225 
226  // append lock extension
227  if( mVars.find("LOCKEXT") )
228  val += *(mVars["LOCKEXT"]);
229  else
230  val += ".lock";
231  }
232 
233  if ( !val.isNull() && !mLockFiles.contains(val) ) {
234  mLockFiles << val;
235  }
236  }
237 
238 }
239 
240 void
241 ProcmailRCParser::processVariableSetting(const TQString &s, int eqPos)
242 {
243  if( eqPos == -1) return;
244 
245  TQString varName = s.left(eqPos),
246  varValue = expandVars(s.mid(eqPos + 1).stripWhiteSpace());
247 
248  mVars.insert(varName.latin1(), new TQString(varValue));
249 }
250 
251 TQString
252 ProcmailRCParser::expandVars(const TQString &s)
253 {
254  if( s.isEmpty()) return s;
255 
256  TQString expS = s;
257 
258  TQAsciiDictIterator<TQString> it( mVars ); // iterator for dict
259 
260  while ( it.current() ) {
261  expS.replace(TQString::fromLatin1("$") + it.currentKey(), *it.current());
262  ++it;
263  }
264 
265  return expS;
266 }
267 
268 
269 
270 AccountDialog::AccountDialog( const TQString & caption, KMAccount *account,
271  TQWidget *parent, const char *name, bool modal )
272  : KDialogBase( parent, name, modal, caption, Ok|Cancel|Help, Ok, true ),
273  mAccount( account ),
274  mServerTest( 0 ),
275  mCurCapa( AllCapa ),
276  mCapaNormal( AllCapa ),
277  mCapaSSL( AllCapa ),
278  mCapaTLS( AllCapa ),
279  mSieveConfigEditor( 0 )
280 {
281  mValidator = new TQRegExpValidator( TQRegExp( "[A-Za-z0-9-_:.]*" ), 0 );
282  setHelp("receiving-mail");
283 
284  TQString accountType = mAccount->type();
285 
286  if( accountType == "local" )
287  {
288  makeLocalAccountPage();
289  }
290  else if( accountType == "maildir" )
291  {
292  makeMaildirAccountPage();
293  }
294  else if( accountType == "pop" )
295  {
296  makePopAccountPage();
297  }
298  else if( accountType == "imap" )
299  {
300  makeImapAccountPage();
301  }
302  else if( accountType == "cachedimap" )
303  {
304  makeImapAccountPage(true);
305  }
306  else
307  {
308  TQString msg = i18n( "Account type is not supported." );
309  KMessageBox::information( topLevelWidget(),msg,i18n("Configure Account") );
310  return;
311  }
312 
313  setupSettings();
314 }
315 
316 AccountDialog::~AccountDialog()
317 {
318  delete mValidator;
319  mValidator = 0;
320  delete mServerTest;
321  mServerTest = 0;
322 }
323 
324 void AccountDialog::makeLocalAccountPage()
325 {
326  ProcmailRCParser procmailrcParser;
327  TQFrame *page = makeMainWidget();
328  TQGridLayout *topLayout = new TQGridLayout( page, 12, 3, 0, spacingHint() );
329  topLayout->addColSpacing( 1, fontMetrics().maxWidth()*15 );
330  topLayout->setRowStretch( 11, 10 );
331  topLayout->setColStretch( 1, 10 );
332 
333  mLocal.titleLabel = new TQLabel( i18n("Account Type: Local Account"), page );
334  topLayout->addMultiCellWidget( mLocal.titleLabel, 0, 0, 0, 2 );
335  TQFont titleFont( mLocal.titleLabel->font() );
336  titleFont.setBold( true );
337  mLocal.titleLabel->setFont( titleFont );
338  KSeparator *hline = new KSeparator( KSeparator::HLine, page);
339  topLayout->addMultiCellWidget( hline, 1, 1, 0, 2 );
340 
341  TQLabel *label = new TQLabel( i18n("Account &name:"), page );
342  topLayout->addWidget( label, 2, 0 );
343  mLocal.nameEdit = new KLineEdit( page );
344  label->setBuddy( mLocal.nameEdit );
345  topLayout->addWidget( mLocal.nameEdit, 2, 1 );
346 
347  label = new TQLabel( i18n("File &location:"), page );
348  topLayout->addWidget( label, 3, 0 );
349  mLocal.locationEdit = new TQComboBox( true, page );
350  label->setBuddy( mLocal.locationEdit );
351  topLayout->addWidget( mLocal.locationEdit, 3, 1 );
352  mLocal.locationEdit->insertStringList(procmailrcParser.getSpoolFilesList());
353 
354  TQPushButton *choose = new TQPushButton( i18n("Choo&se..."), page );
355  choose->setAutoDefault( false );
356  connect( choose, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotLocationChooser()) );
357  topLayout->addWidget( choose, 3, 2 );
358 
359  TQButtonGroup *group = new TQButtonGroup(i18n("Locking Method"), page );
360  group->setColumnLayout(0, TQt::Horizontal);
361  group->layout()->setSpacing( 0 );
362  group->layout()->setMargin( 0 );
363  TQGridLayout *groupLayout = new TQGridLayout( group->layout() );
364  groupLayout->setAlignment( TQt::AlignTop );
365  groupLayout->setSpacing( 6 );
366  groupLayout->setMargin( 11 );
367 
368  mLocal.lockProcmail = new TQRadioButton( i18n("Procmail loc&kfile:"), group);
369  groupLayout->addWidget(mLocal.lockProcmail, 0, 0);
370 
371  mLocal.procmailLockFileName = new TQComboBox( true, group );
372  groupLayout->addWidget(mLocal.procmailLockFileName, 0, 1);
373  mLocal.procmailLockFileName->insertStringList(procmailrcParser.getLockFilesList());
374  mLocal.procmailLockFileName->setEnabled(false);
375 
376  TQObject::connect(mLocal.lockProcmail, TQ_SIGNAL(toggled(bool)),
377  mLocal.procmailLockFileName, TQ_SLOT(setEnabled(bool)));
378 
379  mLocal.lockMutt = new TQRadioButton(
380  i18n("&Mutt dotlock"), group);
381  groupLayout->addWidget(mLocal.lockMutt, 1, 0);
382 
383  mLocal.lockMuttPriv = new TQRadioButton(
384  i18n("M&utt dotlock privileged"), group);
385  groupLayout->addWidget(mLocal.lockMuttPriv, 2, 0);
386 
387  mLocal.lockFcntl = new TQRadioButton(
388  i18n("&FCNTL"), group);
389  groupLayout->addWidget(mLocal.lockFcntl, 3, 0);
390 
391  mLocal.lockNone = new TQRadioButton(
392  i18n("Non&e (use with care)"), group);
393  groupLayout->addWidget(mLocal.lockNone, 4, 0);
394 
395  topLayout->addMultiCellWidget( group, 4, 4, 0, 2 );
396 
397 #if 0
398  TQHBox* resourceHB = new TQHBox( page );
399  resourceHB->setSpacing( 11 );
400  mLocal.resourceCheck =
401  new TQCheckBox( i18n( "Account for semiautomatic resource handling" ), resourceHB );
402  mLocal.resourceClearButton =
403  new TQPushButton( i18n( "Clear" ), resourceHB );
404  TQWhatsThis::add( mLocal.resourceClearButton,
405  i18n( "Delete all allocations for the resource represented by this account." ) );
406  mLocal.resourceClearButton->setEnabled( false );
407  connect( mLocal.resourceCheck, TQ_SIGNAL( toggled(bool) ),
408  mLocal.resourceClearButton, TQ_SLOT( setEnabled(bool) ) );
409  connect( mLocal.resourceClearButton, TQ_SIGNAL( clicked() ),
410  this, TQ_SLOT( slotClearResourceAllocations() ) );
411  mLocal.resourceClearPastButton =
412  new TQPushButton( i18n( "Clear Past" ), resourceHB );
413  mLocal.resourceClearPastButton->setEnabled( false );
414  connect( mLocal.resourceCheck, TQ_SIGNAL( toggled(bool) ),
415  mLocal.resourceClearPastButton, TQ_SLOT( setEnabled(bool) ) );
416  TQWhatsThis::add( mLocal.resourceClearPastButton,
417  i18n( "Delete all outdated allocations for the resource represented by this account." ) );
418  connect( mLocal.resourceClearPastButton, TQ_SIGNAL( clicked() ),
419  this, TQ_SLOT( slotClearPastResourceAllocations() ) );
420  topLayout->addMultiCellWidget( resourceHB, 5, 5, 0, 2 );
421 #endif
422 
423  mLocal.includeInCheck =
424  new TQCheckBox( i18n("Include in m&anual mail check"),
425  page );
426  topLayout->addMultiCellWidget( mLocal.includeInCheck, 5, 5, 0, 2 );
427 
428  mLocal.intervalCheck =
429  new TQCheckBox( i18n("Enable &interval mail checking"), page );
430  topLayout->addMultiCellWidget( mLocal.intervalCheck, 6, 6, 0, 2 );
431  connect( mLocal.intervalCheck, TQ_SIGNAL(toggled(bool)),
432  this, TQ_SLOT(slotEnableLocalInterval(bool)) );
433  mLocal.intervalLabel = new TQLabel( i18n("Check inter&val:"), page );
434  topLayout->addWidget( mLocal.intervalLabel, 7, 0 );
435  mLocal.intervalSpin = new KIntNumInput( page );
436  mLocal.intervalLabel->setBuddy( mLocal.intervalSpin );
437  mLocal.intervalSpin->setRange( GlobalSettings::self()->minimumCheckInterval(), 10000, 1, false );
438  mLocal.intervalSpin->setSuffix( i18n(" min") );
439  mLocal.intervalSpin->setValue( defaultmailcheckintervalmin );
440  topLayout->addWidget( mLocal.intervalSpin, 7, 1 );
441 
442  label = new TQLabel( i18n("&Destination folder:"), page );
443  topLayout->addWidget( label, 8, 0 );
444  mLocal.folderCombo = new TQComboBox( false, page );
445  label->setBuddy( mLocal.folderCombo );
446  topLayout->addWidget( mLocal.folderCombo, 8, 1 );
447 
448  label = new TQLabel( i18n("&Pre-command:"), page );
449  topLayout->addWidget( label, 9, 0 );
450  mLocal.precommand = new KLineEdit( page );
451  label->setBuddy( mLocal.precommand );
452  topLayout->addWidget( mLocal.precommand, 9, 1 );
453 
454  mLocal.identityLabel = new TQLabel( i18n("Identity:"), page );
455  topLayout->addWidget( mLocal.identityLabel, 10, 0 );
456  mLocal.identityCombo = new KPIM::IdentityCombo(kmkernel->identityManager(), page );
457  mLocal.identityLabel->setBuddy( mLocal.identityCombo );
458  topLayout->addWidget( mLocal.identityCombo, 10, 1 );
459 
460  connect(kapp,TQ_SIGNAL(tdedisplayFontChanged()),TQ_SLOT(slotFontChanged()));
461 }
462 
463 void AccountDialog::makeMaildirAccountPage()
464 {
465  ProcmailRCParser procmailrcParser;
466 
467  TQFrame *page = makeMainWidget();
468  TQGridLayout *topLayout = new TQGridLayout( page, 11, 3, 0, spacingHint() );
469  topLayout->addColSpacing( 1, fontMetrics().maxWidth()*15 );
470  topLayout->setRowStretch( 11, 10 );
471  topLayout->setColStretch( 1, 10 );
472 
473  mMaildir.titleLabel = new TQLabel( i18n("Account Type: Maildir Account"), page );
474  topLayout->addMultiCellWidget( mMaildir.titleLabel, 0, 0, 0, 2 );
475  TQFont titleFont( mMaildir.titleLabel->font() );
476  titleFont.setBold( true );
477  mMaildir.titleLabel->setFont( titleFont );
478  TQFrame *hline = new TQFrame( page );
479  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
480  topLayout->addMultiCellWidget( hline, 1, 1, 0, 2 );
481 
482  mMaildir.nameEdit = new KLineEdit( page );
483  topLayout->addWidget( mMaildir.nameEdit, 2, 1 );
484  TQLabel *label = new TQLabel( mMaildir.nameEdit, i18n("Account &name:"), page );
485  topLayout->addWidget( label, 2, 0 );
486 
487  mMaildir.locationEdit = new TQComboBox( true, page );
488  topLayout->addWidget( mMaildir.locationEdit, 3, 1 );
489  mMaildir.locationEdit->insertStringList(procmailrcParser.getSpoolFilesList());
490  label = new TQLabel( mMaildir.locationEdit, i18n("Folder &location:"), page );
491  topLayout->addWidget( label, 3, 0 );
492 
493  TQPushButton *choose = new TQPushButton( i18n("Choo&se..."), page );
494  choose->setAutoDefault( false );
495  connect( choose, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotMaildirChooser()) );
496  topLayout->addWidget( choose, 3, 2 );
497 
498 #if 0
499  TQHBox* resourceHB = new TQHBox( page );
500  resourceHB->setSpacing( 11 );
501  mMaildir.resourceCheck =
502  new TQCheckBox( i18n( "Account for semiautomatic resource handling" ), resourceHB );
503  mMaildir.resourceClearButton =
504  new TQPushButton( i18n( "Clear" ), resourceHB );
505  mMaildir.resourceClearButton->setEnabled( false );
506  connect( mMaildir.resourceCheck, TQ_SIGNAL( toggled(bool) ),
507  mMaildir.resourceClearButton, TQ_SLOT( setEnabled(bool) ) );
508  TQWhatsThis::add( mMaildir.resourceClearButton,
509  i18n( "Delete all allocations for the resource represented by this account." ) );
510  connect( mMaildir.resourceClearButton, TQ_SIGNAL( clicked() ),
511  this, TQ_SLOT( slotClearResourceAllocations() ) );
512  mMaildir.resourceClearPastButton =
513  new TQPushButton( i18n( "Clear Past" ), resourceHB );
514  mMaildir.resourceClearPastButton->setEnabled( false );
515  connect( mMaildir.resourceCheck, TQ_SIGNAL( toggled(bool) ),
516  mMaildir.resourceClearPastButton, TQ_SLOT( setEnabled(bool) ) );
517  TQWhatsThis::add( mMaildir.resourceClearPastButton,
518  i18n( "Delete all outdated allocations for the resource represented by this account." ) );
519  connect( mMaildir.resourceClearPastButton, TQ_SIGNAL( clicked() ),
520  this, TQ_SLOT( slotClearPastResourceAllocations() ) );
521  topLayout->addMultiCellWidget( resourceHB, 4, 4, 0, 2 );
522 #endif
523 
524  mMaildir.includeInCheck =
525  new TQCheckBox( i18n("Include in &manual mail check"), page );
526  topLayout->addMultiCellWidget( mMaildir.includeInCheck, 4, 4, 0, 2 );
527 
528  mMaildir.intervalCheck =
529  new TQCheckBox( i18n("Enable &interval mail checking"), page );
530  topLayout->addMultiCellWidget( mMaildir.intervalCheck, 5, 5, 0, 2 );
531  connect( mMaildir.intervalCheck, TQ_SIGNAL(toggled(bool)),
532  this, TQ_SLOT(slotEnableMaildirInterval(bool)) );
533  mMaildir.intervalLabel = new TQLabel( i18n("Check inter&val:"), page );
534  topLayout->addWidget( mMaildir.intervalLabel, 6, 0 );
535  mMaildir.intervalSpin = new KIntNumInput( page );
536  mMaildir.intervalSpin->setRange( GlobalSettings::self()->minimumCheckInterval(), 10000, 1, false );
537  mMaildir.intervalSpin->setSuffix( i18n(" min") );
538  mMaildir.intervalSpin->setValue( defaultmailcheckintervalmin );
539  mMaildir.intervalLabel->setBuddy( mMaildir.intervalSpin );
540  topLayout->addWidget( mMaildir.intervalSpin, 6, 1 );
541 
542  mMaildir.folderCombo = new TQComboBox( false, page );
543  topLayout->addWidget( mMaildir.folderCombo, 7, 1 );
544  label = new TQLabel( mMaildir.folderCombo,
545  i18n("&Destination folder:"), page );
546  topLayout->addWidget( label, 7, 0 );
547 
548  mMaildir.precommand = new KLineEdit( page );
549  topLayout->addWidget( mMaildir.precommand, 8, 1 );
550  label = new TQLabel( mMaildir.precommand, i18n("&Pre-command:"), page );
551  topLayout->addWidget( label, 8, 0 );
552 
553 
554  mMaildir.identityLabel = new TQLabel( i18n("Identity:"), page );
555  topLayout->addWidget( mMaildir.identityLabel, 9, 0 );
556  mMaildir.identityCombo = new KPIM::IdentityCombo(kmkernel->identityManager(), page );
557  mMaildir.identityLabel->setBuddy( mMaildir.identityCombo );
558  topLayout->addWidget( mMaildir.identityCombo, 9, 1 );
559 
560  connect(kapp,TQ_SIGNAL(tdedisplayFontChanged()),TQ_SLOT(slotFontChanged()));
561 }
562 
563 
564 void AccountDialog::makePopAccountPage()
565 {
566  TQFrame *page = makeMainWidget();
567  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
568 
569  mPop.titleLabel = new TQLabel( page );
570  mPop.titleLabel->setText( i18n("Account Type: POP Account") );
571  TQFont titleFont( mPop.titleLabel->font() );
572  titleFont.setBold( true );
573  mPop.titleLabel->setFont( titleFont );
574  topLayout->addWidget( mPop.titleLabel );
575  KSeparator *hline = new KSeparator( KSeparator::HLine, page);
576  topLayout->addWidget( hline );
577 
578  TQTabWidget *tabWidget = new TQTabWidget(page);
579  topLayout->addWidget( tabWidget );
580 
581  TQWidget *page1 = new TQWidget( tabWidget );
582  tabWidget->addTab( page1, i18n("&General") );
583 
584  TQGridLayout *grid = new TQGridLayout( page1, 16, 2, marginHint(), spacingHint() );
585  grid->addColSpacing( 1, fontMetrics().maxWidth()*15 );
586  grid->setRowStretch( 15, 10 );
587  grid->setColStretch( 1, 10 );
588 
589  TQLabel *label = new TQLabel( i18n("Account &name:"), page1 );
590  grid->addWidget( label, 0, 0 );
591  mPop.nameEdit = new KLineEdit( page1 );
592  label->setBuddy( mPop.nameEdit );
593  grid->addWidget( mPop.nameEdit, 0, 1 );
594 
595  label = new TQLabel( i18n("&Login:"), page1 );
596  TQWhatsThis::add( label, i18n("Your Internet Service Provider gave you a <em>user name</em> which is used to authenticate you with their servers. It usually is the first part of your email address (the part before <em>@</em>).") );
597  grid->addWidget( label, 1, 0 );
598  mPop.loginEdit = new KLineEdit( page1 );
599  label->setBuddy( mPop.loginEdit );
600  grid->addWidget( mPop.loginEdit, 1, 1 );
601 
602  label = new TQLabel( i18n("P&assword:"), page1 );
603  grid->addWidget( label, 2, 0 );
604  mPop.passwordEdit = new KLineEdit( page1 );
605  mPop.passwordEdit->setEchoMode( TQLineEdit::Password );
606  label->setBuddy( mPop.passwordEdit );
607  grid->addWidget( mPop.passwordEdit, 2, 1 );
608 
609  label = new TQLabel( i18n("Ho&st:"), page1 );
610  grid->addWidget( label, 3, 0 );
611  mPop.hostEdit = new KLineEdit( page1 );
612  // only letters, digits, '-', '.', ':' (IPv6) and '_' (for Windows
613  // compatibility) are allowed
614  mPop.hostEdit->setValidator(mValidator);
615  label->setBuddy( mPop.hostEdit );
616  grid->addWidget( mPop.hostEdit, 3, 1 );
617 
618  label = new TQLabel( i18n("&Port:"), page1 );
619  grid->addWidget( label, 4, 0 );
620  mPop.portEdit = new KLineEdit( page1 );
621  mPop.portEdit->setValidator( new TQIntValidator(this) );
622  label->setBuddy( mPop.portEdit );
623  grid->addWidget( mPop.portEdit, 4, 1 );
624 
625  mPop.storePasswordCheck =
626  new TQCheckBox( i18n("Sto&re POP password"), page1 );
627  TQWhatsThis::add( mPop.storePasswordCheck,
628  i18n("Check this option to have KMail store "
629  "the password.\nIf TDEWallet is available "
630  "the password will be stored there which is considered "
631  "safe.\nHowever, if TDEWallet is not available, "
632  "the password will be stored in KMail's configuration "
633  "file. The password is stored in an "
634  "obfuscated format, but should not be "
635  "considered secure from decryption efforts "
636  "if access to the configuration file is obtained.") );
637  grid->addMultiCellWidget( mPop.storePasswordCheck, 5, 5, 0, 1 );
638 
639  mPop.leaveOnServerCheck =
640  new TQCheckBox( i18n("Lea&ve fetched messages on the server"), page1 );
641  connect( mPop.leaveOnServerCheck, TQ_SIGNAL( clicked() ),
642  this, TQ_SLOT( slotLeaveOnServerClicked() ) );
643  grid->addMultiCellWidget( mPop.leaveOnServerCheck, 6, 6, 0, 1 );
644  TQHBox *afterDaysBox = new TQHBox( page1 );
645  afterDaysBox->setSpacing( KDialog::spacingHint() );
646  mPop.leaveOnServerDaysCheck =
647  new TQCheckBox( i18n("Leave messages on the server for"), afterDaysBox );
648  connect( mPop.leaveOnServerDaysCheck, TQ_SIGNAL( toggled(bool) ),
649  this, TQ_SLOT( slotEnableLeaveOnServerDays(bool)) );
650  mPop.leaveOnServerDaysSpin = new KIntNumInput( afterDaysBox );
651  mPop.leaveOnServerDaysSpin->setRange( 1, 365, 1, false );
652  connect( mPop.leaveOnServerDaysSpin, TQ_SIGNAL(valueChanged(int)),
653  TQ_SLOT(slotLeaveOnServerDaysChanged(int)));
654  mPop.leaveOnServerDaysSpin->setValue( 1 );
655  afterDaysBox->setStretchFactor( mPop.leaveOnServerDaysSpin, 1 );
656  grid->addMultiCellWidget( afterDaysBox, 7, 7, 0, 1 );
657  TQHBox *leaveOnServerCountBox = new TQHBox( page1 );
658  leaveOnServerCountBox->setSpacing( KDialog::spacingHint() );
659  mPop.leaveOnServerCountCheck =
660  new TQCheckBox( i18n("Keep only the last"), leaveOnServerCountBox );
661  connect( mPop.leaveOnServerCountCheck, TQ_SIGNAL( toggled(bool) ),
662  this, TQ_SLOT( slotEnableLeaveOnServerCount(bool)) );
663  mPop.leaveOnServerCountSpin = new KIntNumInput( leaveOnServerCountBox );
664  mPop.leaveOnServerCountSpin->setRange( 1, 999999, 1, false );
665  connect( mPop.leaveOnServerCountSpin, TQ_SIGNAL(valueChanged(int)),
666  TQ_SLOT(slotLeaveOnServerCountChanged(int)));
667  mPop.leaveOnServerCountSpin->setValue( 100 );
668  grid->addMultiCellWidget( leaveOnServerCountBox, 8, 8, 0, 1 );
669  TQHBox *leaveOnServerSizeBox = new TQHBox( page1 );
670  leaveOnServerSizeBox->setSpacing( KDialog::spacingHint() );
671  mPop.leaveOnServerSizeCheck =
672  new TQCheckBox( i18n("Keep only the last"), leaveOnServerSizeBox );
673  connect( mPop.leaveOnServerSizeCheck, TQ_SIGNAL( toggled(bool) ),
674  this, TQ_SLOT( slotEnableLeaveOnServerSize(bool)) );
675  mPop.leaveOnServerSizeSpin = new KIntNumInput( leaveOnServerSizeBox );
676  mPop.leaveOnServerSizeSpin->setRange( 1, 999999, 1, false );
677  mPop.leaveOnServerSizeSpin->setSuffix( i18n(" MB") );
678  mPop.leaveOnServerSizeSpin->setValue( 10 );
679  grid->addMultiCellWidget( leaveOnServerSizeBox, 9, 9, 0, 1 );
680 #if 0
681  TQHBox *resourceHB = new TQHBox( page1 );
682  resourceHB->setSpacing( 11 );
683  mPop.resourceCheck =
684  new TQCheckBox( i18n( "Account for semiautomatic resource handling" ), resourceHB );
685  mPop.resourceClearButton =
686  new TQPushButton( i18n( "Clear" ), resourceHB );
687  mPop.resourceClearButton->setEnabled( false );
688  connect( mPop.resourceCheck, TQ_SIGNAL( toggled(bool) ),
689  mPop.resourceClearButton, TQ_SLOT( setEnabled(bool) ) );
690  TQWhatsThis::add( mPop.resourceClearButton,
691  i18n( "Delete all allocations for the resource represented by this account." ) );
692  connect( mPop.resourceClearButton, TQ_SIGNAL( clicked() ),
693  this, TQ_SLOT( slotClearResourceAllocations() ) );
694  mPop.resourceClearPastButton =
695  new TQPushButton( i18n( "Clear Past" ), resourceHB );
696  mPop.resourceClearPastButton->setEnabled( false );
697  connect( mPop.resourceCheck, TQ_SIGNAL( toggled(bool) ),
698  mPop.resourceClearPastButton, TQ_SLOT( setEnabled(bool) ) );
699  TQWhatsThis::add( mPop.resourceClearPastButton,
700  i18n( "Delete all outdated allocations for the resource represented by this account." ) );
701  connect( mPop.resourceClearPastButton, TQ_SIGNAL( clicked() ),
702  this, TQ_SLOT( slotClearPastResourceAllocations() ) );
703  grid->addMultiCellWidget( resourceHB, 10, 10, 0, 2 );
704 #endif
705 
706  mPop.includeInCheck =
707  new TQCheckBox( i18n("Include in man&ual mail check"), page1 );
708  grid->addMultiCellWidget( mPop.includeInCheck, 10, 10, 0, 1 );
709 
710  TQHBox * hbox = new TQHBox( page1 );
711  hbox->setSpacing( KDialog::spacingHint() );
712  mPop.filterOnServerCheck =
713  new TQCheckBox( i18n("&Filter messages if they are greater than"), hbox );
714  mPop.filterOnServerSizeSpin = new KIntNumInput ( hbox );
715  mPop.filterOnServerSizeSpin->setEnabled( false );
716  hbox->setStretchFactor( mPop.filterOnServerSizeSpin, 1 );
717  mPop.filterOnServerSizeSpin->setRange( 1, 10000000, 100, false );
718  connect(mPop.filterOnServerSizeSpin, TQ_SIGNAL(valueChanged(int)),
719  TQ_SLOT(slotFilterOnServerSizeChanged(int)));
720  mPop.filterOnServerSizeSpin->setValue( 50000 );
721  grid->addMultiCellWidget( hbox, 11, 11, 0, 1 );
722  connect( mPop.filterOnServerCheck, TQ_SIGNAL(toggled(bool)),
723  mPop.filterOnServerSizeSpin, TQ_SLOT(setEnabled(bool)) );
724  connect( mPop.filterOnServerCheck, TQ_SIGNAL( clicked() ),
725  this, TQ_SLOT( slotFilterOnServerClicked() ) );
726  TQString msg = i18n("If you select this option, POP Filters will be used to "
727  "decide what to do with messages. You can then select "
728  "to download, delete or keep them on the server." );
729  TQWhatsThis::add( mPop.filterOnServerCheck, msg );
730  TQWhatsThis::add( mPop.filterOnServerSizeSpin, msg );
731 
732  mPop.intervalCheck =
733  new TQCheckBox( i18n("Enable &interval mail checking"), page1 );
734  grid->addMultiCellWidget( mPop.intervalCheck, 12, 12, 0, 1 );
735  connect( mPop.intervalCheck, TQ_SIGNAL(toggled(bool)),
736  this, TQ_SLOT(slotEnablePopInterval(bool)) );
737  mPop.intervalLabel = new TQLabel( i18n("Chec&k interval:"), page1 );
738  grid->addWidget( mPop.intervalLabel, 13, 0 );
739  mPop.intervalSpin = new KIntNumInput( page1 );
740  mPop.intervalSpin->setRange( GlobalSettings::self()->minimumCheckInterval(), 10000, 1, false );
741  mPop.intervalSpin->setSuffix( i18n(" min") );
742  mPop.intervalSpin->setValue( defaultmailcheckintervalmin );
743  mPop.intervalLabel->setBuddy( mPop.intervalSpin );
744  grid->addWidget( mPop.intervalSpin, 13, 1 );
745 
746  label = new TQLabel( i18n("Des&tination folder:"), page1 );
747  grid->addWidget( label, 14, 0 );
748  mPop.folderCombo = new TQComboBox( false, page1 );
749  label->setBuddy( mPop.folderCombo );
750  grid->addWidget( mPop.folderCombo, 14, 1 );
751 
752  label = new TQLabel( i18n("Pre-com&mand:"), page1 );
753  grid->addWidget( label, 15, 0 );
754  mPop.precommand = new KLineEdit( page1 );
755  label->setBuddy(mPop.precommand);
756  grid->addWidget( mPop.precommand, 15, 1 );
757 
758  mPop.identityLabel = new TQLabel( i18n("Identity:"), page1 );
759  grid->addWidget( mPop.identityLabel, 16, 0 );
760  mPop.identityCombo = new KPIM::IdentityCombo(kmkernel->identityManager(), page1 );
761  mPop.identityLabel->setBuddy( mPop.identityCombo );
762  grid->addWidget( mPop.identityCombo, 16, 1 );
763 
764  TQWidget *page2 = new TQWidget( tabWidget );
765  tabWidget->addTab( page2, i18n("&Extras") );
766  TQVBoxLayout *vlay = new TQVBoxLayout( page2, marginHint(), spacingHint() );
767 
768  vlay->addSpacing( KDialog::spacingHint() );
769 
770  TQHBoxLayout *buttonLay = new TQHBoxLayout( vlay );
771  mPop.checkCapabilities =
772  new TQPushButton( i18n("Check &What the Server Supports"), page2 );
773  connect(mPop.checkCapabilities, TQ_SIGNAL(clicked()),
774  TQ_SLOT(slotCheckPopCapabilities()));
775  buttonLay->addStretch();
776  buttonLay->addWidget( mPop.checkCapabilities );
777  buttonLay->addStretch();
778 
779  vlay->addSpacing( KDialog::spacingHint() );
780 
781  mPop.encryptionGroup = new TQButtonGroup( 1, TQt::Horizontal,
782  i18n("Encryption"), page2 );
783  mPop.encryptionNone =
784  new TQRadioButton( i18n("&None"), mPop.encryptionGroup );
785  mPop.encryptionSSL =
786  new TQRadioButton( i18n("Use &SSL for secure mail download"),
787  mPop.encryptionGroup );
788  mPop.encryptionTLS =
789  new TQRadioButton( i18n("Use &TLS for secure mail download"),
790  mPop.encryptionGroup );
791  connect(mPop.encryptionGroup, TQ_SIGNAL(clicked(int)),
792  TQ_SLOT(slotPopEncryptionChanged(int)));
793  vlay->addWidget( mPop.encryptionGroup );
794 
795  mPop.authGroup = new TQButtonGroup( 1, TQt::Horizontal,
796  i18n("Authentication Method"), page2 );
797  mPop.authUser = new TQRadioButton( i18n("Clear te&xt") , mPop.authGroup,
798  "auth clear text" );
799  mPop.authLogin = new TQRadioButton( i18n("Please translate this "
800  "authentication method only if you have a good reason", "&LOGIN"),
801  mPop.authGroup, "auth login" );
802  mPop.authPlain = new TQRadioButton( i18n("Please translate this "
803  "authentication method only if you have a good reason", "&PLAIN"),
804  mPop.authGroup, "auth plain" );
805  mPop.authCRAM_MD5 = new TQRadioButton( i18n("CRAM-MD&5"), mPop.authGroup, "auth cram-md5" );
806  mPop.authDigestMd5 = new TQRadioButton( i18n("&DIGEST-MD5"), mPop.authGroup, "auth digest-md5" );
807  mPop.authNTLM = new TQRadioButton( i18n("&NTLM"), mPop.authGroup, "auth ntlm" );
808  mPop.authGSSAPI = new TQRadioButton( i18n("&GSSAPI"), mPop.authGroup, "auth gssapi" );
809  if ( KProtocolInfo::capabilities("pop3").contains("SASL") == 0 )
810  {
811  mPop.authNTLM->hide();
812  mPop.authGSSAPI->hide();
813  }
814  mPop.authAPOP = new TQRadioButton( i18n("&APOP"), mPop.authGroup, "auth apop" );
815 
816  vlay->addWidget( mPop.authGroup );
817 
818  mPop.usePipeliningCheck =
819  new TQCheckBox( i18n("&Use pipelining for faster mail download"), page2 );
820  connect(mPop.usePipeliningCheck, TQ_SIGNAL(clicked()),
821  TQ_SLOT(slotPipeliningClicked()));
822  vlay->addWidget( mPop.usePipeliningCheck );
823 
824  vlay->addStretch();
825 
826  connect(kapp,TQ_SIGNAL(tdedisplayFontChanged()),TQ_SLOT(slotFontChanged()));
827 }
828 
829 
830 void AccountDialog::makeImapAccountPage( bool connected )
831 {
832  TQFrame *page = makeMainWidget();
833  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
834 
835  mImap.titleLabel = new TQLabel( page );
836  if( connected )
837  mImap.titleLabel->setText( i18n("Account Type: Disconnected IMAP Account") );
838  else
839  mImap.titleLabel->setText( i18n("Account Type: IMAP Account") );
840  TQFont titleFont( mImap.titleLabel->font() );
841  titleFont.setBold( true );
842  mImap.titleLabel->setFont( titleFont );
843  topLayout->addWidget( mImap.titleLabel );
844  KSeparator *hline = new KSeparator( KSeparator::HLine, page);
845  topLayout->addWidget( hline );
846 
847  TQTabWidget *tabWidget = new TQTabWidget(page);
848  topLayout->addWidget( tabWidget );
849 
850  TQWidget *page1 = new TQWidget( tabWidget );
851  tabWidget->addTab( page1, i18n("&General") );
852 
853  int row = -1;
854  TQGridLayout *grid = new TQGridLayout( page1, 16, 2, marginHint(), spacingHint() );
855  grid->addColSpacing( 1, fontMetrics().maxWidth()*16 );
856 
857  ++row;
858  TQLabel *label = new TQLabel( i18n("Account &name:"), page1 );
859  grid->addWidget( label, row, 0 );
860  mImap.nameEdit = new KLineEdit( page1 );
861  label->setBuddy( mImap.nameEdit );
862  grid->addWidget( mImap.nameEdit, row, 1 );
863 
864  ++row;
865  label = new TQLabel( i18n("&Login:"), page1 );
866  TQWhatsThis::add( label, i18n("Your Internet Service Provider gave you a <em>user name</em> which is used to authenticate you with their servers. It usually is the first part of your email address (the part before <em>@</em>).") );
867  grid->addWidget( label, row, 0 );
868  mImap.loginEdit = new KLineEdit( page1 );
869  label->setBuddy( mImap.loginEdit );
870  grid->addWidget( mImap.loginEdit, row, 1 );
871 
872  ++row;
873  label = new TQLabel( i18n("P&assword:"), page1 );
874  grid->addWidget( label, row, 0 );
875  mImap.passwordEdit = new KLineEdit( page1 );
876  mImap.passwordEdit->setEchoMode( TQLineEdit::Password );
877  label->setBuddy( mImap.passwordEdit );
878  grid->addWidget( mImap.passwordEdit, row, 1 );
879 
880  ++row;
881  label = new TQLabel( i18n("Ho&st:"), page1 );
882  grid->addWidget( label, row, 0 );
883  mImap.hostEdit = new KLineEdit( page1 );
884  // only letters, digits, '-', '.', ':' (IPv6) and '_' (for Windows
885  // compatibility) are allowed
886  mImap.hostEdit->setValidator(mValidator);
887  label->setBuddy( mImap.hostEdit );
888  grid->addWidget( mImap.hostEdit, row, 1 );
889 
890  ++row;
891  label = new TQLabel( i18n("&Port:"), page1 );
892  grid->addWidget( label, row, 0 );
893  mImap.portEdit = new KLineEdit( page1 );
894  mImap.portEdit->setValidator( new TQIntValidator(this) );
895  label->setBuddy( mImap.portEdit );
896  grid->addWidget( mImap.portEdit, row, 1 );
897 
898  // namespace list
899  ++row;
900  TQHBox* box = new TQHBox( page1 );
901  label = new TQLabel( i18n("Namespaces:"), box );
902  TQWhatsThis::add( label, i18n( "Here you see the different namespaces that your IMAP server supports."
903  "Each namespace represents a prefix that separates groups of folders."
904  "Namespaces allow KMail for example to display your personal folders and shared folders in one account." ) );
905  // button to reload
906  TQToolButton* button = new TQToolButton( box );
907  button->setAutoRaise(true);
908  button->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
909  button->setFixedSize( 22, 22 );
910  button->setIconSet(
911  TDEGlobal::iconLoader()->loadIconSet( "reload", TDEIcon::Small, 0 ) );
912  connect( button, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotReloadNamespaces()) );
913  TQWhatsThis::add( button,
914  i18n("Reload the namespaces from the server. This overwrites any changes.") );
915  grid->addWidget( box, row, 0 );
916 
917  // grid with label, namespace list and edit button
918  TQGrid* listbox = new TQGrid( 3, page1 );
919  label = new TQLabel( i18n("Personal"), listbox );
920  TQWhatsThis::add( label, i18n( "Personal namespaces include your personal folders." ) );
921  mImap.personalNS = new KLineEdit( listbox );
922  mImap.personalNS->setReadOnly( true );
923  mImap.editPNS = new TQToolButton( listbox );
924  mImap.editPNS->setIconSet(
925  TDEGlobal::iconLoader()->loadIconSet( "edit", TDEIcon::Small, 0 ) );
926  mImap.editPNS->setAutoRaise( true );
927  mImap.editPNS->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
928  mImap.editPNS->setFixedSize( 22, 22 );
929  connect( mImap.editPNS, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotEditPersonalNamespace()) );
930 
931  label = new TQLabel( i18n("Other Users"), listbox );
932  TQWhatsThis::add( label, i18n( "These namespaces include the folders of other users." ) );
933  mImap.otherUsersNS = new KLineEdit( listbox );
934  mImap.otherUsersNS->setReadOnly( true );
935  mImap.editONS = new TQToolButton( listbox );
936  mImap.editONS->setIconSet(
937  TDEGlobal::iconLoader()->loadIconSet( "edit", TDEIcon::Small, 0 ) );
938  mImap.editONS->setAutoRaise( true );
939  mImap.editONS->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
940  mImap.editONS->setFixedSize( 22, 22 );
941  connect( mImap.editONS, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotEditOtherUsersNamespace()) );
942 
943  label = new TQLabel( i18n("Shared"), listbox );
944  TQWhatsThis::add( label, i18n( "These namespaces include the shared folders." ) );
945  mImap.sharedNS = new KLineEdit( listbox );
946  mImap.sharedNS->setReadOnly( true );
947  mImap.editSNS = new TQToolButton( listbox );
948  mImap.editSNS->setIconSet(
949  TDEGlobal::iconLoader()->loadIconSet( "edit", TDEIcon::Small, 0 ) );
950  mImap.editSNS->setAutoRaise( true );
951  mImap.editSNS->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
952  mImap.editSNS->setFixedSize( 22, 22 );
953  connect( mImap.editSNS, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotEditSharedNamespace()) );
954 
955  label->setBuddy( listbox );
956  grid->addWidget( listbox, row, 1 );
957 
958  ++row;
959  mImap.storePasswordCheck =
960  new TQCheckBox( i18n("Sto&re IMAP password"), page1 );
961  TQWhatsThis::add( mImap.storePasswordCheck,
962  i18n("Check this option to have KMail store "
963  "the password.\nIf TDEWallet is available "
964  "the password will be stored there which is considered "
965  "safe.\nHowever, if TDEWallet is not available, "
966  "the password will be stored in KMail's configuration "
967  "file. The password is stored in an "
968  "obfuscated format, but should not be "
969  "considered secure from decryption efforts "
970  "if access to the configuration file is obtained.") );
971  grid->addMultiCellWidget( mImap.storePasswordCheck, row, row, 0, 1 );
972 
973  if( !connected ) {
974  ++row;
975  mImap.autoExpungeCheck =
976  new TQCheckBox( i18n("Automaticall&y compact folders (expunges deleted messages)"), page1);
977  grid->addMultiCellWidget( mImap.autoExpungeCheck, row, row, 0, 1 );
978  }
979 
980  ++row;
981  mImap.hiddenFoldersCheck = new TQCheckBox( i18n("Sho&w hidden folders"), page1);
982  grid->addMultiCellWidget( mImap.hiddenFoldersCheck, row, row, 0, 1 );
983 
984 
985  ++row;
986  mImap.subscribedFoldersCheck = new TQCheckBox(
987  i18n("Show only serverside s&ubscribed folders"), page1);
988  grid->addMultiCellWidget( mImap.subscribedFoldersCheck, row, row, 0, 1 );
989 
990  ++row;
991  mImap.locallySubscribedFoldersCheck = new TQCheckBox(
992  i18n("Show only &locally subscribed folders"), page1);
993  grid->addMultiCellWidget( mImap.locallySubscribedFoldersCheck, row, row, 0, 1 );
994 
995  if ( !connected ) {
996  // not implemented for disconnected yet
997  ++row;
998  mImap.loadOnDemandCheck = new TQCheckBox(
999  i18n("Load attach&ments on demand"), page1);
1000  TQWhatsThis::add( mImap.loadOnDemandCheck,
1001  i18n("Activate this to load attachments not automatically when you select the email but only when you click on the attachment. This way also big emails are shown instantly.") );
1002  grid->addMultiCellWidget( mImap.loadOnDemandCheck, row, row, 0, 1 );
1003  }
1004 
1005  if ( !connected ) {
1006  // not implemented for disconnected yet
1007  ++row;
1008  mImap.listOnlyOpenCheck = new TQCheckBox(
1009  i18n("List only open folders"), page1);
1010  TQWhatsThis::add( mImap.listOnlyOpenCheck,
1011  i18n("Only folders that are open (expanded) in the folder tree are checked for subfolders. Use this if there are many folders on the server.") );
1012  grid->addMultiCellWidget( mImap.listOnlyOpenCheck, row, row, 0, 1 );
1013  }
1014 
1015 #if 0
1016  ++row;
1017  TQHBox* resourceHB = new TQHBox( page1 );
1018  resourceHB->setSpacing( 11 );
1019  mImap.resourceCheck =
1020  new TQCheckBox( i18n( "Account for semiautomatic resource handling" ), resourceHB );
1021  mImap.resourceClearButton =
1022  new TQPushButton( i18n( "Clear" ), resourceHB );
1023  mImap.resourceClearButton->setEnabled( false );
1024  connect( mImap.resourceCheck, TQ_SIGNAL( toggled(bool) ),
1025  mImap.resourceClearButton, TQ_SLOT( setEnabled(bool) ) );
1026  TQWhatsThis::add( mImap.resourceClearButton,
1027  i18n( "Delete all allocations for the resource represented by this account." ) );
1028  connect( mImap.resourceClearButton, TQ_SIGNAL( clicked() ),
1029  this, TQ_SLOT( slotClearResourceAllocations() ) );
1030  mImap.resourceClearPastButton =
1031  new TQPushButton( i18n( "Clear Past" ), resourceHB );
1032  mImap.resourceClearPastButton->setEnabled( false );
1033  connect( mImap.resourceCheck, TQ_SIGNAL( toggled(bool) ),
1034  mImap.resourceClearPastButton, TQ_SLOT( setEnabled(bool) ) );
1035  TQWhatsThis::add( mImap.resourceClearPastButton,
1036  i18n( "Delete all outdated allocations for the resource represented by this account." ) );
1037  connect( mImap.resourceClearPastButton, TQ_SIGNAL( clicked() ),
1038  this, TQ_SLOT( slotClearPastResourceAllocations() ) );
1039  grid->addMultiCellWidget( resourceHB, row, row, 0, 2 );
1040 #endif
1041 
1042  ++row;
1043  mImap.includeInCheck =
1044  new TQCheckBox( i18n("Include in manual mail chec&k"), page1 );
1045  grid->addMultiCellWidget( mImap.includeInCheck, row, row, 0, 1 );
1046 
1047  ++row;
1048  mImap.intervalCheck =
1049  new TQCheckBox( i18n("Enable &interval mail checking"), page1 );
1050  grid->addMultiCellWidget( mImap.intervalCheck, row, row, 0, 2 );
1051  connect( mImap.intervalCheck, TQ_SIGNAL(toggled(bool)),
1052  this, TQ_SLOT(slotEnableImapInterval(bool)) );
1053  ++row;
1054  mImap.intervalLabel = new TQLabel( i18n("Check inter&val:"), page1 );
1055  grid->addWidget( mImap.intervalLabel, row, 0 );
1056  mImap.intervalSpin = new KIntNumInput( page1 );
1057  mImap.intervalSpin->setRange( GlobalSettings::minimumCheckInterval(), 60, 1, false );
1058  mImap.intervalSpin->setValue( defaultmailcheckintervalmin );
1059  mImap.intervalSpin->setSuffix( i18n( " min" ) );
1060  mImap.intervalLabel->setBuddy( mImap.intervalSpin );
1061  grid->addWidget( mImap.intervalSpin, row, 1 );
1062 
1063  ++row;
1064  label = new TQLabel( i18n("&Trash folder:"), page1 );
1065  grid->addWidget( label, row, 0 );
1066  mImap.trashCombo = new FolderRequester( page1,
1067  kmkernel->getKMMainWidget()->folderTree() );
1068  mImap.trashCombo->setShowOutbox( false );
1069  label->setBuddy( mImap.trashCombo );
1070  grid->addWidget( mImap.trashCombo, row, 1 );
1071 
1072  ++row;
1073  mImap.identityLabel = new TQLabel( i18n("Identity:"), page1 );
1074  grid->addWidget( mImap.identityLabel, row, 0 );
1075  mImap.identityCombo = new KPIM::IdentityCombo(kmkernel->identityManager(), page1 );
1076  mImap.identityLabel->setBuddy( mImap.identityCombo );
1077  grid->addWidget( mImap.identityCombo, row, 1 );
1078 
1079  TQWidget *page2 = new TQWidget( tabWidget );
1080  tabWidget->addTab( page2, i18n("S&ecurity") );
1081  TQVBoxLayout *vlay = new TQVBoxLayout( page2, marginHint(), spacingHint() );
1082 
1083  vlay->addSpacing( KDialog::spacingHint() );
1084 
1085  TQHBoxLayout *buttonLay = new TQHBoxLayout( vlay );
1086  mImap.checkCapabilities =
1087  new TQPushButton( i18n("Check &What the Server Supports"), page2 );
1088  connect(mImap.checkCapabilities, TQ_SIGNAL(clicked()),
1089  TQ_SLOT(slotCheckImapCapabilities()));
1090  buttonLay->addStretch();
1091  buttonLay->addWidget( mImap.checkCapabilities );
1092  buttonLay->addStretch();
1093 
1094  vlay->addSpacing( KDialog::spacingHint() );
1095 
1096  mImap.encryptionGroup = new TQButtonGroup( 1, TQt::Horizontal,
1097  i18n("Encryption"), page2 );
1098  mImap.encryptionNone =
1099  new TQRadioButton( i18n("&None"), mImap.encryptionGroup );
1100  mImap.encryptionSSL =
1101  new TQRadioButton( i18n("Use &SSL for secure mail download"),
1102  mImap.encryptionGroup );
1103  mImap.encryptionTLS =
1104  new TQRadioButton( i18n("Use &TLS for secure mail download"),
1105  mImap.encryptionGroup );
1106  connect(mImap.encryptionGroup, TQ_SIGNAL(clicked(int)),
1107  TQ_SLOT(slotImapEncryptionChanged(int)));
1108  vlay->addWidget( mImap.encryptionGroup );
1109 
1110  mImap.authGroup = new TQButtonGroup( 1, TQt::Horizontal,
1111  i18n("Authentication Method"), page2 );
1112  mImap.authUser = new TQRadioButton( i18n("Clear te&xt"), mImap.authGroup );
1113  mImap.authLogin = new TQRadioButton( i18n("Please translate this "
1114  "authentication method only if you have a good reason", "&LOGIN"),
1115  mImap.authGroup );
1116  mImap.authPlain = new TQRadioButton( i18n("Please translate this "
1117  "authentication method only if you have a good reason", "&PLAIN"),
1118  mImap.authGroup );
1119  mImap.authCramMd5 = new TQRadioButton( i18n("CRAM-MD&5"), mImap.authGroup );
1120  mImap.authDigestMd5 = new TQRadioButton( i18n("&DIGEST-MD5"), mImap.authGroup );
1121  mImap.authNTLM = new TQRadioButton( i18n("&NTLM"), mImap.authGroup );
1122  mImap.authGSSAPI = new TQRadioButton( i18n("&GSSAPI"), mImap.authGroup );
1123  mImap.authAnonymous = new TQRadioButton( i18n("&Anonymous"), mImap.authGroup );
1124  vlay->addWidget( mImap.authGroup );
1125 
1126  vlay->addStretch();
1127 
1128  // TODO (marc/bo): Test this
1129  mSieveConfigEditor = new SieveConfigEditor( tabWidget );
1130  mSieveConfigEditor->layout()->setMargin( KDialog::marginHint() );
1131  tabWidget->addTab( mSieveConfigEditor, i18n("&Filtering") );
1132 
1133  connect(kapp,TQ_SIGNAL(tdedisplayFontChanged()),TQ_SLOT(slotFontChanged()));
1134 }
1135 
1136 
1137 void AccountDialog::setupSettings()
1138 {
1139  TQComboBox *folderCombo = 0;
1140  int interval = mAccount->checkInterval();
1141 
1142  TQString accountType = mAccount->type();
1143  if( accountType == "local" )
1144  {
1145  ProcmailRCParser procmailrcParser;
1146  KMAcctLocal *acctLocal = dynamic_cast<KMAcctLocal*>(mAccount);
1147 
1148  if ( acctLocal->location().isEmpty() )
1149  acctLocal->setLocation( procmailrcParser.getSpoolFilesList().first() );
1150  else
1151  mLocal.locationEdit->insertItem( acctLocal->location() );
1152 
1153  if ( acctLocal->procmailLockFileName().isEmpty() )
1154  acctLocal->setProcmailLockFileName( procmailrcParser.getLockFilesList().first() );
1155  else
1156  mLocal.procmailLockFileName->insertItem( acctLocal->procmailLockFileName() );
1157 
1158  mLocal.nameEdit->setText( mAccount->name() );
1159  mLocal.nameEdit->setFocus();
1160  mLocal.locationEdit->setEditText( acctLocal->location() );
1161  if (acctLocal->lockType() == mutt_dotlock)
1162  mLocal.lockMutt->setChecked(true);
1163  else if (acctLocal->lockType() == mutt_dotlock_privileged)
1164  mLocal.lockMuttPriv->setChecked(true);
1165  else if (acctLocal->lockType() == procmail_lockfile) {
1166  mLocal.lockProcmail->setChecked(true);
1167  mLocal.procmailLockFileName->setEditText(acctLocal->procmailLockFileName());
1168  } else if (acctLocal->lockType() == FCNTL)
1169  mLocal.lockFcntl->setChecked(true);
1170  else if (acctLocal->lockType() == lock_none)
1171  mLocal.lockNone->setChecked(true);
1172 
1173  if ( interval <= 0 ) mLocal.intervalSpin->setValue( defaultmailcheckintervalmin );
1174  else mLocal.intervalSpin->setValue( interval );
1175  mLocal.intervalCheck->setChecked( interval >= 1 );
1176 #if 0
1177  mLocal.resourceCheck->setChecked( mAccount->resource() );
1178 #endif
1179  mLocal.includeInCheck->setChecked( !mAccount->checkExclude() );
1180  mLocal.precommand->setText( mAccount->precommand() );
1181 
1182  slotEnableLocalInterval( interval >= 1 );
1183  folderCombo = mLocal.folderCombo;
1184  mLocal.identityCombo-> setCurrentIdentity( mAccount->identityId() );
1185  }
1186  else if( accountType == "pop" )
1187  {
1188  PopAccount &ap = *(PopAccount*)mAccount;
1189  mPop.nameEdit->setText( mAccount->name() );
1190  mPop.nameEdit->setFocus();
1191  mPop.loginEdit->setText( ap.login() );
1192  mPop.passwordEdit->setText( ap.passwd());
1193  mPop.hostEdit->setText( ap.host() );
1194  mPop.portEdit->setText( TQString("%1").arg( ap.port() ) );
1195  mPop.usePipeliningCheck->setChecked( ap.usePipelining() );
1196  mPop.storePasswordCheck->setChecked( ap.storePasswd() );
1197  mPop.leaveOnServerCheck->setChecked( ap.leaveOnServer() );
1198  mPop.leaveOnServerDaysCheck->setEnabled( ap.leaveOnServer() );
1199  mPop.leaveOnServerDaysCheck->setChecked( ap.leaveOnServerDays() >= 1 );
1200  mPop.leaveOnServerDaysSpin->setValue( ap.leaveOnServerDays() >= 1 ?
1201  ap.leaveOnServerDays() : 7 );
1202  mPop.leaveOnServerCountCheck->setEnabled( ap.leaveOnServer() );
1203  mPop.leaveOnServerCountCheck->setChecked( ap.leaveOnServerCount() >= 1 );
1204  mPop.leaveOnServerCountSpin->setValue( ap.leaveOnServerCount() >= 1 ?
1205  ap.leaveOnServerCount() : 100 );
1206  mPop.leaveOnServerSizeCheck->setEnabled( ap.leaveOnServer() );
1207  mPop.leaveOnServerSizeCheck->setChecked( ap.leaveOnServerSize() >= 1 );
1208  mPop.leaveOnServerSizeSpin->setValue( ap.leaveOnServerSize() >= 1 ?
1209  ap.leaveOnServerSize() : 10 );
1210  mPop.filterOnServerCheck->setChecked( ap.filterOnServer() );
1211  mPop.filterOnServerSizeSpin->setValue( ap.filterOnServerCheckSize() );
1212  mPop.intervalCheck->setChecked( interval >= 1 );
1213  if ( interval <= 0 ) mPop.intervalSpin->setValue( defaultmailcheckintervalmin );
1214  else mPop.intervalSpin->setValue( interval );
1215 #if 0
1216  mPop.resourceCheck->setChecked( mAccount->resource() );
1217 #endif
1218  mPop.includeInCheck->setChecked( !mAccount->checkExclude() );
1219  mPop.precommand->setText( ap.precommand() );
1220  mPop.identityCombo-> setCurrentIdentity( mAccount->identityId() );
1221  if (ap.useSSL())
1222  mPop.encryptionSSL->setChecked( true );
1223  else if (ap.useTLS())
1224  mPop.encryptionTLS->setChecked( true );
1225  else mPop.encryptionNone->setChecked( true );
1226  if (ap.auth() == "LOGIN")
1227  mPop.authLogin->setChecked( true );
1228  else if (ap.auth() == "PLAIN")
1229  mPop.authPlain->setChecked( true );
1230  else if (ap.auth() == "CRAM-MD5")
1231  mPop.authCRAM_MD5->setChecked( true );
1232  else if (ap.auth() == "DIGEST-MD5")
1233  mPop.authDigestMd5->setChecked( true );
1234  else if (ap.auth() == "NTLM")
1235  mPop.authNTLM->setChecked( true );
1236  else if (ap.auth() == "GSSAPI")
1237  mPop.authGSSAPI->setChecked( true );
1238  else if (ap.auth() == "APOP")
1239  mPop.authAPOP->setChecked( true );
1240  else mPop.authUser->setChecked( true );
1241 
1242  slotEnableLeaveOnServerDays( mPop.leaveOnServerDaysCheck->isEnabled() ?
1243  ap.leaveOnServerDays() >= 1 : 0);
1244  slotEnableLeaveOnServerCount( mPop.leaveOnServerCountCheck->isEnabled() ?
1245  ap.leaveOnServerCount() >= 1 : 0);
1246  slotEnableLeaveOnServerSize( mPop.leaveOnServerSizeCheck->isEnabled() ?
1247  ap.leaveOnServerSize() >= 1 : 0);
1248  slotEnablePopInterval( interval >= 1 );
1249  folderCombo = mPop.folderCombo;
1250  }
1251  else if( accountType == "imap" )
1252  {
1253  KMAcctImap &ai = *(KMAcctImap*)mAccount;
1254  mImap.nameEdit->setText( mAccount->name() );
1255  mImap.nameEdit->setFocus();
1256  mImap.loginEdit->setText( ai.login() );
1257  mImap.passwordEdit->setText( ai.passwd());
1258  mImap.hostEdit->setText( ai.host() );
1259  mImap.portEdit->setText( TQString("%1").arg( ai.port() ) );
1260  mImap.autoExpungeCheck->setChecked( ai.autoExpunge() );
1261  mImap.hiddenFoldersCheck->setChecked( ai.hiddenFolders() );
1262  mImap.subscribedFoldersCheck->setChecked( ai.onlySubscribedFolders() );
1263  mImap.locallySubscribedFoldersCheck->setChecked( ai.onlyLocallySubscribedFolders() );
1264  mImap.loadOnDemandCheck->setChecked( ai.loadOnDemand() );
1265  mImap.listOnlyOpenCheck->setChecked( ai.listOnlyOpenFolders() );
1266  mImap.storePasswordCheck->setChecked( ai.storePasswd() );
1267 #if 0
1268  mImap.resourceCheck->setChecked( ai.resource() );
1269 #endif
1270  mImap.includeInCheck->setChecked( !ai.checkExclude() );
1271  mImap.intervalCheck->setChecked( interval >= 1 );
1272  if ( interval <= 0 ) mImap.intervalSpin->setValue( defaultmailcheckintervalmin );
1273  else mImap.intervalSpin->setValue( interval );
1274  TQString trashfolder = ai.trash();
1275  if (trashfolder.isEmpty())
1276  trashfolder = kmkernel->trashFolder()->idString();
1277  mImap.trashCombo->setFolder( trashfolder );
1278  slotEnableImapInterval( interval >= 1 );
1279  mImap.identityCombo-> setCurrentIdentity( mAccount->identityId() );
1280  //mImap.identityCombo->insertStringList( kmkernel->identityManager()->shadowIdentities() );
1281  if (ai.useSSL())
1282  mImap.encryptionSSL->setChecked( true );
1283  else if (ai.useTLS())
1284  mImap.encryptionTLS->setChecked( true );
1285  else mImap.encryptionNone->setChecked( true );
1286  if (ai.auth() == "CRAM-MD5")
1287  mImap.authCramMd5->setChecked( true );
1288  else if (ai.auth() == "DIGEST-MD5")
1289  mImap.authDigestMd5->setChecked( true );
1290  else if (ai.auth() == "NTLM")
1291  mImap.authNTLM->setChecked( true );
1292  else if (ai.auth() == "GSSAPI")
1293  mImap.authGSSAPI->setChecked( true );
1294  else if (ai.auth() == "ANONYMOUS")
1295  mImap.authAnonymous->setChecked( true );
1296  else if (ai.auth() == "PLAIN")
1297  mImap.authPlain->setChecked( true );
1298  else if (ai.auth() == "LOGIN")
1299  mImap.authLogin->setChecked( true );
1300  else mImap.authUser->setChecked( true );
1301  if ( mSieveConfigEditor )
1302  mSieveConfigEditor->setConfig( ai.sieveConfig() );
1303  }
1304  else if( accountType == "cachedimap" )
1305  {
1306  KMAcctCachedImap &ai = *(KMAcctCachedImap*)mAccount;
1307  mImap.nameEdit->setText( mAccount->name() );
1308  mImap.nameEdit->setFocus();
1309  mImap.loginEdit->setText( ai.login() );
1310  mImap.passwordEdit->setText( ai.passwd());
1311  mImap.hostEdit->setText( ai.host() );
1312  mImap.portEdit->setText( TQString("%1").arg( ai.port() ) );
1313 #if 0
1314  mImap.resourceCheck->setChecked( ai.resource() );
1315 #endif
1316  mImap.hiddenFoldersCheck->setChecked( ai.hiddenFolders() );
1317  mImap.subscribedFoldersCheck->setChecked( ai.onlySubscribedFolders() );
1318  mImap.locallySubscribedFoldersCheck->setChecked( ai.onlyLocallySubscribedFolders() );
1319  mImap.storePasswordCheck->setChecked( ai.storePasswd() );
1320  mImap.intervalCheck->setChecked( interval >= 1 );
1321  if ( interval <= 0 ) mImap.intervalSpin->setValue( defaultmailcheckintervalmin );
1322  else mImap.intervalSpin->setValue( interval );
1323  mImap.includeInCheck->setChecked( !ai.checkExclude() );
1324  TQString trashfolder = ai.trash();
1325  if (trashfolder.isEmpty())
1326  trashfolder = kmkernel->trashFolder()->idString();
1327  mImap.trashCombo->setFolder( trashfolder );
1328  slotEnableImapInterval( interval >= 1 );
1329  mImap.identityCombo-> setCurrentIdentity( mAccount->identityId() );
1330  //mImap.identityCombo->insertStringList( kmkernel->identityManager()->shadowIdentities() );
1331  if (ai.useSSL())
1332  mImap.encryptionSSL->setChecked( true );
1333  else if (ai.useTLS())
1334  mImap.encryptionTLS->setChecked( true );
1335  else mImap.encryptionNone->setChecked( true );
1336  if (ai.auth() == "CRAM-MD5")
1337  mImap.authCramMd5->setChecked( true );
1338  else if (ai.auth() == "DIGEST-MD5")
1339  mImap.authDigestMd5->setChecked( true );
1340  else if (ai.auth() == "GSSAPI")
1341  mImap.authGSSAPI->setChecked( true );
1342  else if (ai.auth() == "NTLM")
1343  mImap.authNTLM->setChecked( true );
1344  else if (ai.auth() == "ANONYMOUS")
1345  mImap.authAnonymous->setChecked( true );
1346  else if (ai.auth() == "PLAIN")
1347  mImap.authPlain->setChecked( true );
1348  else if (ai.auth() == "LOGIN")
1349  mImap.authLogin->setChecked( true );
1350  else mImap.authUser->setChecked( true );
1351  if ( mSieveConfigEditor )
1352  mSieveConfigEditor->setConfig( ai.sieveConfig() );
1353  }
1354  else if( accountType == "maildir" )
1355  {
1356  KMAcctMaildir *acctMaildir = dynamic_cast<KMAcctMaildir*>(mAccount);
1357 
1358  mMaildir.nameEdit->setText( mAccount->name() );
1359  mMaildir.nameEdit->setFocus();
1360  mMaildir.locationEdit->setEditText( acctMaildir->location() );
1361 
1362  if ( interval <= 0 ) mMaildir.intervalSpin->setValue( defaultmailcheckintervalmin );
1363  else mMaildir.intervalSpin->setValue( interval );
1364  mMaildir.intervalCheck->setChecked( interval >= 1 );
1365 #if 0
1366  mMaildir.resourceCheck->setChecked( mAccount->resource() );
1367 #endif
1368  mMaildir.includeInCheck->setChecked( !mAccount->checkExclude() );
1369  mMaildir.precommand->setText( mAccount->precommand() );
1370  mMaildir.identityCombo-> setCurrentIdentity( mAccount->identityId() );
1371  slotEnableMaildirInterval( interval >= 1 );
1372  folderCombo = mMaildir.folderCombo;
1373  }
1374  else // Unknown account type
1375  return;
1376 
1377  if ( accountType == "imap" || accountType == "cachedimap" )
1378  {
1379  // settings for imap in general
1380  ImapAccountBase &ai = *(ImapAccountBase*)mAccount;
1381  // namespaces
1382  if ( ( ai.namespaces().isEmpty() || ai.namespaceToDelimiter().isEmpty() ) &&
1383  !ai.login().isEmpty() && !ai.passwd().isEmpty() && !ai.host().isEmpty() )
1384  {
1385  slotReloadNamespaces();
1386  } else {
1387  slotSetupNamespaces( ai.namespacesWithDelimiter() );
1388  }
1389  }
1390 
1391  if (!folderCombo) return;
1392 
1393  KMFolderDir *fdir = (KMFolderDir*)&kmkernel->folderMgr()->dir();
1394  KMFolder *acctFolder = mAccount->folder();
1395  if( acctFolder == 0 )
1396  {
1397  acctFolder = (KMFolder*)fdir->first();
1398  }
1399  if( acctFolder == 0 )
1400  {
1401  folderCombo->insertItem( i18n("<none>") );
1402  }
1403  else
1404  {
1405  uint i = 0;
1406  int curIndex = -1;
1407  kmkernel->folderMgr()->createI18nFolderList(&mFolderNames, &mFolderList);
1408  while (i < mFolderNames.count())
1409  {
1410  TQValueList<TQGuardedPtr<KMFolder> >::Iterator it = mFolderList.at(i);
1411  KMFolder *folder = *it;
1412  if (folder->isSystemFolder())
1413  {
1414  mFolderList.remove(it);
1415  mFolderNames.remove(mFolderNames.at(i));
1416  } else {
1417  if (folder == acctFolder) curIndex = i;
1418  i++;
1419  }
1420  }
1421  mFolderNames.prepend(i18n("inbox"));
1422  mFolderList.prepend(kmkernel->inboxFolder());
1423  folderCombo->insertStringList(mFolderNames);
1424  folderCombo->setCurrentItem(curIndex + 1);
1425 
1426  // -sanders hack for startup users. Must investigate this properly
1427  if (folderCombo->count() == 0)
1428  folderCombo->insertItem( i18n("inbox") );
1429  }
1430 }
1431 
1432 void AccountDialog::slotLeaveOnServerClicked()
1433 {
1434  bool state = mPop.leaveOnServerCheck->isChecked();
1435  mPop.leaveOnServerDaysCheck->setEnabled( state );
1436  mPop.leaveOnServerCountCheck->setEnabled( state );
1437  mPop.leaveOnServerSizeCheck->setEnabled( state );
1438  if ( state ) {
1439  if ( mPop.leaveOnServerDaysCheck->isChecked() ) {
1440  slotEnableLeaveOnServerDays( state );
1441  }
1442  if ( mPop.leaveOnServerCountCheck->isChecked() ) {
1443  slotEnableLeaveOnServerCount( state );
1444  }
1445  if ( mPop.leaveOnServerSizeCheck->isChecked() ) {
1446  slotEnableLeaveOnServerSize( state );
1447  }
1448  } else {
1449  slotEnableLeaveOnServerDays( state );
1450  slotEnableLeaveOnServerCount( state );
1451  slotEnableLeaveOnServerSize( state );
1452  }
1453  if ( !( mCurCapa & UIDL ) && mPop.leaveOnServerCheck->isChecked() ) {
1454  KMessageBox::information( topLevelWidget(),
1455  i18n("The server does not seem to support unique "
1456  "message numbers, but this is a "
1457  "requirement for leaving messages on the "
1458  "server.\n"
1459  "Since some servers do not correctly "
1460  "announce their capabilities you still "
1461  "have the possibility to turn leaving "
1462  "fetched messages on the server on.") );
1463  }
1464 }
1465 
1466 void AccountDialog::slotFilterOnServerClicked()
1467 {
1468  if ( !( mCurCapa & TOP ) && mPop.filterOnServerCheck->isChecked() ) {
1469  KMessageBox::information( topLevelWidget(),
1470  i18n("The server does not seem to support "
1471  "fetching message headers, but this is a "
1472  "requirement for filtering messages on the "
1473  "server.\n"
1474  "Since some servers do not correctly "
1475  "announce their capabilities you still "
1476  "have the possibility to turn filtering "
1477  "messages on the server on.") );
1478  }
1479 }
1480 
1481 void AccountDialog::slotPipeliningClicked()
1482 {
1483  if (mPop.usePipeliningCheck->isChecked())
1484  KMessageBox::information( topLevelWidget(),
1485  i18n("Please note that this feature can cause some POP3 servers "
1486  "that do not support pipelining to send corrupted mail;\n"
1487  "this is configurable, though, because some servers support pipelining "
1488  "but do not announce their capabilities. To check whether your POP3 server "
1489  "announces pipelining support use the \"Check What the Server "
1490  "Supports\" button at the bottom of the dialog;\n"
1491  "if your server does not announce it, but you want more speed, then "
1492  "you should do some testing first by sending yourself a batch "
1493  "of mail and downloading it."), TQString(),
1494  "pipelining");
1495 }
1496 
1497 
1498 void AccountDialog::slotPopEncryptionChanged(int id)
1499 {
1500  kdDebug(5006) << "slotPopEncryptionChanged( " << id << " )" << endl;
1501  // adjust port
1502  if ( id == SSL || mPop.portEdit->text() == "995" )
1503  mPop.portEdit->setText( ( id == SSL ) ? "995" : "110" );
1504 
1505  // switch supported auth methods
1506  mCurCapa = ( id == TLS ) ? mCapaTLS
1507  : ( id == SSL ) ? mCapaSSL
1508  : mCapaNormal;
1509  enablePopFeatures( mCurCapa );
1510  const TQButton *old = mPop.authGroup->selected();
1511  if ( !old->isEnabled() )
1512  checkHighest( mPop.authGroup );
1513 }
1514 
1515 
1516 void AccountDialog::slotImapEncryptionChanged(int id)
1517 {
1518  kdDebug(5006) << "slotImapEncryptionChanged( " << id << " )" << endl;
1519  // adjust port
1520  if ( id == SSL || mImap.portEdit->text() == "993" )
1521  mImap.portEdit->setText( ( id == SSL ) ? "993" : "143" );
1522 
1523  // switch supported auth methods
1524  int authMethods = ( id == TLS ) ? mCapaTLS
1525  : ( id == SSL ) ? mCapaSSL
1526  : mCapaNormal;
1527  enableImapAuthMethods( authMethods );
1528  TQButton *old = mImap.authGroup->selected();
1529  if ( !old->isEnabled() )
1530  checkHighest( mImap.authGroup );
1531 }
1532 
1533 
1534 void AccountDialog::slotCheckPopCapabilities()
1535 {
1536  if ( mPop.hostEdit->text().isEmpty() || mPop.portEdit->text().isEmpty() )
1537  {
1538  KMessageBox::sorry( this, i18n( "Please specify a server and port on "
1539  "the General tab first." ) );
1540  return;
1541  }
1542  delete mServerTest;
1543  mServerTest = new KMServerTest(POP_PROTOCOL, mPop.hostEdit->text(),
1544  mPop.portEdit->text().toInt());
1545  connect( mServerTest, TQ_SIGNAL( capabilities( const TQStringList &,
1546  const TQStringList & ) ),
1547  this, TQ_SLOT( slotPopCapabilities( const TQStringList &,
1548  const TQStringList & ) ) );
1549  mPop.checkCapabilities->setEnabled(false);
1550 }
1551 
1552 
1553 void AccountDialog::slotCheckImapCapabilities()
1554 {
1555  if ( mImap.hostEdit->text().isEmpty() || mImap.portEdit->text().isEmpty() )
1556  {
1557  KMessageBox::sorry( this, i18n( "Please specify a server and port on "
1558  "the General tab first." ) );
1559  return;
1560  }
1561  delete mServerTest;
1562  mServerTest = new KMServerTest(IMAP_PROTOCOL, mImap.hostEdit->text(),
1563  mImap.portEdit->text().toInt());
1564  connect( mServerTest, TQ_SIGNAL( capabilities( const TQStringList &,
1565  const TQStringList & ) ),
1566  this, TQ_SLOT( slotImapCapabilities( const TQStringList &,
1567  const TQStringList & ) ) );
1568  mImap.checkCapabilities->setEnabled(false);
1569 }
1570 
1571 
1572 unsigned int AccountDialog::popCapabilitiesFromStringList( const TQStringList & l )
1573 {
1574  unsigned int capa = 0;
1575  kdDebug( 5006 ) << k_funcinfo << l << endl;
1576  for ( TQStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) {
1577  TQString cur = (*it).upper();
1578  if ( cur == "PLAIN" )
1579  capa |= Plain;
1580  else if ( cur == "LOGIN" )
1581  capa |= Login;
1582  else if ( cur == "CRAM-MD5" )
1583  capa |= CRAM_MD5;
1584  else if ( cur == "DIGEST-MD5" )
1585  capa |= Digest_MD5;
1586  else if ( cur == "NTLM" )
1587  capa |= NTLM;
1588  else if ( cur == "GSSAPI" )
1589  capa |= GSSAPI;
1590  else if ( cur == "APOP" )
1591  capa |= APOP;
1592  else if ( cur == "PIPELINING" )
1593  capa |= Pipelining;
1594  else if ( cur == "TOP" )
1595  capa |= TOP;
1596  else if ( cur == "UIDL" )
1597  capa |= UIDL;
1598  else if ( cur == "STLS" )
1599  capa |= STLS;
1600  }
1601  return capa;
1602 }
1603 
1604 
1605 void AccountDialog::slotPopCapabilities( const TQStringList & capaNormal,
1606  const TQStringList & capaSSL )
1607 {
1608  mPop.checkCapabilities->setEnabled( true );
1609  mCapaNormal = popCapabilitiesFromStringList( capaNormal );
1610  if ( mCapaNormal & STLS )
1611  mCapaTLS = mCapaNormal;
1612  else
1613  mCapaTLS = 0;
1614  mCapaSSL = popCapabilitiesFromStringList( capaSSL );
1615  kdDebug(5006) << "mCapaNormal = " << mCapaNormal
1616  << "; mCapaSSL = " << mCapaSSL
1617  << "; mCapaTLS = " << mCapaTLS << endl;
1618  mPop.encryptionNone->setEnabled( !capaNormal.isEmpty() );
1619  mPop.encryptionSSL->setEnabled( !capaSSL.isEmpty() );
1620  mPop.encryptionTLS->setEnabled( mCapaTLS != 0 );
1621  checkHighest( mPop.encryptionGroup );
1622  delete mServerTest;
1623  mServerTest = 0;
1624 }
1625 
1626 
1627 void AccountDialog::enablePopFeatures( unsigned int capa )
1628 {
1629  kdDebug(5006) << "enablePopFeatures( " << capa << " )" << endl;
1630  mPop.authPlain->setEnabled( capa & Plain );
1631  mPop.authLogin->setEnabled( capa & Login );
1632  mPop.authCRAM_MD5->setEnabled( capa & CRAM_MD5 );
1633  mPop.authDigestMd5->setEnabled( capa & Digest_MD5 );
1634  mPop.authNTLM->setEnabled( capa & NTLM );
1635  mPop.authGSSAPI->setEnabled( capa & GSSAPI );
1636  mPop.authAPOP->setEnabled( capa & APOP );
1637  if ( !( capa & Pipelining ) && mPop.usePipeliningCheck->isChecked() ) {
1638  mPop.usePipeliningCheck->setChecked( false );
1639  KMessageBox::information( topLevelWidget(),
1640  i18n("The server does not seem to support "
1641  "pipelining; therefore, this option has "
1642  "been disabled.\n"
1643  "Since some servers do not correctly "
1644  "announce their capabilities you still "
1645  "have the possibility to turn pipelining "
1646  "on. But please note that this feature can "
1647  "cause some POP servers that do not "
1648  "support pipelining to send corrupt "
1649  "messages. So before using this feature "
1650  "with important mail you should first "
1651  "test it by sending yourself a larger "
1652  "number of test messages which you all "
1653  "download in one go from the POP "
1654  "server.") );
1655  }
1656  if ( !( capa & UIDL ) && mPop.leaveOnServerCheck->isChecked() ) {
1657  mPop.leaveOnServerCheck->setChecked( false );
1658  KMessageBox::information( topLevelWidget(),
1659  i18n("The server does not seem to support unique "
1660  "message numbers, but this is a "
1661  "requirement for leaving messages on the "
1662  "server; therefore, this option has been "
1663  "disabled.\n"
1664  "Since some servers do not correctly "
1665  "announce their capabilities you still "
1666  "have the possibility to turn leaving "
1667  "fetched messages on the server on.") );
1668  }
1669  if ( !( capa & TOP ) && mPop.filterOnServerCheck->isChecked() ) {
1670  mPop.filterOnServerCheck->setChecked( false );
1671  KMessageBox::information( topLevelWidget(),
1672  i18n("The server does not seem to support "
1673  "fetching message headers, but this is a "
1674  "requirement for filtering messages on the "
1675  "server; therefore, this option has been "
1676  "disabled.\n"
1677  "Since some servers do not correctly "
1678  "announce their capabilities you still "
1679  "have the possibility to turn filtering "
1680  "messages on the server on.") );
1681  }
1682 }
1683 
1684 
1685 unsigned int AccountDialog::imapCapabilitiesFromStringList( const TQStringList & l )
1686 {
1687  unsigned int capa = 0;
1688  for ( TQStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) {
1689  TQString cur = (*it).upper();
1690  if ( cur == "AUTH=PLAIN" )
1691  capa |= Plain;
1692  else if ( cur == "AUTH=LOGIN" )
1693  capa |= Login;
1694  else if ( cur == "AUTH=CRAM-MD5" )
1695  capa |= CRAM_MD5;
1696  else if ( cur == "AUTH=DIGEST-MD5" )
1697  capa |= Digest_MD5;
1698  else if ( cur == "AUTH=NTLM" )
1699  capa |= NTLM;
1700  else if ( cur == "AUTH=GSSAPI" )
1701  capa |= GSSAPI;
1702  else if ( cur == "AUTH=ANONYMOUS" )
1703  capa |= Anonymous;
1704  else if ( cur == "STARTTLS" )
1705  capa |= STARTTLS;
1706  }
1707  return capa;
1708 }
1709 
1710 
1711 void AccountDialog::slotImapCapabilities( const TQStringList & capaNormal,
1712  const TQStringList & capaSSL )
1713 {
1714  mImap.checkCapabilities->setEnabled( true );
1715  mCapaNormal = imapCapabilitiesFromStringList( capaNormal );
1716  if ( mCapaNormal & STARTTLS )
1717  mCapaTLS = mCapaNormal;
1718  else
1719  mCapaTLS = 0;
1720  mCapaSSL = imapCapabilitiesFromStringList( capaSSL );
1721  kdDebug(5006) << "mCapaNormal = " << mCapaNormal
1722  << "; mCapaSSL = " << mCapaSSL
1723  << "; mCapaTLS = " << mCapaTLS << endl;
1724  mImap.encryptionNone->setEnabled( !capaNormal.isEmpty() );
1725  mImap.encryptionSSL->setEnabled( !capaSSL.isEmpty() );
1726  mImap.encryptionTLS->setEnabled( mCapaTLS != 0 );
1727  checkHighest( mImap.encryptionGroup );
1728  delete mServerTest;
1729  mServerTest = 0;
1730 }
1731 
1732 void AccountDialog::slotLeaveOnServerDaysChanged ( int value )
1733 {
1734  mPop.leaveOnServerDaysSpin->setSuffix( i18n(" day", " days", value) );
1735 }
1736 
1737 
1738 void AccountDialog::slotLeaveOnServerCountChanged ( int value )
1739 {
1740  mPop.leaveOnServerCountSpin->setSuffix( i18n(" message", " messages", value) );
1741 }
1742 
1743 
1744 void AccountDialog::slotFilterOnServerSizeChanged ( int value )
1745 {
1746  mPop.filterOnServerSizeSpin->setSuffix( i18n(" byte", " bytes", value) );
1747 }
1748 
1749 
1750 void AccountDialog::enableImapAuthMethods( unsigned int capa )
1751 {
1752  kdDebug(5006) << "enableImapAuthMethods( " << capa << " )" << endl;
1753  mImap.authPlain->setEnabled( capa & Plain );
1754  mImap.authLogin->setEnabled( capa & Login );
1755  mImap.authCramMd5->setEnabled( capa & CRAM_MD5 );
1756  mImap.authDigestMd5->setEnabled( capa & Digest_MD5 );
1757  mImap.authNTLM->setEnabled( capa & NTLM );
1758  mImap.authGSSAPI->setEnabled( capa & GSSAPI );
1759  mImap.authAnonymous->setEnabled( capa & Anonymous );
1760 }
1761 
1762 
1763 void AccountDialog::checkHighest( TQButtonGroup *btnGroup )
1764 {
1765  kdDebug(5006) << "checkHighest( " << btnGroup << " )" << endl;
1766  for ( int i = btnGroup->count() - 1; i >= 0 ; --i ) {
1767  TQButton * btn = btnGroup->find( i );
1768  if ( btn && btn->isEnabled() ) {
1769  btn->animateClick();
1770  return;
1771  }
1772  }
1773 }
1774 
1775 
1776 void AccountDialog::slotOk()
1777 {
1778  saveSettings();
1779  accept();
1780 }
1781 
1782 
1783 void AccountDialog::saveSettings()
1784 {
1785  TQString accountType = mAccount->type();
1786  if( accountType == "local" )
1787  {
1788  KMAcctLocal *acctLocal = dynamic_cast<KMAcctLocal*>(mAccount);
1789 
1790  if (acctLocal) {
1791  mAccount->setName( mLocal.nameEdit->text() );
1792  acctLocal->setLocation( mLocal.locationEdit->currentText() );
1793  if (mLocal.lockMutt->isChecked())
1794  acctLocal->setLockType(mutt_dotlock);
1795  else if (mLocal.lockMuttPriv->isChecked())
1796  acctLocal->setLockType(mutt_dotlock_privileged);
1797  else if (mLocal.lockProcmail->isChecked()) {
1798  acctLocal->setLockType(procmail_lockfile);
1799  acctLocal->setProcmailLockFileName(mLocal.procmailLockFileName->currentText());
1800  }
1801  else if (mLocal.lockNone->isChecked())
1802  acctLocal->setLockType(lock_none);
1803  else acctLocal->setLockType(FCNTL);
1804  }
1805 
1806  mAccount->setCheckInterval( mLocal.intervalCheck->isChecked() ?
1807  mLocal.intervalSpin->value() : 0 );
1808 #if 0
1809  mAccount->setResource( mLocal.resourceCheck->isChecked() );
1810 #endif
1811  mAccount->setCheckExclude( !mLocal.includeInCheck->isChecked() );
1812 
1813  mAccount->setPrecommand( mLocal.precommand->text() );
1814 
1815  mAccount->setFolder( *mFolderList.at(mLocal.folderCombo->currentItem()) );
1816 
1817  mAccount->setIdentityId( mLocal.identityCombo->currentIdentity() );
1818 
1819  }
1820  else if( accountType == "pop" )
1821  {
1822  mAccount->setName( mPop.nameEdit->text() );
1823  mAccount->setCheckInterval( mPop.intervalCheck->isChecked() ?
1824  mPop.intervalSpin->value() : 0 );
1825 #if 0
1826  mAccount->setResource( mPop.resourceCheck->isChecked() );
1827 #endif
1828  mAccount->setCheckExclude( !mPop.includeInCheck->isChecked() );
1829 
1830  mAccount->setFolder( *mFolderList.at(mPop.folderCombo->currentItem()) );
1831 
1832  mAccount->setIdentityId( mPop.identityCombo->currentIdentity() );
1833 
1834  initAccountForConnect();
1835  PopAccount &epa = *(PopAccount*)mAccount;
1836  epa.setUsePipelining( mPop.usePipeliningCheck->isChecked() );
1837  epa.setLeaveOnServer( mPop.leaveOnServerCheck->isChecked() );
1838  epa.setLeaveOnServerDays( mPop.leaveOnServerCheck->isChecked() ?
1839  ( mPop.leaveOnServerDaysCheck->isChecked() ?
1840  mPop.leaveOnServerDaysSpin->value() : -1 ) : 0);
1841  epa.setLeaveOnServerCount( mPop.leaveOnServerCheck->isChecked() ?
1842  ( mPop.leaveOnServerCountCheck->isChecked() ?
1843  mPop.leaveOnServerCountSpin->value() : -1 ) : 0 );
1844  epa.setLeaveOnServerSize( mPop.leaveOnServerCheck->isChecked() ?
1845  ( mPop.leaveOnServerSizeCheck->isChecked() ?
1846  mPop.leaveOnServerSizeSpin->value() : -1 ) : 0 );
1847  epa.setFilterOnServer( mPop.filterOnServerCheck->isChecked() );
1848  epa.setFilterOnServerCheckSize (mPop.filterOnServerSizeSpin->value() );
1849  epa.setPrecommand( mPop.precommand->text() );
1850 
1851  }
1852  else if( accountType == "imap" )
1853  {
1854  mAccount->setName( mImap.nameEdit->text() );
1855  mAccount->setCheckInterval( mImap.intervalCheck->isChecked() ?
1856  mImap.intervalSpin->value() : 0 );
1857  mAccount->setIdentityId( mImap.identityCombo->currentIdentity() );
1858 
1859 #if 0
1860  mAccount->setResource( mImap.resourceCheck->isChecked() );
1861 #endif
1862  mAccount->setCheckExclude( !mImap.includeInCheck->isChecked() );
1863  mAccount->setFolder( kmkernel->imapFolderMgr()->findById(mAccount->id()) );
1864 
1865  initAccountForConnect();
1866  KMAcctImap &epa = *(KMAcctImap*)mAccount;
1867  epa.setAutoExpunge( mImap.autoExpungeCheck->isChecked() );
1868  epa.setHiddenFolders( mImap.hiddenFoldersCheck->isChecked() );
1869  epa.setOnlySubscribedFolders( mImap.subscribedFoldersCheck->isChecked() );
1870  epa.setOnlyLocallySubscribedFolders( mImap.locallySubscribedFoldersCheck->isChecked() );
1871  epa.setLoadOnDemand( mImap.loadOnDemandCheck->isChecked() );
1872  epa.setListOnlyOpenFolders( mImap.listOnlyOpenCheck->isChecked() );
1873  KMFolder *t = mImap.trashCombo->folder();
1874  if ( t )
1875  epa.setTrash( mImap.trashCombo->folder()->idString() );
1876  else
1877  epa.setTrash( kmkernel->trashFolder()->idString() );
1878 #if 0
1879  epa.setResource( mImap.resourceCheck->isChecked() );
1880 #endif
1881  epa.setCheckExclude( !mImap.includeInCheck->isChecked() );
1882  if ( mSieveConfigEditor )
1883  epa.setSieveConfig( mSieveConfigEditor->config() );
1884  }
1885  else if( accountType == "cachedimap" )
1886  {
1887  mAccount->setName( mImap.nameEdit->text() );
1888  mAccount->setCheckInterval( mImap.intervalCheck->isChecked() ?
1889  mImap.intervalSpin->value() : 0 );
1890  mAccount->setIdentityId( mImap.identityCombo->currentIdentity() );
1891 
1892 #if 0
1893  mAccount->setResource( mImap.resourceCheck->isChecked() );
1894 #endif
1895  mAccount->setCheckExclude( !mImap.includeInCheck->isChecked() );
1896  //mAccount->setFolder( NULL );
1897  mAccount->setFolder( kmkernel->dimapFolderMgr()->findById(mAccount->id()) );
1898  //kdDebug(5006) << "account for folder " << mAccount->folder()->name() << endl;
1899 
1900  initAccountForConnect();
1901  KMAcctCachedImap &epa = *(KMAcctCachedImap*)mAccount;
1902  epa.setHiddenFolders( mImap.hiddenFoldersCheck->isChecked() );
1903  epa.setOnlySubscribedFolders( mImap.subscribedFoldersCheck->isChecked() );
1904  epa.setOnlyLocallySubscribedFolders( mImap.locallySubscribedFoldersCheck->isChecked() );
1905  epa.setStorePasswd( mImap.storePasswordCheck->isChecked() );
1906  epa.setPasswd( mImap.passwordEdit->text(), epa.storePasswd() );
1907  KMFolder *t = mImap.trashCombo->folder();
1908  if ( t )
1909  epa.setTrash( mImap.trashCombo->folder()->idString() );
1910  else
1911  epa.setTrash( kmkernel->trashFolder()->idString() );
1912 #if 0
1913  epa.setResource( mImap.resourceCheck->isChecked() );
1914 #endif
1915  epa.setCheckExclude( !mImap.includeInCheck->isChecked() );
1916  if ( mSieveConfigEditor )
1917  epa.setSieveConfig( mSieveConfigEditor->config() );
1918  }
1919  else if( accountType == "maildir" )
1920  {
1921  KMAcctMaildir *acctMaildir = dynamic_cast<KMAcctMaildir*>(mAccount);
1922 
1923  if (acctMaildir) {
1924  mAccount->setName( mMaildir.nameEdit->text() );
1925  acctMaildir->setLocation( mMaildir.locationEdit->currentText() );
1926 
1927  KMFolder *targetFolder = *mFolderList.at(mMaildir.folderCombo->currentItem());
1928  if ( targetFolder->location() == acctMaildir->location() ) {
1929  /*
1930  Prevent data loss if the user sets the destination folder to be the same as the
1931  source account maildir folder by setting the target folder to the inbox.
1932  ### FIXME post 3.2: show dialog and let the user chose another target folder
1933  */
1934  targetFolder = kmkernel->inboxFolder();
1935  }
1936  mAccount->setFolder( targetFolder );
1937  }
1938  mAccount->setCheckInterval( mMaildir.intervalCheck->isChecked() ?
1939  mMaildir.intervalSpin->value() : 0 );
1940 #if 0
1941  mAccount->setResource( mMaildir.resourceCheck->isChecked() );
1942 #endif
1943  mAccount->setCheckExclude( !mMaildir.includeInCheck->isChecked() );
1944 
1945  mAccount->setPrecommand( mMaildir.precommand->text() );
1946 
1947  mAccount->setIdentityId( mMaildir.identityCombo->currentIdentity() );
1948  }
1949 
1950  if ( accountType == "imap" || accountType == "cachedimap" )
1951  {
1952  // settings for imap in general
1953  ImapAccountBase &ai = *(ImapAccountBase*)mAccount;
1954  // namespace
1955  ImapAccountBase::nsMap map;
1956  ImapAccountBase::namespaceDelim delimMap;
1957  ImapAccountBase::nsDelimMap::Iterator it;
1958  ImapAccountBase::namespaceDelim::Iterator it2;
1959  for ( it = mImap.nsMap.begin(); it != mImap.nsMap.end(); ++it ) {
1960  TQStringList list;
1961  for ( it2 = it.data().begin(); it2 != it.data().end(); ++it2 ) {
1962  list << it2.key();
1963  delimMap[it2.key()] = it2.data();
1964  }
1965  map[it.key()] = list;
1966  }
1967  ai.setNamespaces( map );
1968  ai.setNamespaceToDelimiter( delimMap );
1969  }
1970 
1971  kmkernel->acctMgr()->writeConfig( true );
1972  // get the new account and register the new destination folder
1973  // this is the target folder for local or pop accounts and the root folder
1974  // of the account for (d)imap
1975  KMAccount* newAcct = kmkernel->acctMgr()->find(mAccount->id());
1976  if (newAcct)
1977  {
1978  if( accountType == "local" ) {
1979  newAcct->setFolder( *mFolderList.at(mLocal.folderCombo->currentItem()), true );
1980  } else if ( accountType == "pop" ) {
1981  newAcct->setFolder( *mFolderList.at(mPop.folderCombo->currentItem()), true );
1982  } else if ( accountType == "maildir" ) {
1983  newAcct->setFolder( *mFolderList.at(mMaildir.folderCombo->currentItem()), true );
1984  } else if ( accountType == "imap" ) {
1985  newAcct->setFolder( kmkernel->imapFolderMgr()->findById(mAccount->id()), true );
1986  } else if ( accountType == "cachedimap" ) {
1987  newAcct->setFolder( kmkernel->dimapFolderMgr()->findById(mAccount->id()), true );
1988  }
1989  }
1990 }
1991 
1992 
1993 void AccountDialog::slotLocationChooser()
1994 {
1995  static TQString directory( "/" );
1996 
1997  KFileDialog dialog( directory, TQString(), this, 0, true );
1998  dialog.setCaption( i18n("Choose Location") );
1999 
2000  bool result = dialog.exec();
2001  if( result == false )
2002  {
2003  return;
2004  }
2005 
2006  KURL url = dialog.selectedURL();
2007  if( url.isEmpty() )
2008  {
2009  return;
2010  }
2011  if( url.isLocalFile() == false )
2012  {
2013  KMessageBox::sorry( 0, i18n( "Only local files are currently supported." ) );
2014  return;
2015  }
2016 
2017  mLocal.locationEdit->setEditText( url.path() );
2018  directory = url.directory();
2019 }
2020 
2021 void AccountDialog::slotMaildirChooser()
2022 {
2023  static TQString directory( "/" );
2024 
2025  TQString dir = KFileDialog::getExistingDirectory(directory, this, i18n("Choose Location"));
2026 
2027  if( dir.isEmpty() )
2028  return;
2029 
2030  mMaildir.locationEdit->setEditText( dir );
2031  directory = dir;
2032 }
2033 
2034 void AccountDialog::slotEnableLeaveOnServerDays( bool state )
2035 {
2036  if ( state && !mPop.leaveOnServerDaysCheck->isEnabled()) return;
2037  mPop.leaveOnServerDaysSpin->setEnabled( state );
2038 }
2039 
2040 void AccountDialog::slotEnableLeaveOnServerCount( bool state )
2041 {
2042  if ( state && !mPop.leaveOnServerCountCheck->isEnabled()) return;
2043  mPop.leaveOnServerCountSpin->setEnabled( state );
2044  return;
2045 }
2046 
2047 void AccountDialog::slotEnableLeaveOnServerSize( bool state )
2048 {
2049  if ( state && !mPop.leaveOnServerSizeCheck->isEnabled()) return;
2050  mPop.leaveOnServerSizeSpin->setEnabled( state );
2051  return;
2052 }
2053 
2054 void AccountDialog::slotEnablePopInterval( bool state )
2055 {
2056  mPop.intervalSpin->setEnabled( state );
2057  mPop.intervalLabel->setEnabled( state );
2058 }
2059 
2060 void AccountDialog::slotEnableImapInterval( bool state )
2061 {
2062  mImap.intervalSpin->setEnabled( state );
2063  mImap.intervalLabel->setEnabled( state );
2064 }
2065 
2066 void AccountDialog::slotEnableLocalInterval( bool state )
2067 {
2068  mLocal.intervalSpin->setEnabled( state );
2069  mLocal.intervalLabel->setEnabled( state );
2070 }
2071 
2072 void AccountDialog::slotEnableMaildirInterval( bool state )
2073 {
2074  mMaildir.intervalSpin->setEnabled( state );
2075  mMaildir.intervalLabel->setEnabled( state );
2076 }
2077 
2078 void AccountDialog::slotFontChanged( void )
2079 {
2080  TQString accountType = mAccount->type();
2081  if( accountType == "local" )
2082  {
2083  TQFont titleFont( mLocal.titleLabel->font() );
2084  titleFont.setBold( true );
2085  mLocal.titleLabel->setFont(titleFont);
2086  }
2087  else if( accountType == "pop" )
2088  {
2089  TQFont titleFont( mPop.titleLabel->font() );
2090  titleFont.setBold( true );
2091  mPop.titleLabel->setFont(titleFont);
2092  }
2093  else if( accountType == "imap" )
2094  {
2095  TQFont titleFont( mImap.titleLabel->font() );
2096  titleFont.setBold( true );
2097  mImap.titleLabel->setFont(titleFont);
2098  }
2099 }
2100 
2101 #if 0
2102 void AccountDialog::slotClearResourceAllocations()
2103 {
2104  mAccount->clearIntervals();
2105 }
2106 
2107 
2108 void AccountDialog::slotClearPastResourceAllocations()
2109 {
2110  mAccount->clearOldIntervals();
2111 }
2112 #endif
2113 
2114 void AccountDialog::slotReloadNamespaces()
2115 {
2116  if ( mAccount->type() == "imap" || mAccount->type() == "cachedimap" )
2117  {
2118  initAccountForConnect();
2119  mImap.personalNS->setText( i18n("Fetching Namespaces...") );
2120  mImap.otherUsersNS->setText( TQString() );
2121  mImap.sharedNS->setText( TQString() );
2122  ImapAccountBase* ai = static_cast<ImapAccountBase*>( mAccount );
2123  connect( ai, TQ_SIGNAL( namespacesFetched( const ImapAccountBase::nsDelimMap& ) ),
2124  this, TQ_SLOT( slotSetupNamespaces( const ImapAccountBase::nsDelimMap& ) ) );
2125  connect( ai, TQ_SIGNAL( connectionResult(int, const TQString&) ),
2126  this, TQ_SLOT( slotConnectionResult(int, const TQString&) ) );
2127  ai->getNamespaces();
2128  }
2129 }
2130 
2131 void AccountDialog::slotConnectionResult( int errorCode, const TQString& )
2132 {
2133  if ( errorCode > 0 ) {
2134  ImapAccountBase* ai = static_cast<ImapAccountBase*>( mAccount );
2135  disconnect( ai, TQ_SIGNAL( namespacesFetched( const ImapAccountBase::nsDelimMap& ) ),
2136  this, TQ_SLOT( slotSetupNamespaces( const ImapAccountBase::nsDelimMap& ) ) );
2137  disconnect( ai, TQ_SIGNAL( connectionResult(int, const TQString&) ),
2138  this, TQ_SLOT( slotConnectionResult(int, const TQString&) ) );
2139  mImap.personalNS->setText( TQString() );
2140  }
2141 }
2142 
2143 void AccountDialog::slotSetupNamespaces( const ImapAccountBase::nsDelimMap& map )
2144 {
2145  disconnect( this, TQ_SLOT( slotSetupNamespaces( const ImapAccountBase::nsDelimMap& ) ) );
2146  mImap.personalNS->setText( TQString() );
2147  mImap.otherUsersNS->setText( TQString() );
2148  mImap.sharedNS->setText( TQString() );
2149  mImap.nsMap = map;
2150 
2151  ImapAccountBase::namespaceDelim ns = map[ImapAccountBase::PersonalNS];
2152  ImapAccountBase::namespaceDelim::ConstIterator it;
2153  if ( !ns.isEmpty() ) {
2154  mImap.personalNS->setText( namespaceListToString( ns.keys() ) );
2155  mImap.editPNS->setEnabled( true );
2156  } else {
2157  mImap.editPNS->setEnabled( false );
2158  }
2159  ns = map[ImapAccountBase::OtherUsersNS];
2160  if ( !ns.isEmpty() ) {
2161  mImap.otherUsersNS->setText( namespaceListToString( ns.keys() ) );
2162  mImap.editONS->setEnabled( true );
2163  } else {
2164  mImap.editONS->setEnabled( false );
2165  }
2166  ns = map[ImapAccountBase::SharedNS];
2167  if ( !ns.isEmpty() ) {
2168  mImap.sharedNS->setText( namespaceListToString( ns.keys() ) );
2169  mImap.editSNS->setEnabled( true );
2170  } else {
2171  mImap.editSNS->setEnabled( false );
2172  }
2173 }
2174 
2175 const TQString AccountDialog::namespaceListToString( const TQStringList& list )
2176 {
2177  TQStringList myList = list;
2178  for ( TQStringList::Iterator it = myList.begin(); it != myList.end(); ++it ) {
2179  if ( (*it).isEmpty() ) {
2180  (*it) = "<" + i18n("Empty") + ">";
2181  }
2182  }
2183  return myList.join(",");
2184 }
2185 
2186 void AccountDialog::initAccountForConnect()
2187 {
2188  TQString type = mAccount->type();
2189  if ( type == "local" )
2190  return;
2191 
2192  NetworkAccount &na = *(NetworkAccount*)mAccount;
2193 
2194  if ( type == "pop" ) {
2195  na.setHost( mPop.hostEdit->text().stripWhiteSpace() );
2196  na.setPort( mPop.portEdit->text().toInt() );
2197  na.setLogin( mPop.loginEdit->text().stripWhiteSpace() );
2198  na.setStorePasswd( mPop.storePasswordCheck->isChecked() );
2199  na.setPasswd( mPop.passwordEdit->text(), na.storePasswd() );
2200  na.setUseSSL( mPop.encryptionSSL->isChecked() );
2201  na.setUseTLS( mPop.encryptionTLS->isChecked() );
2202  if (mPop.authUser->isChecked())
2203  na.setAuth("USER");
2204  else if (mPop.authLogin->isChecked())
2205  na.setAuth("LOGIN");
2206  else if (mPop.authPlain->isChecked())
2207  na.setAuth("PLAIN");
2208  else if (mPop.authCRAM_MD5->isChecked())
2209  na.setAuth("CRAM-MD5");
2210  else if (mPop.authDigestMd5->isChecked())
2211  na.setAuth("DIGEST-MD5");
2212  else if (mPop.authNTLM->isChecked())
2213  na.setAuth("NTLM");
2214  else if (mPop.authGSSAPI->isChecked())
2215  na.setAuth("GSSAPI");
2216  else if (mPop.authAPOP->isChecked())
2217  na.setAuth("APOP");
2218  else na.setAuth("AUTO");
2219  }
2220  else if ( type == "imap" || type == "cachedimap" ) {
2221  na.setHost( mImap.hostEdit->text().stripWhiteSpace() );
2222  na.setPort( mImap.portEdit->text().toInt() );
2223  na.setLogin( mImap.loginEdit->text().stripWhiteSpace() );
2224  na.setStorePasswd( mImap.storePasswordCheck->isChecked() );
2225  na.setPasswd( mImap.passwordEdit->text(), na.storePasswd() );
2226  na.setUseSSL( mImap.encryptionSSL->isChecked() );
2227  na.setUseTLS( mImap.encryptionTLS->isChecked() );
2228  if (mImap.authCramMd5->isChecked())
2229  na.setAuth("CRAM-MD5");
2230  else if (mImap.authDigestMd5->isChecked())
2231  na.setAuth("DIGEST-MD5");
2232  else if (mImap.authNTLM->isChecked())
2233  na.setAuth("NTLM");
2234  else if (mImap.authGSSAPI->isChecked())
2235  na.setAuth("GSSAPI");
2236  else if (mImap.authAnonymous->isChecked())
2237  na.setAuth("ANONYMOUS");
2238  else if (mImap.authLogin->isChecked())
2239  na.setAuth("LOGIN");
2240  else if (mImap.authPlain->isChecked())
2241  na.setAuth("PLAIN");
2242  else na.setAuth("*");
2243  }
2244 }
2245 
2246 void AccountDialog::slotEditPersonalNamespace()
2247 {
2248  NamespaceEditDialog dialog( this, ImapAccountBase::PersonalNS, &mImap.nsMap );
2249  if ( dialog.exec() == TQDialog::Accepted ) {
2250  slotSetupNamespaces( mImap.nsMap );
2251  }
2252 }
2253 
2254 void AccountDialog::slotEditOtherUsersNamespace()
2255 {
2256  NamespaceEditDialog dialog( this, ImapAccountBase::OtherUsersNS, &mImap.nsMap );
2257  if ( dialog.exec() == TQDialog::Accepted ) {
2258  slotSetupNamespaces( mImap.nsMap );
2259  }
2260 }
2261 
2262 void AccountDialog::slotEditSharedNamespace()
2263 {
2264  NamespaceEditDialog dialog( this, ImapAccountBase::SharedNS, &mImap.nsMap );
2265  if ( dialog.exec() == TQDialog::Accepted ) {
2266  slotSetupNamespaces( mImap.nsMap );
2267  }
2268 }
2269 
2270 NamespaceLineEdit::NamespaceLineEdit( TQWidget* parent )
2271  : KLineEdit( parent )
2272 {
2273 }
2274 
2275 void NamespaceLineEdit::setText( const TQString& text )
2276 {
2277  mLastText = text;
2278  KLineEdit::setText( text );
2279 }
2280 
2281 NamespaceEditDialog::NamespaceEditDialog( TQWidget *parent,
2282  ImapAccountBase::imapNamespace type, ImapAccountBase::nsDelimMap* map )
2283  : KDialogBase( parent, "edit_namespace", false, TQString(),
2284  Ok|Cancel, Ok, true ), mType( type ), mNamespaceMap( map )
2285 {
2286  TQVBox *page = makeVBoxMainWidget();
2287 
2288  TQString ns;
2289  if ( mType == ImapAccountBase::PersonalNS ) {
2290  ns = i18n("Personal");
2291  } else if ( mType == ImapAccountBase::OtherUsersNS ) {
2292  ns = i18n("Other Users");
2293  } else {
2294  ns = i18n("Shared");
2295  }
2296  setCaption( i18n("Edit Namespace '%1'").arg(ns) );
2297  TQGrid* grid = new TQGrid( 2, page );
2298 
2299  mBg = new TQButtonGroup( 0 );
2300  connect( mBg, TQ_SIGNAL( clicked(int) ), this, TQ_SLOT( slotRemoveEntry(int) ) );
2301  mDelimMap = mNamespaceMap->find( mType ).data();
2302  ImapAccountBase::namespaceDelim::Iterator it;
2303  for ( it = mDelimMap.begin(); it != mDelimMap.end(); ++it ) {
2304  NamespaceLineEdit* edit = new NamespaceLineEdit( grid );
2305  edit->setText( it.key() );
2306  TQToolButton* button = new TQToolButton( grid );
2307  button->setIconSet(
2308  TDEGlobal::iconLoader()->loadIconSet( "edit-delete", TDEIcon::Small, 0 ) );
2309  button->setAutoRaise( true );
2310  button->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
2311  button->setFixedSize( 22, 22 );
2312  mLineEditMap[ mBg->insert( button ) ] = edit;
2313  }
2314 }
2315 
2316 void NamespaceEditDialog::slotRemoveEntry( int id )
2317 {
2318  if ( mLineEditMap.contains( id ) ) {
2319  // delete the lineedit and remove namespace from map
2320  NamespaceLineEdit* edit = mLineEditMap[id];
2321  mDelimMap.remove( edit->text() );
2322  if ( edit->isModified() ) {
2323  mDelimMap.remove( edit->lastText() );
2324  }
2325  mLineEditMap.remove( id );
2326  delete edit;
2327  }
2328  if ( mBg->find( id ) ) {
2329  // delete the button
2330  delete mBg->find( id );
2331  }
2332  adjustSize();
2333 }
2334 
2335 void NamespaceEditDialog::slotOk()
2336 {
2337  TQMap<int, NamespaceLineEdit*>::Iterator it;
2338  for ( it = mLineEditMap.begin(); it != mLineEditMap.end(); ++it ) {
2339  NamespaceLineEdit* edit = it.data();
2340  if ( edit->isModified() ) {
2341  // register delimiter for new namespace
2342  mDelimMap[edit->text()] = mDelimMap[edit->lastText()];
2343  mDelimMap.remove( edit->lastText() );
2344  }
2345  }
2346  mNamespaceMap->replace( mType, mDelimMap );
2347  KDialogBase::slotOk();
2348 }
2349 
2350 } // namespace KMail
2351 
2352 #include "accountdialog.moc"
KMail list that manages the contents of one directory that may contain folders and/or other directori...
Definition: kmfolderdir.h:16
Mail folder.
Definition: kmfolder.h:69
bool isSystemFolder() const
Returns true if the folder is a kmail system folder.
Definition: kmfolder.h:369
void remove()
Removes the folder physically from disk and empties the contents of the folder in memory.
Definition: kmfolder.cpp:515
TQString location() const
Returns full path to folder file.
Definition: kmfolder.cpp:243
@ Ok
The user rights/ACL have been fetched from the server sucessfully.
Definition: acljobs.h:66
folderdiaquotatab.h
Definition: aboutdata.cpp:40