|
1 /* |
|
2 * Copyright (c) 2009 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 #include <QApplication> |
|
19 |
|
20 #include "cxutils.h" |
|
21 #include "cxeengine.h" |
|
22 #include "cxecameradevicecontrol.h" |
|
23 #include "cxestillcapturecontrol.h" |
|
24 #include "cxevideocapturecontrol.h" |
|
25 |
|
26 #include "cxuiserviceprovider.h" |
|
27 #include "cxesettings.h" |
|
28 |
|
29 CxuiServiceProvider* CxuiServiceProvider::mInstance = NULL; |
|
30 |
|
31 |
|
32 const QString CXUI_SERVICE_NAME = "Camera.com.nokia.ICaptureNew"; |
|
33 |
|
34 const QString CAMERA_INDEX = "camera_index"; |
|
35 const QString QUALITY = "quality"; |
|
36 const QString ALLOW_MODE_SWITCH = "allow_mode_switch"; |
|
37 const QString ALLOW_CAMERA_SWITCH = "allow_camera_switch"; |
|
38 const QString ALLOW_QUALITY_CHANGE = "allow_quality_change"; |
|
39 |
|
40 CxuiServiceProvider::CxuiServiceProvider(CxeEngine *engine) |
|
41 : |
|
42 XQServiceProvider(CXUI_SERVICE_NAME), |
|
43 mRequestIndex(-1), |
|
44 mEngine(engine), |
|
45 mRequestedMode(Cxe::ImageMode), |
|
46 mCameraIndex(0), |
|
47 mQuality(0), |
|
48 mAllowModeSwitching(true), |
|
49 mAllowQualityChange(true), |
|
50 mAllowCameraSwitching(true) |
|
51 { |
|
52 CX_DEBUG_ENTER_FUNCTION(); |
|
53 publishAll(); |
|
54 CX_DEBUG_EXIT_FUNCTION(); |
|
55 } |
|
56 |
|
57 CxuiServiceProvider::~CxuiServiceProvider() |
|
58 { |
|
59 CX_DEBUG_ENTER_FUNCTION(); |
|
60 if (mRequestIndex != -1) { |
|
61 CX_DEBUG(("Request still active...")); |
|
62 // Complete request now, this will return error to client |
|
63 completeRequest(mRequestIndex, QString()); |
|
64 } |
|
65 CX_DEBUG_EXIT_FUNCTION(); |
|
66 } |
|
67 |
|
68 /*! |
|
69 * Creates singleton instance of service provider. |
|
70 */ |
|
71 void CxuiServiceProvider::create(CxeEngine* engine) |
|
72 { |
|
73 if (mInstance == NULL) { |
|
74 mInstance = new CxuiServiceProvider(engine); |
|
75 } |
|
76 } |
|
77 |
|
78 /*! |
|
79 * Returns singleton instance of service provider. |
|
80 * |
|
81 */ |
|
82 CxuiServiceProvider* CxuiServiceProvider::instance() |
|
83 { |
|
84 return mInstance; |
|
85 } |
|
86 |
|
87 /*! |
|
88 * Deletes singleton instance of service provider. |
|
89 */ |
|
90 void CxuiServiceProvider::destroy() |
|
91 { |
|
92 delete mInstance; |
|
93 mInstance = NULL; |
|
94 } |
|
95 |
|
96 /*! |
|
97 * Returns true if camera is started by another application. |
|
98 * |
|
99 * "Embedded" in camera means that the camera is started as a service |
|
100 * by another application using QtHighway. It doesn't necessarily |
|
101 * mean that camera is actually embedded (=window groups chained). The |
|
102 * distinction between embedded and non-embedded service is not relevant on |
|
103 * camera side, it's more meaningful to the client app. |
|
104 * |
|
105 */ |
|
106 bool CxuiServiceProvider::isCameraEmbedded() |
|
107 { |
|
108 return mInstance != NULL; |
|
109 } |
|
110 |
|
111 /*! |
|
112 * |
|
113 */ |
|
114 Cxe::CameraMode CxuiServiceProvider::requestedMode() |
|
115 { |
|
116 return mRequestedMode; |
|
117 } |
|
118 |
|
119 /*! |
|
120 * |
|
121 */ |
|
122 bool CxuiServiceProvider::allowModeSwitching() |
|
123 { |
|
124 return mAllowModeSwitching; |
|
125 } |
|
126 |
|
127 /*! |
|
128 * |
|
129 */ |
|
130 bool CxuiServiceProvider::allowQualityChange() |
|
131 { |
|
132 return mAllowQualityChange; |
|
133 } |
|
134 |
|
135 /*! |
|
136 * |
|
137 */ |
|
138 bool CxuiServiceProvider::allowCameraSwitching() |
|
139 { |
|
140 return mAllowCameraSwitching; |
|
141 } |
|
142 |
|
143 /*! |
|
144 * |
|
145 */ |
|
146 void CxuiServiceProvider::sendFilenameToClientAndExit(QString filename) |
|
147 { |
|
148 CX_DEBUG_ENTER_FUNCTION(); |
|
149 |
|
150 if (mRequestIndex == -1) { |
|
151 CX_DEBUG(("CxuiServiceProvider: no request in progress")); |
|
152 QCoreApplication::instance()->quit(); |
|
153 return; |
|
154 } |
|
155 |
|
156 connect(this, SIGNAL(returnValueDelivered()), QCoreApplication::instance(), SLOT(quit())); |
|
157 |
|
158 CX_DEBUG(("CxuiServiceProvider: completing request")); |
|
159 if (!completeRequest(mRequestIndex, QVariant(filename))) { |
|
160 // if request completion fails call quit immediately because signal is not coming |
|
161 QCoreApplication::instance()->quit(); |
|
162 } |
|
163 mRequestIndex = -1; |
|
164 |
|
165 CX_DEBUG_EXIT_FUNCTION(); |
|
166 } |
|
167 |
|
168 void CxuiServiceProvider::capture(int mode, const QVariantMap ¶meters) |
|
169 { |
|
170 CX_DEBUG_ENTER_FUNCTION(); |
|
171 |
|
172 if (mRequestIndex != -1) { |
|
173 // only one request can be active at once |
|
174 CX_DEBUG(("Request already active, ignoring")); |
|
175 CX_DEBUG_EXIT_FUNCTION(); |
|
176 return; |
|
177 } |
|
178 |
|
179 // read options from map |
|
180 if (!readParameters(parameters)) { |
|
181 CX_DEBUG_EXIT_FUNCTION(); |
|
182 return; |
|
183 } |
|
184 |
|
185 if (mCameraIndex < 0 || mCameraIndex > 1) { |
|
186 CX_DEBUG(("Invalid camera index")); |
|
187 CX_DEBUG_EXIT_FUNCTION(); |
|
188 return; |
|
189 } |
|
190 |
|
191 mRequestIndex = setCurrentRequestAsync(); |
|
192 |
|
193 mEngine->cameraDeviceControl().switchCamera(static_cast<Cxe::CameraIndex> (mCameraIndex)); |
|
194 |
|
195 |
|
196 if (mode == 0) { |
|
197 CX_DEBUG(("Image capture requested")); |
|
198 mRequestedMode = Cxe::ImageMode; |
|
199 } |
|
200 else { |
|
201 CX_DEBUG(("Video capture requested")); |
|
202 mRequestedMode = Cxe::VideoMode; |
|
203 } |
|
204 |
|
205 if (mQuality == 1) { |
|
206 // set image quality to lowest |
|
207 int imageQualityIndex = mEngine->stillCaptureControl().supportedImageQualities().size() - 1; |
|
208 CX_DEBUG(("Setting image quality to lowest, index=%d", imageQualityIndex)); |
|
209 mEngine->settings().set(CxeSettingIds::IMAGE_QUALITY, imageQualityIndex); |
|
210 |
|
211 // set video quality to lowest |
|
212 int videoQualityIndex = mEngine->videoCaptureControl().supportedVideoQualities().size() - 1; |
|
213 CX_DEBUG(("Setting video quality to lowest, index=%d", videoQualityIndex)); |
|
214 mEngine->settings().set(CxeSettingIds::VIDEO_QUALITY, videoQualityIndex); |
|
215 } else if (mQuality == 2) { |
|
216 // set image quality to highest |
|
217 CX_DEBUG(("Setting image quality to highest, index=0")); |
|
218 mEngine->settings().set(CxeSettingIds::IMAGE_QUALITY, 0); |
|
219 |
|
220 // set video quality to highest |
|
221 CX_DEBUG(("Setting video quality to highest, index=0")); |
|
222 mEngine->settings().set(CxeSettingIds::VIDEO_QUALITY, 0); |
|
223 } |
|
224 |
|
225 mEngine->initMode(mRequestedMode); |
|
226 |
|
227 |
|
228 |
|
229 CX_DEBUG_EXIT_FUNCTION(); |
|
230 } |
|
231 |
|
232 bool CxuiServiceProvider::readParameters(const QVariantMap& parameters) |
|
233 { |
|
234 |
|
235 CX_DEBUG_ENTER_FUNCTION(); |
|
236 CX_DEBUG(("Reading parameters")); |
|
237 bool ok; |
|
238 mCameraIndex = parameters[CAMERA_INDEX].toInt(&ok); |
|
239 if (!ok) { |
|
240 CX_DEBUG(("Error reading parameter %s", CAMERA_INDEX.toAscii().constData())); |
|
241 CX_DEBUG_EXIT_FUNCTION(); |
|
242 return false; |
|
243 } |
|
244 mQuality = parameters[QUALITY].toInt(&ok); |
|
245 if (!ok) { |
|
246 CX_DEBUG(("Error reading parameter %s", CAMERA_INDEX.toAscii().constData())); |
|
247 CX_DEBUG_EXIT_FUNCTION(); |
|
248 return false; |
|
249 } |
|
250 |
|
251 mAllowModeSwitching = parameters[ALLOW_MODE_SWITCH].toBool(); |
|
252 mAllowQualityChange = parameters[ALLOW_QUALITY_CHANGE].toBool(); |
|
253 mAllowCameraSwitching = parameters[ALLOW_CAMERA_SWITCH].toBool(); |
|
254 |
|
255 CX_DEBUG_EXIT_FUNCTION(); |
|
256 return true; |
|
257 } |
|
258 |