11 #include "transaction.h"
15 #include <QDBusConnection>
16 #include <QDBusConnectionInterface>
18 #include <QDBusServiceWatcher>
23 using namespace Baloo;
24 Monitor::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()) {
64 void Monitor::newFile(
const QString& filePath)
66 m_filePath = filePath;
67 if (m_totalFiles == 0) {
71 Q_EMIT newFileIndexed();
74 if (now > m_remainingTimeTimer) {
75 updateRemainingTime();
76 m_remainingTimeTimer = now + 1000;
80 QString Monitor::suspendState()
const
82 return m_indexerState == Baloo::Suspended ? QStringLiteral(
"Resume") : QStringLiteral(
"Suspend");
85 void Monitor::toggleSuspendState()
87 if (m_indexerState == Baloo::Suspended) {
88 m_scheduler->resume();
90 m_scheduler->suspend();
94 void Monitor::balooStarted()
96 m_balooRunning =
true;
97 m_fileindexer->registerMonitor();
99 slotIndexerStateChanged(m_scheduler->state());
100 Q_EMIT balooStateChanged();
103 void Monitor::fetchTotalFiles()
105 Baloo::Database *db = Baloo::globalDatabaseInstance();
106 if (db->open(Baloo::Database::ReadOnlyDatabase)) {
107 Baloo::Transaction tr(db, Baloo::Transaction::ReadOnly);
108 m_totalFiles = tr.size();
109 m_filesIndexed = tr.size() - tr.phaseOneSize();
110 Q_EMIT totalFilesChanged();
111 Q_EMIT newFileIndexed();
115 void Monitor::startBaloo()
117 const QString exe = QStringLiteral(KDE_INSTALL_FULL_LIBEXECDIR
"/baloo_file");
121 void Monitor::updateRemainingTime()
123 auto remainingTime = m_scheduler->getRemainingTime();
124 if ((remainingTime != m_remainingTimeSeconds) && (remainingTime > 0)) {
126 m_remainingTimeSeconds = remainingTime;
127 Q_EMIT remainingTimeChanged();
131 void Monitor::slotIndexerStateChanged(
int state)
133 Baloo::IndexerState newState =
static_cast<Baloo::IndexerState
>(state);
135 if (m_indexerState != newState) {
136 m_indexerState = newState;
138 if (m_indexerState != Baloo::ContentIndexing) {
141 Q_EMIT indexerStateChanged();
145 #include "moc_monitor.cpp"