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 | Q_EMIT indexingStarted(); | ||||
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 | | |||
135 | auto newFile = QUrl::fromLocalFile(fileName); | 139 | auto newFile = QUrl::fromLocalFile(fileName); | ||
136 | 140 | | |||
137 | auto newTrack = scanOneFile(newFile, scanFileInfo); | 141 | auto newTrack = scanOneFile(newFile, scanFileInfo); | ||
138 | 142 | | |||
139 | if (newTrack.isValid()) { | 143 | if (newTrack.isValid()) { | ||
140 | QFileInfo newFileInfo(fileName); | 144 | QFileInfo newFileInfo(fileName); | ||
141 | 145 | | |||
142 | addFileInDirectory(newFile, QUrl::fromLocalFile(newFileInfo.absoluteDir().absolutePath())); | 146 | addFileInDirectory(newFile, QUrl::fromLocalFile(newFileInfo.absoluteDir().absolutePath())); | ||
143 | 147 | | |||
144 | emitNewFiles({newTrack}); | 148 | emitNewFiles({newTrack}); | ||
145 | } | 149 | } | ||
150 | | ||||
151 | Q_EMIT indexingFinished(); | ||||
146 | } | 152 | } | ||
147 | 153 | | |||
148 | void LocalBalooFileListing::registeredToBaloo(QDBusPendingCallWatcher *watcher) | 154 | void LocalBalooFileListing::registeredToBaloo(QDBusPendingCallWatcher *watcher) | ||
149 | { | 155 | { | ||
150 | qDebug() << "LocalBalooFileListing::registeredToBaloo"; | 156 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registeredToBaloo"; | ||
151 | 157 | | |||
152 | if (!watcher) { | 158 | if (!watcher) { | ||
153 | return; | 159 | return; | ||
154 | } | 160 | } | ||
155 | 161 | | |||
156 | QDBusPendingReply<> reply = *watcher; | 162 | QDBusPendingReply<> reply = *watcher; | ||
157 | if (reply.isError()) { | 163 | if (reply.isError()) { | ||
158 | qDebug() << "LocalBalooFileListing::registeredToBaloo" << reply.error().name() << reply.error().message(); | 164 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registeredToBaloo" << reply.error().name() << reply.error().message(); | ||
159 | d->mIsRegisteredToBaloo = false; | 165 | d->mIsRegisteredToBaloo = false; | ||
160 | } else { | 166 | } else { | ||
161 | d->mIsRegisteredToBaloo = true; | 167 | d->mIsRegisteredToBaloo = true; | ||
162 | } | 168 | } | ||
163 | 169 | | |||
164 | d->mIsRegisteringToBaloo = false; | 170 | d->mIsRegisteringToBaloo = false; | ||
165 | 171 | | |||
166 | watcher->deleteLater(); | 172 | watcher->deleteLater(); | ||
167 | } | 173 | } | ||
168 | 174 | | |||
169 | void LocalBalooFileListing::registeredToBalooWatcher(QDBusPendingCallWatcher *watcher) | 175 | void LocalBalooFileListing::registeredToBalooWatcher(QDBusPendingCallWatcher *watcher) | ||
170 | { | 176 | { | ||
171 | qDebug() << "LocalBalooFileListing::registeredToBalooWatcher"; | 177 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registeredToBalooWatcher"; | ||
172 | 178 | | |||
173 | if (!watcher) { | 179 | if (!watcher) { | ||
174 | return; | 180 | return; | ||
175 | } | 181 | } | ||
176 | 182 | | |||
177 | QDBusPendingReply<> reply = *watcher; | 183 | QDBusPendingReply<> reply = *watcher; | ||
178 | if (reply.isError()) { | 184 | if (reply.isError()) { | ||
179 | qDebug() << "LocalBalooFileListing::registeredToBalooWatcher" << reply.error().name() << reply.error().message(); | 185 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registeredToBalooWatcher" << reply.error().name() << reply.error().message(); | ||
180 | d->mIsRegisteredToBalooWatcher = false; | 186 | d->mIsRegisteredToBalooWatcher = false; | ||
181 | } else { | 187 | } else { | ||
182 | d->mIsRegisteredToBalooWatcher = true; | 188 | d->mIsRegisteredToBalooWatcher = true; | ||
183 | } | 189 | } | ||
184 | 190 | | |||
185 | d->mIsRegisteringToBalooWatcher = false; | 191 | d->mIsRegisteringToBalooWatcher = false; | ||
186 | 192 | | |||
187 | watcher->deleteLater(); | 193 | watcher->deleteLater(); | ||
188 | } | 194 | } | ||
189 | 195 | | |||
190 | void LocalBalooFileListing::registerToBaloo() | 196 | void LocalBalooFileListing::registerToBaloo() | ||
191 | { | 197 | { | ||
192 | if (d->mIsRegisteringToBaloo || d->mIsRegisteringToBalooWatcher) { | 198 | if (d->mIsRegisteringToBaloo || d->mIsRegisteringToBalooWatcher) { | ||
193 | qDebug() << "LocalBalooFileListing::registerToBaloo" << "already registering"; | 199 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registerToBaloo" << "already registering"; | ||
194 | return; | 200 | return; | ||
195 | } | 201 | } | ||
196 | 202 | | |||
197 | qDebug() << "LocalBalooFileListing::registerToBaloo"; | 203 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registerToBaloo"; | ||
198 | 204 | | |||
199 | d->mIsRegisteringToBaloo = true; | 205 | d->mIsRegisteringToBaloo = true; | ||
200 | d->mIsRegisteringToBalooWatcher = true; | 206 | d->mIsRegisteringToBalooWatcher = true; | ||
201 | 207 | | |||
202 | auto sessionBus = QDBusConnection::sessionBus(); | 208 | auto sessionBus = QDBusConnection::sessionBus(); | ||
203 | 209 | | |||
204 | d->mBalooMainInterface.reset(new org::kde::baloo::main(QStringLiteral("org.kde.baloo"), QStringLiteral("/"), | 210 | d->mBalooMainInterface.reset(new org::kde::baloo::main(QStringLiteral("org.kde.baloo"), QStringLiteral("/"), | ||
205 | sessionBus, this)); | 211 | sessionBus, this)); | ||
206 | 212 | | |||
207 | if (!d->mBalooMainInterface->isValid()) { | 213 | if (!d->mBalooMainInterface->isValid()) { | ||
208 | qDebug() << "LocalBalooFileListing::registerToBaloo" << "invalid org.kde.baloo/main interface"; | 214 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registerToBaloo" << "invalid org.kde.baloo/main interface"; | ||
209 | return; | 215 | return; | ||
210 | } | 216 | } | ||
211 | 217 | | |||
212 | d->mBalooIndexer.reset(new org::kde::baloo::fileindexer(QStringLiteral("org.kde.baloo"), QStringLiteral("/fileindexer"), | 218 | d->mBalooIndexer.reset(new org::kde::baloo::fileindexer(QStringLiteral("org.kde.baloo"), QStringLiteral("/fileindexer"), | ||
213 | sessionBus, this)); | 219 | sessionBus, this)); | ||
214 | 220 | | |||
215 | if (!d->mBalooIndexer->isValid()) { | 221 | if (!d->mBalooIndexer->isValid()) { | ||
216 | qDebug() << "LocalBalooFileListing::registerToBaloo" << "invalid org.kde.baloo/fileindexer interface"; | 222 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registerToBaloo" << "invalid org.kde.baloo/fileindexer interface"; | ||
217 | return; | 223 | return; | ||
218 | } | 224 | } | ||
219 | 225 | | |||
220 | connect(d->mBalooIndexer.data(), &org::kde::baloo::fileindexer::finishedIndexingFile, | 226 | connect(d->mBalooIndexer.data(), &org::kde::baloo::fileindexer::finishedIndexingFile, | ||
221 | this, &LocalBalooFileListing::newBalooFile); | 227 | this, &LocalBalooFileListing::newBalooFile); | ||
222 | 228 | | |||
223 | d->mBalooScheduler.reset(new org::kde::baloo::scheduler(QStringLiteral("org.kde.baloo"), QStringLiteral("/scheduler"), | 229 | d->mBalooScheduler.reset(new org::kde::baloo::scheduler(QStringLiteral("org.kde.baloo"), QStringLiteral("/scheduler"), | ||
224 | sessionBus, this)); | 230 | sessionBus, this)); | ||
225 | 231 | | |||
226 | if (!d->mBalooScheduler->isValid()) { | 232 | if (!d->mBalooScheduler->isValid()) { | ||
227 | qDebug() << "LocalBalooFileListing::registerToBaloo" << "invalid org.kde.baloo/scheduler interface"; | 233 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registerToBaloo" << "invalid org.kde.baloo/scheduler interface"; | ||
228 | return; | 234 | return; | ||
229 | } | 235 | } | ||
230 | 236 | | |||
231 | qDebug() << "LocalBalooFileListing::registerToBaloo" << "call registerMonitor"; | 237 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registerToBaloo" << "call registerMonitor"; | ||
232 | auto answer = d->mBalooIndexer->registerMonitor(); | 238 | auto answer = d->mBalooIndexer->registerMonitor(); | ||
233 | 239 | | |||
234 | if (answer.isError()) { | 240 | if (answer.isError()) { | ||
235 | qDebug() << "LocalBalooFileListing::executeInit" << answer.error().name() << answer.error().message(); | 241 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::executeInit" << answer.error().name() << answer.error().message(); | ||
236 | } | 242 | } | ||
237 | 243 | | |||
238 | auto pendingCallWatcher = new QDBusPendingCallWatcher(answer); | 244 | auto pendingCallWatcher = new QDBusPendingCallWatcher(answer); | ||
239 | 245 | | |||
240 | connect(pendingCallWatcher, &QDBusPendingCallWatcher::finished, this, &LocalBalooFileListing::registeredToBaloo); | 246 | connect(pendingCallWatcher, &QDBusPendingCallWatcher::finished, this, &LocalBalooFileListing::registeredToBaloo); | ||
241 | if (pendingCallWatcher->isFinished()) { | 247 | if (pendingCallWatcher->isFinished()) { | ||
242 | registeredToBaloo(pendingCallWatcher); | 248 | registeredToBaloo(pendingCallWatcher); | ||
243 | } | 249 | } | ||
244 | 250 | | |||
245 | auto pendingCall = d->mBalooMainInterface->registerBalooWatcher(QStringLiteral("org.mpris.MediaPlayer2.elisa/org/kde/BalooWatcherApplication")); | 251 | auto pendingCall = d->mBalooMainInterface->registerBalooWatcher(QStringLiteral("org.mpris.MediaPlayer2.elisa/org/kde/BalooWatcherApplication")); | ||
246 | qDebug() << "LocalBalooFileListing::registerToBaloo" << "call registerBalooWatcher"; | 252 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::registerToBaloo" << "call registerBalooWatcher"; | ||
247 | auto pendingCallWatcher2 = new QDBusPendingCallWatcher(pendingCall); | 253 | auto pendingCallWatcher2 = new QDBusPendingCallWatcher(pendingCall); | ||
248 | 254 | | |||
249 | connect(pendingCallWatcher2, &QDBusPendingCallWatcher::finished, this, &LocalBalooFileListing::registeredToBalooWatcher); | 255 | connect(pendingCallWatcher2, &QDBusPendingCallWatcher::finished, this, &LocalBalooFileListing::registeredToBalooWatcher); | ||
250 | if (pendingCallWatcher2->isFinished()) { | 256 | if (pendingCallWatcher2->isFinished()) { | ||
251 | registeredToBalooWatcher(pendingCallWatcher2); | 257 | registeredToBalooWatcher(pendingCallWatcher2); | ||
252 | } | 258 | } | ||
253 | } | 259 | } | ||
254 | 260 | | |||
255 | void LocalBalooFileListing::renamedFiles(const QString &from, const QString &to, const QStringList &listFiles) | 261 | void LocalBalooFileListing::renamedFiles(const QString &from, const QString &to, const QStringList &listFiles) | ||
256 | { | 262 | { | ||
257 | qDebug() << "LocalBalooFileListing::renamedFiles" << from << to << listFiles; | 263 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::renamedFiles" << from << to << listFiles; | ||
258 | } | 264 | } | ||
259 | 265 | | |||
260 | void LocalBalooFileListing::serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner) | 266 | void LocalBalooFileListing::serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner) | ||
261 | { | 267 | { | ||
262 | Q_UNUSED(oldOwner); | 268 | Q_UNUSED(oldOwner); | ||
263 | Q_UNUSED(newOwner); | 269 | Q_UNUSED(newOwner); | ||
264 | 270 | | |||
265 | qDebug() << "LocalBalooFileListing::serviceOwnerChanged" << serviceName << oldOwner << newOwner; | 271 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::serviceOwnerChanged" << serviceName << oldOwner << newOwner; | ||
266 | 272 | | |||
267 | if (serviceName == QStringLiteral("org.kde.baloo") && !newOwner.isEmpty()) { | 273 | if (serviceName == QStringLiteral("org.kde.baloo") && !newOwner.isEmpty()) { | ||
268 | d->mIsRegisteredToBaloo = false; | 274 | d->mIsRegisteredToBaloo = false; | ||
269 | d->mIsRegisteredToBalooWatcher = false; | 275 | d->mIsRegisteredToBalooWatcher = false; | ||
270 | registerToBaloo(); | 276 | registerToBaloo(); | ||
271 | } | 277 | } | ||
272 | } | 278 | } | ||
273 | 279 | | |||
274 | void LocalBalooFileListing::serviceRegistered(const QString &serviceName) | 280 | void LocalBalooFileListing::serviceRegistered(const QString &serviceName) | ||
275 | { | 281 | { | ||
276 | qDebug() << "LocalBalooFileListing::serviceRegistered" << serviceName; | 282 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::serviceRegistered" << serviceName; | ||
277 | 283 | | |||
278 | if (serviceName == QStringLiteral("org.kde.baloo")) { | 284 | if (serviceName == QStringLiteral("org.kde.baloo")) { | ||
279 | registerToBaloo(); | 285 | registerToBaloo(); | ||
280 | } | 286 | } | ||
281 | } | 287 | } | ||
282 | 288 | | |||
283 | void LocalBalooFileListing::serviceUnregistered(const QString &serviceName) | 289 | void LocalBalooFileListing::serviceUnregistered(const QString &serviceName) | ||
284 | { | 290 | { | ||
285 | qDebug() << "LocalBalooFileListing::serviceUnregistered" << serviceName; | 291 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::serviceUnregistered" << serviceName; | ||
286 | 292 | | |||
287 | if (serviceName == QStringLiteral("org.kde.baloo")) { | 293 | if (serviceName == QStringLiteral("org.kde.baloo")) { | ||
288 | d->mIsRegisteredToBaloo = false; | 294 | d->mIsRegisteredToBaloo = false; | ||
289 | d->mIsRegisteredToBalooWatcher = false; | 295 | d->mIsRegisteredToBalooWatcher = false; | ||
290 | } | 296 | } | ||
291 | } | 297 | } | ||
292 | 298 | | |||
293 | void LocalBalooFileListing::executeInit(QHash<QUrl, QDateTime> allFiles) | 299 | void LocalBalooFileListing::executeInit(QHash<QUrl, QDateTime> allFiles) | ||
294 | { | 300 | { | ||
295 | AbstractFileListing::executeInit(std::move(allFiles)); | 301 | AbstractFileListing::executeInit(std::move(allFiles)); | ||
296 | } | 302 | } | ||
297 | 303 | | |||
298 | void LocalBalooFileListing::triggerRefreshOfContent() | 304 | void LocalBalooFileListing::triggerRefreshOfContent() | ||
299 | { | 305 | { | ||
300 | if (!checkBalooConfiguration()) { | | |||
301 | return; | | |||
302 | } | | |||
303 | | ||||
304 | Q_EMIT indexingStarted(); | 306 | Q_EMIT indexingStarted(); | ||
305 | 307 | | |||
306 | AbstractFileListing::triggerRefreshOfContent(); | 308 | AbstractFileListing::triggerRefreshOfContent(); | ||
307 | 309 | | |||
310 | const auto &rootPaths = allRootPaths(); | ||||
311 | bool hasSingleRootPath = (rootPaths.size() == 1); | ||||
312 | auto singleRootPath = rootPaths.at(0); | ||||
313 | | ||||
308 | auto resultIterator = d->mQuery.exec(); | 314 | auto resultIterator = d->mQuery.exec(); | ||
309 | auto newFiles = QList<MusicAudioTrack>(); | 315 | auto newFiles = QList<MusicAudioTrack>(); | ||
310 | 316 | | |||
311 | while(resultIterator.next() && d->mStopRequest == 0) { | 317 | while(resultIterator.next() && d->mStopRequest == 0) { | ||
312 | const auto &fileName = resultIterator.filePath(); | 318 | const auto &fileName = resultIterator.filePath(); | ||
319 | | ||||
320 | if (hasSingleRootPath) { | ||||
321 | if (!fileName.startsWith(singleRootPath)) { | ||||
322 | continue; | ||||
323 | } | ||||
324 | } else { | ||||
325 | bool isIncluded = false; | ||||
326 | for (const auto &oneRootPath : rootPaths) { | ||||
327 | if (fileName.startsWith(oneRootPath)) { | ||||
328 | isIncluded = true; | ||||
329 | break; | ||||
330 | } | ||||
331 | } | ||||
332 | if (!isIncluded) { | ||||
333 | continue; | ||||
334 | } | ||||
335 | } | ||||
336 | | ||||
313 | const auto &newFileUrl = QUrl::fromLocalFile(resultIterator.filePath()); | 337 | const auto &newFileUrl = QUrl::fromLocalFile(resultIterator.filePath()); | ||
314 | 338 | | |||
315 | auto scanFileInfo = QFileInfo(fileName); | 339 | auto scanFileInfo = QFileInfo(fileName); | ||
316 | 340 | | |||
317 | if (!scanFileInfo.exists()) { | 341 | if (!scanFileInfo.exists()) { | ||
318 | return; | 342 | return; | ||
319 | } | 343 | } | ||
320 | 344 | | |||
Show All 19 Lines | 359 | if (newTrack.isValid()) { | |||
340 | } | 364 | } | ||
341 | } | 365 | } | ||
342 | } | 366 | } | ||
343 | 367 | | |||
344 | if (!newFiles.isEmpty() && d->mStopRequest == 0) { | 368 | if (!newFiles.isEmpty() && d->mStopRequest == 0) { | ||
345 | emitNewFiles(newFiles); | 369 | emitNewFiles(newFiles); | ||
346 | } | 370 | } | ||
347 | 371 | | |||
372 | setWaitEndTrackRemoval(false); | ||||
373 | | ||||
348 | checkFilesToRemove(); | 374 | checkFilesToRemove(); | ||
349 | 375 | | |||
376 | if (!waitEndTrackRemoval()) { | ||||
350 | Q_EMIT indexingFinished(); | 377 | Q_EMIT indexingFinished(); | ||
351 | } | 378 | } | ||
379 | } | ||||
352 | 380 | | |||
353 | MusicAudioTrack LocalBalooFileListing::scanOneFile(const QUrl &scanFile, const QFileInfo &scanFileInfo) | 381 | MusicAudioTrack LocalBalooFileListing::scanOneFile(const QUrl &scanFile, const QFileInfo &scanFileInfo) | ||
354 | { | 382 | { | ||
355 | auto newTrack = MusicAudioTrack(); | 383 | auto newTrack = MusicAudioTrack(); | ||
356 | 384 | | |||
385 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::scanOneFile" << scanFile; | ||||
386 | | ||||
357 | auto localFileName = scanFile.toLocalFile(); | 387 | auto localFileName = scanFile.toLocalFile(); | ||
358 | 388 | | |||
359 | Baloo::File match(localFileName); | 389 | Baloo::File match(localFileName); | ||
360 | 390 | | |||
361 | match.load(); | 391 | match.load(); | ||
362 | 392 | | |||
363 | newTrack.setFileModificationTime(scanFileInfo.fileTime(QFile::FileModificationTime)); | 393 | newTrack.setFileModificationTime(scanFileInfo.fileTime(QFile::FileModificationTime)); | ||
364 | newTrack.setResourceURI(scanFile); | 394 | newTrack.setResourceURI(scanFile); | ||
365 | 395 | | |||
366 | fileScanner().scanProperties(match, newTrack); | 396 | fileScanner().scanProperties(match, newTrack); | ||
367 | 397 | | |||
368 | if (!newTrack.isValid()) { | 398 | if (!newTrack.isValid()) { | ||
399 | qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::scanOneFile" << scanFile << "falling back to plain file metadata analysis"; | ||||
369 | newTrack = AbstractFileListing::scanOneFile(scanFile, scanFileInfo); | 400 | newTrack = AbstractFileListing::scanOneFile(scanFile, scanFileInfo); | ||
370 | } | 401 | } | ||
371 | 402 | | |||
372 | if (newTrack.isValid()) { | 403 | if (newTrack.isValid()) { | ||
373 | newTrack.setHasEmbeddedCover(checkEmbeddedCoverImage(localFileName)); | 404 | newTrack.setHasEmbeddedCover(checkEmbeddedCoverImage(localFileName)); | ||
374 | addCover(newTrack); | 405 | addCover(newTrack); | ||
375 | watchPath(localFileName); | 406 | watchPath(localFileName); | ||
376 | } | 407 | } | ||
377 | 408 | | |||
378 | return newTrack; | 409 | return newTrack; | ||
379 | } | 410 | } | ||
380 | 411 | | |||
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 { | | |||
408 | Q_EMIT closeNotification(QStringLiteral("balooInvalidConfiguration")); | | |||
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 | } | | |||
427 | | ||||
428 | balooConfiguration.refresh(); | | |||
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 | } | | |||
440 | | ||||
441 | 412 | | |||
442 | #include "moc_localbaloofilelisting.cpp" | 413 | #include "moc_localbaloofilelisting.cpp" |