Warning, file /frameworks/kservice/src/sycoca/kctimefactory.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2000 Waldo Bastian <bastian@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 
0008 #include "kctimefactory_p.h"
0009 #include "sycocadebug.h"
0010 #include <ksycoca.h>
0011 #include <ksycocatype.h>
0012 #include <ksycocautils_p.h>
0013 
0014 #include <assert.h>
0015 
0016 // NOTE: the storing of "resource" here is now completely useless (since everything is under GenericDataLocation)
0017 
0018 static inline QString key(const QString &path, const QByteArray &resource)
0019 {
0020     return QString::fromLatin1(resource) + QLatin1Char('|') + path;
0021 }
0022 
0023 void KCTimeDict::addCTime(const QString &path, const QByteArray &resource, quint32 ctime)
0024 {
0025     Q_ASSERT(ctime != 0);
0026     assert(!path.isEmpty());
0027     m_hash.insert(key(path, resource), ctime);
0028 }
0029 
0030 quint32 KCTimeDict::ctime(const QString &path, const QByteArray &resource) const
0031 {
0032     return m_hash.value(key(path, resource), 0);
0033 }
0034 
0035 void KCTimeDict::remove(const QString &path, const QByteArray &resource)
0036 {
0037     m_hash.remove(key(path, resource));
0038 }
0039 
0040 void KCTimeDict::dump() const
0041 {
0042     qCDebug(SYCOCA) << m_hash.keys();
0043 }
0044 
0045 void KCTimeDict::load(QDataStream &str)
0046 {
0047     QString key;
0048     quint32 ctime;
0049     while (true) {
0050         str >> key >> ctime;
0051         if (key.isEmpty()) {
0052             break;
0053         }
0054         m_hash.insert(key, ctime);
0055     }
0056 }
0057 
0058 void KCTimeDict::save(QDataStream &str) const
0059 {
0060     for (auto it = m_hash.cbegin(), endIt = m_hash.cend(); it != endIt; ++it) {
0061         str << it.key() << it.value();
0062     }
0063     str << QString() << quint32(0);
0064 }
0065 
0066 ///////////
0067 
0068 KCTimeFactory::KCTimeFactory(KSycoca *db)
0069     : KSycocaFactory(KST_CTimeInfo, db)
0070     , m_ctimeDict()
0071 {
0072     if (!sycoca()->isBuilding()) {
0073         QDataStream *str = stream();
0074         (*str) >> m_dictOffset;
0075     } else {
0076         m_dictOffset = 0;
0077     }
0078 }
0079 
0080 KCTimeFactory::~KCTimeFactory()
0081 {
0082 }
0083 
0084 void KCTimeFactory::saveHeader(QDataStream &str)
0085 {
0086     KSycocaFactory::saveHeader(str);
0087 
0088     str << m_dictOffset;
0089 }
0090 
0091 void KCTimeFactory::save(QDataStream &str)
0092 {
0093     KSycocaFactory::save(str);
0094 
0095     m_dictOffset = str.device()->pos();
0096     m_ctimeDict.save(str);
0097     const qint64 endOfFactoryData = str.device()->pos();
0098     saveHeader(str);
0099     str.device()->seek(endOfFactoryData);
0100 }
0101 
0102 KCTimeDict KCTimeFactory::loadDict() const
0103 {
0104     KCTimeDict dict;
0105     QDataStream *str = stream();
0106     assert(str);
0107     str->device()->seek(m_dictOffset);
0108     dict.load(*str);
0109     return dict;
0110 }