RazorAutostartEntry => LxQt::AutostartEntry
[lxde/liblxqt.git] / razorsettings.h
CommitLineData
4ef6cee9 1/* BEGIN_COMMON_COPYRIGHT_HEADER
c4af778e 2 * (c)LGPL2+
4ef6cee9 3 *
4 * Razor - a lightweight, Qt based, desktop toolset
5 * http://razor-qt.org
6 *
7 * Copyright: 2010-2011 Razor team
8 * Authors:
626f1f31 9 * Alexander Sokoloff <sokoloff.a@gmail.com>
4ef6cee9 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
c4af778e 14 * version 2.1 of the License, or (at your option) any later version.
4ef6cee9 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>
63a934d5 34#include <QtCore/QSharedDataPointer>
4ef6cee9 35
36class QEvent;
37
4ef6cee9 38class RazorSettingsPrivate;
63a934d5 39class GlobalRazorSettings;
de53bc2d 40
8966cbec 41/*! \brief User settings handling */
4ef6cee9 42class RazorSettings : public QSettings
43{
44 Q_OBJECT
45public:
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);
e6173915 61 RazorSettings(const QString &fileName, QSettings::Format format, QObject *parent = 0);
4ef6cee9 62 ~RazorSettings();
63
63a934d5 64 static const GlobalRazorSettings *globalSettings();
de53bc2d
AS
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
4ef6cee9 78signals:
c16a53ee 79 void settingsChanged();
4ef6cee9 80
0de9564b
PV
81protected:
82 bool event(QEvent *event);
83
7ee52b88
PV
84protected slots:
85 virtual void fileChanged();
4ef6cee9 86
87private:
88 Q_DISABLE_COPY(RazorSettings)
89
90 RazorSettingsPrivate* const d_ptr;
91 Q_DECLARE_PRIVATE(RazorSettings)
92};
93
94
63a934d5
AS
95class RazorThemeData;
96
8966cbec 97/*! \brief QSS theme handling */
63a934d5 98class RazorTheme
4ef6cee9 99{
4ef6cee9 100public:
63a934d5
AS
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;
4ef6cee9 117
63a934d5
AS
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 */
4ef6cee9 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
63a934d5
AS
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();
4ef6cee9 144
63a934d5 145private:
4ef6cee9 146 static RazorTheme* mInstance;
63a934d5 147 QSharedDataPointer<RazorThemeData> d;
4ef6cee9 148};
149
150/*!
151A global pointer referring to the unique RazorTheme object.
152It is equivalent to the pointer returned by the RazorTheme::instance() function.
153Only one theme object can be created. !*/
154
63a934d5
AS
155#define razorTheme RazorTheme::currentTheme()
156
4ef6cee9 157
158class RazorSettingsCache
159{
160public:
161 explicit RazorSettingsCache(QSettings &settings);
162 explicit RazorSettingsCache(QSettings *settings);
163 virtual ~RazorSettingsCache() {}
164
165 void loadFromSettings();
166 void loadToSettings();
167
168private:
169 QSettings &mSettings;
170 QHash<QString, QVariant> mCache;
171};
172
173class GlobalRazorSettingsPrivate;
174
175class GlobalRazorSettings: public RazorSettings
176{
177 Q_OBJECT
178public:
179 GlobalRazorSettings();
180 ~GlobalRazorSettings();
181
182signals:
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
7ee52b88 189protected slots:
4ef6cee9 190 void fileChanged();
191
192private:
193 GlobalRazorSettingsPrivate* const d_ptr;
194 Q_DECLARE_PRIVATE(GlobalRazorSettings)
195};
196
197#endif // RAZORSETTINGS_H