RazorAutostartEntry => LxQt::AutostartEntry
[lxde/liblxqt.git] / razorsettings.h
1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2 * (c)LGPL2+
3 *
4 * Razor - 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 RAZORSETTINGS_H
30 #define RAZORSETTINGS_H
31
32 #include <QtCore/QObject>
33 #include <QtCore/QSettings>
34 #include <QtCore/QSharedDataPointer>
35
36 class QEvent;
37
38 class RazorSettingsPrivate;
39 class GlobalRazorSettings;
40
41 /*! \brief User settings handling */
42 class RazorSettings : public QSettings
43 {
44 Q_OBJECT
45 public:
46
47 /*! \brief Constructs a RazorSettings object for accessing settings of the module called module, and with parent parent.
48 RazorSettings can be accessed using the standard interface provided by QSettings, but it also provides some convenience functions and signals.
49
50 \param module a base name of the config file. It's a name without
51 the extension. For example: if you want to open settings for
52 panel create it as RazorSettings("panel").
53 The function will create all parent directories necessary to create
54 the file.
55 \param parent It's no need to delete this class manually if it's set.
56 */
57 explicit RazorSettings(const QString& module, QObject* parent = 0);
58 //explicit RazorSettings(QObject* parent=0);
59 explicit RazorSettings(const QSettings* parentSettings, const QString& subGroup, QObject* parent=0);
60 explicit RazorSettings(const QSettings& parentSettings, const QString& subGroup, QObject* parent=0);
61 RazorSettings(const QString &fileName, QSettings::Format format, QObject *parent = 0);
62 ~RazorSettings();
63
64 static const GlobalRazorSettings *globalSettings();
65
66
67 /*! Returns the localized value for key. In the desktop file keys may be postfixed by [LOCALE]. If the
68 localized value doesn't exist, returns non lokalized value. If non localized value doesn't exist, returns defaultValue.
69 LOCALE must be of the form lang_COUNTRY.ENCODING@MODIFIER, where _COUNTRY, .ENCODING, and @MODIFIER may be omitted.
70
71 If no default value is specified, a default QVariant is returned. */
72 QVariant localizedValue(const QString& key, const QVariant& defaultValue = QVariant()) const;
73
74 /*! Sets the value of setting key to value. If a localized version of the key already exists, the previous value is
75 overwritten. Otherwise, it overwrites the the un-localized version. */
76 void setLocalizedValue(const QString &key, const QVariant &value);
77
78 signals:
79 void settingsChanged();
80
81 protected:
82 bool event(QEvent *event);
83
84 protected slots:
85 virtual void fileChanged();
86
87 private:
88 Q_DISABLE_COPY(RazorSettings)
89
90 RazorSettingsPrivate* const d_ptr;
91 Q_DECLARE_PRIVATE(RazorSettings)
92 };
93
94
95 class RazorThemeData;
96
97 /*! \brief QSS theme handling */
98 class RazorTheme
99 {
100 public:
101 /// Constructs a null theme.
102 RazorTheme();
103
104 /*! Constructs an theme from the dir with the given path. If path not absolute
105 (i.e. the theme name only) the relevant dir must be found relative to the
106 $XDG_DATA_HOME + $XDG_DATA_DIRS directories. */
107 RazorTheme(const QString &path);
108
109 /// Constructs a copy of other. This is very fast.
110 RazorTheme(const RazorTheme &other);
111
112 RazorTheme& operator=(const RazorTheme &other);
113 ~RazorTheme();
114
115 /// Returns the name of the theme.
116 QString name() const;
117
118 QString path() const;
119
120 QString previewImage() const;
121
122 /// Returns true if this theme is valid; otherwise returns false.
123 bool isValid() const;
124
125 /*! \brief Returns StyleSheet text (not file name, but real text) of the module called module.
126 Paths in url() C/QSS functions are parsed to be real values for the theme,
127 relative to full path
128 */
129 QString qss(const QString& module) const;
130
131 /*! \brief A full path to image used as a wallpaper
132 \param screen is an ID of the screen like in Qt. -1 means default (any) screen.
133 Any other value greater than -1 is the exact screen (in dualhead).
134 In themes the index starts from 1 (ix 1 means 1st screen).
135 \retval QString a file name (including path).
136 */
137 QString desktopBackground(int screen=-1) const;
138
139 /// Returns the current razor theme.
140 static const RazorTheme &currentTheme();
141
142 /// Returns the all themes found in the system.
143 static QList<RazorTheme> allThemes();
144
145 private:
146 static RazorTheme* mInstance;
147 QSharedDataPointer<RazorThemeData> d;
148 };
149
150 /*!
151 A global pointer referring to the unique RazorTheme object.
152 It is equivalent to the pointer returned by the RazorTheme::instance() function.
153 Only one theme object can be created. !*/
154
155 #define razorTheme RazorTheme::currentTheme()
156
157
158 class RazorSettingsCache
159 {
160 public:
161 explicit RazorSettingsCache(QSettings &settings);
162 explicit RazorSettingsCache(QSettings *settings);
163 virtual ~RazorSettingsCache() {}
164
165 void loadFromSettings();
166 void loadToSettings();
167
168 private:
169 QSettings &mSettings;
170 QHash<QString, QVariant> mCache;
171 };
172
173 class GlobalRazorSettingsPrivate;
174
175 class GlobalRazorSettings: public RazorSettings
176 {
177 Q_OBJECT
178 public:
179 GlobalRazorSettings();
180 ~GlobalRazorSettings();
181
182 signals:
183 /// Signal emitted when the icon theme has changed.
184 void iconThemeChanged();
185
186 /// Signal emitted when the razor theme has changed.
187 void razorThemeChanged();
188
189 protected slots:
190 void fileChanged();
191
192 private:
193 GlobalRazorSettingsPrivate* const d_ptr;
194 Q_DECLARE_PRIVATE(GlobalRazorSettings)
195 };
196
197 #endif // RAZORSETTINGS_H