Changeset View
Changeset View
Standalone View
Standalone View
src/akonadictl/akonadistarter.cpp
Show All 29 Lines | |||||
30 | #include <QTimer> | 30 | #include <QTimer> | ||
31 | #include <QDBusConnection> | 31 | #include <QDBusConnection> | ||
32 | #include <QDBusServiceWatcher> | 32 | #include <QDBusServiceWatcher> | ||
33 | 33 | | |||
34 | #include <iostream> | 34 | #include <iostream> | ||
35 | 35 | | |||
36 | AkonadiStarter::AkonadiStarter(QObject *parent) | 36 | AkonadiStarter::AkonadiStarter(QObject *parent) | ||
37 | : QObject(parent) | 37 | : QObject(parent) | ||
38 | , mWatcher(Akonadi::DBus::serviceName(Akonadi::DBus::ControlLock), QDBusConnection::sessionBus(), | ||||
39 | QDBusServiceWatcher::WatchForRegistration) | ||||
38 | { | 40 | { | ||
39 | QDBusServiceWatcher *watcher = new QDBusServiceWatcher(Akonadi::DBus::serviceName(Akonadi::DBus::ControlLock), | 41 | connect(&mWatcher, &QDBusServiceWatcher::serviceRegistered, | ||
40 | QDBusConnection::sessionBus(), | 42 | this, [this]() { | ||
41 | QDBusServiceWatcher::WatchForOwnerChange, this); | 43 | mRegistered = true; | ||
42 | 44 | QCoreApplication::instance()->quit(); | |||
43 | connect(watcher, &QDBusServiceWatcher::serviceOwnerChanged, | 45 | }); | ||
44 | this, &AkonadiStarter::serviceOwnerChanged); | | |||
45 | } | 46 | } | ||
46 | 47 | | |||
47 | bool AkonadiStarter::start(bool verbose) | 48 | bool AkonadiStarter::start(bool verbose) | ||
48 | { | 49 | { | ||
49 | qCDebug(AKONADICTL_LOG) << "Starting Akonadi Server..."; | 50 | qCInfo(AKONADICTL_LOG) << "Starting Akonadi Server..."; | ||
50 | 51 | | |||
51 | QStringList serverArgs; | 52 | QStringList serverArgs; | ||
52 | if (Akonadi::Instance::hasIdentifier()) { | 53 | if (Akonadi::Instance::hasIdentifier()) { | ||
53 | serverArgs << QStringLiteral("--instance") << Akonadi::Instance::identifier(); | 54 | serverArgs << QStringLiteral("--instance") << Akonadi::Instance::identifier(); | ||
54 | } | 55 | } | ||
55 | if (verbose) { | 56 | if (verbose) { | ||
56 | serverArgs << QStringLiteral("--verbose"); | 57 | serverArgs << QStringLiteral("--verbose"); | ||
57 | } | 58 | } | ||
Show All 11 Lines | |||||
69 | 70 | | |||
70 | if (!mRegistered) { | 71 | if (!mRegistered) { | ||
71 | std::cerr << "Error: akonadi_control was started but didn't register at D-Bus session bus." | 72 | std::cerr << "Error: akonadi_control was started but didn't register at D-Bus session bus." | ||
72 | << std::endl | 73 | << std::endl | ||
73 | << "Make sure your system is set up correctly!" << std::endl; | 74 | << "Make sure your system is set up correctly!" << std::endl; | ||
74 | return false; | 75 | return false; | ||
75 | } | 76 | } | ||
76 | 77 | | |||
77 | qCDebug(AKONADICTL_LOG) << " done."; | 78 | qCInfo(AKONADICTL_LOG) << " done."; | ||
78 | return true; | 79 | return true; | ||
79 | } | 80 | } | ||
80 | 81 | | |||
81 | void AkonadiStarter::serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner) | | |||
82 | { | | |||
83 | Q_UNUSED(name); | | |||
84 | Q_UNUSED(oldOwner); | | |||
85 | if (newOwner.isEmpty()) { | | |||
86 | return; | | |||
87 | } | | |||
88 | | ||||
89 | mRegistered = true; | | |||
90 | QCoreApplication::instance()->quit(); | | |||
91 | } | |