• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.11.3 API Reference
  • KDE Home
  • Contact Us
 

KAlarm Library

  • kalarmcal
collectionattribute.cpp
1 /*
2  * collectionattribute.cpp - Akonadi attribute holding Collection characteristics
3  * This file is part of kalarmcal library, which provides access to KAlarm
4  * calendar data.
5  * Copyright © 2010-2011 by David Jarvie <djarvie@kde.org>
6  *
7  * This library is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Library General Public License as published
9  * by the Free Software Foundation; either version 2 of the License, or (at
10  * your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15  * License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to the
19  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301, USA.
21  */
22 
23 #include "collectionattribute.h"
24 
25 #include <kdebug.h>
26 
27 namespace KAlarmCal
28 {
29 
30 class CollectionAttribute::Private
31 {
32  public:
33  Private() : mEnabled(CalEvent::EMPTY),
34  mStandard(CalEvent::EMPTY),
35  mKeepFormat(false) {}
36 
37  QColor mBackgroundColour; // background color for collection and its alarms
38  CalEvent::Types mEnabled; // which alarm types the collection is enabled for
39  CalEvent::Types mStandard; // whether the collection is a standard collection
40  bool mKeepFormat; // whether user has chosen to keep old calendar storage format
41 };
42 
43 
44 CollectionAttribute::CollectionAttribute()
45  : d(new Private)
46 {
47 }
48 
49 CollectionAttribute::CollectionAttribute(const CollectionAttribute& rhs)
50  : Akonadi::Attribute(rhs),
51  d(new Private(*rhs.d))
52 {
53 }
54 
55 CollectionAttribute::~CollectionAttribute()
56 {
57  delete d;
58 }
59 
60 CollectionAttribute& CollectionAttribute::operator=(const CollectionAttribute& other)
61 {
62  if (&other != this)
63  {
64  Attribute::operator=(other);
65  *d = *other.d;
66  }
67  return *this;
68 }
69 
70 CollectionAttribute* CollectionAttribute::clone() const
71 {
72  return new CollectionAttribute(*this);
73 }
74 
75 bool CollectionAttribute::isEnabled(CalEvent::Type type) const
76 {
77  return d->mEnabled & type;
78 }
79 
80 CalEvent::Types CollectionAttribute::enabled() const
81 {
82  return d->mEnabled;
83 }
84 
85 void CollectionAttribute::setEnabled(CalEvent::Type type, bool enabled)
86 {
87  switch (type)
88  {
89  case CalEvent::ACTIVE:
90  case CalEvent::ARCHIVED:
91  case CalEvent::TEMPLATE:
92  break;
93  default:
94  return;
95  }
96  if (enabled)
97  d->mEnabled |= type;
98  else
99  {
100  d->mEnabled &= ~type;
101  d->mStandard &= ~type;
102  }
103 }
104 
105 void CollectionAttribute::setEnabled(CalEvent::Types types)
106 {
107  d->mEnabled = types & (CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE);
108  d->mStandard &= d->mEnabled;
109 }
110 
111 bool CollectionAttribute::isStandard(CalEvent::Type type) const
112 {
113  switch (type)
114  {
115  case CalEvent::ACTIVE:
116  case CalEvent::ARCHIVED:
117  case CalEvent::TEMPLATE:
118  return d->mStandard & type;
119  default:
120  return false;
121  }
122 }
123 
124 CalEvent::Types CollectionAttribute::standard() const
125 {
126  return d->mStandard;
127 }
128 
129 void CollectionAttribute::setStandard(CalEvent::Type type, bool standard)
130 {
131  switch (type)
132  {
133  case CalEvent::ACTIVE:
134  case CalEvent::ARCHIVED:
135  case CalEvent::TEMPLATE:
136  if (standard)
137  d->mStandard = static_cast<CalEvent::Types>(d->mStandard | type);
138  else
139  d->mStandard = static_cast<CalEvent::Types>(d->mStandard & ~type);
140  break;
141  default:
142  break;
143  }
144 }
145 
146 void CollectionAttribute::setStandard(CalEvent::Types types)
147 {
148  d->mStandard = types & (CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE);
149 }
150 
151 QColor CollectionAttribute::backgroundColor() const
152 {
153  return d->mBackgroundColour;
154 }
155 
156 void CollectionAttribute::setBackgroundColor(const QColor& c)
157 {
158  d->mBackgroundColour = c;
159 }
160 
161 bool CollectionAttribute::keepFormat() const
162 {
163  return d->mKeepFormat;
164 }
165 
166 void CollectionAttribute::setKeepFormat(bool keep)
167 {
168  d->mKeepFormat = keep;
169 }
170 
171 QByteArray CollectionAttribute::type() const
172 {
173  return name();
174 }
175 
176 QByteArray CollectionAttribute::name()
177 {
178  return "KAlarmCollection";
179 }
180 
181 QByteArray CollectionAttribute::serialized() const
182 {
183  QByteArray v = QByteArray::number(d->mEnabled) + ' '
184  + QByteArray::number(d->mStandard) + ' '
185  + QByteArray(d->mKeepFormat ? "1" : "0") + ' '
186  + QByteArray(d->mBackgroundColour.isValid() ? "1" : "0");
187  if (d->mBackgroundColour.isValid())
188  v += ' '
189  + QByteArray::number(d->mBackgroundColour.red()) + ' '
190  + QByteArray::number(d->mBackgroundColour.green()) + ' '
191  + QByteArray::number(d->mBackgroundColour.blue()) + ' '
192  + QByteArray::number(d->mBackgroundColour.alpha());
193  kDebug() << v;
194  return v;
195 }
196 
197 void CollectionAttribute::deserialize(const QByteArray& data)
198 {
199  kDebug() << data;
200 
201  // Set default values
202  d->mEnabled = CalEvent::EMPTY;
203  d->mStandard = CalEvent::EMPTY;
204  d->mBackgroundColour = QColor();
205  d->mKeepFormat = false;
206 
207  bool ok;
208  int c[4];
209  const QList<QByteArray> items = data.simplified().split(' ');
210  int count = items.count();
211  int index = 0;
212  if (count > index)
213  {
214  // 0: type(s) of alarms for which the collection is enabled
215  c[0] = items[index++].toInt(&ok);
216  if (!ok || (c[0] & ~(CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE)))
217  {
218  kError() << "Invalid alarm types:" << c[0];
219  return;
220  }
221  d->mEnabled = static_cast<CalEvent::Types>(c[0]);
222  }
223  if (count > index)
224  {
225  // 1: type(s) of alarms for which the collection is the standard collection
226  c[0] = items[index++].toInt(&ok);
227  if (!ok || (c[0] & ~(CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE)))
228  {
229  kError() << "Invalid alarm types:" << c[0];
230  return;
231  }
232  if (d->mEnabled)
233  d->mStandard = static_cast<CalEvent::Types>(c[0]);
234  }
235  if (count > index)
236  {
237  // 2: keep old calendar storage format
238  c[0] = items[index++].toInt(&ok);
239  if (!ok)
240  return;
241  d->mKeepFormat = c[0];
242  }
243  if (count > index)
244  {
245  // 3: background color valid flag
246  c[0] = items[index++].toInt(&ok);
247  if (!ok)
248  return;
249  if (c[0])
250  {
251  if (count < index + 4)
252  {
253  kError() << "Invalid number of background color elements";
254  return;
255  }
256  // 4-7: background color elements
257  for (int i = 0; i < 4; ++i)
258  {
259  c[i] = items[index++].toInt(&ok);
260  if (!ok)
261  return;
262  }
263  d->mBackgroundColour.setRgb(c[0], c[1], c[2], c[3]);
264  }
265  }
266 }
267 
268 } // namespace KAlarmCal
269 
270 // vim: et sw=4:
KAlarmCal::CollectionAttribute::setStandard
void setStandard(CalEvent::Type, bool standard)
Set or clear the collection as the standard collection for a specified alarm type (active...
Definition: collectionattribute.cpp:129
KAlarmCal::CollectionAttribute::enabled
CalEvent::Types enabled() const
Return which alarm types (active, archived or template) the collection is enabled for...
Definition: collectionattribute.cpp:80
KAlarmCal::CalEvent::TEMPLATE
the event is an alarm template
Definition: kacalendar.h:159
KAlarmCal::CollectionAttribute::isStandard
bool isStandard(CalEvent::Type type) const
Return whether the collection is the standard collection for a specified alarm type (active...
Definition: collectionattribute.cpp:111
KAlarmCal::CollectionAttribute
An Attribute for a KAlarm Collection containing various status information.
Definition: collectionattribute.h:51
KAlarmCal::CollectionAttribute::operator=
CollectionAttribute & operator=(const CollectionAttribute &other)
Assignment operator.
Definition: collectionattribute.cpp:60
KAlarmCal::CollectionAttribute::keepFormat
bool keepFormat() const
Return whether the user has chosen to keep the old calendar storage format, i.e.
Definition: collectionattribute.cpp:161
KAlarmCal::CollectionAttribute::isEnabled
bool isEnabled(CalEvent::Type type) const
Return whether the collection is enabled for a specified alarm type (active, archived, template or displaying).
Definition: collectionattribute.cpp:75
KAlarmCal::CalEvent::Type
Type
The category of an event, indicated by the middle part of its UID.
Definition: kacalendar.h:154
KAlarmCal::CollectionAttribute::standard
CalEvent::Types standard() const
Return which alarm types (active, archived or template) the collection is standard for...
Definition: collectionattribute.cpp:124
KAlarmCal::CollectionAttribute::backgroundColor
QColor backgroundColor() const
Return the background color to display this collection and its alarms, or invalid color if none is se...
Definition: collectionattribute.cpp:151
KAlarmCal::CollectionAttribute::name
static QByteArray name()
Return the attribute name.
Definition: collectionattribute.cpp:176
KAlarmCal::CalEvent::ACTIVE
the event is currently active
Definition: kacalendar.h:157
KAlarmCal::CollectionAttribute::deserialize
virtual void deserialize(const QByteArray &data)
Reimplemented from Attribute.
Definition: collectionattribute.cpp:197
KAlarmCal::CollectionAttribute::clone
virtual CollectionAttribute * clone() const
Reimplemented from Attribute.
Definition: collectionattribute.cpp:70
KAlarmCal::CollectionAttribute::setBackgroundColor
void setBackgroundColor(const QColor &c)
Set the background color for this collection and its alarms.
Definition: collectionattribute.cpp:156
KAlarmCal::CollectionAttribute::setKeepFormat
void setKeepFormat(bool keep)
Set whether to keep the old calendar storage format unchanged.
Definition: collectionattribute.cpp:166
KAlarmCal::CalEvent::EMPTY
the event has no alarms
Definition: kacalendar.h:156
KAlarmCal::CollectionAttribute::type
virtual QByteArray type() const
Reimplemented from Attribute.
Definition: collectionattribute.cpp:171
KAlarmCal::CalEvent::ARCHIVED
the event is archived
Definition: kacalendar.h:158
KAlarmCal::CollectionAttribute::setEnabled
void setEnabled(CalEvent::Type type, bool enabled)
Set the enabled/disabled state of the collection and its alarms, for a specified alarm type (active...
Definition: collectionattribute.cpp:85
KAlarmCal::CollectionAttribute::serialized
virtual QByteArray serialized() const
Reimplemented from Attribute.
Definition: collectionattribute.cpp:181
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:04:30 by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KAlarm Library

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

kdepimlibs-4.11.3 API Reference

Skip menu "kdepimlibs-4.11.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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