Baloo

fileindexscheduler.h
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_FILEINDEXSCHEDULER_H
8#define BALOO_FILEINDEXSCHEDULER_H
9
10#include <QObject>
11#include <QStringList>
12#include <QThreadPool>
13#include <QTimer>
14
15#include "filecontentindexerprovider.h"
16#include "powerstatemonitor.h"
17#include "indexerstate.h"
18#include "timeestimator.h"
19
20namespace Baloo {
21
22class Database;
23class FileIndexerConfig;
24class FileContentIndexer;
25
26class FileIndexScheduler : public QObject
27{
29 Q_CLASSINFO("D-Bus Interface", "org.kde.baloo.scheduler")
30
31 Q_PROPERTY(int state READ state NOTIFY stateChanged)
32public:
33 FileIndexScheduler(Database* db, FileIndexerConfig* config, bool firstRun, QObject* parent = nullptr);
34 ~FileIndexScheduler() override;
35 int state() const { return m_indexerState; }
36
38 Q_SCRIPTABLE void stateChanged(int state);
39
40public Q_SLOTS:
41 void indexNewFile(const QString& file) {
42 if (!m_newFiles.contains(file)) {
43 m_newFiles << file;
44 if (isIndexerIdle()) {
45 QTimer::singleShot(0, this, &FileIndexScheduler::scheduleIndexing);
46 }
47 }
48 }
49
50 void indexModifiedFile(const QString& file) {
51 if (!m_modifiedFiles.contains(file)) {
52 m_modifiedFiles << file;
53 if (isIndexerIdle()) {
54 QTimer::singleShot(0, this, &FileIndexScheduler::scheduleIndexing);
55 }
56 }
57 }
58
59 void indexXAttrFile(const QString& file) {
60 if (!m_xattrFiles.contains(file)) {
61 m_xattrFiles << file;
62 if (isIndexerIdle()) {
63 QTimer::singleShot(0, this, &FileIndexScheduler::scheduleIndexing);
64 }
65 }
66 }
67
68 void runnerFinished() {
69 m_isGoingIdle = true;
70 QTimer::singleShot(0, this, &FileIndexScheduler::scheduleIndexing);
71 }
72
73 void handleFileRemoved(const QString& file);
74
75 void updateConfig();
76 void scheduleIndexing();
77 void scheduleCheckUnindexedFiles();
78 void scheduleCheckStaleIndexEntries();
79 void startupFinished();
80
81 Q_SCRIPTABLE void suspend() { setSuspend(true); }
82 Q_SCRIPTABLE void resume() { setSuspend(false); }
83 Q_SCRIPTABLE uint getRemainingTime();
84 Q_SCRIPTABLE void checkUnindexedFiles();
85 Q_SCRIPTABLE void checkStaleIndexEntries();
86 Q_SCRIPTABLE uint getBatchSize();
87
88private Q_SLOTS:
89 void powerManagementStatusChanged(bool isOnBattery);
90
91private:
92 void setSuspend(bool suspend);
93 bool isIndexerIdle() {
94 return m_isGoingIdle ||
95 (m_indexerState == Suspended) ||
96 (m_indexerState == Startup) ||
97 (m_indexerState == Idle) ||
98 (m_indexerState == LowPowerIdle);
99 }
100
101 Database* m_db;
102 FileIndexerConfig* m_config;
103
104 QStringList m_newFiles;
105 QStringList m_modifiedFiles;
106 QStringList m_xattrFiles;
107
108 QThreadPool m_threadPool;
109
110 FileContentIndexerProvider m_provider;
111 FileContentIndexer* m_contentIndexer;
112
113 PowerStateMonitor m_powerMonitor;
114
115 IndexerState m_indexerState;
116 TimeEstimator m_timeEstimator;
117 uint m_indexPendingFiles = 0;
118 uint m_indexFinishedFiles = 0;
119
120 bool m_checkUnindexedFiles;
121 bool m_checkStaleIndexEntries;
122 bool m_isGoingIdle;
123 bool m_isSuspended;
124 bool m_isFirstRun;
125 bool m_inStartup;
126};
127
128}
129
130#endif // BALOO_FILEINDEXSCHEDULER_H
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
Q_CLASSINFO(Name, Value)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:03:07 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.