Updated Russian translation
[lxde/liblxqt.git] / lxqtsettings.h
1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2 * (c)LGPL2+
3 *
4 * LXQt - a lightweight, Qt based, desktop toolset
5 * http://razor-qt.org
6 *
7 * Copyright: 2010-2011 Razor team
8 * Authors:
9 * Alexander Sokoloff <sokoloff.a@gmail.com>
10 *
11 * This program or library is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20
21 * You should have received a copy of the GNU Lesser General
22 * Public License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301 USA
25 *
26 * END_COMMON_COPYRIGHT_HEADER */
27
28
29 #ifndef LXQTSETTINGS_H
30 #define LXQTSETTINGS_H
31
32 #include <QObject>
33 #include <QSettings>
34 #include <QSharedDataPointer>
35 #include "lxqtglobals.h"
36
37 class QEvent;
38
39 namespace LXQt
40 {
41
42 class SettingsPrivate;
43 class GlobalSettings;
44
45 /*! \brief User settings handling */
46 class LXQT_API Settings : public QSettings
47 {
48 Q_OBJECT
49 public:
50
51 /*! \brief Constructs a Settings object for accessing settings of the module called module, and with parent parent.
52 Settings can be accessed using the standard interface provided by QSettings, but it also provides some convenience functions and signals.
53
54 \param module a base name of the config file. It's a name without
55 the extension. For example: if you want to open settings for
56 panel create it as Settings("panel").
57 The function will create all parent directories necessary to create
58 the file.
59 \param parent It's no need to delete this class manually if it's set.
60 */
61 explicit Settings(const QString& module, QObject* parent = 0);
62 //explicit Settings(QObject* parent=0);
63 explicit Settings(const QSettings* parentSettings, const QString& subGroup, QObject* parent=0);
64 explicit Settings(const QSettings& parentSettings, const QString& subGroup, QObject* parent=0);
65 Settings(const QString &fileName, QSettings::Format format, QObject *parent = 0);
66 ~Settings();
67
68 static const GlobalSettings *globalSettings();
69
70
71 /*! Returns the localized value for key. In the desktop file keys may be postfixed by [LOCALE]. If the
72 localized value doesn't exist, returns non lokalized value. If non localized value doesn't exist, returns defaultValue.
73 LOCALE must be of the form lang_COUNTRY.ENCODING@MODIFIER, where _COUNTRY, .ENCODING, and @MODIFIER may be omitted.
74
75 If no default value is specified, a default QVariant is returned. */
76 QVariant localizedValue(const QString& key, const QVariant& defaultValue = QVariant()) const;
77
78 /*! Sets the value of setting key to value. If a localized version of the key already exists, the previous value is
79 overwritten. Otherwise, it overwrites the the un-localized version. */
80 void setLocalizedValue(const QString &key, const QVariant &value);
81
82 signals:
83 void settingsChanged();
84
85 protected:
86 bool event(QEvent *event);
87
88 protected slots:
89 /*! Called when the config file is changed */
90 virtual void fileChanged();
91
92 private slots:
93 void _fileChanged(QString path);
94
95 private:
96 Q_DISABLE_COPY(Settings)
97
98 SettingsPrivate* const d_ptr;
99 Q_DECLARE_PRIVATE(Settings)
100 };
101
102
103 class LXQtThemeData;
104
105 /*! \brief QSS theme handling */
106 class LXQT_API LXQtTheme
107 {
108 public:
109 /// Constructs a null theme.
110 LXQtTheme();
111
112 /*! Constructs an theme from the dir with the given path. If path not absolute
113 (i.e. the theme name only) the relevant dir must be found relative to the
114 $XDG_DATA_HOME + $XDG_DATA_DIRS directories. */
115 LXQtTheme(const QString &path);
116
117 /// Constructs a copy of other. This is very fast.
118 LXQtTheme(const LXQtTheme &other);
119
120 LXQtTheme& operator=(const LXQtTheme &other);
121 ~LXQtTheme();
122
123 /// Returns the name of the theme.
124 QString name() const;
125
126 QString path() const;
127
128 QString previewImage() const;
129
130 /// Returns true if this theme is valid; otherwise returns false.
131 bool isValid() const;
132
133 /*! \brief Returns StyleSheet text (not file name, but real text) of the module called module.
134 Paths in url() C/QSS functions are parsed to be real values for the theme,
135 relative to full path
136 */
137 QString qss(const QString& module) const;
138
139 /*! \brief A full path to image used as a wallpaper
140 \param screen is an ID of the screen like in Qt. -1 means default (any) screen.
141 Any other value greater than -1 is the exact screen (in dualhead).
142 In themes the index starts from 1 (ix 1 means 1st screen).
143 \retval QString a file name (including path).
144 */
145 QString desktopBackground(int screen=-1) const;
146
147 /// Returns the current lxqt theme.
148 static const LXQtTheme &currentTheme();
149
150 /// Returns the all themes found in the system.
151 static QList<LXQtTheme> allThemes();
152
153 private:
154 static LXQtTheme* mInstance;
155 QSharedDataPointer<LXQtThemeData> d;
156 };
157
158 /*!
159 A global pointer referring to the unique LXQtTheme object.
160 It is equivalent to the pointer returned by the LXQtTheme::instance() function.
161 Only one theme object can be created. !*/
162
163 #define lxqtTheme LXQtTheme::currentTheme()
164
165
166 class LXQT_API SettingsCache
167 {
168 public:
169 explicit SettingsCache(QSettings &settings);
170 explicit SettingsCache(QSettings *settings);
171 virtual ~SettingsCache() {}
172
173 void loadFromSettings();
174 void loadToSettings();
175
176 private:
177 QSettings &mSettings;
178 QHash<QString, QVariant> mCache;
179 };
180
181 class GlobalSettingsPrivate;
182
183 class GlobalSettings: public Settings
184 {
185 Q_OBJECT
186 public:
187 GlobalSettings();
188 ~GlobalSettings();
189
190 signals:
191 /// Signal emitted when the icon theme has changed.
192 void iconThemeChanged();
193
194 /// Signal emitted when the lxqt theme has changed.
195 void lxqtThemeChanged();
196
197 protected slots:
198 void fileChanged();
199
200 private:
201 GlobalSettingsPrivate* const d_ptr;
202 Q_DECLARE_PRIVATE(GlobalSettings)
203 };
204
205 } // namespace LXQt
206 #endif // LXQTSETTINGS_H