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