]> cloud.milkyroute.net Git - dolphin.git/commitdiff
handle maps with multiple or single entries from Baloo
authorAlexander Stippich <a.stippich@gmx.net>
Tue, 21 May 2019 18:27:29 +0000 (20:27 +0200)
committerAlexander Stippich <a.stippich@gmx.net>
Thu, 30 May 2019 09:18:41 +0000 (11:18 +0200)
Summary:
Handle maps which may contain multiple entries with the same key.
Bumps frameworks to 5.58. Equivalent to D20739.

Reviewers: #dolphin, elvisangelaccio, bruns

Reviewed By: #dolphin, elvisangelaccio, bruns

Subscribers: kfm-devel

Tags: #dolphin

Differential Revision: https://phabricator.kde.org/D21157

CMakeLists.txt
src/kitemviews/private/kbaloorolesprovider.cpp

index 78a89a55821ea9eb796a8af8a7ac8969f1b35647..7816b5717e4a0323f7a2bf044f3dbaf9a4330b1e 100644 (file)
@@ -8,7 +8,7 @@ set (KDE_APPLICATIONS_VERSION "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATI
 project(Dolphin VERSION ${KDE_APPLICATIONS_VERSION})
 
 set(QT_MIN_VERSION "5.8.0")
-set(KF5_MIN_VERSION "5.56.0")
+set(KF5_MIN_VERSION "5.58.0")
 
 # ECM setup
 find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED)
index 469f0791550a9a5d152a8f8a0c35a1e44bf74582..f3671540dd89c4e6d49fbfdfe18404d978d44c4b 100644 (file)
@@ -56,18 +56,34 @@ QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& f
 {
     QHash<QByteArray, QVariant> values;
 
-    QMapIterator<KFileMetaData::Property::Property, QVariant> it(file.properties());
-    while (it.hasNext()) {
-        it.next();
+    using entry = std::pair<const KFileMetaData::Property::Property&, const QVariant&>;
+
+    const auto& propMap = file.properties();
+    auto rangeBegin = propMap.constKeyValueBegin();
+
+    while (rangeBegin != propMap.constKeyValueEnd()) {
+        auto key = (*rangeBegin).first;
+        const KFileMetaData::PropertyInfo propertyInfo(key);
+        const QByteArray role = roleForProperty(propertyInfo.name());
+
+        auto rangeEnd = std::find_if(rangeBegin, propMap.constKeyValueEnd(),
+            [key](const entry& e) { return e.first != key; });
 
-        const KFileMetaData::PropertyInfo pi(it.key());
-        const QString property = pi.name();
-        const QByteArray role = roleForProperty(property);
         if (role.isEmpty() || !roles.contains(role)) {
+            rangeBegin = rangeEnd;
             continue;
         }
 
-        values.insert(role, pi.formatAsDisplayString(it.value()));
+        auto distance = std::distance(rangeBegin, rangeEnd);
+        if (distance > 1) {
+            QVariantList list;
+            list.reserve(static_cast<int>(distance));
+            std::for_each(rangeBegin, rangeEnd, [&list](const entry& s) { list.append(s.second); });
+            values.insert(role, propertyInfo.formatAsDisplayString(list));
+        } else {
+            values.insert(role, propertyInfo.formatAsDisplayString((*rangeBegin).second));
+        }
+        rangeBegin = rangeEnd;
     }
 
     KFileMetaData::UserMetaData md(file.path());