1 /* |
|
2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 /* |
|
18 * cxesettings.h |
|
19 * |
|
20 * Created on: Dec 30, 2008 |
|
21 * |
|
22 */ |
|
23 #ifndef CXESETTINGS_H_ |
|
24 #define CXESETTINGS_H_ |
|
25 |
|
26 #include <QObject> |
|
27 #include <QString> |
|
28 #include <QVariant> |
|
29 |
|
30 #include "cxeerror.h" |
|
31 #include "cxenamespace.h" |
|
32 #include "cxeexception.h" |
|
33 |
|
34 /*! |
|
35 * Class to access all kind of Camera Settings |
|
36 * |
|
37 * There are templated get() and set() methods for accessing and modifying settings. |
|
38 * Supported types are int, qreal, QString, QVariantMap and enums. |
|
39 * |
|
40 * It is possible to monitor changes in settings, either by connecting to settingValueChanged() signal |
|
41 * or registering a slot as listener to a specific setting using listenForSetting(). With the latter |
|
42 * method you will only be notified of the change in the requested setting, as opposed to the settingValueChanged() |
|
43 * which will be emitted for any setting change. |
|
44 */ |
|
45 class CxeSettings : public QObject |
|
46 { |
|
47 |
|
48 Q_OBJECT |
|
49 |
|
50 public: |
|
51 |
|
52 |
|
53 /*! |
|
54 * Returns value of external setting item which is not owned by camera |
|
55 */ |
|
56 virtual void get(long int uid, |
|
57 unsigned long int key, |
|
58 Cxe::SettingKeyType type, |
|
59 QVariant &value) const = 0; |
|
60 |
|
61 /*! |
|
62 * Get a value of a certain setting. Template method that can be used |
|
63 * with any enumeration (well actually, anything that can be cast to from int), |
|
64 * int, QString and QVariantMap. Will throw CxeException in case of error. |
|
65 * |
|
66 * An example: |
|
67 * \code |
|
68 * try { |
|
69 * Cxe::Whitebalance wb = settings.get<Cxe::Whitebalance>(CxeSettingIds::WHITE_BALANCE); |
|
70 * catch (CxeException &e) { |
|
71 * CX_DEBUG(("Error getting white balance")); |
|
72 * } |
|
73 * \endcode |
|
74 * @param settingId Setting key |
|
75 * @return Setting value |
|
76 */ |
|
77 template<typename T> |
|
78 inline T get(const QString &key) const { |
|
79 QVariant v; |
|
80 getValue(key, v); |
|
81 return (T)v.value<int>(); |
|
82 } |
|
83 |
|
84 /*! |
|
85 * Same as above but with default value in case of error. No exceptions are thrown. |
|
86 * |
|
87 *An example: |
|
88 * \code |
|
89 * |
|
90 * Cxe::Whitebalance wb = settings.get<Cxe::Whitebalance>(CxeSettingIds::WHITE_BALANCE, Cxe::WhitebalanceAutomatic); |
|
91 * |
|
92 * \endcode |
|
93 * @param key Setting key |
|
94 * @param defaultValue Default value returned in case of error |
|
95 * @return Value of the setting |
|
96 */ |
|
97 template<typename T> |
|
98 inline T get(const QString &key, const T &defaultValue) const { |
|
99 try { |
|
100 return get<T>(key); |
|
101 } catch (CxeException &e) { |
|
102 return defaultValue; |
|
103 } |
|
104 } |
|
105 |
|
106 |
|
107 |
|
108 /*! |
|
109 * Set a value of a certain setting. Template method that can be used |
|
110 * with any enumeration (well actually, anything that can be cast to from int), |
|
111 * int, QString and QVariantMap. |
|
112 * |
|
113 * An example: |
|
114 * \code |
|
115 * try { |
|
116 * Cxe::Whitebalance wb = Cxe::WhiteBalanceAutomatic; |
|
117 * settings.get<Cxe::Whitebalance>(CxeSettingIds::WHITE_BALANCE, wb); |
|
118 * catch (CxeException &e) { |
|
119 * CX_DEBUG(("Error setting white balance")); |
|
120 * } |
|
121 * \endcode |
|
122 * @param settingId Setting key |
|
123 * @param value Setting value |
|
124 */ |
|
125 template<typename T> |
|
126 inline void set(const QString &key, const T &value) { |
|
127 QVariant v; |
|
128 v.setValue((int)value); |
|
129 setValue(key, v); |
|
130 } |
|
131 |
|
132 /*! |
|
133 * Resets settings to default values. |
|
134 */ |
|
135 virtual void reset() = 0; |
|
136 |
|
137 /*! |
|
138 * Get value of variation setting. |
|
139 */ |
|
140 virtual CxeError::Id getVariationValue(const QString &key, QVariant &value) = 0; |
|
141 |
|
142 /*! |
|
143 * Add listener for changes in one setting. When the value of the setting changes, the given |
|
144 * slot is invoked on given object. |
|
145 * |
|
146 * @param settingKey Setting to listen to |
|
147 * @param target Object that the slot will be invoked for |
|
148 * @param slot Slot that will be invoked. The slot can have either of these two signatures: |
|
149 * slotName(const QVariant&) only new value of setting is passed as parameter |
|
150 * slotName(const QString&, const QVariant&) both setting key and new value are passed as parameter |
|
151 * @return boolean to indicate success |
|
152 */ |
|
153 virtual bool listenForSetting(const QString &settingKey, QObject *target, const char *slot) = 0; |
|
154 |
|
155 protected: |
|
156 /*! |
|
157 * returns the setting as QVariant |
|
158 */ |
|
159 virtual void getValue(const QString &key, QVariant &value) const = 0; |
|
160 |
|
161 /*! |
|
162 * Set new value for the given key |
|
163 */ |
|
164 virtual void setValue(const QString &key, const QVariant &newValue) = 0; |
|
165 |
|
166 signals: |
|
167 |
|
168 /*! |
|
169 * to notify engine and ui components for a change in a setting value |
|
170 */ |
|
171 void settingValueChanged(const QString &key, QVariant newValue); |
|
172 |
|
173 /*! |
|
174 * to notify engine and ui components for a change in a setting value |
|
175 */ |
|
176 void settingValueChanged(long int uid, unsigned long int key, QVariant value); |
|
177 |
|
178 protected: |
|
179 CxeSettings() {} |
|
180 |
|
181 private: |
|
182 Q_DISABLE_COPY( CxeSettings ) |
|
183 }; |
|
184 |
|
185 // include set/get function specializations |
|
186 #include "cxesettings.inl" |
|
187 |
|
188 #endif /*CXESETTINGS_H_*/ |
|
189 |
|
190 // end of file |
|