1 | /* |
2 | This file is part of the KDE project |
3 | SPDX-FileCopyrightText: 2000 Waldo Bastian <bastian@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-only |
6 | */ |
7 | |
8 | #ifndef KCTIME_FACTORY_H |
9 | #define KCTIME_FACTORY_H |
10 | |
11 | #include <QHash> |
12 | #include <ksycocafactory_p.h> |
13 | |
14 | /*! |
15 | * Simple dict for associating a timestamp with each file in ksycoca |
16 | * |
17 | * \internal |
18 | */ |
19 | class KCTimeDict |
20 | { |
21 | public: |
22 | void addCTime(const QString &path, const QByteArray &resource, quint32 ctime); |
23 | quint32 ctime(const QString &path, const QByteArray &resource) const; |
24 | void remove(const QString &path, const QByteArray &resource); |
25 | void dump() const; |
26 | bool isEmpty() const |
27 | { |
28 | return m_hash.isEmpty(); |
29 | } |
30 | |
31 | void load(QDataStream &str); |
32 | void save(QDataStream &str) const; |
33 | |
34 | private: |
35 | typedef QHash<QString, quint32> Hash; |
36 | Hash m_hash; |
37 | }; |
38 | |
39 | /*! |
40 | * Internal factory for storing the timestamp of each file in ksycoca |
41 | * \internal |
42 | */ |
43 | class KCTimeFactory : public KSycocaFactory |
44 | { |
45 | K_SYCOCAFACTORY(KST_CTimeInfo) |
46 | public: |
47 | /*! |
48 | * Create factory |
49 | */ |
50 | explicit KCTimeFactory(KSycoca *db); |
51 | |
52 | ~KCTimeFactory() override; |
53 | |
54 | /*! |
55 | * Write out header information |
56 | */ |
57 | void (QDataStream &str) override; |
58 | |
59 | /*! |
60 | * Write out data |
61 | */ |
62 | void save(QDataStream &str) override; |
63 | |
64 | KSycocaEntry *createEntry(const QString &) const override |
65 | { |
66 | return nullptr; |
67 | } |
68 | KSycocaEntry *createEntry(int) const override |
69 | { |
70 | return nullptr; |
71 | } |
72 | |
73 | // Loads the dict and returns it; does not set m_ctimeDict; |
74 | // this is only used in incremental mode for loading the old timestamps. |
75 | KCTimeDict loadDict() const; |
76 | |
77 | // The API for inserting/looking up entries is in KCTimeDict. |
78 | KCTimeDict *dict() |
79 | { |
80 | return &m_ctimeDict; |
81 | } |
82 | |
83 | private: |
84 | KCTimeDict m_ctimeDict; |
85 | int m_dictOffset; |
86 | }; |
87 | |
88 | #endif |
89 | |