KConfig

kconfigbackend.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2006 Thomas Braxton <[email protected]>
4  SPDX-FileCopyrightText: 1999 Preston Brown <[email protected]>
5  SPDX-FileCopyrightText: 1997-1999 Matthias Kalle Dalheimer <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #include "kconfigbackend_p.h"
11 
12 #include <QDateTime>
13 #include <QStringList>
14 #include <QDir>
15 #include <QFileInfo>
16 #include <QHash>
17 #include <QDebug>
18 
19 #include "kconfigini_p.h"
20 #include "kconfigdata.h"
21 
23 
24 class KConfigBackendPrivate
25 {
26 public:
27  QString localFileName;
28 
29  static QString whatSystem(const QString & /*fileName*/)
30  {
31  return QStringLiteral("INI");
32  }
33 };
34 
35 void KConfigBackend::registerMappings(const KEntryMap & /*entryMap*/)
36 {
37 }
38 
39 BackendPtr 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 
70 KConfigBackend::KConfigBackend()
71  : d(new KConfigBackendPrivate)
72 {
73 }
74 
75 KConfigBackend::~KConfigBackend()
76 {
77  delete d;
78 }
79 
80 QString KConfigBackend::filePath() const
81 {
82  return d->localFileName;
83 }
84 
85 void KConfigBackend::setLocalFilePath(const QString &file)
86 {
87  d->localFileName = file;
88 }
static KServiceTypeTrader * self()
CaseInsensitive
bool isEmpty() const const
KService::List query(const QString &servicetype, const QString &constraint=QString()) const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromLatin1(const char *str, int size)
int compare(const QString &other, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Jul 1 2020 22:46:30 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.