1/*
2 This file is part of the KDE Baloo Project
3 SPDX-FileCopyrightText: 2015 Pinak Ahuja <pinak.ahuja@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#ifndef BALOOMONITOR_MONITOR_H
9#define BALOOMONITOR_MONITOR_H
10
11#include <QDeadlineTimer>
12#include <QObject>
13#include <QString>
14
15#include "indexerstate.h"
16#include "schedulerinterface.h"
17#include "fileindexerinterface.h"
18
19namespace Baloo {
20class Monitor : public QObject
21{
22 Q_OBJECT
23
24 Q_PROPERTY(QString filePath READ filePath NOTIFY newFileIndexed)
25 Q_PROPERTY(QString suspendState READ suspendState NOTIFY indexerStateChanged)
26 Q_PROPERTY(bool balooRunning MEMBER m_balooRunning NOTIFY balooStateChanged)
27 Q_PROPERTY(uint totalFiles MEMBER m_totalFiles NOTIFY totalFilesChanged)
28 Q_PROPERTY(uint filesIndexed MEMBER m_filesIndexed NOTIFY newFileIndexed)
29 Q_PROPERTY(QString remainingTime READ remainingTime NOTIFY remainingTimeChanged)
30 Q_PROPERTY(QString stateString READ stateString NOTIFY indexerStateChanged)
31 Q_PROPERTY(Baloo::IndexerState state READ state NOTIFY indexerStateChanged)
32public:
33 explicit Monitor(QObject* parent = nullptr);
34
35 // Property readers
36 QString filePath() const { return m_filePath; }
37 QString suspendState() const;
38 QString remainingTime() const { return m_remainingTime; }
39 QString stateString() const { return Baloo::stateString(state: m_indexerState); }
40 Baloo::IndexerState state() const { return m_indexerState; }
41
42 // Invokable methods
43 Q_INVOKABLE void toggleSuspendState();
44 Q_INVOKABLE void startBaloo();
45
46Q_SIGNALS:
47 void newFileIndexed();
48 void balooStateChanged();
49 void totalFilesChanged();
50 void remainingTimeChanged();
51 void indexerStateChanged();
52
53private Q_SLOTS:
54 void newFile(const QString& filePath);
55 void balooStarted();
56 void slotIndexerStateChanged(int state);
57
58private:
59 void fetchTotalFiles();
60 void updateRemainingTime();
61
62 QDBusConnection m_bus;
63
64 QString m_filePath;
65 bool m_balooRunning = false;
66 Baloo::IndexerState m_indexerState = Baloo::Unavailable;
67 QDeadlineTimer m_remainingTimeTimer = QDeadlineTimer(0);
68
69 org::kde::baloo::scheduler* m_scheduler;
70 org::kde::baloo::fileindexer* m_fileindexer;
71
72 uint m_totalFiles = 0;
73 uint m_filesIndexed = 0;
74 QString m_remainingTime;
75 uint m_remainingTimeSeconds = 0;
76};
77}
78#endif //BALOOMONITOR_MONITOR_H
79

source code of baloo/src/qml/experimental/monitor.h