Akonadi

resourcemanager.cpp
1/*
2 SPDX-FileCopyrightText: 2006 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "resourcemanager.h"
8#include "resourcemanageradaptor.h"
9#include "storage/datastore.h"
10#include "storage/transaction.h"
11#include "tracer.h"
12
13#include "private/capabilities_p.h"
14#include "shared/akranges.h"
15
16#include <QDBusConnection>
17
18using namespace Akonadi::Server;
19using namespace AkRanges;
20
21ResourceManager::ResourceManager(Tracer &tracer)
22 : mTracer(tracer)
23{
24 new ResourceManagerAdaptor(this);
25 QDBusConnection::sessionBus().registerObject(QStringLiteral("/ResourceManager"), this);
26}
27
28void ResourceManager::addResourceInstance(const QString &name, const QStringList &capabilities)
29{
30 Transaction transaction(DataStore::self(), QStringLiteral("ADD RESOURCE INSTANCE"));
31 Resource resource = Resource::retrieveByName(name);
32 if (resource.isValid()) {
33 mTracer.error("ResourceManager", QStringLiteral("Resource '%1' already exists.").arg(name));
34 return; // resource already exists
35 }
36
37 // create the resource
38 resource.setName(name);
39 resource.setIsVirtual(capabilities.contains(QLatin1StringView(AKONADI_AGENT_CAPABILITY_VIRTUAL)));
40 if (!resource.insert()) {
41 mTracer.error("ResourceManager", QStringLiteral("Could not create resource '%1'.").arg(name));
42 }
43 transaction.commit();
44}
45
46void ResourceManager::removeResourceInstance(const QString &name)
47{
48 // remove items and collections
49 Resource resource = Resource::retrieveByName(name);
50 if (resource.isValid()) {
51 resource.collections() | Actions::forEach([](Collection col) {
53 });
54
55 // remove resource
56 resource.remove();
57 }
58}
59
60QStringList ResourceManager::resourceInstances() const
61{
62 return Resource::retrieveAll() | Views::transform(&Resource::name) | Actions::toQList;
63}
64
65#include "moc_resourcemanager.cpp"
Represents a collection of PIM items.
Definition collection.h:62
virtual bool cleanupCollection(Collection &collection)
removes the given collection and all its content
static DataStore * self()
Per thread singleton.
The global tracer instance where all akonadi components can send their tracing information to.
Definition tracer.h:38
void error(const QString &componentName, const QString &msg) override
This method is called whenever a component wants to output an error.
Definition tracer.cpp:125
Helper class for DataStore transaction handling.
Definition transaction.h:23
QString name() const
void setName(QString value)
Capabilities capabilities()
bool registerObject(const QString &path, QObject *object, RegisterOptions options)
QDBusConnection sessionBus()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.