diff --git a/src/tools/balooctl/monitorcommand.h b/src/tools/balooctl/monitorcommand.h --- a/src/tools/balooctl/monitorcommand.h +++ b/src/tools/balooctl/monitorcommand.h @@ -24,13 +24,12 @@ #ifndef MONITOR_H #define MONITOR_H +#include "command.h" +#include "fileindexerinterface.h" #include #include #include -#include "command.h" -#include "fileindexerinterface.h" - namespace Baloo { class MonitorCommand : public QObject, public Command @@ -55,8 +54,8 @@ private: QTextStream m_out; - org::kde::baloo::fileindexer* m_interface; - + QTextStream m_err; + org::kde::baloo::fileindexer* m_dbusInterface; QString m_currentFile; }; } diff --git a/src/tools/balooctl/monitorcommand.cpp b/src/tools/balooctl/monitorcommand.cpp --- a/src/tools/balooctl/monitorcommand.cpp +++ b/src/tools/balooctl/monitorcommand.cpp @@ -31,27 +31,50 @@ MonitorCommand::MonitorCommand(QObject *parent) : QObject(parent) , m_out(stdout) + , m_err(stderr) + , m_dbusInterface(nullptr) + { - m_interface = new org::kde::baloo::fileindexer(QStringLiteral("org.kde.baloo"), - QStringLiteral("/fileindexer"), - QDBusConnection::sessionBus(), - this); + QString waitMessage(i18nc("Application", "Waiting for %1 to start", "Baloo")); + QString runningMessage(i18nc("Application", "%1 is running", "Baloo")); + QString diedMessage(i18nc("Application", "%1 died", "Baloo")); + QString killMessage(i18n("Press ctrl+c to exit monitor")); + m_dbusInterface = new org::kde::baloo::fileindexer(QStringLiteral("org.kde.baloo") + , QStringLiteral("/fileindexer") + , QDBusConnection::sessionBus() + , this + ); - if (!m_interface->isValid()) { - m_out << i18n("Baloo is not running") << endl; - QCoreApplication::exit(); + m_err << killMessage << endl; + if (!m_dbusInterface->isValid()) { + m_err << waitMessage << endl; } - m_interface->registerMonitor(); - connect(m_interface, &org::kde::baloo::fileindexer::startedIndexingFile, this, &MonitorCommand::startedIndexingFile); - connect(m_interface, &org::kde::baloo::fileindexer::finishedIndexingFile, this, &MonitorCommand::finishedIndexingFile); - m_out << i18n("Press ctrl+c to exit monitor") << endl; - + while (!m_dbusInterface->isValid()) { + QThread::msleep(50); + m_dbusInterface->disconnect(); + delete m_dbusInterface; + m_dbusInterface = new org::kde::baloo::fileindexer(QStringLiteral("org.kde.baloo") + , QStringLiteral("/fileindexer") + , QDBusConnection::sessionBus() + , this + ); + }; + + m_err << runningMessage << endl; + m_dbusInterface->registerMonitor(); + connect(m_dbusInterface, &org::kde::baloo::fileindexer::startedIndexingFile + , this, &MonitorCommand::startedIndexingFile); + connect(m_dbusInterface, &org::kde::baloo::fileindexer::finishedIndexingFile + , this, &MonitorCommand::finishedIndexingFile); + auto balooWatcher = new QDBusServiceWatcher(QStringLiteral("org.kde.baloo"), QDBusConnection::sessionBus()); balooWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration); - connect(balooWatcher, &QDBusServiceWatcher::serviceUnregistered, this, [&]() { - m_out << i18n("Baloo died") << endl; - QCoreApplication::instance()->quit(); - }); + connect(balooWatcher, &QDBusServiceWatcher::serviceUnregistered + , [this, diedMessage]() { + m_out << diedMessage << endl; + //TODO: Wait again for dbus interface + QCoreApplication::exit(0); + }); } int MonitorCommand::exec(const QCommandLineParser& parser) @@ -71,5 +94,5 @@ Q_UNUSED(filePath); m_currentFile.clear(); - m_out << endl; + m_out << i18n(": Ok") << endl; }