Changeset View
Changeset View
Standalone View
Standalone View
src/musiclistenersmanager.cpp
Show All 13 Lines | |||||
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 "musiclistenersmanager.h" | 18 | #include "musiclistenersmanager.h" | ||
19 | 19 | | |||
20 | #include "config-upnp-qt.h" | 20 | #include "config-upnp-qt.h" | ||
21 | 21 | | |||
22 | #include "indexersManager.h" | ||||
23 | | ||||
22 | #if defined UPNPQT_FOUND && UPNPQT_FOUND | 24 | #if defined UPNPQT_FOUND && UPNPQT_FOUND | ||
23 | #include "upnp/upnplistener.h" | 25 | #include "upnp/upnplistener.h" | ||
24 | #endif | 26 | #endif | ||
25 | 27 | | |||
26 | #if defined KF5Baloo_FOUND && KF5Baloo_FOUND | 28 | #if defined KF5Baloo_FOUND && KF5Baloo_FOUND | ||
27 | #include "baloo/baloolistener.h" | 29 | #include "baloo/baloolistener.h" | ||
30 | #include "baloo/baloodetector.h" | ||||
28 | #endif | 31 | #endif | ||
29 | 32 | | |||
30 | #if defined Qt5AndroidExtras_FOUND && Qt5AndroidExtras_FOUND | 33 | #if defined Qt5AndroidExtras_FOUND && Qt5AndroidExtras_FOUND | ||
31 | #include "android/androidmusiclistener.h" | 34 | #include "android/androidmusiclistener.h" | ||
32 | #endif | 35 | #endif | ||
33 | 36 | | |||
34 | #include "databaseinterface.h" | 37 | #include "databaseinterface.h" | ||
35 | #include "mediaplaylist.h" | 38 | #include "mediaplaylist.h" | ||
Show All 11 Lines | |||||
47 | #include <QMutex> | 50 | #include <QMutex> | ||
48 | #include <QStandardPaths> | 51 | #include <QStandardPaths> | ||
49 | #include <QDir> | 52 | #include <QDir> | ||
50 | #include <QCoreApplication> | 53 | #include <QCoreApplication> | ||
51 | #include <QList> | 54 | #include <QList> | ||
52 | #include <QScopedPointer> | 55 | #include <QScopedPointer> | ||
53 | #include <QPointer> | 56 | #include <QPointer> | ||
54 | #include <QFileSystemWatcher> | 57 | #include <QFileSystemWatcher> | ||
55 | | ||||
56 | #include <QAction> | 58 | #include <QAction> | ||
57 | 59 | | |||
60 | #include <QDebug> | ||||
61 | | ||||
58 | #include <list> | 62 | #include <list> | ||
59 | 63 | | |||
60 | class MusicListenersManagerPrivate | 64 | class MusicListenersManagerPrivate | ||
61 | { | 65 | { | ||
62 | public: | 66 | public: | ||
63 | 67 | | |||
64 | QThread mDatabaseThread; | 68 | QThread mDatabaseThread; | ||
65 | 69 | | |||
66 | QThread mListenerThread; | 70 | QThread mListenerThread; | ||
67 | 71 | | |||
68 | #if defined UPNPQT_FOUND && UPNPQT_FOUND | 72 | #if defined UPNPQT_FOUND && UPNPQT_FOUND | ||
69 | UpnpListener mUpnpListener; | 73 | UpnpListener mUpnpListener; | ||
70 | #endif | 74 | #endif | ||
71 | 75 | | |||
72 | #if defined KF5Baloo_FOUND && KF5Baloo_FOUND | 76 | #if defined KF5Baloo_FOUND && KF5Baloo_FOUND | ||
73 | std::unique_ptr<BalooListener> mBalooListener; | 77 | BalooDetector mBalooDetector; | ||
78 | | ||||
79 | BalooListener mBalooListener; | ||||
74 | #endif | 80 | #endif | ||
75 | 81 | | |||
76 | std::list<std::unique_ptr<FileListener>> mFileListener; | 82 | FileListener mFileListener; | ||
77 | 83 | | |||
78 | #if defined Qt5AndroidExtras_FOUND && Qt5AndroidExtras_FOUND | 84 | #if defined Qt5AndroidExtras_FOUND && Qt5AndroidExtras_FOUND | ||
79 | std::unique_ptr<AndroidMusicListener> mAndroidMusicListener; | 85 | std::unique_ptr<AndroidMusicListener> mAndroidMusicListener; | ||
80 | #endif | 86 | #endif | ||
81 | 87 | | |||
82 | DatabaseInterface mDatabaseInterface; | 88 | DatabaseInterface mDatabaseInterface; | ||
83 | 89 | | |||
84 | std::unique_ptr<TracksListener> mTracksListener; | 90 | std::unique_ptr<TracksListener> mTracksListener; | ||
85 | 91 | | |||
86 | QFileSystemWatcher mConfigFileWatcher; | 92 | QFileSystemWatcher mConfigFileWatcher; | ||
87 | 93 | | |||
88 | ElisaApplication *mElisaApplication = nullptr; | 94 | ElisaApplication *mElisaApplication = nullptr; | ||
89 | 95 | | |||
90 | int mImportedTracksCount = 0; | 96 | int mImportedTracksCount = 0; | ||
91 | 97 | | |||
92 | int mActiveMusicListenersCount = 0; | 98 | bool mIndexerBusy = false; | ||
93 | 99 | | |||
94 | bool mIndexingRunning = false; | 100 | bool mFileSystemIndexerActive = false; | ||
95 | 101 | | |||
96 | bool mIndexerBusy = false; | 102 | bool mBalooIndexerActive = false; | ||
103 | | ||||
104 | bool mBalooIndexerAvailable = false; | ||||
105 | | ||||
106 | bool mAndroidIndexerActive = false; | ||||
107 | | ||||
108 | bool mAndroidIndexerAvailable = false; | ||||
97 | 109 | | |||
98 | }; | 110 | }; | ||
99 | 111 | | |||
100 | MusicListenersManager::MusicListenersManager(QObject *parent) | 112 | MusicListenersManager::MusicListenersManager(QObject *parent) | ||
101 | : QObject(parent), d(std::make_unique<MusicListenersManagerPrivate>()) | 113 | : QObject(parent), d(std::make_unique<MusicListenersManagerPrivate>()) | ||
102 | { | 114 | { | ||
103 | d->mListenerThread.start(); | 115 | d->mListenerThread.start(); | ||
104 | d->mDatabaseThread.start(); | 116 | d->mDatabaseThread.start(); | ||
Show All 37 Lines | 148 | if (initialRootPath.isEmpty()) { | |||
142 | Elisa::ElisaConfiguration::setRootPath(initialRootPath); | 154 | Elisa::ElisaConfiguration::setRootPath(initialRootPath); | ||
143 | Elisa::ElisaConfiguration::self()->save(); | 155 | Elisa::ElisaConfiguration::self()->save(); | ||
144 | } | 156 | } | ||
145 | 157 | | |||
146 | d->mConfigFileWatcher.addPath(Elisa::ElisaConfiguration::self()->config()->name()); | 158 | d->mConfigFileWatcher.addPath(Elisa::ElisaConfiguration::self()->config()->name()); | ||
147 | 159 | | |||
148 | connect(&d->mDatabaseInterface, &DatabaseInterface::tracksAdded, | 160 | connect(&d->mDatabaseInterface, &DatabaseInterface::tracksAdded, | ||
149 | this, &MusicListenersManager::increaseImportedTracksCount); | 161 | this, &MusicListenersManager::increaseImportedTracksCount); | ||
162 | | ||||
163 | #if defined KF5Baloo_FOUND && KF5Baloo_FOUND | ||||
164 | connect(&d->mBalooDetector, &BalooDetector::balooAvailabilityChanged, | ||||
165 | this, &MusicListenersManager::balooAvailabilityChanged); | ||||
166 | #endif | ||||
167 | | ||||
168 | qCInfo(orgKdeElisaIndexersManager) << "Local file system indexer is inactive"; | ||||
169 | qCInfo(orgKdeElisaIndexersManager) << "Baloo indexer is unavailable"; | ||||
170 | qCInfo(orgKdeElisaIndexersManager) << "Baloo indexer is inactive"; | ||||
150 | } | 171 | } | ||
151 | 172 | | |||
152 | MusicListenersManager::~MusicListenersManager() | 173 | MusicListenersManager::~MusicListenersManager() | ||
153 | = default; | 174 | = default; | ||
154 | 175 | | |||
155 | DatabaseInterface *MusicListenersManager::viewDatabase() const | 176 | DatabaseInterface *MusicListenersManager::viewDatabase() const | ||
156 | { | 177 | { | ||
157 | return &d->mDatabaseInterface; | 178 | return &d->mDatabaseInterface; | ||
Show All 9 Lines | 182 | { | |||
167 | connect(client, &MediaPlayList::newTrackByNameInList, d->mTracksListener.get(), &TracksListener::trackByNameInList); | 188 | connect(client, &MediaPlayList::newTrackByNameInList, d->mTracksListener.get(), &TracksListener::trackByNameInList); | ||
168 | } | 189 | } | ||
169 | 190 | | |||
170 | int MusicListenersManager::importedTracksCount() const | 191 | int MusicListenersManager::importedTracksCount() const | ||
171 | { | 192 | { | ||
172 | return d->mImportedTracksCount; | 193 | return d->mImportedTracksCount; | ||
173 | } | 194 | } | ||
174 | 195 | | |||
175 | bool MusicListenersManager::isIndexingRunning() const | | |||
176 | { | | |||
177 | return d->mIndexingRunning; | | |||
178 | } | | |||
179 | | ||||
180 | ElisaApplication *MusicListenersManager::elisaApplication() const | 196 | ElisaApplication *MusicListenersManager::elisaApplication() const | ||
181 | { | 197 | { | ||
182 | return d->mElisaApplication; | 198 | return d->mElisaApplication; | ||
183 | } | 199 | } | ||
184 | 200 | | |||
185 | bool MusicListenersManager::indexerBusy() const | 201 | bool MusicListenersManager::indexerBusy() const | ||
186 | { | 202 | { | ||
187 | return d->mIndexerBusy; | 203 | return d->mIndexerBusy; | ||
188 | } | 204 | } | ||
189 | 205 | | |||
190 | void MusicListenersManager::databaseReady() | 206 | bool MusicListenersManager::fileSystemIndexerActive() const | ||
191 | { | 207 | { | ||
192 | d->mIndexerBusy = true; | 208 | return d->mFileSystemIndexerActive; | ||
193 | Q_EMIT indexerBusyChanged(); | 209 | } | ||
194 | 210 | | |||
211 | bool MusicListenersManager::balooIndexerActive() const | ||||
212 | { | ||||
213 | return d->mBalooIndexerActive; | ||||
214 | } | ||||
215 | | ||||
216 | bool MusicListenersManager::balooIndexerAvailable() const | ||||
217 | { | ||||
218 | return d->mBalooIndexerAvailable; | ||||
219 | } | ||||
220 | | ||||
221 | bool MusicListenersManager::androidIndexerActive() const | ||||
222 | { | ||||
223 | return d->mAndroidIndexerActive; | ||||
224 | } | ||||
225 | | ||||
226 | bool MusicListenersManager::androidIndexerAvailable() const | ||||
227 | { | ||||
228 | return d->mAndroidIndexerAvailable; | ||||
229 | } | ||||
230 | | ||||
231 | void MusicListenersManager::databaseReady() | ||||
232 | { | ||||
195 | configChanged(); | 233 | configChanged(); | ||
196 | } | 234 | } | ||
197 | 235 | | |||
198 | void MusicListenersManager::applicationAboutToQuit() | 236 | void MusicListenersManager::applicationAboutToQuit() | ||
199 | { | 237 | { | ||
200 | d->mDatabaseInterface.applicationAboutToQuit(); | 238 | d->mDatabaseInterface.applicationAboutToQuit(); | ||
201 | 239 | | |||
202 | Q_EMIT applicationIsTerminating(); | 240 | Q_EMIT applicationIsTerminating(); | ||
Show All 19 Lines | 257 | { | |||
222 | } | 260 | } | ||
223 | 261 | | |||
224 | d->mElisaApplication = elisaApplication; | 262 | d->mElisaApplication = elisaApplication; | ||
225 | emit elisaApplicationChanged(); | 263 | emit elisaApplicationChanged(); | ||
226 | } | 264 | } | ||
227 | 265 | | |||
228 | void MusicListenersManager::playBackError(const QUrl &sourceInError, QMediaPlayer::Error playerError) | 266 | void MusicListenersManager::playBackError(const QUrl &sourceInError, QMediaPlayer::Error playerError) | ||
229 | { | 267 | { | ||
230 | qDebug() << "MusicListenersManager::playBackError" << sourceInError; | 268 | qCDebug(orgKdeElisaIndexersManager) << "MusicListenersManager::playBackError" << sourceInError; | ||
231 | 269 | | |||
232 | if (playerError == QMediaPlayer::ResourceError) { | 270 | if (playerError == QMediaPlayer::ResourceError) { | ||
233 | Q_EMIT removeTracksInError({sourceInError}); | 271 | Q_EMIT removeTracksInError({sourceInError}); | ||
234 | 272 | | |||
235 | if (sourceInError.isLocalFile()) { | 273 | if (sourceInError.isLocalFile()) { | ||
236 | Q_EMIT displayTrackError(sourceInError.toLocalFile()); | 274 | Q_EMIT displayTrackError(sourceInError.toLocalFile()); | ||
237 | } else { | 275 | } else { | ||
238 | Q_EMIT displayTrackError(sourceInError.toString()); | 276 | Q_EMIT displayTrackError(sourceInError.toString()); | ||
Show All 13 Lines | |||||
252 | 290 | | |||
253 | void MusicListenersManager::configChanged() | 291 | void MusicListenersManager::configChanged() | ||
254 | { | 292 | { | ||
255 | auto currentConfiguration = Elisa::ElisaConfiguration::self(); | 293 | auto currentConfiguration = Elisa::ElisaConfiguration::self(); | ||
256 | 294 | | |||
257 | d->mConfigFileWatcher.addPath(currentConfiguration->config()->name()); | 295 | d->mConfigFileWatcher.addPath(currentConfiguration->config()->name()); | ||
258 | 296 | | |||
259 | currentConfiguration->load(); | 297 | currentConfiguration->load(); | ||
298 | currentConfiguration->read(); | ||||
299 | | ||||
300 | const auto &allRootPaths = currentConfiguration->rootPath(); | ||||
301 | d->mFileListener.setAllRootPaths(allRootPaths); | ||||
260 | 302 | | |||
261 | #if defined KF5Baloo_FOUND && KF5Baloo_FOUND | 303 | #if defined KF5Baloo_FOUND && KF5Baloo_FOUND | ||
262 | if (currentConfiguration->balooIndexer() && !d->mBalooListener) { | 304 | d->mBalooListener.setAllRootPaths(allRootPaths); | ||
263 | d->mBalooListener = std::make_unique<BalooListener>(); | 305 | #endif | ||
264 | d->mBalooListener->moveToThread(&d->mListenerThread); | 306 | | ||
265 | d->mBalooListener->setDatabaseInterface(&d->mDatabaseInterface); | 307 | if (!d->mBalooIndexerActive && !d->mFileSystemIndexerActive) { | ||
266 | connect(this, &MusicListenersManager::applicationIsTerminating, | 308 | testBalooIndexerAvailability(); | ||
267 | d->mBalooListener.get(), &BalooListener::applicationAboutToQuit, Qt::DirectConnection); | 309 | } else { | ||
268 | connect(d->mBalooListener.get(), &BalooListener::indexingStarted, | 310 | if (d->mBalooIndexerActive) { | ||
269 | this, &MusicListenersManager::monitorStartingListeners); | 311 | #if defined KF5Baloo_FOUND && KF5Baloo_FOUND | ||
270 | connect(d->mBalooListener.get(), &BalooListener::indexingFinished, | 312 | QMetaObject::invokeMethod(d->mBalooListener.fileListing(), "init", Qt::QueuedConnection); | ||
271 | this, &MusicListenersManager::monitorEndingListeners); | | |||
272 | connect(d->mBalooListener.get(), &BalooListener::clearDatabase, | | |||
273 | &d->mDatabaseInterface, &DatabaseInterface::removeAllTracksFromSource); | | |||
274 | connect(d->mBalooListener.get(), &BalooListener::newNotification, | | |||
275 | this, &MusicListenersManager::newNotification); | | |||
276 | connect(d->mBalooListener.get(), &BalooListener::closeNotification, | | |||
277 | this, &MusicListenersManager::closeNotification); | | |||
278 | } else if (!currentConfiguration->balooIndexer() && d->mBalooListener) { | | |||
279 | QMetaObject::invokeMethod(d->mBalooListener.get(), "quitListener", Qt::QueuedConnection); | | |||
280 | d->mBalooListener.reset(); | | |||
281 | } | | |||
282 | #endif | 313 | #endif | ||
314 | } else if (d->mFileSystemIndexerActive) { | ||||
315 | QMetaObject::invokeMethod(d->mFileListener.fileListing(), "init", Qt::QueuedConnection); | ||||
316 | } | ||||
317 | } | ||||
318 | | ||||
283 | #if defined UPNPQT_FOUND && UPNPQT_FOUND | 319 | #if defined UPNPQT_FOUND && UPNPQT_FOUND | ||
284 | d->mUpnpListener.setDatabaseInterface(&d->mDatabaseInterface); | 320 | d->mUpnpListener.setDatabaseInterface(&d->mDatabaseInterface); | ||
285 | d->mUpnpListener.moveToThread(&d->mDatabaseThread); | 321 | d->mUpnpListener.moveToThread(&d->mDatabaseThread); | ||
286 | connect(this, &MusicListenersManager::applicationIsTerminating, | 322 | connect(this, &MusicListenersManager::applicationIsTerminating, | ||
287 | &d->mUpnpListener, &UpnpListener::applicationAboutToQuit, Qt::DirectConnection); | 323 | &d->mUpnpListener, &UpnpListener::applicationAboutToQuit, Qt::DirectConnection); | ||
288 | #endif | 324 | #endif | ||
289 | 325 | | |||
290 | #if defined Qt5AndroidExtras_FOUND && Qt5AndroidExtras_FOUND | 326 | #if defined Qt5AndroidExtras_FOUND && Qt5AndroidExtras_FOUND | ||
Show All 10 Lines | 327 | if (!d->mAndroidMusicListener) { | |||
301 | connect(d->mAndroidMusicListener.get(), &AndroidMusicListener::clearDatabase, | 337 | connect(d->mAndroidMusicListener.get(), &AndroidMusicListener::clearDatabase, | ||
302 | &d->mDatabaseInterface, &DatabaseInterface::removeAllTracksFromSource); | 338 | &d->mDatabaseInterface, &DatabaseInterface::removeAllTracksFromSource); | ||
303 | connect(d->mAndroidMusicListener.get(), &AndroidMusicListener::newNotification, | 339 | connect(d->mAndroidMusicListener.get(), &AndroidMusicListener::newNotification, | ||
304 | this, &MusicListenersManager::newNotification); | 340 | this, &MusicListenersManager::newNotification); | ||
305 | connect(d->mAndroidMusicListener.get(), &AndroidMusicListener::closeNotification, | 341 | connect(d->mAndroidMusicListener.get(), &AndroidMusicListener::closeNotification, | ||
306 | this, &MusicListenersManager::closeNotification); | 342 | this, &MusicListenersManager::closeNotification); | ||
307 | } | 343 | } | ||
308 | #endif | 344 | #endif | ||
309 | | ||||
310 | if (currentConfiguration->elisaFilesIndexer()) | | |||
311 | { | | |||
312 | const auto &allRootPaths = currentConfiguration->rootPath(); | | |||
313 | for (auto itFileListener = d->mFileListener.begin(); itFileListener != d->mFileListener.end(); ) { | | |||
314 | const auto ¤tRootPath = (*itFileListener)->localFileIndexer().rootPath(); | | |||
315 | auto itPath = std::find(allRootPaths.begin(), allRootPaths.end(), currentRootPath); | | |||
316 | | ||||
317 | if (itPath == allRootPaths.end()) { | | |||
318 | d->mDatabaseInterface.removeAllTracksFromSource((*itFileListener)->fileListing()->sourceName()); | | |||
319 | itFileListener = d->mFileListener.erase(itFileListener); | | |||
320 | } else { | | |||
321 | ++itFileListener; | | |||
322 | } | | |||
323 | } | | |||
324 | | ||||
325 | for (const auto &oneRootPath : allRootPaths) { | | |||
326 | auto itPath = std::find_if(d->mFileListener.begin(), d->mFileListener.end(), | | |||
327 | [&oneRootPath](const auto &value)->bool {return value->localFileIndexer().rootPath() == oneRootPath;}); | | |||
328 | if (itPath == d->mFileListener.end()) { | | |||
329 | auto newFileIndexer = std::make_unique<FileListener>(); | | |||
330 | | ||||
331 | newFileIndexer->setDatabaseInterface(&d->mDatabaseInterface); | | |||
332 | newFileIndexer->moveToThread(&d->mListenerThread); | | |||
333 | connect(this, &MusicListenersManager::applicationIsTerminating, | | |||
334 | newFileIndexer.get(), &FileListener::applicationAboutToQuit, Qt::DirectConnection); | | |||
335 | connect(newFileIndexer.get(), &FileListener::indexingStarted, | | |||
336 | this, &MusicListenersManager::monitorStartingListeners); | | |||
337 | connect(newFileIndexer.get(), &FileListener::indexingFinished, | | |||
338 | this, &MusicListenersManager::monitorEndingListeners); | | |||
339 | connect(newFileIndexer.get(), &FileListener::newNotification, | | |||
340 | this, &MusicListenersManager::newNotification); | | |||
341 | connect(newFileIndexer.get(), &FileListener::closeNotification, | | |||
342 | this, &MusicListenersManager::closeNotification); | | |||
343 | | ||||
344 | newFileIndexer->setRootPath(oneRootPath); | | |||
345 | | ||||
346 | d->mFileListener.emplace_back(std::move(newFileIndexer)); | | |||
347 | } | | |||
348 | } | | |||
349 | } | | |||
350 | } | 345 | } | ||
351 | 346 | | |||
352 | void MusicListenersManager::increaseImportedTracksCount(const DatabaseInterface::ListTrackDataType &allTracks) | 347 | void MusicListenersManager::increaseImportedTracksCount(const DatabaseInterface::ListTrackDataType &allTracks) | ||
353 | { | 348 | { | ||
354 | d->mImportedTracksCount += allTracks.size(); | 349 | d->mImportedTracksCount += allTracks.size(); | ||
355 | 350 | | |||
356 | if (d->mImportedTracksCount && d->mIndexerBusy) { | | |||
357 | d->mIndexerBusy = false; | | |||
358 | Q_EMIT indexerBusyChanged(); | | |||
359 | } | | |||
360 | | ||||
361 | //if (d->mImportedTracksCount >= 4) { | 351 | //if (d->mImportedTracksCount >= 4) { | ||
362 | Q_EMIT closeNotification(QStringLiteral("notEnoughTracks")); | 352 | Q_EMIT closeNotification(QStringLiteral("notEnoughTracks")); | ||
363 | //} | 353 | //} | ||
364 | 354 | | |||
365 | Q_EMIT importedTracksCountChanged(); | 355 | Q_EMIT importedTracksCountChanged(); | ||
366 | } | 356 | } | ||
367 | 357 | | |||
368 | void MusicListenersManager::decreaseImportedTracksCount() | 358 | void MusicListenersManager::decreaseImportedTracksCount() | ||
369 | { | 359 | { | ||
370 | --d->mImportedTracksCount; | 360 | --d->mImportedTracksCount; | ||
371 | 361 | | |||
372 | Q_EMIT importedTracksCountChanged(); | 362 | Q_EMIT importedTracksCountChanged(); | ||
373 | } | 363 | } | ||
374 | 364 | | |||
375 | void MusicListenersManager::monitorStartingListeners() | 365 | void MusicListenersManager::monitorStartingListeners() | ||
376 | { | 366 | { | ||
377 | if (d->mActiveMusicListenersCount == 0) { | 367 | d->mIndexerBusy = true; | ||
378 | d->mIndexingRunning = true; | 368 | Q_EMIT indexerBusyChanged(); | ||
379 | Q_EMIT indexingRunningChanged(); | | |||
380 | } | | |||
381 | | ||||
382 | ++d->mActiveMusicListenersCount; | | |||
383 | } | 369 | } | ||
384 | 370 | | |||
385 | void MusicListenersManager::monitorEndingListeners() | 371 | void MusicListenersManager::monitorEndingListeners() | ||
386 | { | 372 | { | ||
387 | --d->mActiveMusicListenersCount; | | |||
388 | | ||||
389 | if (d->mActiveMusicListenersCount == 0) { | | |||
390 | /*if (d->mImportedTracksCount < 4 && d->mElisaApplication) { | 373 | /*if (d->mImportedTracksCount < 4 && d->mElisaApplication) { | ||
391 | NotificationItem notEnoughTracks; | 374 | NotificationItem notEnoughTracks; | ||
392 | 375 | | |||
393 | notEnoughTracks.setNotificationId(QStringLiteral("notEnoughTracks")); | 376 | notEnoughTracks.setNotificationId(QStringLiteral("notEnoughTracks")); | ||
394 | 377 | | |||
395 | notEnoughTracks.setTargetObject(this); | 378 | notEnoughTracks.setTargetObject(this); | ||
396 | 379 | | |||
397 | notEnoughTracks.setMessage(i18nc("No track found message", "No track have been found")); | 380 | notEnoughTracks.setMessage(i18nc("No track found message", "No track have been found")); | ||
398 | 381 | | |||
399 | auto configureAction = d->mElisaApplication->action(QStringLiteral("options_configure")); | 382 | auto configureAction = d->mElisaApplication->action(QStringLiteral("options_configure")); | ||
400 | 383 | | |||
401 | notEnoughTracks.setMainButtonText(configureAction->text()); | 384 | notEnoughTracks.setMainButtonText(configureAction->text()); | ||
402 | notEnoughTracks.setMainButtonIconName(configureAction->icon().name()); | 385 | notEnoughTracks.setMainButtonIconName(configureAction->icon().name()); | ||
403 | notEnoughTracks.setMainButtonMethodName(QStringLiteral("showConfiguration")); | 386 | notEnoughTracks.setMainButtonMethodName(QStringLiteral("showConfiguration")); | ||
404 | 387 | | |||
405 | Q_EMIT newNotification(notEnoughTracks); | 388 | Q_EMIT newNotification(notEnoughTracks); | ||
406 | }*/ | 389 | }*/ | ||
407 | 390 | | |||
408 | d->mIndexingRunning = false; | 391 | d->mIndexerBusy = false; | ||
409 | Q_EMIT indexingRunningChanged(); | 392 | Q_EMIT indexerBusyChanged(); | ||
410 | } | | |||
411 | } | 393 | } | ||
412 | 394 | | |||
413 | void MusicListenersManager::cleanedDatabase() | 395 | void MusicListenersManager::cleanedDatabase() | ||
414 | { | 396 | { | ||
415 | d->mImportedTracksCount = 0; | 397 | d->mImportedTracksCount = 0; | ||
416 | Q_EMIT importedTracksCountChanged(); | 398 | Q_EMIT importedTracksCountChanged(); | ||
417 | } | 399 | } | ||
418 | 400 | | |||
401 | void MusicListenersManager::balooAvailabilityChanged() | ||||
402 | { | ||||
403 | if (!d->mBalooDetector.balooAvailability()) { | ||||
404 | if (!d->mFileSystemIndexerActive) { | ||||
405 | startLocalFileSystemIndexing(); | ||||
406 | } | ||||
407 | | ||||
408 | return; | ||||
409 | } | ||||
410 | | ||||
411 | qCInfo(orgKdeElisaIndexersManager) << "Baloo indexer is available"; | ||||
412 | d->mBalooIndexerAvailable = true; | ||||
413 | Q_EMIT balooIndexerAvailableChanged(); | ||||
414 | startBalooIndexing(); | ||||
415 | } | ||||
416 | | ||||
417 | void MusicListenersManager::testBalooIndexerAvailability() | ||||
418 | { | ||||
419 | #if defined KF5Baloo_FOUND && KF5Baloo_FOUND | ||||
420 | d->mBalooDetector.checkBalooAvailability(); | ||||
421 | #else | ||||
422 | qCInfo(orgKdeElisaIndexersManager) << "Baloo indexer is unavailable"; | ||||
423 | d->mBalooIndexerAvailable = false; | ||||
424 | Q_EMIT balooIndexerAvailableChanged(); | ||||
425 | | ||||
426 | qCInfo(orgKdeElisaIndexersManager) << "Baloo indexer is inactive"; | ||||
427 | d->mBalooIndexerActive = false; | ||||
428 | Q_EMIT balooIndexerActiveChanged(); | ||||
429 | | ||||
430 | startLocalFileSystemIndexing(); | ||||
431 | #endif | ||||
432 | } | ||||
433 | | ||||
434 | void MusicListenersManager::startLocalFileSystemIndexing() | ||||
435 | { | ||||
436 | if (d->mFileSystemIndexerActive) { | ||||
437 | return; | ||||
438 | } | ||||
439 | | ||||
440 | d->mFileListener.setDatabaseInterface(&d->mDatabaseInterface); | ||||
441 | d->mFileListener.moveToThread(&d->mListenerThread); | ||||
442 | connect(this, &MusicListenersManager::applicationIsTerminating, | ||||
443 | &d->mFileListener, &FileListener::applicationAboutToQuit, Qt::DirectConnection); | ||||
444 | connect(&d->mFileListener, &FileListener::indexingStarted, | ||||
445 | this, &MusicListenersManager::monitorStartingListeners); | ||||
446 | connect(&d->mFileListener, &FileListener::indexingFinished, | ||||
447 | this, &MusicListenersManager::monitorEndingListeners); | ||||
448 | connect(&d->mFileListener, &FileListener::newNotification, | ||||
449 | this, &MusicListenersManager::newNotification); | ||||
450 | connect(&d->mFileListener, &FileListener::closeNotification, | ||||
451 | this, &MusicListenersManager::closeNotification); | ||||
452 | | ||||
453 | QMetaObject::invokeMethod(d->mFileListener.fileListing(), "init", Qt::QueuedConnection); | ||||
454 | | ||||
455 | qCInfo(orgKdeElisaIndexersManager) << "Local file system indexer is active"; | ||||
456 | | ||||
457 | d->mFileSystemIndexerActive = true; | ||||
458 | Q_EMIT fileSystemIndexerActiveChanged(); | ||||
459 | } | ||||
460 | | ||||
461 | void MusicListenersManager::startBalooIndexing() | ||||
462 | { | ||||
463 | #if defined KF5Baloo_FOUND && KF5Baloo_FOUND | ||||
464 | d->mBalooListener.moveToThread(&d->mListenerThread); | ||||
465 | d->mBalooListener.setDatabaseInterface(&d->mDatabaseInterface); | ||||
466 | connect(this, &MusicListenersManager::applicationIsTerminating, | ||||
467 | &d->mBalooListener, &BalooListener::applicationAboutToQuit, Qt::DirectConnection); | ||||
468 | connect(&d->mBalooListener, &BalooListener::indexingStarted, | ||||
469 | this, &MusicListenersManager::monitorStartingListeners); | ||||
470 | connect(&d->mBalooListener, &BalooListener::indexingFinished, | ||||
471 | this, &MusicListenersManager::monitorEndingListeners); | ||||
472 | connect(&d->mBalooListener, &BalooListener::clearDatabase, | ||||
473 | &d->mDatabaseInterface, &DatabaseInterface::clearData); | ||||
474 | connect(&d->mBalooListener, &BalooListener::newNotification, | ||||
475 | this, &MusicListenersManager::newNotification); | ||||
476 | connect(&d->mBalooListener, &BalooListener::closeNotification, | ||||
477 | this, &MusicListenersManager::closeNotification); | ||||
478 | | ||||
479 | QMetaObject::invokeMethod(d->mBalooListener.fileListing(), "init", Qt::QueuedConnection); | ||||
480 | | ||||
481 | qCInfo(orgKdeElisaIndexersManager) << "Baloo indexer is active"; | ||||
482 | | ||||
483 | d->mBalooIndexerActive = true; | ||||
484 | Q_EMIT balooIndexerActiveChanged(); | ||||
485 | #endif | ||||
486 | } | ||||
487 | | ||||
419 | void MusicListenersManager::createTracksListener() | 488 | void MusicListenersManager::createTracksListener() | ||
420 | { | 489 | { | ||
421 | if (!d->mTracksListener) { | 490 | if (!d->mTracksListener) { | ||
422 | d->mTracksListener = std::make_unique<TracksListener>(&d->mDatabaseInterface); | 491 | d->mTracksListener = std::make_unique<TracksListener>(&d->mDatabaseInterface); | ||
423 | d->mTracksListener->moveToThread(&d->mDatabaseThread); | 492 | d->mTracksListener->moveToThread(&d->mDatabaseThread); | ||
424 | 493 | | |||
425 | connect(this, &MusicListenersManager::removeTracksInError, | 494 | connect(this, &MusicListenersManager::removeTracksInError, | ||
426 | &d->mDatabaseInterface, &DatabaseInterface::removeTracksList); | 495 | &d->mDatabaseInterface, &DatabaseInterface::removeTracksList); | ||
Show All 9 Lines |