Akonadi

akonadistarter.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "akonadistarter.h"
8 #include "akonadictl_debug.h"
9 
10 #include <shared/akapplication.h>
11 
12 #include <private/dbus_p.h>
13 #include <private/instance_p.h>
14 
15 #include <QCoreApplication>
16 #include <QDBusConnection>
17 #include <QProcess>
18 #include <QStandardPaths>
19 #include <QTimer>
20 
21 #include <iostream>
22 
23 AkonadiStarter::AkonadiStarter(QObject *parent)
24  : QObject(parent)
25  , mWatcher(Akonadi::DBus::serviceName(Akonadi::DBus::ControlLock), QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration)
26 {
27  connect(&mWatcher, &QDBusServiceWatcher::serviceRegistered, this, [this]() {
28  mRegistered = true;
30  });
31 }
32 
33 bool AkonadiStarter::start(bool verbose)
34 {
35  qCInfo(AKONADICTL_LOG) << "Starting Akonadi Server...";
36 
37  QStringList serverArgs;
38  if (Akonadi::Instance::hasIdentifier()) {
39  serverArgs << QStringLiteral("--instance") << Akonadi::Instance::identifier();
40  }
41  if (verbose) {
42  serverArgs << QStringLiteral("--verbose");
43  }
44 
45  const QString exec = QStandardPaths::findExecutable(QStringLiteral("akonadi_control"));
46  if (exec.isEmpty() || !QProcess::startDetached(exec, serverArgs)) {
47  std::cerr << "Error: unable to execute binary akonadi_control" << std::endl;
48  return false;
49  }
50 
51  // safety timeout
53  // wait for the server to register with D-Bus
55 
56  if (!mRegistered) {
57  std::cerr << "Error: akonadi_control was started but didn't register at D-Bus session bus." << std::endl
58  << "Make sure your system is set up correctly!" << std::endl;
59  return false;
60  }
61 
62  qCInfo(AKONADICTL_LOG) << " done.";
63  return true;
64 }
Q_SCRIPTABLE Q_NOREPLY void start()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString findExecutable(const QString &executableName, const QStringList &paths)
bool isEmpty() const const
QCoreApplication * instance()
void serviceRegistered(const QString &serviceName)
bool startDetached(qint64 *pid)
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:52:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.