kmail

kmfolderdia.cpp
1 // -*- mode: C++; c-file-style: "gnu" -*-
33 #include <config.h>
34 
35 #include "acljobs.h"
36 #include "kmfolderdia.h"
37 #include "kmacctfolder.h"
38 #include "kmfoldermgr.h"
39 #include <libkpimidentities/identitycombo.h>
40 #include "kmfolderimap.h"
41 #include "kmfoldercachedimap.h"
42 #include "kmfolder.h"
43 #include "kmheaders.h"
44 #include "kmcommands.h"
45 #include "kmfoldertree.h"
46 #include "folderdiaacltab.h"
47 #include "folderdiaquotatab.h"
48 #include "kmailicalifaceimpl.h"
49 #include "globalsettings.h"
50 #include "folderrequester.h"
51 
52 #include <keditlistbox.h>
53 #include <klineedit.h>
54 #include <tdelocale.h>
55 #include <knuminput.h>
56 #include <tdemessagebox.h>
57 #include <kicondialog.h>
58 #include <tdeconfig.h>
59 #include <kdebug.h>
60 #include <tdelistview.h>
61 #include <kpushbutton.h>
62 
63 #include <tqcheckbox.h>
64 #include <tqlayout.h>
65 #include <tqgroupbox.h>
66 #include <tqregexp.h>
67 #include <tqlabel.h>
68 #include <tqvbox.h>
69 #include <tqtooltip.h>
70 #include <tqwhatsthis.h>
71 
72 #include <assert.h>
73 #include <tqhbuttongroup.h>
74 #include <tqradiobutton.h>
75 #include <tqtextedit.h>
76 
77 #include "templatesconfiguration.h"
78 #include "templatesconfiguration_kfg.h"
79 
80 #include "kmfolderdia.moc"
81 
82 using namespace KMail;
83 
84 static TQString inCaseWeDecideToRenameTheTab( I18N_NOOP( "Permissions (ACL)" ) );
85 
86 //-----------------------------------------------------------------------------
87 KMFolderDialog::KMFolderDialog(KMFolder *aFolder, KMFolderDir *aFolderDir,
88  KMFolderTree* aParent, const TQString& aCap,
89  const TQString& aName):
90  KDialogBase( KDialogBase::Tabbed,
91  aCap, KDialogBase::Ok|KDialogBase::Cancel,
92  KDialogBase::Ok, aParent, "KMFolderDialog", TRUE ),
93  mFolder( aFolder ),
94  mFolderDir( aFolderDir ),
95  mParentFolder( 0 ),
96  mIsNewFolder( aFolder == 0 ),
97  mFolderTree( aParent )
98 {
99  kdDebug(5006)<<"KMFolderDialog::KMFolderDialog()" << endl;
100 
101  TQStringList folderNames;
102  TQValueList<TQGuardedPtr<KMFolder> > folders;
103  // get all folders but search and folders that can not have children
104  aParent->createFolderList(&folderNames, &folders, true, true,
105  true, false, true, false);
106 
107  if( mFolderDir ) {
108  // search the parent folder of the folder
109  FolderList::ConstIterator it;
110  int i = 1;
111  for( it = folders.begin(); it != folders.end(); ++it, ++i ) {
112  if( (*it)->child() == mFolderDir ) {
113  mParentFolder = *it;
114  break;
115  }
116  }
117  }
118 
119  FolderDiaTab* tab;
120  TQVBox* box;
121 
122  box = addVBoxPage( i18n("General") );
123  tab = new FolderDiaGeneralTab( this, aName, box );
124  addTab( tab );
125  box = addVBoxPage( i18n("Templates") );
126  tab = new FolderDiaTemplatesTab( this, box );
127  addTab( tab );
128 
129  KMFolder* refFolder = mFolder ? mFolder : mParentFolder;
130  KMFolderType folderType = refFolder ? refFolder->folderType() : KMFolderTypeUnknown;
131  bool noContent = mFolder ? mFolder->storage()->noContent() : false;
132  if ( !noContent && refFolder && ( folderType == KMFolderTypeImap || folderType == KMFolderTypeCachedImap ) ) {
133  if ( FolderDiaACLTab::supports( refFolder ) ) {
134  box = addVBoxPage( i18n("Access Control") );
135  tab = new FolderDiaACLTab( this, box );
136  addTab( tab );
137  }
138  }
139  if ( !noContent && refFolder && ( folderType == KMFolderTypeImap || folderType == KMFolderTypeCachedImap ) ) {
140  if ( FolderDiaQuotaTab::supports( refFolder ) ) {
141  box = addVBoxPage( i18n("Quota") );
142  tab = new FolderDiaQuotaTab( this, box );
143  addTab( tab );
144  }
145  }
146 
147  for ( unsigned int i = 0 ; i < mTabs.count() ; ++i )
148  mTabs[i]->load();
149 }
150 
151 void KMFolderDialog::addTab( FolderDiaTab* tab )
152 {
153  connect( tab, TQT_SIGNAL( readyForAccept() ),
154  this, TQT_SLOT( slotReadyForAccept() ) );
155  connect( tab, TQT_SIGNAL( cancelAccept() ),
156  this, TQT_SLOT( slotCancelAccept() ) );
157  //connect( tab, TQT_SIGNAL(changed( bool )),
158  // this, TQT_SLOT(slotChanged( bool )) );
159  mTabs.append( tab );
160 }
161 
162 // Not used yet (no button), but ready to be used :)
163 void KMFolderDialog::slotApply()
164 {
165  if ( mFolder.isNull() && !mIsNewFolder ) { // deleted meanwhile?
166  KDialogBase::slotApply();
167  return;
168  }
169  for ( unsigned int i = 0 ; i < mTabs.count() ; ++i )
170  mTabs[i]->save();
171  if ( !mFolder.isNull() && mIsNewFolder ) // we just created it
172  mIsNewFolder = false; // so it's not new anymore :)
173  KDialogBase::slotApply();
174 }
175 
176 // Called when pressing Ok
177 // We want to apply the changes first (which is async), before closing the dialog,
178 // in case of errors during the upload.
179 void KMFolderDialog::slotOk()
180 {
181  if ( mFolder.isNull() && !mIsNewFolder ) { // deleted meanwhile?
182  KDialogBase::slotOk();
183  return;
184  }
185 
186  mDelayedSavingTabs = 0; // number of tabs which need delayed saving
187  for ( unsigned int i = 0 ; i < mTabs.count() ; ++i ) {
188  FolderDiaTab::AccepStatus s = mTabs[i]->accept();
189  if ( s == FolderDiaTab::Canceled ) {
190  slotCancelAccept();
191  return;
192  }
193  else if ( s == FolderDiaTab::Delayed )
194  ++mDelayedSavingTabs;
195  }
196 
197  if ( mDelayedSavingTabs )
198  enableButtonOK( false );
199  else
200  KDialogBase::slotOk();
201 }
202 
203 void KMFolderDialog::slotReadyForAccept()
204 {
205  --mDelayedSavingTabs;
206  if ( mDelayedSavingTabs == 0 )
207  KDialogBase::slotOk();
208 }
209 
210 void KMFolderDialog::slotCancelAccept()
211 {
212  mDelayedSavingTabs = -1;
213  enableButtonOK( true );
214  // Don't try to create it twice
215  if ( !mFolder.isNull() )
216  mIsNewFolder = false;
217 
218  // Other tabs might call slotReadyForAccept. -1 ensures that it won't close the dialog,
219  // but the OK button being enabled means that people might succeed in running
220  // the same job from save more than once.
221  // Solution: mAcceptCanceled = true instead of -1.
222  // Bah for now we only have one tab which can delay saving -> later.
223 }
224 
225 void KMFolderDialog::slotChanged( bool )
226 {
227  // TODO, support for 'changed', and Apply button.
228  // sample code for here: KCMultiDialog calls bool changed() on every TDECModuleProxy...
229 }
230 
231 void KMFolderDialog::setFolder( KMFolder* folder )
232 {
233  Q_ASSERT( mFolder.isNull() );
234  mFolder = folder;
235 }
236 
237 static void addLine( TQWidget *parent, TQVBoxLayout* layout )
238 {
239  TQFrame *line = new TQFrame( parent, "line" );
240  line->setGeometry( TQRect( 80, 150, 250, 20 ) );
241  line->setFrameShape( TQFrame::HLine );
242  line->setFrameShadow( TQFrame::Sunken );
243  line->setFrameShape( TQFrame::HLine );
244  layout->addWidget( line );
245 }
246 
247 //----------------------------------------------------------------------------
248 KMail::FolderDiaGeneralTab::FolderDiaGeneralTab( KMFolderDialog* dlg,
249  const TQString& aName,
250  TQWidget* parent, const char* name )
251  : FolderDiaTab( parent, name ),
252  mSharedSeenFlagsCheckBox( 0 ),
253  mDlg( dlg )
254 {
255 
256  mIsLocalSystemFolder = mDlg->folder()->isSystemFolder();
257  mIsResourceFolder = kmkernel->iCalIface().isStandardResourceFolder( mDlg->folder() );
258 
259  TQLabel *label;
260 
261  TQVBoxLayout *topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
262 
263  // Musn't be able to edit details for a non-resource, system folder.
264  if ( !mIsLocalSystemFolder || mIsResourceFolder ) {
265 
266  TQHBoxLayout *hl = new TQHBoxLayout( topLayout );
267  hl->setSpacing( KDialog::spacingHint() );
268 
269  label = new TQLabel( i18n("&Name:"), this );
270  hl->addWidget( label );
271 
272  // Determine if we are allowed to rename this folder. Only possible if the folder supports
273  // ACLs.
274  bool nameChangeAllowed = true;
275  if ( mDlg->folder() && mDlg->parentFolder() &&
276  mDlg->folder()->storage() && mDlg->parentFolder()->storage() &&
277  ( mDlg->folder()->folderType() == KMFolderTypeCachedImap ||
278  mDlg->folder()->folderType() == KMFolderTypeImap ) ) {
279  ImapAccountBase *account = 0;
280  KMFolderCachedImap *dimap = 0;
281  KMFolderImap *imap = 0;
282  if ( mDlg->folder()->folderType() == KMFolderTypeCachedImap ) {
283  dimap = static_cast<KMFolderCachedImap*>( mDlg->folder()->storage() );
284  account = dynamic_cast<ImapAccountBase*>( dimap->account() );
285  }
286  if ( mDlg->folder()->folderType() == KMFolderTypeImap ) {
287  imap = static_cast<KMFolderImap*>( mDlg->folder()->storage() );
288  account = dynamic_cast<ImapAccountBase*>( imap->account() );
289  }
290 
291  if ( account && account->hasACLSupport() ) {
292  int parentRights = -1;
293  int folderRights = -1;
294  bool parentRightsOk = false;
295  bool folderRightsOk = false;
296  if ( imap ) {
297  KMFolderImap * const parent = dynamic_cast<KMFolderImap*>( mDlg->parentFolder()->storage() );
298  folderRights = imap->userRights();
299  folderRightsOk = imap->userRightsState() == KMail::ACLJobs::Ok;
300  if ( parent ) {
301  parentRights = parent->userRights();
302  parentRightsOk = parent->userRightsState() == KMail::ACLJobs::Ok;
303  }
304  } else if ( dimap ) {
305  KMFolderCachedImap * const parent = dynamic_cast<KMFolderCachedImap*>( mDlg->parentFolder()->storage() );
306  folderRights = dimap->userRights();
307  folderRightsOk = dimap->userRightsState() == KMail::ACLJobs::Ok;
308  if ( parent ) {
309  parentRights = parent->userRights();
310  parentRightsOk = parent->userRightsState() == KMail::ACLJobs::Ok;
311  }
312  }
313 
314  // For renaming, we need support for deleting the mailbox and then re-creating it.
315  if ( parentRightsOk && folderRightsOk &&
316  ( !( parentRights & KMail::ACLJobs::Create ) || !( folderRights & KMail::ACLJobs::Delete ) ) ) {
317  nameChangeAllowed = false;
318  }
319  }
320  }
321 
322  mNameEdit = new KLineEdit( this );
323  if( !mDlg->folder() && nameChangeAllowed )
324  mNameEdit->setFocus();
325  mNameEdit->setEnabled( nameChangeAllowed );
326  if ( !nameChangeAllowed ) {
327  TQToolTip::add( mNameEdit, i18n( "Not enough permissions to rename this folder.\n"
328  "The parent folder doesn't have write support.\n"
329  "A sync is needed after changing the permissions." ) );
330  }
331  mNameEdit->setText( mDlg->folder() ? mDlg->folder()->label() : i18n("unnamed") );
332  if (!aName.isEmpty())
333  mNameEdit->setText(aName);
334  mNameEdit->setMinimumSize(mNameEdit->sizeHint());
335  // prevent renaming of IMAP inbox
336  if ( mDlg->folder() && mDlg->folder()->isSystemFolder() ) {
337  TQString imapPath;
338  if ( mDlg->folder()->folderType() == KMFolderTypeImap )
339  imapPath = static_cast<KMFolderImap*>( mDlg->folder()->storage() )->imapPath();
340  if ( mDlg->folder()->folderType() == KMFolderTypeCachedImap )
341  imapPath = static_cast<KMFolderCachedImap*>( mDlg->folder()->storage() )->imapPath();
342  if ( imapPath == "/INBOX/" )
343  mNameEdit->setEnabled( false );
344  }
345  label->setBuddy( mNameEdit );
346  hl->addWidget( mNameEdit );
347  connect( mNameEdit, TQT_SIGNAL( textChanged( const TQString & ) ),
348  this, TQT_SLOT( slotFolderNameChanged( const TQString & ) ) );
349 
350 
351  //start icons group
352  TQVBoxLayout *ivl = new TQVBoxLayout( topLayout );
353  ivl->setSpacing( KDialog::spacingHint() );
354 
355  TQHBoxLayout *ihl = new TQHBoxLayout( ivl );
356  mIconsCheckBox = new TQCheckBox( i18n("Use custom &icons"), this );
357  mIconsCheckBox->setChecked( false );
358  ihl->addWidget( mIconsCheckBox );
359  ihl->addStretch( 2 );
360 
361  mNormalIconLabel = new TQLabel( i18n("&Normal:"), this );
362  mNormalIconLabel->setEnabled( false );
363  ihl->addWidget( mNormalIconLabel );
364 
365  mNormalIconButton = new TDEIconButton( this );
366  mNormalIconLabel->setBuddy( mNormalIconButton );
367  mNormalIconButton->setIconType( TDEIcon::NoGroup , TDEIcon::Any, true );
368  mNormalIconButton->setIconSize( 16 );
369  mNormalIconButton->setStrictIconSize( true );
370  mNormalIconButton->setFixedSize( 28, 28 );
371  // Can't use iconset here
372  mNormalIconButton->setIcon( "folder" );
373  mNormalIconButton->setEnabled( false );
374  ihl->addWidget( mNormalIconButton );
375 
376  mUnreadIconLabel = new TQLabel( i18n("&Unread:"), this );
377  mUnreadIconLabel->setEnabled( false );
378  ihl->addWidget( mUnreadIconLabel );
379 
380  mUnreadIconButton = new TDEIconButton( this );
381  mUnreadIconLabel->setBuddy( mUnreadIconButton );
382  mUnreadIconButton->setIconType( TDEIcon::NoGroup, TDEIcon::Any, true );
383  mUnreadIconButton->setIconSize( 16 );
384  mUnreadIconButton->setStrictIconSize( true );
385  mUnreadIconButton->setFixedSize( 28, 28 );
386  // Can't use iconset here
387  mUnreadIconButton->setIcon( "folder_open" );
388  mUnreadIconButton->setEnabled( false );
389  ihl->addWidget( mUnreadIconButton );
390  ihl->addStretch( 1 );
391 
392  connect( mIconsCheckBox, TQT_SIGNAL(toggled(bool)),
393  mNormalIconButton, TQT_SLOT(setEnabled(bool)) );
394  connect( mIconsCheckBox, TQT_SIGNAL(toggled(bool)),
395  mUnreadIconButton, TQT_SLOT(setEnabled(bool)) );
396  connect( mIconsCheckBox, TQT_SIGNAL(toggled(bool)),
397  mNormalIconLabel, TQT_SLOT(setEnabled(bool)) );
398  connect( mIconsCheckBox, TQT_SIGNAL(toggled(bool)),
399  mUnreadIconLabel, TQT_SLOT(setEnabled(bool)) );
400 
401  connect( mNormalIconButton, TQT_SIGNAL(iconChanged(TQString)),
402  this, TQT_SLOT(slotChangeIcon(TQString)) );
403 
404  //end icons group
405  addLine( this, topLayout);
406  }
407 
408 
409  // should new mail in this folder be ignored?
410  TQHBoxLayout *hbl = new TQHBoxLayout( topLayout );
411  hbl->setSpacing( KDialog::spacingHint() );
412  mNotifyOnNewMailCheckBox =
413  new TQCheckBox( i18n("Act on new/unread mail in this folder" ), this );
414  TQWhatsThis::add( mNotifyOnNewMailCheckBox,
415  i18n( "<qt><p>If this option is enabled then you will be notified about "
416  "new/unread mail in this folder. Moreover, going to the "
417  "next/previous folder with unread messages will stop at this "
418  "folder.</p>"
419  "<p>Uncheck this option if you do not want to be notified about "
420  "new/unread mail in this folder and if you want this folder to "
421  "be skipped when going to the next/previous folder with unread "
422  "messages. This is useful for ignoring any new/unread mail in "
423  "your trash and spam folder.</p></qt>" ) );
424  hbl->addWidget( mNotifyOnNewMailCheckBox );
425 
426  if ( mDlg->folder()->folderType() == KMFolderTypeImap ) {
427  // should this folder be included in new-mail-checks?
428 
429  TQHBoxLayout *nml = new TQHBoxLayout( topLayout );
430  nml->setSpacing( KDialog::spacingHint() );
431  mNewMailCheckBox = new TQCheckBox( i18n("Include this folder in mail checks"), this );
432  // default is on
433  mNewMailCheckBox->setChecked(true);
434  nml->addWidget( mNewMailCheckBox );
435  nml->addStretch( 1 );
436  }
437 
438  // should replies to mails in this folder be kept in this same folder?
439  hbl = new TQHBoxLayout( topLayout );
440  hbl->setSpacing( KDialog::spacingHint() );
441  mKeepRepliesInSameFolderCheckBox =
442  new TQCheckBox( i18n("Keep replies in this folder" ), this );
443  TQWhatsThis::add( mKeepRepliesInSameFolderCheckBox,
444  i18n( "Check this option if you want replies you write "
445  "to mails in this folder to be put in this same folder "
446  "after sending, instead of in the configured sent-mail folder." ) );
447  hbl->addWidget( mKeepRepliesInSameFolderCheckBox );
448  hbl->addStretch( 1 );
449 
450  addLine( this, topLayout );
451 
452  // use grid layout for the following combobox settings
453  TQGridLayout *gl = new TQGridLayout( topLayout, 3, 2, KDialog::spacingHint() );
454  gl->setColStretch( 1, 100 ); // make the second column use all available space
455  int row = -1;
456 
457  // sender or receiver column?
458  ++row;
459  TQString tip = i18n("Show Sender/Receiver Column in List of Messages");
460 
461  TQLabel *sender_label = new TQLabel( i18n("Sho&w column:" ), this );
462  gl->addWidget( sender_label, row, 0 );
463  mShowSenderReceiverComboBox = new TQComboBox( this );
464  TQToolTip::add( mShowSenderReceiverComboBox, tip );
465  sender_label->setBuddy(mShowSenderReceiverComboBox);
466  gl->addWidget( mShowSenderReceiverComboBox, row, 1 );
467  mShowSenderReceiverComboBox->insertItem(i18n("Default"), 0);
468  mShowSenderReceiverComboBox->insertItem(i18n("Sender"), 1);
469  mShowSenderReceiverComboBox->insertItem(i18n("Receiver"), 2);
470 
471  TQString whoField;
472  if (mDlg->folder()) whoField = mDlg->folder()->userWhoField();
473  if (whoField.isEmpty()) mShowSenderReceiverComboBox->setCurrentItem(0);
474  else if (whoField == "From") mShowSenderReceiverComboBox->setCurrentItem(1);
475  else if (whoField == "To") mShowSenderReceiverComboBox->setCurrentItem(2);
476 
477 
478  // sender identity
479  ++row;
480  label = new TQLabel( i18n("&Sender identity:"), this );
481  gl->addWidget( label, row, 0 );
482  mIdentityComboBox = new KPIM::IdentityCombo( kmkernel->identityManager(), this );
483  label->setBuddy( mIdentityComboBox );
484  gl->addWidget( mIdentityComboBox, row, 1 );
485  TQWhatsThis::add( mIdentityComboBox,
486  i18n( "Select the sender identity to be used when writing new mail "
487  "or replying to mail in this folder. This means that if you are in "
488  "one of your work folders, you can make KMail use the corresponding "
489  "sender email address, signature and signing or encryption keys "
490  "automatically. Identities can be set up in the main configuration "
491  "dialog. (Settings -> Configure KMail)") );
492 
493  // folder contents
494  if ( ( !mIsLocalSystemFolder || mIsResourceFolder ) &&
495  kmkernel->iCalIface().isEnabled() &&
496  mDlg->folder() && mDlg->folder()->folderType() != KMFolderTypeImap ) {
497  // Only do make this settable, if the IMAP resource is enabled
498  // and it's not the personal folders (those must not be changed)
499  ++row;
500  label = new TQLabel( i18n("&Folder contents:"), this );
501  gl->addWidget( label, row, 0 );
502  mContentsComboBox = new TQComboBox( this );
503  label->setBuddy( mContentsComboBox );
504  gl->addWidget( mContentsComboBox, row, 1 );
505 
506  mContentsComboBox->insertItem( i18n( "Mail" ) );
507  mContentsComboBox->insertItem( i18n( "Calendar" ) );
508  mContentsComboBox->insertItem( i18n( "Contacts" ) );
509  mContentsComboBox->insertItem( i18n( "Notes" ) );
510  mContentsComboBox->insertItem( i18n( "Tasks" ) );
511  mContentsComboBox->insertItem( i18n( "Journal" ) );
512  if ( mDlg->folder() )
513  mContentsComboBox->setCurrentItem( mDlg->folder()->storage()->contentsType() );
514  connect ( mContentsComboBox, TQT_SIGNAL ( activated( int ) ),
515  this, TQT_SLOT( slotFolderContentsSelectionChanged( int ) ) );
516  if ( mDlg->folder()->isReadOnly() || mIsResourceFolder )
517  mContentsComboBox->setEnabled( false );
518  } else {
519  mContentsComboBox = 0;
520  }
521 
522  mIncidencesForComboBox = 0;
523  mAlarmsBlockedCheckBox = 0;
524 
525  // Kolab incidences-for annotation.
526  // Show incidences-for combobox if the contents type can be changed (new folder),
527  // or if it's set to calendar or task (existing folder)
528  if ( ( GlobalSettings::self()->theIMAPResourceStorageFormat() ==
529  GlobalSettings::EnumTheIMAPResourceStorageFormat::XML ) &&
530  mContentsComboBox ) {
531  ++row;
532 
533  TQLabel* label = new TQLabel( i18n( "Generate free/&busy and activate alarms for:" ), this );
534  gl->addWidget( label, row, 0 );
535  mIncidencesForComboBox = new TQComboBox( this );
536  label->setBuddy( mIncidencesForComboBox );
537  gl->addWidget( mIncidencesForComboBox, row, 1 );
538 
539  const TQString whatsThisForMyOwnFolders =
540  i18n( "This setting defines which users sharing "
541  "this folder should get \"busy\" periods in their freebusy lists "
542  "and should see the alarms for the events or tasks in this folder. "
543  "The setting applies to Calendar and Task folders only "
544  "(for tasks, this setting is only used for alarms).\n\n"
545  "Example use cases: if the boss shares a folder with his secretary, "
546  "only the boss should be marked as busy for his meetings, so he should "
547  "select \"Admins\", since the secretary has no admin rights on the folder.\n"
548  "On the other hand if a working group shares a Calendar for "
549  "group meetings, all readers of the folders should be marked "
550  "as busy for meetings.\n"
551  "A company-wide folder with optional events in it would use \"Nobody\" "
552  "since it is not known who will go to those events." );
553 
554  TQWhatsThis::add( mIncidencesForComboBox, whatsThisForMyOwnFolders );
555  mIncidencesForComboBox->insertItem( i18n( "Nobody" ) );
556  mIncidencesForComboBox->insertItem( i18n( "Admins of This Folder" ) );
557  mIncidencesForComboBox->insertItem( i18n( "All Readers of This Folder" ) );
558  ++row;
559  const TQString whatsThisForReadOnlyFolders =
560  i18n( "This setting allows you to disable alarms for folders shared by others. ");
561  mAlarmsBlockedCheckBox = new TQCheckBox( this );
562  mAlarmsBlockedCheckBox->setText( i18n( "Block alarms locally" ) );
563  gl->addMultiCellWidget( mAlarmsBlockedCheckBox, row, row, 0, 1);
564  TQWhatsThis::add( mAlarmsBlockedCheckBox, whatsThisForReadOnlyFolders );
565 
566  if ( mDlg->folder()->storage()->contentsType() != KMail::ContentsTypeCalendar
567  && mDlg->folder()->storage()->contentsType() != KMail::ContentsTypeTask ) {
568  mIncidencesForComboBox->setEnabled( false );
569  mAlarmsBlockedCheckBox->setEnabled( false );
570  }
571  }
572 
573  if ( mDlg->folder()->folderType() == KMFolderTypeCachedImap ) {
574  kdDebug() << k_funcinfo << mDlg->folder()->folderType() << endl;
575  mSharedSeenFlagsCheckBox = new TQCheckBox( this );
576  mSharedSeenFlagsCheckBox->setText( i18n( "Share unread state with all users" ) );
577  ++row;
578  gl->addMultiCellWidget( mSharedSeenFlagsCheckBox, row, row, 0, 1 );
579  TQWhatsThis::add( mSharedSeenFlagsCheckBox, i18n( "If enabled, the unread state of messages in this folder will be the same "
580  "for all users having access to this folders. If disabled (the default), every user with access to this folder has her "
581  "own unread state." ) );
582  }
583  topLayout->addStretch( 100 ); // eat all superfluous space
584 
585  initializeWithValuesFromFolder( mDlg->folder() );
586 }
587 
588 void FolderDiaGeneralTab::load()
589 {
590  // Nothing here, all is done in the ctor
591 }
592 
593 void FolderDiaGeneralTab::initializeWithValuesFromFolder( KMFolder* folder ) {
594  if ( !folder )
595  return;
596 
597  if ( !mIsLocalSystemFolder ) {
598  // folder icons
599  mIconsCheckBox->setChecked( folder->useCustomIcons() );
600  mNormalIconLabel->setEnabled( folder->useCustomIcons() );
601  mNormalIconButton->setEnabled( folder->useCustomIcons() );
602  mUnreadIconLabel->setEnabled( folder->useCustomIcons() );
603  mUnreadIconButton->setEnabled( folder->useCustomIcons() );
604  TQString iconPath = folder->normalIconPath();
605  if ( !iconPath.isEmpty() )
606  mNormalIconButton->setIcon( iconPath );
607  iconPath = folder->unreadIconPath();
608  if ( !iconPath.isEmpty() )
609  mUnreadIconButton->setIcon( iconPath );
610  }
611 
612  // folder identity
613  mIdentityComboBox->setCurrentIdentity( folder->identity() );
614  // ignore new mail
615  mNotifyOnNewMailCheckBox->setChecked( !folder->ignoreNewMail() );
616 
617  const bool keepInFolder = !folder->isReadOnly() && folder->putRepliesInSameFolder();
618  mKeepRepliesInSameFolderCheckBox->setChecked( keepInFolder );
619  mKeepRepliesInSameFolderCheckBox->setDisabled( folder->isReadOnly() );
620 
621  if (folder->folderType() == KMFolderTypeImap)
622  {
623  KMFolderImap* imapFolder = static_cast<KMFolderImap*>(folder->storage());
624  bool checked = imapFolder->includeInMailCheck();
625  mNewMailCheckBox->setChecked(checked);
626  }
627 
628  if ( mIncidencesForComboBox ) {
629  KMFolderCachedImap* dimap = static_cast<KMFolderCachedImap *>( folder->storage() );
630  mIncidencesForComboBox->setCurrentItem( dimap->incidencesFor() );
631  mIncidencesForComboBox->setDisabled( mDlg->folder()->isReadOnly() );
632  }
633  if ( mAlarmsBlockedCheckBox ) {
634  KMFolderCachedImap* dimap = static_cast<KMFolderCachedImap *>( folder->storage() );
635  mAlarmsBlockedCheckBox->setChecked( dimap->alarmsBlocked() );
636  }
637  if ( mSharedSeenFlagsCheckBox ) {
638  KMFolderCachedImap *dimap = static_cast<KMFolderCachedImap*>( folder->storage() );
639  ImapAccountBase *account = dynamic_cast<ImapAccountBase*>( dimap->account() );
640  mSharedSeenFlagsCheckBox->setChecked( dimap->sharedSeenFlags() );
641  mSharedSeenFlagsCheckBox->setDisabled( folder->isReadOnly() );
642  if ( account && account->hasCapability( "x-kmail-sharedseen" ) )
643  mSharedSeenFlagsCheckBox->show();
644  else
645  mSharedSeenFlagsCheckBox->hide();
646  }
647 }
648 
649 //-----------------------------------------------------------------------------
650 void FolderDiaGeneralTab::slotFolderNameChanged( const TQString& str )
651 {
652  mDlg->enableButtonOK( !str.isEmpty() );
653 }
654 
655 //-----------------------------------------------------------------------------
656 void FolderDiaGeneralTab::slotFolderContentsSelectionChanged( int )
657 {
658  KMail::FolderContentsType type =
659  static_cast<KMail::FolderContentsType>( mContentsComboBox->currentItem() );
660  if( type != KMail::ContentsTypeMail && GlobalSettings::self()->hideGroupwareFolders() ) {
661  TQString message = i18n("You have configured this folder to contain groupware information "
662  "and the general configuration option to hide groupware folders is "
663  "set. That means that this folder will disappear once the configuration "
664  "dialog is closed. If you want to remove the folder again, you will need "
665  "to temporarily disable hiding of groupware folders to be able to see it.");
666  KMessageBox::information( this, message );
667  }
668  const bool enable = type == KMail::ContentsTypeCalendar ||
669  type == KMail::ContentsTypeTask;
670  if ( mIncidencesForComboBox )
671  mIncidencesForComboBox->setEnabled( enable );
672  if ( mAlarmsBlockedCheckBox )
673  mAlarmsBlockedCheckBox->setEnabled( enable );
674 }
675 
676 //-----------------------------------------------------------------------------
678 {
679  KMFolder* folder = mDlg->folder();
680  folder->setIdentity( mIdentityComboBox->currentIdentity() );
681  // set whoField
682  if (mShowSenderReceiverComboBox->currentItem() == 1)
683  folder->setUserWhoField("From");
684  else if (mShowSenderReceiverComboBox->currentItem() == 2)
685  folder->setUserWhoField("To");
686  else
687  folder->setUserWhoField("");
688 
689  folder->setIgnoreNewMail( !mNotifyOnNewMailCheckBox->isChecked() );
690  folder->setPutRepliesInSameFolder( mKeepRepliesInSameFolderCheckBox->isChecked() );
691 
692  TQString fldName, oldFldName;
693  KMFolderCachedImap* dimap = 0;
694  if ( folder->folderType() == KMFolderTypeCachedImap )
695  dimap = static_cast<KMFolderCachedImap *>( mDlg->folder()->storage() );
696 
697  if ( !mIsLocalSystemFolder || mIsResourceFolder )
698  {
699  oldFldName = mDlg->folder()->name();
700  if (!mNameEdit->text().isEmpty())
701  fldName = mNameEdit->text();
702  else
703  fldName = oldFldName;
704 
705  if ( mDlg->parentFolder() &&
706  mDlg->parentFolder()->folderType() != KMFolderTypeImap &&
707  mDlg->parentFolder()->folderType() != KMFolderTypeCachedImap )
708  fldName.remove('/');
709  fldName.remove(TQRegExp("^\\.*"));
710  if (fldName.isEmpty()) fldName = i18n("unnamed");
711 
712 
713  // Update the tree iff new icon paths are different and not empty or if
714  // useCustomIcons changed.
715  if ( folder->useCustomIcons() != mIconsCheckBox->isChecked() ) {
716  folder->setUseCustomIcons( mIconsCheckBox->isChecked() );
717  // Reset icons, useCustomIcons was turned off.
718  if ( !folder->useCustomIcons() ) {
719  folder->setIconPaths( "", "" );
720  }
721  }
722  if ( folder->useCustomIcons() && (
723  (( mNormalIconButton->icon() != folder->normalIconPath() ) &&
724  ( !mNormalIconButton->icon().isEmpty())) ||
725  (( mUnreadIconButton->icon() != folder->unreadIconPath() ) &&
726  ( !mUnreadIconButton->icon().isEmpty())) ) ) {
727  folder->setIconPaths( mNormalIconButton->icon(), mUnreadIconButton->icon() );
728  }
729 
730  // Set type field
731  if ( mContentsComboBox ) {
732  KMail::FolderContentsType type =
733  static_cast<KMail::FolderContentsType>( mContentsComboBox->currentItem() );
734  folder->storage()->setContentsType( type );
735  }
736 
737  if ( dimap ) {
738  if ( mIncidencesForComboBox ) {
739  KMFolderCachedImap::IncidencesFor incfor = KMFolderCachedImap::IncForAdmins;
740  incfor = static_cast<KMFolderCachedImap::IncidencesFor>( mIncidencesForComboBox->currentItem() );
741  if ( dimap->incidencesFor() != incfor ) {
742  dimap->setIncidencesFor( incfor );
743  dimap->writeConfig();
744  }
745  }
746  if ( mAlarmsBlockedCheckBox && mAlarmsBlockedCheckBox->isChecked() != dimap->alarmsBlocked() ) {
747  dimap->setAlarmsBlocked( mAlarmsBlockedCheckBox->isChecked() );
748  dimap->writeConfig();
749  }
750  }
751 
752  if( folder->folderType() == KMFolderTypeImap )
753  {
754  KMFolderImap* imapFolder = static_cast<KMFolderImap*>( folder->storage() );
755  imapFolder->setIncludeInMailCheck(
756  mNewMailCheckBox->isChecked() );
757  }
758  }
759 
760  if ( dimap && mSharedSeenFlagsCheckBox &&
761  mSharedSeenFlagsCheckBox->isChecked() != dimap->sharedSeenFlags() ) {
762  dimap->setSharedSeenFlags( mSharedSeenFlagsCheckBox->isChecked() );
763  dimap->writeConfig();
764  }
765 
766  // make sure everything is on disk, connected slots will call readConfig()
767  // when creating a new folder.
768  folder->storage()->writeConfig();
769 
770  TQString msg;
771  if ( !folder->isValidName( fldName, msg ) ) {
772  KMessageBox::sorry( this, msg );
773  return false;
774  } else {
775  // Renamed an existing folder? We don't check for oldName == newName on
776  // purpose here. The folder might be pending renaming on the next dimap
777  // sync already, in which case the old name would still be around and
778  // something like Calendar -> CalendarFoo -> Calendar inbetween syncs would
779  // fail. Therefor let the folder sort it out itself, whether the rename is
780  // a noop or not.
781  if ( !oldFldName.isEmpty() )
782  {
783  kmkernel->folderMgr()->renameFolder( folder, fldName );
784  } else {
785  kmkernel->folderMgr()->contentsChanged();
786  }
787  }
788 
789  return true;
790 }
791 
792 void FolderDiaGeneralTab::slotChangeIcon( TQString icon ) // can't use a const-ref here, due to TDEIconButton's signal
793 {
794  mUnreadIconButton->setIcon( icon );
795 }
796 
797 //----------------------------------------------------------------------------
798 KMail::FolderDiaTemplatesTab::FolderDiaTemplatesTab( KMFolderDialog* dlg,
799  TQWidget* parent )
800  : FolderDiaTab( parent, 0 ), mDlg( dlg )
801 {
802 
803  mIsLocalSystemFolder = mDlg->folder()->isSystemFolder();
804 
805 
806  TQVBoxLayout *topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
807 
808  mCustom = new TQCheckBox( i18n("&Use custom message templates"), this );
809  topLayout->addWidget( mCustom );
810 
811  mWidget = new TemplatesConfiguration( this , "folder-templates" );
812  mWidget->setEnabled( false );
813  topLayout->addWidget( mWidget );
814 
815  TQHBoxLayout *btns = new TQHBoxLayout( topLayout, KDialog::spacingHint() );
816  mCopyGlobal = new KPushButton( i18n("&Copy global templates"), this );
817  mCopyGlobal->setEnabled( false );
818  btns->addWidget( mCopyGlobal );
819 
820  connect( mCustom, TQT_SIGNAL(toggled(bool)),
821  mWidget, TQT_SLOT(setEnabled(bool)) );
822  connect( mCustom, TQT_SIGNAL(toggled(bool)),
823  mCopyGlobal, TQT_SLOT(setEnabled(bool)) );
824 
825  connect( mCopyGlobal, TQT_SIGNAL(clicked()),
826  this, TQT_SLOT(slotCopyGlobal()) );
827 
828  initializeWithValuesFromFolder( mDlg->folder() );
829 
830  connect( mWidget, TQT_SIGNAL( changed() ),
831  this, TQT_SLOT( slotEmitChanged( void ) ) );
832 }
833 
834 void FolderDiaTemplatesTab::load()
835 {
836 
837 }
838 
839 void FolderDiaTemplatesTab::initializeWithValuesFromFolder( KMFolder* folder ) {
840  if ( !folder )
841  return;
842 
843  mFolder = folder;
844 
845  TQString fid = folder->idString();
846 
847  Templates t( fid );
848 
849  mCustom->setChecked(t.useCustomTemplates());
850 
851  mIdentity = folder->identity();
852 
853  mWidget->loadFromFolder( fid, mIdentity );
854 }
855 
856 //-----------------------------------------------------------------------------
858 {
859  KMFolder* folder = mDlg->folder();
860 
861  TQString fid = folder->idString();
862  Templates t(fid);
863 
864  kdDebug() << "use custom templates for folder " << fid << ": " << mCustom->isChecked() << endl;
865  t.setUseCustomTemplates(mCustom->isChecked());
866  t.writeConfig();
867 
868  mWidget->saveToFolder(fid);
869 
870  return true;
871 }
872 
873 
874 void FolderDiaTemplatesTab::slotEmitChanged() {}
875 
876 void FolderDiaTemplatesTab::slotCopyGlobal() {
877  if ( mIdentity ) {
878  mWidget->loadFromIdentity( mIdentity );
879  }
880  else {
881  mWidget->loadFromGlobal();
882  }
883 }
bool putRepliesInSameFolder() const
Returns true if the replies to mails from this folder should be put in the same folder.
Definition: kmfolder.h:519
bool ignoreNewMail() const
Returns true if the user doesn't want to get notified about new mail in this folder.
Definition: kmfolder.h:526
void changed(bool)
Called when this module was changed [not really used yet].
bool isReadOnly() const
Is the folder read-only?
Definition: kmfolder.cpp:561
Dialog for handling the properties of a mail folder.
Definition: kmfolderdia.h:199
KMail list that manages the contents of one directory that may contain folders and/or other directori...
Definition: kmfolderdir.h:15
bool useCustomIcons() const
Icon related methods.
Definition: kmfolder.h:499
bool isValidName(const TQString &folderName, TQString &message)
Returns true if the name is valid for a child of this folder.
Definition: kmfolder.cpp:899
virtual void writeConfig()
Write the config file.
This is the base class for tabs in the folder dialog.
Definition: kmfolderdia.h:70
virtual void setContentsType(KMail::FolderContentsType type, bool quiet=false)
Set the type of contents held in this folder (mail, calendar, etc.)
"Quota" tab in the folder dialog Internal class, only used by KMFolderDialog
"General" tab in the folder dialog Internal class, only used by KMFolderDialog
Definition: kmfolderdia.h:112
virtual bool save()
Unlike ConfigModuleTab, we return a bool from save.
"Templates" tab in the folder dialog Internal class, only used by KMFolderDialog
Definition: kmfolderdia.h:164
TQString idString() const
Returns a string that can be used to identify this folder.
Definition: kmfolder.cpp:705
virtual bool save()
Unlike ConfigModuleTab, we return a bool from save.
"Access Control" tab in the folder dialog Internal class, only used by KMFolderDialog
KMFolderType folderType() const
Returns the type of this folder.
Definition: kmfolder.cpp:233
folderdiaquotatab.h
Definition: aboutdata.cpp:40
bool isSystemFolder() const
Returns true if the folder is a kmail system folder.
Definition: kmfolder.h:369
The user rights/ACL have been fetched from the server sucessfully.
Definition: acljobs.h:66
Mail folder.
Definition: kmfolder.h:68
virtual bool noContent() const
Returns, if the folder can't contain mails, but only subfolder.