26 #include "pimcommon/util/pimutil.h"
27 #include <Akonadi/AgentManager>
28 #include <Akonadi/AttributeFactory>
29 #include <Akonadi/Collection>
30 #include <Akonadi/CollectionModifyJob>
31 #include <Akonadi/EntityDisplayAttribute>
33 #include <KPIMIdentities/IdentityCombo>
35 #include <KColorScheme>
40 #include <KMessageBox>
43 #include <QHBoxLayout>
45 #include <QVBoxLayout>
48 #define KOLAB_FOLDERTYPE "/vendor/kolab/folder-type"
49 #define KOLAB_INCIDENCESFOR "/vendor/kolab/incidences-for"
50 #define KOLAB_SHAREDSEEN "/vendor/cmu/cyrus-imapd/sharedseen"
52 using namespace Akonadi;
53 using namespace MailCommon;
55 CollectionGeneralPage::CollectionGeneralPage(
QWidget *parent )
56 : CollectionPropertiesPage( parent ), mNameEdit( 0 ), mFolderCollection( 0 )
58 setObjectName( QLatin1String(
"MailCommon::CollectionGeneralPage" ) );
59 setPageTitle( i18nc(
"@title:tab General settings for a folder.",
"General" ) );
68 QFrame *line =
new QFrame( parent );
69 line->setGeometry( QRect( 80, 150, 250, 20 ) );
70 line->setFrameShape( QFrame::HLine );
71 line->setFrameShadow( QFrame::Sunken );
72 line->setFrameShape( QFrame::HLine );
73 layout->addWidget( line );
80 return QLatin1String(
"nobody");
82 return QLatin1String(
"admins");
84 return QLatin1String(
"readers");
92 if (
string == QLatin1String(
"nobody") ) {
95 else if (
string == QLatin1String(
"admins") ) {
98 else if (
string == QLatin1String(
"readers") ) {
109 return ( i18nc(
"type of folder content",
"Mail" ) );
111 return ( i18nc(
"type of folder content",
"Calendar" ) );
113 return ( i18nc(
"type of folder content",
"Contacts" ) );
115 return ( i18nc(
"type of folder content",
"Notes" ) );
117 return ( i18nc(
"type of folder content",
"Tasks" ) );
119 return ( i18nc(
"type of folder content",
"Journal" ) );
121 return ( i18nc(
"type of folder content",
"Configuration" ) );
123 return ( i18nc(
"type of folder content",
"Freebusy" ) );
125 return ( i18nc(
"type of folder content",
"Files" ) );
127 return ( i18nc(
"type of folder content",
"Unknown" ) );
133 if ( type == i18nc(
"type of folder content",
"Mail" ) ) {
136 if ( type == i18nc(
"type of folder content",
"Calendar" ) ) {
139 if ( type == i18nc(
"type of folder content",
"Contacts" ) ) {
142 if ( type == i18nc(
"type of folder content",
"Notes" ) ) {
145 if ( type == i18nc(
"type of folder content",
"Tasks" ) ) {
148 if ( type == i18nc(
"type of folder content",
"Journal" ) ) {
151 if ( type == i18nc(
"type of folder content",
"Configuration" ) ) {
154 if ( type == i18nc(
"type of folder content",
"Freebusy" ) ) {
157 if ( type == i18nc(
"type of folder content",
"Files" ) ) {
166 if ( type ==
"task" || type ==
"task.default" ) {
167 return i18nc(
"type of folder content",
"Tasks" );
169 if ( type ==
"event" || type ==
"event.default" ) {
170 return i18nc(
"type of folder content",
"Calendar" );
172 if ( type ==
"contact" || type ==
"contact.default" ) {
173 return i18nc(
"type of folder content",
"Contacts" );
175 if ( type ==
"note" || type ==
"note.default" ) {
176 return i18nc(
"type of folder content",
"Notes" );
178 if ( type ==
"journal" || type ==
"journal.default" ) {
179 return i18nc(
"type of folder content",
"Journal" );
181 if ( type ==
"configuration" || type ==
"configuration.default" ) {
182 return i18nc(
"type of folder content",
"Configuration" );
184 if ( type ==
"freebusy" || type ==
"freebusy.default" ) {
185 return i18nc(
"type of folder content",
"Freebusy" );
187 if ( type ==
"file" || type ==
"file.default" ) {
188 return i18nc(
"type of folder content",
"Files" );
191 return i18nc(
"type of folder content",
"Mail" );
208 return "configuration";
220 if ( name ==
"task" || name ==
"task.default" ) {
223 if ( name ==
"event" || name ==
"event.default" ) {
226 if ( name ==
"contact" || name ==
"contact.default" ) {
229 if ( name ==
"note" || name ==
"note.default" ) {
232 if ( name ==
"journal" || name ==
"journal.default" ) {
235 if ( name ==
"configuration" || name ==
"configuration.default" ) {
238 if ( name ==
"freebusy" || name ==
"freebusy.default" ) {
241 if ( name ==
"file" || name ==
"file.default" ) {
250 mIsLocalSystemFolder =
CommonKernel->isSystemFolderCollection( collection ) ||
253 mIsResourceFolder = ( collection.parentCollection() == Akonadi::Collection::root() );
256 QVBoxLayout *topLayout =
new QVBoxLayout(
this );
257 topLayout->setSpacing( KDialog::spacingHint() );
258 topLayout->setMargin( 0 );
261 if ( ( !mIsLocalSystemFolder || mIsResourceFolder ) &&
262 !mFolderCollection->isReadOnly() ) {
264 QHBoxLayout *hl =
new QHBoxLayout();
265 topLayout->addItem( hl );
266 hl->setSpacing( KDialog::spacingHint() );
267 hl->setMargin( KDialog::marginHint() );
268 label =
new QLabel( i18nc(
"@label:textbox Name of the folder.",
"&Name:" ),
this );
269 hl->addWidget( label );
271 mNameEdit =
new KLineEdit(
this );
272 connect( mNameEdit, SIGNAL(textChanged(QString)), SLOT(slotNameChanged(QString)) );
273 label->setBuddy( mNameEdit );
274 hl->addWidget( mNameEdit );
278 QHBoxLayout *hbl =
new QHBoxLayout();
279 topLayout->addItem( hbl );
280 hbl->setSpacing( KDialog::spacingHint() );
281 hbl->setMargin( KDialog::marginHint() );
282 mNotifyOnNewMailCheckBox =
283 new QCheckBox( i18n(
"Act on new/unread mail in this folder" ),
this );
284 mNotifyOnNewMailCheckBox->setWhatsThis(
285 i18n(
"<qt><p>If this option is enabled then you will be notified about "
286 "new/unread mail in this folder. Moreover, going to the "
287 "next/previous folder with unread messages will stop at this "
289 "<p>Uncheck this option if you do not want to be notified about "
290 "new/unread mail in this folder and if you want this folder to "
291 "be skipped when going to the next/previous folder with unread "
292 "messages. This is useful for ignoring any new/unread mail in "
293 "your trash and spam folder.</p></qt>" ) );
294 hbl->addWidget( mNotifyOnNewMailCheckBox );
296 hbl =
new QHBoxLayout();
297 topLayout->addItem( hbl );
298 hbl->setSpacing( KDialog::spacingHint() );
299 hbl->setMargin( KDialog::marginHint() );
300 mKeepRepliesInSameFolderCheckBox =
301 new QCheckBox( i18n(
"Keep replies in this folder" ),
this );
302 mKeepRepliesInSameFolderCheckBox->setWhatsThis(
303 i18n(
"Check this option if you want replies you write "
304 "to mails in this folder to be put in this same folder "
305 "after sending, instead of in the configured sent-mail folder." ) );
306 hbl->addWidget( mKeepRepliesInSameFolderCheckBox );
307 hbl->addStretch( 1 );
309 hbl =
new QHBoxLayout();
310 topLayout->addItem( hbl );
311 hbl->setSpacing( KDialog::spacingHint() );
312 hbl->setMargin( KDialog::marginHint() );
313 mHideInSelectionDialogCheckBox =
314 new QCheckBox( i18n(
"Hide this folder in the folder selection dialog" ),
this );
315 mHideInSelectionDialogCheckBox->setWhatsThis(
316 i18nc(
"@info:whatsthis",
317 "Check this option if you do not want this folder "
318 "to be shown in folder selection dialogs, such as the <interface>"
319 "Jump to Folder</interface> dialog." ) );
320 hbl->addWidget( mHideInSelectionDialogCheckBox );
321 hbl->addStretch( 1 );
325 QGridLayout *gl =
new QGridLayout();
326 gl->setMargin( KDialog::marginHint() );
327 topLayout->addItem( gl );
328 gl->setSpacing( KDialog::spacingHint() );
329 gl->setColumnStretch( 1, 100 );
334 mUseDefaultIdentityCheckBox =
new QCheckBox( i18n(
"Use &default identity" ),
this );
335 gl->addWidget( mUseDefaultIdentityCheckBox );
336 connect( mUseDefaultIdentityCheckBox, SIGNAL(stateChanged(
int)),
337 this, SLOT(slotIdentityCheckboxChanged()) );
339 label =
new QLabel( i18n(
"&Sender identity:" ),
this );
340 gl->addWidget( label, row, 0 );
341 mIdentityComboBox =
new KPIMIdentities::IdentityCombo(
KernelIf->identityManager(), this );
342 label->setBuddy( mIdentityComboBox );
343 gl->addWidget( mIdentityComboBox, row, 1 );
344 mIdentityComboBox->setWhatsThis(
345 i18n(
"Select the sender identity to be used when writing new mail "
346 "or replying to mail in this folder. This means that if you are in "
347 "one of your work folders, you can make KMail use the corresponding "
348 "sender email address, signature and signing or encryption keys "
349 "automatically. Identities can be set up in the main configuration "
350 "dialog. (Settings -> Configure KMail)" ) );
357 const QMap<QByteArray, QByteArray> annotations =
358 ( annotationAttribute ?
360 QMap<QByteArray, QByteArray>() );
362 const bool sharedSeen = ( annotations.value(
KOLAB_SHAREDSEEN ) ==
"true" );
371 if ( collection.resource().contains( IMAP_RESOURCE_IDENTIFIER ) ) {
373 label =
new QLabel( i18n(
"&Folder contents:" ),
this );
374 gl->addWidget( label, row, 0 );
375 mContentsComboBox =
new KComboBox(
this );
376 label->setBuddy( mContentsComboBox );
377 gl->addWidget( mContentsComboBox, row, 1 );
388 mContentsComboBox->setCurrentIndex( contentsType );
390 connect( mContentsComboBox, SIGNAL(activated(
int)),
391 this, SLOT(slotFolderContentsSelectionChanged(
int)) );
393 if ( mFolderCollection->isReadOnly() || mIsResourceFolder ) {
394 mContentsComboBox->setEnabled(
false );
398 mContentsComboBox = 0;
406 QLabel *label =
new QLabel( i18n(
"Generate free/&busy and activate alarms for:" ),
this );
407 gl->addWidget( label, row, 0 );
408 mIncidencesForComboBox =
new KComboBox(
this );
409 label->setBuddy( mIncidencesForComboBox );
410 gl->addWidget( mIncidencesForComboBox, row, 1 );
412 mIncidencesForComboBox->addItem( i18n(
"Nobody" ) );
413 mIncidencesForComboBox->addItem( i18n(
"Admins of This Folder" ) );
414 mIncidencesForComboBox->addItem( i18n(
"All Readers of This Folder" ) );
415 const QString whatsThisForMyOwnFolders =
416 i18n(
"This setting defines which users sharing "
417 "this folder should get \"busy\" periods in their freebusy lists "
418 "and should see the alarms for the events or tasks in this folder. "
419 "The setting applies to Calendar and Task folders only "
420 "(for tasks, this setting is only used for alarms).\n\n"
421 "Example use cases: if the boss shares a folder with his secretary, "
422 "only the boss should be marked as busy for his meetings, so he should "
423 "select \"Admins\", since the secretary has no admin rights on the folder.\n"
424 "On the other hand if a working group shares a Calendar for "
425 "group meetings, all readers of the folders should be marked "
426 "as busy for meetings.\n"
427 "A company-wide folder with optional events in it would use \"Nobody\" "
428 "since it is not known who will go to those events." );
430 mIncidencesForComboBox->setWhatsThis( whatsThisForMyOwnFolders );
431 mIncidencesForComboBox->setCurrentIndex( incidencesFor );
433 mIncidencesForComboBox = 0;
436 if ( collection.resource().contains( IMAP_RESOURCE_IDENTIFIER ) ) {
437 mSharedSeenFlagsCheckBox =
new QCheckBox(
this );
438 mSharedSeenFlagsCheckBox->setText( i18n(
"Share unread state with all users" ) );
439 mSharedSeenFlagsCheckBox->setChecked( sharedSeen );
441 gl->addWidget( mSharedSeenFlagsCheckBox, row, 0, 1, 1 );
442 mSharedSeenFlagsCheckBox->setWhatsThis(
443 i18n(
"If enabled, the unread state of messages in this folder will be "
444 "the same for all users having access to this folder. If disabled "
445 "(the default), every user with access to this folder has their "
446 "own unread state." ) );
448 mSharedSeenFlagsCheckBox = 0;
451 topLayout->addStretch( 100 );
460 const QString
displayName = collection.displayName();
462 if ( !mIsLocalSystemFolder || mIsResourceFolder ) {
463 mNameEdit->setText( displayName );
468 mIdentityComboBox->setCurrentIdentity( mFolderCollection->identity() );
469 mUseDefaultIdentityCheckBox->setChecked( mFolderCollection->useDefaultIdentity() );
474 const bool keepInFolder = ( mFolderCollection->canCreateMessages() &&
475 mFolderCollection->putRepliesInSameFolder() );
477 mKeepRepliesInSameFolderCheckBox->setChecked( keepInFolder );
478 mKeepRepliesInSameFolderCheckBox->setEnabled( mFolderCollection->canCreateMessages() );
479 mHideInSelectionDialogCheckBox->setChecked( mFolderCollection->hideInSelectionDialog() );
481 if ( mContentsComboBox ) {
485 if ( annotationsAttribute ) {
486 const QMap<QByteArray, QByteArray> annotations = annotationsAttribute->
annotations();
488 mContentsComboBox->setCurrentItem(
498 if ( !mIsLocalSystemFolder ) {
499 const QString nameFolder(mNameEdit->text().trimmed());
500 bool canRenameFolder = !(nameFolder.startsWith( QLatin1Char(
'.') ) ||
501 nameFolder.endsWith( QLatin1Char(
'.') ) ||
502 nameFolder.contains( QLatin1Char(
'/' ) ) ||
503 nameFolder.isEmpty());
505 if ( mIsResourceFolder && collection.resource().contains( IMAP_RESOURCE_IDENTIFIER ) ) {
506 collection.setName( nameFolder );
507 Akonadi::AgentInstance instance =
508 Akonadi::AgentManager::self()->instance( collection.resource() );
509 instance.setName( nameFolder );
510 }
else if (canRenameFolder) {
511 if ( collection.hasAttribute<Akonadi::EntityDisplayAttribute>() &&
512 !collection.attribute<Akonadi::EntityDisplayAttribute>()->displayName().isEmpty() ) {
513 collection.attribute<Akonadi::EntityDisplayAttribute>()->setDisplayName(
515 }
else if ( !nameFolder.isEmpty() ) {
516 collection.setName( nameFolder );
522 if (!mNotifyOnNewMailCheckBox->isChecked()) {
532 QMap<QByteArray, QByteArray> annotations = annotationsAttribute->
annotations();
533 if ( mSharedSeenFlagsCheckBox && mSharedSeenFlagsCheckBox->isEnabled() ) {
534 annotations[
KOLAB_SHAREDSEEN ] = mSharedSeenFlagsCheckBox->isChecked() ?
"true" :
"false";
537 if ( mIncidencesForComboBox && mIncidencesForComboBox->isEnabled() ) {
540 static_cast<IncidencesFor>( mIncidencesForComboBox->currentIndex() ) ).toLatin1();
543 if ( mContentsComboBox ) {
548 if ( !kolabName.isEmpty() ) {
552 iconName= QString::fromLatin1(
"view-calendar" );
555 iconName= QString::fromLatin1(
"view-pim-contacts" );
558 iconName = QString::fromLatin1(
"view-pim-notes" );
561 iconName = QString::fromLatin1(
"view-pim-tasks" );
564 iconName = QString::fromLatin1(
"view-pim-journal" );
567 iconName = QString::fromLatin1(
"configure" );
570 iconName = QString::fromLatin1(
"view-calendar-agenda" );
573 iconName = QString::fromLatin1(
"document-open" );
580 Akonadi::EntityDisplayAttribute *attribute =
581 collection.attribute<Akonadi::EntityDisplayAttribute>( Akonadi::Entity::AddIfMissing );
582 attribute->setIconName( iconName );
583 new Akonadi::CollectionModifyJob( collection );
587 if ( annotations.isEmpty() ) {
593 if ( mFolderCollection ) {
594 mFolderCollection->setIdentity( mIdentityComboBox->currentIdentity() );
595 mFolderCollection->setUseDefaultIdentity( mUseDefaultIdentityCheckBox->isChecked() );
597 mFolderCollection->setPutRepliesInSameFolder( mKeepRepliesInSameFolderCheckBox->isChecked() );
598 mFolderCollection->setHideInSelectionDialog( mHideInSelectionDialogCheckBox->isChecked() );
599 mFolderCollection->writeConfig();
603 void CollectionGeneralPage::slotIdentityCheckboxChanged()
605 mIdentityComboBox->setEnabled( !mUseDefaultIdentityCheckBox->isChecked() );
608 void CollectionGeneralPage::slotFolderContentsSelectionChanged(
int )
614 const QString message =
615 i18n(
"You have configured this folder to contain groupware information. "
616 "That means that this folder will disappear once the configuration "
617 "dialog is closed." );
619 KMessageBox::information(
this, message );
625 if ( mIncidencesForComboBox ) {
626 mIncidencesForComboBox->setEnabled( enable );
630 void CollectionGeneralPage::slotNameChanged(
const QString &name )
632 #ifndef QT_NO_STYLE_STYLESHEET
634 if ( name.startsWith( QLatin1Char(
'.') ) ||
635 name.endsWith( QLatin1Char(
'.') ) ||
636 name.contains( QLatin1Char(
'/' ) ) ||
638 if (mColorName.isEmpty()) {
639 const KColorScheme::BackgroundRole bgColorScheme( KColorScheme::NegativeBackground );
640 KStatefulBrush bgBrush( KColorScheme::View, bgColorScheme );
641 mColorName = bgBrush.brush(
this ).color().name();
643 styleSheet = QString::fromLatin1(
"QLineEdit{ background-color:%1 }" ).
646 setStyleSheet(styleSheet);
650 #include "collectiongeneralpage.moc"
MAILCOMMON_EXPORT bool ignoreNewMailInFolder(const Akonadi::Collection &collection)
static CollectionGeneralPage::FolderContentsType contentsTypeFromString(const QString &type)
static bool folderIsInbox(const Akonadi::Collection &, bool withoutPop3InboxSetting=false)
#define KOLAB_INCIDENCESFOR
static QString incidencesForToString(CollectionGeneralPage::IncidencesFor type)
static void addLine(QWidget *parent, QVBoxLayout *layout)
void load(const Akonadi::Collection &collection)
static QString folderContentDescription(CollectionGeneralPage::FolderContentsType type)
static CollectionGeneralPage::IncidencesFor incidencesForFromString(const QString &string)
void setAnnotations(const QMap< QByteArray, QByteArray > &annotations)
static QSharedPointer< FolderCollection > forCollection(const Akonadi::Collection &coll, bool writeConfig=true)
void save(Akonadi::Collection &collection)
static CollectionGeneralPage::FolderContentsType typeFromKolabName(const QByteArray &name)
static QString typeNameFromKolabType(const QByteArray &type)
void setIgnoreNewMail(bool b)
void init(const Akonadi::Collection &)
QMap< QByteArray, QByteArray > annotations() const
static QByteArray kolabNameFromType(CollectionGeneralPage::FolderContentsType type)