Akonadi

agentprocessinstance.cpp
1 /*
2  Copyright (c) 2008 Volker Krause <[email protected]>
3  Copyright (c) 2010 Bertjan Broeksema <[email protected]>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 #include "agentprocessinstance.h"
21 
22 #include "agenttype.h"
23 #include "processcontrol.h"
24 #include "akonadicontrol_debug.h"
25 #include "private/standarddirs_p.h"
26 
27 #include <QStandardPaths>
28 
29 using namespace Akonadi;
30 
31 AgentProcessInstance::AgentProcessInstance(AgentManager &manager)
32  : AgentInstance(manager)
33 {
34 }
35 
36 bool AgentProcessInstance::start(const AgentType &agentInfo)
37 {
38  Q_ASSERT(!identifier().isEmpty());
39  if (identifier().isEmpty()) {
40  return false;
41  }
42 
43  setAgentType(agentInfo.identifier);
44 
45  Q_ASSERT(agentInfo.launchMethod == AgentType::Process ||
46  agentInfo.launchMethod == AgentType::Launcher);
47 
48  const QString executable = (agentInfo.launchMethod == AgentType::Process)
49  ? Akonadi::StandardDirs::findExecutable(agentInfo.exec) : agentInfo.exec;
50 
51  if (executable.isEmpty()) {
52  qCWarning(AKONADICONTROL_LOG) << "Unable to find agent executable" << agentInfo.exec;
53  return false;
54  }
55 
56  mController = std::make_unique<Akonadi::ProcessControl>();
57  connect(mController.get(), &ProcessControl::unableToStart, this, &AgentProcessInstance::failedToStart);
58 
59  if (agentInfo.launchMethod == AgentType::Process) {
60  const QStringList arguments = { QStringLiteral("--identifier"), identifier()};
61  mController->start(executable, arguments);
62  } else {
63  Q_ASSERT(agentInfo.launchMethod == AgentType::Launcher);
64  const QStringList arguments = QStringList() << executable << identifier();
65  const QString agentLauncherExec = Akonadi::StandardDirs::findExecutable(QStringLiteral("akonadi_agent_launcher"));
66  mController->start(agentLauncherExec, arguments);
67  }
68  return true;
69 }
70 
71 void AgentProcessInstance::quit()
72 {
73  mController->setCrashPolicy(Akonadi::ProcessControl::StopOnCrash);
74  AgentInstance::quit();
75 }
76 
77 void AgentProcessInstance::cleanup()
78 {
79  mController->setCrashPolicy(Akonadi::ProcessControl::StopOnCrash);
80  AgentInstance::cleanup();
81 }
82 
83 void AgentProcessInstance::restartWhenIdle()
84 {
85  if (mController->isRunning()) {
86  if (status() != 1) {
87  mController->restartOnceWhenFinished();
88  quit();
89  }
90  } else {
91  mController->start();
92  }
93 }
94 
95 void Akonadi::AgentProcessInstance::configure(qlonglong windowId)
96 {
97  controlInterface()->configure(windowId);
98 }
99 
100 void AgentProcessInstance::failedToStart()
101 {
102  statusChanged(2 /*Broken*/, QStringLiteral("Unable to start."));
103 }
NETWORKMANAGERQT_EXPORT NetworkManager::Status status()
Provides an interface to retrieve agent types and manage agent instances.
QString identifier() const
Returns the unique identifier of the agent type.
A representation of an agent type.
bool isEmpty() const const
AKONADICORE_DEPRECATED void configure(QWidget *parent=nullptr)
Triggers the agent instance to show its configuration dialog.
void unableToStart()
Emitted if the process could not be started since it terminated too often.
KDEGAMES_EXPORT QAction * quit(const QObject *recvr, const char *slot, QObject *parent)
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 Fri Jun 5 2020 23:08:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.