Git commit 514d50fc7ca363539f2009f40b9cf43dc5e0733e by Albert Astals Cid. Committed on 26/03/2013 at 23:40. Pushed by aacid into branch 'frameworks'. Merge remote-tracking branch 'origin/master' into frameworks Conflicts: knewstuff/knewstuff3/uploaddialog.cpp plasma/data/servicetypes/plasma-wallpaper.desktop M +1 -1 CMakeLists.txt M +1 -3 khtml/rendering/render_form.h M +2 -2 khtml/rendering/render_replaced.cpp M +8 -33 kio/kio/tcpslavebase.cpp M +14 -0 knewstuff/knewstuff3/uploaddialog.cpp M +2 -0 knewstuff/knewstuff3/uploaddialog.h M +2 -0 knewstuff/knewstuff3/uploaddialog_p.h A +1 -1 tier1/solid/src/solid/backends/upower/upowerdevice.cpp [= License: LGPL] A +1 -0 tier2/kconfig/src/core/kconfig.cpp [License: LGPL (v2+)] http://commits.kde.org/kdelibs/514d50fc7ca363539f2009f40b9cf43dc5e0733e diff --cc knewstuff/knewstuff3/uploaddialog.cpp index 2e0989a,7f2cbe9..db7f775 --- a/knewstuff/knewstuff3/uploaddialog.cpp +++ b/knewstuff/knewstuff3/uploaddialog.cpp @@@ -21,19 -21,20 +21,20 @@@ #include "uploaddialog.h" #include "uploaddialog_p.h" = -#include -#include -#include +#include +#include +#include +#include #include #include +#include = -#include -#include #include #include -#include + #include #include + #include = #include #include @@@ -717,7 -707,11 +727,11 @@@ void UploadDialog::Private::_k_contentA } } = + void UploadDialog::Private::_k_openRegisterAccountWebpage(QString) { + KRun::runUrl(atticaHelper->provider().getRegisterAccountUrl(), "text/= html", q); + } + = -void UploadDialog::Private::doUpload(const QString& index, const KUrl& pa= th) +void UploadDialog::Private::doUpload(const QString& index, const QUrl & p= ath) { QFile file(path.toLocalFile()); if (!file.open(QIODevice::ReadOnly)) { diff --cc tier1/solid/src/solid/backends/upower/upowerdevice.cpp index 498f68f,0000000..c61bee9 mode 100644,000000..100644 --- a/tier1/solid/src/solid/backends/upower/upowerdevice.cpp +++ b/tier1/solid/src/solid/backends/upower/upowerdevice.cpp @@@ -1,221 -1,0 +1,221 @@@ +/* + Copyright 2010 Michael Zanetti + Copyright 2010 Lukas Tinkl + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "upower.h" +#include "upowerdevice.h" +#include "upowerdeviceinterface.h" +#include "upowergenericinterface.h" +#include "upoweracadapter.h" +#include "upowerbattery.h" + +#include +#include + +#include +#include +#include +#include + +using namespace Solid::Backends::UPower; + +UPowerDevice::UPowerDevice(const QString &udi) + : Solid::Ifaces::Device() + , m_device(UP_DBUS_SERVICE, + udi, + UP_DBUS_INTERFACE_DEVICE, + QDBusConnection::systemBus()) + , m_udi(udi) +{ + if (m_device.isValid()) + connect(&m_device, SIGNAL(Changed()), this, SLOT(slotChanged())); +} + +UPowerDevice::~UPowerDevice() +{ +} + +QObject* UPowerDevice::createDeviceInterface(const Solid::DeviceInterface= ::Type& type) +{ + if (!queryDeviceInterface(type)) { + return 0; + } + + DeviceInterface *iface =3D 0; + switch (type) + { + case Solid::DeviceInterface::GenericInterface: + iface =3D new GenericInterface(this); + break; + case Solid::DeviceInterface::AcAdapter: + iface =3D new AcAdapter(this); + break; + case Solid::DeviceInterface::Battery: + iface =3D new Battery(this); + break; + default: + break; + } + return iface; +} + +bool UPowerDevice::queryDeviceInterface(const Solid::DeviceInterface::Typ= e& type) const +{ + const uint uptype =3D prop("Type").toUInt(); + switch (type) + { + case Solid::DeviceInterface::GenericInterface: + return true; + case Solid::DeviceInterface::Battery: - return (uptype =3D=3D 2 || uptype =3D=3D 3); ++ return (uptype =3D=3D 2 || uptype =3D=3D 3 || uptype =3D=3D 5= || uptype =3D=3D 6); + case Solid::DeviceInterface::AcAdapter: + return (uptype =3D=3D 1); + default: + return false; + } +} + +QStringList UPowerDevice::emblems() const +{ + return QStringList(); +} + +QString UPowerDevice::description() const +{ + if (queryDeviceInterface(Solid::DeviceInterface::AcAdapter)) + return QCoreApplication::translate("", "A/C Adapter"); + else if (queryDeviceInterface(Solid::DeviceInterface::Battery)) + return QCoreApplication::translate("", "%1 Battery", "%1 is batte= ry technology").arg(batteryTechnology()); + else + return product(); +} + +QString UPowerDevice::batteryTechnology() const +{ + const uint tech =3D prop("Technology").toUInt(); + switch (tech) + { + case 1: + return QCoreApplication::translate("", "Lithium Ion", "battery te= chnology"); + case 2: + return QCoreApplication::translate("", "Lithium Polymer", "batter= y technology"); + case 3: + return QCoreApplication::translate("", "Lithium Iron Phosphate", = "battery technology"); + case 4: + return QCoreApplication::translate("", "Lead Acid", "battery tech= nology"); + case 5: + return QCoreApplication::translate("", "Nickel Cadmium", "battery= technology"); + case 6: + return QCoreApplication::translate("", "Nickel Metal Hydride", "b= attery technology"); + default: + return QCoreApplication::translate("", "Unknown", "battery techno= logy"); + } +} + +QString UPowerDevice::icon() const +{ + if (queryDeviceInterface(Solid::DeviceInterface::AcAdapter)) { + return "preferences-system-power-management"; + + } else if (queryDeviceInterface(Solid::DeviceInterface::Battery)) { + return "battery"; + + } else { + return QString(); + } +} + +QString UPowerDevice::product() const +{ + QString result =3D prop("Model").toString(); + + if (result.isEmpty()) { + result =3D description(); + } + + return result; +} + +QString UPowerDevice::vendor() const +{ + return prop("Vendor").toString(); +} + +QString UPowerDevice::udi() const +{ + return m_udi; +} + +QString UPowerDevice::parentUdi() const +{ + return UP_UDI_PREFIX; +} + +void UPowerDevice::checkCache(const QString &key) const +{ + if (m_cache.isEmpty()) // recreate the cache + allProperties(); + + if (m_cache.contains(key)) + return; + + QVariant reply =3D m_device.property(key.toUtf8()); + + if (reply.isValid()) { + m_cache[key] =3D reply; + } else { + m_cache[key] =3D QVariant(); + } +} + +QVariant UPowerDevice::prop(const QString &key) const +{ + checkCache(key); + return m_cache.value(key); +} + +bool UPowerDevice::propertyExists(const QString &key) const +{ + checkCache(key); + return m_cache.contains(key); +} + +QMap UPowerDevice::allProperties() const +{ + QDBusMessage call =3D QDBusMessage::createMethodCall(m_device.service= (), m_device.path(), + "org.freedesktop.D= Bus.Properties", "GetAll"); + call << m_device.interface(); + QDBusPendingReply< QVariantMap > reply =3D QDBusConnection::systemBus= ().asyncCall(call); + reply.waitForFinished(); + + if (reply.isValid()) + m_cache =3D reply.value(); + else + m_cache.clear(); + + return m_cache; +} + +void UPowerDevice::slotChanged() +{ + // given we cannot know which property/ies changed, clear the cache + m_cache.clear(); + Q_EMIT changed(); +} diff --cc tier2/kconfig/src/core/kconfig.cpp index 5809275,0000000..d26f941 mode 100644,000000..100644 --- a/tier2/kconfig/src/core/kconfig.cpp +++ b/tier2/kconfig/src/core/kconfig.cpp @@@ -1,903 -1,0 +1,904 @@@ +/* + This file is part of the KDE libraries + Copyright (c) 2006, 2007 Thomas Braxton + Copyright (c) 1999 Preston Brown + Copyright (c) 1997-1999 Matthias Kalle Dalheimer + + 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 Lice= nse + 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. +*/ + +// Qt5 TODO: re-enable. No point in doing it before, it breaks on QString= ::fromUtf8(QByteArray), which exists in qt5. +#undef QT_NO_CAST_FROM_BYTEARRAY + +#include "kconfig.h" +#include "kconfig_p.h" + +#include +#include +#include + +#include "kconfigbackend.h" +#include "kconfiggroup.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool KConfigPrivate::mappingsRegistered=3Dfalse; + +KConfigPrivate::KConfigPrivate(KConfig::OpenFlags flags, + QStandardPaths::StandardLocation resourceT= ype) + : openFlags(flags), resourceType(resourceType), mBackend(0), + bDynamicBackend(true), bDirty(false), bReadDefaults(false), + bFileImmutable(false), bForceGlobal(false), bSuppressGlobal(false), + configState(KConfigBase::NoAccess) +{ + sGlobalFileName =3D QStandardPaths::writableLocation(QStandardPaths::= ConfigLocation) + QLatin1String("/kdeglobals"); + + static int use_etc_kderc =3D -1; + if (use_etc_kderc < 0) + use_etc_kderc =3D getenv("KDE_SKIP_KDERC") !=3D 0 ? 0 : 1; // for= unit tests + if (use_etc_kderc) { + + etc_kderc =3D +#ifdef Q_OS_WIN + QFile::decodeName( qgetenv("WINDIR") + "/kde4rc" ); +#else + QLatin1String("/etc/kde4rc"); +#endif + if (!QFileInfo(etc_kderc).isReadable()) { + etc_kderc.clear(); + } + } + +// if (!mappingsRegistered) { +// KEntryMap tmp; +// if (!etc_kderc.isEmpty()) { +// KSharedPtr backend =3D KConfigBackend::crea= te(etc_kderc, QLatin1String("INI")); +// backend->parseConfig( "en_US", tmp, KConfigBackend::ParseDe= faults); +// } +// const QString kde4rc(QDir::home().filePath(".kde4rc")); +// if (KStandardDirs::checkAccess(kde4rc, R_OK)) { +// KSharedPtr backend =3D KConfigBackend::crea= te(kde4rc, QLatin1String("INI")); +// backend->parseConfig( "en_US", tmp, KConfigBackend::ParseOp= tions()); +// } +// KConfigBackend::registerMappings(tmp); +// mappingsRegistered =3D true; +// } + +#if 0 // KDE4 code + setLocale(KLocale::global()->language()); +#else + setLocale(QLocale::system().name()); +#endif +} + + +bool KConfigPrivate::lockLocal() +{ + if (mBackend) { + return mBackend->lock(); + } + // anonymous object - pretend we locked it + return true; +} + +void KConfigPrivate::copyGroup(const QByteArray& source, const QByteArray= & destination, + KConfigGroup *otherGroup, KConfigBase::Wr= iteConfigFlags flags) const +{ + KEntryMap& otherMap =3D otherGroup->config()->d_ptr->entryMap; + const int len =3D source.length(); + const bool sameName =3D (destination =3D=3D source); + + // we keep this bool outside the foreach loop so that if + // the group is empty, we don't end up marking the other config + // as dirty erroneously + bool dirtied =3D false; + + for (KEntryMap::ConstIterator entryMapIt( entryMap.constBegin() ); en= tryMapIt !=3D entryMap.constEnd(); ++entryMapIt) { + const QByteArray& group =3D entryMapIt.key().mGroup; + + if (!group.startsWith(source)) // nothing to do + continue; + + // don't copy groups that start with the same prefix, but are not= sub-groups + if (group.length() > len && group[len] !=3D '\x1d') + continue; + + KEntryKey newKey =3D entryMapIt.key(); + + if (flags & KConfigBase::Localized) { + newKey.bLocal =3D true; + } + + if (!sameName) + newKey.mGroup.replace(0, len, destination); + + KEntry entry =3D entryMap[ entryMapIt.key() ]; + dirtied =3D entry.bDirty =3D flags & KConfigBase::Persistent; + + if (flags & KConfigBase::Global) { + entry.bGlobal =3D true; + } + + otherMap[newKey] =3D entry; + } + + if (dirtied) { + otherGroup->config()->d_ptr->bDirty =3D true; + } +} + +QString KConfigPrivate::expandString(const QString& value) +{ + QString aValue =3D value; + + // check for environment variables and make necessary translations + int nDollarPos =3D aValue.indexOf( QLatin1Char('$') ); + while( nDollarPos !=3D -1 && nDollarPos+1 < aValue.length()) { + // there is at least one $ + if( aValue[nDollarPos+1] =3D=3D QLatin1Char('(') ) { + int nEndPos =3D nDollarPos+1; + // the next character is not $ + while ( (nEndPos <=3D aValue.length()) && (aValue[nEndPos]!= =3DQLatin1Char(')')) ) + nEndPos++; + nEndPos++; + QString cmd =3D aValue.mid( nDollarPos+2, nEndPos-nDollarPos-= 3 ); + + QString result; +#if 0 // Removed in KDE Frameworks 5. No such concept anymore. Just set y= our PATH. + QByteArray oldpath =3D qgetenv( "PATH" ); + QByteArray newpath; + if (KComponentData::hasMainComponent()) { + newpath =3D QFile::encodeName(KGlobal::dirs()->resourceDi= rs("exe").join(QChar::fromLatin1(KPATH_SEPARATOR))); + if (!newpath.isEmpty() && !oldpath.isEmpty()) + newpath +=3D KPATH_SEPARATOR; + } + newpath +=3D oldpath; + qputenv( "PATH", newpath); +#endif + +// FIXME: wince does not have pipes +#ifndef _WIN32_WCE + FILE *fs =3D popen(QFile::encodeName(cmd).data(), "r"); + if (fs) { + QTextStream ts(fs, QIODevice::ReadOnly); + result =3D ts.readAll().trimmed(); + pclose(fs); + } +#endif +#if 0 // Removed in KDE Frameworks 5, see above. + qputenv( "PATH", oldpath); +#endif + aValue.replace( nDollarPos, nEndPos-nDollarPos, result ); + nDollarPos +=3D result.length(); + } else if( aValue[nDollarPos+1] !=3D QLatin1Char('$') ) { + int nEndPos =3D nDollarPos+1; + // the next character is not $ + QString aVarName; + if ( aValue[nEndPos] =3D=3D QLatin1Char('{') ) { + while ( (nEndPos <=3D aValue.length()) && (aValue[nEndPos= ] !=3D QLatin1Char('}')) ) + nEndPos++; + nEndPos++; + aVarName =3D aValue.mid( nDollarPos+2, nEndPos-nDollarPos= -3 ); + } else { + while ( nEndPos <=3D aValue.length() && + (aValue[nEndPos].isNumber() || + aValue[nEndPos].isLetter() || + aValue[nEndPos] =3D=3D QLatin1Char('_') ) ) + nEndPos++; + aVarName =3D aValue.mid( nDollarPos+1, nEndPos-nDollarPos= -1 ); + } + QString env; + if (!aVarName.isEmpty()) { +#ifdef Q_OS_WIN + if (aVarName =3D=3D QLatin1String("HOME")) + env =3D QDir::homePath(); + else +#endif + { + QByteArray pEnv =3D qgetenv(aVarName.toLatin1().const= Data()); + if( !pEnv.isEmpty() ) + env =3D QString::fromLocal8Bit(pEnv.constData()); + } + aValue.replace(nDollarPos, nEndPos-nDollarPos, env); + nDollarPos +=3D env.length(); + } else + aValue.remove( nDollarPos, nEndPos-nDollarPos ); + } else { + // remove one of the dollar signs + aValue.remove( nDollarPos, 1 ); + nDollarPos++; + } + nDollarPos =3D aValue.indexOf( QLatin1Char('$'), nDollarPos ); + } + + return aValue; +} + + +KConfig::KConfig(const QString& file, OpenFlags mode, + QStandardPaths::StandardLocation resourceType) + : d_ptr(new KConfigPrivate(mode, resourceType)) +{ + d_ptr->changeFileName(file); // set the local file name + + // read initial information off disk + reparseConfiguration(); +} + +KConfig::KConfig(const QString& file, const QString& backend, QStandardPa= ths::StandardLocation resourceType) + : d_ptr(new KConfigPrivate(SimpleConfig, resourceType)) +{ + d_ptr->mBackend =3D KConfigBackend::create(file, backend); + d_ptr->bDynamicBackend =3D false; + d_ptr->changeFileName(file); // set the local file name + + // read initial information off disk + reparseConfiguration(); +} + +KConfig::KConfig(KConfigPrivate &d) + : d_ptr(&d) +{ +} + +KConfig::~KConfig() +{ + Q_D(KConfig); + if (d->bDirty && d->mBackend.isUnique()) + sync(); + delete d; +} + +QStringList KConfig::groupList() const +{ + Q_D(const KConfig); + QSet groups; + + for (KEntryMap::ConstIterator entryMapIt( d->entryMap.constBegin() );= entryMapIt !=3D d->entryMap.constEnd(); ++entryMapIt) { + const KEntryKey& key =3D entryMapIt.key(); + const QByteArray group =3D key.mGroup; + if (key.mKey.isNull() && !group.isEmpty() && group !=3D "" && group !=3D "$Version") { + const QString groupname =3D QString::fromUtf8(group); + groups << groupname.left(groupname.indexOf(QLatin1Char('\x1d'= ))); + } + } + + return groups.toList(); +} + +QStringList KConfigPrivate::groupList(const QByteArray& group) const +{ + QByteArray theGroup =3D group + '\x1d'; + QSet groups; + + for (KEntryMap::ConstIterator entryMapIt( entryMap.constBegin() ); en= tryMapIt !=3D entryMap.constEnd(); ++entryMapIt) { + const KEntryKey& key =3D entryMapIt.key(); + if (key.mKey.isNull() && key.mGroup.startsWith(theGroup)) { + const QString groupname =3D QString::fromUtf8(key.mGroup.mid(= theGroup.length())); + groups << groupname.left(groupname.indexOf(QLatin1Char('\x1d'= ))); + } + } + + return groups.toList(); +} + +// List all sub groups, including subsubgroups +QSet KConfigPrivate::allSubGroups(const QByteArray& parentGro= up) const +{ + QSet groups; + QByteArray theGroup =3D parentGroup + '\x1d'; + groups << parentGroup; + + for (KEntryMap::const_iterator entryMapIt =3D entryMap.begin(); entry= MapIt !=3D entryMap.end(); ++entryMapIt) { + const KEntryKey& key =3D entryMapIt.key(); + if (key.mKey.isNull() && key.mGroup.startsWith(theGroup)) { + groups << key.mGroup; + } + } + return groups; +} + +bool KConfigPrivate::hasNonDeletedEntries(const QByteArray& group) const +{ + const QSet allGroups =3D allSubGroups(group); + + Q_FOREACH(const QByteArray& aGroup, allGroups) { + // Could be optimized, let's use the slow way for now + // Check for any non-deleted entry + if (!keyListImpl(aGroup).isEmpty()) + return true; + } + return false; +} + + +QStringList KConfigPrivate::keyListImpl(const QByteArray& theGroup) const +{ + QStringList keys; + + const KEntryMapConstIterator theEnd =3D entryMap.constEnd(); + KEntryMapConstIterator it =3D entryMap.findEntry(theGroup); + if (it !=3D theEnd) { + ++it; // advance past the special group entry marker + + QSet tmp; + for (; it !=3D theEnd && it.key().mGroup =3D=3D theGroup; ++it) { + const KEntryKey& key =3D it.key(); + if (key.mGroup =3D=3D theGroup && !key.mKey.isNull() && !it->= bDeleted) + tmp << QString::fromUtf8(key.mKey); + } + keys =3D tmp.toList(); + } + + return keys; +} + +QStringList KConfig::keyList(const QString& aGroup) const +{ + Q_D(const KConfig); + const QByteArray theGroup(aGroup.isEmpty() ? "" : aGroup.toU= tf8()); + return d->keyListImpl(theGroup); +} + +QMap KConfig::entryMap(const QString& aGroup) const +{ + Q_D(const KConfig); + QMap theMap; + const QByteArray theGroup(aGroup.isEmpty() ? "" : aGroup.toU= tf8()); + + const KEntryMapConstIterator theEnd =3D d->entryMap.constEnd(); + KEntryMapConstIterator it =3D d->entryMap.findEntry(theGroup, 0, 0); + if (it !=3D theEnd) { + ++it; // advance past the special group entry marker + + for (; it !=3D theEnd && it.key().mGroup =3D=3D theGroup; ++it) { + // leave the default values and deleted entries out + if (!it->bDeleted && !it.key().bDefault) { + const QString key =3D QString::fromUtf8(it.key().mKey.con= stData()); + // the localized entry should come first, so don't overwr= ite it + // with the non-localized entry + if (!theMap.contains(key)) { + if (it->bExpand) { + theMap.insert(key,KConfigPrivate::expandString(QS= tring::fromUtf8(it->mValue.constData()))); + } else { + theMap.insert(key,QString::fromUtf8(it->mValue.co= nstData())); + } + } + } + } + } + + return theMap; +} + +// TODO KDE5: return a bool value +void KConfig::sync() +{ + Q_D(KConfig); + + if (isImmutable() || name().isEmpty()) { + // can't write to an immutable or anonymous file. + return; + } + + if (d->bDirty && d->mBackend) { + const QByteArray utf8Locale(locale().toUtf8()); + + // Create the containing dir, maybe it wasn't there + d->mBackend->createEnclosing(); + + // lock the local file + if (d->configState =3D=3D ReadWrite && !d->lockLocal()) { + qWarning() << "couldn't lock local file"; + return; + } + + // Rewrite global/local config only if there is a dirty entry in = it. + bool writeGlobals =3D false; + bool writeLocals =3D false; + Q_FOREACH (const KEntry& e, d->entryMap) { + if (e.bDirty) { + if (e.bGlobal) { + writeGlobals =3D true; + } else { + writeLocals =3D true; + } + + if (writeGlobals && writeLocals) { + break; + } + } + } + + d->bDirty =3D false; // will revert to true if a config write fai= ls + + if (d->wantGlobals() && writeGlobals) { + KSharedPtr tmp =3D KConfigBackend::create(d->= sGlobalFileName); + if (d->configState =3D=3D ReadWrite && !tmp->lock()) { + qWarning() << "couldn't lock global file"; ++ d->bDirty =3D true; + return; + } + if (!tmp->writeConfig(utf8Locale, d->entryMap, KConfigBackend= ::WriteGlobal)) { + d->bDirty =3D true; + // TODO KDE5: return false? (to tell the app that writing= wasn't possible, e.g. + // config file is immutable or disk full) + } + if (tmp->isLocked()) { + tmp->unlock(); + } + } + + if (writeLocals) { + if (!d->mBackend->writeConfig(utf8Locale, d->entryMap, KConfi= gBackend::WriteOptions())) { + d->bDirty =3D true; + // TODO KDE5: return false? (to tell the app that writing= wasn't possible, e.g. + // config file is immutable or disk full) + } + } + if (d->mBackend->isLocked()) { + d->mBackend->unlock(); + } + } +} + +void KConfig::markAsClean() +{ + Q_D(KConfig); + d->bDirty =3D false; + + // clear any dirty flags that entries might have set + const KEntryMapIterator theEnd =3D d->entryMap.end(); + for (KEntryMapIterator it =3D d->entryMap.begin(); it !=3D theEnd; ++= it) + it->bDirty =3D false; +} + +void KConfig::checkUpdate(const QString &id, const QString &updateFile) +{ + const KConfigGroup cg(this, "$Version"); + const QString cfg_id =3D updateFile+QLatin1Char(':')+id; + const QStringList ids =3D cg.readEntry("update_info", QStringList()); + if (!ids.contains(cfg_id)) { +#if 0 + KToolInvocation::kdeinitExecWait(QString::fromLatin1("kconf_updat= e"), QStringList() << QString::fromLatin1("--check") << updateFile); +#else + QProcess::execute(QString::fromLatin1("kconf_update"), QStringLis= t() << QString::fromLatin1("--check") << updateFile); +#endif + reparseConfiguration(); + } +} + +KConfig* KConfig::copyTo(const QString &file, KConfig *config) const +{ + Q_D(const KConfig); + if (!config) + config =3D new KConfig(QString(), SimpleConfig, d->resourceType); + config->d_func()->changeFileName(file); + config->d_func()->entryMap =3D d->entryMap; + config->d_func()->bFileImmutable =3D false; + + const KEntryMapIterator theEnd =3D config->d_func()->entryMap.end(); + for (KEntryMapIterator it =3D config->d_func()->entryMap.begin(); it = !=3D theEnd; ++it) + it->bDirty =3D true; + config->d_ptr->bDirty =3D true; + + return config; +} + +QString KConfig::name() const +{ + Q_D(const KConfig); + return d->fileName; +} + +Q_GLOBAL_STATIC(QString, globalMainConfigName) + +void KConfig::setMainConfigName(const QString& str) +{ + *globalMainConfigName() =3D str; +} + +QString KConfig::mainConfigName() +{ + // --config on the command line overrides everything else + const QStringList args =3D QCoreApplication::arguments(); + for (int i =3D 1; i < args.count() ; ++i) { + if (args.at(i) =3D=3D QLatin1String("--config") && i < args.count= ()-1) { + return args.at(i+1); + } + } + const QString globalName =3D *globalMainConfigName(); + if (!globalName.isEmpty()) + return globalName; + + QString appName =3D QCoreApplication::applicationName(); + return appName + QLatin1String("rc"); +} + +void KConfigPrivate::changeFileName(const QString& name) +{ + fileName =3D name; + + QString file; + if (name.isEmpty()) { + if (wantDefaults()) { // accessing default app-specific config "a= ppnamerc" + fileName =3D KConfig::mainConfigName(); + file =3D QStandardPaths::writableLocation(resourceType) + QLa= tin1Char('/') + fileName; + } else if (wantGlobals()) { // accessing "kdeglobals" - XXX used = anywhere? + resourceType =3D QStandardPaths::ConfigLocation; + fileName =3D QLatin1String("kdeglobals"); + file =3D sGlobalFileName; + } else { + // anonymous config + openFlags =3D KConfig::SimpleConfig; + return; + } + } else if (QDir::isAbsolutePath(fileName)) { + fileName =3D QFileInfo(fileName).canonicalFilePath(); + if (fileName.isEmpty()) // file doesn't exist (yet) + fileName =3D name; + file =3D fileName; + } else { + file =3D QStandardPaths::writableLocation(resourceType) + QLatin1= Char('/') + fileName; + } + + Q_ASSERT(!file.isEmpty()); + + bSuppressGlobal =3D (file =3D=3D sGlobalFileName); + + if (bDynamicBackend || !mBackend) // allow dynamic changing of backend + mBackend =3D KConfigBackend::create(file); + else + mBackend->setFilePath(file); + + configState =3D mBackend->accessMode(); +} + +void KConfig::reparseConfiguration() +{ + Q_D(KConfig); + if (d->fileName.isEmpty()) { + return; + } + + // Don't lose pending changes + if (!d->isReadOnly() && d->bDirty) + sync(); + + d->entryMap.clear(); + + d->bFileImmutable =3D false; + + // Parse all desired files from the least to the most specific. + if (d->wantGlobals()) + d->parseGlobalFiles(); + + d->parseConfigFiles(); +} + + +QStringList KConfigPrivate::getGlobalFiles() const +{ + QStringList globalFiles; + Q_FOREACH (const QString& dir1, QStandardPaths::locateAll(QStandardPa= ths::ConfigLocation, QLatin1String("kdeglobals"))) + globalFiles.push_front(dir1); + Q_FOREACH (const QString& dir2, QStandardPaths::locateAll(QStandardPa= ths::ConfigLocation, QLatin1String("system.kdeglobals"))) + globalFiles.push_front(dir2); + if (!etc_kderc.isEmpty()) + globalFiles.push_front(etc_kderc); + return globalFiles; +} + +void KConfigPrivate::parseGlobalFiles() +{ + const QStringList globalFiles =3D getGlobalFiles(); +// qDebug() << "parsing global files" << globalFiles; + + // TODO: can we cache the values in etc_kderc / other global files + // on a per-application basis? + const QByteArray utf8Locale =3D locale.toUtf8(); + Q_FOREACH(const QString& file, globalFiles) { + KConfigBackend::ParseOptions parseOpts =3D KConfigBackend::ParseG= lobal|KConfigBackend::ParseExpansions; + if (file !=3D sGlobalFileName) + parseOpts |=3D KConfigBackend::ParseDefaults; + + KSharedPtr backend =3D KConfigBackend::create(fil= e); + if ( backend->parseConfig( utf8Locale, entryMap, parseOpts) =3D= =3D KConfigBackend::ParseImmutable) + break; + } +} + +void KConfigPrivate::parseConfigFiles() +{ + // can only read the file if there is a backend and a file name + if (mBackend && !fileName.isEmpty()) { + + bFileImmutable =3D false; + + QList files; + if (wantDefaults()) { + if (bSuppressGlobal) { + files =3D getGlobalFiles(); + } else { + if (QDir::isAbsolutePath(fileName)) { + files << fileName; + } else { + Q_FOREACH (const QString& f, QStandardPaths::locateAl= l(resourceType, fileName)) + files.prepend(f); + } + } + } else { + files << mBackend->filePath(); + } + if (!isSimple()) + files =3D extraFiles.toList() + files; + +// qDebug() << "parsing local files" << files; + + const QByteArray utf8Locale =3D locale.toUtf8(); + Q_FOREACH(const QString& file, files) { + if (file =3D=3D mBackend->filePath()) { + switch (mBackend->parseConfig(utf8Locale, entryMap, KConf= igBackend::ParseExpansions)) { + case KConfigBackend::ParseOk: + break; + case KConfigBackend::ParseImmutable: + bFileImmutable =3D true; + break; + case KConfigBackend::ParseOpenError: + configState =3D KConfigBase::NoAccess; + break; + } + } else { + KSharedPtr backend =3D KConfigBackend::cr= eate(file); + bFileImmutable =3D (backend->parseConfig(utf8Locale, entr= yMap, + KConfigBackend::ParseDefaults|KCo= nfigBackend::ParseExpansions) + =3D=3D KConfigBackend::ParseImmutable); + } + + if (bFileImmutable) + break; + } +#pragma message("TODO: enable kiosk feature again (resource restrictions)= , but without KStandardDirs... Needs a class in the kconfig framework.") +#if 0 + if (componentData.dirs()->isRestrictedResource(resourceType, file= Name)) + bFileImmutable =3D true; +#endif + } +} + +KConfig::AccessMode KConfig::accessMode() const +{ + Q_D(const KConfig); + return d->configState; +} + +void KConfig::addConfigSources(const QStringList& files) +{ + Q_D(KConfig); + Q_FOREACH(const QString& file, files) { + d->extraFiles.push(file); + } + + if (!files.isEmpty()) { + reparseConfiguration(); + } +} + +QString KConfig::locale() const +{ + Q_D(const KConfig); + return d->locale; +} + +bool KConfigPrivate::setLocale(const QString& aLocale) +{ + if (aLocale !=3D locale) { + locale =3D aLocale; + return true; + } + return false; +} + +bool KConfig::setLocale(const QString& locale) +{ + Q_D(KConfig); + if (d->setLocale(locale)) { + reparseConfiguration(); + return true; + } + return false; +} + +void KConfig::setReadDefaults(bool b) +{ + Q_D(KConfig); + d->bReadDefaults =3D b; +} + +bool KConfig::readDefaults() const +{ + Q_D(const KConfig); + return d->bReadDefaults; +} + +bool KConfig::isImmutable() const +{ + Q_D(const KConfig); + return d->bFileImmutable; +} + +bool KConfig::isGroupImmutableImpl(const QByteArray& aGroup) const +{ + Q_D(const KConfig); + return isImmutable() || d->entryMap.getEntryOption(aGroup, 0, 0, KEnt= ryMap::EntryImmutable); +} + +#ifndef KDE_NO_DEPRECATED +void KConfig::setForceGlobal(bool b) +{ + Q_D(KConfig); + d->bForceGlobal =3D b; +} +#endif + +#ifndef KDE_NO_DEPRECATED +bool KConfig::forceGlobal() const +{ + Q_D(const KConfig); + return d->bForceGlobal; +} +#endif + +KConfigGroup KConfig::groupImpl(const QByteArray &group) +{ + return KConfigGroup(this, group.constData()); +} + +const KConfigGroup KConfig::groupImpl(const QByteArray &group) const +{ + return KConfigGroup(this, group.constData()); +} + +KEntryMap::EntryOptions convertToOptions(KConfig::WriteConfigFlags flags) +{ + KEntryMap::EntryOptions options=3D0; + + if (flags&KConfig::Persistent) + options |=3D KEntryMap::EntryDirty; + if (flags&KConfig::Global) + options |=3D KEntryMap::EntryGlobal; + if (flags&KConfig::Localized) + options |=3D KEntryMap::EntryLocalized; + return options; +} + +void KConfig::deleteGroupImpl(const QByteArray &aGroup, WriteConfigFlags = flags) +{ + Q_D(KConfig); + KEntryMap::EntryOptions options =3D convertToOptions(flags)|KEntryMap= ::EntryDeleted; + + const QSet groups =3D d->allSubGroups(aGroup); + Q_FOREACH (const QByteArray& group, groups) { + const QStringList keys =3D d->keyListImpl(group); + Q_FOREACH (const QString& _key, keys) { + const QByteArray &key =3D _key.toUtf8(); + if (d->canWriteEntry(group, key.constData())) { + d->entryMap.setEntry(group, key, QByteArray(), options); + d->bDirty =3D true; + } + } + } +} + +bool KConfig::isConfigWritable(bool warnUser) +{ + Q_D(KConfig); + bool allWritable =3D (d->mBackend.isNull()? false: d->mBackend->isWri= table()); + + if (warnUser && !allWritable) { + QString errorMsg; + if (!d->mBackend.isNull()) // TODO how can be it be null? Set err= orMsg appropriately + errorMsg =3D d->mBackend->nonWritableErrorMessage(); + + // Note: We don't ask the user if we should not ask this question= again because we can't save the answer. + errorMsg +=3D QCoreApplication::translate("KConfig", "Please cont= act your system administrator."); + QString cmdToExec =3D QStandardPaths::findExecutable(QString::fro= mLatin1("kdialog")); + if (!cmdToExec.isEmpty()) + { + QProcess::execute(cmdToExec, QStringList() + << QString::fromLatin1("--title") << QCoreA= pplication::applicationName() + << QString::fromLatin1("--msgbox") << error= Msg); + } + } + + d->configState =3D allWritable ? ReadWrite : ReadOnly; // update the= read/write status + + return allWritable; +} + +bool KConfig::hasGroupImpl(const QByteArray& aGroup) const +{ + Q_D(const KConfig); + + // No need to look for the actual group entry anymore, or for subgrou= ps: + // a group exists if it contains any non-deleted entry. + + return d->hasNonDeletedEntries(aGroup); +} + +bool KConfigPrivate::canWriteEntry(const QByteArray& group, const char* k= ey, bool isDefault) const +{ + if (bFileImmutable || + entryMap.getEntryOption(group, key, KEntryMap::SearchLocalized, K= EntryMap::EntryImmutable)) + return isDefault; + return true; +} + +void KConfigPrivate::putData( const QByteArray& group, const char* key, + const QByteArray& value, KConfigBase::WriteConfigFl= ags flags, bool expand) +{ + KEntryMap::EntryOptions options =3D convertToOptions(flags); + + if (bForceGlobal) + options |=3D KEntryMap::EntryGlobal; + if (expand) + options |=3D KEntryMap::EntryExpansion; + + if (value.isNull()) // deleting entry + options |=3D KEntryMap::EntryDeleted; + + bool dirtied =3D entryMap.setEntry(group, key, value, options); + if (dirtied && (flags & KConfigBase::Persistent)) + bDirty =3D true; +} + +QByteArray KConfigPrivate::lookupData(const QByteArray& group, const char= * key, + KEntryMap::SearchFlags flags) const +{ + if (bReadDefaults) + flags |=3D KEntryMap::SearchDefaults; + const KEntryMapConstIterator it =3D entryMap.findEntry(group, key, fl= ags); + if (it =3D=3D entryMap.constEnd()) + return QByteArray(); + return it->mValue; +} + +QString KConfigPrivate::lookupData(const QByteArray& group, const char* k= ey, + KEntryMap::SearchFlags flags, bool *ex= pand) const +{ + if (bReadDefaults) + flags |=3D KEntryMap::SearchDefaults; + return entryMap.getEntry(group, key, QString(), flags, expand); +} + +QStandardPaths::StandardLocation KConfig::locationType() const +{ + Q_D(const KConfig); + return d->resourceType; +} + +void KConfig::virtual_hook(int /*id*/, void* /*data*/) +{ + /* nothing */ +}