]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/private/kbaloorolesprovider.cpp
Fix a bunch of Qt6/Kf6 warnings
[dolphin.git] / src / kitemviews / private / kbaloorolesprovider.cpp
index 5c87de7129f9570d76fca0a8b8ac3e2faddedc49..1a9bebb8ba679e8b5a9ef9a16dd38ffd38508d21 100644 (file)
 #include <KFileMetaData/UserMetaData>
 
 #include <QCollator>
-#include <QDebug>
-#include <QTime>
-
-namespace {
-    QString tagsFromValues(const QStringList& values)
-    {
-        if (values.size() == 1) {
-            return values.at(0);
-        }
+#include <QSize>
 
-        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(", "));
+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(", "));
+}
+
     using Property = KFileMetaData::Property::Property;
     // Mapping from the KFM::Property to the KFileItemModel roles.
     const QHash<Property, QByteArray> propertyRoleMap() {
@@ -36,6 +38,9 @@ namespace {
             { Property::Rating,            QByteArrayLiteral("rating") },
             { Property::Comment,           QByteArrayLiteral("comment") },
             { Property::Title,             QByteArrayLiteral("title") },
+            { Property::Author,            QByteArrayLiteral("author") },
+            { Property::Publisher,         QByteArrayLiteral("publisher") },
+            { Property::PageCount,         QByteArrayLiteral("pageCount") },
             { Property::WordCount,         QByteArrayLiteral("wordCount") },
             { Property::LineCount,         QByteArrayLiteral("lineCount") },
             { Property::Width,             QByteArrayLiteral("width") },
@@ -56,14 +61,12 @@ namespace {
     }
 }
 
-struct KBalooRolesProviderSingleton
-{
+struct KBalooRolesProviderSingleton {
     KBalooRolesProvider instance;
 };
 Q_GLOBAL_STATIC(KBalooRolesProviderSingleton, s_balooRolesProvider)
 
-
-KBalooRolesProvider& KBalooRolesProvider::instance()
+KBalooRolesProvider &KBalooRolesProvider::instance()
 {
     return s_balooRolesProvider->instance;
 }
@@ -77,21 +80,21 @@ QSet<QByteArray> KBalooRolesProvider::roles() const
     return m_roles;
 }
 
-QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& file,
-                                                            const QSet<QByteArray>& roles) const
+QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File &file, const QSet<QByteArray> &roles) const
 {
     QHash<QByteArray, QVariant> values;
 
-    using entry = std::pair<const KFileMetaData::Property::Property&, const QVariant&>;
+    using entry = std::pair<const KFileMetaData::Property::Property &, const QVariant &>;
 
-    const autopropMap = file.properties();
+    const auto &propMap = file.properties();
     auto rangeBegin = propMap.constKeyValueBegin();
 
     while (rangeBegin != propMap.constKeyValueEnd()) {
         auto key = (*rangeBegin).first;
 
-        auto rangeEnd = std::find_if(rangeBegin, propMap.constKeyValueEnd(),
-            [key](const entry& e) { return e.first != key; });
+        auto rangeEnd = std::find_if(rangeBegin, propMap.constKeyValueEnd(), [key](const entry &e) {
+            return e.first != key;
+        });
 
         const QByteArray role = propertyRoleMap().value(key);
         if (role.isEmpty() || !roles.contains(role)) {
@@ -104,10 +107,12 @@ QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& f
         if (distance > 1) {
             QVariantList list;
             list.reserve(static_cast<int>(distance));
-            std::for_each(rangeBegin, rangeEnd, [&list](const entry& s) { list.append(s.second); });
+            std::for_each(rangeBegin, rangeEnd, [&list](const entry &s) {
+                list.append(s.second);
+            });
             values.insert(role, propertyInfo.formatAsDisplayString(list));
         } else {
-            if (propertyInfo.valueType() == QVariant::DateTime) {
+            if (propertyInfo.valueTypeId() == QMetaType::Type::DateTime) {
                 // Let dolphin format later Dates
                 values.insert(role, (*rangeBegin).second);
             } else {
@@ -117,6 +122,18 @@ QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& f
         rangeBegin = rangeEnd;
     }
 
+    if (roles.contains("dimensions")) {
+        bool widthOk = false;
+        bool heightOk = false;
+
+        const int width = propMap.value(KFileMetaData::Property::Width).toInt(&widthOk);
+        const int height = propMap.value(KFileMetaData::Property::Height).toInt(&heightOk);
+
+        if (widthOk && heightOk && width >= 0 && height >= 0) {
+            values.insert("dimensions", QSize(width, height));
+        }
+    }
+
     KFileMetaData::UserMetaData::Attributes attributes;
     if (roles.contains("tags")) {
         attributes |= KFileMetaData::UserMetaData::Tags;
@@ -157,9 +174,10 @@ QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& f
 KBalooRolesProvider::KBalooRolesProvider()
 {
     // Display roles filled from Baloo property cache
-    for (const autorole : propertyRoleMap()) {
+    for (const auto &role : propertyRoleMap()) {
         m_roles.insert(role);
     }
+    m_roles.insert("dimensions");
 
     // Display roles provided by UserMetaData
     m_roles.insert(QByteArrayLiteral("tags"));
@@ -167,4 +185,3 @@ KBalooRolesProvider::KBalooRolesProvider()
     m_roles.insert(QByteArrayLiteral("comment"));
     m_roles.insert(QByteArrayLiteral("originUrl"));
 }
-