Akonadi

akonadistarter.cpp
1 /*
2  Copyright (c) 2008 Volker Krause <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "akonadistarter.h"
21 #include "akonadictl_debug.h"
22 
23 #include <shared/akapplication.h>
24 
25 #include <private/dbus_p.h>
26 #include <private/instance_p.h>
27 
28 #include <QCoreApplication>
29 #include <QProcess>
30 #include <QTimer>
31 #include <QDBusConnection>
32 #include <QDBusServiceWatcher>
33 
34 #include <iostream>
35 
36 AkonadiStarter::AkonadiStarter(QObject *parent)
37  : QObject(parent)
38  , mWatcher(Akonadi::DBus::serviceName(Akonadi::DBus::ControlLock), QDBusConnection::sessionBus(),
39  QDBusServiceWatcher::WatchForRegistration)
40 {
42  this, [this]() {
43  mRegistered = true;
45  });
46 }
47 
48 bool AkonadiStarter::start(bool verbose)
49 {
50  qCInfo(AKONADICTL_LOG) << "Starting Akonadi Server...";
51 
52  QStringList serverArgs;
53  if (Akonadi::Instance::hasIdentifier()) {
54  serverArgs << QStringLiteral("--instance") << Akonadi::Instance::identifier();
55  }
56  if (verbose) {
57  serverArgs << QStringLiteral("--verbose");
58  }
59 
60  const bool ok = QProcess::startDetached(QStringLiteral("akonadi_control"), serverArgs);
61  if (!ok) {
62  std::cerr << "Error: unable to execute binary akonadi_control" << std::endl;
63  return false;
64  }
65 
66  // safety timeout
68  // wait for the server to register with D-Bus
70 
71  if (!mRegistered) {
72  std::cerr << "Error: akonadi_control was started but didn't register at D-Bus session bus."
73  << std::endl
74  << "Make sure your system is set up correctly!" << std::endl;
75  return false;
76  }
77 
78  qCInfo(AKONADICTL_LOG) << " done.";
79  return true;
80 }
81 
void serviceRegistered(const QString &serviceName)
bool startDetached(qint64 *pid)
QCoreApplication * instance()
Helper integration between Akonadi and Qt.
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 Sat May 30 2020 22:46:06 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.