kmail Library API Documentation

kmfolderdia.cpp

00001 // -*- mode: C++; c-file-style: "gnu" -*- 00033 #include <config.h> 00034 00035 #include "kmfolderdia.h" 00036 #include "kmacctfolder.h" 00037 #include "kmfoldermgr.h" 00038 #include <libkpimidentities/identitycombo.h> 00039 #include "kmfolderimap.h" 00040 #include "kmfoldercachedimap.h" 00041 #include "kmfolder.h" 00042 #include "kmkernel.h" 00043 #include "kmcommands.h" 00044 #include "mailinglist-magic.h" 00045 #include "kmfoldertree.h" 00046 #include "folderdiaacltab.h" 00047 #include "kmailicalifaceimpl.h" 00048 #include "kmmainwidget.h" 00049 00050 #include <keditlistbox.h> 00051 #include <klineedit.h> 00052 #include <klocale.h> 00053 #include <knuminput.h> 00054 #include <kmessagebox.h> 00055 #include <kicondialog.h> 00056 #include <kconfig.h> 00057 #include <kdebug.h> 00058 #include <klistview.h> 00059 00060 #include <qcheckbox.h> 00061 #include <qlayout.h> 00062 #include <qgroupbox.h> 00063 #include <qregexp.h> 00064 #include <qlabel.h> 00065 #include <qvbox.h> 00066 #include <qwhatsthis.h> 00067 00068 #include <assert.h> 00069 #include <qhbuttongroup.h> 00070 #include <qradiobutton.h> 00071 00072 #include "kmfolderdia.moc" 00073 00074 using namespace KMail; 00075 00076 //----------------------------------------------------------------------------- 00077 KMFolderDialog::KMFolderDialog(KMFolder *aFolder, KMFolderDir *aFolderDir, 00078 KMFolderTree* aParent, const QString& aCap, 00079 const QString& aName): 00080 KDialogBase( KDialogBase::Tabbed, 00081 aCap, KDialogBase::Ok|KDialogBase::Cancel, 00082 KDialogBase::Ok, aParent, "KMFolderDialog", TRUE ), 00083 mFolder( aFolder ), 00084 mFolderDir( aFolderDir ), 00085 mParentFolder( 0 ), 00086 mPositionInFolderList( 0 ), 00087 mIsNewFolder( aFolder == 0 ) 00088 { 00089 kdDebug(5006)<<"KMFolderDialog::KMFolderDialog()" << endl; 00090 00091 if( !mFolder ) { 00092 // new folder can be subfolder of any other folder 00093 aParent->createFolderList(&mFolderNameList, &mFolders, true, true, 00094 true, false, true, false); 00095 } 00096 else if( mFolder->folderType() != KMFolderTypeImap 00097 && mFolder->folderType() != KMFolderTypeCachedImap ) { 00098 // already existant local folder can only be moved locally 00099 aParent->createFolderList(&mFolderNameList, &mFolders, true, false, 00100 false, false, true, false); 00101 } 00102 else { 00103 // already existant IMAP folder can't be moved, but we add all 00104 // IMAP folders so that the correct parent folder can be shown 00105 aParent->createFolderList(&mFolderNameList, &mFolders, false, true, 00106 true, false, true, false); 00107 } 00108 00109 mFolderNameList.prepend( i18n( "Local Folders" ) ); 00110 00111 if( mFolderDir ) { 00112 // search the parent folder of the folder 00113 // kdDebug(5006) << "search the parent folder of the folder" << endl; 00114 FolderList::ConstIterator it; 00115 int i = 1; 00116 for( it = mFolders.begin(); it != mFolders.end(); ++it, ++i ) { 00117 // kdDebug(5006) << "checking folder '" << (*it)->label() << "'" << endl; 00118 if( (*it)->child() == mFolderDir ) { 00119 mParentFolder = *it; 00120 mPositionInFolderList = i; 00121 break; 00122 } 00123 } 00124 } 00125 00126 // Now create the folder list for the "move expired message to..." combo 00127 aParent->createFolderList(&mMoveToFolderNameList, &mMoveToFolderList, true, true, 00128 true, false, true, true); // all except search folders 00129 00130 00131 FolderDiaTab* tab; 00132 QVBox* box; 00133 00134 box = addVBoxPage( i18n("General") ); 00135 tab = new FolderDiaGeneralTab( this, aName, box ); 00136 addTab( tab ); 00137 00138 if ( !mFolder || !mFolder->noContent() ) 00139 { 00140 box = addVBoxPage( i18n("Old Message Expiry") ); 00141 tab = new FolderDiaExpiryTab( this, box ); 00142 addTab( tab ); 00143 00144 box = addVBoxPage( i18n("Mailing List") ); 00145 tab = new FolderDiaMailingListTab( this, box ); 00146 addTab( tab ); 00147 } 00148 00149 KMFolder* refFolder = mFolder ? mFolder : mParentFolder; 00150 KMFolderType folderType = refFolder ? refFolder->folderType() : KMFolderTypeUnknown; 00151 bool noContent = mFolder ? mFolder->storage()->noContent() : false; 00152 if ( !noContent && refFolder && ( folderType == KMFolderTypeImap || folderType == KMFolderTypeCachedImap ) ) { 00153 if ( FolderDiaACLTab::supports( refFolder ) ) { 00154 box = addVBoxPage( i18n("Access Control") ); 00155 tab = new FolderDiaACLTab( this, box ); 00156 addTab( tab ); 00157 } 00158 } 00159 00160 for ( unsigned int i = 0 ; i < mTabs.count() ; ++i ) 00161 mTabs[i]->load(); 00162 } 00163 00164 void KMFolderDialog::addTab( FolderDiaTab* tab ) 00165 { 00166 connect( tab, SIGNAL( readyForAccept() ), 00167 this, SLOT( slotReadyForAccept() ) ); 00168 connect( tab, SIGNAL( cancelAccept() ), 00169 this, SLOT( slotCancelAccept() ) ); 00170 //connect( tab, SIGNAL(changed( bool )), 00171 // this, SLOT(slotChanged( bool )) ); 00172 mTabs.append( tab ); 00173 } 00174 00175 // Not used yet (no button), but ready to be used :) 00176 void KMFolderDialog::slotApply() 00177 { 00178 if ( mFolder.isNull() && !mIsNewFolder ) { // deleted meanwhile? 00179 KDialogBase::slotApply(); 00180 return; 00181 } 00182 for ( unsigned int i = 0 ; i < mTabs.count() ; ++i ) 00183 mTabs[i]->save(); 00184 if ( !mFolder.isNull() && mIsNewFolder ) // we just created it 00185 mIsNewFolder = false; // so it's new anymore :) 00186 KDialogBase::slotApply(); 00187 } 00188 00189 // Called when pressing Ok 00190 // We want to apply the changes first (which is async), before closing the dialog, 00191 // in case of errors during the upload. 00192 void KMFolderDialog::slotOk() 00193 { 00194 if ( mFolder.isNull() && !mIsNewFolder ) { // deleted meanwhile? 00195 KDialogBase::slotOk(); 00196 return; 00197 } 00198 00199 mDelayedSavingTabs = 0; // number of tabs which need delayed saving 00200 for ( unsigned int i = 0 ; i < mTabs.count() ; ++i ) { 00201 FolderDiaTab::AcceptStatus s = mTabs[i]->accept(); 00202 if ( s == FolderDiaTab::Canceled ) { 00203 slotCancelAccept(); 00204 return; 00205 } 00206 else if ( s == FolderDiaTab::Delayed ) 00207 ++mDelayedSavingTabs; 00208 } 00209 00210 if ( mDelayedSavingTabs ) 00211 enableButtonOK( false ); 00212 else 00213 KDialogBase::slotOk(); 00214 } 00215 00216 void KMFolderDialog::slotReadyForAccept() 00217 { 00218 --mDelayedSavingTabs; 00219 if ( mDelayedSavingTabs == 0 ) 00220 KDialogBase::slotOk(); 00221 } 00222 00223 void KMFolderDialog::slotCancelAccept() 00224 { 00225 mDelayedSavingTabs = -1; 00226 enableButtonOK( true ); 00227 // Don't try to create it twice 00228 if ( !mFolder.isNull() ) 00229 mIsNewFolder = false; 00230 00231 // Other tabs might call slotReadyForAccept. -1 ensures that it won't close the dialog, 00232 // but the OK button being enabled means that people might succeed in running 00233 // the same job from save more than once. 00234 // Solution: mAcceptCanceled = true instead of -1. 00235 // Bah for now we only have one tab which can delay saving -> later. 00236 } 00237 00238 void KMFolderDialog::slotChanged( bool ) 00239 { 00240 // TODO, support for 'changed', and Apply button. 00241 // sample code for here: KCMultiDialog calls bool changed() on every KCModuleProxy... 00242 } 00243 00244 void KMFolderDialog::setFolder( KMFolder* folder ) 00245 { 00246 Q_ASSERT( mFolder.isNull() ); 00247 mFolder = folder; 00248 } 00249 00250 //---------------------------------------------------------------------------- 00251 KMail::FolderDiaGeneralTab::FolderDiaGeneralTab( KMFolderDialog* dlg, 00252 const QString& aName, 00253 QWidget* parent, const char* name ) 00254 : FolderDiaTab( parent, name ), mDlg( dlg ) 00255 { 00256 QLabel *label; 00257 00258 QVBoxLayout *topLayout = new QVBoxLayout( this, 0, KDialog::spacingHint() ); 00259 00260 QGroupBox *fpGroup = new QGroupBox( i18n("Folder Position"), this, "fpGroup" ); 00261 fpGroup->setColumnLayout( 0, Qt::Vertical ); 00262 00263 topLayout->addWidget( fpGroup ); 00264 00265 QHBoxLayout *hl = new QHBoxLayout( fpGroup->layout() ); 00266 hl->setSpacing( 6 ); 00267 00268 label = new QLabel( i18n("&Name:"), fpGroup ); 00269 hl->addWidget( label ); 00270 00271 mNameEdit = new KLineEdit( fpGroup ); 00272 if( !mDlg->folder() ) 00273 mNameEdit->setFocus(); 00274 mNameEdit->setText( mDlg->folder() ? mDlg->folder()->label() : i18n("unnamed") ); 00275 if (!aName.isEmpty()) 00276 mNameEdit->setText(aName); 00277 mNameEdit->setMinimumSize(mNameEdit->sizeHint()); 00278 label->setBuddy( mNameEdit ); 00279 hl->addWidget( mNameEdit ); 00280 connect( mNameEdit, SIGNAL( textChanged( const QString & ) ), 00281 this, SLOT( slotFolderNameChanged( const QString & ) ) ); 00282 00283 QLabel* belongsToLabel = new QLabel( i18n("&Belongs to:" ), fpGroup ); 00284 hl->addWidget( belongsToLabel ); 00285 00286 mBelongsToComboBox = new QComboBox(fpGroup); 00287 hl->addWidget( mBelongsToComboBox ); 00288 belongsToLabel->setBuddy( mBelongsToComboBox ); 00289 00290 //start icons group 00291 QGroupBox *iconGroup = new QGroupBox( i18n("Folder Icons"), this, "iconGroup" ); 00292 iconGroup->setColumnLayout( 0, Qt::Vertical ); 00293 00294 topLayout->addWidget( iconGroup ); 00295 00296 QVBoxLayout *ivl = new QVBoxLayout( iconGroup->layout() ); 00297 ivl->setSpacing( 6 ); 00298 00299 QHBoxLayout *ihl = new QHBoxLayout( ivl ); 00300 mIconsCheckBox = new QCheckBox( i18n("Use custom &icons"), iconGroup ); 00301 mIconsCheckBox->setChecked( false ); 00302 ihl->addWidget( mIconsCheckBox ); 00303 ihl->addStretch( 2 ); 00304 00305 mNormalIconLabel = new QLabel( i18n("&Normal:"), iconGroup ); 00306 mNormalIconLabel->setEnabled( false ); 00307 ihl->addWidget( mNormalIconLabel ); 00308 00309 mNormalIconButton = new KIconButton( iconGroup ); 00310 mNormalIconLabel->setBuddy( mNormalIconButton ); 00311 mNormalIconButton->setIconType( KIcon::NoGroup , KIcon::Any, true ); 00312 mNormalIconButton->setIconSize( 16 ); 00313 mNormalIconButton->setStrictIconSize( true ); 00314 mNormalIconButton->setFixedSize( 28, 28 ); 00315 mNormalIconButton->setIcon( QString("folder") ); 00316 mNormalIconButton->setEnabled( false ); 00317 ihl->addWidget( mNormalIconButton ); 00318 00319 mUnreadIconLabel = new QLabel( i18n("&Unread:"), iconGroup ); 00320 mUnreadIconLabel->setEnabled( false ); 00321 ihl->addWidget( mUnreadIconLabel ); 00322 00323 mUnreadIconButton = new KIconButton( iconGroup ); 00324 mUnreadIconLabel->setBuddy( mUnreadIconButton ); 00325 mUnreadIconButton->setIconType( KIcon::NoGroup, KIcon::Any, true ); 00326 mUnreadIconButton->setIconSize( 16 ); 00327 mUnreadIconButton->setStrictIconSize( true ); 00328 mUnreadIconButton->setFixedSize( 28, 28 ); 00329 mUnreadIconButton->setIcon( QString("folder_open") ); 00330 mUnreadIconButton->setEnabled( false ); 00331 ihl->addWidget( mUnreadIconButton ); 00332 ihl->addStretch( 1 ); 00333 00334 connect( mIconsCheckBox, SIGNAL(toggled(bool)), 00335 mNormalIconButton, SLOT(setEnabled(bool)) ); 00336 connect( mIconsCheckBox, SIGNAL(toggled(bool)), 00337 mUnreadIconButton, SLOT(setEnabled(bool)) ); 00338 connect( mIconsCheckBox, SIGNAL(toggled(bool)), 00339 mNormalIconLabel, SLOT(setEnabled(bool)) ); 00340 connect( mIconsCheckBox, SIGNAL(toggled(bool)), 00341 mUnreadIconLabel, SLOT(setEnabled(bool)) ); 00342 00343 connect( mNormalIconButton, SIGNAL(iconChanged(QString)), 00344 this, SLOT(slotChangeIcon(QString)) ); 00345 00346 //end icons group 00347 00348 mMailboxTypeGroupBox = new QGroupBox( i18n("Folder Type"), this, "mMailboxTypeGroupBox" ); 00349 mMailboxTypeGroupBox->setColumnLayout( 0, Qt::Vertical ); 00350 00351 topLayout->addWidget( mMailboxTypeGroupBox ); 00352 00353 QHBoxLayout *ml = new QHBoxLayout( mMailboxTypeGroupBox->layout() ); 00354 ml->setSpacing( 6 ); 00355 00356 QLabel *label_type = new QLabel( i18n("&Mailbox format:" ), mMailboxTypeGroupBox ); 00357 ml->addWidget( label_type ); 00358 mMailboxTypeComboBox = new QComboBox(mMailboxTypeGroupBox); 00359 label_type->setBuddy( mMailboxTypeComboBox ); 00360 mMailboxTypeComboBox->insertItem("mbox", 0); 00361 mMailboxTypeComboBox->insertItem("maildir", 1); 00362 mMailboxTypeComboBox->insertItem("search", 2); 00363 { 00364 KConfig *config = KMKernel::config(); 00365 KConfigGroupSaver saver(config, "General"); 00366 int type = config->readNumEntry("default-mailbox-format", 1); 00367 if ( type < 0 || type > 1 ) type = 1; 00368 mMailboxTypeComboBox->setCurrentItem( type ); 00369 } 00370 mMailboxTypeComboBox->setEnabled( !mDlg->folder() ); 00371 ml->addWidget( mMailboxTypeComboBox ); 00372 ml->addStretch( 1 ); 00373 00374 mBelongsToComboBox->insertStringList( mDlg->folderNameList() ); 00375 // we want to know if the activated changes 00376 connect( mBelongsToComboBox, SIGNAL(activated(int)), SLOT(slotUpdateItems(int)) ); 00377 00378 QGroupBox *idGroup = new QGroupBox( i18n("Identity" ), this ); 00379 idGroup->setColumnLayout( 0, Qt::Vertical ); 00380 QHBoxLayout *idLayout = new QHBoxLayout(idGroup->layout()); 00381 idLayout->setSpacing( 6 ); 00382 topLayout->addWidget( idGroup ); 00383 00384 label = new QLabel( i18n("&Sender:"), idGroup ); 00385 idLayout->addWidget( label ); 00386 mIdentityComboBox = new KPIM::IdentityCombo( kmkernel->identityManager(), idGroup ); 00387 label->setBuddy( mIdentityComboBox ); 00388 idLayout->addWidget( mIdentityComboBox, 3 ); 00389 00390 QGroupBox* senderGroup = new QGroupBox( i18n("Show Sender/Receiver"), this, "senderGroup" ); 00391 senderGroup->setColumnLayout( 0, Qt::Vertical ); 00392 00393 topLayout->addWidget( senderGroup ); 00394 00395 QHBoxLayout *sl = new QHBoxLayout( senderGroup->layout() ); 00396 sl->setSpacing( 6 ); 00397 00398 QLabel *sender_label = new QLabel( i18n("Sho&w:" ), senderGroup ); 00399 sl->addWidget( sender_label ); 00400 mShowSenderReceiverComboBox = new QComboBox(senderGroup); 00401 sender_label->setBuddy(mShowSenderReceiverComboBox); 00402 mShowSenderReceiverComboBox->insertItem(i18n("Default"), 0); 00403 mShowSenderReceiverComboBox->insertItem(i18n("Sender"), 1); 00404 mShowSenderReceiverComboBox->insertItem(i18n("Receiver"), 2); 00405 00406 QString whoField; 00407 if (mDlg->folder()) whoField = mDlg->folder()->userWhoField(); 00408 if (whoField.isEmpty()) mShowSenderReceiverComboBox->setCurrentItem(0); 00409 if (whoField == "From") mShowSenderReceiverComboBox->setCurrentItem(1); 00410 if (whoField == "To") mShowSenderReceiverComboBox->setCurrentItem(2); 00411 00412 sl->addWidget( mShowSenderReceiverComboBox ); 00413 sl->addStretch( 1 ); 00414 00415 if ( kmkernel->iCalIface().isEnabled() && 00416 !kmkernel->iCalIface().isResourceImapFolder( mDlg->folder() ) ) { 00417 // Only do make this settable, if the IMAP resource is enabled 00418 // and it's not the personal folders (those must not be changed) 00419 QGroupBox *typeGroup = new QGroupBox( i18n("Contents" ), this ); 00420 typeGroup->setColumnLayout( 0, Qt::Vertical ); 00421 QHBoxLayout *typeLayout = new QHBoxLayout( typeGroup->layout() ); 00422 typeLayout->setSpacing( 6 ); 00423 topLayout->addWidget( typeGroup ); 00424 label = new QLabel( i18n("&Folder contents:"), typeGroup ); 00425 typeLayout->addWidget( label ); 00426 mContentsComboBox = new QComboBox( typeGroup ); 00427 label->setBuddy( mContentsComboBox ); 00428 typeLayout->addWidget( mContentsComboBox, 3 ); 00429 00430 mContentsComboBox->insertItem( i18n( "Mail" ) ); 00431 mContentsComboBox->insertItem( i18n( "Calendar" ) ); 00432 mContentsComboBox->insertItem( i18n( "Contacts" ) ); 00433 mContentsComboBox->insertItem( i18n( "Notes" ) ); 00434 mContentsComboBox->insertItem( i18n( "Tasks" ) ); 00435 mContentsComboBox->insertItem( i18n( "Journal" ) ); 00436 if ( mDlg->folder() ) 00437 mContentsComboBox->setCurrentItem( mDlg->folder()->storage()->contentsType() ); 00438 } else 00439 mContentsComboBox = 0; 00440 00441 // should this folder be included in new-mail-checks? 00442 QGroupBox* newmailGroup = new QGroupBox( i18n("Check for New Mail"), this, "newmailGroup" ); 00443 newmailGroup->setColumnLayout( 0, Qt::Vertical ); 00444 topLayout->addWidget( newmailGroup ); 00445 00446 QHBoxLayout *nml = new QHBoxLayout( newmailGroup->layout() ); 00447 nml->setSpacing( 6 ); 00448 mNewMailCheckBox = new QCheckBox( i18n("Include in check" ), newmailGroup ); 00449 // default is on 00450 mNewMailCheckBox->setChecked(true); 00451 nml->addWidget( mNewMailCheckBox ); 00452 nml->addStretch( 1 ); 00453 00454 // should new mail in this folder be ignored? 00455 QGroupBox* notifyGroup = new QGroupBox( i18n("New Mail Notification"), this, 00456 "notifyGroup" ); 00457 notifyGroup->setColumnLayout( 0, Qt::Vertical ); 00458 topLayout->addWidget( notifyGroup ); 00459 00460 QHBoxLayout *hbl = new QHBoxLayout( notifyGroup->layout() ); 00461 hbl->setSpacing( KDialog::spacingHint() ); 00462 mIgnoreNewMailCheckBox = 00463 new QCheckBox( i18n("Ignore new mail in this folder" ), notifyGroup ); 00464 QWhatsThis::add( mIgnoreNewMailCheckBox, 00465 i18n( "Check this option if you do not want to be notified " 00466 "about new mail that is moved to this folder; this " 00467 "is useful, for example, for ignoring spam." ) ); 00468 hbl->addWidget( mIgnoreNewMailCheckBox ); 00469 hbl->addStretch( 1 ); 00470 00471 // should replies to mails in this folder be kept in this same folder? 00472 QGroupBox* replyGroup = new QGroupBox( i18n("Reply Handling"), this, 00473 "replyGroup" ); 00474 replyGroup->setColumnLayout( 0, Qt::Vertical ); 00475 topLayout->addWidget( replyGroup ); 00476 00477 hbl = new QHBoxLayout( replyGroup->layout() ); 00478 hbl->setSpacing( KDialog::spacingHint() ); 00479 mKeepRepliesInSameFolderCheckBox = 00480 new QCheckBox( i18n("Keep replies in this folder" ), replyGroup ); 00481 QWhatsThis::add( mKeepRepliesInSameFolderCheckBox, 00482 i18n( "Check this option if you want replies you write " 00483 "to mails in this folder to be put in this same folder " 00484 "after sending, instead of in the configured sent-mail folder." ) ); 00485 hbl->addWidget( mKeepRepliesInSameFolderCheckBox ); 00486 hbl->addStretch( 1 ); 00487 00488 topLayout->addStretch( 100 ); // eat all superfluous space 00489 00490 KMFolder* parentFolder = mDlg->parentFolder(); 00491 00492 if ( parentFolder ) { 00493 mBelongsToComboBox->setCurrentItem( mDlg->positionInFolderList() ); 00494 slotUpdateItems( mDlg->positionInFolderList() ); 00495 } 00496 00497 if ( mDlg->folder() ) { 00498 // existing folder 00499 initializeWithValuesFromFolder( mDlg->folder() ); 00500 00501 // mailbox folder type 00502 switch ( mDlg->folder()->folderType() ) { 00503 case KMFolderTypeSearch: 00504 mMailboxTypeComboBox->setCurrentItem( 2 ); 00505 belongsToLabel->hide(); 00506 mBelongsToComboBox->hide(); 00507 newmailGroup->hide(); 00508 break; 00509 case KMFolderTypeMaildir: 00510 mMailboxTypeComboBox->setCurrentItem( 1 ); 00511 newmailGroup->hide(); 00512 break; 00513 case KMFolderTypeMbox: 00514 mMailboxTypeComboBox->setCurrentItem( 0 ); 00515 newmailGroup->hide(); 00516 break; 00517 case KMFolderTypeImap: 00518 belongsToLabel->setEnabled( false ); 00519 mBelongsToComboBox->setEnabled( false ); 00520 mMailboxTypeGroupBox->hide(); 00521 break; 00522 case KMFolderTypeCachedImap: 00523 belongsToLabel->setEnabled( false ); 00524 mBelongsToComboBox->setEnabled( false ); 00525 mMailboxTypeGroupBox->hide(); 00526 newmailGroup->hide(); 00527 break; 00528 default: ; 00529 } 00530 } 00531 00532 else if ( parentFolder ) { 00533 // new folder 00534 initializeWithValuesFromFolder( parentFolder ); 00535 00536 // mailbox folder type 00537 switch ( parentFolder->folderType() ) { 00538 case KMFolderTypeSearch: 00539 mMailboxTypeComboBox->setCurrentItem( 2 ); 00540 belongsToLabel->hide(); 00541 mBelongsToComboBox->hide(); 00542 newmailGroup->hide(); 00543 break; 00544 case KMFolderTypeMaildir: 00545 newmailGroup->hide(); 00546 break; 00547 case KMFolderTypeMbox: 00548 newmailGroup->hide(); 00549 break; 00550 case KMFolderTypeImap: 00551 mMailboxTypeGroupBox->hide(); 00552 break; 00553 case KMFolderTypeCachedImap: 00554 mMailboxTypeGroupBox->hide(); 00555 newmailGroup->hide(); 00556 break; 00557 default: ; 00558 } 00559 } 00560 00561 // Musn't be able to edit details for a system folder. 00562 // Make sure we don't bomb out if there isn't a folder 00563 // object yet (i.e. just about to create new folder). 00564 00565 if ( mDlg->folder() && mDlg->folder()->isSystemFolder() && 00566 mDlg->folder()->folderType() != KMFolderTypeImap && 00567 mDlg->folder()->folderType() != KMFolderTypeCachedImap ) { 00568 fpGroup->hide(); 00569 iconGroup->hide(); 00570 mMailboxTypeGroupBox->hide(); 00571 idGroup->hide(); 00572 } 00573 } 00574 00575 void FolderDiaGeneralTab::load() 00576 { 00577 // Nothing here, all is done in the ctor 00578 } 00579 00580 void FolderDiaGeneralTab::initializeWithValuesFromFolder( KMFolder* folder ) { 00581 if ( !folder ) 00582 return; 00583 00584 // folder icons 00585 mIconsCheckBox->setChecked( folder->useCustomIcons() ); 00586 mNormalIconLabel->setEnabled( folder->useCustomIcons() ); 00587 mNormalIconButton->setEnabled( folder->useCustomIcons() ); 00588 mUnreadIconLabel->setEnabled( folder->useCustomIcons() ); 00589 mUnreadIconButton->setEnabled( folder->useCustomIcons() ); 00590 QString iconPath = folder->normalIconPath(); 00591 if ( !iconPath.isEmpty() ) 00592 mNormalIconButton->setIcon( iconPath ); 00593 iconPath = folder->unreadIconPath(); 00594 if ( !iconPath.isEmpty() ) 00595 mUnreadIconButton->setIcon( iconPath ); 00596 00597 // folder identity 00598 mIdentityComboBox->setCurrentIdentity( folder->identity() ); 00599 00600 // ignore new mail 00601 mIgnoreNewMailCheckBox->setChecked( folder->ignoreNewMail() ); 00602 00603 mKeepRepliesInSameFolderCheckBox->setChecked( folder->putRepliesInSameFolder() ); 00604 00605 if (folder->folderType() == KMFolderTypeImap) 00606 { 00607 KMFolderImap* imapFolder = static_cast<KMFolderImap*>(folder->storage()); 00608 bool checked = imapFolder->includeInMailCheck(); 00609 mNewMailCheckBox->setChecked(checked); 00610 } 00611 } 00612 00613 //----------------------------------------------------------------------------- 00614 void FolderDiaGeneralTab::slotFolderNameChanged( const QString& str ) 00615 { 00616 mDlg->enableButtonOK( !str.isEmpty() ); 00617 } 00618 00619 //----------------------------------------------------------------------------- 00620 void FolderDiaGeneralTab::slotUpdateItems ( int current ) 00621 { 00622 KMFolder* selectedFolder = 0; 00623 // check if the index is valid (the top level has no entrance in the mDlg->folders()) 00624 if (current > 0) selectedFolder = *mDlg->folders().at(current - 1); 00625 if (selectedFolder && (selectedFolder->folderType() == KMFolderTypeImap || 00626 selectedFolder->folderType() == KMFolderTypeCachedImap)) 00627 { 00628 // deactivate stuff that is not available for imap 00629 mMailboxTypeGroupBox->setEnabled( false ); 00630 } else { 00631 // activate it 00632 mMailboxTypeGroupBox->setEnabled( true ); 00633 } 00634 } 00635 00636 //----------------------------------------------------------------------------- 00637 bool FolderDiaGeneralTab::save() 00638 { 00639 // moving of IMAP folders is not yet supported 00640 if ( mDlg->isNewFolder() || !mDlg->folder()->isSystemFolder() ) 00641 { 00642 QString acctName; 00643 QString fldName, oldFldName; 00644 KMFolderDir *selectedFolderDir = &(kmkernel->folderMgr()->dir()); 00645 KMFolder *selectedFolder = 0; 00646 int curFolder = mBelongsToComboBox->currentItem(); 00647 00648 if( !mDlg->isNewFolder() ) oldFldName = mDlg->folder()->name(); 00649 if (!mNameEdit->text().isEmpty()) fldName = mNameEdit->text(); 00650 else fldName = oldFldName; 00651 if ( mDlg->parentFolder() && 00652 mDlg->parentFolder()->folderType() != KMFolderTypeImap && 00653 mDlg->parentFolder()->folderType() != KMFolderTypeCachedImap ) 00654 fldName.remove('/'); 00655 fldName.remove(QRegExp("^\\.*")); 00656 if (fldName.isEmpty()) fldName = i18n("unnamed"); 00657 00658 if (mMailboxTypeComboBox->currentItem() == 2) { 00659 selectedFolderDir = &(kmkernel->searchFolderMgr()->dir()); 00660 } 00661 else if (curFolder != 0) 00662 { 00663 selectedFolder = *mDlg->folders().at(curFolder - 1); 00664 selectedFolderDir = selectedFolder->createChildFolder(); 00665 } 00666 00667 QString message = i18n( "<qt>Failed to create folder <b>%1</b>, folder already exists.</qt>" ).arg(fldName); 00668 if( selectedFolderDir->hasNamedFolder( fldName ) 00669 && ( !( mDlg->folder() 00670 && ( selectedFolderDir == mDlg->folder()->parent() ) 00671 && ( mDlg->folder()->name() == fldName ) ) ) ) 00672 { 00673 KMessageBox::error( this, message ); 00674 return false; 00675 } 00676 00677 message = i18n( "<qt>Cannot move folder <b>%1</b> into a subfolder below itself.</qt>" ).arg(fldName); 00678 KMFolderDir* folderDir = selectedFolderDir; 00679 00680 00681 // Buggy? 00682 if( mDlg->folder() && mDlg->folder()->child() ) 00683 while( ( folderDir != &kmkernel->folderMgr()->dir() ) 00684 && ( folderDir != mDlg->folder()->parent() ) ) { 00685 if( folderDir->findRef( mDlg->folder() ) != -1 ) { 00686 KMessageBox::error( this, message ); 00687 return false; 00688 } 00689 folderDir = folderDir->parent(); 00690 } 00691 // End buggy? 00692 00693 00694 if( mDlg->folder() && mDlg->folder()->child() && selectedFolderDir && 00695 ( selectedFolderDir->path().find( mDlg->folder()->child()->path() + "/" ) == 0 ) ) { 00696 KMessageBox::error( this, message ); 00697 return false; 00698 } 00699 00700 if( mDlg->folder() && mDlg->folder()->child() 00701 && ( selectedFolderDir == mDlg->folder()->child() ) ) { 00702 KMessageBox::error( this, message ); 00703 return false; 00704 } 00705 00706 if( mDlg->isNewFolder() ) { 00707 if (selectedFolder && selectedFolder->folderType() == KMFolderTypeImap) 00708 { 00709 mDlg->setFolder( kmkernel->imapFolderMgr()->createFolder( fldName, FALSE, KMFolderTypeImap, selectedFolderDir ) ); 00710 KMFolderImap* selectedStorage = static_cast<KMFolderImap*>(selectedFolder->storage()); 00711 selectedStorage->createFolder(fldName); // create it on the server 00712 static_cast<KMFolderImap*>(mDlg->folder()->storage())->setAccount( selectedStorage->account() ); 00713 } else if (selectedFolder && selectedFolder->folderType() == KMFolderTypeCachedImap){ 00714 mDlg->setFolder( kmkernel->dimapFolderMgr()->createFolder( fldName, FALSE, KMFolderTypeCachedImap, selectedFolderDir ) ); 00715 KMFolderCachedImap* selectedStorage = static_cast<KMFolderCachedImap*>(selectedFolder->storage()); 00716 KMFolderCachedImap* newStorage = static_cast<KMFolderCachedImap*>(mDlg->folder()->storage()); 00717 newStorage->initializeFrom( selectedStorage ); 00718 } else if (mMailboxTypeComboBox->currentItem() == 2) { 00719 mDlg->setFolder( kmkernel->searchFolderMgr()->createFolder(fldName, FALSE, KMFolderTypeSearch, &kmkernel->searchFolderMgr()->dir() ) ); 00720 } else if (mMailboxTypeComboBox->currentItem() == 1) { 00721 mDlg->setFolder( kmkernel->folderMgr()->createFolder(fldName, FALSE, KMFolderTypeMaildir, selectedFolderDir ) ); 00722 } else { 00723 mDlg->setFolder( kmkernel->folderMgr()->createFolder(fldName, FALSE, KMFolderTypeMbox, selectedFolderDir ) ); 00724 } 00725 } 00726 else if( ( oldFldName != fldName ) 00727 || ( mDlg->folder()->parent() != selectedFolderDir ) ) 00728 { 00729 if( mDlg->folder()->parent() != selectedFolderDir ) { 00730 if( mDlg->folder()->folderType() == KMFolderTypeCachedImap ) { 00731 QString message = i18n("Moving IMAP folders is not supported"); 00732 KMessageBox::error( this, message ); 00733 } else 00734 mDlg->folder()->rename(fldName, selectedFolderDir ); 00735 } else 00736 mDlg->folder()->rename(fldName); 00737 00738 kmkernel->folderMgr()->contentsChanged(); 00739 } 00740 } 00741 00742 KMFolder* folder = mDlg->folder(); 00743 if( folder ) { 00744 folder->setIdentity( mIdentityComboBox->currentIdentity() ); 00745 00746 // Update the tree iff new icon paths are different and not empty or if 00747 // useCustomIcons changed. 00748 if ( folder->useCustomIcons() != mIconsCheckBox->isChecked() ) { 00749 folder->setUseCustomIcons( mIconsCheckBox->isChecked() ); 00750 // Reset icons, useCustomIcons was turned off. 00751 if ( !folder->useCustomIcons() ) { 00752 folder->setIconPaths( "", "" ); 00753 } 00754 } 00755 if ( folder->useCustomIcons() && 00756 (( mNormalIconButton->icon() != folder->normalIconPath() ) && 00757 ( !mNormalIconButton->icon().isEmpty())) || 00758 (( mUnreadIconButton->icon() != folder->unreadIconPath() ) && 00759 ( !mUnreadIconButton->icon().isEmpty())) ) { 00760 folder->setIconPaths( mNormalIconButton->icon(), mUnreadIconButton->icon() ); 00761 } 00762 // set whoField 00763 if (mShowSenderReceiverComboBox->currentItem() == 1) 00764 folder->setUserWhoField("From"); 00765 else if (mShowSenderReceiverComboBox->currentItem() == 2) 00766 folder->setUserWhoField("To"); 00767 else 00768 folder->setUserWhoField(QString::null); 00769 00770 // Set type field 00771 if ( mContentsComboBox ) 00772 folder->storage()->setContentsType( static_cast<KMail::FolderContentsType>( mContentsComboBox->currentItem() ) ); 00773 00774 folder->setIgnoreNewMail( mIgnoreNewMailCheckBox->isChecked() ); 00775 kmkernel->folderMgr()->contentsChanged(); 00776 00777 folder->setPutRepliesInSameFolder( mKeepRepliesInSameFolderCheckBox->isChecked() ); 00778 00779 if( mDlg->isNewFolder() ) 00780 folder->close(); 00781 00782 if( folder->folderType() == KMFolderTypeImap ) 00783 { 00784 KMFolderImap* imapFolder = static_cast<KMFolderImap*>( folder->storage() ); 00785 imapFolder->setIncludeInMailCheck( 00786 mNewMailCheckBox->isChecked() ); 00787 } 00788 } 00789 return true; 00790 } 00791 00792 void FolderDiaGeneralTab::slotChangeIcon( QString icon ) // can't use a const-ref here, due to KIconButton's signal 00793 { 00794 mUnreadIconButton->setIcon( icon ); 00795 } 00796 00797 //---------------------------------------------------------------------------- 00798 KMail::FolderDiaExpiryTab::FolderDiaExpiryTab( KMFolderDialog* dlg, 00799 QWidget* parent, 00800 const char* name ) 00801 : FolderDiaTab( parent, name ), mDlg( dlg ) 00802 { 00803 QLabel *label; 00804 00805 QVBoxLayout *topLayout = new QVBoxLayout( this, 0, KDialog::spacingHint() ); 00806 00807 // Checkbox for setting whether expiry is enabled on this folder. 00808 mExpireFolderCheckBox = 00809 new QCheckBox( i18n("E&xpire old messages in this folder"), this ); 00810 QObject::connect( mExpireFolderCheckBox, SIGNAL( toggled( bool ) ), 00811 this, SLOT( slotExpireFolder( bool ) ) ); 00812 topLayout->addWidget( mExpireFolderCheckBox ); 00813 00814 QGridLayout *expLayout = new QGridLayout( topLayout ); 00815 00816 // Expiry time for read documents. 00817 label = new QLabel( i18n("Expire &read email after:"), this ); 00818 label->setEnabled( false ); 00819 QObject::connect( mExpireFolderCheckBox, SIGNAL( toggled( bool ) ), 00820 label, SLOT( setEnabled( bool ) ) ); 00821 expLayout->addWidget( label, 1, 0 ); 00822 00823 mReadExpiryTimeNumInput = new KIntNumInput( this ); 00824 mReadExpiryTimeNumInput->setRange( 1, 500, 1, false ); 00825 label->setBuddy( mReadExpiryTimeNumInput ); 00826 expLayout->addWidget( mReadExpiryTimeNumInput, 1, 1 ); 00827 00828 mReadExpiryUnitsComboBox = new QComboBox( this ); 00829 mReadExpiryUnitsComboBox->insertItem( i18n("Never") ); 00830 mReadExpiryUnitsComboBox->insertItem( i18n("Day(s)") ); 00831 mReadExpiryUnitsComboBox->insertItem( i18n("Week(s)") ); 00832 mReadExpiryUnitsComboBox->insertItem( i18n("Month(s)") ); 00833 expLayout->addWidget( mReadExpiryUnitsComboBox, 1, 2 ); 00834 connect( mReadExpiryUnitsComboBox, SIGNAL( activated( int ) ), 00835 this, SLOT( slotReadExpiryUnitChanged( int ) ) ); 00836 00837 // Expiry time for unread documents. 00838 label = new QLabel( i18n("Expire unr&ead email after:"), this ); 00839 label->setEnabled(false); 00840 QObject::connect( mExpireFolderCheckBox, SIGNAL( toggled( bool ) ), 00841 label, SLOT( setEnabled( bool ) ) ); 00842 expLayout->addWidget( label, 2, 0 ); 00843 00844 mUnreadExpiryTimeNumInput = new KIntNumInput( this ); 00845 mUnreadExpiryTimeNumInput->setRange( 1, 500, 1, false ); 00846 label->setBuddy( mUnreadExpiryTimeNumInput ); 00847 expLayout->addWidget( mUnreadExpiryTimeNumInput, 2, 1 ); 00848 00849 mUnreadExpiryUnitsComboBox = new QComboBox( this ); 00850 mUnreadExpiryUnitsComboBox->insertItem( i18n("Never") ); 00851 mUnreadExpiryUnitsComboBox->insertItem( i18n("Day(s)") ); 00852 mUnreadExpiryUnitsComboBox->insertItem( i18n("Week(s)") ); 00853 mUnreadExpiryUnitsComboBox->insertItem( i18n("Month(s)") ); 00854 expLayout->addWidget( mUnreadExpiryUnitsComboBox, 2, 2 ); 00855 connect( mUnreadExpiryUnitsComboBox, SIGNAL( activated( int ) ), 00856 this, SLOT( slotUnreadExpiryUnitChanged( int ) ) ); 00857 00858 expLayout->setColStretch( 3, 100 ); 00859 00860 // delete or archive old messages 00861 QButtonGroup* radioBG = new QButtonGroup( this ); 00862 radioBG->hide(); // just for the exclusive behavior 00863 mExpireActionDelete = new QRadioButton( i18n( "Delete old messages" ), 00864 this ); 00865 radioBG->insert( mExpireActionDelete ); 00866 topLayout->addWidget( mExpireActionDelete ); 00867 00868 QHBoxLayout *hbl = new QHBoxLayout( topLayout ); 00869 mExpireActionMove = new QRadioButton( i18n( "Move old messages to:" ), 00870 this ); 00871 radioBG->insert( mExpireActionMove ); 00872 hbl->addWidget( mExpireActionMove ); 00873 mExpireToFolderComboBox = new QComboBox( this ); 00874 hbl->addWidget( mExpireToFolderComboBox ); 00875 mExpireToFolderComboBox->insertStringList( mDlg->moveToFolderNameList() ); 00876 hbl->addStretch( 100 ); 00877 00878 topLayout->addStretch( 100 ); // eat all superfluous space 00879 00880 connect( mExpireFolderCheckBox, SIGNAL( toggled( bool ) ), 00881 mExpireActionDelete, SLOT( setEnabled( bool ) ) ); 00882 connect( mExpireFolderCheckBox, SIGNAL( toggled( bool ) ), 00883 mExpireActionMove, SLOT( setEnabled( bool ) ) ); 00884 connect( mExpireFolderCheckBox, SIGNAL( toggled( bool ) ), 00885 mExpireToFolderComboBox, SLOT( setEnabled( bool ) ) ); 00886 } 00887 00888 void FolderDiaExpiryTab::load() 00889 { 00890 KMFolder* folder = mDlg->folder(); 00891 if( folder ) { 00892 // settings for automatic deletion of old messages 00893 mExpireFolderCheckBox->setChecked( folder->isAutoExpire() ); 00894 // Legal values for units are 0=never, 1=days, 2=weeks, 3=months. 00895 if( folder->getReadExpireUnits() >= 0 00896 && folder->getReadExpireUnits() < expireMaxUnits ) { 00897 mReadExpiryUnitsComboBox->setCurrentItem( folder->getReadExpireUnits() ); 00898 } 00899 if( folder->getUnreadExpireUnits() >= 0 00900 && folder->getUnreadExpireUnits() < expireMaxUnits ) { 00901 mUnreadExpiryUnitsComboBox->setCurrentItem( folder->getUnreadExpireUnits() ); 00902 } 00903 int age = folder->getReadExpireAge(); 00904 if ( age >= 1 && age <= 500 ) { 00905 mReadExpiryTimeNumInput->setValue( age ); 00906 } else { 00907 mReadExpiryTimeNumInput->setValue( 7 ); 00908 } 00909 age = folder->getUnreadExpireAge(); 00910 if ( age >= 1 && age <= 500 ) { 00911 mUnreadExpiryTimeNumInput->setValue( age ); 00912 } else { 00913 mUnreadExpiryTimeNumInput->setValue( 28 ); 00914 } 00915 if ( folder->expireAction() == KMFolder::ExpireDelete ) 00916 mExpireActionDelete->setChecked( true ); 00917 else 00918 mExpireActionMove->setChecked( true ); 00919 QString destFolderID = folder->expireToFolderId(); 00920 if ( !destFolderID.isEmpty() ) { 00921 KMFolderDialog::FolderList moveToFolderList = mDlg->moveToFolderList(); 00922 KMFolder* destFolder = kmkernel->findFolderById( destFolderID ); 00923 int pos = moveToFolderList.findIndex( QGuardedPtr<KMFolder>( destFolder ) ); 00924 if ( pos > -1 ) 00925 mExpireToFolderComboBox->setCurrentItem( pos ); 00926 } 00927 } else { // new folder, use default values 00928 mReadExpiryTimeNumInput->setValue( 7 ); 00929 mUnreadExpiryTimeNumInput->setValue(28); 00930 mExpireActionDelete->setChecked( true ); 00931 } 00932 if( !folder || !folder->isAutoExpire() ) { 00933 mReadExpiryTimeNumInput->setEnabled( false ); 00934 mReadExpiryUnitsComboBox->setEnabled( false ); 00935 mUnreadExpiryTimeNumInput->setEnabled( false ); 00936 mUnreadExpiryUnitsComboBox->setEnabled( false ); 00937 mExpireActionDelete->setEnabled( false ); 00938 mExpireActionMove->setEnabled( false ); 00939 mExpireToFolderComboBox->setEnabled( false ); 00940 } 00941 else { 00942 // disable the number fields if "Never" is selected 00943 mReadExpiryTimeNumInput->setEnabled( mReadExpiryUnitsComboBox->currentItem() != 0 ); 00944 mUnreadExpiryTimeNumInput->setEnabled( mUnreadExpiryUnitsComboBox->currentItem() != 0 ); 00945 } 00946 } 00947 00948 //----------------------------------------------------------------------------- 00949 bool FolderDiaExpiryTab::save() 00950 { 00951 KMFolder* folder = mDlg->folder(); 00952 if( !folder ) 00953 return true; 00954 00955 // Settings for auto expiry of old email messages. 00956 folder->setAutoExpire( mExpireFolderCheckBox->isChecked() ); 00957 folder->setUnreadExpireAge( mUnreadExpiryTimeNumInput->value() ); 00958 folder->setReadExpireAge( mReadExpiryTimeNumInput->value() ); 00959 folder->setUnreadExpireUnits( static_cast<ExpireUnits>( mUnreadExpiryUnitsComboBox->currentItem() ) ); 00960 folder->setReadExpireUnits( static_cast<ExpireUnits>( mReadExpiryUnitsComboBox->currentItem() ) ); 00961 if ( mExpireActionDelete->isChecked() ) 00962 folder->setExpireAction( KMFolder::ExpireDelete ); 00963 else 00964 folder->setExpireAction( KMFolder::ExpireMove ); 00965 KMFolder* expireToFolder = 00966 mDlg->moveToFolderList()[mExpireToFolderComboBox->currentItem()]; 00967 if ( expireToFolder ) 00968 folder->setExpireToFolderId( expireToFolder->idString() ); 00969 00970 return true; 00971 } 00972 00977 void FolderDiaExpiryTab::slotExpireFolder(bool expire) 00978 { 00979 if (expire) { 00980 // disable the number field if "Never" is selected 00981 mReadExpiryTimeNumInput->setEnabled( mReadExpiryUnitsComboBox->currentItem() != 0 ); 00982 mReadExpiryUnitsComboBox->setEnabled(true); 00983 // disable the number field if "Never" is selected 00984 mUnreadExpiryTimeNumInput->setEnabled( mUnreadExpiryUnitsComboBox->currentItem() != 0 ); 00985 mUnreadExpiryUnitsComboBox->setEnabled(true); 00986 } else { 00987 mReadExpiryTimeNumInput->setEnabled(false); 00988 mReadExpiryUnitsComboBox->setEnabled(false); 00989 mUnreadExpiryTimeNumInput->setEnabled(false); 00990 mUnreadExpiryUnitsComboBox->setEnabled(false); 00991 } 00992 } 00993 00994 00998 void FolderDiaExpiryTab::slotReadExpiryUnitChanged( int value ) 00999 { 01000 // disable the number field if "Never" is selected 01001 mReadExpiryTimeNumInput->setEnabled( value != 0 ); 01002 } 01003 01004 01008 void FolderDiaExpiryTab::slotUnreadExpiryUnitChanged( int value ) 01009 { 01010 // disable the number field if "Never" is selected 01011 mUnreadExpiryTimeNumInput->setEnabled( value != 0 ); 01012 } 01013 01014 //---------------------------------------------------------------------------- 01015 FolderDiaMailingListTab::FolderDiaMailingListTab( KMFolderDialog* dlg, 01016 QWidget* parent, const char* name ) 01017 : FolderDiaTab( parent, name ), mDlg( dlg ) 01018 { 01019 QLabel* label; 01020 mLastItem = 0; 01021 01022 QVBoxLayout *topLayout = new QVBoxLayout( this, 0, KDialog::spacingHint(), 01023 "topLayout" ); 01024 01025 QGroupBox *mlGroup = new QGroupBox( i18n("Associated Mailing List" ), this ); 01026 mlGroup->setColumnLayout( 0, Qt::Vertical ); 01027 QVBoxLayout *groupLayout = new QVBoxLayout( mlGroup->layout() ); 01028 topLayout->addWidget( mlGroup ); 01029 01030 mHoldsMailingList = new QCheckBox( i18n("&Folder holds a mailing list"), mlGroup ); 01031 QObject::connect( mHoldsMailingList, SIGNAL(toggled(bool)), 01032 SLOT(slotHoldsML(bool)) ); 01033 groupLayout->addWidget( mHoldsMailingList ); 01034 01035 groupLayout->addSpacing( 10 ); 01036 01037 mDetectButton = new QPushButton( i18n("Detect Automatically"), mlGroup ); 01038 mDetectButton->setEnabled( false ); 01039 QObject::connect( mDetectButton, SIGNAL(pressed()), SLOT(slotDetectMailingList()) ); 01040 groupLayout->addWidget( mDetectButton, 0, Qt::AlignHCenter ); 01041 01042 groupLayout->addSpacing( 10 ); 01043 01044 QHBoxLayout *handlerLayout = new QHBoxLayout( groupLayout ); 01045 //FIXME: add QWhatsThis 01046 label = new QLabel( i18n("Preferred handler: "), mlGroup ); 01047 QObject::connect( mHoldsMailingList, SIGNAL(toggled(bool)), 01048 label, SLOT(setEnabled(bool)) ); 01049 handlerLayout->addWidget( label, 0, Qt::AlignCenter ); 01050 mMLHandlerCombo = new QComboBox( mlGroup ); 01051 mMLHandlerCombo->insertItem( i18n("KMail"), MailingList::KMail ); 01052 mMLHandlerCombo->insertItem( i18n("Browser"), MailingList::Browser ); 01053 mMLHandlerCombo->setEnabled( false ); 01054 handlerLayout->addWidget( mMLHandlerCombo, 0, Qt::AlignCenter ); 01055 QObject::connect( mMLHandlerCombo, SIGNAL(activated(int)), 01056 SLOT(slotMLHandling(int)) ); 01057 label->setBuddy( mMLHandlerCombo ); 01058 01059 //groupLayout->addSpacing( 10 ); 01060 01061 QVBoxLayout *idLayout = new QVBoxLayout( groupLayout ); 01062 label = new QLabel( i18n("<b>Mailing list description: </b>"), mlGroup ); 01063 label->setEnabled( false ); 01064 QObject::connect( mHoldsMailingList, SIGNAL(toggled(bool)), 01065 label, SLOT(setEnabled(bool)) ); 01066 idLayout->addWidget( label, 0 ); 01067 mMLId = new QLabel( label, "", mlGroup ); 01068 idLayout->addWidget( mMLId, 0 ); 01069 mMLId->setEnabled( false ); 01070 01071 QGridLayout *mlLayout = new QGridLayout( groupLayout ); 01072 mlLayout->setSpacing( 6 ); 01073 // mlLayout->setColStretch(0, 1); 01074 // mlLayout->setColStretch(1, 100); 01075 01076 label = new QLabel( i18n("&Address type:"), mlGroup ); 01077 label->setEnabled(false); 01078 QObject::connect( mHoldsMailingList, SIGNAL(toggled(bool)), 01079 label, SLOT(setEnabled(bool)) ); 01080 mlLayout->addWidget( label, 0, 0, Qt::AlignTop ); 01081 mAddressCombo = new QComboBox( mlGroup ); 01082 label->setBuddy( mAddressCombo ); 01083 mlLayout->addWidget( mAddressCombo, 0, 1, Qt::AlignTop ); 01084 mAddressCombo->setEnabled( false ); 01085 01086 //FIXME: if the mailing list actions have either KAction's or toolbar buttons 01087 // associated with them - remove this button since it's really silly 01088 // here 01089 QPushButton *handleButton = new QPushButton( i18n( "Invoke Handler" ), mlGroup ); 01090 handleButton->setEnabled( false ); 01091 QObject::connect( mHoldsMailingList, SIGNAL(toggled(bool)), 01092 handleButton, SLOT(setEnabled(bool)) ); 01093 QObject::connect( handleButton, SIGNAL(clicked()), 01094 SLOT(slotInvokeHandler()) ); 01095 mlLayout->addWidget( handleButton, 0, 2, Qt::AlignTop ); 01096 01097 mEditList = new KEditListBox( mlGroup ); 01098 mEditList->setEnabled( false ); 01099 mlLayout->addMultiCellWidget( mEditList, 1, 2, 0, 3, Qt::AlignTop ); 01100 01101 QStringList el; 01102 01103 //Order is important because the activate handler and fillMLFromWidgets 01104 //depend on it 01105 el << i18n( "Post to List" ) 01106 << i18n( "Subscribe to List" ) 01107 << i18n( "Unsubscribe from List" ) 01108 << i18n( "List Archives" ) 01109 << i18n( "List Help" ); 01110 mAddressCombo->insertStringList( el ); 01111 QObject::connect( mAddressCombo, SIGNAL(activated(int)), 01112 SLOT(slotAddressChanged(int)) ); 01113 } 01114 01115 void FolderDiaMailingListTab::load() 01116 { 01117 if (mDlg->folder()) mMailingList = mDlg->folder()->mailingList(); 01118 mMLId->setText( (mMailingList.id().isEmpty() ? i18n("Not available") : mMailingList.id()) ); 01119 mMLHandlerCombo->setCurrentItem( mMailingList.handler() ); 01120 mEditList->insertStringList( mMailingList.postURLS().toStringList() ); 01121 01122 mAddressCombo->setCurrentItem( mLastItem ); 01123 mHoldsMailingList->setChecked( mDlg->folder() && mDlg->folder()->isMailingListEnabled() ); 01124 } 01125 01126 //----------------------------------------------------------------------------- 01127 bool FolderDiaMailingListTab::save() 01128 { 01129 KMFolder* folder = mDlg->folder(); 01130 if( folder ) 01131 { 01132 // settings for mailingList 01133 folder->setMailingListEnabled( mHoldsMailingList && mHoldsMailingList->isChecked() ); 01134 fillMLFromWidgets(); 01135 folder->setMailingList( mMailingList ); 01136 } 01137 return true; 01138 } 01139 01140 //---------------------------------------------------------------------------- 01141 void FolderDiaMailingListTab::slotHoldsML( bool holdsML ) 01142 { 01143 mMLHandlerCombo->setEnabled( holdsML ); 01144 if ( mDlg->folder() && mDlg->folder()->count() ) 01145 mDetectButton->setEnabled( holdsML ); 01146 mAddressCombo->setEnabled( holdsML ); 01147 mEditList->setEnabled( holdsML ); 01148 mMLId->setEnabled( holdsML ); 01149 } 01150 01151 //---------------------------------------------------------------------------- 01152 void FolderDiaMailingListTab::slotDetectMailingList() 01153 { 01154 if ( !mDlg->folder() ) return; // in case the folder was just created 01155 int num = mDlg->folder()->count(); 01156 01157 kdDebug(5006)<<k_funcinfo<<" Detecting mailing list"<<endl; 01158 01159 // first try the currently selected message 01160 KMFolderTree *folderTree = static_cast<KMFolderTree *>( mDlg->parent() ); 01161 int curMsgIdx = folderTree->mainWidget()->headers()->currentItemIndex(); 01162 if ( curMsgIdx > 0 ) { 01163 KMMessage *mes = mDlg->folder()->getMsg( curMsgIdx ); 01164 if ( mes ) 01165 mMailingList = MailingList::detect( mes ); 01166 } 01167 01168 // next try the 5 most recently added messages 01169 if ( !( mMailingList.features() & MailingList::Post ) ) { 01170 const int maxchecks = 5; 01171 for( int i = --num; i > num-maxchecks; --i ) { 01172 KMMessage *mes = mDlg->folder()->getMsg( i ); 01173 if ( !mes ) 01174 continue; 01175 mMailingList = MailingList::detect( mes ); 01176 if ( mMailingList.features() & MailingList::Post ) 01177 break; 01178 } 01179 } 01180 if ( !(mMailingList.features() & MailingList::Post) ) { 01181 KMessageBox::error( this, 01182 i18n("KMail was unable to detect a mailing list in this folder. " 01183 "Please fill the addresses by hand.") ); 01184 } else { 01185 mMLId->setText( (mMailingList.id().isEmpty() ? i18n("Not available.") : mMailingList.id() ) ); 01186 fillEditBox(); 01187 } 01188 } 01189 01190 //---------------------------------------------------------------------------- 01191 void FolderDiaMailingListTab::slotMLHandling( int element ) 01192 { 01193 mMailingList.setHandler( static_cast<MailingList::Handler>( element ) ); 01194 } 01195 01196 //---------------------------------------------------------------------------- 01197 void FolderDiaMailingListTab::slotAddressChanged( int i ) 01198 { 01199 fillMLFromWidgets(); 01200 fillEditBox(); 01201 mLastItem = i; 01202 } 01203 01204 //---------------------------------------------------------------------------- 01205 void FolderDiaMailingListTab::fillMLFromWidgets() 01206 { 01207 if ( !mHoldsMailingList->isChecked() ) 01208 return; 01209 01210 //mMailingList.setHandler( static_cast<MailingList::Handler>( mMLHandlerCombo->currentItem() ) ); 01211 switch ( mLastItem ) { 01212 case 0: 01213 mMailingList.setPostURLS( mEditList->items() ); 01214 break; 01215 case 1: 01216 mMailingList.setSubscribeURLS( mEditList->items() ); 01217 break; 01218 case 2: 01219 mMailingList.setUnsubscribeURLS( mEditList->items() ); 01220 break; 01221 case 3: 01222 mMailingList.setArchiveURLS( mEditList->items() ); 01223 break; 01224 case 4: 01225 mMailingList.setHelpURLS( mEditList->items() ); 01226 break; 01227 default: 01228 kdWarning( 5006 )<<"Wrong entry in the mailing list entry combo!"<<endl; 01229 } 01230 } 01231 01232 void FolderDiaMailingListTab::fillEditBox() 01233 { 01234 mEditList->clear(); 01235 switch ( mAddressCombo->currentItem() ) { 01236 case 0: 01237 mEditList->insertStringList( mMailingList.postURLS().toStringList() ); 01238 break; 01239 case 1: 01240 mEditList->insertStringList( mMailingList.subscribeURLS().toStringList() ); 01241 break; 01242 case 2: 01243 mEditList->insertStringList( mMailingList.unsubscribeURLS().toStringList() ); 01244 break; 01245 case 3: 01246 mEditList->insertStringList( mMailingList.archiveURLS().toStringList() ); 01247 break; 01248 case 4: 01249 mEditList->insertStringList( mMailingList.helpURLS().toStringList() ); 01250 break; 01251 default: 01252 kdWarning( 5006 )<<"Wrong entry in the mailing list entry combo!"<<endl; 01253 } 01254 } 01255 01256 void FolderDiaMailingListTab::slotInvokeHandler() 01257 { 01258 KMCommand *command =0; 01259 switch ( mAddressCombo->currentItem() ) { 01260 case 0: 01261 command = new KMMailingListPostCommand( this, mDlg->folder() ); 01262 break; 01263 case 1: 01264 command = new KMMailingListSubscribeCommand( this, mDlg->folder() ); 01265 break; 01266 case 2: 01267 command = new KMMailingListUnsubscribeCommand( this, mDlg->folder() ); 01268 break; 01269 case 3: 01270 command = new KMMailingListArchivesCommand( this, mDlg->folder() ); 01271 break; 01272 case 4: 01273 command = new KMMailingListHelpCommand( this, mDlg->folder() ); 01274 break; 01275 default: 01276 kdWarning( 5006 )<<"Wrong entry in the mailing list entry combo!"<<endl; 01277 } 01278 if ( command ) command->start(); 01279 }
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:52:33 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003