1/* This file is part of the KDE project
2 Copyright (C) 2000 Waldo Bastian <bastian@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#ifndef KDED_KCTIME_FACTORY_H
20#define KDED_KCTIME_FACTORY_H
21
22#include <ksycocafactory.h>
23#include <QtCore/QHash>
24
25/**
26 * Simple dict for assocating a timestamp with each file in ksycoca
27 */
28class KCTimeDict
29{
30public:
31 void addCTime(const QString &path, const QByteArray& resource, quint32 ctime);
32 quint32 ctime(const QString &path, const QByteArray& resource) const;
33 void remove(const QString &path, const QByteArray& resource);
34 void dump() const;
35 bool isEmpty() const { return m_hash.isEmpty(); }
36 QStringList resourceList() const;
37
38 void load(QDataStream &str);
39 void save(QDataStream &str) const;
40private:
41 typedef QHash<QString, quint32> Hash;
42 Hash m_hash;
43};
44
45/**
46 * Internal factory for storing the timestamp of each file in ksycoca
47 * @internal
48 */
49class KCTimeInfo : public KSycocaFactory // TODO rename to KCTimeFactory
50{
51 K_SYCOCAFACTORY( KST_CTimeInfo )
52public:
53 /**
54 * Create factory
55 */
56 KCTimeInfo();
57
58 virtual ~KCTimeInfo();
59
60 /**
61 * Write out header information
62 */
63 virtual void saveHeader(QDataStream &str);
64
65 /**
66 * Write out data
67 */
68 virtual void save(QDataStream &str);
69
70 KSycocaEntry * createEntry(const QString &, const char *) const { return 0; }
71 KSycocaEntry * createEntry(int) const { return 0; }
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() { return &m_ctimeDict; }
79
80private:
81 KCTimeDict m_ctimeDict;
82 int m_dictOffset;
83};
84
85#endif
86