KDECore
kconfigbackend.cpp
Go to the documentation of this file.00001 /* 00002 This file is part of the KDE libraries 00003 Copyright (c) 2006 Thomas Braxton <brax108@cox.net> 00004 Copyright (c) 1999 Preston Brown <pbrown@kde.org> 00005 Copyright (c) 1997-1999 Matthias Kalle Dalheimer <kalle@kde.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #include "kconfigbackend.h" 00024 00025 #include <QtCore/QDateTime> 00026 #include <QtCore/QStringList> 00027 #include <QtCore/QDir> 00028 #include <QtCore/QFileInfo> 00029 #include <QtCore/QHash> 00030 #include <QtCore/QDebug> 00031 00032 #include "kglobal.h" 00033 //#include "klocale.h" 00034 #include "kpluginloader.h" 00035 #include "kservicetypetrader.h" 00036 //#include "kapplication.h" 00037 #include "kconfig.h" 00038 #include "kconfigini_p.h" 00039 #include "kconfigdata.h" 00040 #include "kdebug.h" 00041 #include "kstandarddirs.h" 00042 #include "kconfigbackend.moc" 00043 00044 typedef KSharedPtr<KConfigBackend> BackendPtr; 00045 00046 class KConfigBackend::Private 00047 { 00048 public: 00049 qint64 size; 00050 QDateTime lastModified; 00051 QString localFileName; 00052 00053 static QString whatSystem(const QString& /*fileName*/) 00054 { 00055 return QLatin1String("INI"); 00056 } 00057 }; 00058 00059 00060 void KConfigBackend::registerMappings(const KEntryMap& /*entryMap*/) 00061 { 00062 } 00063 00064 BackendPtr KConfigBackend::create(const KComponentData& componentData, const QString& file, 00065 const QString& sys) 00066 { 00067 //qDebug() << "creating a backend for file" << file << "with system" << sys; 00068 const QString system = (sys.isEmpty() ? Private::whatSystem(file) : sys); 00069 KConfigBackend* backend = 0; 00070 00071 if (system.compare("INI", Qt::CaseInsensitive) != 0) { 00072 QString constraint = QString("'%1' ~~ Name").arg(system); 00073 KService::List offers = KServiceTypeTrader::self()->query("KConfigBackend", constraint); 00074 00075 //qDebug() << "found" << offers.count() << "offers for KConfigBackend plugins with name" << system; 00076 foreach (const KService::Ptr& offer, offers) { 00077 backend = offer->createInstance<KConfigBackend>(0); 00078 if (backend) { 00079 //qDebug() << "successfully created a backend for" << system; 00080 backend->setFilePath(file); 00081 return BackendPtr(backend); 00082 } 00083 } // foreach offers 00084 } 00085 00086 //qDebug() << "default creation of the Ini backend"; 00087 backend = new KConfigIniBackend; 00088 backend->setFilePath(file); 00089 return BackendPtr(backend); 00090 } 00091 00092 KConfigBackend::KConfigBackend() 00093 : d(new Private) 00094 { 00095 } 00096 00097 KConfigBackend::~KConfigBackend() 00098 { 00099 delete d; 00100 } 00101 00102 QDateTime KConfigBackend::lastModified() const 00103 { 00104 return d->lastModified; 00105 } 00106 00107 void KConfigBackend::setLastModified(const QDateTime& dt) 00108 { 00109 d->lastModified = dt; 00110 } 00111 00112 qint64 KConfigBackend::size() const 00113 { 00114 return d->size; 00115 } 00116 00117 void KConfigBackend::setSize(qint64 sz) 00118 { 00119 d->size = sz; 00120 } 00121 00122 QString KConfigBackend::filePath() const 00123 { 00124 return d->localFileName; 00125 } 00126 00127 void KConfigBackend::setLocalFilePath(const QString& file) 00128 { 00129 d->localFileName = file; 00130 }