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 */
17class KCTimeDict
18{
19public:
20 void addCTime(const QString &path, const QByteArray &resource, quint32 ctime);
21 quint32 ctime(const QString &path, const QByteArray &resource) const;
22 void remove(const QString &path, const QByteArray &resource);
23 void dump() const;
24 bool isEmpty() const
25 {
26 return m_hash.isEmpty();
27 }
28
29 void load(QDataStream &str);
30 void save(QDataStream &str) const;
31
32private:
33 typedef QHash<QString, quint32> Hash;
34 Hash m_hash;
35};
36
37/**
38 * Internal factory for storing the timestamp of each file in ksycoca
39 * @internal
40 */
41class KCTimeFactory : public KSycocaFactory
42{
43 K_SYCOCAFACTORY(KST_CTimeInfo)
44public:
45 /**
46 * Create factory
47 */
48 explicit KCTimeFactory(KSycoca *db);
49
50 ~KCTimeFactory() override;
51
52 /**
53 * Write out header information
54 */
55 void saveHeader(QDataStream &str) override;
56
57 /**
58 * Write out data
59 */
60 void save(QDataStream &str) override;
61
62 KSycocaEntry *createEntry(const QString &) const override
63 {
64 return nullptr;
65 }
66 KSycocaEntry *createEntry(int) const override
67 {
68 return nullptr;
69 }
70
71 // Loads the dict and returns it; does not set m_ctimeDict;
72 // this is only used in incremental mode for loading the old timestamps.
73 KCTimeDict loadDict() const;
74
75 // The API for inserting/looking up entries is in KCTimeDict.
76 KCTimeDict *dict()
77 {
78 return &m_ctimeDict;
79 }
80
81private:
82 KCTimeDict m_ctimeDict;
83 int m_dictOffset;
84};
85
86#endif
87

source code of kservice/src/sycoca/kctimefactory_p.h