Commit a89f1260 authored by Stefan Brüns's avatar Stefan Brüns
Browse files

[WidgetFactory] Move isLocalFile() check, toLocalFile() to setters

Summary:
Avoid converting the KFileItem to a path for the common case of only
showing the file attributes.
This is the first/preparatory part.

Reviewers: #baloo, astippich, ngraham

Reviewed By: astippich

Tags: #baloo

Differential Revision: https://phabricator.kde.org/D20979
parent d04e9281
......@@ -295,7 +295,6 @@ FileMetaDataWidget::~FileMetaDataWidget()
void FileMetaDataWidget::setItems(const KFileItemList& items)
{
KFileItemList localItemsList;
QStringList list;
bool xAttrSuppored = true;
......@@ -304,7 +303,6 @@ void FileMetaDataWidget::setItems(const KFileItemList& items)
if (url.isLocalFile()) {
localItemsList << item;
QString path = url.toLocalFile();
list << path;
KFileMetaData::UserMetaData md(path);
xAttrSuppored &= md.isSupported();
......@@ -313,9 +311,9 @@ void FileMetaDataWidget::setItems(const KFileItemList& items)
setReadOnly(!xAttrSuppored);
d->m_provider->setItems(localItemsList);
d->m_widgetFactory->setItems(list);
setReadOnly(!xAttrSuppored);
d->m_widgetFactory->setItems(items);
}
KFileItemList FileMetaDataWidget::items() const
......
......@@ -252,8 +252,12 @@ QWidget* WidgetFactory::createValueWidget(const QString& value, QWidget* parent)
void WidgetFactory::slotCommentChanged(const QString& comment)
{
for (const QString& filePath : m_items) {
KFileMetaData::UserMetaData md(filePath);
for (const KFileItem& item : qAsConst(m_items)) {
QUrl url = item.targetUrl();
if (!url.isLocalFile()) {
continue;
}
KFileMetaData::UserMetaData md(url.toLocalFile());
md.setUserComment(comment);
}
emit dataChangeStarted();
......@@ -262,8 +266,12 @@ void WidgetFactory::slotCommentChanged(const QString& comment)
void WidgetFactory::slotRatingChanged(uint rating)
{
for (const QString& filePath : m_items) {
KFileMetaData::UserMetaData md(filePath);
for (const KFileItem& item : qAsConst(m_items)) {
QUrl url = item.targetUrl();
if (!url.isLocalFile()) {
continue;
}
KFileMetaData::UserMetaData md(url.toLocalFile());
md.setRating(rating);
}
emit dataChangeStarted();
......@@ -273,8 +281,12 @@ void WidgetFactory::slotRatingChanged(uint rating)
void WidgetFactory::slotTagsChanged(const QStringList& tags)
{
if (m_tagWidget) {
for (const QString& filePath : m_items) {
KFileMetaData::UserMetaData md(filePath);
for (const KFileItem& item : qAsConst(m_items)) {
QUrl url = item.targetUrl();
if (!url.isLocalFile()) {
continue;
}
KFileMetaData::UserMetaData md(url.toLocalFile());
// When multiple tags are selected one doesn't want to loose the old tags
// of any of the resources. Unless specifically removed.
......@@ -327,7 +339,7 @@ void WidgetFactory::setNoLinks(bool value)
m_noLinks = value;
}
void WidgetFactory::setItems(const QStringList& items)
void WidgetFactory::setItems(const KFileItemList& items)
{
m_items = items;
}
......
......@@ -43,7 +43,7 @@ namespace Baloo {
explicit WidgetFactory(QObject* parent = nullptr);
~WidgetFactory() override;
void setItems(const QStringList& items);
void setItems(const KFileItemList& items);
void setReadOnly(bool value);
void setNoLinks(bool value);
......@@ -76,7 +76,7 @@ namespace Baloo {
KRatingWidget* m_ratingWidget;
KCommentWidget* m_commentWidget;
QStringList m_items;
KFileItemList m_items;
QStringList m_prevTags;
bool m_readOnly;
bool m_noLinks;
......
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