• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDED

  • kded
kctimefactory.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
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 2 as 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#include "kctimefactory.h"
20#include <ksycoca.h>
21#include <ksycocatype.h>
22#include <kdebug.h>
23
24#include <assert.h>
25
26static inline QString key(const QString &path, const QByteArray& resource)
27{
28 return QString::fromLatin1(resource) + QLatin1Char('|') + path;
29}
30
31void KCTimeDict::addCTime(const QString &path, const QByteArray& resource, quint32 ctime)
32{
33 assert(!path.isEmpty());
34 m_hash.insert(key(path, resource), ctime );
35}
36
37quint32 KCTimeDict::ctime(const QString &path, const QByteArray& resource) const
38{
39 return m_hash.value(key(path, resource), 0);
40}
41
42void KCTimeDict::remove(const QString &path, const QByteArray &resource)
43{
44 m_hash.remove(key(path, resource));
45}
46
47void KCTimeDict::dump() const
48{
49 kDebug() << m_hash.keys();
50}
51
52QStringList KCTimeDict::resourceList() const
53{
54 QSet<QString> resources;
55 Hash::const_iterator it = m_hash.constBegin();
56 const Hash::const_iterator end = m_hash.constEnd();
57 for ( ; it != end; ++it ) {
58 const QString key = it.key();
59 const QString res = key.left(key.indexOf('|'));
60 resources.insert(res);
61 }
62 return resources.toList();
63}
64
65void KCTimeDict::load(QDataStream &str)
66{
67 QString key;
68 quint32 ctime;
69 while(true)
70 {
71 KSycocaEntry::read(str, key);
72 str >> ctime;
73 if (key.isEmpty()) break;
74 m_hash.insert(key, ctime);
75 }
76}
77
78void KCTimeDict::save(QDataStream &str) const
79{
80 Hash::const_iterator it = m_hash.constBegin();
81 const Hash::const_iterator end = m_hash.constEnd();
82 for ( ; it != end; ++it ) {
83 str << it.key() << it.value();
84 }
85 str << QString() << (quint32) 0;
86}
87
89
90KCTimeInfo::KCTimeInfo()
91 : KSycocaFactory( KST_CTimeInfo ), m_ctimeDict()
92{
93 if (!KSycoca::self()->isBuilding()) {
94 QDataStream* str = stream();
95 (*str) >> m_dictOffset;
96 } else {
97 m_dictOffset = 0;
98 }
99}
100
101KCTimeInfo::~KCTimeInfo()
102{
103}
104
105void
106KCTimeInfo::saveHeader(QDataStream &str)
107{
108 KSycocaFactory::saveHeader(str);
109
110 str << m_dictOffset;
111}
112
113void KCTimeInfo::save(QDataStream &str)
114{
115 KSycocaFactory::save(str);
116
117 m_dictOffset = str.device()->pos();
118 m_ctimeDict.save(str);
119 const int endOfFactoryData = str.device()->pos();
120 saveHeader(str);
121 str.device()->seek(endOfFactoryData);
122}
123
124KCTimeDict KCTimeInfo::loadDict() const
125{
126 KCTimeDict dict;
127 QDataStream* str = stream();
128 assert(str);
129 str->device()->seek(m_dictOffset);
130 dict.load(*str);
131 return dict;
132}
KCTimeDict
Simple dict for assocating a timestamp with each file in ksycoca.
Definition: kctimefactory.h:29
KCTimeDict::ctime
quint32 ctime(const QString &path, const QByteArray &resource) const
Definition: kctimefactory.cpp:37
KCTimeDict::resourceList
QStringList resourceList() const
Definition: kctimefactory.cpp:52
KCTimeDict::remove
void remove(const QString &path, const QByteArray &resource)
Definition: kctimefactory.cpp:42
KCTimeDict::addCTime
void addCTime(const QString &path, const QByteArray &resource, quint32 ctime)
Definition: kctimefactory.cpp:31
KCTimeDict::dump
void dump() const
Definition: kctimefactory.cpp:47
KCTimeDict::load
void load(QDataStream &str)
Definition: kctimefactory.cpp:65
KCTimeDict::save
void save(QDataStream &str) const
Definition: kctimefactory.cpp:78
KCTimeInfo::save
virtual void save(QDataStream &str)
Write out data.
Definition: kctimefactory.cpp:113
KCTimeInfo::saveHeader
virtual void saveHeader(QDataStream &str)
Write out header information.
Definition: kctimefactory.cpp:106
KCTimeInfo::~KCTimeInfo
virtual ~KCTimeInfo()
Definition: kctimefactory.cpp:101
KCTimeInfo::dict
KCTimeDict * dict()
Definition: kctimefactory.h:78
KCTimeInfo::KCTimeInfo
KCTimeInfo()
Create factory.
Definition: kctimefactory.cpp:90
KCTimeInfo::loadDict
KCTimeDict loadDict() const
Definition: kctimefactory.cpp:124
KSycocaEntry::read
static void read(QDataStream &s, QString &str)
KSycocaFactory
KSycocaFactory::saveHeader
virtual void saveHeader(QDataStream &str)
KSycocaFactory::save
virtual void save(QDataStream &str)
KSycocaFactory::stream
QDataStream * stream() const
KSycoca::self
static KSycoca * self()
QSet
kDebug
#define kDebug
key
static QString key(const QString &path, const QByteArray &resource)
Definition: kctimefactory.cpp:26
kctimefactory.h
kdebug.h
ksycoca.h
ksycocatype.h
end
const KShortcut & end()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDED

Skip menu "KDED"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal