File indexing completed on 2024-10-06 12:24:00
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 2000 Waldo Bastian <bastian@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only 0006 */ 0007 0008 #ifndef KCTIME_FACTORY_H 0009 #define KCTIME_FACTORY_H 0010 0011 #include <QHash> 0012 #include <ksycocafactory_p.h> 0013 0014 /** 0015 * Simple dict for associating a timestamp with each file in ksycoca 0016 */ 0017 class KCTimeDict 0018 { 0019 public: 0020 void addCTime(const QString &path, const QByteArray &resource, quint32 ctime); 0021 quint32 ctime(const QString &path, const QByteArray &resource) const; 0022 void remove(const QString &path, const QByteArray &resource); 0023 void dump() const; 0024 bool isEmpty() const 0025 { 0026 return m_hash.isEmpty(); 0027 } 0028 0029 void load(QDataStream &str); 0030 void save(QDataStream &str) const; 0031 0032 private: 0033 typedef QHash<QString, quint32> Hash; 0034 Hash m_hash; 0035 }; 0036 0037 /** 0038 * Internal factory for storing the timestamp of each file in ksycoca 0039 * @internal 0040 */ 0041 class KCTimeFactory : public KSycocaFactory 0042 { 0043 K_SYCOCAFACTORY(KST_CTimeInfo) 0044 public: 0045 /** 0046 * Create factory 0047 */ 0048 explicit KCTimeFactory(KSycoca *db); 0049 0050 ~KCTimeFactory() override; 0051 0052 /** 0053 * Write out header information 0054 */ 0055 void saveHeader(QDataStream &str) override; 0056 0057 /** 0058 * Write out data 0059 */ 0060 void save(QDataStream &str) override; 0061 0062 KSycocaEntry *createEntry(const QString &) const override 0063 { 0064 return nullptr; 0065 } 0066 KSycocaEntry *createEntry(int) const override 0067 { 0068 return nullptr; 0069 } 0070 0071 // Loads the dict and returns it; does not set m_ctimeDict; 0072 // this is only used in incremental mode for loading the old timestamps. 0073 KCTimeDict loadDict() const; 0074 0075 // The API for inserting/looking up entries is in KCTimeDict. 0076 KCTimeDict *dict() 0077 { 0078 return &m_ctimeDict; 0079 } 0080 0081 private: 0082 KCTimeDict m_ctimeDict; 0083 int m_dictOffset; 0084 }; 0085 0086 #endif