Akonadi

agentthreadinstance.cpp
1 /*
2  SPDX-FileCopyrightText: 2010 Bertjan Broeksema <[email protected]>
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 
13 using namespace Akonadi;
14 
15 AgentThreadInstance::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 
22 bool 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 
45 void 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 
55 void 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 
66 void AgentThreadInstance::agentServerRegistered()
67 {
68  start(mAgentType);
69 }
70 
71 void 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 }
A representation of an agent type.
Q_SCRIPTABLE Q_NOREPLY void start()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Provides an interface to retrieve agent types and manage agent instances.
QDBusConnection sessionBus()
NETWORKMANAGERQT_EXPORT NetworkManager::Status status()
void serviceRegistered(const QString &serviceName)
QString identifier() const
Returns the unique identifier of the agent type.
A representation of an agent instance.
AKONADICORE_DEPRECATED void configure(QWidget *parent=nullptr)
Triggers the agent instance to show its configuration dialog.
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:00:31 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.