1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2006 Thomas Braxton <brax108@cox.net>
4 SPDX-FileCopyrightText: 1999 Preston Brown <pbrown@kde.org>
5 SPDX-FileCopyrightText: 1997-1999 Matthias Kalle Dalheimer <kalle@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#include "kconfigbackend_p.h"
11
12#include <QDateTime>
13#include <QDebug>
14#include <QDir>
15#include <QFileInfo>
16#include <QHash>
17#include <QStringList>
18
19#include "kconfigdata_p.h"
20#include "kconfigini_p.h"
21
22typedef QExplicitlySharedDataPointer<KConfigBackend> BackendPtr;
23
24class KConfigBackendPrivate
25{
26public:
27 QString localFileName;
28
29 static QString whatSystem(const QString & /*fileName*/)
30 {
31 return QStringLiteral("INI");
32 }
33};
34
35void KConfigBackend::registerMappings(const KEntryMap & /*entryMap*/)
36{
37}
38
39BackendPtr KConfigBackend::create(const QString &file, const QString &sys)
40{
41 // qDebug() << "creating a backend for file" << file << "with system" << sys;
42 KConfigBackend *backend = nullptr;
43
44#if 0 // TODO port to Qt5 plugin loading
45 const QString system = (sys.isEmpty() ? KConfigBackendPrivate::whatSystem(file) : sys);
46 if (system.compare(QLatin1String("INI"), Qt::CaseInsensitive) != 0) {
47 const QString constraint = QString::fromLatin1("[X-KDE-PluginInfo-Name] ~~ '%1'").arg(system);
48 KService::List offers = KServiceTypeTrader::self()->query(QLatin1String("KConfigBackend"), constraint);
49
50 //qDebug() << "found" << offers.count() << "offers for KConfigBackend plugins with name" << system;
51 foreach (const KService::Ptr &offer, offers) {
52 backend = offer->createInstance<KConfigBackend>(nullptr);
53 if (backend) {
54 //qDebug() << "successfully created a backend for" << system;
55 backend->setFilePath(file);
56 return BackendPtr(backend);
57 }
58 } // foreach offers
59 }
60#else
61 Q_UNUSED(sys);
62#endif
63
64 // qDebug() << "default creation of the Ini backend";
65 backend = new KConfigIniBackend;
66 backend->setFilePath(file);
67 return BackendPtr(backend);
68}
69
70KConfigBackend::KConfigBackend()
71 : d(new KConfigBackendPrivate)
72{
73}
74
75KConfigBackend::~KConfigBackend()
76{
77 delete d;
78}
79
80QString KConfigBackend::filePath() const
81{
82 return d->localFileName;
83}
84
85void KConfigBackend::setLocalFilePath(const QString &file)
86{
87 d->localFileName = file;
88}
89
90#include "moc_kconfigbackend_p.cpp"
91

source code of kconfig/src/core/kconfigbackend.cpp