Backport r950340 | aacid | 2009-04-06 23:21:18 +0200 (Mon, 06 Apr 2009) | 4 lines
[kdepim.git] / kmail / kmfolderdialog.cpp
blob710b491f55185c9b3643bd7eec88fcf3be6a9dcc
1 // -*- mode: C++; c-file-style: "gnu" -*-
2 /**
3 * kmfolderdialog.cpp
5 * Copyright (c) 1997-2004 KMail Developers
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * In addition, as a special exception, the copyright holders give
22 * permission to link the code of this program with any edition of
23 * the Qt library by Trolltech AS, Norway (or with modified versions
24 * of Qt that use the same license as Qt), and distribute linked
25 * combinations including the two. You must obey the GNU General
26 * Public License in all respects for all of the code used other than
27 * Qt. If you modify this file, you may extend this exception to
28 * your version of the file, but you are not obligated to do so. If
29 * you do not wish to do so, delete this exception statement from
30 * your version.
34 #include "kmfolderdialog.h"
35 #include "kmacctfolder.h"
36 #include "kmfoldermgr.h"
37 #include <kpimidentities/identitycombo.h>
38 #include "kmfolderimap.h"
39 #include "kmfoldercachedimap.h"
40 #include "kmfolder.h"
41 #include "kmcommands.h"
42 #include "folderdialogacltab.h"
43 #include "folderdialogquotatab.h"
44 #include "kmailicalifaceimpl.h"
45 #include "globalsettings.h"
46 #include "folderrequester.h"
47 #include "mainfolderview.h"
49 #include <keditlistbox.h>
50 #include <klineedit.h>
51 #include <klocale.h>
52 #include <knuminput.h>
53 #include <kmessagebox.h>
54 #include <kicondialog.h>
55 #include <kconfig.h>
56 #include <kdebug.h>
57 #include <kvbox.h>
59 #include <QCheckBox>
60 #include <QLayout>
61 #include <QRegExp>
62 #include <QLabel>
63 #include <QGridLayout>
64 #include <QFrame>
65 #include <QHBoxLayout>
66 #include <QList>
67 #include <QVBoxLayout>
68 #include <QRadioButton>
70 #include <assert.h>
72 #include "templatesconfiguration.h"
73 #include "templatesconfiguration_kfg.h"
75 using namespace KMail;
77 static QString inCaseWeDecideToRenameTheTab( I18N_NOOP( "Permissions (ACL)" ) );
79 //-----------------------------------------------------------------------------
80 KMFolderDialog::KMFolderDialog( KMFolder *aFolder, KMFolderDir *aFolderDir,
81 MainFolderView *aParent, const QString& aCap,
82 const QString& aName):
83 KPageDialog( aParent ),
84 mFolder( aFolder ),
85 mFolderDir( aFolderDir ),
86 mParentFolder( 0 ),
87 mIsNewFolder( aFolder == 0 )
89 setFaceType( Tabbed );
90 setCaption( aCap );
91 setButtons( Ok|Cancel );
92 setDefaultButton( Ok );
93 setObjectName( "KMFolderDialog" );
94 setModal( true );
96 kDebug(5006);
98 QStringList folderNames;
99 QList<QPointer<KMFolder> > folders;
100 // get all folders but search and folders that can not have children
102 aParent->createFolderList(
103 &folderNames, &folders,
104 MainFolderView::IncludeLocalFolders | MainFolderView::IncludeImapFolders |
105 MainFolderView::IncludeCachedImapFolders | MainFolderView::SkipFoldersWithNoChildren
108 if( mFolderDir ) {
109 // search the parent folder of the folder
110 FolderList::ConstIterator it;
111 int i = 1;
112 for( it = folders.constBegin(); it != folders.constEnd(); ++it, ++i ) {
113 if( (*it)->child() == mFolderDir ) {
114 mParentFolder = *it;
115 break;
120 FolderDialogTab* tab;
121 QFrame *box;
123 box = new KVBox;
124 addPage( box, i18nc("@title:tab General settings for a folder.", "General") );
125 tab = new FolderDialogGeneralTab( this, aName, box );
126 addTab( tab );
128 // Don't add template tab for special folders
129 if (!mFolder->isSystemFolder() || mFolder->isMainInbox())
131 box = new KVBox( this );
132 addPage( box, i18n("Templates") );
133 tab = new FolderDialogTemplatesTab( this, box );
134 addTab( tab );
137 KMFolder* refFolder = mFolder ? mFolder : mParentFolder;
138 KMFolderType folderType = refFolder ? refFolder->folderType() : KMFolderTypeUnknown;
139 bool noContent = mFolder ? mFolder->storage()->noContent() : false;
140 if ( !noContent && refFolder && ( folderType == KMFolderTypeImap || folderType == KMFolderTypeCachedImap ) ) {
141 if ( FolderDialogACLTab::supports( refFolder ) ) {
142 box = new KVBox;
143 addPage( box, i18n("Access Control") );
144 tab = new FolderDialogACLTab( this, box );
145 addTab( tab );
149 if ( !noContent && refFolder && ( folderType == KMFolderTypeImap || folderType == KMFolderTypeCachedImap ) ) {
150 if ( FolderDialogQuotaTab::supports( refFolder ) ) {
151 box = new KVBox;
152 addPage( box, i18n("Quota") );
153 tab = new FolderDialogQuotaTab( this, box );
154 addTab( tab );
158 for ( int i = 0 ; i < mTabs.count() ; ++i )
159 mTabs[i]->load();
160 connect( this, SIGNAL( okClicked() ), SLOT( slotOk() ) );
161 connect( this, SIGNAL( applyClicked() ), SLOT( slotApply() ) );
164 void KMFolderDialog::addTab( FolderDialogTab* tab )
166 connect( tab, SIGNAL( readyForAccept() ),
167 this, SLOT( slotReadyForAccept() ) );
168 connect( tab, SIGNAL( cancelAccept() ),
169 this, SLOT( slotCancelAccept() ) );
170 //connect( tab, SIGNAL(changed( bool )),
171 // this, SLOT(slotChanged( bool )) );
172 mTabs.append( tab );
175 // Not used yet (no button), but ready to be used :)
176 void KMFolderDialog::slotApply()
178 if ( mFolder.isNull() && !mIsNewFolder ) // deleted meanwhile?
179 return;
181 for ( int i = 0 ; i < mTabs.count() ; ++i )
182 mTabs[i]->save();
183 if ( !mFolder.isNull() && mIsNewFolder ) // we just created it
184 mIsNewFolder = false; // so it's not new anymore :)
187 // Called when pressing Ok
188 // We want to apply the changes first (which is async), before closing the dialog,
189 // in case of errors during the upload.
190 void KMFolderDialog::slotOk()
192 if ( mFolder.isNull() && !mIsNewFolder ) { // deleted meanwhile?
193 KDialog::accept();
194 return;
197 mDelayedSavingTabs = 0; // number of tabs which need delayed saving
198 for ( int i = 0 ; i < mTabs.count() ; ++i ) {
199 FolderDialogTab::AcceptStatus s = mTabs[i]->accept();
200 if ( s == FolderDialogTab::Canceled ) {
201 slotCancelAccept();
202 return;
204 else if ( s == FolderDialogTab::Delayed )
205 ++mDelayedSavingTabs;
208 if ( mDelayedSavingTabs )
209 enableButtonOk( false );
210 else
211 KDialog::accept();
214 void KMFolderDialog::slotReadyForAccept()
216 --mDelayedSavingTabs;
217 if ( mDelayedSavingTabs == 0 )
218 KDialog::accept();
221 void KMFolderDialog::slotCancelAccept()
223 mDelayedSavingTabs = -1;
224 enableButtonOk( true );
225 // Don't try to create it twice
226 if ( !mFolder.isNull() )
227 mIsNewFolder = false;
229 // Other tabs might call slotReadyForAccept. -1 ensures that it won't close the dialog,
230 // but the OK button being enabled means that people might succeed in running
231 // the same job from save more than once.
232 // Solution: mAcceptCanceled = true instead of -1.
233 // Bah for now we only have one tab which can delay saving -> later.
236 void KMFolderDialog::slotChanged( bool )
238 // TODO, support for 'changed', and Apply button.
239 // sample code for here: KCMultiDialog calls bool changed() on every KCModuleProxy...
242 void KMFolderDialog::setFolder( KMFolder* folder )
244 Q_ASSERT( mFolder.isNull() );
245 mFolder = folder;
248 KMFolderDir* KMFolderDialog::folderDir() const
250 return mFolderDir;
253 static void addLine( QWidget *parent, QVBoxLayout* layout )
255 QFrame *line = new QFrame( parent );
256 line->setObjectName( "line" );
257 line->setGeometry( QRect( 80, 150, 250, 20 ) );
258 line->setFrameShape( QFrame::HLine );
259 line->setFrameShadow( QFrame::Sunken );
260 line->setFrameShape( QFrame::HLine );
261 layout->addWidget( line );
264 //----------------------------------------------------------------------------
265 KMail::FolderDialogGeneralTab::FolderDialogGeneralTab( KMFolderDialog* dlg,
266 const QString& aName,
267 QWidget* parent, const char* name )
268 : FolderDialogTab( parent, name ), mDlg( dlg )
272 mIsLocalSystemFolder = mDlg->folder()->isSystemFolder() &&
273 mDlg->folder()->folderType() != KMFolderTypeImap &&
274 mDlg->folder()->folderType() != KMFolderTypeCachedImap;
276 QLabel *label;
278 QVBoxLayout *topLayout = new QVBoxLayout( this );
279 topLayout->setSpacing( KDialog::spacingHint() );
280 topLayout->setMargin( 0 );
282 // Musn't be able to edit details for a system folder.
283 if ( !mIsLocalSystemFolder ) {
285 QHBoxLayout *hl = new QHBoxLayout();
286 topLayout->addItem( hl );
287 hl->setSpacing( KDialog::spacingHint() );
289 label = new QLabel( i18nc("@label:textbox Name of the folder.","&Name:"), this );
290 hl->addWidget( label );
292 mNameEdit = new KLineEdit( this );
293 if( !mDlg->folder() )
294 mNameEdit->setFocus();
295 mNameEdit->setText( mDlg->folder() ? mDlg->folder()->label() : i18n("unnamed") );
296 if (!aName.isEmpty())
297 mNameEdit->setText(aName);
298 mNameEdit->setMinimumSize(mNameEdit->sizeHint());
299 // prevent renaming of IMAP inbox
300 if ( mDlg->folder() && mDlg->folder()->isSystemFolder() ) {
301 QString imapPath;
302 if ( mDlg->folder()->folderType() == KMFolderTypeImap )
303 imapPath = static_cast<KMFolderImap*>( mDlg->folder()->storage() )->imapPath();
304 if ( mDlg->folder()->folderType() == KMFolderTypeCachedImap )
305 imapPath = static_cast<KMFolderCachedImap*>( mDlg->folder()->storage() )->imapPath();
306 if ( imapPath == "/INBOX/" )
307 mNameEdit->setEnabled( false );
309 label->setBuddy( mNameEdit );
310 hl->addWidget( mNameEdit );
311 connect( mNameEdit, SIGNAL( textChanged( const QString & ) ),
312 this, SLOT( slotFolderNameChanged( const QString & ) ) );
315 //start icons group
316 QVBoxLayout *ivl = new QVBoxLayout();
317 topLayout->addItem( ivl );
318 ivl->setSpacing( KDialog::spacingHint() );
320 QHBoxLayout *ihl = new QHBoxLayout();
321 ivl->addLayout( ihl );
322 mIconsCheckBox = new QCheckBox( i18n("Use custom &icons"), this );
323 mIconsCheckBox->setChecked( false );
324 ihl->addWidget( mIconsCheckBox );
325 ihl->addStretch( 2 );
327 mNormalIconLabel = new QLabel(
328 i18nc("Icon used for folders with no unread messages.", "&Normal:"), this );
329 mNormalIconLabel->setEnabled( false );
330 ihl->addWidget( mNormalIconLabel );
332 mNormalIconButton = new KIconButton( this );
333 mNormalIconLabel->setBuddy( mNormalIconButton );
334 mNormalIconButton->setIconType( KIconLoader::NoGroup, KIconLoader::Place, false );
335 mNormalIconButton->setIconSize( 16 );
336 mNormalIconButton->setStrictIconSize( true );
337 mNormalIconButton->setFixedSize( 28, 28 );
338 // Can't use iconset here
339 mNormalIconButton->setIcon( "folder" );
340 mNormalIconButton->setEnabled( false );
341 ihl->addWidget( mNormalIconButton );
343 mUnreadIconLabel = new QLabel(
344 i18nc("Icon used for folders which do have unread messages.","&Unread:"), this );
345 mUnreadIconLabel->setEnabled( false );
346 ihl->addWidget( mUnreadIconLabel );
348 mUnreadIconButton = new KIconButton( this );
349 mUnreadIconLabel->setBuddy( mUnreadIconButton );
350 mUnreadIconButton->setIconType( KIconLoader::NoGroup, KIconLoader::Place, false );
351 mUnreadIconButton->setIconSize( 16 );
352 mUnreadIconButton->setStrictIconSize( true );
353 mUnreadIconButton->setFixedSize( 28, 28 );
354 // Can't use iconset here
355 mUnreadIconButton->setIcon( "folder-open" );
356 mUnreadIconButton->setEnabled( false );
357 ihl->addWidget( mUnreadIconButton );
358 ihl->addStretch( 1 );
360 connect( mIconsCheckBox, SIGNAL(toggled(bool)),
361 mNormalIconButton, SLOT(setEnabled(bool)) );
362 connect( mIconsCheckBox, SIGNAL(toggled(bool)),
363 mUnreadIconButton, SLOT(setEnabled(bool)) );
364 connect( mIconsCheckBox, SIGNAL(toggled(bool)),
365 mNormalIconLabel, SLOT(setEnabled(bool)) );
366 connect( mIconsCheckBox, SIGNAL(toggled(bool)),
367 mUnreadIconLabel, SLOT(setEnabled(bool)) );
369 connect( mNormalIconButton, SIGNAL(iconChanged(const QString&)),
370 this, SLOT(slotChangeIcon(const QString&)) );
372 //end icons group
373 addLine( this, topLayout);
377 // should new mail in this folder be ignored?
378 QHBoxLayout *hbl = new QHBoxLayout();
379 topLayout->addItem( hbl );
380 hbl->setSpacing( KDialog::spacingHint() );
381 mNotifyOnNewMailCheckBox =
382 new QCheckBox( i18n("Act on new/unread mail in this folder" ), this );
383 mNotifyOnNewMailCheckBox->setWhatsThis(
384 i18n( "<qt><p>If this option is enabled then you will be notified about "
385 "new/unread mail in this folder. Moreover, going to the "
386 "next/previous folder with unread messages will stop at this "
387 "folder.</p>"
388 "<p>Uncheck this option if you do not want to be notified about "
389 "new/unread mail in this folder and if you want this folder to "
390 "be skipped when going to the next/previous folder with unread "
391 "messages. This is useful for ignoring any new/unread mail in "
392 "your trash and spam folder.</p></qt>" ) );
393 hbl->addWidget( mNotifyOnNewMailCheckBox );
395 if ( mDlg->folder()->folderType() == KMFolderTypeImap ) {
396 // should this folder be included in new-mail-checks?
398 QHBoxLayout *nml = new QHBoxLayout();
399 topLayout->addItem( nml );
400 nml->setSpacing( KDialog::spacingHint() );
401 mNewMailCheckBox = new QCheckBox( i18n("Include this folder in mail checks"), this );
402 mNewMailCheckBox->setWhatsThis(
403 i18n("<qt><p>If this option is enabled this folder will be included "
404 "while checking new emails.</p>"
405 "<p>Uncheck this option if you want to skip this folder "
406 "while checking new emails.</p></qt>") );
407 // default is on
408 mNewMailCheckBox->setChecked(true);
409 nml->addWidget( mNewMailCheckBox );
410 nml->addStretch( 1 );
413 // should replies to mails in this folder be kept in this same folder?
414 hbl = new QHBoxLayout();
415 topLayout->addItem( hbl );
416 hbl->setSpacing( KDialog::spacingHint() );
417 mKeepRepliesInSameFolderCheckBox =
418 new QCheckBox( i18n("Keep replies in this folder" ), this );
419 mKeepRepliesInSameFolderCheckBox->setWhatsThis(
420 i18n( "Check this option if you want replies you write "
421 "to mails in this folder to be put in this same folder "
422 "after sending, instead of in the configured sent-mail folder." ) );
423 hbl->addWidget( mKeepRepliesInSameFolderCheckBox );
424 hbl->addStretch( 1 );
426 addLine( this, topLayout );
428 // use grid layout for the following combobox settings
429 QGridLayout *gl = new QGridLayout();
430 topLayout->addItem( gl );
431 gl->setSpacing( KDialog::spacingHint() );
432 gl->setColumnStretch( 1, 100 ); // make the second column use all available space
433 int row = -1;
435 // sender identity
436 ++row;
437 mUseDefaultIdentityCheckBox = new QCheckBox( i18n("Use &default identity"),
438 this );
439 gl->addWidget( mUseDefaultIdentityCheckBox );
440 connect( mUseDefaultIdentityCheckBox, SIGNAL( stateChanged(int) ),
441 this, SLOT( slotIdentityCheckboxChanged() ) );
442 ++row;
443 label = new QLabel( i18n("&Sender identity:"), this );
444 gl->addWidget( label, row, 0 );
445 mIdentityComboBox = new KPIMIdentities::IdentityCombo( kmkernel->identityManager(), this );
446 label->setBuddy( mIdentityComboBox );
447 gl->addWidget( mIdentityComboBox, row, 1 );
448 mIdentityComboBox->setWhatsThis(
449 i18n( "Select the sender identity to be used when writing new mail "
450 "or replying to mail in this folder. This means that if you are in "
451 "one of your work folders, you can make KMail use the corresponding "
452 "sender email address, signature and signing or encryption keys "
453 "automatically. Identities can be set up in the main configuration "
454 "dialog. (Settings -> Configure KMail)") );
457 // sender or receiver column?
458 ++row;
459 QString tip = i18n("Show Sender/Receiver Column in List of Messages");
461 QLabel *sender_label = new QLabel( i18n("Sho&w column:" ), this );
462 gl->addWidget( sender_label, row, 0 );
463 mShowSenderReceiverComboBox = new KComboBox( this );
464 mShowSenderReceiverComboBox->setToolTip( tip );
465 sender_label->setBuddy(mShowSenderReceiverComboBox);
466 gl->addWidget( mShowSenderReceiverComboBox, row, 1 );
467 mShowSenderReceiverComboBox->insertItem(0, i18nc("@item:inlistbox Show default value.", "Default"));
468 mShowSenderReceiverComboBox->insertItem(1, i18nc("@item:inlistbox Show sender.", "Sender"));
469 mShowSenderReceiverComboBox->insertItem(2, i18nc("@item:inlistbox Show receiver.", "Receiver"));
471 QString whoField;
472 if (mDlg->folder()) whoField = mDlg->folder()->userWhoField();
473 if (whoField.isEmpty()) mShowSenderReceiverComboBox->setCurrentIndex(0);
474 else if (whoField == "From") mShowSenderReceiverComboBox->setCurrentIndex(1);
475 else if (whoField == "To") mShowSenderReceiverComboBox->setCurrentIndex(2);
477 // folder contents
478 if ( !mIsLocalSystemFolder && kmkernel->iCalIface().isEnabled() ) {
479 // Only do make this settable, if the IMAP resource is enabled
480 // and it's not the personal folders (those must not be changed)
481 ++row;
482 label = new QLabel( i18n("&Folder contents:"), this );
483 gl->addWidget( label, row, 0 );
484 mContentsComboBox = new KComboBox( this );
485 label->setBuddy( mContentsComboBox );
486 gl->addWidget( mContentsComboBox, row, 1 );
488 mContentsComboBox->addItem( i18nc( "type of folder content", "Mail" ) );
489 mContentsComboBox->addItem( i18nc( "type of folder content", "Calendar" ) );
490 mContentsComboBox->addItem( i18nc( "type of folder content", "Contacts" ) );
491 mContentsComboBox->addItem( i18nc( "type of folder content", "Notes" ) );
492 mContentsComboBox->addItem( i18nc( "type of folder content", "Tasks" ) );
493 mContentsComboBox->addItem( i18nc( "type of folder content", "Journal" ) );
494 if ( mDlg->folder() )
495 mContentsComboBox->setCurrentIndex( mDlg->folder()->storage()->contentsType() );
496 connect ( mContentsComboBox, SIGNAL ( activated( int ) ),
497 this, SLOT( slotFolderContentsSelectionChanged( int ) ) );
498 if ( mDlg->folder()->isReadOnly() )
499 mContentsComboBox->setEnabled( false );
500 } else {
501 mContentsComboBox = 0;
504 mIncidencesForComboBox = 0;
505 mAlarmsBlockedCheckBox = 0;
507 // Kolab incidences-for annotation.
508 // Show incidences-for combobox if the contents type can be changed (new folder),
509 // or if it's set to calendar or task (existing folder)
510 if ( ( GlobalSettings::self()->theIMAPResourceStorageFormat() ==
511 GlobalSettings::EnumTheIMAPResourceStorageFormat::XML ) &&
512 mContentsComboBox ) {
513 ++row;
514 QLabel* label = new QLabel( i18n( "Generate free/&busy and activate alarms for:" ), this );
515 gl->addWidget( label, row, 0 );
516 mIncidencesForComboBox = new KComboBox( this );
517 label->setBuddy( mIncidencesForComboBox );
518 gl->addWidget( mIncidencesForComboBox, row, 1 );
520 mIncidencesForComboBox->addItem( i18n( "Nobody" ) );
521 mIncidencesForComboBox->addItem( i18n( "Admins of This Folder" ) );
522 mIncidencesForComboBox->addItem( i18n( "All Readers of This Folder" ) );
523 const QString whatsThisForMyOwnFolders =
524 i18n( "This setting defines which users sharing "
525 "this folder should get \"busy\" periods in their freebusy lists "
526 "and should see the alarms for the events or tasks in this folder. "
527 "The setting applies to Calendar and Task folders only "
528 "(for tasks, this setting is only used for alarms).\n\n"
529 "Example use cases: if the boss shares a folder with his secretary, "
530 "only the boss should be marked as busy for his meetings, so he should "
531 "select \"Admins\", since the secretary has no admin rights on the folder.\n"
532 "On the other hand if a working group shares a Calendar for "
533 "group meetings, all readers of the folders should be marked "
534 "as busy for meetings.\n"
535 "A company-wide folder with optional events in it would use \"Nobody\" "
536 "since it is not known who will go to those events." );
538 mIncidencesForComboBox->setWhatsThis( whatsThisForMyOwnFolders );
540 ++row;
541 const QString whatsThisForReadOnlyFolders =
542 i18n( "This setting allows you to disable alarms for folders shared by "
543 "others. ");
544 mAlarmsBlockedCheckBox = new QCheckBox( this );
545 mAlarmsBlockedCheckBox->setText( i18n( "Block free/&busy and alarms locally" ) );
546 gl->addWidget( mAlarmsBlockedCheckBox, row, 0, 1, 1 );
547 mAlarmsBlockedCheckBox->setWhatsThis( whatsThisForReadOnlyFolders );
549 if ( mDlg->folder()->storage()->contentsType() != KMail::ContentsTypeCalendar
550 && mDlg->folder()->storage()->contentsType() != KMail::ContentsTypeTask ) {
551 mIncidencesForComboBox->setEnabled( false );
552 mAlarmsBlockedCheckBox->setEnabled( false );
554 } else {
555 mIncidencesForComboBox = 0;
558 topLayout->addStretch( 100 ); // eat all superfluous space
560 initializeWithValuesFromFolder( mDlg->folder() );
563 void FolderDialogGeneralTab::load()
565 // Nothing here, all is done in the ctor
568 void FolderDialogGeneralTab::initializeWithValuesFromFolder( KMFolder* folder ) {
569 if ( !folder )
570 return;
572 if ( !mIsLocalSystemFolder ) {
573 // folder icons
574 mIconsCheckBox->setChecked( folder->useCustomIcons() );
575 mNormalIconLabel->setEnabled( folder->useCustomIcons() );
576 mNormalIconButton->setEnabled( folder->useCustomIcons() );
577 mUnreadIconLabel->setEnabled( folder->useCustomIcons() );
578 mUnreadIconButton->setEnabled( folder->useCustomIcons() );
579 QString iconPath = folder->normalIconPath();
580 if ( !iconPath.isEmpty() )
581 mNormalIconButton->setIcon( iconPath );
582 iconPath = folder->unreadIconPath();
583 if ( !iconPath.isEmpty() )
584 mUnreadIconButton->setIcon( iconPath );
587 // folder identity
588 mIdentityComboBox->setCurrentIdentity( folder->identity() );
589 mUseDefaultIdentityCheckBox->setChecked( folder->useDefaultIdentity() );
591 // ignore new mail
592 mNotifyOnNewMailCheckBox->setChecked( !folder->ignoreNewMail() );
594 const bool keepInFolder = !folder->isReadOnly() && folder->putRepliesInSameFolder();
595 mKeepRepliesInSameFolderCheckBox->setChecked( keepInFolder );
596 mKeepRepliesInSameFolderCheckBox->setDisabled( folder->isReadOnly() );
598 if (folder->folderType() == KMFolderTypeImap)
600 KMFolderImap* imapFolder = static_cast<KMFolderImap*>(folder->storage());
601 bool checked = imapFolder->includeInMailCheck();
602 mNewMailCheckBox->setChecked(checked);
605 if ( mIncidencesForComboBox ) {
606 KMFolderCachedImap* dimap = static_cast<KMFolderCachedImap *>( folder->storage() );
607 mIncidencesForComboBox->setCurrentIndex( dimap->incidencesFor() );
608 mIncidencesForComboBox->setDisabled( mDlg->folder()->isReadOnly() );
610 if ( mAlarmsBlockedCheckBox ) {
611 KMFolderCachedImap* dimap = static_cast<KMFolderCachedImap *>( folder->storage() );
612 mAlarmsBlockedCheckBox->setChecked( dimap->alarmsBlocked() );
616 //-----------------------------------------------------------------------------
617 void FolderDialogGeneralTab::slotFolderNameChanged( const QString& str )
619 mDlg->enableButtonOk( !str.isEmpty() );
622 //-----------------------------------------------------------------------------
623 void FolderDialogGeneralTab::slotFolderContentsSelectionChanged( int )
625 KMail::FolderContentsType type =
626 static_cast<KMail::FolderContentsType>( mContentsComboBox->currentIndex() );
627 if( type != KMail::ContentsTypeMail && GlobalSettings::self()->hideGroupwareFolders() ) {
628 QString message = i18n("You have configured this folder to contain groupware information "
629 "and the general configuration option to hide groupware folders is "
630 "set. That means that this folder will disappear once the configuration "
631 "dialog is closed. If you want to remove the folder again, you will need "
632 "to temporarily disable hiding of groupware folders to be able to see it.");
633 KMessageBox::information( this, message );
636 const bool enable = type == KMail::ContentsTypeCalendar || type == KMail::ContentsTypeTask;
637 if ( mIncidencesForComboBox )
638 mIncidencesForComboBox->setEnabled( enable );
639 if ( mAlarmsBlockedCheckBox )
640 mAlarmsBlockedCheckBox->setEnabled( enable );
643 //-----------------------------------------------------------------------------
644 void FolderDialogGeneralTab::slotIdentityCheckboxChanged()
646 mIdentityComboBox->setEnabled( !mUseDefaultIdentityCheckBox->isChecked() );
649 //-----------------------------------------------------------------------------
650 bool FolderDialogGeneralTab::save()
652 KMFolder* folder = mDlg->folder();
653 folder->setIdentity( mIdentityComboBox->currentIdentity() );
654 folder->setUseDefaultIdentity( mUseDefaultIdentityCheckBox->isChecked() );
655 // set whoField
656 if (mShowSenderReceiverComboBox->currentIndex() == 1)
657 folder->setUserWhoField("From");
658 else if (mShowSenderReceiverComboBox->currentIndex() == 2)
659 folder->setUserWhoField("To");
660 else
661 folder->setUserWhoField("");
663 folder->setIgnoreNewMail( !mNotifyOnNewMailCheckBox->isChecked() );
664 folder->setPutRepliesInSameFolder( mKeepRepliesInSameFolderCheckBox->isChecked() );
666 QString fldName, oldFldName;
667 if ( !mIsLocalSystemFolder )
669 QString acctName;
670 oldFldName = mDlg->folder()->name();
672 if (!mNameEdit->text().isEmpty())
673 fldName = mNameEdit->text();
674 else
675 fldName = oldFldName;
677 if ( mDlg->parentFolder() &&
678 mDlg->parentFolder()->folderType() != KMFolderTypeImap &&
679 mDlg->parentFolder()->folderType() != KMFolderTypeCachedImap )
680 fldName.remove('/');
681 fldName.remove(QRegExp("^\\.*"));
682 if (fldName.isEmpty()) fldName = i18n("unnamed");
685 // Update the tree iff new icon paths are different and not empty or if
686 // useCustomIcons changed.
687 if ( folder->useCustomIcons() != mIconsCheckBox->isChecked() ) {
688 folder->setUseCustomIcons( mIconsCheckBox->isChecked() );
689 // Reset icons, useCustomIcons was turned off.
690 if ( !folder->useCustomIcons() ) {
691 folder->setIconPaths( "", "" );
694 if ( folder->useCustomIcons() &&
695 (( mNormalIconButton->icon() != folder->normalIconPath() ) &&
696 ( !mNormalIconButton->icon().isEmpty())) ||
697 (( mUnreadIconButton->icon() != folder->unreadIconPath() ) &&
698 ( !mUnreadIconButton->icon().isEmpty())) ) {
699 folder->setIconPaths( mNormalIconButton->icon(), mUnreadIconButton->icon() );
702 // Set type field
703 if ( mContentsComboBox ) {
704 KMail::FolderContentsType type =
705 static_cast<KMail::FolderContentsType>( mContentsComboBox->currentIndex() );
706 folder->storage()->setContentsType( type );
709 if ( folder->folderType() == KMFolderTypeCachedImap ) {
710 KMFolderCachedImap* dimap = static_cast<KMFolderCachedImap *>( mDlg->folder()->storage() );
711 if ( mIncidencesForComboBox ) {
712 KMFolderCachedImap::IncidencesFor incfor =
713 static_cast<KMFolderCachedImap::IncidencesFor>( mIncidencesForComboBox->currentIndex() );
714 if ( dimap->incidencesFor() != incfor ) {
715 dimap->setIncidencesFor( incfor );
716 dimap->writeConfig();
719 if ( mAlarmsBlockedCheckBox && mAlarmsBlockedCheckBox->isChecked() != dimap->alarmsBlocked() ) {
720 dimap->setAlarmsBlocked( mAlarmsBlockedCheckBox->isChecked() );
721 dimap->writeConfig();
725 if( folder->folderType() == KMFolderTypeImap )
727 KMFolderImap* imapFolder = static_cast<KMFolderImap*>( folder->storage() );
728 imapFolder->setIncludeInMailCheck(
729 mNewMailCheckBox->isChecked() );
731 // make sure everything is on disk, connected slots will call readConfig()
732 // when creating a new folder.
733 folder->storage()->writeConfig();
734 // Renamed an existing folder? We don't check for oldName == newName on
735 // purpose here. The folder might be pending renaming on the next dimap
736 // sync already, in which case the old name would still be around and
737 // something like Calendar -> CalendarFoo -> Calendar inbetween syncs would
738 // fail. Therefor let the folder sort it out itself, whether the rename is
739 // a noop or not.
740 if ( !oldFldName.isEmpty() )
742 kmkernel->folderMgr()->renameFolder( folder, fldName );
743 } else {
744 kmkernel->folderMgr()->contentsChanged();
747 return true;
750 void FolderDialogGeneralTab::slotChangeIcon( const QString &icon )
752 mUnreadIconButton->setIcon( icon );
755 //----------------------------------------------------------------------------
756 KMail::FolderDialogTemplatesTab::FolderDialogTemplatesTab( KMFolderDialog *dlg,
757 QWidget *parent )
758 : FolderDialogTab( parent, 0 ), mDlg( dlg )
761 mIsLocalSystemFolder = mDlg->folder()->isSystemFolder() &&
762 mDlg->folder()->folderType() != KMFolderTypeImap &&
763 mDlg->folder()->folderType() != KMFolderTypeCachedImap;
765 QVBoxLayout *topLayout = new QVBoxLayout( this );
766 topLayout->setMargin( 0 );
767 topLayout->setSpacing( KDialog::spacingHint() );
769 QHBoxLayout *topItems = new QHBoxLayout( this );
770 topLayout->addLayout( topItems );
772 mCustom = new QCheckBox( i18n("&Use custom message templates"), this );
773 topItems->addWidget( mCustom, Qt::AlignLeft );
775 mWidget = new TemplatesConfiguration( this, "folder-templates" );
776 mWidget->setEnabled( false );
778 // Move the help label outside of the templates configuration widget,
779 // so that the help can be read even if the widget is not enabled.
780 topItems->addStretch( 9 );
781 topItems->addWidget( mWidget->helpLabel(), Qt::AlignRight );
783 topLayout->addWidget( mWidget );
785 QHBoxLayout *btns = new QHBoxLayout();
786 btns->setSpacing( KDialog::spacingHint() );
787 mCopyGlobal = new KPushButton( i18n("&Copy Global Templates"), this );
788 mCopyGlobal->setEnabled( false );
789 btns->addWidget( mCopyGlobal );
790 topLayout->addLayout( btns );
792 connect( mCustom, SIGNAL(toggled( bool )),
793 mWidget, SLOT(setEnabled( bool )) );
794 connect( mCustom, SIGNAL(toggled( bool )),
795 mCopyGlobal, SLOT(setEnabled( bool )) );
797 connect( mCopyGlobal, SIGNAL(clicked()),
798 this, SLOT(slotCopyGlobal()) );
800 initializeWithValuesFromFolder( mDlg->folder() );
802 connect( mWidget, SIGNAL(changed()),
803 this, SLOT(slotEmitChanged( void )) );
806 void FolderDialogTemplatesTab::load()
811 void FolderDialogTemplatesTab::initializeWithValuesFromFolder( KMFolder* folder ) {
812 if ( !folder )
813 return;
815 mFolder = folder;
817 QString fid = folder->idString();
819 Templates t( fid );
821 mCustom->setChecked(t.useCustomTemplates());
823 mIdentity = folder->identity();
825 mWidget->loadFromFolder( fid, mIdentity );
828 //-----------------------------------------------------------------------------
829 bool FolderDialogTemplatesTab::save()
831 KMFolder* folder = mDlg->folder();
833 QString fid = folder->idString();
834 Templates t(fid);
836 kDebug(5006) <<"use custom templates for folder" << fid <<":" << mCustom->isChecked();
837 t.setUseCustomTemplates(mCustom->isChecked());
838 t.writeConfig();
840 mWidget->saveToFolder(fid);
842 return true;
846 void FolderDialogTemplatesTab::slotEmitChanged() {}
848 void FolderDialogTemplatesTab::slotCopyGlobal() {
849 if ( mIdentity ) {
850 mWidget->loadFromIdentity( mIdentity );
852 else {
853 mWidget->loadFromGlobal();
857 #include "kmfolderdialog.moc"