]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/private/kbaloorolesprovider.cpp
[BalooRolesProvider] Simplify single tag case
[dolphin.git] / src / kitemviews / private / kbaloorolesprovider.cpp
index 8a2a64b31d5fdce3044cb7f193787fb6c03e09fd..2c891bb79085f1640d3d6d32caf066b227a83eef 100644 (file)
@@ -1,35 +1,35 @@
-/***************************************************************************
- *   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"
 
 #include <Baloo/File>
 #include <KFileMetaData/PropertyInfo>
 #include <KFileMetaData/UserMetaData>
-#include <KFormat>
-#include <KLocalizedString>
 
 #include <QCollator>
 #include <QDebug>
 #include <QTime>
 
+namespace {
+    QString tagsFromValues(const QStringList& values)
+    {
+        if (values.size() == 1) {
+            return values.at(0);
+        }
+
+        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(QLatin1String(", "));
+    }
+}
+
 struct KBalooRolesProviderSingleton
 {
     KBalooRolesProvider instance;
@@ -81,7 +81,12 @@ QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& f
             std::for_each(rangeBegin, rangeEnd, [&list](const entry& s) { list.append(s.second); });
             values.insert(role, propertyInfo.formatAsDisplayString(list));
         } else {
-            values.insert(role, propertyInfo.formatAsDisplayString((*rangeBegin).second));
+            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;
     }
@@ -147,13 +152,6 @@ KBalooRolesProvider::KBalooRolesProvider() :
         m_roleForProperty.insert(propertyInfoList[i].property, propertyInfoList[i].role);
         m_roles.insert(propertyInfoList[i].role);
     }
-}
 
-QString KBalooRolesProvider::tagsFromValues(const QStringList& values) const
-{
-    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(QLatin1String(", "));
 }
+