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