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

calendarsupport

  • sources
  • kde-4.14
  • kdepim
  • calendarsupport
collectiongeneralpage.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
3  Author: Tobias Koenig <tokoe@kdab.com>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #include "collectiongeneralpage.h"
22 #include "pimcommon/util/pimutil.h"
23 #include <Akonadi/Collection>
24 #include <Akonadi/EntityDisplayAttribute>
25 #include <akonadi/calendar/blockalarmsattribute.h>
26 
27 #include <KCalCore/Event>
28 #include <KCalCore/Journal>
29 #include <KCalCore/Todo>
30 
31 #include <KDialog>
32 #include <KIconButton>
33 #include <KLineEdit>
34 #include <KLocalizedString>
35 
36 #include <QCheckBox>
37 #include <QHBoxLayout>
38 #include <QLabel>
39 #include <QVBoxLayout>
40 
41 #include <mailcommon/collectionpage/attributes/collectionannotationsattribute.h>
42 #include <mailcommon/collectionpage/collectiontypeutil.h>
43 #include <mailcommon/collectionpage/incidencesforwidget.h>
44 
45 using namespace Akonadi;
46 using namespace CalendarSupport;
47 
48 CollectionGeneralPage::CollectionGeneralPage( QWidget *parent )
49  : CollectionPropertiesPage( parent ),
50  mIncidencesForComboBox(0)
51 {
52  setObjectName( QLatin1String( "CalendarSupport::CollectionGeneralPage" ) );
53  setPageTitle( i18nc( "@title:tab General settings for a folder.", "General" ) );
54 }
55 
56 void CollectionGeneralPage::init(const Akonadi::Collection &collection)
57 {
58  QVBoxLayout *topLayout = new QVBoxLayout( this );
59  topLayout->setSpacing( KDialog::spacingHint() );
60 
61  QHBoxLayout *hbox = new QHBoxLayout();
62  topLayout->addItem( hbox );
63  hbox->setSpacing( KDialog::spacingHint() );
64 
65  QLabel *label = new QLabel( i18nc( "@label:textbox Name of the folder.", "&Name:" ), this );
66  hbox->addWidget( label );
67 
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." ) );
74  label->setBuddy( mNameEdit );
75  hbox->addWidget( mNameEdit );
76 
77  // should replies to mails in this folder be kept in this same folder?
78  hbox = new QHBoxLayout();
79  topLayout->addItem( hbox );
80  hbox->setSpacing( KDialog::spacingHint() );
81 
82  mBlockAlarmsCheckBox = new QCheckBox( i18nc( "@option:check", "Block reminders locally" ), this );
83  mBlockAlarmsCheckBox->setToolTip(
84  i18nc( "@info:tooltip", "Ignore reminders from this calendar" ) );
85  mBlockAlarmsCheckBox->setWhatsThis(
86  i18nc( "@info:whatsthis",
87  "Check this box if you do not want to receive reminders from items "
88  "associated with this calendar." ) );
89  hbox->addWidget( mBlockAlarmsCheckBox );
90  hbox->addStretch( 1 );
91 
92 #ifndef KDEPIM_MOBILE_UI
93  hbox = new QHBoxLayout();
94  topLayout->addItem( hbox );
95  hbox->setSpacing( KDialog::spacingHint() );
96  mIconCheckBox = new QCheckBox( i18nc( "@option:check", "&Use custom icon:" ), this );
97  mIconCheckBox->setToolTip(
98  i18nc( "@info:tooltip", "Set a custom icon" ) );
99  mIconCheckBox->setWhatsThis(
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 );
104  hbox->addWidget( mIconCheckBox );
105  hbox->addWidget( mIconButton );
106  hbox->addStretch();
107 #endif
108 
109  if ( ( collection.parentCollection() != Akonadi::Collection::root() ) && PimCommon::Util::isImapResource(collection.resource()) ) {
110  const MailCommon::CollectionAnnotationsAttribute *annotationAttribute =
111  collection.attribute<MailCommon::CollectionAnnotationsAttribute>();
112 
113  const QMap<QByteArray, QByteArray> annotations =
114  ( annotationAttribute ?
115  annotationAttribute->annotations() :
116  QMap<QByteArray, QByteArray>() );
117 
118 
119  MailCommon::CollectionTypeUtil collectionUtil;
120  const MailCommon::CollectionTypeUtil::IncidencesFor incidencesFor =
121  collectionUtil.incidencesForFromString( QLatin1String(annotations.value( MailCommon::CollectionTypeUtil::kolabIncidencesFor() )) );
122  hbox = new QHBoxLayout();
123  topLayout->addItem( hbox );
124  mIncidencesForComboBox = new MailCommon::IncidencesForWidget(this);
125  hbox->addWidget(mIncidencesForComboBox);
126 
127  mIncidencesForComboBox->setCurrentIndex( incidencesFor );
128  }
129  topLayout->addStretch( 100 ); // eat all superfluous space
130 }
131 
132 CollectionGeneralPage::~CollectionGeneralPage()
133 {
134 }
135 
136 void CollectionGeneralPage::load( const Akonadi::Collection &collection )
137 {
138  init(collection);
139  mNameEdit->setEnabled( collection.rights() & Collection::CanChangeCollection );
140 
141  const QString displayName = collection.displayName();
142 
143  mNameEdit->setText( displayName );
144  mBlockAlarmsCheckBox->setChecked( collection.hasAttribute<BlockAlarmsAttribute>() );
145 
146  QString iconName;
147  if ( collection.hasAttribute<EntityDisplayAttribute>() ) {
148  iconName = collection.attribute<EntityDisplayAttribute>()->iconName();
149  }
150 
151 #ifndef KDEPIM_MOBILE_UI
152  if ( iconName.isEmpty() ) {
153  const QStringList mimeTypes = collection.contentMimeTypes();
154  if ( collection.contentMimeTypes().count() > 1 ||
155  collection.contentMimeTypes().contains( KCalCore::Event::eventMimeType() ) ) {
156  mIconButton->setIcon( QLatin1String("view-pim-calendar") );
157  } else if ( collection.contentMimeTypes().contains( KCalCore::Todo::todoMimeType() ) ) {
158  mIconButton->setIcon( QLatin1String("view-pim-tasks") );
159  } else if ( collection.contentMimeTypes().contains( KCalCore::Journal::journalMimeType() ) ) {
160  mIconButton->setIcon( QLatin1String("view-pim-journal") );
161  } else if ( mimeTypes.isEmpty() ) {
162  mIconButton->setIcon( QLatin1String("folder-grey") );
163  } else {
164  mIconButton->setIcon( QLatin1String("folder") );
165  }
166  } else {
167  mIconButton->setIcon( iconName );
168  }
169  mIconCheckBox->setChecked( !iconName.isEmpty() );
170 #endif
171 }
172 
173 void CollectionGeneralPage::save( Collection &collection )
174 {
175  if ( collection.hasAttribute<EntityDisplayAttribute>() &&
176  !collection.attribute<EntityDisplayAttribute>()->displayName().isEmpty() ) {
177  collection.attribute<EntityDisplayAttribute>()->setDisplayName( mNameEdit->text() );
178  } else {
179  collection.setName( mNameEdit->text() );
180  }
181 
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);
188  } else {
189  collection.removeAttribute<BlockAlarmsAttribute>();
190  }
191 
192 #ifndef KDEPIM_MOBILE_UI
193  if ( mIconCheckBox->isChecked() ) {
194  collection.attribute<EntityDisplayAttribute>( Collection::AddIfMissing )->
195  setIconName( mIconButton->icon() );
196  } else if ( collection.hasAttribute<EntityDisplayAttribute>() ) {
197  collection.attribute<EntityDisplayAttribute>()->setIconName( QString() );
198  }
199 #endif
200  MailCommon::CollectionAnnotationsAttribute *annotationsAttribute =
201  collection.attribute<MailCommon::CollectionAnnotationsAttribute>( Entity::AddIfMissing );
202 
203  QMap<QByteArray, QByteArray> annotations = annotationsAttribute->annotations();
204 
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();
210  }
211 
212  if ( annotations.isEmpty() ) {
213  collection.removeAttribute<MailCommon::CollectionAnnotationsAttribute>();
214  } else {
215  annotationsAttribute->setAnnotations( annotations );
216  }
217 
218 }
219 
CalendarSupport::CollectionGeneralPage::~CollectionGeneralPage
~CollectionGeneralPage()
Definition: collectiongeneralpage.cpp:132
QWidget
CalendarSupport::CollectionGeneralPage::load
void load(const Akonadi::Collection &collection)
Definition: collectiongeneralpage.cpp:136
QMap
QHBoxLayout
QLabel::setBuddy
void setBuddy(QWidget *buddy)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
CalendarSupport::CollectionGeneralPage::save
void save(Akonadi::Collection &collection)
Definition: collectiongeneralpage.cpp:173
collectiongeneralpage.h
QCheckBox
QList::isEmpty
bool isEmpty() const
QBoxLayout::addItem
virtual void addItem(QLayoutItem *item)
QString::isEmpty
bool isEmpty() const
QVBoxLayout
QString
QStringList
CalendarSupport::displayName
CALENDARSUPPORT_EXPORT QString displayName(Akonadi::ETMCalendar *calendar, const Akonadi::Collection &coll)
Definition: utils.cpp:500
QAbstractButton::setChecked
void setChecked(bool)
QWidget::setWhatsThis
void setWhatsThis(const QString &)
QLatin1String
QBoxLayout::addStretch
void addStretch(int stretch)
QWidget::setToolTip
void setToolTip(const QString &)
QLabel
QBoxLayout::setSpacing
void setSpacing(int spacing)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:31:15 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

calendarsupport

Skip menu "calendarsupport"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal