File indexing completed on 2025-01-05 04:46:27
0001 /* 0002 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "akonadistarter.h" 0008 #include "akonadictl_debug.h" 0009 0010 #include "shared/akapplication.h" 0011 0012 #include "private/dbus_p.h" 0013 #include "private/instance_p.h" 0014 0015 #include <QCoreApplication> 0016 #include <QDBusConnection> 0017 #include <QProcess> 0018 #include <QStandardPaths> 0019 #include <QTimer> 0020 0021 #include <iostream> 0022 0023 AkonadiStarter::AkonadiStarter(QObject *parent) 0024 : QObject(parent) 0025 , mWatcher(Akonadi::DBus::serviceName(Akonadi::DBus::ControlLock), QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration) 0026 { 0027 connect(&mWatcher, &QDBusServiceWatcher::serviceRegistered, this, [this]() { 0028 mRegistered = true; 0029 QCoreApplication::instance()->quit(); 0030 }); 0031 } 0032 0033 bool AkonadiStarter::start(bool verbose) 0034 { 0035 qCInfo(AKONADICTL_LOG) << "Starting Akonadi Server..."; 0036 0037 QStringList serverArgs; 0038 if (Akonadi::Instance::hasIdentifier()) { 0039 serverArgs << QStringLiteral("--instance") << Akonadi::Instance::identifier(); 0040 } 0041 if (verbose) { 0042 serverArgs << QStringLiteral("--verbose"); 0043 } 0044 0045 const QString exec = QStandardPaths::findExecutable(QStringLiteral("akonadi_control")); 0046 if (exec.isEmpty() || !QProcess::startDetached(exec, serverArgs)) { 0047 std::cerr << "Error: unable to execute binary akonadi_control" << std::endl; 0048 return false; 0049 } 0050 0051 // safety timeout 0052 QTimer::singleShot(std::chrono::seconds{5}, QCoreApplication::instance(), &QCoreApplication::quit); 0053 // wait for the server to register with D-Bus 0054 QCoreApplication::instance()->exec(); 0055 0056 if (!mRegistered) { 0057 std::cerr << "Error: akonadi_control was started but didn't register at D-Bus session bus." << std::endl 0058 << "Make sure your system is set up correctly!" << std::endl; 0059 return false; 0060 } 0061 0062 qCInfo(AKONADICTL_LOG) << " done."; 0063 return true; 0064 } 0065 0066 #include "moc_akonadistarter.cpp"