-/***************************************************************************
- * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
- * Copyright (C) 2013 by Vishesh Handa <me@vhanda.in> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program 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 General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
+ * SPDX-FileCopyrightText: 2013 Vishesh Handa <me@vhanda.in>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
#include "kbaloorolesprovider.h"
{
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;
}
- const QVariant value = it.value();
-
- if (role == "orientation") {
- const QString orientation = orientationFromValue(value.toInt());
- values.insert(role, orientation);
- } else if (role == "duration") {
- const QString duration = durationFromValue(value.toInt());
- values.insert(role, duration);
- } else if (role == "bitrate") {
- const QString bitrate = bitrateFromValue(value.toInt());
- values.insert(role, bitrate);
+ 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, value.toString());
+ if (propertyInfo.valueType() == QVariant::DateTime) {
+ // Let dolphin format later Dates
+ values.insert(role, (*rangeBegin).second);
+ } else {
+ values.insert(role, propertyInfo.formatAsDisplayString((*rangeBegin).second));
+ }
}
+ rangeBegin = rangeEnd;
}
KFileMetaData::UserMetaData md(file.path());
{ "width", "width" },
{ "height", "height" },
{ "imageDateTime", "imageDateTime"},
- { "nexif.orientation", "orientation", },
+ { "imageOrientation", "orientation", },
{ "artist", "artist" },
{ "genre", "genre" },
{ "album", "album" },
{ "duration", "duration" },
{ "bitRate", "bitrate" },
+ { "aspectRatio", "aspectRatio" },
+ { "frameRate", "frameRate" },
{ "releaseYear", "releaseYear" },
{ "trackNumber", "track" },
{ "originUrl", "originUrl" }
QCollator coll;
coll.setNumericMode(true);
std::sort(alphabeticalOrderTags.begin(), alphabeticalOrderTags.end(), [&](const QString& s1, const QString& s2){ return coll.compare(s1, s2) < 0; });
- return alphabeticalOrderTags.join(QStringLiteral(", "));
-}
-
-QString KBalooRolesProvider::orientationFromValue(int value) const
-{
- QString string;
- switch (value) {
- case 1: string = i18nc("@item:intable Image orientation", "Unchanged"); break;
- case 2: string = i18nc("@item:intable Image orientation", "Horizontally flipped"); break;
- case 3: string = i18nc("@item:intable image orientation", "180° rotated"); break;
- case 4: string = i18nc("@item:intable image orientation", "Vertically flipped"); break;
- case 5: string = i18nc("@item:intable image orientation", "Transposed"); break;
- case 6: string = i18nc("@item:intable image orientation", "90° rotated"); break;
- case 7: string = i18nc("@item:intable image orientation", "Transversed"); break;
- case 8: string = i18nc("@item:intable image orientation", "270° rotated"); break;
- default:
- break;
- }
- return string;
+ return alphabeticalOrderTags.join(QLatin1String(", "));
}
-
-QString KBalooRolesProvider::durationFromValue(int value) const
-{
- QTime duration(0, 0, 0);
- duration = duration.addSecs(value);
- return duration.toString(QStringLiteral("hh:mm:ss"));
-}
-
-
-QString KBalooRolesProvider::bitrateFromValue(int value) const
-{
- KFormat form;
- QString bitrate = i18nc("@label bitrate (per second)", "%1/s", form.formatByteSize(value, 1, KFormat::MetricBinaryDialect));
- return bitrate;
-}
-