• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • config
kconfigbackend.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the KDE libraries
3  Copyright (c) 2006 Thomas Braxton <brax108@cox.net>
4  Copyright (c) 1999 Preston Brown <pbrown@kde.org>
5  Copyright (c) 1997-1999 Matthias Kalle Dalheimer <kalle@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "kconfigbackend.h"
24 
25 #include <QtCore/QDateTime>
26 #include <QtCore/QStringList>
27 #include <QtCore/QDir>
28 #include <QtCore/QFileInfo>
29 #include <QtCore/QHash>
30 #include <QtCore/QDebug>
31 
32 #include "kglobal.h"
33 //#include "klocale.h"
34 #include "kpluginloader.h"
35 #include "kservicetypetrader.h"
36 //#include "kapplication.h"
37 #include "kconfig.h"
38 #include "kconfigini_p.h"
39 #include "kconfigdata.h"
40 #include "kdebug.h"
41 #include "kstandarddirs.h"
42 #include "kconfigbackend.moc"
43 
44 typedef KSharedPtr<KConfigBackend> BackendPtr;
45 
46 class KConfigBackend::Private
47 {
48 public:
49  qint64 size;
50  QDateTime lastModified;
51  QString localFileName;
52 
53  static QString whatSystem(const QString& /*fileName*/)
54  {
55  return QLatin1String("INI");
56  }
57 };
58 
59 
60 void KConfigBackend::registerMappings(const KEntryMap& /*entryMap*/)
61 {
62 }
63 
64 BackendPtr KConfigBackend::create(const KComponentData& componentData, const QString& file,
65  const QString& sys)
66 {
67  Q_UNUSED(componentData);
68  //qDebug() << "creating a backend for file" << file << "with system" << sys;
69  const QString system = (sys.isEmpty() ? Private::whatSystem(file) : sys);
70  KConfigBackend* backend = 0;
71 
72  if (system.compare(QLatin1String("INI"), Qt::CaseInsensitive) != 0) {
73  const QString constraint = QString::fromLatin1("[X-KDE-PluginInfo-Name] ~~ '%1'").arg(system);
74  KService::List offers = KServiceTypeTrader::self()->query(QLatin1String("KConfigBackend"), constraint);
75 
76  //qDebug() << "found" << offers.count() << "offers for KConfigBackend plugins with name" << system;
77  foreach (const KService::Ptr& offer, offers) {
78  backend = offer->createInstance<KConfigBackend>(0);
79  if (backend) {
80  //qDebug() << "successfully created a backend for" << system;
81  backend->setFilePath(file);
82  return BackendPtr(backend);
83  }
84  } // foreach offers
85  }
86 
87  //qDebug() << "default creation of the Ini backend";
88  backend = new KConfigIniBackend;
89  backend->setFilePath(file);
90  return BackendPtr(backend);
91 }
92 
93 KConfigBackend::KConfigBackend()
94  : d(new Private)
95 {
96 }
97 
98 KConfigBackend::~KConfigBackend()
99 {
100  delete d;
101 }
102 
103 QDateTime KConfigBackend::lastModified() const
104 {
105  return d->lastModified;
106 }
107 
108 void KConfigBackend::setLastModified(const QDateTime& dt)
109 {
110  d->lastModified = dt;
111 }
112 
113 qint64 KConfigBackend::size() const
114 {
115  return d->size;
116 }
117 
118 void KConfigBackend::setSize(qint64 sz)
119 {
120  d->size = sz;
121 }
122 
123 QString KConfigBackend::filePath() const
124 {
125  return d->localFileName;
126 }
127 
128 void KConfigBackend::setLocalFilePath(const QString& file)
129 {
130  d->localFileName = file;
131 }
KSharedPtr< KConfigBackend >
qint64
kdebug.h
kconfigini_p.h
KEntryMap
Definition: kconfigdata.h:152
KConfigBackend::KConfigBackend
KConfigBackend()
Definition: kconfigbackend.cpp:93
KConfigBackend::size
qint64 size() const
Definition: kconfigbackend.cpp:113
KServiceTypeTrader::self
static KServiceTypeTrader * self()
This is a static pointer to the KServiceTypeTrader singleton.
Definition: kservicetypetrader.cpp:37
KConfigBackend::setLocalFilePath
void setLocalFilePath(const QString &file)
Definition: kconfigbackend.cpp:128
kconfig.h
BackendPtr
KSharedPtr< KConfigBackend > BackendPtr
Definition: kconfigbackend.cpp:44
kservicetypetrader.h
kconfigbackend.h
kglobal.h
kpluginloader.h
QString::isEmpty
bool isEmpty() const
KConfigBackend::~KConfigBackend
virtual ~KConfigBackend()
Destroys the backend.
Definition: kconfigbackend.cpp:98
KConfigBackend
Provides the implementation for accessing configuration sources.
Definition: kconfigbackend.h:55
QString
KConfigBackend::setFilePath
virtual void setFilePath(const QString &path)=0
Set the file path.
QList< Ptr >
kconfigdata.h
KConfigBackend::filePath
QString filePath() const
Definition: kconfigbackend.cpp:123
KConfigBackend::setLastModified
void setLastModified(const QDateTime &dt)
Definition: kconfigbackend.cpp:108
KServiceTypeTrader::query
KService::List query(const QString &servicetype, const QString &constraint=QString()) const
The main function in the KServiceTypeTrader class.
Definition: kservicetypetrader.cpp:134
QLatin1String
kstandarddirs.h
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KConfigBackend::registerMappings
static void registerMappings(const KEntryMap &entryMap)
Registers mappings from directories/files to configuration systems.
Definition: kconfigbackend.cpp:60
KConfigBackend::setSize
void setSize(qint64 sz)
Definition: kconfigbackend.cpp:118
QString::compare
int compare(const QString &other) const
KConfigBackend::create
static KSharedPtr< KConfigBackend > create(const KComponentData &componentData, const QString &fileName=QString(), const QString &system=QString())
Creates a new KConfig backend.
Definition: kconfigbackend.cpp:64
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
KService::createInstance
T * createInstance(QObject *parent=0, const QVariantList &args=QVariantList(), QString *error=0) const
This template allows to load the library for the specified service and ask the factory to create an i...
Definition: kservice.h:547
KComponentData
Per component data.
Definition: kcomponentdata.h:46
KConfigBackend::lastModified
QDateTime lastModified() const
Definition: kconfigbackend.cpp:103
KConfigIniBackend
Definition: kconfigini_p.h:30
QDateTime
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal