1 /***************************************************************************
2  *   Copyright (C) 2005-2009 by Rajko Albrecht  ral@alwins-world.de        *
3  *   http://kdesvn.alwins-world.de/                                        *
4  *                                                                         *
5  * This program is free software; you can redistribute it and/or           *
6  * modify it under the terms of the GNU Lesser General Public              *
7  * License as published by the Free Software Foundation; either            *
8  * version 2.1 of the License, or (at your option) any later version.      *
9  *                                                                         *
10  * This program is distributed in the hope that it will be useful,         *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
13  * Lesser General Public License for more details.                         *
14  *                                                                         *
15  * You should have received a copy of the GNU Lesser General Public        *
16  * License along with this program (in the file LGPL.txt); if not,         *
17  * write to the Free Software Foundation, Inc., 51 Franklin St,            *
18  * Fifth Floor, Boston, MA  02110-1301  USA                                *
19  *                                                                         *
20  * This software consists of voluntary contributions made by many          *
21  * individuals.  For exact contribution history, see the revision          *
22  * history and logs, available at http://kdesvn.alwins-world.de.           *
23  ***************************************************************************/
24 
25 /***************************************************************************
26  * Lot of code and ideas taken from KDE 4 KConfigGroup source code         *
27  * ksvn://anonsvn.kde.org/home/kde/branches/KDE/4.2/kdelibs/kdecore/config *
28  ***************************************************************************/
29 
30 #ifndef REPOSCONFIG_HPP
31 #define REPOSCONFIG_HPP
32 
33 #include <QVariant>
34 #include <QString>
35 #include <QList>
36 
37 #include <ConversionCheck>
38 #include "svnqt/svnqt_defines.h"
39 
40 namespace svn
41 {
42 namespace cache
43 {
44 
45 class SVNQT_EXPORT ReposConfig
46 {
47 
48 private:
49     static ReposConfig *mSelf;
50 protected:
51     ReposConfig();
52     template <typename T> void writeCheck(const QString &repository, const QString &key, const T &value);
53     template <typename T> void writeListCheck(const QString &repository, const QString &key, const QList<T> &value);
54 
55 public:
56     static ReposConfig *self();
57 
58     template<typename T> void setValue(const QString &repository, const QString &key, const T &value);
59     template<typename T> void setValue(const QString &repository, const QString &key, const QList<T> &value);
60     void setValue(const QString &repository, const QString &key, const QStringList &value);
61     void setValue(const QString &repository, const QString &key, const QVariant &value);
62     void setValue(const QString &repository, const QString &key, const QVariantList &list);
63     void setValue(const QString &repository, const QString &key, const QString &value);
64 
65     //! special setter
66     void eraseValue(const QString &repository, const QString &key);
67 
68     QVariant readEntry(const QString &repository, const QString &key, const QVariant &aDefault);
69     int readEntry(const QString &repository, const QString &key, int aDefault);
70     bool readEntry(const QString &repository, const QString &key, bool aDefault);
71     QStringList readEntry(const QString &repository, const QString &key, const QStringList &aDefault);
72 };
73 
setValue(const QString & repository,const QString & key,const T & value)74 template<typename T> inline void ReposConfig::setValue(const QString &repository, const QString &key, const T &value)
75 {
76     writeCheck(repository, key, value);
77 }
78 
79 template <typename T> inline
writeCheck(const QString & repository,const QString & key,const T & value)80 void ReposConfig::writeCheck(const QString &repository, const QString &key, const T &value)
81 {
82     ConversionCheck::to_QVariant<T>();
83     setValue(repository, key, qVariantFromValue(value));
84 }
85 
86 template<typename T> inline
setValue(const QString & repository,const QString & key,const QList<T> & value)87 void ReposConfig::setValue(const QString &repository, const QString &key, const QList<T> &value)
88 {
89     writeListCheck(repository, key, value);
90 }
91 
92 template <typename T> inline
writeListCheck(const QString & repository,const QString & key,const QList<T> & list)93 void ReposConfig::writeListCheck(const QString &repository, const QString &key, const QList<T> &list)
94 {
95     ConversionCheck::to_QVariant<T>();
96     ConversionCheck::to_QString<T>();
97     QVariantList data;
98     for (const T &value : list)
99         data.append(qVariantFromValue(value));
100     setValue(repository, key, data);
101 }
102 
103 } // namespace cache
104 } // namespace svn
105 
106 #endif
107