Baloo

monitorcommand.cpp
1/*
2 This file is part of the KDE Baloo Project
3 SPDX-FileCopyrightText: 2015 Pinak Ahuja <pinak.ahuja@gmail.com>
4 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7*/
8
9#include "monitorcommand.h"
10#include "indexerstate.h"
11
12#include <QDBusConnection>
13#include <QDBusServiceWatcher>
14
15using namespace Baloo;
16
17MonitorCommand::MonitorCommand(QObject *parent)
18 : QObject(parent)
19 , m_out(stdout)
20 , m_err(stderr)
21 , m_indexerDBusInterface(nullptr)
22 , m_schedulerDBusInterface(nullptr)
23 , m_dbusServiceWatcher(nullptr)
24
25{
26 m_dbusServiceWatcher = new QDBusServiceWatcher(
27 QStringLiteral("org.kde.baloo"), QDBusConnection::sessionBus(),
29 );
31 this, &MonitorCommand::balooIsAvailable);
33 this, &MonitorCommand::balooIsNotAvailable);
34
35 m_indexerDBusInterface = new org::kde::baloo::fileindexer(QStringLiteral("org.kde.baloo"),
36 QStringLiteral("/fileindexer"),
38 this
39 );
40 connect(m_indexerDBusInterface, &org::kde::baloo::fileindexer::startedIndexingFile,
41 this, &MonitorCommand::startedIndexingFile);
42 connect(m_indexerDBusInterface, &org::kde::baloo::fileindexer::finishedIndexingFile,
43 this, &MonitorCommand::finishedIndexingFile);
44
45 m_schedulerDBusInterface = new org::kde::baloo::scheduler(QStringLiteral("org.kde.baloo"),
46 QStringLiteral("/scheduler"),
48 this
49 );
50 connect(m_schedulerDBusInterface, &org::kde::baloo::scheduler::stateChanged,
51 this, &MonitorCommand::stateChanged);
52
53 if (m_indexerDBusInterface->isValid() && m_schedulerDBusInterface->isValid()) {
54 m_err << i18n("Press ctrl+c to stop monitoring\n");
55 m_err.flush();
56 balooIsAvailable();
57 stateChanged(m_schedulerDBusInterface->state());
58 const QString currentFile = m_indexerDBusInterface->currentFile();
59 if (!currentFile.isEmpty()) {
60 startedIndexingFile(currentFile);
61 }
62 } else {
63 balooIsNotAvailable();
64 }
65}
66
67void MonitorCommand::balooIsNotAvailable()
68{
69 m_indexerDBusInterface->unregisterMonitor();
70 m_err << i18n("Waiting for file indexer to start\n");
71 m_err << i18n("Press Ctrl+C to stop monitoring\n");
72 m_err.flush();
73}
74
75void MonitorCommand::balooIsAvailable()
76{
77 m_indexerDBusInterface->registerMonitor();
78 m_err << i18n("File indexer is running\n");
79 m_err.flush();
80}
81
82int MonitorCommand::exec(const QCommandLineParser& parser)
83{
84 Q_UNUSED(parser);
86}
87
88void MonitorCommand::startedIndexingFile(const QString& filePath)
89{
90 if (!m_currentFile.isEmpty()) {
91 m_out << '\n';
92 }
93 m_currentFile = filePath;
94 m_out << i18nc("currently indexed file", "Indexing: %1", filePath);
95 m_out.flush();
96}
97
98void MonitorCommand::finishedIndexingFile(const QString& filePath)
99{
100 Q_UNUSED(filePath);
101
102 m_currentFile.clear();
103 m_out << i18n(": Ok\n");
104 m_out.flush();
105}
106
107void MonitorCommand::stateChanged(int state)
108{
109 m_out << stateString(state) << '\n';
110 m_out.flush();
111}
112
113#include "moc_monitorcommand.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
QCoreApplication * instance()
QDBusConnection sessionBus()
void serviceRegistered(const QString &serviceName)
void serviceUnregistered(const QString &serviceName)
void clear()
bool isEmpty() const const
void flush()
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.