|
1 /* |
|
2 * Copyright (c) 2007 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 the License "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: Defination of class CCalendarInterface |
|
15 * |
|
16 */ |
|
17 |
|
18 function __device_camera_descriptor(provider){ |
|
19 this.interfaceName = provider.interfaceName; |
|
20 this.version = provider.version; |
|
21 } |
|
22 |
|
23 //Why bother to define these methods? Because the camera |
|
24 //object defines the contract for providers! |
|
25 |
|
26 function __device_camera_startCamera(camera_cb, ErrorCallback){ |
|
27 return this.provider.startCamera(camera_cb, ErrorCallback); |
|
28 } |
|
29 |
|
30 function __device_camera_stopViewfinder(){ |
|
31 this.provider.stopViewfinder(); |
|
32 } |
|
33 |
|
34 function __device_camera_takePicture(format){ |
|
35 this.provider.takePicture(format); |
|
36 } |
|
37 |
|
38 // Private camera prototype: called from service factory |
|
39 function __device_camera(provider){ |
|
40 //Private properties |
|
41 this.provider = provider; |
|
42 //Read-only properties |
|
43 this.interfaceName = provider.descriptor.interfaceName; |
|
44 this.version = provider.descriptor.version; |
|
45 this.supportedMediaTypes = provider.supportedMediaTypes; |
|
46 this.supportedSizes = provider.supportedSizes; |
|
47 //Core methods |
|
48 this.startCamera = __device_camera_startCamera; |
|
49 this.stopViewfinder = __device_camera_stopViewfinder; |
|
50 //Extended methods |
|
51 this.takePicture = __device_camera_takePicture; |
|
52 } |
|
53 |
|
54 // Camera service interface |
|
55 |
|
56 var __device_camera_service_entry = {"name": null, |
|
57 "version": null, |
|
58 "proto": __device_camera, |
|
59 "descriptor": __device_camera_descriptor, |
|
60 "providers": [{"descriptor": __sp_camera_descriptor, "instance": __sp_camera_instance}] |
|
61 }; |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 /* |
|
68 Copyright © 2009 Nokia. All rights reserved. |
|
69 Code licensed under the BSD License: |
|
70 Software License Agreement (BSD License) Copyright © 2009 Nokia. |
|
71 All rights reserved. |
|
72 Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
|
73 |
|
74 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
|
75 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. |
|
76 Neither the name of Nokia Corporation. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Nokia Corporation. |
|
77 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
78 |
|
79 version: 1.0 |
|
80 */ |
|
81 |
|
82 |
|
83 // S60 sp-based camera provider |
|
84 |
|
85 function __sp_camera_descriptor(){ |
|
86 //__device_debug("sp_camera_descriptor"); |
|
87 //Read-only properties |
|
88 this.interfaceName = "camera"; |
|
89 if(window.__Service_Interface_Ver) |
|
90 this.version =__Service_Interface_Ver; |
|
91 else |
|
92 this.version =1.0; |
|
93 //Class-static properties |
|
94 } |
|
95 |
|
96 // TBD make local to closure funcs |
|
97 var __sp_camera_start_date; |
|
98 |
|
99 var CAMERA_APP_ID = 0x101f857a; |
|
100 |
|
101 //Apps should take care that this is not reinvoked |
|
102 //while the viewfinder is running. |
|
103 |
|
104 function __sp_startCamera(camera_cb, err_cb){ |
|
105 //If callback is null , then return missing argument error |
|
106 |
|
107 |
|
108 |
|
109 if (camera_cb == null) { |
|
110 throw new DeviceException(this.error.MISSING_ARG_ERR, "Camera:startCamera:callback is missing"); |
|
111 } |
|
112 //If the callback is not a function, then return bad type error |
|
113 if(camera_cb == undefined) |
|
114 { |
|
115 throw new DeviceException(this.error.INVALID_ARG_ERR, "Camera:startCamera:callback is a non-function" ); |
|
116 } |
|
117 |
|
118 if (typeof(camera_cb) != "function") { |
|
119 throw new DeviceException(this.error.INVALID_ARG_ERR, "Camera:startCamera:callback is a non-function" ); |
|
120 } |
|
121 |
|
122 if(err_cb) |
|
123 { |
|
124 |
|
125 if(typeof err_cb != 'function') |
|
126 { |
|
127 |
|
128 throw new DeviceException(this.error.INVALID_ARG_ERR, "Camera:startCamera:callback is invalid"); |
|
129 } |
|
130 |
|
131 } |
|
132 |
|
133 var finished = function (){ |
|
134 var invoker = function (arg1, arg2, arg3){ |
|
135 //__device_debug("invoker with: " + camera_cb); |
|
136 var it = arg3.ReturnValue; |
|
137 //arg3.ReturnValue.close(); |
|
138 var item; |
|
139 var items = []; |
|
140 |
|
141 if(arg3.ErrorCode != 0) |
|
142 { |
|
143 |
|
144 err_cb(new DeviceException(arg3.ErrorCode, "Camera:startCamera: Operation Failed")); |
|
145 |
|
146 return; |
|
147 } |
|
148 |
|
149 |
|
150 if (( item = it.getNext()) != undefined){ |
|
151 var d = new Date(Date.parse(item.FileDate)); |
|
152 //__device_debug(item.FileName + " " + d ); |
|
153 // Items returned in reverse date order, so stop iterating before |
|
154 // reaching initial date. (Should be able to do this more efficiently |
|
155 // with sp filter, but that doesn't seem to work right now.) |
|
156 if (d > __sp_camera_start_date) { |
|
157 |
|
158 var itemMap = {}; |
|
159 modifyObjectBaseProp(itemMap); |
|
160 var pathname = item.FileNameAndPath.replace(/\\/g, "/"); |
|
161 var fileScheme = "file:///"; |
|
162 //Non-patched builds don't allow file scheme TBD: change this for patched builds |
|
163 var fileUrl = ""; |
|
164 fileUrl = fileUrl.concat(fileScheme,pathname); |
|
165 itemMap.uri = fileUrl;// url |
|
166 |
|
167 var formatMap = {}; |
|
168 // modifyObjectBaseProp(formatMap); |
|
169 //var stringTemp = ""; |
|
170 //stringTemp = stringTemp.concat(item.XPixels,"X",item.YPixels); |
|
171 //formatMap.dimensions = stringTemp; |
|
172 |
|
173 formatMap.height = item.XPixels; |
|
174 formatMap.width = item.YPixels; |
|
175 |
|
176 formatMap.type = item.MimeType; |
|
177 |
|
178 itemMap.format = formatMap;//format |
|
179 |
|
180 items.unshift(itemMap); |
|
181 if (formatMap) { |
|
182 //delete formatMap.dimensions; |
|
183 //delete formatMap.mtype; |
|
184 } |
|
185 } |
|
186 |
|
187 } |
|
188 var dummyTransID = 0; |
|
189 var dummyStatusCode = 0; |
|
190 |
|
191 camera_cb(items); |
|
192 }; |
|
193 |
|
194 //When camera returns, get the image(s) created |
|
195 try { |
|
196 var mso = device.getServiceObject("Service.MediaManagement", "IDataSource"); |
|
197 } |
|
198 catch(e) { |
|
199 __device_handle_exception (e, "media service not available : " + e); |
|
200 } |
|
201 |
|
202 var criteria = {}; |
|
203 modifyObjectBaseProp(criteria); |
|
204 criteria.Type = 'FileInfo'; |
|
205 criteria.Filter = {}; |
|
206 modifyObjectBaseProp(criteria.Filter); |
|
207 criteria.Filter.FileType = 'Image'; |
|
208 //criteria.Filter.Key = 'FileDate'; |
|
209 //criteria.Filter.StartRange = null; |
|
210 //criteria.Filter.EndRange = null; |
|
211 criteria.Sort = {}; |
|
212 modifyObjectBaseProp(criteria.Sort); |
|
213 criteria.Sort.Key = 'FileDate'; |
|
214 criteria.Sort.Order = 'Descending'; |
|
215 |
|
216 try { |
|
217 var rval = mso.IDataSource.GetList(criteria, invoker); |
|
218 } |
|
219 catch (error) { |
|
220 __device_handle_exception (error, "media service GetList failed: " + error); |
|
221 } |
|
222 }; |
|
223 |
|
224 __sp_camera_start_date = new Date(); |
|
225 __s60_start_and_wait(CAMERA_APP_ID, "", finished); |
|
226 var dummyTid = 0; |
|
227 return dummyTid; |
|
228 } |
|
229 |
|
230 function __sp_supportedSizes() { |
|
231 try { |
|
232 var SysInfo = device.getServiceObject('Service.SysInfo', 'ISysInfo'); |
|
233 } |
|
234 catch(e) { |
|
235 __device_handle_exception (e, "SysInfo Service not available : " + e); |
|
236 } |
|
237 var sys_req = {}; |
|
238 modifyObjectBaseProp(sys_req); |
|
239 sys_req.Entity = "Camera"; |
|
240 sys_req.Key = "CameraProperties"; |
|
241 //Get supported Sizes |
|
242 try { |
|
243 var rval = SysInfo.ISysInfo.GetInfo(sys_req); |
|
244 if (sys_req) { |
|
245 delete sys_req.Entity; |
|
246 delete sys_req.Key; |
|
247 } |
|
248 } |
|
249 catch (error) { |
|
250 __device_handle_exception (error, "Camera : Failed to fetch supported size Info: " + error); |
|
251 } |
|
252 var returnValue = rval.ReturnValue; |
|
253 var resolutionArray = []; |
|
254 var supportedResolutions = []; |
|
255 resolutionArray = returnValue.ResolutionList; |
|
256 for(var i=0;i<resolutionArray.length;i++) { |
|
257 var stringTemp =""; |
|
258 stringTemp = stringTemp.concat(resolutionArray[i].height,"X",resolutionArray[i].width); |
|
259 supportedResolutions.push(stringTemp); |
|
260 } |
|
261 return supportedResolutions; |
|
262 } |
|
263 |
|
264 function __sp_supportedMediaTypes() { |
|
265 try { |
|
266 var SysInfo = device.getServiceObject('Service.SysInfo', 'ISysInfo'); |
|
267 } |
|
268 catch(e) { |
|
269 __device_handle_exception (e, "SysInfo Service not available : " + e); |
|
270 } |
|
271 var sys_req = {}; |
|
272 modifyObjectBaseProp(sys_req); |
|
273 sys_req.Entity = "Camera"; |
|
274 sys_req.Key = "CameraProperties"; |
|
275 //Get supported Media Types |
|
276 try { |
|
277 var rval = SysInfo.ISysInfo.GetInfo(sys_req); |
|
278 if (sys_req) { |
|
279 delete sys_req.Entity; |
|
280 delete sys_req.Key; |
|
281 } |
|
282 } |
|
283 catch (error) { |
|
284 __device_handle_exception (error, "Camera :Failed to fetch supported media type Info: " + error); |
|
285 } |
|
286 var returnValue = rval.ReturnValue; |
|
287 var supportedMimeTypes = []; |
|
288 supportedMimeTypes = returnValue.MimeTypeList; |
|
289 return supportedMimeTypes; |
|
290 } |
|
291 |
|
292 function __sp_camera_instance(){ |
|
293 //__device_debug("sp_camera_instance"); |
|
294 //Descriptor |
|
295 this.descriptor = new __sp_camera_descriptor(); |
|
296 //Read-only properties |
|
297 this.supportedMediaTypes = __sp_supportedMediaTypes(); |
|
298 this.supportedSizes = __sp_supportedSizes(); |
|
299 //Core methods |
|
300 this.startCamera = __sp_startCamera; |
|
301 this.stopViewfinder = __s60_api_not_supported; |
|
302 //Extended methods |
|
303 this.takePicture = __s60_api_not_supported; |
|
304 this.error = new DeviceException(0, "Dummy"); |
|
305 //Private data |
|
306 } |