libkdegames Library API Documentation

kconfigrawbackend.cpp

00001 /*
00002    This file is part of the KDE games library
00003    Copyright (C) 2003 Nicolas Hadacek <hadacek@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #include <config.h>
00021 
00022 #include "kconfigrawbackend.h"
00023 #include "kconfigrawbackend.moc"
00024 
00025 #include <unistd.h>
00026 #include <qfile.h>
00027 
00028 
00029 KConfigRawBackEnd::KConfigRawBackEnd(KConfigBase *_config, int fd)
00030     : KConfigINIBackEnd(_config, QString::null, "config", false),
00031       _fd(fd), _stream(0)
00032 {
00033     _file.open(IO_ReadOnly, _fd);
00034 }
00035 
00036 KConfigRawBackEnd::~KConfigRawBackEnd()
00037 {
00038     if (_stream) fclose(_stream);
00039 }
00040 
00041 bool KConfigRawBackEnd::parseConfigFiles()
00042 {
00043     _file.reset();
00044     parseSingleConfigFile(_file);
00045     return true;
00046 }
00047 
00048 void KConfigRawBackEnd::sync(bool bMerge)
00049 {
00050   // write-sync is only necessary if there are dirty entries
00051   if ( !pConfig->isDirty() || pConfig->isReadOnly() ) return;
00052 
00053   _file.reset();
00054   KEntryMap aTempMap;
00055   getEntryMap(aTempMap, false, bMerge ? &_file : 0);
00056 
00057   if ( _stream==0 ) {
00058       _stream = fdopen(_fd, "w");
00059       if ( _stream==0 ) return;
00060   }
00061   ftruncate(_fd, 0);
00062   writeEntries(_stream, aTempMap);
00063   fflush(_stream);
00064 }
KDE Logo
This file is part of the documentation for libkdegames Library Version 3.4.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Oct 9 09:38:12 2005 by doxygen 1.4.4 written by Dimitri van Heesch, © 1997-2003