Commit 63e9df2c authored by Matthieu Gallien's avatar Matthieu Gallien

Merge branch 'disactivateBalooWhenNeeded' into release/19.12

BUG: 407918
parents 09598593 20337654
......@@ -106,5 +106,10 @@ AbstractFileListing *AbstractFileListener::fileListing() const
return d->mFileListing;
}
bool AbstractFileListener::canHandleRootPaths() const
{
return d->mFileListing->canHandleRootPaths();
}
#include "moc_abstractfilelistener.cpp"
......@@ -49,6 +49,8 @@ public:
AbstractFileListing* fileListing() const;
bool canHandleRootPaths() const;
Q_SIGNALS:
void databaseInterfaceChanged();
......
......@@ -66,6 +66,8 @@ public:
bool mErrorWatchingFileSystemChanges = false;
bool mIsActive = false;
};
AbstractFileListing::AbstractFileListing(QObject *parent) : QObject(parent), d(std::make_unique<AbstractFileListingPrivate>())
......@@ -81,9 +83,20 @@ AbstractFileListing::~AbstractFileListing()
void AbstractFileListing::init()
{
qCDebug(orgKdeElisaIndexer()) << "AbstractFileListing::init";
d->mIsActive = true;
Q_EMIT askRestoredTracks();
}
void AbstractFileListing::stop()
{
d->mIsActive = false;
triggerStop();
}
void AbstractFileListing::newTrackFile(const DataTypes::TrackDataType &partialTrack)
{
auto scanFileInfo = QFileInfo(partialTrack.resourceURI().toLocalFile());
......@@ -128,6 +141,11 @@ const QStringList &AbstractFileListing::allRootPaths() const
return d->mAllRootPaths;
}
bool AbstractFileListing::canHandleRootPaths() const
{
return true;
}
void AbstractFileListing::scanDirectory(DataTypes::ListTrackDataType &newFiles, const QUrl &path)
{
if (d->mStopRequest == 1) {
......@@ -210,6 +228,15 @@ void AbstractFileListing::scanDirectory(DataTypes::ListTrackDataType &newFiles,
continue;
}
auto itExistingFile = allFiles().find(newFilePath);
if (itExistingFile != allFiles().end()) {
if (*itExistingFile >= oneEntry.metadataChangeTime()) {
allFiles().erase(itExistingFile);
qCDebug(orgKdeElisaIndexer()) << "AbstractFileListing::scanDirectory" << newFilePath << "file not modified since last scan";
continue;
}
}
auto newTrack = scanOneFile(newFilePath, oneEntry);
if (newTrack.isValid() && d->mStopRequest == 0) {
......@@ -266,6 +293,10 @@ void AbstractFileListing::executeInit(QHash<QUrl, QDateTime> allFiles)
d->mAllFiles = std::move(allFiles);
}
void AbstractFileListing::triggerStop()
{
}
void AbstractFileListing::triggerRefreshOfContent()
{
d->mImportedTracksCount = 0;
......@@ -285,6 +316,7 @@ DataTypes::TrackDataType AbstractFileListing::scanOneFile(const QUrl &scanFile,
auto localFileName = scanFile.toLocalFile();
if (!d->mFileScanner.shouldScanFile(localFileName)) {
qCDebug(orgKdeElisaIndexer) << "AbstractFileListing::scanOneFile" << "invalid mime type";
return newTrack;
}
......@@ -293,6 +325,7 @@ DataTypes::TrackDataType AbstractFileListing::scanOneFile(const QUrl &scanFile,
if (itExistingFile != d->mAllFiles.end()) {
if (*itExistingFile >= scanFileInfo.metadataChangeTime()) {
d->mAllFiles.erase(itExistingFile);
qCDebug(orgKdeElisaIndexer) << "AbstractFileListing::scanOneFile" << "not changed file";
return newTrack;
}
}
......@@ -456,5 +489,10 @@ void AbstractFileListing::setWaitEndTrackRemoval(bool wait)
d->mWaitEndTrackRemoval = wait;
}
bool AbstractFileListing::isActive() const
{
return d->mIsActive;
}
#include "moc_abstractfilelisting.cpp"
......@@ -49,6 +49,8 @@ public:
const QStringList& allRootPaths() const;
virtual bool canHandleRootPaths() const;
Q_SIGNALS:
void tracksList(const DataTypes::ListTrackDataType &tracks, const QHash<QString, QUrl> &covers);
......@@ -71,6 +73,8 @@ public Q_SLOTS:
void init();
void stop();
void newTrackFile(const DataTypes::TrackDataType &partialTrack);
void restoredTracks(QHash<QUrl, QDateTime> allFiles);
......@@ -93,6 +97,8 @@ protected:
virtual void triggerRefreshOfContent();
virtual void triggerStop();
void scanDirectory(DataTypes::ListTrackDataType &newFiles, const QUrl &path);
virtual DataTypes::TrackDataType scanOneFile(const QUrl &scanFile, const QFileInfo &scanFileInfo);
......@@ -125,6 +131,8 @@ protected:
void setWaitEndTrackRemoval(bool wait);
bool isActive() const;
private:
std::unique_ptr<AbstractFileListingPrivate> d;
......
......@@ -121,10 +121,55 @@ void LocalBalooFileListing::applicationAboutToQuit()
d->mStopRequest = 1;
}
bool LocalBalooFileListing::canHandleRootPaths() const
{
Baloo::IndexerConfig balooConfiguration;
auto balooIncludedFolders = balooConfiguration.includeFolders();
auto balooExcludedFolders = balooConfiguration.excludeFolders();
for (const auto &onePath : allRootPaths()) {
auto onePathInfo = QFileInfo{onePath};
auto onePathCanonicalPath = onePathInfo.canonicalFilePath();
auto includedPath = false;
for (const auto &balooIncludedPath : balooIncludedFolders) {
auto balooIncludedPathInfo = QFileInfo{balooIncludedPath};
auto balooIncludedCanonicalPath = balooIncludedPathInfo.canonicalFilePath();
if (onePathCanonicalPath.startsWith(balooIncludedCanonicalPath)) {
includedPath = true;
break;
}
}
for (const auto &balooExcludedPath : balooExcludedFolders) {
auto balooExcludedPathInfo = QFileInfo{balooExcludedPath};
auto balooExcludedCanonicalPath = balooExcludedPathInfo.canonicalFilePath();
if (onePathCanonicalPath.startsWith(balooExcludedCanonicalPath)) {
includedPath = false;
break;
}
}
if (!includedPath) {
return false;
}
}
return true;
}
void LocalBalooFileListing::newBalooFile(const QString &fileName)
{
qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::newBalooFile" << fileName;
if (!isActive()) {
qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::newBalooFile is inactive";
return;
}
auto scanFileInfo = QFileInfo(fileName);
if (!scanFileInfo.exists()) {
......@@ -299,12 +344,24 @@ void LocalBalooFileListing::serviceUnregistered(const QString &serviceName)
void LocalBalooFileListing::executeInit(QHash<QUrl, QDateTime> allFiles)
{
if (!isActive()) {
qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::executeInit is inactive";
return;
}
qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::executeInit" << "with" << allFiles.size() << "files";
AbstractFileListing::executeInit(std::move(allFiles));
}
void LocalBalooFileListing::triggerRefreshOfContent()
{
qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::triggerRefreshOfContent";
if (!isActive()) {
qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::triggerRefreshOfContent is inactive";
return;
}
Q_EMIT indexingStarted();
AbstractFileListing::triggerRefreshOfContent();
......@@ -388,6 +445,12 @@ void LocalBalooFileListing::triggerRefreshOfContent()
}
}
void LocalBalooFileListing::triggerStop()
{
qCDebug(orgKdeElisaBaloo()) << "LocalBalooFileListing::triggerStop";
AbstractFileListing::triggerStop();
}
DataTypes::TrackDataType LocalBalooFileListing::scanOneFile(const QUrl &scanFile, const QFileInfo &scanFileInfo)
{
DataTypes::TrackDataType trackData;
......
......@@ -44,6 +44,8 @@ public:
void applicationAboutToQuit() override;
bool canHandleRootPaths() const override;
Q_SIGNALS:
public Q_SLOTS:
......@@ -72,6 +74,8 @@ private:
void triggerRefreshOfContent() override;
void triggerStop() override;
DataTypes::TrackDataType scanOneFile(const QUrl &scanFile, const QFileInfo &scanFileInfo) override;
std::unique_ptr<LocalBalooFileListingPrivate> d;
......
......@@ -45,12 +45,24 @@ LocalFileListing::~LocalFileListing()
void LocalFileListing::executeInit(QHash<QUrl, QDateTime> allFiles)
{
if (!isActive()) {
qCDebug(orgKdeElisaIndexer()) << "LocalFileListing::executeInit is inactive";
return;
}
qCDebug(orgKdeElisaIndexer()) << "LocalFileListing::executeInit" << "with" << allFiles.size() << "files";
AbstractFileListing::executeInit(std::move(allFiles));
}
void LocalFileListing::triggerRefreshOfContent()
{
qCDebug(orgKdeElisaIndexer()) << "LocalFileListing::triggerRefreshOfContent";
if (!isActive()) {
qCDebug(orgKdeElisaIndexer()) << "LocalFileListing::triggerRefreshOfContent is inactive";
return;
}
Q_EMIT indexingStarted();
qCDebug(orgKdeElisaIndexer()) << "LocalFileListing::triggerRefreshOfContent" << allRootPaths();
......@@ -71,5 +83,11 @@ void LocalFileListing::triggerRefreshOfContent()
}
}
void LocalFileListing::triggerStop()
{
qCDebug(orgKdeElisaIndexer()) << "LocalFileListing::triggerStop";
AbstractFileListing::triggerStop();
}
#include "moc_localfilelisting.cpp"
......@@ -45,6 +45,8 @@ private:
void triggerRefreshOfContent() override;
void triggerStop() override;
std::unique_ptr<LocalFileListingPrivate> d;
};
......
......@@ -361,11 +361,27 @@ void MusicListenersManager::configChanged()
if (!d->mBalooIndexerActive && !d->mFileSystemIndexerActive) {
testBalooIndexerAvailability();
}
if (d->mBalooIndexerAvailable && !d->mBalooIndexerActive && d->mBalooListener.canHandleRootPaths())
{
qCDebug(orgKdeElisaIndexersManager()) << "trigger start of baloo file indexer";
QMetaObject::invokeMethod(d->mFileListener.fileListing(), "stop", Qt::BlockingQueuedConnection);
d->mFileSystemIndexerActive = false;
startBalooIndexing();
} else if (!d->mFileSystemIndexerActive && d->mBalooIndexerActive && !d->mBalooListener.canHandleRootPaths())
{
qCDebug(orgKdeElisaIndexersManager()) << "trigger stop of baloo file indexer";
QMetaObject::invokeMethod(d->mBalooListener.fileListing(), "stop", Qt::BlockingQueuedConnection);
d->mBalooIndexerActive = false;
startLocalFileSystemIndexing();
}
if (d->mBalooIndexerActive) {
qCInfo(orgKdeElisaIndexersManager()) << "trigger init of baloo file indexer";
#if defined KF5Baloo_FOUND && KF5Baloo_FOUND
QMetaObject::invokeMethod(d->mBalooListener.fileListing(), "init", Qt::QueuedConnection);
#endif
} else if (d->mFileSystemIndexerActive) {
qCInfo(orgKdeElisaIndexersManager()) << "trigger init of local file indexer";
QMetaObject::invokeMethod(d->mFileListener.fileListing(), "init", Qt::QueuedConnection);
}
......@@ -429,10 +445,18 @@ void MusicListenersManager::cleanedDatabase()
void MusicListenersManager::balooAvailabilityChanged()
{
#if defined KF5Baloo_FOUND && KF5Baloo_FOUND
if (!d->mBalooDetector.balooAvailability()) {
if (!d->mBalooDetector.balooAvailability() || !d->mBalooListener.canHandleRootPaths()) {
if (d->mBalooDetector.balooAvailability()) {
qCInfo(orgKdeElisaIndexersManager) << "Baloo indexer is available";
d->mBalooIndexerAvailable = true;
}
#else
if (true) {
#endif
if (!d->mBalooListener.canHandleRootPaths() && d->mBalooDetector.balooAvailability())
{
qCInfo(orgKdeElisaIndexersManager()) << "Baloo cannot handle all configured paths: falling back to plain filex indexer";
}
if (!d->mFileSystemIndexerActive) {
startLocalFileSystemIndexing();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment