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

KAlarm Library

  • sources
  • kde-4.12
  • kdepimlibs
  • 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 CollectionAttribute::CollectionAttribute()
44  : d(new Private)
45 {
46 }
47 
48 CollectionAttribute::CollectionAttribute(const CollectionAttribute& rhs)
49  : Akonadi::Attribute(rhs),
50  d(new Private(*rhs.d))
51 {
52 }
53 
54 CollectionAttribute::~CollectionAttribute()
55 {
56  delete d;
57 }
58 
59 CollectionAttribute& CollectionAttribute::operator=(const CollectionAttribute& other)
60 {
61  if (&other != this)
62  {
63  Attribute::operator=(other);
64  *d = *other.d;
65  }
66  return *this;
67 }
68 
69 CollectionAttribute* CollectionAttribute::clone() const
70 {
71  return new CollectionAttribute(*this);
72 }
73 
74 bool CollectionAttribute::isEnabled(CalEvent::Type type) const
75 {
76  return d->mEnabled & type;
77 }
78 
79 CalEvent::Types CollectionAttribute::enabled() const
80 {
81  return d->mEnabled;
82 }
83 
84 void CollectionAttribute::setEnabled(CalEvent::Type type, bool enabled)
85 {
86  switch (type)
87  {
88  case CalEvent::ACTIVE:
89  case CalEvent::ARCHIVED:
90  case CalEvent::TEMPLATE:
91  break;
92  default:
93  return;
94  }
95  if (enabled)
96  d->mEnabled |= type;
97  else
98  {
99  d->mEnabled &= ~type;
100  d->mStandard &= ~type;
101  }
102 }
103 
104 void CollectionAttribute::setEnabled(CalEvent::Types types)
105 {
106  d->mEnabled = types & (CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE);
107  d->mStandard &= d->mEnabled;
108 }
109 
110 bool CollectionAttribute::isStandard(CalEvent::Type type) const
111 {
112  switch (type)
113  {
114  case CalEvent::ACTIVE:
115  case CalEvent::ARCHIVED:
116  case CalEvent::TEMPLATE:
117  return d->mStandard & type;
118  default:
119  return false;
120  }
121 }
122 
123 CalEvent::Types CollectionAttribute::standard() const
124 {
125  return d->mStandard;
126 }
127 
128 void CollectionAttribute::setStandard(CalEvent::Type type, bool standard)
129 {
130  switch (type)
131  {
132  case CalEvent::ACTIVE:
133  case CalEvent::ARCHIVED:
134  case CalEvent::TEMPLATE:
135  if (standard)
136  d->mStandard = static_cast<CalEvent::Types>(d->mStandard | type);
137  else
138  d->mStandard = static_cast<CalEvent::Types>(d->mStandard & ~type);
139  break;
140  default:
141  break;
142  }
143 }
144 
145 void CollectionAttribute::setStandard(CalEvent::Types types)
146 {
147  d->mStandard = types & (CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE);
148 }
149 
150 QColor CollectionAttribute::backgroundColor() const
151 {
152  return d->mBackgroundColour;
153 }
154 
155 void CollectionAttribute::setBackgroundColor(const QColor& c)
156 {
157  d->mBackgroundColour = c;
158 }
159 
160 bool CollectionAttribute::keepFormat() const
161 {
162  return d->mKeepFormat;
163 }
164 
165 void CollectionAttribute::setKeepFormat(bool keep)
166 {
167  d->mKeepFormat = keep;
168 }
169 
170 QByteArray CollectionAttribute::type() const
171 {
172  return name();
173 }
174 
175 QByteArray CollectionAttribute::name()
176 {
177  return "KAlarmCollection";
178 }
179 
180 QByteArray CollectionAttribute::serialized() const
181 {
182  QByteArray v = QByteArray::number(d->mEnabled) + ' '
183  + QByteArray::number(d->mStandard) + ' '
184  + QByteArray(d->mKeepFormat ? "1" : "0") + ' '
185  + QByteArray(d->mBackgroundColour.isValid() ? "1" : "0");
186  if (d->mBackgroundColour.isValid())
187  v += ' '
188  + QByteArray::number(d->mBackgroundColour.red()) + ' '
189  + QByteArray::number(d->mBackgroundColour.green()) + ' '
190  + QByteArray::number(d->mBackgroundColour.blue()) + ' '
191  + QByteArray::number(d->mBackgroundColour.alpha());
192  kDebug() << v;
193  return v;
194 }
195 
196 void CollectionAttribute::deserialize(const QByteArray& data)
197 {
198  kDebug() << data;
199 
200  // Set default values
201  d->mEnabled = CalEvent::EMPTY;
202  d->mStandard = CalEvent::EMPTY;
203  d->mBackgroundColour = QColor();
204  d->mKeepFormat = false;
205 
206  bool ok;
207  int c[4];
208  const QList<QByteArray> items = data.simplified().split(' ');
209  int count = items.count();
210  int index = 0;
211  if (count > index)
212  {
213  // 0: type(s) of alarms for which the collection is enabled
214  c[0] = items[index++].toInt(&ok);
215  if (!ok || (c[0] & ~(CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE)))
216  {
217  kError() << "Invalid alarm types:" << c[0];
218  return;
219  }
220  d->mEnabled = static_cast<CalEvent::Types>(c[0]);
221  }
222  if (count > index)
223  {
224  // 1: type(s) of alarms for which the collection is the standard collection
225  c[0] = items[index++].toInt(&ok);
226  if (!ok || (c[0] & ~(CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE)))
227  {
228  kError() << "Invalid alarm types:" << c[0];
229  return;
230  }
231  if (d->mEnabled)
232  d->mStandard = static_cast<CalEvent::Types>(c[0]);
233  }
234  if (count > index)
235  {
236  // 2: keep old calendar storage format
237  c[0] = items[index++].toInt(&ok);
238  if (!ok)
239  return;
240  d->mKeepFormat = c[0];
241  }
242  if (count > index)
243  {
244  // 3: background color valid flag
245  c[0] = items[index++].toInt(&ok);
246  if (!ok)
247  return;
248  if (c[0])
249  {
250  if (count < index + 4)
251  {
252  kError() << "Invalid number of background color elements";
253  return;
254  }
255  // 4-7: background color elements
256  for (int i = 0; i < 4; ++i)
257  {
258  c[i] = items[index++].toInt(&ok);
259  if (!ok)
260  return;
261  }
262  d->mBackgroundColour.setRgb(c[0], c[1], c[2], c[3]);
263  }
264  }
265 }
266 
267 } // namespace KAlarmCal
268 
269 // 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:128
KAlarmCal::CollectionAttribute::enabled
CalEvent::Types enabled() const
Return which alarm types (active, archived or template) the collection is enabled for...
Definition: collectionattribute.cpp:79
KAlarmCal::CalEvent::TEMPLATE
the event is an alarm template
Definition: kacalendar.h:160
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:110
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:59
KAlarmCal::CollectionAttribute::keepFormat
bool keepFormat() const
Return whether the user has chosen to keep the old calendar storage format, i.e.
Definition: collectionattribute.cpp:160
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:74
KAlarmCal::CalEvent::Type
Type
The category of an event, indicated by the middle part of its UID.
Definition: kacalendar.h:155
KAlarmCal::CollectionAttribute::standard
CalEvent::Types standard() const
Return which alarm types (active, archived or template) the collection is standard for...
Definition: collectionattribute.cpp:123
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:150
KAlarmCal::CollectionAttribute::name
static QByteArray name()
Return the attribute name.
Definition: collectionattribute.cpp:175
KAlarmCal::CalEvent::ACTIVE
the event is currently active
Definition: kacalendar.h:158
KAlarmCal::CollectionAttribute::deserialize
virtual void deserialize(const QByteArray &data)
Reimplemented from Attribute.
Definition: collectionattribute.cpp:196
KAlarmCal::CollectionAttribute::clone
virtual CollectionAttribute * clone() const
Reimplemented from Attribute.
Definition: collectionattribute.cpp:69
KAlarmCal::CollectionAttribute::setBackgroundColor
void setBackgroundColor(const QColor &c)
Set the background color for this collection and its alarms.
Definition: collectionattribute.cpp:155
KAlarmCal::CollectionAttribute::setKeepFormat
void setKeepFormat(bool keep)
Set whether to keep the old calendar storage format unchanged.
Definition: collectionattribute.cpp:165
KAlarmCal::CalEvent::EMPTY
the event has no alarms
Definition: kacalendar.h:157
KAlarmCal::CollectionAttribute::type
virtual QByteArray type() const
Reimplemented from Attribute.
Definition: collectionattribute.cpp:170
KAlarmCal::CalEvent::ARCHIVED
the event is archived
Definition: kacalendar.h:159
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:84
KAlarmCal::CollectionAttribute::serialized
virtual QByteArray serialized() const
Reimplemented from Attribute.
Definition: collectionattribute.cpp:180
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:01:14 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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