11#include "transaction.h"
15#include <QDBusConnection>
16#include <QDBusConnectionInterface>
18#include <QDBusServiceWatcher>
24Monitor::Monitor(
QObject *parent)
27 , m_filePath(QStringLiteral(
"Idle"))
28 , m_scheduler(nullptr)
29 , m_fileindexer(nullptr)
30 , m_remainingTime(QStringLiteral(
"Estimating"))
32 m_scheduler =
new org::kde::baloo::scheduler(QStringLiteral(
"org.kde.baloo"),
33 QStringLiteral(
"/scheduler"),
36 m_fileindexer =
new org::kde::baloo::fileindexer(QStringLiteral(
"org.kde.baloo"),
37 QStringLiteral(
"/fileindexer"),
40 connect(m_fileindexer, &org::kde::baloo::fileindexer::startedIndexingFile,
41 this, &Monitor::newFile);
43 connect(m_scheduler, &org::kde::baloo::scheduler::stateChanged,
44 this, &Monitor::slotIndexerStateChanged);
52 m_balooRunning =
false;
53 m_indexerState = Baloo::Unavailable;
54 Q_EMIT balooStateChanged();
55 Q_EMIT indexerStateChanged();
58 if (m_scheduler->isValid()) {
64void Monitor::newFile(
const QString& filePath)
66 m_filePath = filePath;
67 if (m_totalFiles == 0) {
74 if (now > m_remainingTimeTimer) {
75 updateRemainingTime();
76 m_remainingTimeTimer = now + 1000;
80QString Monitor::suspendState()
const
82 return m_indexerState == Baloo::Suspended ? QStringLiteral(
"Resume") : QStringLiteral(
"Suspend");
85void Monitor::toggleSuspendState()
87 if (m_indexerState == Baloo::Suspended) {
88 m_scheduler->resume();
90 m_scheduler->suspend();
94void Monitor::balooStarted()
96 m_balooRunning =
true;
97 m_fileindexer->registerMonitor();
101 QDBusMessage::createMethodCall(m_scheduler->service(), m_scheduler->path(), QStringLiteral(
"org.freedesktop.DBus.Properties"), QStringLiteral(
"Get"));
102 methodCall << m_scheduler->interface() << QStringLiteral(
"state");
103 auto pendingCall = m_scheduler->connection().asyncCall(methodCall, m_scheduler->timeout());
104 auto *watcher =
new QDBusPendingCallWatcher(pendingCall,
this);
106 QDBusPendingReply<QDBusVariant> state = *call;
108 if (state.isError()) {
109 qWarning() <<
"Error fetching Baloo indexer state:" << state.error().message();
111 slotIndexerStateChanged(state.value().variant().toInt());
112 Q_EMIT balooStateChanged();
119void Monitor::fetchTotalFiles()
121 Baloo::Database *db = Baloo::globalDatabaseInstance();
122 if (db->open(Baloo::Database::ReadOnlyDatabase)) {
123 Baloo::Transaction
tr(db, Baloo::Transaction::ReadOnly);
124 m_totalFiles =
tr.size();
125 m_filesIndexed =
tr.size() -
tr.phaseOneSize();
126 Q_EMIT totalFilesChanged();
131void Monitor::startBaloo()
133 const QString exe = QStringLiteral(KDE_INSTALL_FULL_LIBEXECDIR_KF
"/baloo_file");
137void Monitor::updateRemainingTime()
139 auto remainingTime = m_scheduler->getRemainingTime();
140 auto *watcher =
new QDBusPendingCallWatcher(remainingTime,
this);
142 QDBusPendingReply<uint> remainingTime = *call;
144 if (remainingTime.isError()) {
145 m_remainingTime = remainingTime.error().message();
146 Q_EMIT remainingTimeChanged();
147 }
else if ((remainingTime != m_remainingTimeSeconds) && (remainingTime > 0)) {
148 m_remainingTime = KFormat().formatSpelloutDuration(remainingTime);
149 m_remainingTimeSeconds = remainingTime;
150 Q_EMIT remainingTimeChanged();
157void Monitor::slotIndexerStateChanged(
int state)
159 Baloo::IndexerState newState =
static_cast<Baloo::IndexerState
>(state);
161 if (m_indexerState != newState) {
162 m_indexerState = newState;
164 if (m_indexerState != Baloo::ContentIndexing) {
165 m_filePath = QString();
167 Q_EMIT indexerStateChanged();
171#include "moc_monitor.cpp"
Implements storage for docIds without any associated data Instantiated for:
QDBusMessage createMethodCall(const QString &service, const QString &path, const QString &interface, const QString &method)
void finished(QDBusPendingCallWatcher *self)
void serviceRegistered(const QString &serviceName)
void serviceUnregistered(const QString &serviceName)
QDeadlineTimer current(Qt::TimerType timerType)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString tr(const char *sourceText, const char *disambiguation, int n)
bool startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)