Commit 09855fef authored by Alexander Stippich's avatar Alexander Stippich
Browse files

consolidate the interface between file and baloo indexers

parent ca1a37d8
......@@ -74,6 +74,16 @@ private Q_SLOTS:
QCOMPARE(scannedTrack.genre(), QStringLiteral("Genre"));
QCOMPARE(scannedTrack.album(), QStringLiteral("Test"));
QCOMPARE(scannedTrack.artist(), QStringLiteral("Artist"));
auto scannedTrackCover1 = fileScanner.scanOneFile(QUrl::fromLocalFile(mTestTracksForMetaData.at(0)));
QCOMPARE(scannedTrackCover1.hasEmbeddedCover(), true);
auto scannedTrackCover2 = fileScanner.scanOneFile(QUrl::fromLocalFile(mTestTracksForMetaData.at(1)));
QCOMPARE(scannedTrackCover2.hasEmbeddedCover(), true);
auto scannedTrackCover3 = fileScanner.scanOneFile(QUrl::fromLocalFile(mTestTracksForMetaData.at(2)));
QCOMPARE(scannedTrackCover2.hasEmbeddedCover(), true);
}
void testFindCoverInDirectory()
......@@ -90,14 +100,6 @@ private Q_SLOTS:
QVERIFY(!fileScanner.searchForCoverFile(mTestTracksForDirectory.at(8)).isEmpty());
}
void loadCoverFromMetaData()
{
FileScanner fileScanner;
QVERIFY(fileScanner.checkEmbeddedCoverImage(mTestTracksForMetaData.at(0)));
QVERIFY(fileScanner.checkEmbeddedCoverImage(mTestTracksForMetaData.at(1)));
QVERIFY(fileScanner.checkEmbeddedCoverImage(mTestTracksForMetaData.at(2)));
}
void benchmarkFileScan()
{
FileScanner fileScanner;
......@@ -125,16 +127,6 @@ private Q_SLOTS:
fileScanner.searchForCoverFile(mTestTracksForDirectory.at(8));
}
}
void benchmarkCoverFromMetadata()
{
FileScanner fileScanner;
QBENCHMARK {
fileScanner.checkEmbeddedCoverImage(mTestTracksForMetaData.at(0));
fileScanner.checkEmbeddedCoverImage(mTestTracksForMetaData.at(1));
fileScanner.checkEmbeddedCoverImage(mTestTracksForMetaData.at(2));
}
}
};
QTEST_GUILESS_MAIN(FileScannerTest)
......
......@@ -330,15 +330,10 @@ DataTypes::TrackDataType AbstractFileListing::scanOneFile(const QUrl &scanFile,
}
}
newTrack = d->mFileScanner.scanOneFile(scanFile);
newTrack = d->mFileScanner.scanOneFile(scanFile, scanFileInfo);
if (newTrack.isValid()) {
newTrack[DataTypes::HasEmbeddedCover] = checkEmbeddedCoverImage(localFileName);
newTrack[DataTypes::FileModificationTime] = scanFileInfo.metadataChangeTime();
if (scanFileInfo.exists()) {
watchPath(scanFile.toLocalFile());
}
if (newTrack.isValid() && scanFileInfo.exists()) {
watchPath(scanFile.toLocalFile());
}
return newTrack;
......@@ -473,11 +468,6 @@ FileScanner &AbstractFileListing::fileScanner()
return d->mFileScanner;
}
bool AbstractFileListing::checkEmbeddedCoverImage(const QString &localFileName)
{
return d->mFileScanner.checkEmbeddedCoverImage(localFileName);
}
bool AbstractFileListing::waitEndTrackRemoval() const
{
return d->mWaitEndTrackRemoval;
......
......@@ -124,8 +124,6 @@ protected:
FileScanner& fileScanner();
bool checkEmbeddedCoverImage(const QString &localFileName);
bool waitEndTrackRemoval() const;
void setWaitEndTrackRemoval(bool wait);
......
......@@ -448,16 +448,8 @@ void LocalBalooFileListing::triggerStop()
DataTypes::TrackDataType LocalBalooFileListing::scanOneFile(const QUrl &scanFile, const QFileInfo &scanFileInfo)
{
DataTypes::TrackDataType trackData;
auto localFileName = scanFile.toLocalFile();
Baloo::File match(localFileName);
match.load();
fileScanner().scanProperties(match, trackData);
trackData[DataTypes::FileModificationTime] = scanFileInfo.metadataChangeTime();
trackData[DataTypes::ResourceRole] = scanFile;
auto trackData = fileScanner().scanOneBalooFile(scanFile, scanFileInfo);
if (!trackData.isValid()) {
qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::scanOneFile" << scanFile << "falling back to plain file metadata analysis";
......@@ -465,7 +457,6 @@ DataTypes::TrackDataType LocalBalooFileListing::scanOneFile(const QUrl &scanFile
}
if (trackData.isValid()) {
trackData[DataTypes::HasEmbeddedCover] = checkEmbeddedCoverImage(localFileName);
addCover(trackData);
} else {
qCDebug(orgKdeElisaBaloo) << "LocalBalooFileListing::scanOneFile" << scanFile << "invalid track";
......@@ -474,5 +465,4 @@ DataTypes::TrackDataType LocalBalooFileListing::scanOneFile(const QUrl &scanFile
return trackData;
}
#include "moc_localbaloofilelisting.cpp"
......@@ -101,9 +101,8 @@ bool FileScanner::shouldScanFile(const QString &scanFile)
FileScanner::~FileScanner() = default;
DataTypes::TrackDataType FileScanner::scanOneFile(const QUrl &scanFile)
DataTypes::TrackDataType FileScanner::scanOneFile(const QUrl &scanFile, const QFileInfo &scanFileInfo)
{
DataTypes::TrackDataType newTrack;
if (!scanFile.isLocalFile() && !scanFile.scheme().isEmpty()) {
......@@ -112,7 +111,6 @@ DataTypes::TrackDataType FileScanner::scanOneFile(const QUrl &scanFile)
auto localFileName = scanFile.toLocalFile();
QFileInfo scanFileInfo(localFileName);
newTrack[DataTypes::FileModificationTime] = scanFileInfo.metadataChangeTime();
newTrack[DataTypes::ResourceRole] = scanFile;
newTrack[DataTypes::RatingRole] = 0;
......@@ -144,6 +142,7 @@ DataTypes::TrackDataType FileScanner::scanOneFile(const QUrl &scanFile)
qCDebug(orgKdeElisaIndexer()) << "scanOneFile" << scanFile << "using KFileMetaData" << newTrack;
#else
Q_UNUSED(scanFile)
Q_UNUSED(scanFileInfo)
qCDebug(orgKdeElisaIndexer()) << "scanOneFile" << scanFile << "no metadata provider" << newTrack;
#endif
......@@ -151,19 +150,41 @@ DataTypes::TrackDataType FileScanner::scanOneFile(const QUrl &scanFile)
return newTrack;
}
void FileScanner::scanProperties(const Baloo::File &match, DataTypes::TrackDataType &trackData)
DataTypes::TrackDataType FileScanner::scanOneFile(const QUrl &scanFile)
{
if (!scanFile.isLocalFile()){
return {};
} else {
QFileInfo scanFileInfo(scanFile.toLocalFile());
return FileScanner::scanOneFile(scanFile, scanFileInfo);
}
}
DataTypes::TrackDataType FileScanner::scanOneBalooFile(const QUrl &scanFile, const QFileInfo &scanFileInfo)
{
DataTypes::TrackDataType newTrack;
#if defined KF5Baloo_FOUND && KF5Baloo_FOUND
auto localFileName = scanFile.toLocalFile();
newTrack[DataTypes::FileModificationTime] = scanFileInfo.metadataChangeTime();
newTrack[DataTypes::ResourceRole] = scanFile;
newTrack[DataTypes::RatingRole] = 0;
Baloo::File match(localFileName);
match.load();
d->mAllProperties = match.properties();
scanProperties(match.path(), trackData);
scanProperties(match.path(), newTrack);
qCDebug(orgKdeElisaIndexer()) << "scanProperties" << match.path() << "using Baloo" << trackData;
qCDebug(orgKdeElisaIndexer()) << "scanOneFile" << scanFile << "using Baloo" << newTrack;
#else
Q_UNUSED(match)
Q_UNUSED(trackData)
Q_UNUSED(scanFile)
Q_UNUSED(scanFileInfo)
qCDebug(orgKdeElisaIndexer()) << "scanProperties" << "no metadata provider" << trackData;
qCDebug(orgKdeElisaIndexer()) << "scanOneFile" << scanFile << "no baloo metadata provider" << newTrack;
#endif
return newTrack;
}
void FileScanner::scanProperties(const QString &localFileName, DataTypes::TrackDataType &trackData)
......@@ -203,6 +224,12 @@ void FileScanner::scanProperties(const QString &localFileName, DataTypes::TrackD
rangeBegin = rangeEnd;
}
if (!trackData.isValid()) {
return;
}
trackData[DataTypes::HasEmbeddedCover] = checkEmbeddedCoverImage(localFileName);
#if !defined Q_OS_ANDROID && !defined Q_OS_WIN
auto fileData = KFileMetaData::UserMetaData(localFileName);
QString comment = fileData.userComment();
......
......@@ -22,16 +22,10 @@
#include "datatypes.h"
#include <QUrl>
#include <memory>
namespace Baloo {
class File;
}
class QFileInfo;
class QUrl;
class FileScannerPrivate;
class ELISALIB_EXPORT FileScanner
......@@ -46,16 +40,18 @@ public:
DataTypes::TrackDataType scanOneFile(const QUrl &scanFile);
void scanProperties(const Baloo::File &match, DataTypes::TrackDataType &trackData);
DataTypes::TrackDataType scanOneFile(const QUrl &scanFile, const QFileInfo &scanFileInfo);
void scanProperties(const QString &localFileName, DataTypes::TrackDataType &trackData);
DataTypes::TrackDataType scanOneBalooFile(const QUrl &scanFile, const QFileInfo &scanFileInfo);
QUrl searchForCoverFile(const QString &localFileName);
bool checkEmbeddedCoverImage(const QString &localFileName);
private:
void scanProperties(const QString &localFileName, DataTypes::TrackDataType &trackData);
bool checkEmbeddedCoverImage(const QString &localFileName);
std::unique_ptr<FileScannerPrivate> d;
};
......
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