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     }
00794 
00795     folder->setIgnoreNewMail( mIgnoreNewMailCheckBox->isChecked() );
00796     folder->setPutRepliesInSameFolder( mKeepRepliesInSameFolderCheckBox->isChecked() );
00797 
00798     if( folder->folderType() == KMFolderTypeImap )
00799     {
00800       KMFolderImap* imapFolder = static_cast<KMFolderImap*>( folder->storage() );
00801       imapFolder->setIncludeInMailCheck(
00802           mNewMailCheckBox->isChecked() );
00803     }
00804     // make sure everything is on disk, connected slots will call readConfig()
00805     // when creating a new folder.
00806     folder->storage()->writeConfig();
00807 
00808     kmkernel->folderMgr()->contentsChanged();
00809 
00810     if( mDlg->isNewFolder() )
00811       folder->close();
00812 
00813   }
00814   return true;
00815 }
00816 
00817 void FolderDiaGeneralTab::slotChangeIcon( QString icon ) // can't use a const-ref here, due to KIconButton's signal
00818 {
00819     mUnreadIconButton->setIcon( icon );
00820 }
00821 
00822 //----------------------------------------------------------------------------
00823 KMail::FolderDiaExpiryTab::FolderDiaExpiryTab( KMFolderDialog* dlg,
00824                                                QWidget* parent,
00825                                                const char* name )
00826   : FolderDiaTab( parent, name ), mDlg( dlg )
00827 {
00828   QLabel *label;
00829 
00830   QVBoxLayout *topLayout = new QVBoxLayout( this, 0, KDialog::spacingHint() );
00831 
00832   // Checkbox for setting whether expiry is enabled on this folder.
00833   mExpireFolderCheckBox =
00834     new QCheckBox( i18n("E&xpire old messages in this folder"), this );
00835   QObject::connect( mExpireFolderCheckBox, SIGNAL( toggled( bool ) ),
00836                     this, SLOT( slotExpireFolder( bool ) ) );
00837   topLayout->addWidget( mExpireFolderCheckBox );
00838 
00839   QGridLayout *expLayout = new QGridLayout( topLayout );
00840 
00841   // Expiry time for read documents.
00842   label = new QLabel( i18n("Expire &read email after:"), this );
00843   label->setEnabled( false );
00844   QObject::connect( mExpireFolderCheckBox, SIGNAL( toggled( bool ) ),
00845             label, SLOT( setEnabled( bool ) ) );
00846   expLayout->addWidget( label, 1, 0 );
00847 
00848   mReadExpiryTimeNumInput = new KIntNumInput( this );
00849   mReadExpiryTimeNumInput->setRange( 1, 500, 1, false );
00850   label->setBuddy( mReadExpiryTimeNumInput );
00851   expLayout->addWidget( mReadExpiryTimeNumInput, 1, 1 );
00852 
00853   mReadExpiryUnitsComboBox = new QComboBox( this );
00854   mReadExpiryUnitsComboBox->insertItem( i18n("Never") );
00855   mReadExpiryUnitsComboBox->insertItem( i18n("Day(s)") );
00856   mReadExpiryUnitsComboBox->insertItem( i18n("Week(s)") );
00857   mReadExpiryUnitsComboBox->insertItem( i18n("Month(s)") );
00858   expLayout->addWidget( mReadExpiryUnitsComboBox, 1, 2 );
00859   connect( mReadExpiryUnitsComboBox, SIGNAL( activated( int ) ),
00860            this, SLOT( slotReadExpiryUnitChanged( int ) ) );
00861 
00862   // Expiry time for unread documents.
00863   label = new QLabel( i18n("Expire unr&ead email after:"), this );
00864   label->setEnabled(false);
00865   QObject::connect( mExpireFolderCheckBox, SIGNAL( toggled( bool ) ),
00866             label, SLOT( setEnabled( bool ) ) );
00867   expLayout->addWidget( label, 2, 0 );
00868 
00869   mUnreadExpiryTimeNumInput = new KIntNumInput( this );
00870   mUnreadExpiryTimeNumInput->setRange( 1, 500, 1, false );
00871   label->setBuddy( mUnreadExpiryTimeNumInput );
00872   expLayout->addWidget( mUnreadExpiryTimeNumInput, 2, 1 );
00873 
00874   mUnreadExpiryUnitsComboBox = new QComboBox( this );
00875   mUnreadExpiryUnitsComboBox->insertItem( i18n("Never") );
00876   mUnreadExpiryUnitsComboBox->insertItem( i18n("Day(s)") );
00877   mUnreadExpiryUnitsComboBox->insertItem( i18n("Week(s)") );
00878   mUnreadExpiryUnitsComboBox->insertItem( i18n("Month(s)") );
00879   expLayout->addWidget( mUnreadExpiryUnitsComboBox, 2, 2 );
00880   connect( mUnreadExpiryUnitsComboBox, SIGNAL( activated( int ) ),
00881            this, SLOT( slotUnreadExpiryUnitChanged( int ) ) );
00882 
00883   expLayout->setColStretch( 3, 100 );
00884 
00885   // delete or archive old messages
00886   QButtonGroup* radioBG = new QButtonGroup( this );
00887   radioBG->hide(); // just for the exclusive behavior
00888   mExpireActionDelete = new QRadioButton( i18n( "Delete old messages" ),
00889                                           this );
00890   radioBG->insert( mExpireActionDelete );
00891   topLayout->addWidget( mExpireActionDelete );
00892 
00893   QHBoxLayout *hbl = new QHBoxLayout( topLayout );
00894   mExpireActionMove = new QRadioButton( i18n( "Move old messages to:" ),
00895                                         this );
00896   radioBG->insert( mExpireActionMove );
00897   hbl->addWidget( mExpireActionMove );
00898   mExpireToFolderComboBox = new QComboBox( this );
00899   hbl->addWidget( mExpireToFolderComboBox );
00900   mExpireToFolderComboBox->insertStringList( mDlg->moveToFolderNameList() );
00901   hbl->addStretch( 100 );
00902 
00903   topLayout->addStretch( 100 ); // eat all superfluous space
00904 
00905   connect( mExpireFolderCheckBox, SIGNAL( toggled( bool ) ),
00906            mExpireActionDelete, SLOT( setEnabled( bool ) ) );
00907   connect( mExpireFolderCheckBox, SIGNAL( toggled( bool ) ),
00908            mExpireActionMove, SLOT( setEnabled( bool ) ) );
00909   connect( mExpireFolderCheckBox, SIGNAL( toggled( bool ) ),
00910            mExpireToFolderComboBox, SLOT( setEnabled( bool ) ) );
00911 }
00912 
00913 void FolderDiaExpiryTab::load()
00914 {
00915   KMFolder* folder = mDlg->folder();
00916   if( folder ) {
00917     // settings for automatic deletion of old messages
00918     mExpireFolderCheckBox->setChecked( folder->isAutoExpire() );
00919     // Legal values for units are 0=never, 1=days, 2=weeks, 3=months.
00920     if( folder->getReadExpireUnits() >= 0
00921         && folder->getReadExpireUnits() < expireMaxUnits ) {
00922       mReadExpiryUnitsComboBox->setCurrentItem( folder->getReadExpireUnits() );
00923     }
00924     if( folder->getUnreadExpireUnits() >= 0
00925         && folder->getUnreadExpireUnits() < expireMaxUnits ) {
00926       mUnreadExpiryUnitsComboBox->setCurrentItem( folder->getUnreadExpireUnits() );
00927     }
00928     int age = folder->getReadExpireAge();
00929     if ( age >= 1 && age <= 500 ) {
00930       mReadExpiryTimeNumInput->setValue( age );
00931     } else {
00932       mReadExpiryTimeNumInput->setValue( 7 );
00933     }
00934     age = folder->getUnreadExpireAge();
00935     if ( age >= 1 && age <= 500 ) {
00936       mUnreadExpiryTimeNumInput->setValue( age );
00937     } else {
00938       mUnreadExpiryTimeNumInput->setValue( 28 );
00939     }
00940     if ( folder->expireAction() == KMFolder::ExpireDelete )
00941       mExpireActionDelete->setChecked( true );
00942     else
00943       mExpireActionMove->setChecked( true );
00944     QString destFolderID = folder->expireToFolderId();
00945     if ( !destFolderID.isEmpty() ) {
00946       KMFolderDialog::FolderList moveToFolderList = mDlg->moveToFolderList();
00947       KMFolder* destFolder = kmkernel->findFolderById( destFolderID );
00948       int pos = moveToFolderList.findIndex( QGuardedPtr<KMFolder>( destFolder ) );
00949       if ( pos > -1 )
00950         mExpireToFolderComboBox->setCurrentItem( pos );
00951     }
00952   } else { // new folder, use default values
00953     mReadExpiryTimeNumInput->setValue( 7 );
00954     mUnreadExpiryTimeNumInput->setValue(28);
00955     mExpireActionDelete->setChecked( true );
00956   }
00957   if( !folder || !folder->isAutoExpire() ) {
00958     mReadExpiryTimeNumInput->setEnabled( false );
00959     mReadExpiryUnitsComboBox->setEnabled( false );
00960     mUnreadExpiryTimeNumInput->setEnabled( false );
00961     mUnreadExpiryUnitsComboBox->setEnabled( false );
00962     mExpireActionDelete->setEnabled( false );
00963     mExpireActionMove->setEnabled( false );
00964     mExpireToFolderComboBox->setEnabled( false );
00965   }
00966   else {
00967     // disable the number fields if "Never" is selected
00968     mReadExpiryTimeNumInput->setEnabled( mReadExpiryUnitsComboBox->currentItem() != 0 );
00969     mUnreadExpiryTimeNumInput->setEnabled( mUnreadExpiryUnitsComboBox->currentItem() != 0 );
00970   }
00971 }
00972 
00973 //-----------------------------------------------------------------------------
00974 bool FolderDiaExpiryTab::save()
00975 {
00976   KMFolder* folder = mDlg->folder();
00977   if( !folder )
00978     return true;
00979 
00980   // Settings for auto expiry of old email messages.
00981   folder->setAutoExpire( mExpireFolderCheckBox->isChecked() );
00982   folder->setUnreadExpireAge( mUnreadExpiryTimeNumInput->value() );
00983   folder->setReadExpireAge( mReadExpiryTimeNumInput->value() );
00984   folder->setUnreadExpireUnits( static_cast<ExpireUnits>( mUnreadExpiryUnitsComboBox->currentItem() ) );
00985   folder->setReadExpireUnits( static_cast<ExpireUnits>( mReadExpiryUnitsComboBox->currentItem() ) );
00986   if ( mExpireActionDelete->isChecked() )
00987     folder->setExpireAction( KMFolder::ExpireDelete );
00988   else
00989     folder->setExpireAction( KMFolder::ExpireMove );
00990   KMFolder* expireToFolder =
00991     mDlg->moveToFolderList()[mExpireToFolderComboBox->currentItem()];
00992   if ( expireToFolder )
00993     folder->setExpireToFolderId( expireToFolder->idString() );
00994 
00995   return true;
00996 }
00997 
01002 void FolderDiaExpiryTab::slotExpireFolder(bool expire)
01003 {
01004   if (expire) {
01005     // disable the number field if "Never" is selected
01006     mReadExpiryTimeNumInput->setEnabled( mReadExpiryUnitsComboBox->currentItem() != 0 );
01007     mReadExpiryUnitsComboBox->setEnabled(true);
01008     // disable the number field if "Never" is selected
01009     mUnreadExpiryTimeNumInput->setEnabled( mUnreadExpiryUnitsComboBox->currentItem() != 0 );
01010     mUnreadExpiryUnitsComboBox->setEnabled(true);
01011   } else {
01012     mReadExpiryTimeNumInput->setEnabled(false);
01013     mReadExpiryUnitsComboBox->setEnabled(false);
01014     mUnreadExpiryTimeNumInput->setEnabled(false);
01015     mUnreadExpiryUnitsComboBox->setEnabled(false);
01016   }
01017 }
01018 
01019 
01023 void FolderDiaExpiryTab::slotReadExpiryUnitChanged( int value )
01024 {
01025   // disable the number field if "Never" is selected
01026   mReadExpiryTimeNumInput->setEnabled( value != 0 );
01027 }
01028 
01029 
01033 void FolderDiaExpiryTab::slotUnreadExpiryUnitChanged( int value )
01034 {
01035   // disable the number field if "Never" is selected
01036   mUnreadExpiryTimeNumInput->setEnabled( value != 0 );
01037 }
01038 
01039 //----------------------------------------------------------------------------
01040 FolderDiaMailingListTab::FolderDiaMailingListTab( KMFolderDialog* dlg,
01041                                                   QWidget* parent, const char* name )
01042   : FolderDiaTab( parent, name ), mDlg( dlg )
01043 {
01044   QLabel* label;
01045   mLastItem = 0;
01046 
01047   QVBoxLayout *topLayout = new QVBoxLayout( this, 0, KDialog::spacingHint(),
01048                                             "topLayout" );
01049 
01050   QGroupBox *mlGroup = new QGroupBox( i18n("Associated Mailing List" ), this );
01051   mlGroup->setColumnLayout( 0,  Qt::Vertical );
01052   QVBoxLayout *groupLayout = new QVBoxLayout( mlGroup->layout() );
01053   topLayout->addWidget( mlGroup );
01054 
01055   mHoldsMailingList = new QCheckBox( i18n("&Folder holds a mailing list"), mlGroup );
01056   QObject::connect( mHoldsMailingList, SIGNAL(toggled(bool)),
01057                     SLOT(slotHoldsML(bool)) );
01058   groupLayout->addWidget( mHoldsMailingList );
01059 
01060   groupLayout->addSpacing( 10 );
01061 
01062   mDetectButton = new QPushButton( i18n("Detect Automatically"), mlGroup );
01063   mDetectButton->setEnabled( false );
01064   QObject::connect( mDetectButton, SIGNAL(pressed()), SLOT(slotDetectMailingList()) );
01065   groupLayout->addWidget( mDetectButton, 0, Qt::AlignHCenter );
01066 
01067   groupLayout->addSpacing( 10 );
01068 
01069   QHBoxLayout *handlerLayout = new QHBoxLayout( groupLayout );
01070   //FIXME: add QWhatsThis
01071   label = new QLabel( i18n("Preferred handler: "), mlGroup );
01072   QObject::connect( mHoldsMailingList, SIGNAL(toggled(bool)),
01073             label, SLOT(setEnabled(bool)) );
01074   handlerLayout->addWidget( label, 0, Qt::AlignCenter );
01075   mMLHandlerCombo = new QComboBox( mlGroup );
01076   mMLHandlerCombo->insertItem( i18n("KMail"), MailingList::KMail );
01077   mMLHandlerCombo->insertItem( i18n("Browser"), MailingList::Browser );
01078   mMLHandlerCombo->setEnabled( false );
01079   handlerLayout->addWidget( mMLHandlerCombo, 0, Qt::AlignCenter );
01080   QObject::connect( mMLHandlerCombo, SIGNAL(activated(int)),
01081                     SLOT(slotMLHandling(int)) );
01082   label->setBuddy( mMLHandlerCombo );
01083 
01084   //groupLayout->addSpacing( 10 );
01085 
01086   QVBoxLayout *idLayout = new QVBoxLayout( groupLayout );
01087   label = new QLabel( i18n("<b>Mailing list description: </b>"), mlGroup );
01088   label->setEnabled( false );
01089   QObject::connect( mHoldsMailingList, SIGNAL(toggled(bool)),
01090             label, SLOT(setEnabled(bool)) );
01091   idLayout->addWidget( label, 0 );
01092   mMLId = new QLabel( label, "", mlGroup );
01093   idLayout->addWidget( mMLId, 0 );
01094   mMLId->setEnabled( false );
01095 
01096   QGridLayout *mlLayout = new QGridLayout( groupLayout );
01097   mlLayout->setSpacing( 6 );
01098   // mlLayout->setColStretch(0, 1);
01099   // mlLayout->setColStretch(1, 100);
01100 
01101   label = new QLabel( i18n("&Address type:"), mlGroup );
01102   label->setEnabled(false);
01103   QObject::connect( mHoldsMailingList, SIGNAL(toggled(bool)),
01104             label, SLOT(setEnabled(bool)) );
01105   mlLayout->addWidget( label, 0, 0, Qt::AlignTop );
01106   mAddressCombo = new QComboBox( mlGroup );
01107   label->setBuddy( mAddressCombo );
01108   mlLayout->addWidget( mAddressCombo, 0, 1, Qt::AlignTop );
01109   mAddressCombo->setEnabled( false );
01110 
01111   //FIXME: if the mailing list actions have either KAction's or toolbar buttons
01112   //       associated with them - remove this button since it's really silly
01113   //       here
01114   QPushButton *handleButton = new QPushButton( i18n( "Invoke Handler" ), mlGroup );
01115   handleButton->setEnabled( false );
01116   if( mDlg->folder())
01117   {
01118     QObject::connect( mHoldsMailingList, SIGNAL(toggled(bool)),
01119                 handleButton, SLOT(setEnabled(bool)) );
01120       QObject::connect( handleButton, SIGNAL(clicked()),
01121                         SLOT(slotInvokeHandler()) );
01122   }
01123   mlLayout->addWidget( handleButton, 0, 2, Qt::AlignTop );
01124 
01125   mEditList = new KEditListBox( mlGroup );
01126   mEditList->setEnabled( false );
01127   mlLayout->addMultiCellWidget( mEditList, 1, 2, 0, 3, Qt::AlignTop );
01128 
01129   QStringList el;
01130 
01131   //Order is important because the activate handler and fillMLFromWidgets
01132   //depend on it
01133   el << i18n( "Post to List" )
01134      << i18n( "Subscribe to List" )
01135      << i18n( "Unsubscribe from List" )
01136      << i18n( "List Archives" )
01137      << i18n( "List Help" );
01138   mAddressCombo->insertStringList( el );
01139   QObject::connect( mAddressCombo, SIGNAL(activated(int)),
01140                     SLOT(slotAddressChanged(int)) );
01141 }
01142 
01143 void FolderDiaMailingListTab::load()
01144 {
01145   if (mDlg->folder()) mMailingList = mDlg->folder()->mailingList();
01146   mMLId->setText( (mMailingList.id().isEmpty() ? i18n("Not available") : mMailingList.id()) );
01147   mMLHandlerCombo->setCurrentItem( mMailingList.handler() );
01148   mEditList->insertStringList( mMailingList.postURLS().toStringList() );
01149 
01150   mAddressCombo->setCurrentItem( mLastItem );
01151   mHoldsMailingList->setChecked( mDlg->folder() && mDlg->folder()->isMailingListEnabled() );
01152 }
01153 
01154 //-----------------------------------------------------------------------------
01155 bool FolderDiaMailingListTab::save()
01156 {
01157   KMFolder* folder = mDlg->folder();
01158   if( folder )
01159   {
01160     // settings for mailingList
01161     folder->setMailingListEnabled( mHoldsMailingList && mHoldsMailingList->isChecked() );
01162     fillMLFromWidgets();
01163     folder->setMailingList( mMailingList );
01164   }
01165   return true;
01166 }
01167 
01168 //----------------------------------------------------------------------------
01169 void FolderDiaMailingListTab::slotHoldsML( bool holdsML )
01170 {
01171   mMLHandlerCombo->setEnabled( holdsML );
01172   if ( mDlg->folder() && mDlg->folder()->count() )
01173     mDetectButton->setEnabled( holdsML );
01174   mAddressCombo->setEnabled( holdsML );
01175   mEditList->setEnabled( holdsML );
01176   mMLId->setEnabled( holdsML );
01177 }
01178 
01179 //----------------------------------------------------------------------------
01180 void FolderDiaMailingListTab::slotDetectMailingList()
01181 {
01182   if ( !mDlg->folder() ) return; // in case the folder was just created
01183   int num = mDlg->folder()->count();
01184 
01185   kdDebug(5006)<<k_funcinfo<<" Detecting mailing list"<<endl;
01186 
01187   // first try the currently selected message
01188   KMFolderTree *folderTree = static_cast<KMFolderTree *>( mDlg->parent() );
01189   int curMsgIdx = folderTree->mainWidget()->headers()->currentItemIndex();
01190   if ( curMsgIdx > 0 ) {
01191     KMMessage *mes = mDlg->folder()->getMsg( curMsgIdx );
01192     if ( mes )
01193       mMailingList = MailingList::detect( mes );
01194   }
01195 
01196   // next try the 5 most recently added messages
01197   if ( !( mMailingList.features() & MailingList::Post ) ) {
01198     const int maxchecks = 5;
01199     for( int i = --num; i > num-maxchecks; --i ) {
01200       KMMessage *mes = mDlg->folder()->getMsg( i );
01201       if ( !mes )
01202         continue;
01203       mMailingList = MailingList::detect( mes );
01204       if ( mMailingList.features() & MailingList::Post )
01205         break;
01206     }
01207   }
01208   if ( !(mMailingList.features() & MailingList::Post) ) {
01209     KMessageBox::error( this,
01210               i18n("KMail was unable to detect a mailing list in this folder. "
01211                    "Please fill the addresses by hand.") );
01212   } else {
01213     mMLId->setText( (mMailingList.id().isEmpty() ? i18n("Not available.") : mMailingList.id() ) );
01214     fillEditBox();
01215   }
01216 }
01217 
01218 //----------------------------------------------------------------------------
01219 void FolderDiaMailingListTab::slotMLHandling( int element )
01220 {
01221   mMailingList.setHandler( static_cast<MailingList::Handler>( element ) );
01222 }
01223 
01224 //----------------------------------------------------------------------------
01225 void FolderDiaMailingListTab::slotAddressChanged( int i )
01226 {
01227   fillMLFromWidgets();
01228   fillEditBox();
01229   mLastItem = i;
01230 }
01231 
01232 //----------------------------------------------------------------------------
01233 void FolderDiaMailingListTab::fillMLFromWidgets()
01234 {
01235   if ( !mHoldsMailingList->isChecked() )
01236     return;
01237 
01238   // make sure that email addresses are prepended by "mailto:"
01239   bool changed = false;
01240   QStringList oldList = mEditList->items();
01241   QStringList newList; // the correct string list
01242   for ( QStringList::ConstIterator it = oldList.begin();
01243         it != oldList.end(); ++it ) {
01244     if ( !(*it).startsWith("http:") && !(*it).startsWith("https:") &&
01245          !(*it).startsWith("mailto:") && ( (*it).find('@') != -1 ) ) {
01246       changed = true;
01247       newList << "mailto:" + *it;
01248     }
01249     else {
01250       newList << *it;
01251     }
01252   }
01253   if ( changed ) {
01254     mEditList->clear();
01255     mEditList->insertStringList( newList );
01256   }
01257 
01258   //mMailingList.setHandler( static_cast<MailingList::Handler>( mMLHandlerCombo->currentItem() ) );
01259   switch ( mLastItem ) {
01260   case 0:
01261     mMailingList.setPostURLS( mEditList->items() );
01262     break;
01263   case 1:
01264     mMailingList.setSubscribeURLS( mEditList->items() );
01265     break;
01266   case 2:
01267     mMailingList.setUnsubscribeURLS( mEditList->items() );
01268     break;
01269   case 3:
01270     mMailingList.setArchiveURLS( mEditList->items() );
01271     break;
01272   case 4:
01273     mMailingList.setHelpURLS( mEditList->items() );
01274     break;
01275   default:
01276     kdWarning( 5006 )<<"Wrong entry in the mailing list entry combo!"<<endl;
01277   }
01278 }
01279 
01280 void FolderDiaMailingListTab::fillEditBox()
01281 {
01282   mEditList->clear();
01283   switch ( mAddressCombo->currentItem() ) {
01284   case 0:
01285     mEditList->insertStringList( mMailingList.postURLS().toStringList() );
01286     break;
01287   case 1:
01288     mEditList->insertStringList( mMailingList.subscribeURLS().toStringList() );
01289     break;
01290   case 2:
01291     mEditList->insertStringList( mMailingList.unsubscribeURLS().toStringList() );
01292     break;
01293   case 3:
01294     mEditList->insertStringList( mMailingList.archiveURLS().toStringList() );
01295     break;
01296   case 4:
01297     mEditList->insertStringList( mMailingList.helpURLS().toStringList() );
01298     break;
01299   default:
01300     kdWarning( 5006 )<<"Wrong entry in the mailing list entry combo!"<<endl;
01301   }
01302 }
01303 
01304 void FolderDiaMailingListTab::slotInvokeHandler()
01305 {
01306   KMCommand *command =0;
01307   switch ( mAddressCombo->currentItem() ) {
01308   case 0:
01309     command = new KMMailingListPostCommand( this, mDlg->folder() );
01310     break;
01311   case 1:
01312     command = new KMMailingListSubscribeCommand( this, mDlg->folder() );
01313     break;
01314   case 2:
01315     command = new KMMailingListUnsubscribeCommand( this, mDlg->folder() );
01316     break;
01317   case 3:
01318     command = new KMMailingListArchivesCommand( this, mDlg->folder() );
01319     break;
01320   case 4:
01321     command = new KMMailingListHelpCommand( this, mDlg->folder() );
01322     break;
01323   default:
01324     kdWarning( 5006 )<<"Wrong entry in the mailing list entry combo!"<<endl;
01325   }
01326   if ( command ) command->start();
01327 }
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 22:43:47 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003