Commit 6f8d9d1c authored by Stefan Brüns's avatar Stefan Brüns

[FileMetaDataProvider] Move readOnly check into the fetch jobs

Summary:
UserMetaData::isSupported() is blocking, so it should be done
asynchronously. Also, the jobs already instantiate a UserMetaData for
each file, so doing it twice is wasteful.

Instead of doing the check in the widget class and pushing it to the
provider, let the provider determine if the file attributes can be
modified and forward the result to the widget factory after the provider
has finished.

Do not check if the file is local twice, once in the provider is
sufficient.

Remove one bogus test case.

Depends on D20979

Test Plan: ctest

Reviewers: #baloo, astippich, ngraham

Reviewed By: astippich

Tags: #baloo

Differential Revision: https://phabricator.kde.org/D20980
parent ba9b1814
......@@ -99,14 +99,6 @@ void FileMetadataWidgetTest::cleanup()
}
void FileMetadataWidgetTest::shouldSignalOnceWithoutFile()
{
QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished);
m_widget->setItems(KFileItemList() << QUrl());
QCOMPARE(spy.count(), 1);
QCOMPARE(m_widget->items().count(), 0);
}
void FileMetadataWidgetTest::shouldSignalOnceWithEmptyFile()
{
QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished);
m_widget->setItems(KFileItemList());
......
......@@ -33,7 +33,6 @@ private Q_SLOTS:
void cleanup();
void shouldSignalOnceWithoutFile();
void shouldSignalOnceWithEmptyFile();
void shouldSignalOnceFile();
void shouldSignalOnceFiles();
void shouldShowProperties();
......
......@@ -28,9 +28,10 @@
using namespace Baloo;
FileFetchJob::FileFetchJob(const QStringList& urls, QObject* parent)
FileFetchJob::FileFetchJob(const QStringList& urls, bool canEditAll, QObject* parent)
: KJob(parent)
, m_urls(urls)
, m_canEditAll(canEditAll)
{
}
......@@ -47,9 +48,15 @@ void FileFetchJob::doStart()
QVariantMap prop = Baloo::Private::toNamedVariantMap(file.properties());
KFileMetaData::UserMetaData umd(filePath);
QVariantMap attributes = Baloo::Private::convertUserMetaData(umd);
prop.unite(attributes);
if (umd.isSupported()) {
// FIXME - check writable
QVariantMap attributes = Baloo::Private::convertUserMetaData(umd);
prop.unite(attributes);
} else {
m_canEditAll = false;
}
m_data << prop;
}
......@@ -61,3 +68,8 @@ QList<QVariantMap> Baloo::FileFetchJob::data() const
{
return m_data;
}
bool FileFetchJob::canEditAll() const
{
return m_canEditAll;
}
......@@ -30,9 +30,10 @@ class FileFetchJob : public KJob
{
Q_OBJECT
public:
explicit FileFetchJob(const QStringList& urls, QObject* parent = nullptr);
explicit FileFetchJob(const QStringList& urls, bool canEditAll, QObject* parent = nullptr);
QList<QVariantMap> data() const;
bool canEditAll() const;
void start() override;
......@@ -42,6 +43,7 @@ private Q_SLOTS:
private:
QStringList m_urls;
QList<QVariantMap> m_data;
bool m_canEditAll;
};
}
......
......@@ -140,6 +140,7 @@ void FileMetaDataProvider::slotFileFetchFinished(KJob* job)
m_data = files.first();
insertSingleFileBasicData();
}
m_readOnly = !fetchJob->canEditAll();
insertEditableData();
emit loadingFinished();
......@@ -149,6 +150,7 @@ void FileMetaDataProvider::slotLoadingFinished(KJob* job)
{
IndexedDataRetriever* ret = dynamic_cast<IndexedDataRetriever*>(job);
m_data = unite(m_data, ret->data());
m_readOnly = !ret->canEdit();
emit loadingFinished();
}
......@@ -298,6 +300,8 @@ void FileMetaDataProvider::setFileItem()
//
const QUrl url = m_fileItems.first().targetUrl();
if (!url.isLocalFile()) {
// FIXME - are extended attributes supported for remote files?
m_readOnly = true;
insertSingleFileBasicData();
emit loadingFinished();
return;
......@@ -318,7 +322,7 @@ void FileMetaDataProvider::setFileItem()
// Fully indexed by Baloo
} else {
FileFetchJob* job = new FileFetchJob(QStringList{filePath}, this);
FileFetchJob* job = new FileFetchJob(QStringList{filePath}, true, this);
connect(job, &FileFetchJob::finished, this, &FileMetaDataProvider::slotFileFetchFinished);
job->start();
}
......@@ -343,11 +347,16 @@ void FileMetaDataProvider::setFileItems()
insertFilesListBasicData();
if (!urls.isEmpty()) {
// Editing only if all URLs are local
bool canEdit = (urls.size() == m_fileItems.size());
FileFetchJob* job = new FileFetchJob(urls, this);
FileFetchJob* job = new FileFetchJob(urls, canEdit, this);
connect(job, &FileFetchJob::finished, this, &FileMetaDataProvider::slotFileFetchFinished);
job->start();
} else {
// FIXME - are extended attributes supported for remote files?
m_readOnly = true;
emit loadingFinished();
}
}
......
......@@ -162,6 +162,7 @@ void FileMetaDataWidget::Private::slotLoadingFinished()
} else {
data = m_filter->filter(data);
m_widgetFactory->setNoLinks( m_provider->realTimeIndexing() );
m_widgetFactory->setReadOnly(m_provider->isReadOnly());
m_gridLayout->setColumnStretch(0, 4);
m_gridLayout->setColumnStretch(1, 0);
m_gridLayout->setColumnStretch(2, 6);
......@@ -294,25 +295,7 @@ FileMetaDataWidget::~FileMetaDataWidget()
void FileMetaDataWidget::setItems(const KFileItemList& items)
{
KFileItemList localItemsList;
bool xAttrSuppored = true;
foreach(const KFileItem& item, items) {
QUrl url = item.targetUrl();
if (url.isLocalFile()) {
localItemsList << item;
QString path = url.toLocalFile();
KFileMetaData::UserMetaData md(path);
xAttrSuppored &= md.isSupported();
}
}
setReadOnly(!xAttrSuppored);
d->m_provider->setItems(localItemsList);
setReadOnly(!xAttrSuppored);
d->m_provider->setItems(items);
d->m_widgetFactory->setItems(items);
}
......
......@@ -64,12 +64,22 @@ void IndexedDataRetriever::slotIndexedFile(int exitCode, QProcess::ExitStatus ex
m_data = Baloo::Private::toNamedVariantMap(properties);
KFileMetaData::UserMetaData umd(m_url);
QVariantMap attributes = Baloo::Private::convertUserMetaData(umd);
m_data.unite(attributes);
if (umd.isSupported()) {
// FIXME - check writable
m_canEdit = true;
QVariantMap attributes = Baloo::Private::convertUserMetaData(umd);
m_data.unite(attributes);
}
emitResult();
}
bool IndexedDataRetriever::canEdit() const
{
return m_canEdit;
}
QVariantMap IndexedDataRetriever::data() const
{
return m_data;
......
......@@ -37,6 +37,7 @@ public:
void start() override;
QVariantMap data() const;
bool canEdit() const;
private Q_SLOTS:
void slotIndexedFile(int exitCode, QProcess::ExitStatus exitStatus);
......@@ -45,6 +46,7 @@ private:
QString m_url;
QProcess* m_process;
QVariantMap m_data;
bool m_canEdit = false;
};
}
......
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