File indexing completed on 2024-04-21 03:51:39

0001 /*
0002     This file is part of the KDE Baloo project.
0003     SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-or-later
0006 */
0007 
0008 #ifndef BALOO_DOCUMENTTIMEDB_H
0009 #define BALOO_DOCUMENTTIMEDB_H
0010 
0011 #include "engine_export.h"
0012 
0013 #include <QMap>
0014 #include <QDebug>
0015 #include <lmdb.h>
0016 
0017 namespace Baloo {
0018 
0019 class BALOO_ENGINE_EXPORT DocumentTimeDB
0020 {
0021 public:
0022     DocumentTimeDB(MDB_dbi dbi, MDB_txn* txn);
0023     ~DocumentTimeDB();
0024 
0025     static MDB_dbi create(MDB_txn* txn);
0026     static MDB_dbi open(MDB_txn* txn);
0027 
0028     struct TimeInfo
0029     {
0030         /** Tracking of file time stamps
0031           *
0032           * @sa QDateTime::toSecsSinceEpoch()
0033           * @sa QFileInfo::lastModified()
0034           * @sa QFileInfo::metadataChangeTime()
0035           */
0036         quint32 mTime; /**< file (data) modification time */
0037         quint32 cTime; /**< metadata (e.g. XAttr) change time */
0038         /* No birthtime yet */
0039 
0040         explicit TimeInfo(quint32 mt = 0, quint32 ct = 0) : mTime(mt), cTime(ct) {}
0041 
0042         bool operator == (const TimeInfo& rhs) const {
0043             return mTime == rhs.mTime && cTime == rhs.cTime;
0044         }
0045     };
0046     void put(quint64 docId, const TimeInfo& info);
0047     TimeInfo get(quint64 docId);
0048 
0049     void del(quint64 docId);
0050     bool contains(quint64 docId);
0051 
0052     QMap<quint64, TimeInfo> toTestMap() const;
0053 private:
0054     MDB_txn* m_txn;
0055     MDB_dbi m_dbi;
0056 };
0057 
0058 inline QDebug operator<<(QDebug dbg, const DocumentTimeDB::TimeInfo &time) {
0059     dbg << "(" << time.mTime << "," << time.cTime << ")";
0060     return dbg;
0061 }
0062 
0063 }
0064 
0065 #endif // BALOO_DOCUMENTTIMEDB_H