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 "agenttype.h"
10 #include "akonadicontrol_debug.h"
11 
12 #include <private/dbus_p.h>
13 
14 using namespace Akonadi;
15 
16 AgentThreadInstance::AgentThreadInstance(AgentManager &manager)
17  : AgentInstance(manager)
18  , mServiceWatcher(Akonadi::DBus::serviceName(Akonadi::DBus::AgentServer),
19  QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration)
20 {
22  this, &AgentThreadInstance::agentServerRegistered);
23 }
24 
25 bool AgentThreadInstance::start(const AgentType &agentInfo)
26 {
27  Q_ASSERT(!identifier().isEmpty());
28  if (identifier().isEmpty()) {
29  return false;
30  }
31 
32  setAgentType(agentInfo.identifier);
33  mAgentType = agentInfo;
34 
35  org::freedesktop::Akonadi::AgentServer agentServer(Akonadi::DBus::serviceName(Akonadi::DBus::AgentServer),
36  QStringLiteral("/AgentServer"), QDBusConnection::sessionBus());
37  if (!agentServer.isValid()) {
38  qCDebug(AKONADICONTROL_LOG) << "AgentServer not up (yet?)";
39  return false;
40  }
41 
42  // TODO: let startAgent return a bool.
43  agentServer.startAgent(identifier(), agentInfo.identifier, agentInfo.exec);
44  return true;
45 }
46 
47 void AgentThreadInstance::quit()
48 {
49  AgentInstance::quit();
50 
51  org::freedesktop::Akonadi::AgentServer agentServer(Akonadi::DBus::serviceName(Akonadi::DBus::AgentServer),
52  QStringLiteral("/AgentServer"), QDBusConnection::sessionBus());
53  agentServer.stopAgent(identifier());
54 }
55 
56 void AgentThreadInstance::restartWhenIdle()
57 {
58  if (status() != 1 && !identifier().isEmpty()) {
59  org::freedesktop::Akonadi::AgentServer agentServer(Akonadi::DBus::serviceName(Akonadi::DBus::AgentServer),
60  QStringLiteral("/AgentServer"), QDBusConnection::sessionBus());
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"), QDBusConnection::sessionBus());
75  agentServer.agentInstanceConfigure(identifier(), windowId);
76 }
void serviceRegistered(const QString &serviceName)
Provides an interface to retrieve agent types and manage agent instances.
QDBusConnection sessionBus()
QString identifier() const
Returns the unique identifier of the agent type.
void start(QThread::Priority priority)
A representation of an agent type.
AKONADICORE_DEPRECATED void configure(QWidget *parent=nullptr)
Triggers the agent instance to show its configuration dialog.
Helper integration between Akonadi and Qt.
A representation of an agent instance.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Jul 12 2020 23:16:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.