Commit d202cc38 authored by Stefan Brüns's avatar Stefan Brüns

Use realtime indexing as fallback when DB has no property data

Summary:
In case the DB provides no data, try to fetch the properties directly
from the file using the new OnDemandIndexer class.

If required, start the extractor in the background, fetch UserMetaData
and wait for the extractor, then unite the results.

BUG: 410114
Depends on D25248

Test Plan:
  # suspend baloo (`balooctl suspend`)
  # copy a file with properties (e.g. PNG) to a included location
    `cp ~/foo.png ~/foo_2.png`
  # `balooshow ~/foo.png ~/foo_2.png` should only display "Cached properties"
     for the original file
  # dolphin displays properties for both files (in the side panel)

Reviewers: #baloo, ngraham, astippich

Reviewed By: #baloo, ngraham, astippich

Tags: #baloo

Differential Revision: https://phabricator.kde.org/D25250
parent 064f4f2b
......@@ -20,6 +20,7 @@
#include "filefetchjob.h"
#include "filemetadatautil_p.h"
#include "widgetsdebug.h"
#include <QFileInfo>
#include <QTimer>
......@@ -29,10 +30,12 @@
using namespace Baloo;
FileFetchJob::FileFetchJob(const QStringList& urls, bool canEditAll, QObject* parent)
FileFetchJob::FileFetchJob(const QStringList& urls, bool canEditAll,
FileFetchJob::UseRealtimeIndexing useRealtime, QObject* parent)
: KJob(parent)
, m_urls(urls)
, m_canEditAll(canEditAll)
, m_useRealtime(useRealtime)
{
}
......@@ -44,17 +47,29 @@ void FileFetchJob::start()
void FileFetchJob::doStart()
{
for (const QString& filePath : m_urls) {
Baloo::File file(filePath);
file.load();
QVariantMap prop = Baloo::Private::toNamedVariantMap(file.properties());
bool extractorRunning = false;
KFileMetaData::PropertyMap fileProperties;
// UseRealtimeIndexing::Fallback: try DB first, then filesystem
// UseRealtimeIndexing::Disabled: DB contents only
// UseRealtimeIndexing::Only: DB disabled, use filesystem
if (m_useRealtime != UseRealtimeIndexing::Only) {
Baloo::File file(filePath);
file.load();
fileProperties = file.properties();
qCDebug(WIDGETS) << filePath << "DB properties:" << fileProperties;
}
if (fileProperties.empty() && m_useRealtime != UseRealtimeIndexing::Disabled) {
extractorRunning = true;
m_extractor.process(filePath);
}
QVariantMap prop;
KFileMetaData::UserMetaData umd(filePath);
if (umd.isSupported()) {
// FIXME - check writable
QVariantMap attributes = Baloo::Private::convertUserMetaData(umd);
prop.unite(attributes);
prop = Baloo::Private::convertUserMetaData(umd);
} else {
m_canEditAll = false;
}
......@@ -62,6 +77,13 @@ void FileFetchJob::doStart()
m_canEditAll = QFileInfo(filePath).isWritable();
}
if (extractorRunning) {
m_extractor.waitFinished();
fileProperties = m_extractor.properties();
qCDebug(WIDGETS) << filePath << " properties:" << fileProperties;
}
prop.unite(Baloo::Private::toNamedVariantMap(fileProperties));
m_data << prop;
}
......
......@@ -23,6 +23,7 @@
#include <KJob>
#include <QVariantMap>
#include "ondemandextractor.h"
namespace Baloo {
......@@ -30,7 +31,13 @@ class FileFetchJob : public KJob
{
Q_OBJECT
public:
explicit FileFetchJob(const QStringList& urls, bool canEditAll, QObject* parent = nullptr);
enum class UseRealtimeIndexing : char {
Disabled = 0,
Only,
Fallback
};
explicit FileFetchJob(const QStringList& urls, bool canEditAll,
UseRealtimeIndexing useRealtime, QObject* parent = nullptr);
QList<QVariantMap> data() const;
bool canEditAll() const;
......@@ -44,6 +51,8 @@ private:
QStringList m_urls;
QList<QVariantMap> m_data;
bool m_canEditAll;
UseRealtimeIndexing m_useRealtime;
Private::OnDemandExtractor m_extractor;
};
}
......
......@@ -343,22 +343,24 @@ void FileMetaDataProvider::setFileItem()
return;
}
// Not indexed or only basic file indexing (no content)
const QString filePath = url.toLocalFile();
FileFetchJob* job;
// Not indexed or only basic file indexing (no content)
if (!m_config.fileIndexingEnabled() || !m_config.shouldBeIndexed(filePath)
|| m_config.onlyBasicIndexing()) {
m_realTimeIndexing = true;
IndexedDataRetriever *ret = new IndexedDataRetriever(filePath, this);
connect(ret, &IndexedDataRetriever::finished, this, &FileMetaDataProvider::slotLoadingFinished);
ret->start();
job = new FileFetchJob(QStringList{filePath}, true,
FileFetchJob::UseRealtimeIndexing::Only, this);
// Fully indexed by Baloo
} else {
FileFetchJob* job = new FileFetchJob(QStringList{filePath}, true, this);
connect(job, &FileFetchJob::finished, this, &FileMetaDataProvider::slotFileFetchFinished);
job->start();
job = new FileFetchJob(QStringList{filePath}, true,
FileFetchJob::UseRealtimeIndexing::Fallback, this);
}
connect(job, &FileFetchJob::finished, this, &FileMetaDataProvider::slotFileFetchFinished);
job->start();
}
void FileMetaDataProvider::setFileItems()
......@@ -383,7 +385,8 @@ void FileMetaDataProvider::setFileItems()
// Editing only if all URLs are local
bool canEdit = (urls.size() == m_fileItems.size());
FileFetchJob* job = new FileFetchJob(urls, canEdit, this);
FileFetchJob* job = new FileFetchJob(urls, canEdit,
FileFetchJob::UseRealtimeIndexing::Disabled, this);
connect(job, &FileFetchJob::finished, this, &FileMetaDataProvider::slotFileFetchFinished);
job->start();
......
......@@ -62,6 +62,11 @@ void OnDemandExtractor::slotIndexedFile(int, QProcess::ExitStatus exitStatus)
emit fileFinished(QProcess::NormalExit);
}
bool OnDemandExtractor::waitFinished()
{
return m_process.waitForFinished();
}
KFileMetaData::PropertyMap OnDemandExtractor::properties() const
{
return m_properties;
......
......@@ -37,6 +37,7 @@ public:
void process(const QString& filePath);
bool waitFinished();
KFileMetaData::PropertyMap properties() const;
Q_SIGNALS:
......
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