22 #include "pimcommon/util/pimutil.h"
23 #include <Akonadi/Collection>
24 #include <Akonadi/EntityDisplayAttribute>
25 #include <akonadi/calendar/blockalarmsattribute.h>
27 #include <KCalCore/Event>
28 #include <KCalCore/Journal>
29 #include <KCalCore/Todo>
32 #include <KIconButton>
34 #include <KLocalizedString>
37 #include <QHBoxLayout>
39 #include <QVBoxLayout>
41 #include <mailcommon/collectionpage/attributes/collectionannotationsattribute.h>
42 #include <mailcommon/collectionpage/collectiontypeutil.h>
43 #include <mailcommon/collectionpage/incidencesforwidget.h>
45 using namespace Akonadi;
46 using namespace CalendarSupport;
48 CollectionGeneralPage::CollectionGeneralPage(
QWidget *parent )
49 : CollectionPropertiesPage( parent ),
50 mIncidencesForComboBox(0)
52 setObjectName(
QLatin1String(
"CalendarSupport::CollectionGeneralPage" ) );
53 setPageTitle( i18nc(
"@title:tab General settings for a folder.",
"General" ) );
56 void CollectionGeneralPage::init(
const Akonadi::Collection &collection)
59 topLayout->
setSpacing( KDialog::spacingHint() );
65 QLabel *label =
new QLabel( i18nc(
"@label:textbox Name of the folder.",
"&Name:" ),
this );
68 mNameEdit =
new KLineEdit(
this );
69 mNameEdit->setToolTip(
70 i18nc(
"@info:tooltip",
"Set the folder name" ) );
71 mNameEdit->setWhatsThis(
72 i18nc(
"@info:whatsthis",
73 "Enter a name here to set the name of this folder." ) );
82 mBlockAlarmsCheckBox =
new QCheckBox( i18nc(
"@option:check",
"Block reminders locally" ),
this );
84 i18nc(
"@info:tooltip",
"Ignore reminders from this calendar" ) );
86 i18nc(
"@info:whatsthis",
87 "Check this box if you do not want to receive reminders from items "
88 "associated with this calendar." ) );
92 #ifndef KDEPIM_MOBILE_UI
96 mIconCheckBox =
new QCheckBox( i18nc(
"@option:check",
"&Use custom icon:" ),
this );
98 i18nc(
"@info:tooltip",
"Set a custom icon" ) );
100 i18nc(
"@info:whatsthis",
101 "Check this box if you want to set a custom icon for this folder." ) );
102 mIconButton =
new KIconButton(
this );
103 mIconButton->setIconSize( 16 );
109 if ( ( collection.parentCollection() != Akonadi::Collection::root() ) && PimCommon::Util::isImapResource(collection.resource()) ) {
110 const MailCommon::CollectionAnnotationsAttribute *annotationAttribute =
111 collection.attribute<MailCommon::CollectionAnnotationsAttribute>();
114 ( annotationAttribute ?
115 annotationAttribute->annotations() :
119 MailCommon::CollectionTypeUtil collectionUtil;
120 const MailCommon::CollectionTypeUtil::IncidencesFor incidencesFor =
121 collectionUtil.incidencesForFromString(
QLatin1String(annotations.value( MailCommon::CollectionTypeUtil::kolabIncidencesFor() )) );
124 mIncidencesForComboBox =
new MailCommon::IncidencesForWidget(
this);
127 mIncidencesForComboBox->setCurrentIndex( incidencesFor );
139 mNameEdit->setEnabled( collection.rights() & Collection::CanChangeCollection );
143 mNameEdit->setText( displayName );
144 mBlockAlarmsCheckBox->
setChecked( collection.hasAttribute<BlockAlarmsAttribute>() );
147 if ( collection.hasAttribute<EntityDisplayAttribute>() ) {
148 iconName = collection.attribute<EntityDisplayAttribute>()->iconName();
151 #ifndef KDEPIM_MOBILE_UI
153 const QStringList mimeTypes = collection.contentMimeTypes();
154 if ( collection.contentMimeTypes().count() > 1 ||
155 collection.contentMimeTypes().contains( KCalCore::Event::eventMimeType() ) ) {
157 }
else if ( collection.contentMimeTypes().contains( KCalCore::Todo::todoMimeType() ) ) {
159 }
else if ( collection.contentMimeTypes().contains( KCalCore::Journal::journalMimeType() ) ) {
161 }
else if ( mimeTypes.
isEmpty() ) {
167 mIconButton->setIcon( iconName );
175 if ( collection.hasAttribute<EntityDisplayAttribute>() &&
176 !collection.attribute<EntityDisplayAttribute>()->displayName().isEmpty() ) {
177 collection.attribute<EntityDisplayAttribute>()->setDisplayName( mNameEdit->text() );
179 collection.setName( mNameEdit->text() );
182 if ( mBlockAlarmsCheckBox->
isChecked() ) {
183 BlockAlarmsAttribute *attr = collection.attribute<BlockAlarmsAttribute>( Collection::AddIfMissing );
184 attr->blockAlarmType(KCalCore::Alarm::Audio,
true);
185 attr->blockAlarmType(KCalCore::Alarm::Display,
true);
186 attr->blockAlarmType(KCalCore::Alarm::Email,
true);
187 attr->blockAlarmType(KCalCore::Alarm::Procedure,
true);
189 collection.removeAttribute<BlockAlarmsAttribute>();
192 #ifndef KDEPIM_MOBILE_UI
194 collection.attribute<EntityDisplayAttribute>( Collection::AddIfMissing )->
195 setIconName( mIconButton->icon() );
196 }
else if ( collection.hasAttribute<EntityDisplayAttribute>() ) {
197 collection.attribute<EntityDisplayAttribute>()->setIconName(
QString() );
200 MailCommon::CollectionAnnotationsAttribute *annotationsAttribute =
201 collection.attribute<MailCommon::CollectionAnnotationsAttribute>( Entity::AddIfMissing );
205 MailCommon::CollectionTypeUtil collectionUtil;
206 if ( mIncidencesForComboBox && mIncidencesForComboBox->isEnabled() ) {
207 annotations[ MailCommon::CollectionTypeUtil::kolabIncidencesFor() ] =
208 collectionUtil.incidencesForToString(
209 static_cast<MailCommon::CollectionTypeUtil::IncidencesFor>( mIncidencesForComboBox->currentIndex() ) ).toLatin1();
212 if ( annotations.isEmpty() ) {
213 collection.removeAttribute<MailCommon::CollectionAnnotationsAttribute>();
215 annotationsAttribute->setAnnotations( annotations );
void load(const Akonadi::Collection &collection)
void setBuddy(QWidget *buddy)
void save(Akonadi::Collection &collection)
virtual void addItem(QLayoutItem *item)
CALENDARSUPPORT_EXPORT QString displayName(Akonadi::ETMCalendar *calendar, const Akonadi::Collection &coll)
void addStretch(int stretch)
void setSpacing(int spacing)