bool KConfigINIBackEnd::getEntryMap(KEntryMap &aTempMap, bool bGlobal, QFile *mergeFile) { bool bEntriesLeft = false; bFileImmutable = false; // Read entries from disk if(mergeFile && mergeFile->open(IO_ReadOnly)) { // fill the temporary structure with entries from the file parseSingleConfigFile(*mergeFile, &aTempMap, bGlobal, false); if(bFileImmutable) // File has become immutable on disk return bEntriesLeft; } KEntryMap aMap = pConfig->internalEntryMap(); // augment this structure with the dirty entries from the config object for(KEntryMapIterator aIt = aMap.begin(); aIt != aMap.end(); ++aIt) { const KEntry ¤tEntry = *aIt; if(aIt.key().bDefault) { aTempMap.replace(aIt.key(), currentEntry); continue; } if(mergeFile && !currentEntry.bDirty) continue; // only write back entries that have the same // "globality" as the file if(currentEntry.bGlobal != bGlobal) { // wrong "globality" - might have to be saved later bEntriesLeft = true; continue; } // put this entry from the config object into the // temporary map, possibly replacing an existing entry KEntryMapIterator aIt2 = aTempMap.find(aIt.key()); if(aIt2 != aTempMap.end() && (*aIt2).bImmutable) continue; // Bail out if the on-disk entry is immutable aTempMap.insert(aIt.key(), currentEntry, true); } // loop return bEntriesLeft; }
bool KConfigINIBackEnd::parseConfigFiles() { // Check if we can write to the local file. mConfigState = KConfigBase::ReadOnly; if(!mLocalFileName.isEmpty() && !pConfig->isReadOnly()) { if(checkAccess(mLocalFileName, W_OK)) { mConfigState = KConfigBase::ReadWrite; } else { // Create the containing dir, maybe it wasn't there KURL path; path.setPath(mLocalFileName); QString dir = path.directory(); KStandardDirs::makeDir(dir); if(checkAccess(mLocalFileName, W_OK)) { mConfigState = KConfigBase::ReadWrite; } } QFileInfo info(mLocalFileName); d->localLastModified = info.lastModified(); d->localLastSize = info.size(); } // Parse all desired files from the least to the most specific. bFileImmutable = false; // Parse the general config files if(useKDEGlobals) { QStringList kdercs = KGlobal::dirs()->findAllResources("config", QString::fromLatin1("kdeglobals")); QString etc_kderc = QString::fromLatin1("/etc/kderc"); if(checkAccess(etc_kderc, R_OK)) kdercs += etc_kderc; kdercs += KGlobal::dirs()->findAllResources("config", QString::fromLatin1("system.kdeglobals")); QStringList::ConstIterator it; for(it = kdercs.fromLast(); it != kdercs.end(); --it) { QFile aConfigFile(*it); if(!aConfigFile.open(IO_ReadOnly)) continue; parseSingleConfigFile(aConfigFile, 0L, true, (*it != mGlobalFileName)); aConfigFile.close(); if(bFileImmutable) break; } } bool bReadFile = !mfileName.isEmpty(); while(bReadFile) { bReadFile = false; QString bootLanguage; if(useKDEGlobals && localeString.isEmpty() && !KGlobal::_locale) { // Boot strap language bootLanguage = KLocale::_initLanguage(pConfig); setLocaleString(bootLanguage.utf8()); } bFileImmutable = false; QStringList list; if(!QDir::isRelativePath(mfileName)) list << mfileName; else list = KGlobal::dirs()->findAllResources(resType, mfileName); QStringList::ConstIterator it; for(it = list.fromLast(); it != list.end(); --it) { QFile aConfigFile(*it); // we can already be sure that this file exists bool bIsLocal = (*it == mLocalFileName); if(aConfigFile.open(IO_ReadOnly)) { parseSingleConfigFile(aConfigFile, 0L, false, !bIsLocal); aConfigFile.close(); if(bFileImmutable) break; } } if(KGlobal::dirs()->isRestrictedResource(resType, mfileName)) bFileImmutable = true; QString currentLanguage; if(!bootLanguage.isEmpty()) { currentLanguage = KLocale::_initLanguage(pConfig); // If the file changed the language, we need to read the file again // with the new language setting. if(bootLanguage != currentLanguage) { bReadFile = true; setLocaleString(currentLanguage.utf8()); } } } if(bFileImmutable) mConfigState = KConfigBase::ReadOnly; return true; }
bool KConfigRawBackEnd::parseConfigFiles() { _file.reset(); parseSingleConfigFile(_file); return true; }