js/camera/s60_camera.js
changeset 0 54063d8b0412
equal deleted inserted replaced
-1:000000000000 0:54063d8b0412
       
     1 /*
       
     2 Copyright © 2009 Nokia. All rights reserved.
       
     3 Code licensed under the BSD License:
       
     4 Software License Agreement (BSD License) Copyright © 2009 Nokia.
       
     5 All rights reserved.
       
     6 Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
       
     7 
       
     8 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
       
     9 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. 
       
    10 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. 
       
    11 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.
       
    12 
       
    13 version: 1.0
       
    14 */
       
    15 
       
    16 
       
    17 // S60 sp-based camera provider
       
    18 
       
    19 function __sp_camera_descriptor(){
       
    20   //__device_debug("sp_camera_descriptor");
       
    21   //Read-only properties
       
    22   this.interfaceName = "com.nokia.device.camera";
       
    23   this.version = "0.1";
       
    24   //Class-static properties 
       
    25 }
       
    26 
       
    27 // TBD make local to closure funcs
       
    28 var __sp_camera_start_date;
       
    29 
       
    30 function __sp_camera_instance(){
       
    31   //__device_debug("sp_camera_instance");
       
    32   //Descriptor
       
    33   this.descriptor = new __sp_camera_descriptor();
       
    34   //Core methods
       
    35   this.startCamera = __sp_startCamera;
       
    36   this.stopViewfinder = __s60_api_not_supported;
       
    37   //Extended methods
       
    38   this.takePicture = __s60_api_not_supported;
       
    39   //Private data
       
    40 }
       
    41 
       
    42 var CAMERA_APP_ID = 0x101f857a;
       
    43 
       
    44 //Apps should take care that this is not reinvoked
       
    45 //while the viewfinder is running. 
       
    46 
       
    47 function __sp_startCamera(camera_cb){
       
    48 
       
    49 	//If callback is null , then return missing argument error
       
    50     if( camera_cb == null )
       
    51         throw new DeviceError("Camera:startCamera:callback is missing", err_missing_argument);
       
    52         
       
    53 	//If the callback is not a function, then return bad type error
       
    54 	if( typeof(camera_cb) != "function" )
       
    55 	    throw new DeviceError("Camera:startCamera:callback is a non-function", err_bad_argument);
       
    56 
       
    57   var finished = function (){
       
    58     var invoker = function (arg1, arg2, arg3){
       
    59       //__device_debug("invoker with: " + camera_cb);
       
    60       var it = arg3.ReturnValue;
       
    61       var item;
       
    62       var items = new Array();
       
    63       while (( item = it.getNext()) != undefined){
       
    64           var d = new Date(Date.parse(item.FileDate));
       
    65           //__device_debug(item.FileName + " " + d );
       
    66           // Items returned in reverse date order, so stop iterating before
       
    67           // reaching initial date. (Should be able to do this more efficiently
       
    68           // with sp filter, but that doesn't seem to work right now.)
       
    69           if (d > __sp_camera_start_date) {
       
    70               var pathname = item.FileNameAndPath.replace(/\\/g, "/");
       
    71               var fileScheme = "file:///";
       
    72               //Non-patched builds don't allow file scheme TBD: change this for patched builds
       
    73               items.unshift(fileScheme + pathname);
       
    74           }
       
    75       }
       
    76       var dummyTransID = 0;
       
    77       var dummyStatusCode = 0;
       
    78       camera_cb(dummyTransID, dummyStatusCode, items);
       
    79     };
       
    80 
       
    81     
       
    82     //When camera returns, get the image(s) created
       
    83     try {
       
    84       var mso = device.getServiceObject("Service.MediaManagement", "IDataSource");
       
    85     }
       
    86     catch(e) {
       
    87       __device_handle_exception (e, "media service not available : " + e);
       
    88     }
       
    89     
       
    90     var criteria = new Object();
       
    91 	modifyObjectBaseProp(criteria);
       
    92     criteria.Type = 'FileInfo';
       
    93     criteria.Filter = new Object();
       
    94 	modifyObjectBaseProp(criteria.Filter);
       
    95     criteria.Filter.FileType = 'Image';
       
    96     //criteria.Filter.Key = 'FileDate';
       
    97     //criteria.Filter.StartRange = null;
       
    98     //criteria.Filter.EndRange = null;
       
    99     criteria.Sort = new Object();
       
   100 	modifyObjectBaseProp(criteria.Sort);
       
   101     criteria.Sort.Key = 'FileDate';
       
   102     criteria.Sort.Order = 'Descending';
       
   103     
       
   104     try {
       
   105       var rval = mso.IDataSource.GetList(criteria, invoker);
       
   106     }
       
   107     catch (e) {
       
   108       __device_handle_exception (e, "media service GetList failed: " + e);
       
   109     }
       
   110   };
       
   111 
       
   112   __sp_camera_start_date = new Date();
       
   113   __s60_start_and_wait(CAMERA_APP_ID, "", finished);
       
   114   var dummyTid = 0;
       
   115   return dummyTid;
       
   116 }
       
   117 
       
   118