Akonadi

agentthreadinstance.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#include "agentthreadinstance.h"
7
8#include "agentserverinterface.h"
9#include "akonadicontrol_debug.h"
10
11#include "private/dbus_p.h"
12
13using namespace Akonadi;
14
15AgentThreadInstance::AgentThreadInstance(AgentManager &manager)
16 : AgentInstance(manager)
17 , mServiceWatcher(Akonadi::DBus::serviceName(Akonadi::DBus::AgentServer), QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration)
18{
19 connect(&mServiceWatcher, &QDBusServiceWatcher::serviceRegistered, this, &AgentThreadInstance::agentServerRegistered);
20}
21
22bool AgentThreadInstance::start(const AgentType &agentInfo)
23{
24 Q_ASSERT(!identifier().isEmpty());
25 if (identifier().isEmpty()) {
26 return false;
27 }
28
29 setAgentType(agentInfo.identifier);
30 mAgentType = agentInfo;
31
32 org::freedesktop::Akonadi::AgentServer agentServer(Akonadi::DBus::serviceName(Akonadi::DBus::AgentServer),
33 QStringLiteral("/AgentServer"),
35 if (!agentServer.isValid()) {
36 qCDebug(AKONADICONTROL_LOG) << "AgentServer not up (yet?)";
37 return false;
38 }
39
40 // TODO: let startAgent return a bool.
41 agentServer.startAgent(identifier(), agentInfo.identifier, agentInfo.exec);
42 return true;
43}
44
45void AgentThreadInstance::quit()
46{
47 AgentInstance::quit();
48
49 org::freedesktop::Akonadi::AgentServer agentServer(Akonadi::DBus::serviceName(Akonadi::DBus::AgentServer),
50 QStringLiteral("/AgentServer"),
52 agentServer.stopAgent(identifier());
53}
54
55void AgentThreadInstance::restartWhenIdle()
56{
57 if (status() != 1 && !identifier().isEmpty()) {
58 org::freedesktop::Akonadi::AgentServer agentServer(Akonadi::DBus::serviceName(Akonadi::DBus::AgentServer),
59 QStringLiteral("/AgentServer"),
61 agentServer.stopAgent(identifier());
62 agentServer.startAgent(identifier(), agentType(), mAgentType.exec);
63 }
64}
65
66void AgentThreadInstance::agentServerRegistered()
67{
68 start(mAgentType);
69}
70
71void Akonadi::AgentThreadInstance::configure(qlonglong windowId)
72{
73 org::freedesktop::Akonadi::AgentServer agentServer(Akonadi::DBus::serviceName(Akonadi::DBus::AgentServer),
74 QStringLiteral("/AgentServer"),
76 agentServer.agentInstanceConfigure(identifier(), windowId);
77}
78
79#include "moc_agentthreadinstance.cpp"
Represents one agent instance and takes care of communication with it.
The agent manager has knowledge about all available agents (it scans for .desktop files in the agent ...
Status status() const
Returns the status of the agent instance.
QString identifier() const
Returns the unique identifier of the agent instance.
Q_SCRIPTABLE Q_NOREPLY void start()
Helper integration between Akonadi and Qt.
QDBusConnection sessionBus()
void serviceRegistered(const QString &serviceName)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
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.