Pimcommon

imapresourcecapabilitiesmanager.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "imapresourcecapabilitiesmanager.h"
8using namespace Qt::Literals::StringLiterals;
9
10#include "pimcommonakonadi_debug.h"
11#include "util/pimutil.h"
12
13#include <Akonadi/AgentManager>
14#include <Akonadi/ServerManager>
15
16#include <QDBusConnection>
17#include <QDBusInterface>
18#include <QDBusPendingCall>
19#include <QDBusPendingReply>
20
21using namespace PimCommon;
22ImapResourceCapabilitiesManager::ImapResourceCapabilitiesManager(QObject *parent)
23 : QObject(parent)
24{
25 init();
26}
27
28ImapResourceCapabilitiesManager::~ImapResourceCapabilitiesManager() = default;
29
30void ImapResourceCapabilitiesManager::slotInstanceAdded(const Akonadi::AgentInstance &instance)
31{
32 searchCapabilities(instance.identifier());
33}
34
35void ImapResourceCapabilitiesManager::slotInstanceRemoved(const Akonadi::AgentInstance &instance)
36{
37 mImapResource.remove(instance.identifier());
38}
39
40void ImapResourceCapabilitiesManager::searchCapabilities(const QString &identifier)
41{
42 // By default makes it as true.
43 mImapResource.insert(identifier, true);
44 const QString service = Akonadi::ServerManager::agentServiceName(Akonadi::ServerManager::Resource, identifier);
45 QDBusInterface iface(service, QStringLiteral("/"), QStringLiteral("org.kde.Akonadi.ImapResourceBase"), QDBusConnection::sessionBus(), this);
46
47 if (iface.isValid()) {
48 QDBusPendingCall call = iface.asyncCall(QStringLiteral("serverCapabilities"));
49 auto watcher = new QDBusPendingCallWatcher(call, this);
50 watcher->setProperty("identifier", identifier);
51 connect(watcher, &QDBusPendingCallWatcher::finished, this, &ImapResourceCapabilitiesManager::slotCapabilities);
52 } else {
53 qCDebug(PIMCOMMONAKONADI_LOG) << "interface not valid";
54 }
55}
56
57void ImapResourceCapabilitiesManager::slotCapabilities(QDBusPendingCallWatcher *watcher)
58{
59 QDBusPendingReply<QStringList> reply = *watcher;
60 if (reply.isValid()) {
61 if (watcher->property("identifier").isValid()) {
62 const QStringList capabilities = reply.value();
63 mImapResource.insert(watcher->property("identifier").toString(), capabilities.contains("ANNOTATEMORE"_L1));
64 }
65 }
66 watcher->deleteLater();
67 watcher = nullptr;
68}
69
70void ImapResourceCapabilitiesManager::init()
71{
73 for (const Akonadi::AgentInstance &instance : lstInstances) {
74 const QString identifier = instance.identifier();
75 if (PimCommon::Util::isImapResource(identifier)) {
76 searchCapabilities(identifier);
77 }
78 }
79 connect(Akonadi::AgentManager::self(), &Akonadi::AgentManager::instanceAdded, this, &ImapResourceCapabilitiesManager::slotInstanceAdded);
80 connect(Akonadi::AgentManager::self(), &Akonadi::AgentManager::instanceRemoved, this, &ImapResourceCapabilitiesManager::slotInstanceRemoved);
81}
82
83bool ImapResourceCapabilitiesManager::hasAnnotationSupport(const QString &identifier) const
84{
85 if (!PimCommon::Util::isImapResource(identifier)) {
86 return false;
87 }
88 return mImapResource.value(identifier, true);
89}
90
91#include "moc_imapresourcecapabilitiesmanager.cpp"
QString identifier() const
static AgentManager * self()
void instanceRemoved(const Akonadi::AgentInstance &instance)
void instanceAdded(const Akonadi::AgentInstance &instance)
AgentInstance::List instances() const
static QString agentServiceName(ServiceAgentType agentType, const QString &identifier)
Capabilities capabilities()
folderdialogacltab.h
QCA_EXPORT void init()
QDBusConnection sessionBus()
void finished(QDBusPendingCallWatcher *self)
bool isValid() const const
typename Select< 0 >::Type value() const const
iterator insert(const Key &key, const T &value)
bool remove(const Key &key)
T value(const Key &key) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
QVariant property(const char *name) const const
bool isValid() const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.