author | hgs |
Mon, 23 Aug 2010 13:50:05 +0300 | |
changeset 52 | 7e18d488ac5f |
parent 46 | c826656d6714 |
permissions | -rw-r--r-- |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
/* |
46 | 2 |
* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
5 |
* under the terms of "Eclipse Public License v1.0" |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
* |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
11 |
* |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
12 |
* Contributors: |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
* |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
14 |
* Description: |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
15 |
* |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
16 |
*/ |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
/* |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
18 |
* cxesettings.h |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
* |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
20 |
* Created on: Dec 30, 2008 |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
21 |
* |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
22 |
*/ |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
23 |
#ifndef CXESETTINGS_H_ |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
24 |
#define CXESETTINGS_H_ |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
25 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
26 |
#include <QObject> |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
27 |
#include <QString> |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
28 |
#include <QVariant> |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
29 |
|
46 | 30 |
#include "cxeerror.h" |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
31 |
#include "cxenamespace.h" |
46 | 32 |
#include "cxeexception.h" |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
33 |
|
46 | 34 |
/*! |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
35 |
* Class to access all kind of Camera Settings |
46 | 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. |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
44 |
*/ |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
45 |
class CxeSettings : public QObject |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
46 |
{ |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
47 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
48 |
Q_OBJECT |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
49 |
|
46 | 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; |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
60 |
|
46 | 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 |
||
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
107 |
|
46 | 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; |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
141 |
|
46 | 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; |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
154 |
|
46 | 155 |
protected: |
156 |
/*! |
|
157 |
* returns the setting as QVariant |
|
158 |
*/ |
|
159 |
virtual void getValue(const QString &key, QVariant &value) const = 0; |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
160 |
|
46 | 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); |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
172 |
|
46 | 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); |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
177 |
|
46 | 178 |
protected: |
179 |
CxeSettings() {} |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
180 |
|
46 | 181 |
private: |
182 |
Q_DISABLE_COPY( CxeSettings ) |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
183 |
}; |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
184 |
|
46 | 185 |
// include set/get function specializations |
186 |
#include "cxesettings.inl" |
|
187 |
||
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
188 |
#endif /*CXESETTINGS_H_*/ |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
189 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
190 |
// end of file |