| 1 | /* |
| 2 | This file is part of the KDE Baloo project. |
| 3 | SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 | */ |
| 7 | |
| 8 | #ifndef BALOO_DOCUMENTTIMEDB_H |
| 9 | #define BALOO_DOCUMENTTIMEDB_H |
| 10 | |
| 11 | #include "engine_export.h" |
| 12 | |
| 13 | #include <QMap> |
| 14 | #include <QDebug> |
| 15 | #include <lmdb.h> |
| 16 | |
| 17 | namespace Baloo { |
| 18 | |
| 19 | class BALOO_ENGINE_EXPORT DocumentTimeDB |
| 20 | { |
| 21 | public: |
| 22 | DocumentTimeDB(MDB_dbi dbi, MDB_txn* txn); |
| 23 | ~DocumentTimeDB(); |
| 24 | |
| 25 | static MDB_dbi create(MDB_txn* txn); |
| 26 | static MDB_dbi open(MDB_txn* txn); |
| 27 | |
| 28 | struct TimeInfo |
| 29 | { |
| 30 | /** Tracking of file time stamps |
| 31 | * |
| 32 | * @sa QDateTime::toSecsSinceEpoch() |
| 33 | * @sa QFileInfo::lastModified() |
| 34 | * @sa QFileInfo::metadataChangeTime() |
| 35 | */ |
| 36 | quint32 mTime; /**< file (data) modification time */ |
| 37 | quint32 cTime; /**< metadata (e.g. XAttr) change time */ |
| 38 | /* No birthtime yet */ |
| 39 | |
| 40 | explicit TimeInfo(quint32 mt = 0, quint32 ct = 0) : mTime(mt), cTime(ct) {} |
| 41 | |
| 42 | bool operator == (const TimeInfo& rhs) const { |
| 43 | return mTime == rhs.mTime && cTime == rhs.cTime; |
| 44 | } |
| 45 | }; |
| 46 | void put(quint64 docId, const TimeInfo& info); |
| 47 | TimeInfo get(quint64 docId); |
| 48 | |
| 49 | void del(quint64 docId); |
| 50 | bool contains(quint64 docId); |
| 51 | |
| 52 | QMap<quint64, TimeInfo> toTestMap() const; |
| 53 | private: |
| 54 | MDB_txn* m_txn; |
| 55 | MDB_dbi m_dbi; |
| 56 | }; |
| 57 | |
| 58 | inline QDebug operator<<(QDebug dbg, const DocumentTimeDB::TimeInfo &time) { |
| 59 | dbg << "(" << time.mTime << "," << time.cTime << ")" ; |
| 60 | return dbg; |
| 61 | } |
| 62 | |
| 63 | } |
| 64 | |
| 65 | #endif // BALOO_DOCUMENTTIMEDB_H |
| 66 | |