File indexing completed on 2024-05-12 15:51:16

0001 // SPDX-FileCopyrightText: 2015 Dan Leinir Turthra Jensen <admin@leinir.dk>
0002 // SPDX-License-Identifier: LGPL-2.1-only or LGPL-3.0-only or LicenseRef-KDE-Accepted-LGPL
0003 
0004 #include "contentlisterbase.h"
0005 
0006 #include <QDateTime>
0007 #include <QFileInfo>
0008 #include <QVariantMap>
0009 
0010 #include <KFileMetaData/UserMetaData>
0011 
0012 ContentListerBase::ContentListerBase(QObject *parent)
0013     : QObject(parent)
0014 {
0015 }
0016 
0017 ContentListerBase::~ContentListerBase() = default;
0018 
0019 void ContentListerBase::startSearch(const QList<ContentQuery *> &queries)
0020 {
0021     Q_UNUSED(queries);
0022 }
0023 
0024 QVariantMap ContentListerBase::metaDataForFile(const QString &file)
0025 {
0026     QVariantMap metadata;
0027 
0028     // TODO: This should include the same information for both the Baloo and
0029     // File searchers. Unfortunately, currently KFileMetaData does not seem able
0030     // to provide this. So this needs changes at a lower level.
0031 
0032     QFileInfo info(file);
0033     metadata[QStringLiteral("lastModified")] = info.lastModified();
0034     metadata[QStringLiteral("created")] = info.birthTime();
0035     metadata[QStringLiteral("lastRead")] = info.lastRead();
0036 
0037     KFileMetaData::UserMetaData data(file);
0038     if (data.hasAttribute(QStringLiteral("peruse.currentPage"))) {
0039         int currentPage = data.attribute(QStringLiteral("peruse.currentPage")).toInt();
0040         metadata[QStringLiteral("currentPage")] = QVariant::fromValue<int>(currentPage);
0041     }
0042     if (data.hasAttribute(QStringLiteral("peruse.totalPages"))) {
0043         int totalPages = data.attribute(QStringLiteral("peruse.totalPages")).toInt();
0044         metadata[QStringLiteral("totalPages")] = QVariant::fromValue<int>(totalPages);
0045     }
0046     if (!data.tags().isEmpty()) {
0047         metadata[QStringLiteral("tags")] = QVariant::fromValue<QStringList>(data.tags());
0048     }
0049     if (!data.userComment().isEmpty()) {
0050         metadata[QStringLiteral("comment")] = QVariant::fromValue<QString>(data.userComment());
0051     }
0052     metadata[QStringLiteral("rating")] = QVariant::fromValue<int>(data.rating());
0053 
0054     return metadata;
0055 }
0056 
0057 #include "moc_contentlisterbase.cpp"