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,7 @@ out.open(stdout, QIODevice::WriteOnly); QDataStream stream(&out); - QVariantMap map; - QMapIterator it(result.properties()); - while (it.hasNext()) { - it.next(); - KFileMetaData::PropertyInfo pi(it.key()); - map.insertMulti(pi.name(), it.value()); - } + auto map = toNamedVariantMap(result.properties()); 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()); + auto 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,39 @@ +/* + * 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. + */ +static inline QVariantMap toNamedVariantMap(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; +} +