From e8ab53258c044969146be385629a80afe801dee5 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 22 Dec 2015 16:35:09 +0100 Subject: Turn operations of resources into a special case. Resources don't live inside a resource context, and as such inherently are a special case. By also removing the option to manually specify the identifier, the commandline is a lot easier to use. --- common/resourceconfig.cpp | 9 +++++++++ common/resourceconfig.h | 1 + common/resourcefacade.cpp | 8 ++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/resourceconfig.cpp b/common/resourceconfig.cpp index 3554b76..a0f39a8 100644 --- a/common/resourceconfig.cpp +++ b/common/resourceconfig.cpp @@ -33,6 +33,15 @@ static QSharedPointer getResourceConfig(const QByteArray &identifier) return QSharedPointer::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/" + identifier, QSettings::IniFormat); } +QByteArray ResourceConfig::newIdentifier(const QByteArray &type) +{ + auto settings = getSettings(); + const auto counter = settings->value("instanceCounter", 0).toInt() + 1; + const QByteArray identifier = type + ".instance" + QByteArray::number(counter); + settings->setValue("instanceCounter", counter); + settings->sync(); + return identifier; +} void ResourceConfig::addResource(const QByteArray &identifier, const QByteArray &type) { diff --git a/common/resourceconfig.h b/common/resourceconfig.h index fec9f56..cc9cb94 100644 --- a/common/resourceconfig.h +++ b/common/resourceconfig.h @@ -28,6 +28,7 @@ class ResourceConfig { public: static QMap getResources(); + static QByteArray newIdentifier(const QByteArray &type); static void addResource(const QByteArray &identifier, const QByteArray &type); static void removeResource(const QByteArray &identifier); static void clear(); diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 367704a..df52538 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp @@ -20,6 +20,9 @@ #include "resourceconfig.h" #include "query.h" +#include "definitions.h" +#include "storage.h" +#include ResourceFacade::ResourceFacade(const QByteArray &) : Akonadi2::StoreFacade() @@ -35,8 +38,9 @@ ResourceFacade::~ResourceFacade() KAsync::Job ResourceFacade::create(const Akonadi2::ApplicationDomain::AkonadiResource &resource) { return KAsync::start([resource, this]() { - const QByteArray identifier = resource.getProperty("identifier").toByteArray(); const QByteArray type = resource.getProperty("type").toByteArray(); + //It is currently a requirement that the resource starts with the type + const QByteArray identifier = ResourceConfig::newIdentifier(type); ResourceConfig::addResource(identifier, type); auto changedProperties = resource.changedProperties(); changedProperties.removeOne("identifier"); @@ -57,7 +61,7 @@ KAsync::Job ResourceFacade::modify(const Akonadi2::ApplicationDomain::Akon return KAsync::start([resource, this]() { const QByteArray identifier = resource.identifier(); if (identifier.isEmpty()) { - Warning() << "We need an \"identifier\" property to identify the resource to configure"; + Warning() << "We need an \"identifier\" property to identify the resource to configure."; return; } auto changedProperties = resource.changedProperties(); -- cgit v1.2.3