]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/private/kbaloorolesprovider.cpp
Merge branch 'Applications/18.12'
[dolphin.git] / src / kitemviews / private / kbaloorolesprovider.cpp
index 5096ef096b01f3a62d9ff5d034ce929f8f1e90ee..41184e119ce0f032219972aca46ee9efce8b2911 100644 (file)
 
 #include "kbaloorolesprovider.h"
 
-#include <KDebug>
-#include <KGlobal>
-#include <KLocale>
-
 #include <Baloo/File>
 #include <KFileMetaData/PropertyInfo>
+#include <KFileMetaData/UserMetaData>
+#include <KFormat>
+#include <KLocalizedString>
 
+#include <QCollator>
+#include <QDebug>
 #include <QTime>
-#include <QMap>
 
 struct KBalooRolesProviderSingleton
 {
     KBalooRolesProvider instance;
 };
-K_GLOBAL_STATIC(KBalooRolesProviderSingleton, s_balooRolesProvider)
+Q_GLOBAL_STATIC(KBalooRolesProviderSingleton, s_balooRolesProvider)
 
 
 KBalooRolesProvider& KBalooRolesProvider::instance()
@@ -56,9 +56,6 @@ QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& f
 {
     QHash<QByteArray, QVariant> values;
 
-    int width = -1;
-    int height = -1;
-
     QMapIterator<KFileMetaData::Property::Property, QVariant> it(file.properties());
     while (it.hasNext()) {
         it.next();
@@ -72,41 +69,34 @@ QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& f
 
         const QVariant value = it.value();
 
-        if (role == "imageSize") {
-            // Merge the two properties for width and height
-            // as one string into the "imageSize" role
-            if (property == QLatin1String("width")) {
-                width = value.toInt();
-            }
-            else if (property == QLatin1String("height")) {
-                height = value.toInt();
-            }
-
-            if (width >= 0 && height >= 0) {
-                QString widthAndHeight = QString::number(width);
-                widthAndHeight += QLatin1String(" x ");
-                widthAndHeight += QString::number(height);
-                values.insert(role, widthAndHeight);
-            }
-        } else if (role == "orientation") {
+        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);
+        } else if (pi.valueType() == QVariant::StringList) {
+            values.insert(role, value.toStringList().join(QStringLiteral(", ")));
         } else {
             values.insert(role, value.toString());
         }
     }
 
+    KFileMetaData::UserMetaData md(file.path());
     if (roles.contains("tags")) {
-        values.insert("tags", tagsFromValues(file.tags()));
+        values.insert("tags", tagsFromValues(md.tags()));
     }
     if (roles.contains("rating")) {
-        values.insert("rating", QString::number(file.rating()));
+        values.insert("rating", QString::number(md.rating()));
     }
     if (roles.contains("comment")) {
-        values.insert("comment", file.userComment());
+        values.insert("comment", md.userComment());
+    }
+    if (roles.contains("originUrl")) {
+        values.insert("originUrl", md.originUrl());
     }
 
     return values;
@@ -128,22 +118,26 @@ KBalooRolesProvider::KBalooRolesProvider() :
     };
 
     // Mapping from the URIs to the KFileItemModel roles. Note that this must not be
-    // a 1:1 mapping: One role may contain several URI-values (e.g. the URIs for height and
-    // width of an image are mapped to the role "imageSize")
+    // a 1:1 mapping: One role may contain several URI-values
     static const PropertyInfo propertyInfoList[] = {
         { "rating", "rating" },
         { "tag",        "tags" },
         { "comment",   "comment" },
+        { "title",         "title" },
         { "wordCount",     "wordCount" },
         { "lineCount",     "lineCount" },
-        { "width",         "imageSize" },
-        { "height",        "imageSize" },
-        { "nexif.orientation", "orientation", },
+        { "width",         "width" },
+        { "height",        "height" },
+        { "imageDateTime",   "imageDateTime"},
+        { "imageOrientation", "orientation", },
         { "artist",     "artist" },
+        { "genre",     "genre"  },
         { "album",    "album" },
         { "duration",      "duration" },
-        { "trackNumber",   "track" }
-        // { "http://www.semanticdesktop.org/ontologies/2010/04/30/ndo#copiedFrom",    "copiedFrom" }
+        { "bitRate", "bitrate" },
+        { "releaseYear",    "releaseYear" },
+        { "trackNumber",   "track" },
+        { "originUrl", "originUrl" }
     };
 
     for (unsigned int i = 0; i < sizeof(propertyInfoList) / sizeof(PropertyInfo); ++i) {
@@ -154,7 +148,11 @@ KBalooRolesProvider::KBalooRolesProvider() :
 
 QString KBalooRolesProvider::tagsFromValues(const QStringList& values) const
 {
-    return values.join(", ");
+    QStringList alphabeticalOrderTags = values;
+    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
@@ -177,8 +175,16 @@ QString KBalooRolesProvider::orientationFromValue(int value) const
 
 QString KBalooRolesProvider::durationFromValue(int value) const
 {
-    QTime duration;
+    QTime duration(0, 0, 0);
     duration = duration.addSecs(value);
-    return duration.toString("hh:mm:ss");
+    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;
 }