a6faba7f2968bfbb8495d3a4d0eed2048e904a67
[mdictionary] / trunk / src / includes / settings.h
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
5     mDictionary is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
10     mDictionary 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
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21
22 /*! /file settings.h
23 \brief Settings object for pluggins \see Settings
24
25 \author Bartosz Szatkowski <bulislaw@linux.com>
26 */
27
28 #ifndef SETTINGS_H
29 #define SETTINGS_H
30
31 #include <QString>
32 #include <QHash>
33 #include "CommonDictInterface.h"
34
35 class CommonDictInterface;
36
37 /*! Plugins or dictionaries may need to keep some of configuration between
38   sessions, moreover Backbone or GUI may want store some additional info in
39   plugin Settings.
40
41   Its important for plugin to store all information given it in Settings.*/
42 class Settings {
43   public:
44     Settings(){}
45     Settings(const Settings* set) {
46         _settings = QHash<QString, QString>(set->_settings);
47     }
48
49     /*! \returns value fo given key
50          \param key
51     */
52     QString value(const QString key) const {
53         if(!_settings.contains(key)) {
54             return QString();
55         }
56         return _settings[key];
57     }
58
59     //! sets key to value
60     void setValue(const QString key, const QString value) {
61         _settings.insert(key, value);
62     }
63
64     QList<QString> keys() const {
65         return _settings.keys();
66     }
67
68 private:
69     QHash<QString, QString> _settings;
70 };
71
72 #endif // SETTINGS_H