Changeset View
Changeset View
Standalone View
Standalone View
src/filemetadatautil.cpp
Show All 15 Lines | |||||
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * | 16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * | ||
17 | * Boston, MA 02110-1301, USA. * | 17 | * Boston, MA 02110-1301, USA. * | ||
18 | *****************************************************************************/ | 18 | *****************************************************************************/ | ||
19 | 19 | | |||
20 | #include "filemetadatautil_p.h" | 20 | #include "filemetadatautil_p.h" | ||
21 | #include <KFileMetaData/UserMetaData> | 21 | #include <KFileMetaData/UserMetaData> | ||
22 | #include <KFileMetaData/PropertyInfo> | 22 | #include <KFileMetaData/PropertyInfo> | ||
23 | 23 | | |||
24 | #include <algorithm> | ||||
25 | | ||||
24 | namespace Baloo | 26 | namespace Baloo | ||
25 | { | 27 | { | ||
26 | namespace Private | 28 | namespace Private | ||
27 | { | 29 | { | ||
28 | 30 | | |||
29 | QVariantMap convertUserMetaData(const KFileMetaData::UserMetaData& metaData) | 31 | QVariantMap convertUserMetaData(const KFileMetaData::UserMetaData& metaData) | ||
30 | { | 32 | { | ||
31 | QVariantMap properties; | 33 | QVariantMap properties; | ||
Show All 19 Lines | |||||
51 | } | 53 | } | ||
52 | 54 | | |||
53 | return properties; | 55 | return properties; | ||
54 | } | 56 | } | ||
55 | 57 | | |||
56 | QVariantMap toNamedVariantMap(const KFileMetaData::PropertyMap& propMap) | 58 | QVariantMap toNamedVariantMap(const KFileMetaData::PropertyMap& propMap) | ||
57 | { | 59 | { | ||
58 | QVariantMap map; | 60 | QVariantMap map; | ||
59 | KFileMetaData::PropertyMap::const_iterator it = propMap.constBegin(); | 61 | if (propMap.isEmpty()) { | ||
60 | for (; it != propMap.constEnd(); it++) { | 62 | return map; | ||
61 | KFileMetaData::PropertyInfo pi(it.key()); | 63 | } | ||
62 | map.insertMulti(pi.name(), it.value()); | 64 | | ||
65 | using entry = std::pair<const KFileMetaData::Property::Property&, const QVariant&>; | ||||
66 | | ||||
67 | auto begin = propMap.constKeyValueBegin(); | ||||
68 | | ||||
bruns: no longer needed here, rangeEnd is set in the loop. | |||||
69 | while (begin != propMap.constKeyValueEnd()) { | ||||
70 | auto key = (*begin).first; | ||||
71 | KFileMetaData::PropertyInfo property(key); | ||||
72 | auto rangeEnd = std::find_if(begin, propMap.constKeyValueEnd(), | ||||
73 | [key](const entry& e) { return e.first != key; }); | ||||
74 | | ||||
75 | auto distance = std::distance(begin, rangeEnd); | ||||
76 | if (distance > 1) { | ||||
77 | QVariantList list; | ||||
78 | list.reserve(static_cast<int>(distance)); | ||||
79 | std::for_each(begin, rangeEnd, [&list](const entry& s) { list.append(s.second); }); | ||||
80 | map.insert(property.name(), list); | ||||
81 | } else { | ||||
82 | map.insert(property.name(), (*begin).second); | ||||
83 | } | ||||
84 | begin = rangeEnd; | ||||
63 | } | 85 | } | ||
64 | 86 | | |||
65 | return map; | 87 | return map; | ||
66 | } | 88 | } | ||
67 | 89 | | |||
68 | } // namespace KFMPrivate | 90 | } // namespace KFMPrivate | ||
69 | } // namespace Baloo | 91 | } // namespace Baloo |
no longer needed here, rangeEnd is set in the loop.