diff options
Diffstat (limited to 'src/kitemviews/private')
| -rw-r--r-- | src/kitemviews/private/kbaloorolesprovider.cpp | 135 | ||||
| -rw-r--r-- | src/kitemviews/private/kbaloorolesprovider.h | 10 | ||||
| -rw-r--r-- | src/kitemviews/private/kdirectorycontentscounterworker.cpp | 1 |
3 files changed, 78 insertions, 68 deletions
diff --git a/src/kitemviews/private/kbaloorolesprovider.cpp b/src/kitemviews/private/kbaloorolesprovider.cpp index d45b06777..5c87de712 100644 --- a/src/kitemviews/private/kbaloorolesprovider.cpp +++ b/src/kitemviews/private/kbaloorolesprovider.cpp @@ -10,13 +10,52 @@ #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(", ")); + } + + using Property = KFileMetaData::Property::Property; + // Mapping from the KFM::Property to the KFileItemModel roles. + const QHash<Property, QByteArray> propertyRoleMap() { + static const auto map = QHash<Property, QByteArray> { + { Property::Rating, QByteArrayLiteral("rating") }, + { Property::Comment, QByteArrayLiteral("comment") }, + { Property::Title, QByteArrayLiteral("title") }, + { Property::WordCount, QByteArrayLiteral("wordCount") }, + { Property::LineCount, QByteArrayLiteral("lineCount") }, + { Property::Width, QByteArrayLiteral("width") }, + { Property::Height, QByteArrayLiteral("height") }, + { Property::ImageDateTime, QByteArrayLiteral("imageDateTime") }, + { Property::ImageOrientation, QByteArrayLiteral("orientation") }, + { Property::Artist, QByteArrayLiteral("artist") }, + { Property::Genre, QByteArrayLiteral("genre") }, + { Property::Album, QByteArrayLiteral("album") }, + { Property::Duration, QByteArrayLiteral("duration") }, + { Property::BitRate, QByteArrayLiteral("bitrate") }, + { Property::AspectRatio, QByteArrayLiteral("aspectRatio") }, + { Property::FrameRate, QByteArrayLiteral("frameRate") }, + { Property::ReleaseYear, QByteArrayLiteral("releaseYear") }, + { Property::TrackNumber, QByteArrayLiteral("track") } + }; + return map; + } +} + struct KBalooRolesProviderSingleton { KBalooRolesProvider instance; @@ -50,17 +89,17 @@ QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& f 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 QByteArray role = propertyRoleMap().value(key); if (role.isEmpty() || !roles.contains(role)) { rangeBegin = rangeEnd; continue; } + const KFileMetaData::PropertyInfo propertyInfo(key); auto distance = std::distance(rangeBegin, rangeEnd); if (distance > 1) { QVariantList list; @@ -78,74 +117,54 @@ QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& f rangeBegin = rangeEnd; } - KFileMetaData::UserMetaData md(file.path()); + KFileMetaData::UserMetaData::Attributes attributes; if (roles.contains("tags")) { - values.insert("tags", tagsFromValues(md.tags())); + attributes |= KFileMetaData::UserMetaData::Tags; } if (roles.contains("rating")) { - values.insert("rating", QString::number(md.rating())); + attributes |= KFileMetaData::UserMetaData::Rating; } if (roles.contains("comment")) { - values.insert("comment", md.userComment()); + attributes |= KFileMetaData::UserMetaData::Comment; } if (roles.contains("originUrl")) { + attributes |= KFileMetaData::UserMetaData::OriginUrl; + } + + if (attributes == KFileMetaData::UserMetaData::None) { + return values; + } + + KFileMetaData::UserMetaData md(file.path()); + attributes = md.queryAttributes(attributes); + + if (attributes & KFileMetaData::UserMetaData::Tags) { + values.insert("tags", tagsFromValues(md.tags())); + } + if (attributes & KFileMetaData::UserMetaData::Rating) { + values.insert("rating", QString::number(md.rating())); + } + if (attributes & KFileMetaData::UserMetaData::Comment) { + values.insert("comment", md.userComment()); + } + if (attributes & KFileMetaData::UserMetaData::OriginUrl) { values.insert("originUrl", md.originUrl()); } return values; } -QByteArray KBalooRolesProvider::roleForProperty(const QString& property) const +KBalooRolesProvider::KBalooRolesProvider() { - return m_roleForProperty.value(property); -} - -KBalooRolesProvider::KBalooRolesProvider() : - m_roles(), - m_roleForProperty() -{ - struct PropertyInfo - { - const char* const property; - const char* const role; - }; - - // 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 - static const PropertyInfo propertyInfoList[] = { - { "rating", "rating" }, - { "tag", "tags" }, - { "comment", "comment" }, - { "title", "title" }, - { "wordCount", "wordCount" }, - { "lineCount", "lineCount" }, - { "width", "width" }, - { "height", "height" }, - { "imageDateTime", "imageDateTime"}, - { "imageOrientation", "orientation", }, - { "artist", "artist" }, - { "genre", "genre" }, - { "album", "album" }, - { "duration", "duration" }, - { "bitRate", "bitrate" }, - { "aspectRatio", "aspectRatio" }, - { "frameRate", "frameRate" }, - { "releaseYear", "releaseYear" }, - { "trackNumber", "track" }, - { "originUrl", "originUrl" } - }; - - for (unsigned int i = 0; i < sizeof(propertyInfoList) / sizeof(PropertyInfo); ++i) { - m_roleForProperty.insert(propertyInfoList[i].property, propertyInfoList[i].role); - m_roles.insert(propertyInfoList[i].role); + // Display roles filled from Baloo property cache + for (const auto& role : propertyRoleMap()) { + m_roles.insert(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(", ")); + // Display roles provided by UserMetaData + m_roles.insert(QByteArrayLiteral("tags")); + m_roles.insert(QByteArrayLiteral("rating")); + m_roles.insert(QByteArrayLiteral("comment")); + m_roles.insert(QByteArrayLiteral("originUrl")); } + diff --git a/src/kitemviews/private/kbaloorolesprovider.h b/src/kitemviews/private/kbaloorolesprovider.h index 99c601e16..97ed58f2b 100644 --- a/src/kitemviews/private/kbaloorolesprovider.h +++ b/src/kitemviews/private/kbaloorolesprovider.h @@ -42,21 +42,11 @@ public: QHash<QByteArray, QVariant> roleValues(const Baloo::File& file, const QSet<QByteArray>& roles) const; - QByteArray roleForProperty(const QString& property) const; - protected: KBalooRolesProvider(); private: - /** - * @return User visible string for the given tag-values. - * The tag-values are sorted in alphabetical order. - */ - QString tagsFromValues(const QStringList& values) const; - -private: QSet<QByteArray> m_roles; - QHash<QString, QByteArray> m_roleForProperty; friend struct KBalooRolesProviderSingleton; }; diff --git a/src/kitemviews/private/kdirectorycontentscounterworker.cpp b/src/kitemviews/private/kdirectorycontentscounterworker.cpp index 1e3b7ff9f..73799e739 100644 --- a/src/kitemviews/private/kdirectorycontentscounterworker.cpp +++ b/src/kitemviews/private/kdirectorycontentscounterworker.cpp @@ -35,6 +35,7 @@ KDirectoryContentsCounterWorker::CountResult walkDir(const QString &dirPath, auto dir = QT_OPENDIR(QFile::encodeName(dirPath)); if (dir) { count = 0; + size = 0; QT_STATBUF buf; while ((dirEntry = QT_READDIR(dir))) { |
