KService

kctimefactory.cpp
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2000 Waldo Bastian <bastian@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6*/
7
8#include "kctimefactory_p.h"
9#include "sycocadebug.h"
10#include <ksycoca.h>
11#include <ksycocatype.h>
12#include <ksycocautils_p.h>
13
14#include <assert.h>
15
16// NOTE: the storing of "resource" here is now completely useless (since everything is under GenericDataLocation)
17
18static inline QString key(const QString &path, const QByteArray &resource)
19{
20 return QString::fromLatin1(resource) + QLatin1Char('|') + path;
21}
22
23void KCTimeDict::addCTime(const QString &path, const QByteArray &resource, quint32 ctime)
24{
25 Q_ASSERT(ctime != 0);
26 assert(!path.isEmpty());
27 m_hash.insert(key(path, resource), ctime);
28}
29
30quint32 KCTimeDict::ctime(const QString &path, const QByteArray &resource) const
31{
32 return m_hash.value(key(path, resource), 0);
33}
34
35void KCTimeDict::remove(const QString &path, const QByteArray &resource)
36{
37 m_hash.remove(key(path, resource));
38}
39
40void KCTimeDict::dump() const
41{
42 qCDebug(SYCOCA) << m_hash.keys();
43}
44
45void KCTimeDict::load(QDataStream &str)
46{
47 QString key;
48 quint32 ctime;
49 while (true) {
50 str >> key >> ctime;
51 if (key.isEmpty()) {
52 break;
53 }
54 m_hash.insert(key, ctime);
55 }
56}
57
58void KCTimeDict::save(QDataStream &str) const
59{
60 for (auto it = m_hash.cbegin(), endIt = m_hash.cend(); it != endIt; ++it) {
61 str << it.key() << it.value();
62 }
63 str << QString() << quint32(0);
64}
65
66///////////
67
68KCTimeFactory::KCTimeFactory(KSycoca *db)
69 : KSycocaFactory(KST_CTimeInfo, db)
70 , m_ctimeDict()
71{
72 if (!sycoca()->isBuilding()) {
73 QDataStream *str = stream();
74 (*str) >> m_dictOffset;
75 } else {
76 m_dictOffset = 0;
77 }
78}
79
80KCTimeFactory::~KCTimeFactory()
81{
82}
83
84void KCTimeFactory::saveHeader(QDataStream &str)
85{
86 KSycocaFactory::saveHeader(str);
87
88 str << m_dictOffset;
89}
90
91void KCTimeFactory::save(QDataStream &str)
92{
93 KSycocaFactory::save(str);
94
95 m_dictOffset = str.device()->pos();
96 m_ctimeDict.save(str);
97 const qint64 endOfFactoryData = str.device()->pos();
98 saveHeader(str);
99 str.device()->seek(endOfFactoryData);
100}
101
102KCTimeDict KCTimeFactory::loadDict() const
103{
104 KCTimeDict dict;
105 QDataStream *str = stream();
106 assert(str);
107 str->device()->seek(m_dictOffset);
108 dict.load(*str);
109 return dict;
110}
QString path(const QString &relativePath)
QIODevice * device() const const
virtual qint64 pos() const const
virtual bool seek(qint64 pos)
QString fromLatin1(QByteArrayView str)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:21 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.