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

KDED

  • sources
  • kde-4.14
  • kdelibs
  • 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 
26 static inline QString key(const QString &path, const QByteArray& resource)
27 {
28  return QString::fromLatin1(resource) + QLatin1Char('|') + path;
29 }
30 
31 void 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 
37 quint32 KCTimeDict::ctime(const QString &path, const QByteArray& resource) const
38 {
39  return m_hash.value(key(path, resource), 0);
40 }
41 
42 void KCTimeDict::remove(const QString &path, const QByteArray &resource)
43 {
44  m_hash.remove(key(path, resource));
45 }
46 
47 void KCTimeDict::dump() const
48 {
49  kDebug() << m_hash.keys();
50 }
51 
52 QStringList 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 
65 void 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 
78 void 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 
90 KCTimeInfo::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 
101 KCTimeInfo::~KCTimeInfo()
102 {
103 }
104 
105 void
106 KCTimeInfo::saveHeader(QDataStream &str)
107 {
108  KSycocaFactory::saveHeader(str);
109 
110  str << m_dictOffset;
111 }
112 
113 void 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 
124 KCTimeDict 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 }
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
KCTimeDict::resourceList
QStringList resourceList() const
Definition: kctimefactory.cpp:52
QHash::insert
iterator insert(const Key &key, const T &value)
kdebug.h
key
static QString key(const QString &path, const QByteArray &resource)
Definition: kctimefactory.cpp:26
QIODevice::seek
virtual bool seek(qint64 pos)
QByteArray
QDataStream
KCTimeDict::save
void save(QDataStream &str) const
Definition: kctimefactory.cpp:78
kctimefactory.h
quint32
QSet::insert
const_iterator insert(const T &value)
KSycocaFactory
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QIODevice::pos
virtual qint64 pos() const
KCTimeInfo::dict
KCTimeDict * dict()
Definition: kctimefactory.h:78
KCTimeInfo::KCTimeInfo
KCTimeInfo()
Create factory.
Definition: kctimefactory.cpp:90
ksycocatype.h
QHash::constEnd
const_iterator constEnd() const
KCTimeInfo::saveHeader
virtual void saveHeader(QDataStream &str)
Write out header information.
Definition: kctimefactory.cpp:106
QString::isEmpty
bool isEmpty() const
QSet< QString >
QString
QHash::remove
int remove(const Key &key)
QStringList
QHash::keys
QList< Key > keys() const
KCTimeInfo::save
virtual void save(QDataStream &str)
Write out data.
Definition: kctimefactory.cpp:113
QHash::value
const T value(const Key &key) const
QLatin1Char
KCTimeDict::ctime
quint32 ctime(const QString &path, const QByteArray &resource) const
Definition: kctimefactory.cpp:37
ksycoca.h
KCTimeInfo::loadDict
KCTimeDict loadDict() const
Definition: kctimefactory.cpp:124
QHash::constBegin
const_iterator constBegin() const
KCTimeDict::addCTime
void addCTime(const QString &path, const QByteArray &resource, quint32 ctime)
Definition: kctimefactory.cpp:31
KCTimeDict::remove
void remove(const QString &path, const QByteArray &resource)
Definition: kctimefactory.cpp:42
QString::left
QString left(int n) const
QSet::toList
QList< T > toList() const
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KCTimeDict::load
void load(QDataStream &str)
Definition: kctimefactory.cpp:65
QDataStream::device
QIODevice * device() const
KCTimeDict::dump
void dump() const
Definition: kctimefactory.cpp:47
KCTimeInfo::~KCTimeInfo
virtual ~KCTimeInfo()
Definition: kctimefactory.cpp:101
end
const KShortcut & end()
KSycoca::self
static KSycoca * self()
KCTimeDict
Simple dict for assocating a timestamp with each file in ksycoca.
Definition: kctimefactory.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:26:11 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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