]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/private/kbaloorolesprovider.cpp
Use qplatformdefs wrappers
[dolphin.git] / src / kitemviews / private / kbaloorolesprovider.cpp
index 74f789e236cf5dede0f215db9d640c4f523faa08..53fc0b3b9cac1d95540756cdeb4ed706ede102ee 100644 (file)
 
 #include "kbaloorolesprovider.h"
 
-#include <KDebug>
-#include <KGlobal>
-#include <KLocale>
+#include <QDebug>
+#include <KLocalizedString>
 
 #include <Baloo/File>
 #include <KFileMetaData/PropertyInfo>
 #include <KFileMetaData/UserMetaData>
+#include <KFormat>
 
 #include <QTime>
 #include <QMap>
+#include <QCollator>
 
 struct KBalooRolesProviderSingleton
 {
     KBalooRolesProvider instance;
 };
-K_GLOBAL_STATIC(KBalooRolesProviderSingleton, s_balooRolesProvider)
+Q_GLOBAL_STATIC(KBalooRolesProviderSingleton, s_balooRolesProvider)
 
 
 KBalooRolesProvider& KBalooRolesProvider::instance()
@@ -95,6 +96,9 @@ QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& f
         } 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 {
             values.insert(role, value.toString());
         }
@@ -110,6 +114,9 @@ QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& f
     if (roles.contains("comment")) {
         values.insert("comment", md.userComment());
     }
+    if (roles.contains("originUrl")) {
+        values.insert("originUrl", md.originUrl());
+    }
 
     return values;
 }
@@ -136,16 +143,21 @@ KBalooRolesProvider::KBalooRolesProvider() :
         { "rating", "rating" },
         { "tag",        "tags" },
         { "comment",   "comment" },
+        { "title",         "title" },
         { "wordCount",     "wordCount" },
         { "lineCount",     "lineCount" },
         { "width",         "imageSize" },
         { "height",        "imageSize" },
+        { "imageDateTime",   "imageDateTime"},
         { "nexif.orientation", "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) {
@@ -156,7 +168,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
@@ -179,8 +195,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;
 }