| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 | */ |
| 6 | |
| 7 | #ifndef BALOO_FILECONTENTINDEXER_H |
| 8 | #define BALOO_FILECONTENTINDEXER_H |
| 9 | |
| 10 | #include <QRunnable> |
| 11 | #include <QObject> |
| 12 | #include <QAtomicInt> |
| 13 | #include <QStringList> |
| 14 | |
| 15 | #include <QDBusServiceWatcher> |
| 16 | #include <QDBusMessage> |
| 17 | |
| 18 | namespace Baloo { |
| 19 | |
| 20 | class FileContentIndexerProvider; |
| 21 | class TimeEstimator; |
| 22 | |
| 23 | class FileContentIndexer : public QObject, public QRunnable |
| 24 | { |
| 25 | Q_OBJECT |
| 26 | Q_CLASSINFO("D-Bus Interface" , "org.kde.baloo.fileindexer" ) |
| 27 | |
| 28 | Q_PROPERTY(QString currentFile READ currentFile NOTIFY startedIndexingFile) |
| 29 | public: |
| 30 | FileContentIndexer(uint batchSize, FileContentIndexerProvider *provider, TimeEstimator &timeEstimator, QObject *parent = nullptr); |
| 31 | |
| 32 | QString currentFile() { return m_currentFile; } |
| 33 | |
| 34 | void run() override; |
| 35 | |
| 36 | void quit() { |
| 37 | m_stop.storeRelaxed(newValue: true); |
| 38 | } |
| 39 | |
| 40 | public Q_SLOTS: |
| 41 | Q_SCRIPTABLE void registerMonitor(const QDBusMessage& message); |
| 42 | Q_SCRIPTABLE void unregisterMonitor(const QDBusMessage& message); |
| 43 | |
| 44 | Q_SIGNALS: |
| 45 | Q_SCRIPTABLE void startedIndexingFile(const QString& filePath); |
| 46 | Q_SCRIPTABLE void finishedIndexingFile(const QString& filePath); |
| 47 | Q_SCRIPTABLE void committedBatch(uint time, uint batchSize); |
| 48 | |
| 49 | void done(); |
| 50 | |
| 51 | private Q_SLOTS: |
| 52 | void monitorClosed(const QString& service); |
| 53 | void slotStartedIndexingFile(const QString &filePath); |
| 54 | void slotFinishedIndexingFile(const QString &filePath); |
| 55 | |
| 56 | private: |
| 57 | uint m_batchSize; |
| 58 | FileContentIndexerProvider *m_provider; |
| 59 | |
| 60 | QAtomicInt m_stop; |
| 61 | |
| 62 | QString m_currentFile; |
| 63 | TimeEstimator &m_timeEstimator; |
| 64 | |
| 65 | QStringList m_registeredMonitors; |
| 66 | QDBusServiceWatcher m_monitorWatcher; |
| 67 | |
| 68 | QString ; |
| 69 | }; |
| 70 | |
| 71 | } |
| 72 | |
| 73 | #endif // BALOO_FILECONTENTINDEXER_H |
| 74 | |