Changeset View
Changeset View
Standalone View
Standalone View
src/baloo/localbaloofilelisting.cpp
Show All 11 Lines | |||||
12 | * Lesser General Public License for more details. | 12 | * Lesser General Public License for more details. | ||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public License | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | 17 | | |||
18 | #include "localbaloofilelisting.h" | 18 | #include "localbaloofilelisting.h" | ||
19 | 19 | | |||
20 | #include "baloo/baloocommon.h" | ||||
21 | | ||||
20 | #include "musicaudiotrack.h" | 22 | #include "musicaudiotrack.h" | ||
21 | #include "notificationitem.h" | 23 | #include "notificationitem.h" | ||
22 | #include "elisa_settings.h" | 24 | #include "elisa_settings.h" | ||
23 | #include "elisautils.h" | 25 | #include "elisautils.h" | ||
24 | 26 | | |||
25 | #include "baloo/scheduler.h" | 27 | #include "baloo/scheduler.h" | ||
26 | #include "baloo/fileindexer.h" | 28 | #include "baloo/fileindexer.h" | ||
27 | #include "baloo/main.h" | 29 | #include "baloo/main.h" | ||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | 63 | public: | |||
82 | 84 | | |||
83 | bool mIsRegisteredToBalooWatcher = false; | 85 | bool mIsRegisteredToBalooWatcher = false; | ||
84 | 86 | | |||
85 | bool mIsRegisteringToBalooWatcher = false; | 87 | bool mIsRegisteringToBalooWatcher = false; | ||
86 | 88 | | |||
87 | }; | 89 | }; | ||
88 | 90 | | |||
89 | LocalBalooFileListing::LocalBalooFileListing(QObject *parent) | 91 | LocalBalooFileListing::LocalBalooFileListing(QObject *parent) | ||
90 | : AbstractFileListing(QStringLiteral("baloo"), parent), d(std::make_unique<LocalBalooFileListingPrivate>()) | 92 | : AbstractFileListing(parent), d(std::make_unique<LocalBalooFileListingPrivate>()) | ||
91 | { | 93 | { | ||
92 | d->mQuery.addType(QStringLiteral("Audio")); | 94 | d->mQuery.addType(QStringLiteral("Audio")); | ||
93 | setHandleNewFiles(false); | 95 | setHandleNewFiles(false); | ||
94 | 96 | | |||
95 | auto sessionBus = QDBusConnection::sessionBus(); | 97 | auto sessionBus = QDBusConnection::sessionBus(); | ||
96 | 98 | | |||
97 | d->mDbusAdaptor = new BalooWatcherApplicationAdaptor(this); | 99 | d->mDbusAdaptor = new BalooWatcherApplicationAdaptor(this); | ||
98 | 100 | | |||
Show All 22 Lines | |||||
121 | void LocalBalooFileListing::applicationAboutToQuit() | 123 | void LocalBalooFileListing::applicationAboutToQuit() | ||
122 | { | 124 | { | ||
123 | AbstractFileListing::applicationAboutToQuit(); | 125 | AbstractFileListing::applicationAboutToQuit(); | ||
124 | d->mStopRequest = 1; | 126 | d->mStopRequest = 1; | ||
125 | } | 127 | } | ||
126 | 128 | | |||
127 | void LocalBalooFileListing::newBalooFile(const QString &fileName) | 129 | void LocalBalooFileListing::newBalooFile(const QString &fileName) | ||
128 | { | 130 | { | ||
131 | qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::newBalooFile" << fileName; | ||||
132 | | ||||
129 | auto scanFileInfo = QFileInfo(fileName); | 133 | auto scanFileInfo = QFileInfo(fileName); | ||
130 | 134 | | |||
131 | if (!scanFileInfo.exists()) { | 135 | if (!scanFileInfo.exists()) { | ||
132 | return; | 136 | return; | ||
133 | } | 137 | } | ||
134 | 138 | | |||
139 | const auto &fileMimeType = mimeDatabase().mimeTypeForFile(fileName); | ||||
140 | if (!fileMimeType.name().startsWith(QStringLiteral("audio/"))) { | ||||
141 | return; | ||||
142 | } | ||||
143 | | ||||
144 | Q_EMIT indexingStarted(); | ||||
145 | | ||||
135 | auto newFile = QUrl::fromLocalFile(fileName); | 146 | auto newFile = QUrl::fromLocalFile(fileName); | ||
136 | 147 | | |||
137 | auto newTrack = scanOneFile(newFile, scanFileInfo); | 148 | auto newTrack = scanOneFile(newFile, scanFileInfo); | ||
138 | 149 | | |||
139 | if (newTrack.isValid()) { | 150 | if (newTrack.isValid()) { | ||
140 | QFileInfo newFileInfo(fileName); | 151 | QFileInfo newFileInfo(fileName); | ||
141 | 152 | | |||
142 | addFileInDirectory(newFile, QUrl::fromLocalFile(newFileInfo.absoluteDir().absolutePath())); | 153 | addFileInDirectory(newFile, QUrl::fromLocalFile(newFileInfo.absoluteDir().absolutePath())); | ||
143 | 154 | | |||
144 | emitNewFiles({newTrack}); | 155 | emitNewFiles({newTrack}); | ||
145 | } | 156 | } | ||
157 | | ||||
158 | Q_EMIT indexingFinished(); | ||||
146 | } | 159 | } | ||
147 | 160 | | |||
148 | void LocalBalooFileListing::registeredToBaloo(QDBusPendingCallWatcher *watcher) | 161 | void LocalBalooFileListing::registeredToBaloo(QDBusPendingCallWatcher *watcher) | ||
149 | { | 162 | { | ||
150 | qDebug() << "LocalBalooFileListing::registeredToBaloo"; | 163 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registeredToBaloo"; | ||
151 | 164 | | |||
152 | if (!watcher) { | 165 | if (!watcher) { | ||
153 | return; | 166 | return; | ||
154 | } | 167 | } | ||
155 | 168 | | |||
156 | QDBusPendingReply<> reply = *watcher; | 169 | QDBusPendingReply<> reply = *watcher; | ||
157 | if (reply.isError()) { | 170 | if (reply.isError()) { | ||
158 | qDebug() << "LocalBalooFileListing::registeredToBaloo" << reply.error().name() << reply.error().message(); | 171 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registeredToBaloo" << reply.error().name() << reply.error().message(); | ||
159 | d->mIsRegisteredToBaloo = false; | 172 | d->mIsRegisteredToBaloo = false; | ||
160 | } else { | 173 | } else { | ||
161 | d->mIsRegisteredToBaloo = true; | 174 | d->mIsRegisteredToBaloo = true; | ||
162 | } | 175 | } | ||
163 | 176 | | |||
164 | d->mIsRegisteringToBaloo = false; | 177 | d->mIsRegisteringToBaloo = false; | ||
165 | 178 | | |||
166 | watcher->deleteLater(); | 179 | watcher->deleteLater(); | ||
167 | } | 180 | } | ||
168 | 181 | | |||
169 | void LocalBalooFileListing::registeredToBalooWatcher(QDBusPendingCallWatcher *watcher) | 182 | void LocalBalooFileListing::registeredToBalooWatcher(QDBusPendingCallWatcher *watcher) | ||
170 | { | 183 | { | ||
171 | qDebug() << "LocalBalooFileListing::registeredToBalooWatcher"; | 184 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registeredToBalooWatcher"; | ||
172 | 185 | | |||
173 | if (!watcher) { | 186 | if (!watcher) { | ||
174 | return; | 187 | return; | ||
175 | } | 188 | } | ||
176 | 189 | | |||
177 | QDBusPendingReply<> reply = *watcher; | 190 | QDBusPendingReply<> reply = *watcher; | ||
178 | if (reply.isError()) { | 191 | if (reply.isError()) { | ||
179 | qDebug() << "LocalBalooFileListing::registeredToBalooWatcher" << reply.error().name() << reply.error().message(); | 192 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registeredToBalooWatcher" << reply.error().name() << reply.error().message(); | ||
180 | d->mIsRegisteredToBalooWatcher = false; | 193 | d->mIsRegisteredToBalooWatcher = false; | ||
181 | } else { | 194 | } else { | ||
182 | d->mIsRegisteredToBalooWatcher = true; | 195 | d->mIsRegisteredToBalooWatcher = true; | ||
183 | } | 196 | } | ||
184 | 197 | | |||
185 | d->mIsRegisteringToBalooWatcher = false; | 198 | d->mIsRegisteringToBalooWatcher = false; | ||
186 | 199 | | |||
187 | watcher->deleteLater(); | 200 | watcher->deleteLater(); | ||
188 | } | 201 | } | ||
189 | 202 | | |||
190 | void LocalBalooFileListing::registerToBaloo() | 203 | void LocalBalooFileListing::registerToBaloo() | ||
191 | { | 204 | { | ||
192 | if (d->mIsRegisteringToBaloo || d->mIsRegisteringToBalooWatcher) { | 205 | if (d->mIsRegisteringToBaloo || d->mIsRegisteringToBalooWatcher) { | ||
193 | qDebug() << "LocalBalooFileListing::registerToBaloo" << "already registering"; | 206 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registerToBaloo" << "already registering"; | ||
194 | return; | 207 | return; | ||
195 | } | 208 | } | ||
196 | 209 | | |||
197 | qDebug() << "LocalBalooFileListing::registerToBaloo"; | 210 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registerToBaloo"; | ||
198 | 211 | | |||
199 | d->mIsRegisteringToBaloo = true; | 212 | d->mIsRegisteringToBaloo = true; | ||
200 | d->mIsRegisteringToBalooWatcher = true; | 213 | d->mIsRegisteringToBalooWatcher = true; | ||
201 | 214 | | |||
202 | auto sessionBus = QDBusConnection::sessionBus(); | 215 | auto sessionBus = QDBusConnection::sessionBus(); | ||
203 | 216 | | |||
204 | d->mBalooMainInterface.reset(new org::kde::baloo::main(QStringLiteral("org.kde.baloo"), QStringLiteral("/"), | 217 | d->mBalooMainInterface.reset(new org::kde::baloo::main(QStringLiteral("org.kde.baloo"), QStringLiteral("/"), | ||
205 | sessionBus, this)); | 218 | sessionBus, this)); | ||
206 | 219 | | |||
207 | if (!d->mBalooMainInterface->isValid()) { | 220 | if (!d->mBalooMainInterface->isValid()) { | ||
208 | qDebug() << "LocalBalooFileListing::registerToBaloo" << "invalid org.kde.baloo/main interface"; | 221 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registerToBaloo" << "invalid org.kde.baloo/main interface"; | ||
209 | return; | 222 | return; | ||
210 | } | 223 | } | ||
211 | 224 | | |||
212 | d->mBalooIndexer.reset(new org::kde::baloo::fileindexer(QStringLiteral("org.kde.baloo"), QStringLiteral("/fileindexer"), | 225 | d->mBalooIndexer.reset(new org::kde::baloo::fileindexer(QStringLiteral("org.kde.baloo"), QStringLiteral("/fileindexer"), | ||
213 | sessionBus, this)); | 226 | sessionBus, this)); | ||
214 | 227 | | |||
215 | if (!d->mBalooIndexer->isValid()) { | 228 | if (!d->mBalooIndexer->isValid()) { | ||
216 | qDebug() << "LocalBalooFileListing::registerToBaloo" << "invalid org.kde.baloo/fileindexer interface"; | 229 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registerToBaloo" << "invalid org.kde.baloo/fileindexer interface"; | ||
217 | return; | 230 | return; | ||
218 | } | 231 | } | ||
219 | 232 | | |||
220 | connect(d->mBalooIndexer.data(), &org::kde::baloo::fileindexer::finishedIndexingFile, | 233 | connect(d->mBalooIndexer.data(), &org::kde::baloo::fileindexer::finishedIndexingFile, | ||
221 | this, &LocalBalooFileListing::newBalooFile); | 234 | this, &LocalBalooFileListing::newBalooFile); | ||
222 | 235 | | |||
223 | d->mBalooScheduler.reset(new org::kde::baloo::scheduler(QStringLiteral("org.kde.baloo"), QStringLiteral("/scheduler"), | 236 | d->mBalooScheduler.reset(new org::kde::baloo::scheduler(QStringLiteral("org.kde.baloo"), QStringLiteral("/scheduler"), | ||
224 | sessionBus, this)); | 237 | sessionBus, this)); | ||
225 | 238 | | |||
226 | if (!d->mBalooScheduler->isValid()) { | 239 | if (!d->mBalooScheduler->isValid()) { | ||
227 | qDebug() << "LocalBalooFileListing::registerToBaloo" << "invalid org.kde.baloo/scheduler interface"; | 240 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registerToBaloo" << "invalid org.kde.baloo/scheduler interface"; | ||
228 | return; | 241 | return; | ||
229 | } | 242 | } | ||
230 | 243 | | |||
231 | qDebug() << "LocalBalooFileListing::registerToBaloo" << "call registerMonitor"; | 244 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registerToBaloo" << "call registerMonitor"; | ||
232 | auto answer = d->mBalooIndexer->registerMonitor(); | 245 | auto answer = d->mBalooIndexer->registerMonitor(); | ||
233 | 246 | | |||
234 | if (answer.isError()) { | 247 | if (answer.isError()) { | ||
235 | qDebug() << "LocalBalooFileListing::executeInit" << answer.error().name() << answer.error().message(); | 248 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::executeInit" << answer.error().name() << answer.error().message(); | ||
236 | } | 249 | } | ||
237 | 250 | | |||
238 | auto pendingCallWatcher = new QDBusPendingCallWatcher(answer); | 251 | auto pendingCallWatcher = new QDBusPendingCallWatcher(answer); | ||
239 | 252 | | |||
240 | connect(pendingCallWatcher, &QDBusPendingCallWatcher::finished, this, &LocalBalooFileListing::registeredToBaloo); | 253 | connect(pendingCallWatcher, &QDBusPendingCallWatcher::finished, this, &LocalBalooFileListing::registeredToBaloo); | ||
241 | if (pendingCallWatcher->isFinished()) { | 254 | if (pendingCallWatcher->isFinished()) { | ||
242 | registeredToBaloo(pendingCallWatcher); | 255 | registeredToBaloo(pendingCallWatcher); | ||
243 | } | 256 | } | ||
244 | 257 | | |||
245 | auto pendingCall = d->mBalooMainInterface->registerBalooWatcher(QStringLiteral("org.mpris.MediaPlayer2.elisa/org/kde/BalooWatcherApplication")); | 258 | auto pendingCall = d->mBalooMainInterface->registerBalooWatcher(QStringLiteral("org.mpris.MediaPlayer2.elisa/org/kde/BalooWatcherApplication")); | ||
246 | qDebug() << "LocalBalooFileListing::registerToBaloo" << "call registerBalooWatcher"; | 259 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registerToBaloo" << "call registerBalooWatcher"; | ||
247 | auto pendingCallWatcher2 = new QDBusPendingCallWatcher(pendingCall); | 260 | auto pendingCallWatcher2 = new QDBusPendingCallWatcher(pendingCall); | ||
248 | 261 | | |||
249 | connect(pendingCallWatcher2, &QDBusPendingCallWatcher::finished, this, &LocalBalooFileListing::registeredToBalooWatcher); | 262 | connect(pendingCallWatcher2, &QDBusPendingCallWatcher::finished, this, &LocalBalooFileListing::registeredToBalooWatcher); | ||
250 | if (pendingCallWatcher2->isFinished()) { | 263 | if (pendingCallWatcher2->isFinished()) { | ||
251 | registeredToBalooWatcher(pendingCallWatcher2); | 264 | registeredToBalooWatcher(pendingCallWatcher2); | ||
252 | } | 265 | } | ||
253 | } | 266 | } | ||
254 | 267 | | |||
255 | void LocalBalooFileListing::renamedFiles(const QString &from, const QString &to, const QStringList &listFiles) | 268 | void LocalBalooFileListing::renamedFiles(const QString &from, const QString &to, const QStringList &listFiles) | ||
256 | { | 269 | { | ||
257 | qDebug() << "LocalBalooFileListing::renamedFiles" << from << to << listFiles; | 270 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::renamedFiles" << from << to << listFiles; | ||
258 | } | 271 | } | ||
259 | 272 | | |||
260 | void LocalBalooFileListing::serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner) | 273 | void LocalBalooFileListing::serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner) | ||
261 | { | 274 | { | ||
262 | Q_UNUSED(oldOwner); | 275 | Q_UNUSED(oldOwner); | ||
263 | Q_UNUSED(newOwner); | 276 | Q_UNUSED(newOwner); | ||
264 | 277 | | |||
265 | qDebug() << "LocalBalooFileListing::serviceOwnerChanged" << serviceName << oldOwner << newOwner; | 278 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::serviceOwnerChanged" << serviceName << oldOwner << newOwner; | ||
266 | 279 | | |||
267 | if (serviceName == QStringLiteral("org.kde.baloo") && !newOwner.isEmpty()) { | 280 | if (serviceName == QStringLiteral("org.kde.baloo") && !newOwner.isEmpty()) { | ||
268 | d->mIsRegisteredToBaloo = false; | 281 | d->mIsRegisteredToBaloo = false; | ||
269 | d->mIsRegisteredToBalooWatcher = false; | 282 | d->mIsRegisteredToBalooWatcher = false; | ||
270 | registerToBaloo(); | 283 | registerToBaloo(); | ||
271 | } | 284 | } | ||
272 | } | 285 | } | ||
273 | 286 | | |||
274 | void LocalBalooFileListing::serviceRegistered(const QString &serviceName) | 287 | void LocalBalooFileListing::serviceRegistered(const QString &serviceName) | ||
275 | { | 288 | { | ||
276 | qDebug() << "LocalBalooFileListing::serviceRegistered" << serviceName; | 289 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::serviceRegistered" << serviceName; | ||
277 | 290 | | |||
278 | if (serviceName == QStringLiteral("org.kde.baloo")) { | 291 | if (serviceName == QStringLiteral("org.kde.baloo")) { | ||
279 | registerToBaloo(); | 292 | registerToBaloo(); | ||
280 | } | 293 | } | ||
281 | } | 294 | } | ||
282 | 295 | | |||
283 | void LocalBalooFileListing::serviceUnregistered(const QString &serviceName) | 296 | void LocalBalooFileListing::serviceUnregistered(const QString &serviceName) | ||
284 | { | 297 | { | ||
285 | qDebug() << "LocalBalooFileListing::serviceUnregistered" << serviceName; | 298 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::serviceUnregistered" << serviceName; | ||
286 | 299 | | |||
287 | if (serviceName == QStringLiteral("org.kde.baloo")) { | 300 | if (serviceName == QStringLiteral("org.kde.baloo")) { | ||
288 | d->mIsRegisteredToBaloo = false; | 301 | d->mIsRegisteredToBaloo = false; | ||
289 | d->mIsRegisteredToBalooWatcher = false; | 302 | d->mIsRegisteredToBalooWatcher = false; | ||
290 | } | 303 | } | ||
291 | } | 304 | } | ||
292 | 305 | | |||
293 | void LocalBalooFileListing::executeInit(QHash<QUrl, QDateTime> allFiles) | 306 | void LocalBalooFileListing::executeInit(QHash<QUrl, QDateTime> allFiles) | ||
294 | { | 307 | { | ||
295 | AbstractFileListing::executeInit(std::move(allFiles)); | 308 | AbstractFileListing::executeInit(std::move(allFiles)); | ||
296 | } | 309 | } | ||
297 | 310 | | |||
298 | void LocalBalooFileListing::triggerRefreshOfContent() | 311 | void LocalBalooFileListing::triggerRefreshOfContent() | ||
299 | { | 312 | { | ||
300 | if (!checkBalooConfiguration()) { | 313 | qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::triggerRefreshOfContent"; | ||
301 | return; | | |||
302 | } | | |||
303 | | ||||
304 | Q_EMIT indexingStarted(); | 314 | Q_EMIT indexingStarted(); | ||
305 | 315 | | |||
306 | AbstractFileListing::triggerRefreshOfContent(); | 316 | AbstractFileListing::triggerRefreshOfContent(); | ||
307 | 317 | | |||
318 | const auto &rootPaths = allRootPaths(); | ||||
319 | bool hasSingleRootPath = (rootPaths.size() == 1); | ||||
320 | auto singleRootPath = rootPaths.at(0); | ||||
321 | | ||||
308 | auto resultIterator = d->mQuery.exec(); | 322 | auto resultIterator = d->mQuery.exec(); | ||
309 | auto newFiles = QList<MusicAudioTrack>(); | 323 | auto newFiles = QList<MusicAudioTrack>(); | ||
310 | 324 | | |||
311 | while(resultIterator.next() && d->mStopRequest == 0) { | 325 | while(resultIterator.next() && d->mStopRequest == 0) { | ||
312 | const auto &fileName = resultIterator.filePath(); | 326 | const auto &fileName = resultIterator.filePath(); | ||
327 | | ||||
328 | if (hasSingleRootPath) { | ||||
329 | if (!fileName.startsWith(singleRootPath)) { | ||||
330 | qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::triggerRefreshOfContent" << fileName << "does not match root paths"; | ||||
331 | continue; | ||||
332 | } | ||||
333 | } else { | ||||
334 | bool isIncluded = false; | ||||
335 | for (const auto &oneRootPath : rootPaths) { | ||||
336 | if (fileName.startsWith(oneRootPath)) { | ||||
337 | isIncluded = true; | ||||
338 | break; | ||||
339 | } | ||||
340 | } | ||||
341 | if (!isIncluded) { | ||||
342 | qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::triggerRefreshOfContent" << fileName << "does not match root paths"; | ||||
343 | continue; | ||||
344 | } | ||||
345 | } | ||||
346 | | ||||
313 | const auto &newFileUrl = QUrl::fromLocalFile(resultIterator.filePath()); | 347 | const auto &newFileUrl = QUrl::fromLocalFile(resultIterator.filePath()); | ||
314 | 348 | | |||
315 | auto scanFileInfo = QFileInfo(fileName); | 349 | auto scanFileInfo = QFileInfo(fileName); | ||
316 | 350 | | |||
317 | if (!scanFileInfo.exists()) { | 351 | if (!scanFileInfo.exists()) { | ||
352 | qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::triggerRefreshOfContent" << fileName << "file does not exists"; | ||||
318 | return; | 353 | return; | ||
319 | } | 354 | } | ||
320 | 355 | | |||
321 | auto itExistingFile = allFiles().find(newFileUrl); | 356 | auto itExistingFile = allFiles().find(newFileUrl); | ||
322 | if (itExistingFile != allFiles().end()) { | 357 | if (itExistingFile != allFiles().end()) { | ||
323 | if (*itExistingFile >= scanFileInfo.fileTime(QFile::FileModificationTime)) { | 358 | if (*itExistingFile >= scanFileInfo.fileTime(QFile::FileModificationTime)) { | ||
324 | allFiles().erase(itExistingFile); | 359 | allFiles().erase(itExistingFile); | ||
360 | qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::triggerRefreshOfContent" << fileName << "file not modified since last scan"; | ||||
325 | continue; | 361 | continue; | ||
326 | } | 362 | } | ||
327 | } | 363 | } | ||
328 | 364 | | |||
329 | const auto currentDirectory = QUrl::fromLocalFile(scanFileInfo.absoluteDir().absolutePath()); | 365 | const auto currentDirectory = QUrl::fromLocalFile(scanFileInfo.absoluteDir().absolutePath()); | ||
330 | 366 | | |||
331 | addFileInDirectory(newFileUrl, currentDirectory); | 367 | addFileInDirectory(newFileUrl, currentDirectory); | ||
332 | 368 | | |||
333 | const auto &newTrack = scanOneFile(newFileUrl, scanFileInfo); | 369 | const auto &newTrack = scanOneFile(newFileUrl, scanFileInfo); | ||
334 | 370 | | |||
335 | if (newTrack.isValid()) { | 371 | if (newTrack.isValid()) { | ||
336 | newFiles.push_back(newTrack); | 372 | newFiles.push_back(newTrack); | ||
337 | if (newFiles.size() > 500 && d->mStopRequest == 0) { | 373 | if (newFiles.size() > 500 && d->mStopRequest == 0) { | ||
374 | qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::triggerRefreshOfContent" << "insert new tracks in database" << newFiles.count(); | ||||
338 | emitNewFiles(newFiles); | 375 | emitNewFiles(newFiles); | ||
339 | newFiles.clear(); | 376 | newFiles.clear(); | ||
340 | } | 377 | } | ||
378 | } else { | ||||
379 | qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::triggerRefreshOfContent" << fileName << "invalid track" << newTrack; | ||||
341 | } | 380 | } | ||
342 | } | 381 | } | ||
343 | 382 | | |||
344 | if (!newFiles.isEmpty() && d->mStopRequest == 0) { | 383 | if (!newFiles.isEmpty() && d->mStopRequest == 0) { | ||
384 | qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::triggerRefreshOfContent" << "insert new tracks in database" << newFiles.count(); | ||||
345 | emitNewFiles(newFiles); | 385 | emitNewFiles(newFiles); | ||
346 | } | 386 | } | ||
347 | 387 | | |||
388 | setWaitEndTrackRemoval(false); | ||||
389 | | ||||
348 | checkFilesToRemove(); | 390 | checkFilesToRemove(); | ||
349 | 391 | | |||
392 | if (!waitEndTrackRemoval()) { | ||||
350 | Q_EMIT indexingFinished(); | 393 | Q_EMIT indexingFinished(); | ||
351 | } | 394 | } | ||
395 | } | ||||
352 | 396 | | |||
353 | MusicAudioTrack LocalBalooFileListing::scanOneFile(const QUrl &scanFile, const QFileInfo &scanFileInfo) | 397 | MusicAudioTrack LocalBalooFileListing::scanOneFile(const QUrl &scanFile, const QFileInfo &scanFileInfo) | ||
354 | { | 398 | { | ||
355 | auto newTrack = MusicAudioTrack(); | 399 | auto newTrack = MusicAudioTrack(); | ||
356 | 400 | | |||
357 | auto localFileName = scanFile.toLocalFile(); | 401 | auto localFileName = scanFile.toLocalFile(); | ||
358 | 402 | | |||
359 | Baloo::File match(localFileName); | 403 | Baloo::File match(localFileName); | ||
360 | 404 | | |||
361 | match.load(); | 405 | match.load(); | ||
362 | 406 | | |||
363 | newTrack.setFileModificationTime(scanFileInfo.fileTime(QFile::FileModificationTime)); | 407 | newTrack.setFileModificationTime(scanFileInfo.fileTime(QFile::FileModificationTime)); | ||
364 | newTrack.setResourceURI(scanFile); | 408 | newTrack.setResourceURI(scanFile); | ||
365 | 409 | | |||
366 | fileScanner().scanProperties(match, newTrack); | 410 | fileScanner().scanProperties(match, newTrack); | ||
367 | 411 | | |||
368 | if (!newTrack.isValid()) { | 412 | if (!newTrack.isValid()) { | ||
413 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::scanOneFile" << scanFile << "falling back to plain file metadata analysis"; | ||||
369 | newTrack = AbstractFileListing::scanOneFile(scanFile, scanFileInfo); | 414 | newTrack = AbstractFileListing::scanOneFile(scanFile, scanFileInfo); | ||
370 | } | 415 | } | ||
371 | 416 | | |||
372 | if (newTrack.isValid()) { | 417 | if (newTrack.isValid()) { | ||
373 | newTrack.setHasEmbeddedCover(checkEmbeddedCoverImage(localFileName)); | 418 | newTrack.setHasEmbeddedCover(checkEmbeddedCoverImage(localFileName)); | ||
374 | addCover(newTrack); | 419 | addCover(newTrack); | ||
375 | watchPath(localFileName); | 420 | watchPath(localFileName); | ||
376 | } | | |||
377 | | ||||
378 | return newTrack; | | |||
379 | } | | |||
380 | | ||||
381 | bool LocalBalooFileListing::checkBalooConfiguration() | | |||
382 | { | | |||
383 | bool problemDetected = false; | | |||
384 | Baloo::IndexerConfig balooConfiguration; | | |||
385 | | ||||
386 | problemDetected = problemDetected || !balooConfiguration.fileIndexingEnabled(); | | |||
387 | problemDetected = problemDetected || balooConfiguration.onlyBasicIndexing(); | | |||
388 | | ||||
389 | if (problemDetected) { | | |||
390 | NotificationItem balooInvalidConfiguration; | | |||
391 | | ||||
392 | balooInvalidConfiguration.setNotificationId(QStringLiteral("balooInvalidConfiguration")); | | |||
393 | | ||||
394 | balooInvalidConfiguration.setTargetObject(this); | | |||
395 | | ||||
396 | balooInvalidConfiguration.setMessage(i18nc("Notification about unusable Baloo Configuration", "Cannot discover music with the current file search settings")); | | |||
397 | | ||||
398 | balooInvalidConfiguration.setMainButtonText(i18nc("Text of button to modify Baloo Configuration", "Modify it")); | | |||
399 | balooInvalidConfiguration.setMainButtonIconName(QStringLiteral("configure")); | | |||
400 | balooInvalidConfiguration.setMainButtonMethodName(QStringLiteral("fixBalooConfiguration")); | | |||
401 | | ||||
402 | balooInvalidConfiguration.setSecondaryButtonText(i18nc("Text of button to disable Baloo indexer", "Disable Baloo support")); | | |||
403 | balooInvalidConfiguration.setSecondaryButtonIconName(QStringLiteral("configure")); | | |||
404 | balooInvalidConfiguration.setSecondaryButtonMethodName(QStringLiteral("disableBalooIndexer")); | | |||
405 | | ||||
406 | Q_EMIT newNotification(balooInvalidConfiguration); | | |||
407 | } else { | 421 | } else { | ||
408 | Q_EMIT closeNotification(QStringLiteral("balooInvalidConfiguration")); | 422 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::scanOneFile" << scanFile << "invalid track"; | ||
409 | } | | |||
410 | | ||||
411 | return !problemDetected; | | |||
412 | } | | |||
413 | | ||||
414 | void LocalBalooFileListing::fixBalooConfiguration() | | |||
415 | { | | |||
416 | qDebug() << "LocalBalooFileListing::fixBalooConfiguration"; | | |||
417 | | ||||
418 | Baloo::IndexerConfig balooConfiguration; | | |||
419 | | ||||
420 | if (!balooConfiguration.fileIndexingEnabled()) { | | |||
421 | balooConfiguration.setFileIndexingEnabled(true); | | |||
422 | } | | |||
423 | | ||||
424 | if (balooConfiguration.onlyBasicIndexing()) { | | |||
425 | balooConfiguration.setOnlyBasicIndexing(false); | | |||
426 | } | 423 | } | ||
427 | 424 | | |||
428 | balooConfiguration.refresh(); | 425 | return newTrack; | ||
429 | | ||||
430 | if (checkBalooConfiguration()) { | | |||
431 | triggerRefreshOfContent(); | | |||
432 | } | | |||
433 | } | | |||
434 | | ||||
435 | void LocalBalooFileListing::disableBalooIndexer() | | |||
436 | { | | |||
437 | Elisa::ElisaConfiguration::self()->setBalooIndexer(false); | | |||
438 | Elisa::ElisaConfiguration::self()->save(); | | |||
439 | } | 426 | } | ||
440 | 427 | | |||
441 | 428 | | |||
442 | #include "moc_localbaloofilelisting.cpp" | 429 | #include "moc_localbaloofilelisting.cpp" |