diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ project(baloo-widgets VERSION ${KDE_APPLICATIONS_VERSION}) set(QT_MIN_VERSION "5.8.0") -set(KF5_MIN_VERSION "5.57.0") +set(KF5_MIN_VERSION "5.58.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ${ECM_MODULE_PATH}) diff --git a/src/extractor.cpp b/src/extractor.cpp --- a/src/extractor.cpp +++ b/src/extractor.cpp @@ -20,6 +20,8 @@ * */ +#include "propertymaputil_p.h" + #include #include #include @@ -64,13 +66,8 @@ out.open(stdout, QIODevice::WriteOnly); QDataStream stream(&out); - QVariantMap map; + auto map = toNamedVariantMap(result.properties()); QMapIterator it(result.properties()); - while (it.hasNext()) { - it.next(); - KFileMetaData::PropertyInfo pi(it.key()); - map.insertMulti(pi.name(), it.value()); - } KFileMetaData::UserMetaData md(url); QStringList tags = md.tags(); diff --git a/src/filefetchjob.cpp b/src/filefetchjob.cpp --- a/src/filefetchjob.cpp +++ b/src/filefetchjob.cpp @@ -19,6 +19,7 @@ */ #include "filefetchjob.h" +#include "propertymaputil_p.h" #include #include @@ -39,25 +40,13 @@ QTimer::singleShot(0, this, SLOT(doStart())); } -static QVariantMap convertPropertyMap(const KFileMetaData::PropertyMap& propMap) -{ - QVariantMap map; - KFileMetaData::PropertyMap::const_iterator it = propMap.constBegin(); - for (; it != propMap.constEnd(); it++) { - KFileMetaData::PropertyInfo pi(it.key()); - map.insertMulti(pi.name(), it.value()); - } - - return map; -} - void FileFetchJob::doStart() { for (const QString& filePath : m_urls) { Baloo::File file(filePath); file.load(); - QVariantMap prop = convertPropertyMap(file.properties()); + QVariantMap prop = toNamedVariantMap(file.properties()); KFileMetaData::UserMetaData md(filePath); QStringList tags = md.tags(); diff --git a/src/propertymaputil_p.h b/src/propertymaputil_p.h new file mode 100644 --- /dev/null +++ b/src/propertymaputil_p.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2019 Alexander Stippich + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include +#include + +/** + * Converts the property map into a variant map + * using the property name as key. Converts maps + * with duplicated keys into single entry maps + * with lists. + */ +static inline QVariantMap toNamedVariantMap(const KFileMetaData::PropertyMap& propMap) +{ + QVariantMap map; + auto it = propMap.constBegin(); + while (it != propMap.constEnd()) { + KFileMetaData::PropertyInfo pi(it.key()); + auto nextIt = ++it; + if (nextIt != propMap.constEnd()) { + break; + } + if (it.key() != nextIt.key()) { + map.insert(pi.name(), it.value()); + } else { + QVariantList list = {it.value(), nextIt.value()}; + ++nextIt; + while (nextIt != propMap.constEnd() && it.key() == nextIt.key()) { + list.append(nextIt.value()); + ++nextIt; + } + map.insert(pi.name(), list); + } + it = nextIt; + } + return map; +} +