File indexing completed on 2024-05-12 03:54:24
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2006 Thomas Braxton <brax108@cox.net> 0004 SPDX-FileCopyrightText: 1999 Preston Brown <pbrown@kde.org> 0005 SPDX-FileCopyrightText: 1997-1999 Matthias Kalle Dalheimer <kalle@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #include "kconfigbackend_p.h" 0011 0012 #include <QDateTime> 0013 #include <QDebug> 0014 #include <QDir> 0015 #include <QFileInfo> 0016 #include <QHash> 0017 #include <QStringList> 0018 0019 #include "kconfigdata_p.h" 0020 #include "kconfigini_p.h" 0021 0022 typedef QExplicitlySharedDataPointer<KConfigBackend> BackendPtr; 0023 0024 class KConfigBackendPrivate 0025 { 0026 public: 0027 QString localFileName; 0028 0029 static QString whatSystem(const QString & /*fileName*/) 0030 { 0031 return QStringLiteral("INI"); 0032 } 0033 }; 0034 0035 void KConfigBackend::registerMappings(const KEntryMap & /*entryMap*/) 0036 { 0037 } 0038 0039 BackendPtr KConfigBackend::create(const QString &file, const QString &sys) 0040 { 0041 // qDebug() << "creating a backend for file" << file << "with system" << sys; 0042 KConfigBackend *backend = nullptr; 0043 0044 #if 0 // TODO port to Qt5 plugin loading 0045 const QString system = (sys.isEmpty() ? KConfigBackendPrivate::whatSystem(file) : sys); 0046 if (system.compare(QLatin1String("INI"), Qt::CaseInsensitive) != 0) { 0047 const QString constraint = QString::fromLatin1("[X-KDE-PluginInfo-Name] ~~ '%1'").arg(system); 0048 KService::List offers = KServiceTypeTrader::self()->query(QLatin1String("KConfigBackend"), constraint); 0049 0050 //qDebug() << "found" << offers.count() << "offers for KConfigBackend plugins with name" << system; 0051 foreach (const KService::Ptr &offer, offers) { 0052 backend = offer->createInstance<KConfigBackend>(nullptr); 0053 if (backend) { 0054 //qDebug() << "successfully created a backend for" << system; 0055 backend->setFilePath(file); 0056 return BackendPtr(backend); 0057 } 0058 } // foreach offers 0059 } 0060 #else 0061 Q_UNUSED(sys); 0062 #endif 0063 0064 // qDebug() << "default creation of the Ini backend"; 0065 backend = new KConfigIniBackend; 0066 backend->setFilePath(file); 0067 return BackendPtr(backend); 0068 } 0069 0070 KConfigBackend::KConfigBackend() 0071 : d(new KConfigBackendPrivate) 0072 { 0073 } 0074 0075 KConfigBackend::~KConfigBackend() 0076 { 0077 delete d; 0078 } 0079 0080 QString KConfigBackend::filePath() const 0081 { 0082 return d->localFileName; 0083 } 0084 0085 void KConfigBackend::setLocalFilePath(const QString &file) 0086 { 0087 d->localFileName = file; 0088 } 0089 0090 #include "moc_kconfigbackend_p.cpp"