Commit fc94f3f6 authored by David Jarvie's avatar David Jarvie
Browse files

Add Resource::compatibilityVersion() and failed()

parent a680f3c5
......@@ -29,6 +29,7 @@
#include <kalarmcal/akonadi.h>
#include <kalarmcal/compatibilityattribute.h>
#include <kalarmcal/eventattribute.h>
#include <kalarmcal/version.h>
#include <AkonadiCore/AgentManager>
#include <AkonadiCore/ChangeRecorder>
......@@ -329,14 +330,26 @@ void AkonadiResource::configSetStandard(CalEvent::Types types)
modifyCollectionAttribute();
}
KACalendar::Compat AkonadiResource::compatibility() const
KACalendar::Compat AkonadiResource::compatibilityVersion(QString& versionString) const
{
versionString.clear();
if (!mValid)
return KACalendar::Incompatible;
AkonadiModel::instance()->refresh(mCollection); // update with latest data
if (!mCollection.hasAttribute<CompatibilityAttribute>())
return KACalendar::Incompatible;
return mCollection.attribute<CompatibilityAttribute>()->compatibility();
const CompatibilityAttribute* attr = mCollection.attribute<CompatibilityAttribute>();
versionString = KAlarmCal::getVersionString(attr->version());
return attr->compatibility();
}
/******************************************************************************
* Update the resource to the current KAlarm storage format.
*/
bool AkonadiResource::updateStorageFormat()
{
//TODO: implement updateStorageFormat(): see CalendarMigrator::updateStorageFormat()
return false;
}
/******************************************************************************
......
......@@ -134,11 +134,11 @@ public:
using ResourceType::isWritable;
/** Return whether the user has chosen not to update the resource's
* calendar storage formst. */
* calendar storage format. */
bool keepFormat() const override;
/** Set or clear whether the user has chosen not to update the resource's
* calendar storage formst. */
* calendar storage format. */
void setKeepFormat(bool keep) override;
/** Return the background colour used to display alarms belonging to
......@@ -209,8 +209,12 @@ public:
* current KAlarm format, in which case it cannot be written to.
* Note that isWritable() takes account of incompatible format
* as well as read-only and enabled statuses.
* @param versionString Receives calendar's KAlarm version as a string.
*/
KACalendar::Compat compatibility() const override;
KACalendar::Compat compatibilityVersion(QString& versionString) const override;
/** Update the resource to the current KAlarm storage format. */
bool updateStorageFormat() override;
/** Edit the resource's configuration. */
void editResource(QWidget* dialogParent) override;
......
......@@ -61,6 +61,11 @@ bool Resource::isValid() const
return mResource.isNull() ? false : mResource->isValid();
}
bool Resource::failed() const
{
return mResource.isNull() ? true : mResource->failed();
}
#if 0
ResourceType::Ptr Resource::resource() const
{
......@@ -194,14 +199,29 @@ void Resource::configSetStandard(CalEvent::Types types)
mResource->configSetStandard(types);
}
bool Resource::isCompatible() const
{
return mResource.isNull() ? false : mResource->isCompatible();
}
KACalendar::Compat Resource::compatibility() const
{
return mResource.isNull() ? KACalendar::Incompatible : mResource->compatibility();
}
bool Resource::isCompatible() const
KACalendar::Compat Resource::compatibilityVersion(QString& versionString) const
{
return mResource.isNull() ? false : mResource->isCompatible();
if (mResource.isNull())
{
versionString.clear();
return KACalendar::Incompatible;
}
return mResource->compatibilityVersion(versionString);
}
bool Resource::updateStorageFormat()
{
return mResource.isNull() ? false : mResource->updateStorageFormat();
}
void Resource::editResource(QWidget* dialogParent)
......
......@@ -56,9 +56,20 @@ public:
/** Return whether the resource has a null calendar resource pointer. */
bool isNull() const;
/** Return whether the resource has a valid configuration. */
/** Return whether the resource has a valid configuration.
* Note that the resource may be unusable even if it has a valid
* configuration: see failed().
*/
bool isValid() const;
/** Return whether the resource has a fatal error.
* Note that failed() will return true if the configuration is invalid
* (i.e. isValid() returns false). It will also return true if some other
* error prevents the resource being used, e.g. if the calendar file
* cannot be created.
*/
bool failed() const;
/** Return the resource's unique ID. */
ResourceId id() const;
......@@ -149,11 +160,11 @@ public:
#endif
/** Return whether the user has chosen not to update the resource's
* calendar storage formst. */
* calendar storage format. */
bool keepFormat() const;
/** Set or clear whether the user has chosen not to update the resource's
* calendar storage formst. */
* calendar storage format. */
void setKeepFormat(bool keep);
/** Return the background colour used to display alarms belonging to
......@@ -227,6 +238,11 @@ public:
*/
void configSetStandard(CalEvent::Types types);
/** Return whether the resource is in the current KAlarm format.
* @see compatibility(), compatibilityVersion()
*/
bool isCompatible() const;
/** Return whether the resource is in a different format from the
* current KAlarm format, in which case it cannot be written to.
* Note that isWritable() takes account of incompatible format
......@@ -234,8 +250,16 @@ public:
*/
KACalendar::Compat compatibility() const;
/** Return whether the resource is in the current KAlarm format. */
bool isCompatible() const;
/** Return whether the resource is in a different format from the
* current KAlarm format, in which case it cannot be written to.
* Note that isWritable() takes account of incompatible format
* as well as read-only and enabled statuses.
* @param versionString Receives calendar's KAlarm version as a string.
*/
KACalendar::Compat compatibilityVersion(QString& versionString) const;
/** Update the resource to the current KAlarm storage format. */
bool updateStorageFormat();
/** Edit the resource's configuration. */
void editResource(QWidget* dialogParent);
......
......@@ -37,6 +37,11 @@ ResourceType::~ResourceType()
{
}
bool ResourceType::failed() const
{
return mFailed || !isValid();
}
bool ResourceType::isEnabled(CalEvent::Type type) const
{
return (type == CalEvent::EMPTY) ? enabledTypes() : enabledTypes() & type;
......@@ -94,6 +99,12 @@ bool ResourceType::isCompatible() const
return compatibility() == KACalendar::Current;
}
KACalendar::Compat ResourceType::compatibility() const
{
QString versionString;
return compatibilityVersion(versionString);
}
/******************************************************************************
* Return all events belonging to this resource, for enabled alarm types.
*/
......@@ -279,6 +290,11 @@ void ResourceType::setLoaded(bool loaded) const
}
}
void ResourceType::setFailed()
{
mFailed = true;
}
QString ResourceType::storageTypeStr(bool description, bool file, bool local) const
{
if (description)
......
......@@ -79,9 +79,20 @@ public:
virtual ~ResourceType() = 0;
/** Return whether the resource has a valid configuration. */
/** Return whether the resource has a valid configuration.
* Note that the resource may be unusable even if it has a valid
* configuration: see failed().
*/
virtual bool isValid() const = 0;
/** Return whether the resource has a fatal error.
* Note that failed() will return true if the configuration is invalid
* (i.e. isValid() returns false). It will also return true if some other
* error prevents the resource being used, e.g. if the calendar file
* cannot be created.
*/
bool failed() const;
/** Return the resource's unique ID. */
ResourceId id() const { return mId; }
......@@ -172,11 +183,11 @@ public:
#endif
/** Return whether the user has chosen not to update the resource's
* calendar storage formst. */
* calendar storage format. */
virtual bool keepFormat() const = 0;
/** Set or clear whether the user has chosen not to update the resource's
* calendar storage formst. */
* calendar storage format. */
virtual void setKeepFormat(bool keep) = 0;
/** Return the background colour used to display alarms belonging to
......@@ -250,15 +261,28 @@ public:
*/
virtual void configSetStandard(CalEvent::Types types) = 0;
/** Return whether the resource is in the current KAlarm format.
* @see compatibility(), compatibilityVersion()
*/
bool isCompatible() const;
/** Return whether the resource is in a different format from the
* current KAlarm format, in which case it cannot be written to.
* Note that isWritable() takes account of incompatible format
* as well as read-only and enabled statuses.
*/
virtual KACalendar::Compat compatibility() const = 0;
KACalendar::Compat compatibility() const;
/** Return whether the resource is in the current KAlarm format. */
bool isCompatible() const;
/** Return whether the resource is in a different format from the
* current KAlarm format, in which case it cannot be written to.
* Note that isWritable() takes account of incompatible format
* as well as read-only and enabled statuses.
* @param versionString Receives calendar's KAlarm version as a string.
*/
virtual KACalendar::Compat compatibilityVersion(QString& versionString) const = 0;
/** Update the resource to the current KAlarm storage format. */
virtual bool updateStorageFormat() = 0;
/** Edit the resource's configuration. */
virtual void editResource(QWidget* dialogParent) = 0;
......@@ -394,6 +418,11 @@ protected:
/** To be called when the loaded status of the resource has changed. */
void setLoaded(bool loaded) const;
/** To be called if the resource has encountered a fatal error.
* A fatal error is one that can never be recovered from.
*/
void setFailed();
QString storageTypeStr(bool description, bool file, bool local) const;
template <class T> static T* resource(Resource&);
template <class T> static const T* resource(const Resource&);
......@@ -404,6 +433,7 @@ private:
QHash<QString, KAEvent> mEvents; // all events (of ALL types) in the resource, indexed by ID
ResourceId mId{-1}; // resource's ID, which can't be changed
bool mFailed{false}; // the resource has a fatal error
mutable bool mLoaded{false}; // the resource has finished loading
bool mBeingDeleted{false}; // the resource is currently being deleted
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment