KDED
kctimefactory.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 * Copyright (C) 2000 Waldo Bastian <bastian@kde.org> 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Library General Public 00006 * License version 2 as published by the Free Software Foundation; 00007 * 00008 * This library is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Library General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Library General Public License 00014 * along with this library; see the file COPYING.LIB. If not, write to 00015 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 * Boston, MA 02110-1301, USA. 00017 **/ 00018 00019 #include "kctimefactory.h" 00020 #include <ksycoca.h> 00021 #include <ksycocatype.h> 00022 #include <kdebug.h> 00023 00024 #include <assert.h> 00025 00026 static inline QString key(const QString &path, const QByteArray& resource) 00027 { 00028 return QString::fromLatin1(resource) + QLatin1Char('|') + path; 00029 } 00030 00031 void KCTimeDict::addCTime(const QString &path, const QByteArray& resource, quint32 ctime) 00032 { 00033 assert(!path.isEmpty()); 00034 m_hash.insert(key(path, resource), ctime ); 00035 } 00036 00037 quint32 KCTimeDict::ctime(const QString &path, const QByteArray& resource) const 00038 { 00039 return m_hash.value(key(path, resource), 0); 00040 } 00041 00042 void KCTimeDict::remove(const QString &path, const QByteArray &resource) 00043 { 00044 m_hash.remove(key(path, resource)); 00045 } 00046 00047 void KCTimeDict::dump() const 00048 { 00049 kDebug() << m_hash.keys(); 00050 } 00051 00052 QStringList KCTimeDict::resourceList() const 00053 { 00054 QSet<QString> resources; 00055 Hash::const_iterator it = m_hash.constBegin(); 00056 const Hash::const_iterator end = m_hash.constEnd(); 00057 for ( ; it != end; ++it ) { 00058 const QString key = it.key(); 00059 const QString res = key.left(key.indexOf('|')); 00060 resources.insert(res); 00061 } 00062 return resources.toList(); 00063 } 00064 00065 void KCTimeDict::load(QDataStream &str) 00066 { 00067 QString key; 00068 quint32 ctime; 00069 while(true) 00070 { 00071 KSycocaEntry::read(str, key); 00072 str >> ctime; 00073 if (key.isEmpty()) break; 00074 m_hash.insert(key, ctime); 00075 } 00076 } 00077 00078 void KCTimeDict::save(QDataStream &str) const 00079 { 00080 Hash::const_iterator it = m_hash.constBegin(); 00081 const Hash::const_iterator end = m_hash.constEnd(); 00082 for ( ; it != end; ++it ) { 00083 str << it.key() << it.value(); 00084 } 00085 str << QString() << (quint32) 0; 00086 } 00087 00089 00090 KCTimeInfo::KCTimeInfo() 00091 : KSycocaFactory( KST_CTimeInfo ), m_ctimeDict() 00092 { 00093 if (!KSycoca::self()->isBuilding()) { 00094 QDataStream* str = stream(); 00095 (*str) >> m_dictOffset; 00096 } else { 00097 m_dictOffset = 0; 00098 } 00099 } 00100 00101 KCTimeInfo::~KCTimeInfo() 00102 { 00103 } 00104 00105 void 00106 KCTimeInfo::saveHeader(QDataStream &str) 00107 { 00108 KSycocaFactory::saveHeader(str); 00109 00110 str << m_dictOffset; 00111 } 00112 00113 void KCTimeInfo::save(QDataStream &str) 00114 { 00115 KSycocaFactory::save(str); 00116 00117 m_dictOffset = str.device()->pos(); 00118 m_ctimeDict.save(str); 00119 const int endOfFactoryData = str.device()->pos(); 00120 saveHeader(str); 00121 str.device()->seek(endOfFactoryData); 00122 } 00123 00124 KCTimeDict KCTimeInfo::loadDict() const 00125 { 00126 KCTimeDict dict; 00127 QDataStream* str = stream(); 00128 assert(str); 00129 str->device()->seek(m_dictOffset); 00130 dict.load(*str); 00131 return dict; 00132 }
KDE 4.6 API Reference