1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
7 **
8 **
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License version 2 as published by the Free Software
11 ** Foundation and appearing in the file gpl-2.0.txt included in the
12 ** packaging of this file.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 **
23 ** This copyright notice MUST APPEAR in all copies of the script!
24 **
25 **********************************************************************/
26 
27 
28 #ifndef RS_SETTINGS_H
29 #define RS_SETTINGS_H
30 
31 #include <QString>
32 #include <map>
33 
34 class QVariant;
35 
36 // ---------------------------------------------------------------------------
37 // Default Settings
38 // ---------------------------------------------------------------------------
39 
40 namespace Colors
41 {
42     const QString snap_indicator   = "#FFC200";
43     const QString background       = "Black";
44     const QString grid             = "Gray";
45     const QString meta_grid        = "#404040";
46     const QString select           = "#A54747";
47     const QString highlight        = "#739373";
48     const QString start_handle     = "Cyan";
49     const QString handle           = "Blue";
50     const QString end_handle       = "Blue";
51 }
52 
53 // ---------------------------------------------------------------------------
54 
55 #define RS_SETTINGS RS_Settings::instance()
56 
57 /**
58  * This class can store and reload settings from a
59  * configuration file or the windoze registry.
60  * Please note that the Qt default implementation doesn't
61  * work as one would expect. That's why this class overwrites
62  * most of the default behaviour.
63  *
64  */
65 class RS_Settings {
66 
67 public:
68 	~RS_Settings();
69 	/**
70      * @return Instance to the unique settings object.
71      */
72 	static RS_Settings* instance();
73 
74     /**
75      * Initialize the system.
76      *
77      * @param companyKey Company Key
78      * @param appKey Application key
79      */
80     void init(const QString& companyKey, const QString& appKey);
81 
82     void beginGroup(const QString& group);
83     void endGroup();
84 
85     bool writeEntry(const QString& key, int value);
86     bool writeEntry(const QString& key, double value);
87     bool writeEntry(const QString& key, const QVariant& value);
88     bool writeEntry(const QString& key, const QString& value);
89     QString readEntry(const QString& key,
90                         const QString& def = QString(),
91                         bool* ok = 0);
92     QByteArray readByteArrayEntry(const QString& key,
93                         const QString& def = QString(),
94                         bool* ok = 0);
95 	int readNumEntry(const QString& key, int def=0);
96     void clear_all();
97     void clear_geometry();
98     static bool save_is_allowed;
99 
100 private:
101     RS_Settings();
102 	RS_Settings(RS_Settings const&) = delete;
103 	RS_Settings& operator = (RS_Settings const&) = delete;
104 	QVariant readEntryCache(const QString& key);
105 	void addToCache(const QString& key, const QVariant& value);
106 
107 protected:
108     static RS_Settings* uniqueInstance;
109 
110 	std::map<QString, QVariant> cache;
111     QString companyKey;
112     QString appKey;
113     QString group;
114     bool initialized;
115 };
116 
117 #endif
118 
119