9#include "pendingfilequeue.h"
17PendingFileQueue::PendingFileQueue(
QObject* parent)
20 m_cacheTimer.setInterval(10);
21 m_cacheTimer.setSingleShot(
true);
26 m_trackingTime = 120 * 1000;
28 m_clearRecentlyEmittedTimer.setInterval(m_trackingTime);
29 m_clearRecentlyEmittedTimer.setSingleShot(
true);
34 m_minTimeout = 5 * 1000;
35 m_maxTimeout = 60 * 1000;
36 m_pendingFilesTimer.setInterval(m_minTimeout);
37 m_pendingFilesTimer.setSingleShot(
true);
43PendingFileQueue::~PendingFileQueue()
47void PendingFileQueue::enqueue(
const PendingFile& file)
55 const auto end = m_cache.
end();
60 m_recentlyEmitted.
remove(
it->path());
65 if (file.shouldRemoveIndex()) {
67 m_pendingFiles.
remove(file.path());
68 Q_EMIT removeFileIndex(file.path());
76 m_cache[
i].merge(file);
82void PendingFileQueue::processCache(
const QTime& currentTime)
85 if (file.shouldIndexXAttrOnly()) {
86 Q_EMIT indexXAttr(file.path());
88 else if (file.shouldIndexContents()) {
89 if (m_pendingFiles.
contains(file.path())) {
90 QTime time = m_pendingFiles[file.path()];
96 m_pendingFiles[file.path()] = time;
98 else if (m_recentlyEmitted.
contains(file.path())) {
100 m_pendingFiles[file.path()] = time;
103 if (file.isNewFile()) {
104 Q_EMIT indexNewFile(file.path());
106 Q_EMIT indexModifiedFile(file.path());
108 m_recentlyEmitted.
insert(file.path(), currentTime);
111 Q_ASSERT_X(
false,
"FileWatch",
"The PendingFile should always have some flags set");
119 m_pendingFilesTimer.
start();
122 if (!m_recentlyEmitted.
isEmpty() && !m_clearRecentlyEmittedTimer.
isActive()) {
123 m_clearRecentlyEmittedTimer.
setInterval(m_trackingTime);
124 m_clearRecentlyEmittedTimer.
start();
128void PendingFileQueue::clearRecentlyEmitted(
const QTime& time)
130 int nextUpdate = m_trackingTime;
133 while (
it.hasNext()) {
145 if (!m_recentlyEmitted.
isEmpty()) {
146 m_clearRecentlyEmittedTimer.
setInterval(nextUpdate);
147 m_clearRecentlyEmittedTimer.
start();
151void PendingFileQueue::processPendingFiles(
const QTime& currentTime)
153 int nextUpdate = m_maxTimeout;
156 while (
it.hasNext()) {
162 m_recentlyEmitted.
insert(
it.key(), currentTime);
171 if (!m_pendingFiles.
isEmpty()) {
173 m_pendingFilesTimer.
start();
176 if (!m_recentlyEmitted.
isEmpty() && !m_clearRecentlyEmittedTimer.
isActive()) {
177 m_clearRecentlyEmittedTimer.
setInterval(m_trackingTime);
178 m_clearRecentlyEmittedTimer.
start();
182void PendingFileQueue::setTrackingTime(
int seconds)
184 m_trackingTime = seconds * 1000;
187void PendingFileQueue::setMinimumTimeout(
int seconds)
189 m_minTimeout = seconds * 1000;
192void PendingFileQueue::setMaximumTimeout(
int seconds)
194 m_maxTimeout = seconds * 1000;
197#include "moc_pendingfilequeue.cpp"
Represents a file which needs to be indexed.
Implements storage for docIds without any associated data Instantiated for:
const QList< QKeySequence > & end()
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
bool isEmpty() const const
bool remove(const Key &key)
iterator erase(const_iterator begin, const_iterator end)
qsizetype indexOf(const AT &value, qsizetype from) const const
void remove(qsizetype i, qsizetype n)
bool removeOne(const AT &t)
bool startsWith(parameter_type value) const const
T value(qsizetype i) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QTime addMSecs(int ms) const const
int msecsTo(QTime t) const const
void setInterval(int msec)
bool isActive() const const