Verified Commit 261678d5 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Move attributes to src/core/attributes subfolder (ABI break)

Same as with models and jobs. Modernizes and cleans up the code a little.
No changes needed to client code except for recompiling.
parent 59931b91
Pipeline #30276 passed with stage
in 30 minutes and 5 seconds
......@@ -8,7 +8,6 @@ set(akonadicore_base_SRCS
agentmanager.cpp
agenttype.cpp
asyncselectionhandler.cpp
attribute.cpp
attributefactory.cpp
attributestorage.cpp
braveheart.cpp
......@@ -21,28 +20,16 @@ set(akonadicore_base_SRCS
changerecorderjournal.cpp
connection.cpp
collection.cpp
collectioncolorattribute.cpp
collectionfetchscope.cpp
collectionpathresolver.cpp
collectionquotaattribute.cpp
collectionquotaattribute.cpp
collectionrightsattribute.cpp
collectionstatistics.cpp
collectionsync.cpp
conflicthandler.cpp
collectionidentificationattribute.cpp
control.cpp
entityannotationsattribute.cpp
entitycache.cpp
entitydeletedattribute.cpp
entitydeletedattribute.cpp
entitydisplayattribute.cpp
entityhiddenattribute.cpp
exception.cpp
favoritecollectionattribute.cpp
firstrun.cpp
gidextractor.cpp
indexpolicyattribute.cpp
item.cpp
itemchangelog.cpp
itemfetchscope.cpp
......@@ -57,7 +44,6 @@ set(akonadicore_base_SRCS
notificationsubscriber.cpp
partfetcher.cpp
pastehelper.cpp
persistentsearchattribute.cpp
pluginloader.cpp
protocolhelper.cpp
remotelog.cpp
......@@ -67,10 +53,8 @@ set(akonadicore_base_SRCS
servermanager.cpp
session.cpp
sessionthread.cpp
specialcollectionattribute.cpp
specialcollections.cpp
tag.cpp
tagattribute.cpp
tagfetchscope.cpp
tagsync.cpp
trashsettings.cpp
......@@ -85,28 +69,18 @@ ecm_generate_headers(AkonadiCore_base_HEADERS
AgentInstance
AgentManager
AgentType
Attribute
AttributeFactory
CachePolicy
ChangeNotification
ChangeRecorder
Collection
CollectionColorAttribute
CollectionFetchScope
CollectionQuotaAttribute
CollectionStatistics
CollectionUtils
CollectionIdentificationAttribute
Control
DifferencesAlgorithmInterface
EntityAnnotationsAttribute
EntityDeletedAttribute
EntityDisplayAttribute
EntityHiddenAttribute
ExceptionBase
FavoriteCollectionAttribute
GidExtractorInterface
IndexPolicyAttribute
Item
ItemFetchScope
ItemMonitor
......@@ -116,22 +90,56 @@ ecm_generate_headers(AkonadiCore_base_HEADERS
NotificationSubscriber
Monitor
PartFetcher
PersistentSearchAttribute
Relation
SearchQuery
ServerManager
Session
SpecialCollections
SpecialCollectionAttribute
Supertrait
Tag
TagAttribute
TagFetchScope
TrashSettings
CollectionPathResolver
REQUIRED_HEADERS AkonadiCore_base_HEADERS
)
set(akonadicore_attributes_SRCS
attributes/attribute.cpp
attributes/collectioncolorattribute.cpp
attributes/collectionquotaattribute.cpp
attributes/collectionidentificationattribute.cpp
attributes/collectionrightsattribute.cpp
attributes/entityannotationsattribute.cpp
attributes/entitydeletedattribute.cpp
attributes/entitydeletedattribute.cpp
attributes/entitydisplayattribute.cpp
attributes/entityhiddenattribute.cpp
attributes/favoritecollectionattribute.cpp
attributes/indexpolicyattribute.cpp
attributes/persistentsearchattribute.cpp
attributes/specialcollectionattribute.cpp
attributes/tagattribute.cpp
)
ecm_generate_headers(AkonadiCore_attributes_HEADERS
HEADER_NAMES
Attribute
CollectionColorAttribute
CollectionIdentificationAttribute
CollectionQuotaAttribute
EntityAnnotationsAttribute
EntityDeletedAttribute
EntityDisplayAttribute
EntityHiddenAttribute
FavoriteCollectionAttribute
IndexPolicyAttribute
PersistentSearchAttribute
SpecialCollectionAttribute
TagAttribute
REQUIRED_HEADERS AkonadiCore_attributes_HEADERS
RELATIVE attributes
)
set(akonadicore_models_SRCS
models/agentfilterproxymodel.cpp
models/agentinstancemodel.cpp
......@@ -272,6 +280,7 @@ qt5_add_dbus_interfaces(akonadicore_dbus_SRCS
set(akonadicore_SRCS
${akonadicore_base_SRCS}
${akonadicore_attributes_SRCS}
${akonadicore_jobs_SRCS}
${akonadicore_models_SRCS}
${akonadicore_dbus_SRCS}
......@@ -291,7 +300,7 @@ generate_export_header(KF5AkonadiCore BASE_NAME akonadicore)
add_library(KF5::AkonadiCore ALIAS KF5AkonadiCore)
target_include_directories(KF5AkonadiCore INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF5}/AkonadiCore;${Boost_INCLUDE_DIR}>")
target_include_directories(KF5AkonadiCore PUBLIC "$<BUILD_INTERFACE:${Akonadi_SOURCE_DIR}/src/core;${Akonadi_BINARY_DIR}/src/core;${Akonadi_BINARY_DIR}/src/private>")
target_include_directories(KF5AkonadiCore PUBLIC "$<BUILD_INTERFACE:${Akonadi_BINARY_DIR};${Akonadi_SOURCE_DIR}/src/core/jobs;${Akonadi_SOURCE_DIR}/src/core/models>")
target_include_directories(KF5AkonadiCore PUBLIC "$<BUILD_INTERFACE:${Akonadi_BINARY_DIR};${Akonadi_SOURCE_DIR}/src/core/jobs;${Akonadi_SOURCE_DIR}/src/core/models;${Akonadi_SOURCE_DIR}/src/core/attributes>")
target_include_directories(KF5AkonadiCore PUBLIC "$<BUILD_INTERFACE:${Boost_INCLUDE_DIR}>")
kde_target_enable_exceptions(KF5AkonadiCore PUBLIC)
......@@ -331,6 +340,7 @@ install(TARGETS
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/akonadicore_export.h
${AkonadiCore_base_HEADERS}
${AkonadiCore_attributes_HEADERS}
${AkonadiCore_models_HEADERS}
${AkonadiCore_jobs_HEADERS}
${AkonadiCore_HEADERS}
......
......@@ -35,8 +35,7 @@ public:
explicit DefaultAttribute(const QByteArray &type, const QByteArray &value = QByteArray())
: mType(type)
, mValue(value)
{
}
{}
DefaultAttribute(const DefaultAttribute &) = delete;
DefaultAttribute &operator=(const DefaultAttribute &) = delete;
......@@ -45,6 +44,7 @@ public:
{
return mType;
}
Attribute *clone() const override
{
return new DefaultAttribute(mType, mValue);
......@@ -54,7 +54,9 @@ public:
{
return mValue;
}
void deserialize(const QByteArray &data) override {
void deserialize(const QByteArray &data) override
{
mValue = data;
}
......@@ -68,30 +70,25 @@ private:
class StaticAttributeFactory : public AttributeFactory
{
public:
StaticAttributeFactory()
: initialized(false)
{
}
void init()
{
if (initialized) {
return;
if (!initialized) {
initialized = true;
// Register built-in attributes
AttributeFactory::registerAttribute<CollectionQuotaAttribute>();
AttributeFactory::registerAttribute<CollectionRightsAttribute>();
AttributeFactory::registerAttribute<EntityDisplayAttribute>();
AttributeFactory::registerAttribute<EntityHiddenAttribute>();
AttributeFactory::registerAttribute<IndexPolicyAttribute>();
AttributeFactory::registerAttribute<PersistentSearchAttribute>();
AttributeFactory::registerAttribute<EntityDeletedAttribute>();
AttributeFactory::registerAttribute<EntityAnnotationsAttribute>();
AttributeFactory::registerAttribute<TagAttribute>();
AttributeFactory::registerAttribute<FavoriteCollectionAttribute>();
}
initialized = true;
// Register built-in attributes
AttributeFactory::registerAttribute<CollectionQuotaAttribute>();
AttributeFactory::registerAttribute<CollectionRightsAttribute>();
AttributeFactory::registerAttribute<EntityDisplayAttribute>();
AttributeFactory::registerAttribute<EntityHiddenAttribute>();
AttributeFactory::registerAttribute<IndexPolicyAttribute>();
AttributeFactory::registerAttribute<PersistentSearchAttribute>();
AttributeFactory::registerAttribute<EntityDeletedAttribute>();
AttributeFactory::registerAttribute<EntityAnnotationsAttribute>();
AttributeFactory::registerAttribute<TagAttribute>();
AttributeFactory::registerAttribute<FavoriteCollectionAttribute>();
}
bool initialized;
bool initialized = false;
};
Q_GLOBAL_STATIC(StaticAttributeFactory, s_attributeInstance) // NOLINT(readability-redundant-member-init)
......@@ -106,7 +103,7 @@ using Akonadi::Internal::s_attributeInstance;
class Q_DECL_HIDDEN AttributeFactory::Private
{
public:
QHash<QByteArray, Attribute *> attributes;
std::unordered_map<QByteArray, std::unique_ptr<Attribute>> attributes;
};
AttributeFactory *AttributeFactory::self()
......@@ -116,35 +113,31 @@ AttributeFactory *AttributeFactory::self()
}
AttributeFactory::AttributeFactory()
: d(new Private)
: d(std::make_unique<Private>())
{
}
AttributeFactory::~AttributeFactory()
{
qDeleteAll(d->attributes);
delete d;
}
AttributeFactory::~AttributeFactory() = default;
void AttributeFactory::registerAttribute(Attribute *attr)
void AttributeFactory::registerAttribute(std::unique_ptr<Attribute> attr)
{
Q_ASSERT(attr);
Q_ASSERT(!attr->type().contains(' ') && !attr->type().contains('\'') && !attr->type().contains('"'));
QHash<QByteArray, Attribute *>::Iterator it = d->attributes.find(attr->type());
auto it = d->attributes.find(attr->type());
if (it != d->attributes.end()) {
delete *it;
d->attributes.erase(it);
}
d->attributes.insert(attr->type(), attr);
d->attributes.emplace(attr->type(), std::move(attr));
}
Attribute *AttributeFactory::createAttribute(const QByteArray &type)
{
Attribute *attr = self()->d->attributes.value(type);
if (attr) {
return attr->clone();
auto attr = self()->d->attributes.find(type);
if (attr == self()->d->attributes.cend()) {
return new Internal::DefaultAttribute(type);
}
return new Internal::DefaultAttribute(type);
return attr->second->clone();
}
} // namespace Akonadi
......@@ -10,6 +10,8 @@
#include "akonadicore_export.h"
#include "attribute.h"
#include <memory>
namespace Akonadi
{
......@@ -47,7 +49,8 @@ public:
*/
template <typename T> inline static void registerAttribute()
{
AttributeFactory::self()->registerAttribute(new T);
static_assert(std::is_default_constructible<T>::value, "An Attribute must be default-constructible.");
AttributeFactory::self()->registerAttribute(std::make_unique<T>());
  • This change makes Akonadi's public API require C++14 support (due to std::make_unique only being available in C++14 mode).

    Intended? I just saw FatCRM (which sets CMAKE_CXX_STANDARD to 11) failing due to this line.

  • My bad, this was not intended. The public interface should remain C++11 compatible (for now). I'll fix it.

  • Fixed: a0d615cb

  • Can confirm this is fixing the FatCRM build in C++11 mode, thanks!

Please register or sign in to reply
}
/**
......@@ -60,18 +63,18 @@ public:
protected:
//@cond PRIVATE
AttributeFactory();
explicit AttributeFactory();
private:
Q_DISABLE_COPY(AttributeFactory)
static AttributeFactory *self();
void registerAttribute(Attribute *attribute);
void registerAttribute(std::unique_ptr<Attribute> attribute);
class Private;
Private *const d;
const std::unique_ptr<Private> d;
//@endcond
};
}
} // namespace Akonadi
#endif
......@@ -8,6 +8,4 @@
using namespace Akonadi;
Attribute::~Attribute()
{
}
Attribute::~Attribute() = default;
......@@ -165,6 +165,6 @@ protected:
Attribute(const Attribute &) = default;
};
}
} // namespace Akonadi
#endif
......@@ -5,7 +5,6 @@
*/
#include "collectioncolorattribute.h"
#include "attributefactory.h"
#include <QByteArray>
#include <QString>
......
......@@ -45,6 +45,6 @@ private:
QColor mColor;
};
}
} // namespace Akonadi
#endif
......@@ -16,9 +16,6 @@ using namespace Akonadi;
class Q_DECL_HIDDEN CollectionIdentificationAttribute::Private
{
public:
Private()
{
}
QByteArray mFolderNamespace;
QByteArray mIdentifier;
QByteArray mName;
......@@ -28,7 +25,7 @@ public:
CollectionIdentificationAttribute::CollectionIdentificationAttribute(const QByteArray &identifier, const QByteArray &folderNamespace,
const QByteArray &name, const QByteArray &organizationUnit, const QByteArray &mail)
: d(new Private)
: d(std::make_unique<Private>())
{
d->mIdentifier = identifier;
d->mFolderNamespace = folderNamespace;
......@@ -37,10 +34,7 @@ CollectionIdentificationAttribute::CollectionIdentificationAttribute(const QByte
d->mMail = mail;
}
CollectionIdentificationAttribute::~CollectionIdentificationAttribute()
{
delete d;
}
CollectionIdentificationAttribute::~CollectionIdentificationAttribute() = default;
void CollectionIdentificationAttribute::setIdentifier(const QByteArray &identifier)
{
......
......@@ -7,9 +7,11 @@
#ifndef COLLECTIONIDENTIFICATIONATTRIBUTE_H
#define COLLECTIONIDENTIFICATIONATTRIBUTE_H
#include <attribute.h>
#include "attribute.h"
#include <QByteArray>
#include <memory>
namespace Akonadi
{
......@@ -60,10 +62,10 @@ public:
private:
//@cond PRIVATE
class Private;
Private *const d;
const std::unique_ptr<Private> d;
//@endcond
};
}
} // namespace Akonadi
#endif
......@@ -13,30 +13,23 @@ using namespace Akonadi;
class Q_DECL_HIDDEN CollectionQuotaAttribute::Private
{
public:
Private(qint64 currentValue, qint64 maxValue)
: mCurrentValue(currentValue)
, mMaximumValue(maxValue)
{
}
qint64 mCurrentValue;
qint64 mMaximumValue;
qint64 mCurrentValue = -1;
qint64 mMaximumValue = -1;
};
CollectionQuotaAttribute::CollectionQuotaAttribute()
: d(new Private(-1, -1))
: d(std::make_unique<Private>())
{
}
CollectionQuotaAttribute::CollectionQuotaAttribute(qint64 currentValue, qint64 maxValue)
: d(new Private(currentValue, maxValue))
: d(std::make_unique<Private>())
{
d->mCurrentValue = currentValue;
d->mMaximumValue = maxValue;
}
CollectionQuotaAttribute::~CollectionQuotaAttribute()
{
delete d;
}
CollectionQuotaAttribute::~CollectionQuotaAttribute() = default;
void CollectionQuotaAttribute::setCurrentValue(qint64 value)
{
......@@ -60,8 +53,7 @@ qint64 CollectionQuotaAttribute::maximumValue() const
QByteArray CollectionQuotaAttribute::type() const
{
static const QByteArray sType("collectionquota");
return sType;
return QByteArrayLiteral("collectionquota");
}
Akonadi::Attribute *CollectionQuotaAttribute::clone() const
......
......@@ -10,6 +10,8 @@
#include "akonadicore_export.h"
#include "attribute.h"
#include <memory>
namespace Akonadi
{
......@@ -42,7 +44,7 @@ public:
/**
* Creates a new collection quota attribute.
*/
CollectionQuotaAttribute();
explicit CollectionQuotaAttribute();
/**
* Creates a new collection quota attribute with initial values.
......@@ -89,10 +91,10 @@ public:
private:
//@cond PRIVATE
class Private;
Private *const d;
const std::unique_ptr<Private> d;
//@endcond
};
}
} // namespace Akonadi
#endif
......@@ -97,14 +97,11 @@ public:
};
CollectionRightsAttribute::CollectionRightsAttribute()
: d(new Private)
: d(std::make_unique<Private>())
{
}
CollectionRightsAttribute::~CollectionRightsAttribute()
{
delete d;
}
CollectionRightsAttribute::~CollectionRightsAttribute() = default;
void CollectionRightsAttribute::setRights(Collection::Rights rights)
{
......
......@@ -12,6 +12,8 @@
#include "collection.h"
#include "attribute.h"
#include <memory>
namespace Akonadi
{
......@@ -63,10 +65,10 @@ public:
private:
//@cond PRIVATE
class Private;
Private *const d;
const std::unique_ptr<Private> d;
//@endcond
};
}
} // namespace Akonadi
#endif
......@@ -12,10 +12,6 @@
using namespace Akonadi;
EntityAnnotationsAttribute::EntityAnnotationsAttribute()
{
}
EntityAnnotationsAttribute::EntityAnnotationsAttribute(const QMap<QByteArray, QByteArray> &annotations)
: mAnnotations(annotations)
{
......
......@@ -32,8 +32,8 @@ namespace Akonadi
class AKONADICORE_EXPORT EntityAnnotationsAttribute : public Akonadi::Attribute
{
public:
EntityAnnotationsAttribute();
EntityAnnotationsAttribute(const QMap<QByteArray, QByteArray> &annotations);
explicit EntityAnnotationsAttribute() = default;
explicit EntityAnnotationsAttribute(const QMap<QByteArray, QByteArray> &annotations);
void setAnnotations(const QMap<QByteArray, QByteArray> &annotations);
QMap<QByteArray, QByteArray> annotations() const;
......@@ -51,6 +51,6 @@ private:
QMap<QByteArray, QByteArray> mAnnotations;
};
}
} // namespace Akonadi
#endif
......@@ -18,26 +18,20 @@ using namespace Akonadi;
class EntityDeletedAttribute::EntityDeletedAttributePrivate
{
public:
EntityDeletedAttributePrivate() {}
Collection restoreCollection;
QString restoreResource;
};
EntityDeletedAttribute::EntityDeletedAttribute()
: d_ptr(new EntityDeletedAttributePrivate())
: d(std::make_unique<EntityDeletedAttributePrivate>())
{
}
EntityDeletedAttribute::~EntityDeletedAttribute()
{
delete d_ptr;
}
EntityDeletedAttribute::~EntityDeletedAttribute() = default;
void EntityDeletedAttribute::setRestoreCollection(const Akonadi::Collection &collection)
{
Q_D(EntityDeletedAttribute);
if (!collection.isValid()) {
qCWarning(AKONADICORE_LOG) << "invalid collection" << collection;
}
......@@ -51,35 +45,29 @@ void EntityDeletedAttribute::setRestoreCollection(const Akonadi::Collection &col
Collection EntityDeletedAttribute::restoreCollection() const
{