• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kmail

kmfolderdialog.cpp

Go to the documentation of this file.
00001 // -*- mode: C++; c-file-style: "gnu" -*-
00034 #include "kmfolderdialog.h"
00035 #include "kmacctfolder.h"
00036 #include "kmfoldermgr.h"
00037 #include <kpimidentities/identitycombo.h>
00038 #include "kmfolderimap.h"
00039 #include "kmfoldercachedimap.h"
00040 #include "kmfolder.h"
00041 #include "kmheaders.h"
00042 #include "kmcommands.h"
00043 #include "kmfoldertree.h"
00044 #include "folderdialogacltab.h"
00045 #include "folderdialogquotatab.h"
00046 #include "kmailicalifaceimpl.h"
00047 #include "globalsettings.h"
00048 #include "folderrequester.h"
00049 
00050 #include <keditlistbox.h>
00051 #include <klineedit.h>
00052 #include <klocale.h>
00053 #include <knuminput.h>
00054 #include <kmessagebox.h>
00055 #include <kicondialog.h>
00056 #include <kconfig.h>
00057 #include <kdebug.h>
00058 #include <kvbox.h>
00059 
00060 #include <QCheckBox>
00061 #include <QLayout>
00062 #include <QRegExp>
00063 #include <QLabel>
00064 
00065 
00066 #include <QGridLayout>
00067 #include <QFrame>
00068 #include <QHBoxLayout>
00069 #include <QList>
00070 #include <QVBoxLayout>
00071 
00072 #include <assert.h>
00073 #include <QRadioButton>
00074 
00075 #include "templatesconfiguration.h"
00076 #include "templatesconfiguration_kfg.h"
00077 
00078 using namespace KMail;
00079 
00080 static QString inCaseWeDecideToRenameTheTab( I18N_NOOP( "Permissions (ACL)" ) );
00081 
00082 //-----------------------------------------------------------------------------
00083 KMFolderDialog::KMFolderDialog( KMFolder *aFolder, KMFolderDir *aFolderDir,
00084                                 KMFolderTree* aParent, const QString& aCap,
00085                                 const QString& aName):
00086   KPageDialog( aParent ),
00087   mFolder( aFolder ),
00088   mFolderDir( aFolderDir ),
00089   mParentFolder( 0 ),
00090   mFolderTree( aParent ),
00091   mIsNewFolder( aFolder == 0 )
00092 {
00093   setFaceType( Tabbed );
00094   setCaption( aCap );
00095   setButtons( Ok|Cancel );
00096   setDefaultButton( Ok );
00097   setObjectName( "KMFolderDialog" );
00098   setModal( true );
00099 
00100   kDebug(5006);
00101 
00102   QStringList folderNames;
00103   QList<QPointer<KMFolder> > folders;
00104   // get all folders but search and folders that can not have children
00105   aParent->createFolderList(&folderNames, &folders, true, true,
00106                             true, false, true, false);
00107 
00108   if( mFolderDir ) {
00109     // search the parent folder of the folder
00110     FolderList::ConstIterator it;
00111     int i = 1;
00112     for( it = folders.begin(); it != folders.end(); ++it, ++i ) {
00113       if( (*it)->child() == mFolderDir ) {
00114         mParentFolder = *it;
00115         break;
00116       }
00117     }
00118   }
00119 
00120   FolderDialogTab* tab;
00121   QFrame *box;
00122 
00123   box = new KVBox;
00124   addPage( box, i18n("General") );
00125   tab = new FolderDialogGeneralTab( this, aName, box );
00126   addTab( tab );
00127 
00128   // Don't add template tab for special folders
00129   if (!mFolder->isSystemFolder() || mFolder->isMainInbox()) 
00130   {
00131     box = new KVBox( this );
00132     addPage( box, i18n("Templates") );
00133     tab = new FolderDialogTemplatesTab( this, box );
00134     addTab( tab );
00135   }
00136 
00137   KMFolder* refFolder = mFolder ? mFolder : mParentFolder;
00138   KMFolderType folderType = refFolder ? refFolder->folderType() : KMFolderTypeUnknown;
00139   bool noContent = mFolder ? mFolder->storage()->noContent() : false;
00140   if ( !noContent && refFolder && ( folderType == KMFolderTypeImap || folderType == KMFolderTypeCachedImap ) ) {
00141     if ( FolderDialogACLTab::supports( refFolder ) ) {
00142       box = new KVBox;
00143       addPage( box, i18n("Access Control") );
00144       tab = new FolderDialogACLTab( this, box );
00145       addTab( tab );
00146     }
00147   }
00148 
00149   if ( !noContent && refFolder && ( folderType == KMFolderTypeImap || folderType == KMFolderTypeCachedImap ) ) {
00150     if ( FolderDialogQuotaTab::supports( refFolder ) ) {
00151       box = new KVBox;
00152       addPage( box, i18n("Quota") );
00153       tab = new FolderDialogQuotaTab( this, box );
00154       addTab( tab );
00155     }
00156   }
00157 
00158   for ( int i = 0 ; i < mTabs.count() ; ++i )
00159     mTabs[i]->load();
00160   connect( this, SIGNAL( okClicked() ), SLOT( slotOk() ) );
00161   connect( this, SIGNAL( applyClicked() ), SLOT( slotApply() ) ); 
00162 }
00163 
00164 void KMFolderDialog::addTab( FolderDialogTab* tab )
00165 {
00166   connect( tab, SIGNAL( readyForAccept() ),
00167            this, SLOT( slotReadyForAccept() ) );
00168   connect( tab, SIGNAL( cancelAccept() ),
00169            this, SLOT( slotCancelAccept() ) );
00170   //connect( tab, SIGNAL(changed( bool )),
00171   //         this, SLOT(slotChanged( bool )) );
00172   mTabs.append( tab );
00173 }
00174 
00175 // Not used yet (no button), but ready to be used :)
00176 void KMFolderDialog::slotApply()
00177 {
00178   if ( mFolder.isNull() && !mIsNewFolder ) // deleted meanwhile?
00179     return;
00180 
00181   for ( int i = 0 ; i < mTabs.count() ; ++i )
00182     mTabs[i]->save();
00183   if ( !mFolder.isNull() && mIsNewFolder ) // we just created it
00184     mIsNewFolder = false; // so it's not new anymore :)
00185 }
00186 
00187 // Called when pressing Ok
00188 // We want to apply the changes first (which is async), before closing the dialog,
00189 // in case of errors during the upload.
00190 void KMFolderDialog::slotOk()
00191 {
00192   if ( mFolder.isNull() && !mIsNewFolder ) { // deleted meanwhile?
00193     KDialog::accept();
00194     return;
00195   }
00196 
00197   mDelayedSavingTabs = 0; // number of tabs which need delayed saving
00198   for ( int i = 0 ; i < mTabs.count() ; ++i ) {
00199     FolderDialogTab::AcceptStatus s = mTabs[i]->accept();
00200     if ( s == FolderDialogTab::Canceled ) {
00201       slotCancelAccept();
00202       return;
00203     }
00204     else if ( s == FolderDialogTab::Delayed )
00205       ++mDelayedSavingTabs;
00206   }
00207 
00208   if ( mDelayedSavingTabs )
00209     enableButtonOk( false );
00210   else
00211     KDialog::accept();
00212 }
00213 
00214 void KMFolderDialog::slotReadyForAccept()
00215 {
00216   --mDelayedSavingTabs;
00217   if ( mDelayedSavingTabs == 0 )
00218     KDialog::accept();
00219 }
00220 
00221 void KMFolderDialog::slotCancelAccept()
00222 {
00223   mDelayedSavingTabs = -1;
00224   enableButtonOk( true );
00225   // Don't try to create it twice
00226   if ( !mFolder.isNull() )
00227     mIsNewFolder = false;
00228 
00229   // Other tabs might call slotReadyForAccept. -1 ensures that it won't close the dialog,
00230   // but the OK button being enabled means that people might succeed in running
00231   // the same job from save more than once.
00232   // Solution: mAcceptCanceled = true instead of -1.
00233   // Bah for now we only have one tab which can delay saving -> later.
00234 }
00235 
00236 void KMFolderDialog::slotChanged( bool )
00237 {
00238   // TODO, support for 'changed', and Apply button.
00239   // sample code for here: KCMultiDialog calls bool changed() on every KCModuleProxy...
00240 }
00241 
00242 void KMFolderDialog::setFolder( KMFolder* folder )
00243 {
00244   Q_ASSERT( mFolder.isNull() );
00245   mFolder = folder;
00246 }
00247 
00248 KMFolderDir* KMFolderDialog::folderDir() const
00249 {
00250   return mFolderDir;
00251 }
00252 
00253 static void addLine( QWidget *parent, QVBoxLayout* layout )
00254 {
00255    QFrame *line = new QFrame( parent );
00256    line->setObjectName( "line" );
00257    line->setGeometry( QRect( 80, 150, 250, 20 ) );
00258    line->setFrameShape( QFrame::HLine );
00259    line->setFrameShadow( QFrame::Sunken );
00260    line->setFrameShape( QFrame::HLine );
00261    layout->addWidget( line );
00262 }
00263 
00264 //----------------------------------------------------------------------------
00265 KMail::FolderDialogGeneralTab::FolderDialogGeneralTab( KMFolderDialog* dlg,
00266                                                  const QString& aName,
00267                                                  QWidget* parent, const char* name )
00268   : FolderDialogTab( parent, name ), mDlg( dlg )
00269 {
00270 
00271 
00272   mIsLocalSystemFolder = mDlg->folder()->isSystemFolder() &&
00273        mDlg->folder()->folderType() != KMFolderTypeImap &&
00274        mDlg->folder()->folderType() != KMFolderTypeCachedImap;
00275 
00276   QLabel *label;
00277 
00278   QVBoxLayout *topLayout = new QVBoxLayout( this );
00279   topLayout->setSpacing( KDialog::spacingHint() );
00280   topLayout->setMargin( 0 );
00281 
00282   // Musn't be able to edit details for a system folder.
00283   if ( !mIsLocalSystemFolder ) {
00284 
00285     QHBoxLayout *hl = new QHBoxLayout();
00286     topLayout->addItem( hl );
00287     hl->setSpacing( KDialog::spacingHint() );
00288 
00289     label = new QLabel( i18n("&Name:"), this );
00290     hl->addWidget( label );
00291 
00292     mNameEdit = new KLineEdit( this );
00293     if( !mDlg->folder() )
00294             mNameEdit->setFocus();
00295     mNameEdit->setText( mDlg->folder() ? mDlg->folder()->label() : i18n("unnamed") );
00296     if (!aName.isEmpty())
00297             mNameEdit->setText(aName);
00298     mNameEdit->setMinimumSize(mNameEdit->sizeHint());
00299     // prevent renaming of IMAP inbox
00300     if ( mDlg->folder() && mDlg->folder()->isSystemFolder() ) {
00301       QString imapPath;
00302       if ( mDlg->folder()->folderType() == KMFolderTypeImap )
00303         imapPath = static_cast<KMFolderImap*>( mDlg->folder()->storage() )->imapPath();
00304       if ( mDlg->folder()->folderType() == KMFolderTypeCachedImap )
00305         imapPath = static_cast<KMFolderCachedImap*>( mDlg->folder()->storage() )->imapPath();
00306       if ( imapPath == "/INBOX/" )
00307         mNameEdit->setEnabled( false );
00308     }
00309     label->setBuddy( mNameEdit );
00310     hl->addWidget( mNameEdit );
00311     connect( mNameEdit, SIGNAL( textChanged( const QString & ) ),
00312                     this, SLOT( slotFolderNameChanged( const QString & ) ) );
00313 
00314 
00315     //start icons group
00316     QVBoxLayout *ivl = new QVBoxLayout();
00317     topLayout->addItem( ivl );
00318     ivl->setSpacing( KDialog::spacingHint() );
00319 
00320     QHBoxLayout *ihl = new QHBoxLayout();
00321     ivl->addLayout( ihl );
00322     mIconsCheckBox = new QCheckBox( i18n("Use custom &icons"), this );
00323     mIconsCheckBox->setChecked( false );
00324     ihl->addWidget( mIconsCheckBox );
00325     ihl->addStretch( 2 );
00326 
00327     mNormalIconLabel = new QLabel( i18n("&Normal:"), this );
00328     mNormalIconLabel->setEnabled( false );
00329     ihl->addWidget( mNormalIconLabel );
00330 
00331     mNormalIconButton = new KIconButton( this );
00332     mNormalIconLabel->setBuddy( mNormalIconButton );
00333     mNormalIconButton->setIconType( KIconLoader::NoGroup, KIconLoader::Place, false );
00334     mNormalIconButton->setIconSize( 16 );
00335     mNormalIconButton->setStrictIconSize( true );
00336     mNormalIconButton->setFixedSize( 28, 28 );
00337     // Can't use iconset here
00338     mNormalIconButton->setIcon( "folder" );
00339     mNormalIconButton->setEnabled( false );
00340     ihl->addWidget( mNormalIconButton );
00341 
00342     mUnreadIconLabel = new QLabel( i18n("&Unread:"), this );
00343     mUnreadIconLabel->setEnabled( false );
00344     ihl->addWidget( mUnreadIconLabel );
00345 
00346     mUnreadIconButton = new KIconButton( this );
00347     mUnreadIconLabel->setBuddy( mUnreadIconButton );
00348     mUnreadIconButton->setIconType( KIconLoader::NoGroup, KIconLoader::Place, false );
00349     mUnreadIconButton->setIconSize( 16 );
00350     mUnreadIconButton->setStrictIconSize( true );
00351     mUnreadIconButton->setFixedSize( 28, 28 );
00352     // Can't use iconset here
00353     mUnreadIconButton->setIcon( "folder-open" );
00354     mUnreadIconButton->setEnabled( false );
00355     ihl->addWidget( mUnreadIconButton );
00356     ihl->addStretch( 1 );
00357 
00358     connect( mIconsCheckBox, SIGNAL(toggled(bool)),
00359                     mNormalIconButton, SLOT(setEnabled(bool)) );
00360     connect( mIconsCheckBox, SIGNAL(toggled(bool)),
00361                     mUnreadIconButton, SLOT(setEnabled(bool)) );
00362     connect( mIconsCheckBox, SIGNAL(toggled(bool)),
00363                     mNormalIconLabel, SLOT(setEnabled(bool)) );
00364     connect( mIconsCheckBox, SIGNAL(toggled(bool)),
00365                     mUnreadIconLabel, SLOT(setEnabled(bool)) );
00366 
00367     connect( mNormalIconButton, SIGNAL(iconChanged(const QString&)),
00368                     this, SLOT(slotChangeIcon(const QString&)) );
00369 
00370     //end icons group
00371     addLine( this, topLayout);
00372   }
00373 
00374 
00375   // should new mail in this folder be ignored?
00376   QHBoxLayout *hbl = new QHBoxLayout();
00377   topLayout->addItem( hbl );
00378   hbl->setSpacing( KDialog::spacingHint() );
00379   mNotifyOnNewMailCheckBox =
00380     new QCheckBox( i18n("Act on new/unread mail in this folder" ), this );
00381   mNotifyOnNewMailCheckBox->setWhatsThis(
00382       i18n( "<qt><p>If this option is enabled then you will be notified about "
00383             "new/unread mail in this folder. Moreover, going to the "
00384             "next/previous folder with unread messages will stop at this "
00385             "folder.</p>"
00386             "<p>Uncheck this option if you do not want to be notified about "
00387             "new/unread mail in this folder and if you want this folder to "
00388             "be skipped when going to the next/previous folder with unread "
00389             "messages. This is useful for ignoring any new/unread mail in "
00390             "your trash and spam folder.</p></qt>" ) );
00391   hbl->addWidget( mNotifyOnNewMailCheckBox );
00392 
00393   if ( mDlg->folder()->folderType() == KMFolderTypeImap ) {
00394     // should this folder be included in new-mail-checks?
00395 
00396     QHBoxLayout *nml = new QHBoxLayout();
00397     topLayout->addItem( nml );
00398     nml->setSpacing( KDialog::spacingHint() );
00399     mNewMailCheckBox = new QCheckBox( i18n("Include this folder in mail checks"), this );
00400     // default is on
00401     mNewMailCheckBox->setChecked(true);
00402     nml->addWidget( mNewMailCheckBox );
00403     nml->addStretch( 1 );
00404   }
00405 
00406   // should replies to mails in this folder be kept in this same folder?
00407   hbl = new QHBoxLayout();
00408   topLayout->addItem( hbl );
00409   hbl->setSpacing( KDialog::spacingHint() );
00410   mKeepRepliesInSameFolderCheckBox =
00411     new QCheckBox( i18n("Keep replies in this folder" ), this );
00412   mKeepRepliesInSameFolderCheckBox->setWhatsThis(
00413                    i18n( "Check this option if you want replies you write "
00414                          "to mails in this folder to be put in this same folder "
00415                          "after sending, instead of in the configured sent-mail folder." ) );
00416   hbl->addWidget( mKeepRepliesInSameFolderCheckBox );
00417   hbl->addStretch( 1 );
00418 
00419   addLine( this, topLayout );
00420 
00421   // use grid layout for the following combobox settings
00422   QGridLayout *gl = new QGridLayout();
00423   topLayout->addItem( gl );
00424   gl->setSpacing( KDialog::spacingHint() );
00425   gl->setColumnStretch( 1, 100 ); // make the second column use all available space
00426   int row = -1;
00427 
00428   // sender identity
00429   ++row;
00430   mUseDefaultIdentityCheckBox = new QCheckBox( i18n("Use &default identity"),
00431                                                this );
00432   gl->addWidget( mUseDefaultIdentityCheckBox );
00433   connect( mUseDefaultIdentityCheckBox, SIGNAL( stateChanged(int) ),
00434            this, SLOT( slotIdentityCheckboxChanged() ) );
00435   ++row;
00436   label = new QLabel( i18n("&Sender identity:"), this );
00437   gl->addWidget( label, row, 0 );
00438   mIdentityComboBox = new KPIMIdentities::IdentityCombo( kmkernel->identityManager(), this );
00439   label->setBuddy( mIdentityComboBox );
00440   gl->addWidget( mIdentityComboBox, row, 1 );
00441   mIdentityComboBox->setWhatsThis(
00442       i18n( "Select the sender identity to be used when writing new mail "
00443         "or replying to mail in this folder. This means that if you are in "
00444         "one of your work folders, you can make KMail use the corresponding "
00445         "sender email address, signature and signing or encryption keys "
00446         "automatically. Identities can be set up in the main configuration "
00447         "dialog. (Settings -> Configure KMail)") );
00448 
00449 
00450   // sender or receiver column?
00451   ++row;
00452   QString tip = i18n("Show Sender/Receiver Column in List of Messages");
00453 
00454   QLabel *sender_label = new QLabel( i18n("Sho&w column:" ), this );
00455   gl->addWidget( sender_label, row, 0 );
00456   mShowSenderReceiverComboBox = new QComboBox( this );
00457   mShowSenderReceiverComboBox->setToolTip( tip );
00458   sender_label->setBuddy(mShowSenderReceiverComboBox);
00459   gl->addWidget( mShowSenderReceiverComboBox, row, 1 );
00460   mShowSenderReceiverComboBox->insertItem(0, i18n("Default"));
00461   mShowSenderReceiverComboBox->insertItem(1, i18n("Sender"));
00462   mShowSenderReceiverComboBox->insertItem(2, i18n("Receiver"));
00463 
00464   QString whoField;
00465   if (mDlg->folder()) whoField = mDlg->folder()->userWhoField();
00466   if (whoField.isEmpty()) mShowSenderReceiverComboBox->setCurrentIndex(0);
00467   else if (whoField == "From") mShowSenderReceiverComboBox->setCurrentIndex(1);
00468   else if (whoField == "To") mShowSenderReceiverComboBox->setCurrentIndex(2);
00469 
00470   // folder contents
00471   if ( !mIsLocalSystemFolder && kmkernel->iCalIface().isEnabled() ) {
00472     // Only do make this settable, if the IMAP resource is enabled
00473     // and it's not the personal folders (those must not be changed)
00474     ++row;
00475     label = new QLabel( i18n("&Folder contents:"), this );
00476     gl->addWidget( label, row, 0 );
00477     mContentsComboBox = new QComboBox( this );
00478     label->setBuddy( mContentsComboBox );
00479     gl->addWidget( mContentsComboBox, row, 1 );
00480 
00481     mContentsComboBox->addItem( i18n( "Mail" ) );
00482     mContentsComboBox->addItem( i18n( "Calendar" ) );
00483     mContentsComboBox->addItem( i18n( "Contacts" ) );
00484     mContentsComboBox->addItem( i18n( "Notes" ) );
00485     mContentsComboBox->addItem( i18n( "Tasks" ) );
00486     mContentsComboBox->addItem( i18n( "Journal" ) );
00487     if ( mDlg->folder() )
00488       mContentsComboBox->setCurrentIndex( mDlg->folder()->storage()->contentsType() );
00489     connect ( mContentsComboBox, SIGNAL ( activated( int ) ),
00490               this, SLOT( slotFolderContentsSelectionChanged( int ) ) );
00491     if ( mDlg->folder()->isReadOnly() )
00492       mContentsComboBox->setEnabled( false );
00493   } else {
00494     mContentsComboBox = 0;
00495   }
00496 
00497   mIncidencesForComboBox = 0;
00498   mAlarmsBlockedCheckBox = 0;
00499 
00500   // Kolab incidences-for annotation.
00501   // Show incidences-for combobox if the contents type can be changed (new folder),
00502   // or if it's set to calendar or task (existing folder)
00503   if ( ( GlobalSettings::self()->theIMAPResourceStorageFormat() ==
00504          GlobalSettings::EnumTheIMAPResourceStorageFormat::XML ) &&
00505       mContentsComboBox ) {
00506     ++row;
00507     QLabel* label = new QLabel( i18n( "Generate free/&busy and activate alarms for:" ), this );
00508     gl->addWidget( label, row, 0 );
00509     mIncidencesForComboBox = new QComboBox( this );
00510     label->setBuddy( mIncidencesForComboBox );
00511     gl->addWidget( mIncidencesForComboBox, row, 1 );
00512 
00513     mIncidencesForComboBox->addItem( i18n( "Nobody" ) );
00514     mIncidencesForComboBox->addItem( i18n( "Admins of This Folder" ) );
00515     mIncidencesForComboBox->addItem( i18n( "All Readers of This Folder" ) );
00516     const QString whatsThisForMyOwnFolders = 
00517       i18n( "This setting defines which users sharing "
00518           "this folder should get \"busy\" periods in their freebusy lists "
00519           "and should see the alarms for the events or tasks in this folder. "
00520           "The setting applies to Calendar and Task folders only "
00521           "(for tasks, this setting is only used for alarms).\n\n"
00522           "Example use cases: if the boss shares a folder with his secretary, "
00523           "only the boss should be marked as busy for his meetings, so he should "
00524           "select \"Admins\", since the secretary has no admin rights on the folder.\n"
00525           "On the other hand if a working group shares a Calendar for "
00526           "group meetings, all readers of the folders should be marked "
00527           "as busy for meetings.\n"
00528           "A company-wide folder with optional events in it would use \"Nobody\" "
00529           "since it is not known who will go to those events." );
00530 
00531     mIncidencesForComboBox->setWhatsThis( whatsThisForMyOwnFolders );
00532  
00533     ++row;
00534     const QString whatsThisForReadOnlyFolders =
00535       i18n( "This setting allows you to disable alarms for folders shared by "
00536           "others. ");
00537     mAlarmsBlockedCheckBox = new QCheckBox( this );
00538     gl->addWidget( mAlarmsBlockedCheckBox, row, 0 );
00539     label = new QLabel( i18n( "Block free/&busy and alarms locally" ), this );
00540     gl->addWidget( label, row, 1 );
00541     label->setBuddy( mAlarmsBlockedCheckBox );
00542     mAlarmsBlockedCheckBox->setWhatsThis( whatsThisForReadOnlyFolders );
00543 
00544     if ( mDlg->folder()->storage()->contentsType() != KMail::ContentsTypeCalendar
00545       && mDlg->folder()->storage()->contentsType() != KMail::ContentsTypeTask ) {
00546         mIncidencesForComboBox->setEnabled( false );
00547         mAlarmsBlockedCheckBox->setEnabled( false );
00548     }
00549   } else {
00550     mIncidencesForComboBox = 0;
00551   }
00552 
00553   topLayout->addStretch( 100 ); // eat all superfluous space
00554 
00555   initializeWithValuesFromFolder( mDlg->folder() );
00556 }
00557 
00558 void FolderDialogGeneralTab::load()
00559 {
00560   // Nothing here, all is done in the ctor
00561 }
00562 
00563 void FolderDialogGeneralTab::initializeWithValuesFromFolder( KMFolder* folder ) {
00564   if ( !folder )
00565     return;
00566 
00567   if ( !mIsLocalSystemFolder ) {
00568     // folder icons
00569     mIconsCheckBox->setChecked( folder->useCustomIcons() );
00570     mNormalIconLabel->setEnabled( folder->useCustomIcons() );
00571     mNormalIconButton->setEnabled( folder->useCustomIcons() );
00572     mUnreadIconLabel->setEnabled( folder->useCustomIcons() );
00573     mUnreadIconButton->setEnabled( folder->useCustomIcons() );
00574     QString iconPath = folder->normalIconPath();
00575     if ( !iconPath.isEmpty() )
00576       mNormalIconButton->setIcon( iconPath );
00577     iconPath = folder->unreadIconPath();
00578     if ( !iconPath.isEmpty() )
00579       mUnreadIconButton->setIcon( iconPath );
00580   }
00581 
00582   // folder identity
00583   mIdentityComboBox->setCurrentIdentity( folder->identity() );
00584   mUseDefaultIdentityCheckBox->setChecked( folder->useDefaultIdentity() );
00585 
00586   // ignore new mail
00587   mNotifyOnNewMailCheckBox->setChecked( !folder->ignoreNewMail() );
00588 
00589   const bool keepInFolder = !folder->isReadOnly() && folder->putRepliesInSameFolder();
00590   mKeepRepliesInSameFolderCheckBox->setChecked( keepInFolder );
00591   mKeepRepliesInSameFolderCheckBox->setDisabled( folder->isReadOnly() );
00592 
00593   if (folder->folderType() == KMFolderTypeImap)
00594   {
00595     KMFolderImap* imapFolder = static_cast<KMFolderImap*>(folder->storage());
00596     bool checked = imapFolder->includeInMailCheck();
00597     mNewMailCheckBox->setChecked(checked);
00598   }
00599 
00600   if ( mIncidencesForComboBox ) {
00601     KMFolderCachedImap* dimap = static_cast<KMFolderCachedImap *>( folder->storage() );
00602     mIncidencesForComboBox->setCurrentIndex( dimap->incidencesFor() );
00603     mIncidencesForComboBox->setDisabled( mDlg->folder()->isReadOnly() );
00604   }
00605   if ( mAlarmsBlockedCheckBox ) {
00606     KMFolderCachedImap* dimap = static_cast<KMFolderCachedImap *>( folder->storage() );
00607     mAlarmsBlockedCheckBox->setChecked( dimap->alarmsBlocked() );
00608   }
00609 }
00610 
00611 //-----------------------------------------------------------------------------
00612 void FolderDialogGeneralTab::slotFolderNameChanged( const QString& str )
00613 {
00614   mDlg->enableButtonOk( !str.isEmpty() );
00615 }
00616 
00617 //-----------------------------------------------------------------------------
00618 void FolderDialogGeneralTab::slotFolderContentsSelectionChanged( int )
00619 {
00620   KMail::FolderContentsType type =
00621     static_cast<KMail::FolderContentsType>( mContentsComboBox->currentIndex() );
00622   if( type != KMail::ContentsTypeMail && GlobalSettings::self()->hideGroupwareFolders() ) {
00623     QString message = i18n("You have configured this folder to contain groupware information "
00624         "and the general configuration option to hide groupware folders is "
00625         "set. That means that this folder will disappear once the configuration "
00626         "dialog is closed. If you want to remove the folder again, you will need "
00627         "to temporarily disable hiding of groupware folders to be able to see it.");
00628     KMessageBox::information( this, message );
00629   }
00630 
00631   const bool enable = type == KMail::ContentsTypeCalendar || type == KMail::ContentsTypeTask;
00632   if ( mIncidencesForComboBox )
00633       mIncidencesForComboBox->setEnabled( enable );
00634   if ( mAlarmsBlockedCheckBox )
00635       mAlarmsBlockedCheckBox->setEnabled( enable );
00636 }
00637 
00638 //-----------------------------------------------------------------------------
00639 void FolderDialogGeneralTab::slotIdentityCheckboxChanged()
00640 {
00641   mIdentityComboBox->setEnabled( !mUseDefaultIdentityCheckBox->isChecked() );
00642 }
00643 
00644 //-----------------------------------------------------------------------------
00645 bool FolderDialogGeneralTab::save()
00646 {
00647   KMFolder* folder = mDlg->folder();
00648   folder->setIdentity( mIdentityComboBox->currentIdentity() );
00649   folder->setUseDefaultIdentity( mUseDefaultIdentityCheckBox->isChecked() );
00650   // set whoField
00651   if (mShowSenderReceiverComboBox->currentIndex() == 1)
00652     folder->setUserWhoField("From");
00653   else if (mShowSenderReceiverComboBox->currentIndex() == 2)
00654     folder->setUserWhoField("To");
00655   else
00656     folder->setUserWhoField("");
00657 
00658   folder->setIgnoreNewMail( !mNotifyOnNewMailCheckBox->isChecked() );
00659   folder->setPutRepliesInSameFolder( mKeepRepliesInSameFolderCheckBox->isChecked() );
00660 
00661   QString fldName, oldFldName;
00662   if ( !mIsLocalSystemFolder )
00663   {
00664     QString acctName;
00665     oldFldName = mDlg->folder()->name();
00666 
00667     if (!mNameEdit->text().isEmpty())
00668       fldName = mNameEdit->text();
00669     else
00670       fldName = oldFldName;
00671 
00672     if ( mDlg->parentFolder() &&
00673          mDlg->parentFolder()->folderType() != KMFolderTypeImap &&
00674          mDlg->parentFolder()->folderType() != KMFolderTypeCachedImap )
00675       fldName.remove('/');
00676     fldName.remove(QRegExp("^\\.*"));
00677     if (fldName.isEmpty()) fldName = i18n("unnamed");
00678 
00679 
00680     // Update the tree iff new icon paths are different and not empty or if
00681     // useCustomIcons changed.
00682     if ( folder->useCustomIcons() != mIconsCheckBox->isChecked() ) {
00683       folder->setUseCustomIcons( mIconsCheckBox->isChecked() );
00684       // Reset icons, useCustomIcons was turned off.
00685       if ( !folder->useCustomIcons() ) {
00686         folder->setIconPaths( "", "" );
00687       }
00688     }
00689     if ( folder->useCustomIcons() &&
00690         (( mNormalIconButton->icon() != folder->normalIconPath() ) &&
00691          ( !mNormalIconButton->icon().isEmpty())) ||
00692         (( mUnreadIconButton->icon() != folder->unreadIconPath() ) &&
00693          ( !mUnreadIconButton->icon().isEmpty())) ) {
00694       folder->setIconPaths( mNormalIconButton->icon(), mUnreadIconButton->icon() );
00695     }
00696 
00697     // Set type field
00698     if ( mContentsComboBox ) {
00699       KMail::FolderContentsType type =
00700         static_cast<KMail::FolderContentsType>( mContentsComboBox->currentIndex() );
00701       folder->storage()->setContentsType( type );
00702     }
00703 
00704     if ( folder->folderType() == KMFolderTypeCachedImap ) {
00705       KMFolderCachedImap* dimap = static_cast<KMFolderCachedImap *>( mDlg->folder()->storage() );
00706       if ( mIncidencesForComboBox ) {
00707         KMFolderCachedImap::IncidencesFor incfor = 
00708                static_cast<KMFolderCachedImap::IncidencesFor>( mIncidencesForComboBox->currentIndex() );
00709         if ( dimap->incidencesFor() != incfor ) {
00710           dimap->setIncidencesFor( incfor );
00711           dimap->writeConfig();
00712         }
00713       }
00714       if ( mAlarmsBlockedCheckBox && mAlarmsBlockedCheckBox->isChecked() != dimap->alarmsBlocked() ) {
00715         dimap->setAlarmsBlocked( mAlarmsBlockedCheckBox->isChecked() );
00716         dimap->writeConfig();
00717       }
00718     }
00719 
00720     if( folder->folderType() == KMFolderTypeImap )
00721     {
00722       KMFolderImap* imapFolder = static_cast<KMFolderImap*>( folder->storage() );
00723       imapFolder->setIncludeInMailCheck(
00724           mNewMailCheckBox->isChecked() );
00725     }
00726     // make sure everything is on disk, connected slots will call readConfig()
00727     // when creating a new folder.
00728     folder->storage()->writeConfig();
00729     // Renamed an existing folder? We don't check for oldName == newName on
00730     // purpose here. The folder might be pending renaming on the next dimap
00731     // sync already, in which case the old name would still be around and
00732     // something like Calendar -> CalendarFoo -> Calendar inbetween syncs would
00733     // fail. Therefor let the folder sort it out itself, whether the rename is
00734     // a noop or not.
00735     if ( !oldFldName.isEmpty() )
00736     {
00737       kmkernel->folderMgr()->renameFolder( folder, fldName );
00738     } else {
00739       kmkernel->folderMgr()->contentsChanged();
00740     }
00741   }
00742   return true;
00743 }
00744 
00745 void FolderDialogGeneralTab::slotChangeIcon( const QString &icon )
00746 {
00747     mUnreadIconButton->setIcon( icon );
00748 }
00749 
00750 //----------------------------------------------------------------------------
00751 KMail::FolderDialogTemplatesTab::FolderDialogTemplatesTab( KMFolderDialog *dlg,
00752                                                      QWidget *parent )
00753   : FolderDialogTab( parent, 0 ), mDlg( dlg )
00754 {
00755 
00756   mIsLocalSystemFolder = mDlg->folder()->isSystemFolder() &&
00757        mDlg->folder()->folderType() != KMFolderTypeImap &&
00758        mDlg->folder()->folderType() != KMFolderTypeCachedImap;
00759 
00760   QVBoxLayout *topLayout = new QVBoxLayout( this );
00761   topLayout->setMargin( 0 );
00762   topLayout->setSpacing( KDialog::spacingHint() );
00763 
00764   QHBoxLayout *topItems = new QHBoxLayout( this );
00765   topLayout->addLayout( topItems );
00766 
00767   mCustom = new QCheckBox( i18n("&Use custom message templates"), this );
00768   topItems->addWidget( mCustom, Qt::AlignLeft );
00769 
00770   mWidget = new TemplatesConfiguration( this, "folder-templates" );
00771   mWidget->setEnabled( false );
00772 
00773   // Move the help label outside of the templates configuration widget,
00774   // so that the help can be read even if the widget is not enabled.
00775   topItems->addStretch( 9 );
00776   topItems->addWidget( mWidget->helpLabel(), Qt::AlignRight );
00777 
00778   topLayout->addWidget( mWidget );
00779 
00780   QHBoxLayout *btns = new QHBoxLayout();
00781   btns->setSpacing( KDialog::spacingHint() );
00782   mCopyGlobal = new KPushButton( i18n("&Copy Global Templates"), this );
00783   mCopyGlobal->setEnabled( false );
00784   btns->addWidget( mCopyGlobal );
00785   topLayout->addLayout( btns );
00786 
00787   connect( mCustom, SIGNAL(toggled( bool )),
00788            mWidget, SLOT(setEnabled( bool )) );
00789   connect( mCustom, SIGNAL(toggled( bool )),
00790            mCopyGlobal, SLOT(setEnabled( bool )) );
00791 
00792   connect( mCopyGlobal, SIGNAL(clicked()),
00793            this, SLOT(slotCopyGlobal()) );
00794 
00795   initializeWithValuesFromFolder( mDlg->folder() );
00796 
00797   connect( mWidget, SIGNAL(changed()),
00798            this, SLOT(slotEmitChanged( void )) );
00799 }
00800 
00801 void FolderDialogTemplatesTab::load()
00802 {
00803 
00804 }
00805 
00806 void FolderDialogTemplatesTab::initializeWithValuesFromFolder( KMFolder* folder ) {
00807   if ( !folder )
00808     return;
00809 
00810   mFolder = folder;
00811 
00812   QString fid = folder->idString();
00813 
00814   Templates t( fid );
00815 
00816   mCustom->setChecked(t.useCustomTemplates());
00817 
00818   mIdentity = folder->identity();
00819 
00820   mWidget->loadFromFolder( fid, mIdentity );
00821 }
00822 
00823 //-----------------------------------------------------------------------------
00824 bool FolderDialogTemplatesTab::save()
00825 {
00826   KMFolder* folder = mDlg->folder();
00827 
00828   QString fid = folder->idString();
00829   Templates t(fid);
00830 
00831   kDebug(5006) <<"use custom templates for folder" << fid <<":" << mCustom->isChecked();
00832   t.setUseCustomTemplates(mCustom->isChecked());
00833   t.writeConfig();
00834 
00835   mWidget->saveToFolder(fid);
00836 
00837   return true;
00838 }
00839 
00840 
00841 void FolderDialogTemplatesTab::slotEmitChanged() {}
00842 
00843 void FolderDialogTemplatesTab::slotCopyGlobal() {
00844   if ( mIdentity ) {
00845     mWidget->loadFromIdentity( mIdentity );
00846   }
00847   else {
00848     mWidget->loadFromGlobal();
00849   }
00850 }
00851 
00852 #include "kmfolderdialog.moc"

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages