Changeset View
Changeset View
Standalone View
Standalone View
src/file/pendingfilequeue.cpp
Show All 29 Lines | |||||
30 | 30 | | |||
31 | PendingFileQueue::PendingFileQueue(QObject* parent) | 31 | PendingFileQueue::PendingFileQueue(QObject* parent) | ||
32 | : QObject(parent) | 32 | : QObject(parent) | ||
33 | { | 33 | { | ||
34 | m_cacheTimer.setInterval(10); | 34 | m_cacheTimer.setInterval(10); | ||
35 | m_cacheTimer.setSingleShot(true); | 35 | m_cacheTimer.setSingleShot(true); | ||
36 | connect(&m_cacheTimer, &QTimer::timeout, this, &PendingFileQueue::processCache); | 36 | connect(&m_cacheTimer, &QTimer::timeout, this, &PendingFileQueue::processCache); | ||
37 | 37 | | |||
38 | m_trackingTime = 120; | 38 | m_trackingTime = 120 * 1000; | ||
39 | 39 | | |||
40 | m_clearRecentlyEmittedTimer.setInterval(m_trackingTime * 1000); | 40 | m_clearRecentlyEmittedTimer.setInterval(m_trackingTime); | ||
41 | m_clearRecentlyEmittedTimer.setSingleShot(true); | 41 | m_clearRecentlyEmittedTimer.setSingleShot(true); | ||
42 | connect(&m_clearRecentlyEmittedTimer, &QTimer::timeout, | 42 | connect(&m_clearRecentlyEmittedTimer, &QTimer::timeout, | ||
43 | this, &PendingFileQueue::clearRecentlyEmitted); | 43 | this, &PendingFileQueue::clearRecentlyEmitted); | ||
44 | 44 | | |||
45 | m_minTimeout = 5; | 45 | m_minTimeout = 5 * 1000; | ||
46 | m_maxTimeout = 60; | 46 | m_maxTimeout = 60 * 1000; | ||
47 | m_pendingFilesTimer.setInterval(m_minTimeout * 1000); | 47 | m_pendingFilesTimer.setInterval(m_minTimeout); | ||
48 | m_pendingFilesTimer.setSingleShot(true); | 48 | m_pendingFilesTimer.setSingleShot(true); | ||
49 | connect(&m_pendingFilesTimer, &QTimer::timeout, | 49 | connect(&m_pendingFilesTimer, &QTimer::timeout, | ||
50 | this, &PendingFileQueue::processPendingFiles); | 50 | this, &PendingFileQueue::processPendingFiles); | ||
51 | } | 51 | } | ||
52 | 52 | | |||
53 | PendingFileQueue::~PendingFileQueue() | 53 | PendingFileQueue::~PendingFileQueue() | ||
54 | { | 54 | { | ||
55 | } | 55 | } | ||
Show All 39 Lines | 89 | for (const PendingFile& file : qAsConst(m_cache)) { | |||
95 | } | 95 | } | ||
96 | else if (file.shouldIndexXAttrOnly()) { | 96 | else if (file.shouldIndexXAttrOnly()) { | ||
97 | Q_EMIT indexXAttr(file.path()); | 97 | Q_EMIT indexXAttr(file.path()); | ||
98 | } | 98 | } | ||
99 | else if (file.shouldIndexContents()) { | 99 | else if (file.shouldIndexContents()) { | ||
100 | if (m_pendingFiles.contains(file.path())) { | 100 | if (m_pendingFiles.contains(file.path())) { | ||
101 | QTime time = m_pendingFiles[file.path()]; | 101 | QTime time = m_pendingFiles[file.path()]; | ||
102 | 102 | | |||
103 | int secondsLeft = currentTime.secsTo(time); | 103 | int msecondsLeft = currentTime.msecsTo(time); | ||
104 | secondsLeft = qBound(m_minTimeout, secondsLeft * 2, m_maxTimeout); | 104 | msecondsLeft = qBound(m_minTimeout, msecondsLeft * 2, m_maxTimeout); | ||
105 | 105 | | |||
106 | time = currentTime.addSecs(secondsLeft); | 106 | time = currentTime.addMSecs(msecondsLeft); | ||
107 | m_pendingFiles[file.path()] = time; | 107 | m_pendingFiles[file.path()] = time; | ||
108 | } | 108 | } | ||
109 | else if (m_recentlyEmitted.contains(file.path())) { | 109 | else if (m_recentlyEmitted.contains(file.path())) { | ||
110 | QTime time = currentTime.addSecs(m_minTimeout); | 110 | QTime time = currentTime.addMSecs(m_minTimeout); | ||
111 | m_pendingFiles[file.path()] = time; | 111 | m_pendingFiles[file.path()] = time; | ||
112 | } | 112 | } | ||
113 | else { | 113 | else { | ||
114 | if (file.isNewFile()) { | 114 | if (file.isNewFile()) { | ||
115 | Q_EMIT indexNewFile(file.path()); | 115 | Q_EMIT indexNewFile(file.path()); | ||
116 | } else { | 116 | } else { | ||
117 | Q_EMIT indexModifiedFile(file.path()); | 117 | Q_EMIT indexModifiedFile(file.path()); | ||
118 | } | 118 | } | ||
119 | m_recentlyEmitted.insert(file.path(), currentTime); | 119 | m_recentlyEmitted.insert(file.path(), currentTime); | ||
120 | } | 120 | } | ||
121 | } else { | 121 | } else { | ||
122 | Q_ASSERT_X(false, "FileWatch", "The PendingFile should always have some flags set"); | 122 | Q_ASSERT_X(false, "FileWatch", "The PendingFile should always have some flags set"); | ||
123 | } | 123 | } | ||
124 | } | 124 | } | ||
125 | 125 | | |||
126 | m_cache.clear(); | 126 | m_cache.clear(); | ||
127 | 127 | | |||
128 | if (!m_pendingFiles.isEmpty() && !m_pendingFilesTimer.isActive()) { | 128 | if (!m_pendingFiles.isEmpty() && !m_pendingFilesTimer.isActive()) { | ||
129 | m_pendingFilesTimer.setInterval(m_minTimeout * 1000); | 129 | m_pendingFilesTimer.setInterval(m_minTimeout); | ||
130 | m_pendingFilesTimer.start(); | 130 | m_pendingFilesTimer.start(); | ||
131 | } | 131 | } | ||
132 | 132 | | |||
133 | if (!m_recentlyEmitted.isEmpty() && !m_clearRecentlyEmittedTimer.isActive()) { | 133 | if (!m_recentlyEmitted.isEmpty() && !m_clearRecentlyEmittedTimer.isActive()) { | ||
134 | m_clearRecentlyEmittedTimer.setInterval(m_trackingTime * 1000); | 134 | m_clearRecentlyEmittedTimer.setInterval(m_trackingTime); | ||
135 | m_clearRecentlyEmittedTimer.start(); | 135 | m_clearRecentlyEmittedTimer.start(); | ||
136 | } | 136 | } | ||
137 | } | 137 | } | ||
138 | 138 | | |||
139 | void PendingFileQueue::clearRecentlyEmitted() | 139 | void PendingFileQueue::clearRecentlyEmitted() | ||
140 | { | 140 | { | ||
141 | QTime time = QTime::currentTime(); | 141 | QTime time = QTime::currentTime(); | ||
142 | int nextUpdate = m_trackingTime; | 142 | int nextUpdate = m_trackingTime; | ||
143 | 143 | | |||
144 | QMutableHashIterator<QString, QTime> it(m_recentlyEmitted); | 144 | QMutableHashIterator<QString, QTime> it(m_recentlyEmitted); | ||
145 | while (it.hasNext()) { | 145 | while (it.hasNext()) { | ||
146 | it.next(); | 146 | it.next(); | ||
147 | 147 | | |||
148 | int secondsSinceEmitted = it.value().secsTo(time); | 148 | int msecondsSinceEmitted = it.value().msecsTo(time); | ||
149 | if (secondsSinceEmitted >= m_trackingTime) { | 149 | if (msecondsSinceEmitted >= m_trackingTime) { | ||
150 | it.remove(); | 150 | it.remove(); | ||
151 | } else { | 151 | } else { | ||
152 | int timeLeft = m_trackingTime - secondsSinceEmitted; | 152 | int timeLeft = m_trackingTime - msecondsSinceEmitted; | ||
153 | nextUpdate = qMin(nextUpdate, timeLeft); | 153 | nextUpdate = qMin(nextUpdate, timeLeft); | ||
154 | } | 154 | } | ||
155 | } | 155 | } | ||
156 | 156 | | |||
157 | if (!m_recentlyEmitted.isEmpty()) { | 157 | if (!m_recentlyEmitted.isEmpty()) { | ||
158 | m_clearRecentlyEmittedTimer.setInterval(nextUpdate * 1000); | 158 | m_clearRecentlyEmittedTimer.setInterval(nextUpdate); | ||
159 | m_clearRecentlyEmittedTimer.start(); | 159 | m_clearRecentlyEmittedTimer.start(); | ||
160 | } | 160 | } | ||
161 | } | 161 | } | ||
162 | 162 | | |||
163 | void PendingFileQueue::processPendingFiles() | 163 | void PendingFileQueue::processPendingFiles() | ||
164 | { | 164 | { | ||
165 | QTime currentTime = QTime::currentTime(); | 165 | QTime currentTime = QTime::currentTime(); | ||
166 | int nextUpdate = m_maxTimeout; | 166 | int nextUpdate = m_maxTimeout; | ||
167 | 167 | | |||
168 | QMutableHashIterator<QString, QTime> it(m_pendingFiles); | 168 | QMutableHashIterator<QString, QTime> it(m_pendingFiles); | ||
169 | while (it.hasNext()) { | 169 | while (it.hasNext()) { | ||
170 | it.next(); | 170 | it.next(); | ||
171 | 171 | | |||
172 | int secondsLeft = currentTime.secsTo(it.value()); | 172 | int mSecondsLeft = currentTime.msecsTo(it.value()); | ||
173 | if (secondsLeft <= 0) { | 173 | if (mSecondsLeft <= 0) { | ||
174 | Q_EMIT indexModifiedFile(it.key()); | 174 | Q_EMIT indexModifiedFile(it.key()); | ||
175 | m_recentlyEmitted.insert(it.key(), currentTime); | 175 | m_recentlyEmitted.insert(it.key(), currentTime); | ||
176 | 176 | | |||
177 | it.remove(); | 177 | it.remove(); | ||
178 | } | 178 | } | ||
179 | else { | 179 | else { | ||
180 | nextUpdate = qMin(secondsLeft, nextUpdate); | 180 | nextUpdate = qMin(mSecondsLeft, nextUpdate); | ||
181 | } | 181 | } | ||
182 | } | 182 | } | ||
183 | 183 | | |||
184 | if (!m_pendingFiles.isEmpty()) { | 184 | if (!m_pendingFiles.isEmpty()) { | ||
185 | m_pendingFilesTimer.setInterval(nextUpdate * 1000); | 185 | m_pendingFilesTimer.setInterval(nextUpdate); | ||
186 | m_pendingFilesTimer.start(); | 186 | m_pendingFilesTimer.start(); | ||
187 | } | 187 | } | ||
188 | 188 | | |||
189 | if (!m_recentlyEmitted.isEmpty() && !m_clearRecentlyEmittedTimer.isActive()) { | 189 | if (!m_recentlyEmitted.isEmpty() && !m_clearRecentlyEmittedTimer.isActive()) { | ||
190 | m_clearRecentlyEmittedTimer.setInterval(m_trackingTime * 1000); | 190 | m_clearRecentlyEmittedTimer.setInterval(m_trackingTime); | ||
191 | m_clearRecentlyEmittedTimer.start(); | 191 | m_clearRecentlyEmittedTimer.start(); | ||
192 | } | 192 | } | ||
193 | } | 193 | } | ||
194 | 194 | | |||
195 | void PendingFileQueue::setTrackingTime(int seconds) | 195 | void PendingFileQueue::setTrackingTime(int seconds) | ||
196 | { | 196 | { | ||
197 | m_trackingTime = seconds; | 197 | m_trackingTime = seconds * 1000; | ||
198 | } | 198 | } | ||
199 | 199 | | |||
200 | void PendingFileQueue::setMinimumTimeout(int seconds) | 200 | void PendingFileQueue::setMinimumTimeout(int seconds) | ||
201 | { | 201 | { | ||
202 | m_minTimeout = seconds; | 202 | m_minTimeout = seconds * 1000; | ||
203 | } | 203 | } | ||
204 | 204 | | |||
205 | void PendingFileQueue::setMaximumTimeout(int seconds) | 205 | void PendingFileQueue::setMaximumTimeout(int seconds) | ||
206 | { | 206 | { | ||
207 | m_maxTimeout = seconds; | 207 | m_maxTimeout = seconds * 1000; | ||
208 | } | 208 | } |