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 00023 #include <assert.h> 00024 00025 KCTimeInfo::KCTimeInfo() 00026 : KSycocaFactory( KST_CTimeInfo ), ctimeDict() 00027 { 00028 if (!KSycoca::self()->isBuilding()) { 00029 QDataStream* str = stream(); 00030 (*str) >> m_dictOffset; 00031 } else { 00032 m_dictOffset = 0; 00033 } 00034 } 00035 00036 KCTimeInfo::~KCTimeInfo() 00037 { 00038 } 00039 00040 void 00041 KCTimeInfo::saveHeader(QDataStream &str) 00042 { 00043 KSycocaFactory::saveHeader(str); 00044 00045 str << m_dictOffset; 00046 } 00047 00048 void 00049 KCTimeInfo::save(QDataStream &str) 00050 { 00051 KSycocaFactory::save(str); 00052 00053 m_dictOffset = str.device()->pos(); 00054 Dict::const_iterator it = ctimeDict.constBegin(); 00055 const Dict::const_iterator end = ctimeDict.constEnd(); 00056 for ( ; it != end; ++it ) 00057 { 00058 str << it.key() << it.value(); 00059 } 00060 str << QString() << (quint32) 0; 00061 00062 int endOfFactoryData = str.device()->pos(); 00063 00064 saveHeader(str); 00065 str.device()->seek(endOfFactoryData); 00066 } 00067 00068 void 00069 KCTimeInfo::addCTime(const QString &path, quint32 ctime) 00070 { 00071 assert(!path.isEmpty()); 00072 ctimeDict.insert(path, ctime); 00073 } 00074 00075 quint32 00076 KCTimeInfo::ctime(const QString &path) 00077 { 00078 return ctimeDict.value( path, 0 ); 00079 } 00080 00081 void 00082 KCTimeInfo::fillCTimeDict(Dict &dict) 00083 { 00084 QDataStream* str = stream(); 00085 assert(str); 00086 str->device()->seek(m_dictOffset); 00087 QString path; 00088 quint32 ctime; 00089 while(true) 00090 { 00091 KSycocaEntry::read(*str, path); 00092 (*str) >> ctime; 00093 if (path.isEmpty()) break; 00094 dict.insert(path, ctime); 00095 } 00096 }