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 ...@@ -8,7 +8,6 @@ set(akonadicore_base_SRCS
agentmanager.cpp agentmanager.cpp
agenttype.cpp agenttype.cpp
asyncselectionhandler.cpp asyncselectionhandler.cpp
attribute.cpp
attributefactory.cpp attributefactory.cpp
attributestorage.cpp attributestorage.cpp
braveheart.cpp braveheart.cpp
...@@ -21,28 +20,16 @@ set(akonadicore_base_SRCS ...@@ -21,28 +20,16 @@ set(akonadicore_base_SRCS
changerecorderjournal.cpp changerecorderjournal.cpp
connection.cpp connection.cpp
collection.cpp collection.cpp
collectioncolorattribute.cpp
collectionfetchscope.cpp collectionfetchscope.cpp
collectionpathresolver.cpp collectionpathresolver.cpp
collectionquotaattribute.cpp
collectionquotaattribute.cpp
collectionrightsattribute.cpp
collectionstatistics.cpp collectionstatistics.cpp
collectionsync.cpp collectionsync.cpp
conflicthandler.cpp conflicthandler.cpp
collectionidentificationattribute.cpp
control.cpp control.cpp
entityannotationsattribute.cpp
entitycache.cpp entitycache.cpp
entitydeletedattribute.cpp
entitydeletedattribute.cpp
entitydisplayattribute.cpp
entityhiddenattribute.cpp
exception.cpp exception.cpp
favoritecollectionattribute.cpp
firstrun.cpp firstrun.cpp
gidextractor.cpp gidextractor.cpp
indexpolicyattribute.cpp
item.cpp item.cpp
itemchangelog.cpp itemchangelog.cpp
itemfetchscope.cpp itemfetchscope.cpp
...@@ -57,7 +44,6 @@ set(akonadicore_base_SRCS ...@@ -57,7 +44,6 @@ set(akonadicore_base_SRCS
notificationsubscriber.cpp notificationsubscriber.cpp
partfetcher.cpp partfetcher.cpp
pastehelper.cpp pastehelper.cpp
persistentsearchattribute.cpp
pluginloader.cpp pluginloader.cpp
protocolhelper.cpp protocolhelper.cpp
remotelog.cpp remotelog.cpp
...@@ -67,10 +53,8 @@ set(akonadicore_base_SRCS ...@@ -67,10 +53,8 @@ set(akonadicore_base_SRCS
servermanager.cpp servermanager.cpp
session.cpp session.cpp
sessionthread.cpp sessionthread.cpp
specialcollectionattribute.cpp
specialcollections.cpp specialcollections.cpp
tag.cpp tag.cpp
tagattribute.cpp
tagfetchscope.cpp tagfetchscope.cpp
tagsync.cpp tagsync.cpp
trashsettings.cpp trashsettings.cpp
...@@ -85,28 +69,18 @@ ecm_generate_headers(AkonadiCore_base_HEADERS ...@@ -85,28 +69,18 @@ ecm_generate_headers(AkonadiCore_base_HEADERS
AgentInstance AgentInstance
AgentManager AgentManager
AgentType AgentType
Attribute
AttributeFactory AttributeFactory
CachePolicy CachePolicy
ChangeNotification ChangeNotification
ChangeRecorder ChangeRecorder
Collection Collection
CollectionColorAttribute
CollectionFetchScope CollectionFetchScope
CollectionQuotaAttribute
CollectionStatistics CollectionStatistics
CollectionUtils CollectionUtils
CollectionIdentificationAttribute
Control Control
DifferencesAlgorithmInterface DifferencesAlgorithmInterface
EntityAnnotationsAttribute
EntityDeletedAttribute
EntityDisplayAttribute
EntityHiddenAttribute
ExceptionBase ExceptionBase
FavoriteCollectionAttribute
GidExtractorInterface GidExtractorInterface
IndexPolicyAttribute
Item Item
ItemFetchScope ItemFetchScope
ItemMonitor ItemMonitor
...@@ -116,22 +90,56 @@ ecm_generate_headers(AkonadiCore_base_HEADERS ...@@ -116,22 +90,56 @@ ecm_generate_headers(AkonadiCore_base_HEADERS
NotificationSubscriber NotificationSubscriber
Monitor Monitor
PartFetcher PartFetcher
PersistentSearchAttribute
Relation Relation
SearchQuery SearchQuery
ServerManager ServerManager
Session Session
SpecialCollections SpecialCollections
SpecialCollectionAttribute
Supertrait Supertrait
Tag Tag
TagAttribute
TagFetchScope TagFetchScope
TrashSettings TrashSettings
CollectionPathResolver CollectionPathResolver
REQUIRED_HEADERS AkonadiCore_base_HEADERS 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 set(akonadicore_models_SRCS
models/agentfilterproxymodel.cpp models/agentfilterproxymodel.cpp
models/agentinstancemodel.cpp models/agentinstancemodel.cpp
...@@ -272,6 +280,7 @@ qt5_add_dbus_interfaces(akonadicore_dbus_SRCS ...@@ -272,6 +280,7 @@ qt5_add_dbus_interfaces(akonadicore_dbus_SRCS
set(akonadicore_SRCS set(akonadicore_SRCS
${akonadicore_base_SRCS} ${akonadicore_base_SRCS}
${akonadicore_attributes_SRCS}
${akonadicore_jobs_SRCS} ${akonadicore_jobs_SRCS}
${akonadicore_models_SRCS} ${akonadicore_models_SRCS}
${akonadicore_dbus_SRCS} ${akonadicore_dbus_SRCS}
...@@ -291,7 +300,7 @@ generate_export_header(KF5AkonadiCore BASE_NAME akonadicore) ...@@ -291,7 +300,7 @@ generate_export_header(KF5AkonadiCore BASE_NAME akonadicore)
add_library(KF5::AkonadiCore ALIAS KF5AkonadiCore) 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 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_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}>") target_include_directories(KF5AkonadiCore PUBLIC "$<BUILD_INTERFACE:${Boost_INCLUDE_DIR}>")
kde_target_enable_exceptions(KF5AkonadiCore PUBLIC) kde_target_enable_exceptions(KF5AkonadiCore PUBLIC)
...@@ -331,6 +340,7 @@ install(TARGETS ...@@ -331,6 +340,7 @@ install(TARGETS
install(FILES install(FILES
${CMAKE_CURRENT_BINARY_DIR}/akonadicore_export.h ${CMAKE_CURRENT_BINARY_DIR}/akonadicore_export.h
${AkonadiCore_base_HEADERS} ${AkonadiCore_base_HEADERS}
${AkonadiCore_attributes_HEADERS}
${AkonadiCore_models_HEADERS} ${AkonadiCore_models_HEADERS}
${AkonadiCore_jobs_HEADERS} ${AkonadiCore_jobs_HEADERS}
${AkonadiCore_HEADERS} ${AkonadiCore_HEADERS}
......
...@@ -35,8 +35,7 @@ public: ...@@ -35,8 +35,7 @@ public:
explicit DefaultAttribute(const QByteArray &type, const QByteArray &value = QByteArray()) explicit DefaultAttribute(const QByteArray &type, const QByteArray &value = QByteArray())
: mType(type) : mType(type)
, mValue(value) , mValue(value)
{ {}
}
DefaultAttribute(const DefaultAttribute &) = delete; DefaultAttribute(const DefaultAttribute &) = delete;
DefaultAttribute &operator=(const DefaultAttribute &) = delete; DefaultAttribute &operator=(const DefaultAttribute &) = delete;
...@@ -45,6 +44,7 @@ public: ...@@ -45,6 +44,7 @@ public:
{ {
return mType; return mType;
} }
Attribute *clone() const override Attribute *clone() const override
{ {
return new DefaultAttribute(mType, mValue); return new DefaultAttribute(mType, mValue);
...@@ -54,7 +54,9 @@ public: ...@@ -54,7 +54,9 @@ public:
{ {
return mValue; return mValue;
} }
void deserialize(const QByteArray &data) override {
void deserialize(const QByteArray &data) override
{
mValue = data; mValue = data;
} }
...@@ -68,30 +70,25 @@ private: ...@@ -68,30 +70,25 @@ private:
class StaticAttributeFactory : public AttributeFactory class StaticAttributeFactory : public AttributeFactory
{ {
public: public:
StaticAttributeFactory()
: initialized(false)
{
}
void init() void init()
{ {
if (initialized) { if (!initialized) {
return; 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) Q_GLOBAL_STATIC(StaticAttributeFactory, s_attributeInstance) // NOLINT(readability-redundant-member-init)
...@@ -106,7 +103,7 @@ using Akonadi::Internal::s_attributeInstance; ...@@ -106,7 +103,7 @@ using Akonadi::Internal::s_attributeInstance;
class Q_DECL_HIDDEN AttributeFactory::Private class Q_DECL_HIDDEN AttributeFactory::Private
{ {
public: public:
QHash<QByteArray, Attribute *> attributes; std::unordered_map<QByteArray, std::unique_ptr<Attribute>> attributes;
}; };
AttributeFactory *AttributeFactory::self() AttributeFactory *AttributeFactory::self()
...@@ -116,35 +113,31 @@ AttributeFactory *AttributeFactory::self() ...@@ -116,35 +113,31 @@ AttributeFactory *AttributeFactory::self()
} }
AttributeFactory::AttributeFactory() AttributeFactory::AttributeFactory()
: d(new Private) : d(std::make_unique<Private>())
{ {
} }
AttributeFactory::~AttributeFactory() AttributeFactory::~AttributeFactory() = default;
{
qDeleteAll(d->attributes);
delete d;
}
void AttributeFactory::registerAttribute(Attribute *attr) void AttributeFactory::registerAttribute(std::unique_ptr<Attribute> attr)
{ {
Q_ASSERT(attr); Q_ASSERT(attr);
Q_ASSERT(!attr->type().contains(' ') && !attr->type().contains('\'') && !attr->type().contains('"')); 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()) { if (it != d->attributes.end()) {
delete *it;
d->attributes.erase(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 *AttributeFactory::createAttribute(const QByteArray &type)
{ {
Attribute *attr = self()->d->attributes.value(type); auto attr = self()->d->attributes.find(type);
if (attr) { if (attr == self()->d->attributes.cend()) {
return attr->clone(); return new Internal::DefaultAttribute(type);
} }
return new Internal::DefaultAttribute(type);
return attr->second->clone();
} }
} // namespace Akonadi } // namespace Akonadi
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "akonadicore_export.h" #include "akonadicore_export.h"
#include "attribute.h" #include "attribute.h"
#include <memory>
namespace Akonadi namespace Akonadi
{ {
...@@ -47,7 +49,8 @@ public: ...@@ -47,7 +49,8 @@ public:
*/ */
template <typename T> inline static void registerAttribute() 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: ...@@ -60,18 +63,18 @@ public:
protected: protected:
//@cond PRIVATE //@cond PRIVATE
AttributeFactory(); explicit AttributeFactory();
private: private:
Q_DISABLE_COPY(AttributeFactory) Q_DISABLE_COPY(AttributeFactory)
static AttributeFactory *self(); static AttributeFactory *self();
void registerAttribute(Attribute *attribute); void registerAttribute(std::unique_ptr<Attribute> attribute);
class Private; class Private;
Private *const d; const std::unique_ptr<Private> d;
//@endcond //@endcond
}; };
} } // namespace Akonadi
#endif #endif
...@@ -8,6 +8,4 @@ ...@@ -8,6 +8,4 @@
using namespace Akonadi; using namespace Akonadi;
Attribute::~Attribute() Attribute::~Attribute() = default;
{
}
...@@ -165,6 +165,6 @@ protected: ...@@ -165,6 +165,6 @@ protected:
Attribute(const Attribute &) = default; Attribute(const Attribute &) = default;
}; };
} } // namespace Akonadi
#endif #endif
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
*/ */
#include "collectioncolorattribute.h" #include "collectioncolorattribute.h"
#include "attributefactory.h"
#include <QByteArray> #include <QByteArray>
#include <QString> #include <QString>
......
...@@ -45,6 +45,6 @@ private: ...@@ -45,6 +45,6 @@ private:
QColor mColor; QColor mColor;
}; };
} } // namespace Akonadi
#endif #endif
...@@ -16,9 +16,6 @@ using namespace Akonadi; ...@@ -16,9 +16,6 @@ using namespace Akonadi;
class Q_DECL_HIDDEN CollectionIdentificationAttribute::Private class Q_DECL_HIDDEN CollectionIdentificationAttribute::Private
{ {
public: public:
Private()
{
}
QByteArray mFolderNamespace; QByteArray mFolderNamespace;
QByteArray mIdentifier; QByteArray mIdentifier;
QByteArray mName; QByteArray mName;
...@@ -28,7 +25,7 @@ public: ...@@ -28,7 +25,7 @@ public:
CollectionIdentificationAttribute::CollectionIdentificationAttribute(const QByteArray &identifier, const QByteArray &folderNamespace, CollectionIdentificationAttribute::CollectionIdentificationAttribute(const QByteArray &identifier, const QByteArray &folderNamespace,
const QByteArray &name, const QByteArray &organizationUnit, const QByteArray &mail) const QByteArray &name, const QByteArray &organizationUnit, const QByteArray &mail)
: d(new Private) : d(std::make_unique<Private>())
{ {
d->mIdentifier = identifier; d->mIdentifier = identifier;
d->mFolderNamespace = folderNamespace; d->mFolderNamespace = folderNamespace;
...@@ -37,10 +34,7 @@ CollectionIdentificationAttribute::CollectionIdentificationAttribute(const QByte ...@@ -37,10 +34,7 @@ CollectionIdentificationAttribute::CollectionIdentificationAttribute(const QByte
d->mMail = mail; d->mMail = mail;
} }
CollectionIdentificationAttribute::~CollectionIdentificationAttribute() CollectionIdentificationAttribute::~CollectionIdentificationAttribute() = default;
{
delete d;
}
void CollectionIdentificationAttribute::setIdentifier(const QByteArray &identifier) void CollectionIdentificationAttribute::setIdentifier(const QByteArray &identifier)
{ {
......
...@@ -7,9 +7,11 @@ ...@@ -7,9 +7,11 @@
#ifndef COLLECTIONIDENTIFICATIONATTRIBUTE_H #ifndef COLLECTIONIDENTIFICATIONATTRIBUTE_H
#define COLLECTIONIDENTIFICATIONATTRIBUTE_H #define COLLECTIONIDENTIFICATIONATTRIBUTE_H
#include <attribute.h> #include "attribute.h"
#include <QByteArray> #include <QByteArray>
#include <memory>
namespace Akonadi namespace Akonadi
{ {
...@@ -60,10 +62,10 @@ public: ...@@ -60,10 +62,10 @@ public:
private: private:
//@cond PRIVATE //@cond PRIVATE
class Private; class Private;
Private *const d; const std::unique_ptr<Private> d;
//@endcond //@endcond
}; };
} } // namespace Akonadi
#endif #endif
...@@ -13,30 +13,23 @@ using namespace Akonadi; ...@@ -13,30 +13,23 @@ using namespace Akonadi;
class Q_DECL_HIDDEN CollectionQuotaAttribute::Private class Q_DECL_HIDDEN CollectionQuotaAttribute::Private
{ {
public: public:
Private(qint64 currentValue, qint64 maxValue) qint64 mCurrentValue = -1;
: mCurrentValue(currentValue)