Commit dcf71d34 authored by David Jarvie's avatar David Jarvie

Move private members into a private class

parent 0de1fa63
......@@ -26,19 +26,61 @@
namespace KAlarm
{
class CollectionAttribute::Private
{
public:
Private() : mEnabled(KAlarm::CalEvent::EMPTY),
mStandard(KAlarm::CalEvent::EMPTY),
mKeepFormat(false) {}
QColor mBackgroundColour; // background color for collection and its alarms
KAlarm::CalEvent::Types mEnabled; // which alarm types the collection is enabled for
KAlarm::CalEvent::Types mStandard; // whether the collection is a standard collection
bool mKeepFormat; // whether user has chosen to keep old calendar storage format
};
CollectionAttribute::CollectionAttribute()
: d(new Private)
{
}
CollectionAttribute::CollectionAttribute(const CollectionAttribute& rhs)
: mBackgroundColour(rhs.mBackgroundColour),
mEnabled(rhs.mEnabled),
mStandard(rhs.mStandard),
mKeepFormat(rhs.mKeepFormat)
: Akonadi::Attribute(rhs),
d(new Private(*rhs.d))
{
}
CollectionAttribute::~CollectionAttribute()
{
delete d;
}
CollectionAttribute& CollectionAttribute::operator=(const CollectionAttribute& other)
{
if (&other != this)
{
Attribute::operator=(other);
*d = *other.d;
}
return *this;
}
CollectionAttribute* CollectionAttribute::clone() const
{
return new CollectionAttribute(*this);
}
bool CollectionAttribute::isEnabled(KAlarm::CalEvent::Type type) const
{
return d->mEnabled & type;
}
KAlarm::CalEvent::Types CollectionAttribute::enabled() const
{
return d->mEnabled;
}
void CollectionAttribute::setEnabled(CalEvent::Type type, bool enabled)
{
switch (type)
......@@ -51,18 +93,18 @@ void CollectionAttribute::setEnabled(CalEvent::Type type, bool enabled)
return;
}
if (enabled)
mEnabled |= type;
d->mEnabled |= type;
else
{
mEnabled &= ~type;
mStandard &= ~type;
d->mEnabled &= ~type;
d->mStandard &= ~type;
}
}
void CollectionAttribute::setEnabled(KAlarm::CalEvent::Types types)
{
mEnabled = types & (CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE);
mStandard &= mEnabled;
d->mEnabled = types & (CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE);
d->mStandard &= d->mEnabled;
}
bool CollectionAttribute::isStandard(KAlarm::CalEvent::Type type) const
......@@ -72,12 +114,17 @@ bool CollectionAttribute::isStandard(KAlarm::CalEvent::Type type) const
case KAlarm::CalEvent::ACTIVE:
case KAlarm::CalEvent::ARCHIVED:
case KAlarm::CalEvent::TEMPLATE:
return mStandard & type;
return d->mStandard & type;
default:
return false;
}
}
KAlarm::CalEvent::Types CollectionAttribute::standard() const
{
return d->mStandard;
}
void CollectionAttribute::setStandard(KAlarm::CalEvent::Type type, bool standard)
{
switch (type)
......@@ -86,9 +133,9 @@ void CollectionAttribute::setStandard(KAlarm::CalEvent::Type type, bool standard
case KAlarm::CalEvent::ARCHIVED:
case KAlarm::CalEvent::TEMPLATE:
if (standard)
mStandard = static_cast<KAlarm::CalEvent::Types>(mStandard | type);
d->mStandard = static_cast<KAlarm::CalEvent::Types>(d->mStandard | type);
else
mStandard = static_cast<KAlarm::CalEvent::Types>(mStandard & ~type);
d->mStandard = static_cast<KAlarm::CalEvent::Types>(d->mStandard & ~type);
break;
default:
break;
......@@ -97,21 +144,51 @@ void CollectionAttribute::setStandard(KAlarm::CalEvent::Type type, bool standard
void CollectionAttribute::setStandard(KAlarm::CalEvent::Types types)
{
mStandard = types & (CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE);
d->mStandard = types & (CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE);
}
QColor CollectionAttribute::backgroundColor() const
{
return d->mBackgroundColour;
}
void CollectionAttribute::setBackgroundColor(const QColor& c)
{
d->mBackgroundColour = c;
}
bool CollectionAttribute::keepFormat() const
{
return d->mKeepFormat;
}
void CollectionAttribute::setKeepFormat(bool keep)
{
d->mKeepFormat = keep;
}
QByteArray CollectionAttribute::type() const
{
return name();
}
QByteArray CollectionAttribute::name()
{
return "KAlarmCollection";
}
QByteArray CollectionAttribute::serialized() const
{
QByteArray v = QByteArray::number(mEnabled) + ' '
+ QByteArray::number(mStandard) + ' '
+ QByteArray(mKeepFormat ? "1" : "0") + ' '
+ QByteArray(mBackgroundColour.isValid() ? "1" : "0");
if (mBackgroundColour.isValid())
QByteArray v = QByteArray::number(d->mEnabled) + ' '
+ QByteArray::number(d->mStandard) + ' '
+ QByteArray(d->mKeepFormat ? "1" : "0") + ' '
+ QByteArray(d->mBackgroundColour.isValid() ? "1" : "0");
if (d->mBackgroundColour.isValid())
v += ' '
+ QByteArray::number(mBackgroundColour.red()) + ' '
+ QByteArray::number(mBackgroundColour.green()) + ' '
+ QByteArray::number(mBackgroundColour.blue()) + ' '
+ QByteArray::number(mBackgroundColour.alpha());
+ QByteArray::number(d->mBackgroundColour.red()) + ' '
+ QByteArray::number(d->mBackgroundColour.green()) + ' '
+ QByteArray::number(d->mBackgroundColour.blue()) + ' '
+ QByteArray::number(d->mBackgroundColour.alpha());
kDebug(5950)<<v;
return v;
}
......@@ -119,10 +196,10 @@ kDebug(5950)<<v;
void CollectionAttribute::deserialize(const QByteArray& data)
{
// Set default values
mEnabled = KAlarm::CalEvent::EMPTY;
mStandard = KAlarm::CalEvent::EMPTY;
mBackgroundColour = QColor();
mKeepFormat = false;
d->mEnabled = KAlarm::CalEvent::EMPTY;
d->mStandard = KAlarm::CalEvent::EMPTY;
d->mBackgroundColour = QColor();
d->mKeepFormat = false;
bool ok;
int c[4];
......@@ -139,7 +216,7 @@ kDebug(5950)<<"Size="<<count<<", data="<<data;
kError() << "Invalid alarm types:" << c[0];
return;
}
mEnabled = static_cast<KAlarm::CalEvent::Types>(c[0]);
d->mEnabled = static_cast<KAlarm::CalEvent::Types>(c[0]);
}
if (count > index)
{
......@@ -150,8 +227,8 @@ kDebug(5950)<<"Size="<<count<<", data="<<data;
kError() << "Invalid alarm types:" << c[0];
return;
}
if (mEnabled)
mStandard = static_cast<KAlarm::CalEvent::Types>(c[0]);
if (d->mEnabled)
d->mStandard = static_cast<KAlarm::CalEvent::Types>(c[0]);
}
if (count > index)
{
......@@ -159,7 +236,7 @@ kDebug(5950)<<"Size="<<count<<", data="<<data;
c[0] = items[index++].toInt(&ok);
if (!ok)
return;
mKeepFormat = c[0];
d->mKeepFormat = c[0];
}
if (count > index)
{
......@@ -181,7 +258,7 @@ kDebug(5950)<<"Size="<<count<<", data="<<data;
if (!ok)
return;
}
mBackgroundColour.setRgb(c[0], c[1], c[2], c[3]);
d->mBackgroundColour.setRgb(c[0], c[1], c[2], c[3]);
}
}
}
......
......@@ -33,23 +33,38 @@
namespace KAlarm
{
/*=============================================================================
= Class: CollectionAttribute
= User-specific attributes of a KAlarm collection.
=============================================================================*/
/**
* @short An Attribute for a KAlarm Collection containing various status information.
*
* This class represents an Akonadi attribute of a KAlarm Collection. It contains
* information on the enabled status, the mime types allowed in the resource,
* which mime types the resource is the standard Collection for, etc.
*
* The attribute is maintained by client applications.
*
* @see CompatibilityAttribute
*
* @author David Jarvie <djarvie@kde.org>
*/
class KALARM_CAL_EXPORT CollectionAttribute : public Akonadi::Attribute
{
public:
CollectionAttribute()
: mEnabled(KAlarm::CalEvent::EMPTY),
mStandard(KAlarm::CalEvent::EMPTY),
mKeepFormat(false) {}
CollectionAttribute();
bool isEnabled(KAlarm::CalEvent::Type type) const { return mEnabled & type; }
/** Copy constructor. */
CollectionAttribute(const CollectionAttribute& other);
/** Assignment operator. */
CollectionAttribute& operator=(const CollectionAttribute& other);
~CollectionAttribute();
/** Return whether the collection is enabled for a specified mime type. */
bool isEnabled(KAlarm::CalEvent::Type type) const;
/** Return which mime types the collection is enabled for. */
KAlarm::CalEvent::Types enabled() const { return mEnabled; }
KAlarm::CalEvent::Types enabled() const;
/** Set the enabled/disabled state of the collection and its alarms, for a
* specified alarm type. The enabled/disabled state for other alarm types
......@@ -72,7 +87,7 @@ class KALARM_CAL_EXPORT CollectionAttribute : public Akonadi::Attribute
void setStandard(KAlarm::CalEvent::Type, bool standard);
/** Return which mime types the collection is standard for. */
KAlarm::CalEvent::Types standard() const { return mStandard; }
KAlarm::CalEvent::Types standard() const;
/** Set which mime types the collection is the standard collection for. */
void setStandard(KAlarm::CalEvent::Types);
......@@ -80,32 +95,35 @@ class KALARM_CAL_EXPORT CollectionAttribute : public Akonadi::Attribute
/** Return the background color to display this collection and its alarms,
* or invalid color if none is set.
*/
QColor backgroundColor() const { return mBackgroundColour; }
QColor backgroundColor() const;
/** Set the background color for this collection and its alarms. */
void setBackgroundColor(const QColor& c) { mBackgroundColour = c; }
void setBackgroundColor(const QColor& c);
/** Return whether the user has chosen to keep the old calendar storage
* format, i.e. not update to current KAlarm format.
*/
bool keepFormat() const { return mKeepFormat; }
bool keepFormat() const;
/** Set whether to keep the old calendar storage format unchanged. */
void setKeepFormat(bool keep) { mKeepFormat = keep; }
void setKeepFormat(bool keep);
virtual QByteArray type() const { return name(); }
/** Reimplemented from Attribute */
virtual QByteArray type() const;
/** Reimplemented from Attribute */
virtual CollectionAttribute* clone() const;
/** Reimplemented from Attribute */
virtual QByteArray serialized() const;
/** Reimplemented from Attribute */
virtual void deserialize(const QByteArray& data);
static QByteArray name() { return "KAlarmCollection"; }
/** Reimplemented from Attribute */
static QByteArray name();
private:
CollectionAttribute(const CollectionAttribute&);
QColor mBackgroundColour; // background color for collection and its alarms
KAlarm::CalEvent::Types mEnabled; // which alarm types the collection is enabled for
KAlarm::CalEvent::Types mStandard; // whether the collection is a standard collection
bool mKeepFormat; // whether user has chosen to keep old calendar storage format
//@cond PRIVATE
class Private;
Private* const d;
//@endcond
};
} // namespace KAlarm
......
......@@ -26,10 +26,44 @@
namespace KAlarm
{
class CompatibilityAttribute::Private
{
public:
Private()
: mCompatibility(KAlarm::Calendar::Incompatible),
mVersion(KAlarm::IncompatibleFormat)
{}
KAlarm::Calendar::Compat mCompatibility; // calendar compatibility with current KAlarm format
int mVersion; // KAlarm calendar format version
};
CompatibilityAttribute::CompatibilityAttribute()
: d(new Private)
{
}
CompatibilityAttribute::CompatibilityAttribute(const CompatibilityAttribute& rhs)
: mCompatibility(rhs.mCompatibility),
mVersion(rhs.mVersion)
: Akonadi::Attribute(rhs),
d(new Private(*rhs.d))
{
}
CompatibilityAttribute::~CompatibilityAttribute()
{
delete d;
}
CompatibilityAttribute& CompatibilityAttribute::operator=(const CompatibilityAttribute& other)
{
if (&other != this)
{
Attribute::operator=(other);
*d = *other.d;
}
return *this;
}
CompatibilityAttribute* CompatibilityAttribute::clone() const
......@@ -37,10 +71,40 @@ CompatibilityAttribute* CompatibilityAttribute::clone() const
return new CompatibilityAttribute(*this);
}
KAlarm::Calendar::Compat CompatibilityAttribute::compatibility() const
{
return d->mCompatibility;
}
void CompatibilityAttribute::setCompatibility(KAlarm::Calendar::Compat c)
{
d->mCompatibility = c;
}
int CompatibilityAttribute::version() const
{
return d->mVersion;
}
void CompatibilityAttribute::setVersion(int v)
{
d->mVersion = v;
}
QByteArray CompatibilityAttribute::type() const
{
return name();
}
QByteArray CompatibilityAttribute::name()
{
return "KAlarmCompatibility";
}
QByteArray CompatibilityAttribute::serialized() const
{
QByteArray v = QByteArray::number(mCompatibility) + ' '
+ QByteArray::number(mVersion);
QByteArray v = QByteArray::number(d->mCompatibility) + ' '
+ QByteArray::number(d->mVersion);
kDebug(5950)<<v;
return v;
}
......@@ -48,8 +112,8 @@ kDebug(5950)<<v;
void CompatibilityAttribute::deserialize(const QByteArray& data)
{
// Set default values
mCompatibility = KAlarm::Calendar::Incompatible;
mVersion = KAlarm::IncompatibleFormat;
d->mCompatibility = KAlarm::Calendar::Incompatible;
d->mVersion = KAlarm::IncompatibleFormat;
bool ok;
const QList<QByteArray> items = data.simplified().split(' ');
......@@ -66,7 +130,7 @@ kDebug(5950)<<"Size="<<count<<", data="<<data;
kError() << "Invalid compatibility:" << c;
return;
}
mCompatibility = static_cast<KAlarm::Calendar::Compat>(c);
d->mCompatibility = static_cast<KAlarm::Calendar::Compat>(c);
}
if (count > index)
{
......@@ -77,7 +141,7 @@ kDebug(5950)<<"Size="<<count<<", data="<<data;
kError() << "Invalid version:" << c;
return;
}
mVersion = c;
d->mVersion = c;
}
}
......
......@@ -18,7 +18,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef COMPATIBILITY_ATTRIBUTE_H
#define COMPATIBILITY_ATTRIBUTE_H
......@@ -31,42 +30,61 @@
namespace KAlarm
{
/*=============================================================================
= Class: CompatibilityAttribute
= Resource-specific attributes of a KAlarm collection, i.e. the compatibility
= status of collections or items.
=============================================================================*/
/**
* @short An Attribute for a KAlarm Collection containing compatibility information.
*
* This class represents an Akonadi attribute of a KAlarm Collection. It contains
* information on the compatibility of the Collection and its Items with the
* current KAlarm calendar format. The attribute is maintained by the Akonadi
* resource, and should be treated as read-only by applications.
*
* @see CollectionAttribute
*
* @author David Jarvie <djarvie@kde.org>
*/
class KALARM_CAL_EXPORT CompatibilityAttribute : public Akonadi::Attribute
{
public:
CompatibilityAttribute()
: mCompatibility(KAlarm::Calendar::Incompatible),
mVersion(KAlarm::IncompatibleFormat) { }
/** Default constructor. Creates an incompatible attribute. */
CompatibilityAttribute();
/** Copy constructor. */
CompatibilityAttribute(const CompatibilityAttribute& other);
/** Assignment operator. */
CompatibilityAttribute& operator=(const CompatibilityAttribute& other);
~CompatibilityAttribute();
/** Return the compatibility status for the entity. */
KAlarm::Calendar::Compat compatibility() const { return mCompatibility; }
KAlarm::Calendar::Compat compatibility() const;
/** Set the compatibility status for the entity. */
void setCompatibility(KAlarm::Calendar::Compat c) { mCompatibility = c; }
void setCompatibility(KAlarm::Calendar::Compat c);
/** Return the KAlarm version of the backend calendar format. */
int version() const { return mVersion; }
int version() const;
/** Set the KAlarm version of the backend calendar format. */
void setVersion(int v) { mVersion = v; }
void setVersion(int v);
virtual QByteArray type() const { return name(); }
/** Reimplemented from Attribute */
virtual QByteArray type() const;
/** Reimplemented from Attribute */
virtual CompatibilityAttribute* clone() const;
/** Reimplemented from Attribute */
virtual QByteArray serialized() const;
/** Reimplemented from Attribute */
virtual void deserialize(const QByteArray& data);
static QByteArray name() { return "KAlarmCompatibility"; }
/** Reimplemented from Attribute */
static QByteArray name();
private:
CompatibilityAttribute(const CompatibilityAttribute&);
KAlarm::Calendar::Compat mCompatibility; // calendar compatibility with current KAlarm format
int mVersion; // KAlarm calendar format version
//@cond PRIVATE
class Private;
Private* const d;
//@endcond
};
} // namespace KAlarm
......
/*
* datetime.cpp - date/time with start-of-day time for date-only values
* datetime.cpp - date/time with start-of-day time for date-only values
* Program: kalarm
* Copyright © 2003,2005-2007,2009,2010 by David Jarvie <djarvie@kde.org>
* Copyright © 2003,2005-2007,2009-2011 by David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published
......@@ -24,66 +24,363 @@
#include <klocale.h>
QTime DateTime::mStartOfDay;
class DateTime::Private
{
public:
Private() {}
Private(const QDate& d, const KDateTime::Spec& spec) : mDateTime(d, spec) {}
Private(const QDate& d, const QTime& t, const KDateTime::Spec& spec) : mDateTime(d, t, spec) {}
Private(const QDateTime& dt, const KDateTime::Spec& spec) : mDateTime(dt, spec) {}
Private(const KDateTime& dt) : mDateTime(dt) {}
static QTime mStartOfDay;
KDateTime mDateTime;
};
QTime DateTime::Private::mStartOfDay;
DateTime::DateTime()
: d(new Private)
{
}
DateTime::DateTime(const QDate& d, const KDateTime::Spec& spec)
: d(new Private(d, spec))
{
}
DateTime::DateTime(const QDate& d, const QTime& t, const KDateTime::Spec& spec)
: d(new Private(d, t, spec))
{
}
DateTime::DateTime(const QDateTime& dt, const KDateTime::Spec& spec)
: d(new Private(dt, spec))
{
}
DateTime::DateTime(const KDateTime& dt)
: d(new Private(dt))
{
}
DateTime::DateTime(const DateTime& dt)
: d(new Private(*dt.d))
{
}
DateTime::~DateTime()
{
delete d;
}
DateTime& DateTime::operator=(const DateTime& dt)
{
if (&dt != this)
*d = *dt.d;
return *this;
}
DateTime& DateTime::operator=(const KDateTime& dt)
{
d->mDateTime = dt;
return *this;
}
bool DateTime::isNull() const