Akonadi

akonadicontrol/main.cpp
1 /***************************************************************************
2  * SPDX-FileCopyrightText: 2006 Tobias Koenig <[email protected]> *
3  * *
4  * SPDX-License-Identifier: LGPL-2.0-or-later *
5  ***************************************************************************/
6 
7 #include "agentmanager.h"
8 #include "akonadi_version.h"
9 #include "akonadicontrol_debug.h"
10 #include "config-akonadi.h"
11 #include "controlmanager.h"
12 #include "processcontrol.h"
13 
14 #if WITH_ACCOUNTS
15 #include "accountsintegration.h"
16 #endif
17 
18 #include <shared/akapplication.h>
19 
20 #include <private/dbus_p.h>
21 
22 #include <QDBusConnection>
23 #include <QGuiApplication>
24 #include <QSessionManager>
25 
26 #include <KAboutData>
27 #include <KCrash>
28 
29 #include <stdlib.h>
30 #if HAVE_UNISTD_H
31 #include <unistd.h>
32 #endif
33 
34 static AgentManager *sAgentManager = nullptr;
35 
36 void crashHandler(int /*unused*/)
37 {
38  if (sAgentManager) {
39  sAgentManager->cleanup();
40  }
41 
42  exit(255);
43 }
44 
45 int main(int argc, char **argv)
46 {
47  AkUniqueGuiApplication app(argc, argv, Akonadi::DBus::serviceName(Akonadi::DBus::ControlLock), AKONADICONTROL_LOG());
48  app.setDescription(QStringLiteral("Akonadi Control Process\nDo not run this manually, use 'akonadictl' instead to start/stop Akonadi."));
49 
50  KAboutData aboutData(QStringLiteral("akonadi_control"),
51  QStringLiteral("Akonadi Control"),
52  QStringLiteral(AKONADI_VERSION_STRING),
53  QStringLiteral("Akonadi Control"),
56 
57  app.parseCommandLine();
58 
59  // older Akonadi server versions don't use the lock service yet, so check if one is already running before we try to start another one
60  // TODO: Remove this legacy check?
61  if (QDBusConnection::sessionBus().interface()->isServiceRegistered(Akonadi::DBus::serviceName(Akonadi::DBus::Control))) {
62  qCWarning(AKONADICONTROL_LOG) << "Another Akonadi control process is already running.";
63  return -1;
64  }
65 
66  ControlManager controlManager;
67 
68  AgentManager agentManager(app.commandLineArguments().isSet(QStringLiteral("verbose")));
69 #if WITH_ACCOUNTS
70  AccountsIntegration accountsIntegration(agentManager);
71 #endif
73 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
75 #endif
76  // akonadi_control is started on-demand, no need to auto restart by session.
77  auto disableSessionManagement = [](QSessionManager &sm) {
78  sm.setRestartHint(QSessionManager::RestartNever);
79  };
80  QObject::connect(qApp, &QGuiApplication::commitDataRequest, disableSessionManagement);
81  QObject::connect(qApp, &QGuiApplication::saveStateRequest, disableSessionManagement);
82 
83  return app.exec();
84 }
void setFallbackSessionManagementEnabled(bool enabled)
void cleanup()
Called by the crash handler and dtor to terminate the child processes.
static void setApplicationData(const KAboutData &aboutData)
The agent manager has knowledge about all available agents (it scans for .desktop files in the agent ...
void commitDataRequest(QSessionManager &manager)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KCRASH_EXPORT void setEmergencySaveFunction(HandlerType saveFunction=nullptr)
QDBusConnection sessionBus()
void saveStateRequest(QSessionManager &manager)
The control manager provides a dbus method to shutdown the Akonadi Control process cleanly.
KCRASH_EXPORT HandlerType crashHandler()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jul 2 2022 06:41:48 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.