Akonadi

akonadicontrol/main.cpp
1/***************************************************************************
2 * SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org> *
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
13#if WITH_ACCOUNTS
14#include "accountsintegration.h"
15#endif
16
17#include "shared/akapplication.h"
18
19#include "private/dbus_p.h"
20
21#include <QDBusConnection>
22#include <QGuiApplication>
23#include <QSessionManager>
24
25#include <KAboutData>
26#include <KCrash>
27#include <KLocalizedString>
28
29#include <stdlib.h>
30#if HAVE_UNISTD_H
31#include <unistd.h>
32#endif
33
34static AgentManager *sAgentManager = nullptr;
35
36void crashHandler(int /*unused*/)
37{
38 if (sAgentManager) {
39 sAgentManager->cleanup();
40 }
41
42 exit(255);
43}
44
45int 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 i18n("Akonadi Control"),
52 QStringLiteral(AKONADI_VERSION_STRING),
53 i18n("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 // akonadi_control is started on-demand, no need to auto restart by session.
74 auto disableSessionManagement = [](QSessionManager &sm) {
75 Q_UNUSED(sm);
76 sm.setRestartHint(QSessionManager::RestartNever);
77 };
78 QObject::connect(qApp, &QGuiApplication::commitDataRequest, qApp, disableSessionManagement);
79 QObject::connect(qApp, &QGuiApplication::saveStateRequest, qApp, disableSessionManagement);
80
81 return app.exec();
82}
The agent manager has knowledge about all available agents (it scans for .desktop files in the agent ...
void cleanup()
Called by the crash handler and dtor to terminate the child processes.
The control manager provides a dbus method to shutdown the Akonadi Control process cleanly.
static void setApplicationData(const KAboutData &aboutData)
QString i18n(const char *text, const TYPE &arg...)
KCRASH_EXPORT HandlerType crashHandler()
KCRASH_EXPORT void setEmergencySaveFunction(HandlerType saveFunction=nullptr)
QDBusConnection sessionBus()
void commitDataRequest(QSessionManager &manager)
void saveStateRequest(QSessionManager &manager)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:38 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.