Akonadi

akonadicontrol/main.cpp
1 /***************************************************************************
2  * Copyright (C) 2006 by Tobias Koenig <[email protected]> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU Library General Public License as *
6  * published by the Free Software Foundation; either version 2 of the *
7  * License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU Library General Public *
15  * License along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18  ***************************************************************************/
19 
20 #include "agentmanager.h"
21 #include "controlmanager.h"
22 #include "processcontrol.h"
23 #include "akonadicontrol_debug.h"
24 #include "akonadi_version.h"
25 #include "config-akonadi.h"
26 
27 #ifdef WITH_ACCOUNTS
28 #include "accountsintegration.h"
29 #endif
30 
31 #include <shared/akapplication.h>
32 
33 #include <private/dbus_p.h>
34 
35 #include <QGuiApplication>
36 #include <QSessionManager>
37 #include <QDBusConnection>
38 
39 #include <KCrash/KCrash>
40 #include <KAboutData>
41 
42 #include <stdlib.h>
43 #ifdef HAVE_UNISTD_H
44 # include <unistd.h>
45 #endif
46 
47 static AgentManager *sAgentManager = nullptr;
48 
49 void crashHandler(int)
50 {
51  if (sAgentManager) {
52  sAgentManager->cleanup();
53  }
54 
55  exit(255);
56 }
57 
58 int main(int argc, char **argv)
59 {
60  AkUniqueGuiApplication app(argc, argv, Akonadi::DBus::serviceName(Akonadi::DBus::ControlLock), AKONADICONTROL_LOG());
61  app.setDescription(QStringLiteral("Akonadi Control Process\nDo not run this manually, use 'akonadictl' instead to start/stop Akonadi."));
62 
63  KAboutData aboutData(QStringLiteral("akonadi_control"),
64  QStringLiteral("Akonadi Control"),
65  QStringLiteral(AKONADI_VERSION_STRING),
66  QStringLiteral("Akonadi Control"),
67  KAboutLicense::LGPL_V2);
69 
70  app.parseCommandLine();
71 
72  // 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
73  // TODO: Remove this legacy check?
74  if (QDBusConnection::sessionBus().interface()->isServiceRegistered(Akonadi::DBus::serviceName(Akonadi::DBus::Control))) {
75  qCWarning(AKONADICONTROL_LOG) << "Another Akonadi control process is already running.";
76  return -1;
77  }
78 
79  ControlManager controlManager;
80 
81  AgentManager agentManager(app.commandLineArguments().isSet(QStringLiteral("verbose")));
82 #ifdef WITH_ACCOUNTS
83  AccountsIntegration accountsIntegration(agentManager);
84 #endif
86 
88 
89  // akonadi_control is started on-demand, no need to auto restart by session.
90  auto disableSessionManagement = [](QSessionManager & sm) {
91  sm.setRestartHint(QSessionManager::RestartNever);
92  };
93  QObject::connect(qApp, &QGuiApplication::commitDataRequest, disableSessionManagement);
94  QObject::connect(qApp, &QGuiApplication::saveStateRequest, disableSessionManagement);
95 
96  return app.exec();
97 }
QDBusConnection sessionBus()
void setFallbackSessionManagementEnabled(bool enabled)
The control manager provides a dbus method to shutdown the Akonadi Control process cleanly...
KCRASH_EXPORT void setEmergencySaveFunction(HandlerType saveFunction=nullptr)
The agent manager has knowledge about all available agents (it scans for .desktop files in the agent ...
void commitDataRequest(QSessionManager &manager)
static void setApplicationData(const KAboutData &aboutData)
void cleanup()
Called by the crash handler and dtor to terminate the child processes.
void saveStateRequest(QSessionManager &manager)
KCRASH_EXPORT HandlerType crashHandler()
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:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.