From 5159cd2beb2e87806a5b54e9991b7895285c9d3e Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 27 Jan 2013 01:04:16 -0600 Subject: Rename a number of libraries and executables to avoid conflicts with KDE4 --- tdecore/tdeconfig.cpp | 367 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 367 insertions(+) create mode 100644 tdecore/tdeconfig.cpp (limited to 'tdecore/tdeconfig.cpp') diff --git a/tdecore/tdeconfig.cpp b/tdecore/tdeconfig.cpp new file mode 100644 index 000000000..62464b81f --- /dev/null +++ b/tdecore/tdeconfig.cpp @@ -0,0 +1,367 @@ +/* + This file is part of the KDE libraries + Copyright (c) 1999 Preston Brown + Copyright (C) 1997-1999 Matthias Kalle Dalheimer (kalle@kde.org) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +// $Id$ + +#include + +#ifdef HAVE_SYS_STAT_H +#include +#endif + +#include +#include + +#include + +#include +#include "tdeconfigbackend.h" + +#include "tdeconfig.h" +#include "kglobal.h" +#include "kstandarddirs.h" +#include "kstaticdeleter.h" +#include + +TDEConfig::TDEConfig( const TQString& fileName, + bool bReadOnly, bool bUseKderc, const char *resType ) + : TDEConfigBase(), bGroupImmutable(false), bFileImmutable(false), + bForceGlobal(false) +{ + // set the object's read-only status. + setReadOnly(bReadOnly); + + // for right now we will hardcode that we are using the INI + // back end driver. In the future this should be converted over to + // a object factory of some sorts. + TDEConfigINIBackEnd *aBackEnd = new TDEConfigINIBackEnd(this, + fileName, + resType, + bUseKderc); + + // set the object's back end pointer to this new backend + backEnd = aBackEnd; + + // read initial information off disk + reparseConfiguration(); + + // we let KStandardDirs add custom user config files. It will do + // this only once. So only the first call ever to this constructor + // will anything else than return here We have to reparse here as + // configuration files may appear after customized directories have + // been added. and the info they contain needs to be inserted into the + // config object. + // Since this makes only sense for config directories, addCustomized + // returns true only if new config directories appeared. + if (TDEGlobal::dirs()->addCustomized(this)) + reparseConfiguration(); +} + +TDEConfig::TDEConfig(TDEConfigBackEnd *aBackEnd, bool bReadOnly) + : bGroupImmutable(false), bFileImmutable(false), + bForceGlobal(false) +{ + setReadOnly(bReadOnly); + backEnd = aBackEnd; + reparseConfiguration(); +} + +TDEConfig::~TDEConfig() +{ + sync(); + + delete backEnd; +} + +void TDEConfig::rollback(bool bDeep) +{ + TDEConfigBase::rollback(bDeep); + + if (!bDeep) + return; // object's bDeep flag is set in TDEConfigBase method + + // clear any dirty flags that entries might have set + for (KEntryMapIterator aIt = aEntryMap.begin(); + aIt != aEntryMap.end(); ++aIt) + (*aIt).bDirty = false; +} + +TQStringList TDEConfig::groupList() const +{ + TQStringList retList; + + KEntryMapConstIterator aIt = aEntryMap.begin(); + KEntryMapConstIterator aEnd = aEntryMap.end(); + for (; aIt != aEnd; ++aIt) + { + while(aIt.key().mKey.isEmpty()) + { + TQCString group = aIt.key().mGroup; + ++aIt; + while (true) + { + if (aIt == aEnd) + return retList; // done + + if (aIt.key().mKey.isEmpty()) + break; // Group is empty, next group + + if (!aIt.key().bDefault && !(*aIt).bDeleted) + { + if (group != "$Version") // Special case! + retList.append(TQString::fromUtf8(group)); + break; // Group is non-empty, added, next group + } + ++aIt; + } + } + } + + return retList; +} + +TQMap TDEConfig::entryMap(const TQString &pGroup) const +{ + TQCString pGroup_utf = pGroup.utf8(); + KEntryKey groupKey( pGroup_utf, 0 ); + TQMap tmpMap; + + KEntryMapConstIterator aIt = aEntryMap.find(groupKey); + if (aIt == aEntryMap.end()) + return tmpMap; + ++aIt; // advance past special group entry marker + for (; aIt.key().mGroup == pGroup_utf && aIt != aEntryMap.end(); ++aIt) + { + // Leave the default values out && leave deleted entries out + if (!aIt.key().bDefault && !(*aIt).bDeleted) + tmpMap.insert(TQString::fromUtf8(aIt.key().mKey), TQString::fromUtf8((*aIt).mValue.data(), (*aIt).mValue.length())); + } + + return tmpMap; +} + +void TDEConfig::reparseConfiguration() +{ + // Don't lose pending changes + if (!isReadOnly() && backEnd && bDirty) + backEnd->sync(); + + aEntryMap.clear(); + + // add the "default group" marker to the map + KEntryKey groupKey("", 0); + aEntryMap.insert(groupKey, KEntry()); + + bFileImmutable = false; + parseConfigFiles(); + bFileImmutable = bReadOnly; +} + +KEntryMap TDEConfig::internalEntryMap(const TQString &pGroup) const +{ + TQCString pGroup_utf = pGroup.utf8(); + KEntry aEntry; + KEntryMapConstIterator aIt; + KEntryKey aKey(pGroup_utf, 0); + KEntryMap tmpEntryMap; + + aIt = aEntryMap.find(aKey); + if (aIt == aEntryMap.end()) { + // the special group key is not in the map, + // so it must be an invalid group. Return + // an empty map. + return tmpEntryMap; + } + // we now have a pointer to the nodes we want to copy. + for (; aIt.key().mGroup == pGroup_utf && aIt != aEntryMap.end(); ++aIt) + { + tmpEntryMap.insert(aIt.key(), *aIt); + } + + return tmpEntryMap; +} + +void TDEConfig::putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup) +{ + if (bFileImmutable && !_key.bDefault) + return; + + // check to see if the special group key is present, + // and if not, put it in. + if (_checkGroup) + { + KEntryKey groupKey( _key.mGroup, 0); + KEntry &entry = aEntryMap[groupKey]; + bGroupImmutable = entry.bImmutable; + } + if (bGroupImmutable && !_key.bDefault) + return; + + // now either add or replace the data + KEntry &entry = aEntryMap[_key]; + bool immutable = entry.bImmutable; + if (immutable && !_key.bDefault) + return; + + entry = _data; + entry.bImmutable |= immutable; + entry.bGlobal |= bForceGlobal; // force to kdeglobals + + if (_key.bDefault) + { + // We have added the data as default value, + // add it as normal value as well. + KEntryKey key(_key); + key.bDefault = false; + aEntryMap[key] = _data; + } +} + +KEntry TDEConfig::lookupData(const KEntryKey &_key) const +{ + KEntryMapConstIterator aIt = aEntryMap.find(_key); + if (aIt != aEntryMap.end()) + { + const KEntry &entry = *aIt; + if (entry.bDeleted) + return KEntry(); + else + return entry; + } + else { + return KEntry(); + } +} + +bool TDEConfig::internalHasGroup(const TQCString &group) const +{ + KEntryKey groupKey( group, 0); + + KEntryMapConstIterator aIt = aEntryMap.find(groupKey); + KEntryMapConstIterator aEnd = aEntryMap.end(); + + if (aIt == aEnd) + return false; + ++aIt; + for(; (aIt != aEnd); ++aIt) + { + if (aIt.key().mKey.isEmpty()) + break; + + if (!aIt.key().bDefault && !(*aIt).bDeleted) + return true; + } + return false; +} + +void TDEConfig::setFileWriteMode(int mode) +{ + backEnd->setFileWriteMode(mode); +} + +KLockFile::Ptr TDEConfig::lockFile(bool bGlobal) +{ + TDEConfigINIBackEnd *aBackEnd = dynamic_cast(backEnd); + if (!aBackEnd) return 0; + return aBackEnd->lockFile(bGlobal); +} + +void TDEConfig::checkUpdate(const TQString &id, const TQString &updateFile) +{ + TQString oldGroup = group(); + setGroup("$Version"); + TQString cfg_id = updateFile+":"+id; + TQStringList ids = readListEntry("update_info"); + if (!ids.contains(cfg_id)) + { + TQStringList args; + args << "--check" << updateFile; + TDEApplication::tdeinitExecWait("tdeconf_update", args); + reparseConfiguration(); + } + setGroup(oldGroup); +} + +TDEConfig* TDEConfig::copyTo(const TQString &file, TDEConfig *config) const +{ + if (!config) + config = new TDEConfig(TQString::null, false, false); + config->backEnd->changeFileName(file, "config", false); + config->setReadOnly(false); + config->bFileImmutable = false; + config->backEnd->mConfigState = ReadWrite; + + TQStringList groups = groupList(); + for(TQStringList::ConstIterator it = groups.begin(); + it != groups.end(); ++it) + { + TQMap map = entryMap(*it); + config->setGroup(*it); + for (TQMap::Iterator it2 = map.begin(); + it2 != map.end(); ++it2) + { + config->writeEntry(it2.key(), it2.data()); + } + + } + return config; +} + +void TDEConfig::virtual_hook( int id, void* data ) +{ TDEConfigBase::virtual_hook( id, data ); } + +static KStaticDeleter< TQValueList > sd; +TQValueList *KSharedConfig::s_list = 0; + +KSharedConfig::Ptr KSharedConfig::openConfig(const TQString& fileName, bool readOnly, bool useKDEGlobals ) +{ + if (s_list) + { + for(TQValueList::ConstIterator it = s_list->begin(); + it != s_list->end(); ++it) + { + if ((*it)->backEnd->fileName() == fileName && + (*it)->bReadOnly == readOnly && + (*it)->backEnd->useKDEGlobals == useKDEGlobals ) + return (*it); + } + } + return new KSharedConfig(fileName, readOnly, useKDEGlobals); +} + +KSharedConfig::KSharedConfig( const TQString& fileName, bool readonly, bool usekdeglobals) + : TDEConfig(fileName, readonly, usekdeglobals) +{ + if (!s_list) + { + sd.setObject(s_list, new TQValueList); + } + + s_list->append(this); +} + +KSharedConfig::~KSharedConfig() +{ + if ( s_list ) + s_list->remove(this); +} + +#include "tdeconfig.moc" -- cgit v1.2.1 From 12f3d421cd2991c0e3f96994efb836ce244172ff Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 31 Jan 2013 00:36:34 -0600 Subject: Rename KShared --- tdecore/tdeconfig.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tdecore/tdeconfig.cpp') diff --git a/tdecore/tdeconfig.cpp b/tdecore/tdeconfig.cpp index 62464b81f..bef3d7944 100644 --- a/tdecore/tdeconfig.cpp +++ b/tdecore/tdeconfig.cpp @@ -328,14 +328,14 @@ TDEConfig* TDEConfig::copyTo(const TQString &file, TDEConfig *config) const void TDEConfig::virtual_hook( int id, void* data ) { TDEConfigBase::virtual_hook( id, data ); } -static KStaticDeleter< TQValueList > sd; -TQValueList *KSharedConfig::s_list = 0; +static KStaticDeleter< TQValueList > sd; +TQValueList *TDESharedConfig::s_list = 0; -KSharedConfig::Ptr KSharedConfig::openConfig(const TQString& fileName, bool readOnly, bool useKDEGlobals ) +TDESharedConfig::Ptr TDESharedConfig::openConfig(const TQString& fileName, bool readOnly, bool useKDEGlobals ) { if (s_list) { - for(TQValueList::ConstIterator it = s_list->begin(); + for(TQValueList::ConstIterator it = s_list->begin(); it != s_list->end(); ++it) { if ((*it)->backEnd->fileName() == fileName && @@ -344,21 +344,21 @@ KSharedConfig::Ptr KSharedConfig::openConfig(const TQString& fileName, bool read return (*it); } } - return new KSharedConfig(fileName, readOnly, useKDEGlobals); + return new TDESharedConfig(fileName, readOnly, useKDEGlobals); } -KSharedConfig::KSharedConfig( const TQString& fileName, bool readonly, bool usekdeglobals) +TDESharedConfig::TDESharedConfig( const TQString& fileName, bool readonly, bool usekdeglobals) : TDEConfig(fileName, readonly, usekdeglobals) { if (!s_list) { - sd.setObject(s_list, new TQValueList); + sd.setObject(s_list, new TQValueList); } s_list->append(this); } -KSharedConfig::~KSharedConfig() +TDESharedConfig::~TDESharedConfig() { if ( s_list ) s_list->remove(this); -- cgit v1.2.1 From d3afa6baf98ef5ac191996cc9b909ff9074c168c Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 31 Jan 2013 13:28:26 -0600 Subject: Rename KStandard for enhanced compatibility with KDE4 --- tdecore/tdeconfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tdecore/tdeconfig.cpp') diff --git a/tdecore/tdeconfig.cpp b/tdecore/tdeconfig.cpp index bef3d7944..28f25e61a 100644 --- a/tdecore/tdeconfig.cpp +++ b/tdecore/tdeconfig.cpp @@ -63,7 +63,7 @@ TDEConfig::TDEConfig( const TQString& fileName, // read initial information off disk reparseConfiguration(); - // we let KStandardDirs add custom user config files. It will do + // we let TDEStandardDirs add custom user config files. It will do // this only once. So only the first call ever to this constructor // will anything else than return here We have to reparse here as // configuration files may appear after customized directories have -- cgit v1.2.1 From 0c9d97065a3d6ceb12d687555a1a33d90db96238 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 1 Feb 2013 10:51:32 -0600 Subject: Rename KLock and KTrader to avoid conflicts with KDE4 --- tdecore/tdeconfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tdecore/tdeconfig.cpp') diff --git a/tdecore/tdeconfig.cpp b/tdecore/tdeconfig.cpp index 28f25e61a..1e75be6f1 100644 --- a/tdecore/tdeconfig.cpp +++ b/tdecore/tdeconfig.cpp @@ -277,7 +277,7 @@ void TDEConfig::setFileWriteMode(int mode) backEnd->setFileWriteMode(mode); } -KLockFile::Ptr TDEConfig::lockFile(bool bGlobal) +TDELockFile::Ptr TDEConfig::lockFile(bool bGlobal) { TDEConfigINIBackEnd *aBackEnd = dynamic_cast(backEnd); if (!aBackEnd) return 0; -- cgit v1.2.1 From 8bd62a3b0d3b362b783a273e2460811392485bbd Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 14 Feb 2013 17:17:18 -0600 Subject: Rename common header files for consistency with class renaming --- tdecore/tdeconfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tdecore/tdeconfig.cpp') diff --git a/tdecore/tdeconfig.cpp b/tdecore/tdeconfig.cpp index 1e75be6f1..35c5b73bc 100644 --- a/tdecore/tdeconfig.cpp +++ b/tdecore/tdeconfig.cpp @@ -32,7 +32,7 @@ #include -#include +#include #include "tdeconfigbackend.h" #include "tdeconfig.h" -- cgit v1.2.1 From ed99a30644c19b0a3cf0d2147243532df4daa16b Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 15 Feb 2013 21:57:54 -0600 Subject: Rename additional header files to avoid conflicts with KDE4 --- tdecore/tdeconfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tdecore/tdeconfig.cpp') diff --git a/tdecore/tdeconfig.cpp b/tdecore/tdeconfig.cpp index 35c5b73bc..68307dc85 100644 --- a/tdecore/tdeconfig.cpp +++ b/tdecore/tdeconfig.cpp @@ -36,7 +36,7 @@ #include "tdeconfigbackend.h" #include "tdeconfig.h" -#include "kglobal.h" +#include "tdeglobal.h" #include "kstandarddirs.h" #include "kstaticdeleter.h" #include -- cgit v1.2.1