Akonadi

resourcemanager.cpp
1 /*
2  SPDX-FileCopyrightText: 2006 Volker Krause <[email protected]>
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 
18 using namespace Akonadi::Server;
19 using namespace AkRanges;
20 
21 ResourceManager::ResourceManager(Tracer &tracer)
22  : mTracer(tracer)
23 {
24  new ResourceManagerAdaptor(this);
25  QDBusConnection::sessionBus().registerObject(QStringLiteral("/ResourceManager"), this);
26 }
27 
28 void 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(QLatin1String(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 
46 void 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) {
52  DataStore::self()->cleanupCollection(col);
53  });
54 
55  // remove resource
56  resource.remove();
57  }
58 }
59 
60 QStringList ResourceManager::resourceInstances() const
61 {
62  return Resource::retrieveAll() | Views::transform(&Resource::name) | Actions::toQList;
63 }
Helper class for DataStore transaction handling.
Definition: transaction.h:22
The global tracer instance where all akonadi components can send their tracing information to.
Definition: tracer.h:37
bool registerObject(const QString &path, QObject *object, QDBusConnection::RegisterOptions options)
QDBusConnection sessionBus()
QString name() const
void setName(QString value)
Capabilities capabilities()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.