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