kdecore Library API Documentation

ksimpleconfig.cpp

00001 /* This file is part of the KDE libraries
00002    Copyright (c) 1999 Preston Brown <pbrown@kde.org>
00003    Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@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 as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 // $Id: ksimpleconfig.cpp,v 1.47 2002/03/03 21:20:26 lunakl Exp $
00021 
00022 #include <config.h>
00023 
00024 #ifdef HAVE_SYS_STAT_H
00025 #include <sys/stat.h>
00026 #endif
00027 
00028 #include <stdlib.h>
00029 #include <unistd.h>
00030 
00031 #include <qfileinfo.h>
00032 
00033 #include "kglobal.h"
00034 #include "kstandarddirs.h"
00035 #include "kconfigbackend.h"
00036 
00037 #include "ksimpleconfig.h"
00038 
00039 KSimpleConfig::KSimpleConfig(const QString &fileName, bool bReadOnly)
00040   : KConfig(QString::fromLatin1(""), bReadOnly, false)
00041 {
00042   // the difference between KConfig and KSimpleConfig is just that
00043   // for KSimpleConfig an absolute filename is guaranteed
00044   if (!fileName.isNull() && fileName[0] != '/') {
00045      backEnd->changeFileName( KGlobal::dirs()->
00046     saveLocation("config", QString::null, !bReadOnly)+fileName, "config", false);
00047   } else {
00048      backEnd->changeFileName(fileName, "config", false);
00049   }
00050   setReadOnly( bReadOnly );
00051   reparseConfiguration();
00052 }
00053 
00054 KSimpleConfig::~KSimpleConfig()
00055 {
00056   // we need to call the KSimpleConfig version of sync.  Relying on the
00057   // regular KConfig sync is bad, because the KSimpleConfig sync has
00058   // different behaviour.  Syncing here will insure that the sync() call
00059   // in the KConfig destructor doesn't actually do anything.
00060   sync();
00061 }
00062 
00063 void KSimpleConfig::sync()
00064 {
00065    if (isReadOnly())
00066        return;
00067    backEnd->sync(false);
00068 
00069    if (isDirty())
00070      rollback();
00071 }
00072 
00073 void KSimpleConfig::virtual_hook( int id, void* data )
00074 { KConfig::virtual_hook( id, data ); }
00075 
00076 #include "ksimpleconfig.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 27 22:14:47 2005 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001