KAlarm Library
collectionattribute.cpp
00001 /* 00002 * collectionattribute.cpp - Akonadi attribute holding Collection characteristics 00003 * This file is part of kalarmcal library, which provides access to KAlarm 00004 * calendar data. 00005 * Copyright © 2010-2011 by David Jarvie <djarvie@kde.org> 00006 * 00007 * This library is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU Library General Public License as published 00009 * by the Free Software Foundation; either version 2 of the License, or (at 00010 * your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00015 * License for more details. 00016 * 00017 * You should have received a copy of the GNU Library General Public License 00018 * along with this library; see the file COPYING.LIB. If not, write to the 00019 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00020 * MA 02110-1301, USA. 00021 */ 00022 00023 #include "collectionattribute.h" 00024 00025 #include <kdebug.h> 00026 00027 namespace KAlarmCal 00028 { 00029 00030 class CollectionAttribute::Private 00031 { 00032 public: 00033 Private() : mEnabled(CalEvent::EMPTY), 00034 mStandard(CalEvent::EMPTY), 00035 mKeepFormat(false) {} 00036 00037 QColor mBackgroundColour; // background color for collection and its alarms 00038 CalEvent::Types mEnabled; // which alarm types the collection is enabled for 00039 CalEvent::Types mStandard; // whether the collection is a standard collection 00040 bool mKeepFormat; // whether user has chosen to keep old calendar storage format 00041 }; 00042 00043 00044 CollectionAttribute::CollectionAttribute() 00045 : d(new Private) 00046 { 00047 } 00048 00049 CollectionAttribute::CollectionAttribute(const CollectionAttribute& rhs) 00050 : Akonadi::Attribute(rhs), 00051 d(new Private(*rhs.d)) 00052 { 00053 } 00054 00055 CollectionAttribute::~CollectionAttribute() 00056 { 00057 delete d; 00058 } 00059 00060 CollectionAttribute& CollectionAttribute::operator=(const CollectionAttribute& other) 00061 { 00062 if (&other != this) 00063 { 00064 Attribute::operator=(other); 00065 *d = *other.d; 00066 } 00067 return *this; 00068 } 00069 00070 CollectionAttribute* CollectionAttribute::clone() const 00071 { 00072 return new CollectionAttribute(*this); 00073 } 00074 00075 bool CollectionAttribute::isEnabled(CalEvent::Type type) const 00076 { 00077 return d->mEnabled & type; 00078 } 00079 00080 CalEvent::Types CollectionAttribute::enabled() const 00081 { 00082 return d->mEnabled; 00083 } 00084 00085 void CollectionAttribute::setEnabled(CalEvent::Type type, bool enabled) 00086 { 00087 switch (type) 00088 { 00089 case CalEvent::ACTIVE: 00090 case CalEvent::ARCHIVED: 00091 case CalEvent::TEMPLATE: 00092 break; 00093 default: 00094 return; 00095 } 00096 if (enabled) 00097 d->mEnabled |= type; 00098 else 00099 { 00100 d->mEnabled &= ~type; 00101 d->mStandard &= ~type; 00102 } 00103 } 00104 00105 void CollectionAttribute::setEnabled(CalEvent::Types types) 00106 { 00107 d->mEnabled = types & (CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE); 00108 d->mStandard &= d->mEnabled; 00109 } 00110 00111 bool CollectionAttribute::isStandard(CalEvent::Type type) const 00112 { 00113 switch (type) 00114 { 00115 case CalEvent::ACTIVE: 00116 case CalEvent::ARCHIVED: 00117 case CalEvent::TEMPLATE: 00118 return d->mStandard & type; 00119 default: 00120 return false; 00121 } 00122 } 00123 00124 CalEvent::Types CollectionAttribute::standard() const 00125 { 00126 return d->mStandard; 00127 } 00128 00129 void CollectionAttribute::setStandard(CalEvent::Type type, bool standard) 00130 { 00131 switch (type) 00132 { 00133 case CalEvent::ACTIVE: 00134 case CalEvent::ARCHIVED: 00135 case CalEvent::TEMPLATE: 00136 if (standard) 00137 d->mStandard = static_cast<CalEvent::Types>(d->mStandard | type); 00138 else 00139 d->mStandard = static_cast<CalEvent::Types>(d->mStandard & ~type); 00140 break; 00141 default: 00142 break; 00143 } 00144 } 00145 00146 void CollectionAttribute::setStandard(CalEvent::Types types) 00147 { 00148 d->mStandard = types & (CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE); 00149 } 00150 00151 QColor CollectionAttribute::backgroundColor() const 00152 { 00153 return d->mBackgroundColour; 00154 } 00155 00156 void CollectionAttribute::setBackgroundColor(const QColor& c) 00157 { 00158 d->mBackgroundColour = c; 00159 } 00160 00161 bool CollectionAttribute::keepFormat() const 00162 { 00163 return d->mKeepFormat; 00164 } 00165 00166 void CollectionAttribute::setKeepFormat(bool keep) 00167 { 00168 d->mKeepFormat = keep; 00169 } 00170 00171 QByteArray CollectionAttribute::type() const 00172 { 00173 return name(); 00174 } 00175 00176 QByteArray CollectionAttribute::name() 00177 { 00178 return "KAlarmCollection"; 00179 } 00180 00181 QByteArray CollectionAttribute::serialized() const 00182 { 00183 QByteArray v = QByteArray::number(d->mEnabled) + ' ' 00184 + QByteArray::number(d->mStandard) + ' ' 00185 + QByteArray(d->mKeepFormat ? "1" : "0") + ' ' 00186 + QByteArray(d->mBackgroundColour.isValid() ? "1" : "0"); 00187 if (d->mBackgroundColour.isValid()) 00188 v += ' ' 00189 + QByteArray::number(d->mBackgroundColour.red()) + ' ' 00190 + QByteArray::number(d->mBackgroundColour.green()) + ' ' 00191 + QByteArray::number(d->mBackgroundColour.blue()) + ' ' 00192 + QByteArray::number(d->mBackgroundColour.alpha()); 00193 kDebug() << v; 00194 return v; 00195 } 00196 00197 void CollectionAttribute::deserialize(const QByteArray& data) 00198 { 00199 kDebug() << data; 00200 00201 // Set default values 00202 d->mEnabled = CalEvent::EMPTY; 00203 d->mStandard = CalEvent::EMPTY; 00204 d->mBackgroundColour = QColor(); 00205 d->mKeepFormat = false; 00206 00207 bool ok; 00208 int c[4]; 00209 const QList<QByteArray> items = data.simplified().split(' '); 00210 int count = items.count(); 00211 int index = 0; 00212 if (count > index) 00213 { 00214 // 0: type(s) of alarms for which the collection is enabled 00215 c[0] = items[index++].toInt(&ok); 00216 if (!ok || (c[0] & ~(CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE))) 00217 { 00218 kError() << "Invalid alarm types:" << c[0]; 00219 return; 00220 } 00221 d->mEnabled = static_cast<CalEvent::Types>(c[0]); 00222 } 00223 if (count > index) 00224 { 00225 // 1: type(s) of alarms for which the collection is the standard collection 00226 c[0] = items[index++].toInt(&ok); 00227 if (!ok || (c[0] & ~(CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE))) 00228 { 00229 kError() << "Invalid alarm types:" << c[0]; 00230 return; 00231 } 00232 if (d->mEnabled) 00233 d->mStandard = static_cast<CalEvent::Types>(c[0]); 00234 } 00235 if (count > index) 00236 { 00237 // 2: keep old calendar storage format 00238 c[0] = items[index++].toInt(&ok); 00239 if (!ok) 00240 return; 00241 d->mKeepFormat = c[0]; 00242 } 00243 if (count > index) 00244 { 00245 // 3: background color valid flag 00246 c[0] = items[index++].toInt(&ok); 00247 if (!ok) 00248 return; 00249 if (c[0]) 00250 { 00251 if (count < index + 4) 00252 { 00253 kError() << "Invalid number of background color elements"; 00254 return; 00255 } 00256 // 4-7: background color elements 00257 for (int i = 0; i < 4; ++i) 00258 { 00259 c[i] = items[index++].toInt(&ok); 00260 if (!ok) 00261 return; 00262 } 00263 d->mBackgroundColour.setRgb(c[0], c[1], c[2], c[3]); 00264 } 00265 } 00266 } 00267 00268 } // namespace KAlarmCal 00269 00270 // vim: et sw=4:
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 05:13:34 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 05:13:34 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.