Akonadi

agentprocessinstance.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Volker Krause <[email protected]>
3  SPDX-FileCopyrightText: 2010 Bertjan Broeksema <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 #include "agentprocessinstance.h"
8 
9 #include "agenttype.h"
10 #include "akonadicontrol_debug.h"
11 #include "private/standarddirs_p.h"
12 #include "processcontrol.h"
13 
14 #include <QStandardPaths>
15 
16 using namespace Akonadi;
17 
18 AgentProcessInstance::AgentProcessInstance(AgentManager &manager)
19  : AgentInstance(manager)
20 {
21 }
22 
23 bool AgentProcessInstance::start(const AgentType &agentInfo)
24 {
25  Q_ASSERT(!identifier().isEmpty());
26  if (identifier().isEmpty()) {
27  return false;
28  }
29 
30  setAgentType(agentInfo.identifier);
31 
32  Q_ASSERT(agentInfo.launchMethod == AgentType::Process || agentInfo.launchMethod == AgentType::Launcher);
33 
34  const QString executable = (agentInfo.launchMethod == AgentType::Process) ? Akonadi::StandardDirs::findExecutable(agentInfo.exec) : agentInfo.exec;
35 
36  if (executable.isEmpty()) {
37  qCWarning(AKONADICONTROL_LOG) << "Unable to find agent executable" << agentInfo.exec;
38  return false;
39  }
40 
41  mController = std::make_unique<Akonadi::ProcessControl>();
42  connect(mController.get(), &ProcessControl::unableToStart, this, &AgentProcessInstance::failedToStart);
43 
44  if (agentInfo.launchMethod == AgentType::Process) {
45  const QStringList arguments = {QStringLiteral("--identifier"), identifier()};
46  mController->start(executable, arguments);
47  } else {
48  Q_ASSERT(agentInfo.launchMethod == AgentType::Launcher);
49  const QStringList arguments = QStringList() << executable << identifier();
50  const QString agentLauncherExec = Akonadi::StandardDirs::findExecutable(QStringLiteral("akonadi_agent_launcher"));
51  mController->start(agentLauncherExec, arguments);
52  }
53  return true;
54 }
55 
56 void AgentProcessInstance::quit()
57 {
58  mController->setCrashPolicy(Akonadi::ProcessControl::StopOnCrash);
59  AgentInstance::quit();
60 }
61 
62 void AgentProcessInstance::cleanup()
63 {
64  mController->setCrashPolicy(Akonadi::ProcessControl::StopOnCrash);
65  AgentInstance::cleanup();
66 }
67 
68 void AgentProcessInstance::restartWhenIdle()
69 {
70  if (mController->isRunning()) {
71  if (status() != 1) {
72  mController->restartOnceWhenFinished();
73  quit();
74  }
75  } else {
76  mController->start();
77  }
78 }
79 
80 void Akonadi::AgentProcessInstance::configure(qlonglong windowId)
81 {
82  controlInterface()->configure(windowId);
83 }
84 
85 void AgentProcessInstance::failedToStart()
86 {
87  statusChanged(2 /*Broken*/, QStringLiteral("Unable to start."));
88 }
A representation of an agent type.
Q_SCRIPTABLE Q_NOREPLY void start()
void unableToStart()
Emitted if the process could not be started since it terminated too often.
Provides an interface to retrieve agent types and manage agent instances.
bool isEmpty() const const
NETWORKMANAGERQT_EXPORT NetworkManager::Status status()
const QList< QKeySequence > & quit()
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 Mon Jun 27 2022 04:01:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.