org.symbian.tools.wrttools/libraries/phonegap.js
author Eugene Ostroukhov <eugeneo@symbian.org>
Mon, 19 Apr 2010 18:03:51 -0700
changeset 310 e9484be98cfe
child 321 b99b8311285c
permissions -rw-r--r--
UI to add libraries was introduced
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     1
if (typeof(DeviceInfo) != 'object')
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     2
    DeviceInfo = {};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     3
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     4
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     5
 * This represents the PhoneGap API itself, and provides a global namespace for accessing
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     6
 * information about the state of PhoneGap.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     7
 * @class
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     8
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     9
PhoneGap = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    10
    queue: {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    11
        ready: true,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    12
        commands: [],
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    13
        timer: null
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    14
    },
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    15
    _constructors: []
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    16
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    17
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    18
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    19
 * Boolean flag indicating if the PhoneGap API is available and initialized.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    20
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    21
PhoneGap.available = DeviceInfo.uuid != undefined;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    22
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    23
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    24
 * Execute a PhoneGap command in a queued fashion, to ensure commands do not
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    25
 * execute with any race conditions, and only run when PhoneGap is ready to
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    26
 * recieve them.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    27
 * @param {String} command Command to be run in PhoneGap, e.g. "ClassName.method"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    28
 * @param {String[]} [args] Zero or more arguments to pass to the method
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    29
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    30
PhoneGap.exec = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    31
    PhoneGap.queue.commands.push(arguments);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    32
    if (PhoneGap.queue.timer == null)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    33
        PhoneGap.queue.timer = setInterval(PhoneGap.run_command, 10);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    34
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    35
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    36
 * Internal function used to dispatch the request to PhoneGap.  This needs to be implemented per-platform to
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    37
 * ensure that methods are called on the phone in a way appropriate for that device.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    38
 * @private
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    39
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    40
PhoneGap.run_command = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    41
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    42
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    43
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    44
 * This class contains acceleration information
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    45
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    46
 * @param {Number} x The force applied by the device in the x-axis.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    47
 * @param {Number} y The force applied by the device in the y-axis.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    48
 * @param {Number} z The force applied by the device in the z-axis.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    49
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    50
function Acceleration(x, y, z) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    51
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    52
	 * The force applied by the device in the x-axis.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    53
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    54
	this.x = x;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    55
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    56
	 * The force applied by the device in the y-axis.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    57
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    58
	this.y = y;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    59
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    60
	 * The force applied by the device in the z-axis.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    61
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    62
	this.z = z;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    63
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    64
	 * The time that the acceleration was obtained.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    65
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    66
	this.timestamp = new Date().getTime();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    67
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    68
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    69
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    70
 * This class specifies the options for requesting acceleration data.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    71
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    72
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    73
function AccelerationOptions() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    74
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    75
	 * The timeout after which if acceleration data cannot be obtained the errorCallback
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    76
	 * is called.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    77
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    78
	this.timeout = 10000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    79
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    80
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    81
 * This class provides access to device accelerometer data.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    82
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    83
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    84
function Accelerometer() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    85
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    86
	 * The last known acceleration.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    87
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    88
	this.lastAcceleration = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    89
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    90
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    91
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    92
 * Asynchronously aquires the current acceleration.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    93
 * @param {Function} successCallback The function to call when the acceleration
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    94
 * data is available
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    95
 * @param {Function} errorCallback The function to call when there is an error 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    96
 * getting the acceleration data.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    97
 * @param {AccelerationOptions} options The options for getting the accelerometer data
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    98
 * such as timeout.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    99
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   100
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   101
Accelerometer.prototype.getCurrentAcceleration = function(successCallback, errorCallback, options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   102
	// If the acceleration is available then call success
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   103
	// If the acceleration is not available then call error
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   104
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   105
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   106
		alert(1);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   107
		if (!this.serviceObj) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   108
			this.serviceObj = this.getServiceObj();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   109
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   110
		if (this.serviceObj == null) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   111
			throw {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   112
				name: "DeviceErr",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   113
				message: "Could not initialize service object"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   114
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   115
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   116
		//get the sensor channel
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   117
		var SensorParams = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   118
			SearchCriterion: "AccelerometerAxis"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   119
		};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   120
		var returnvalue = this.serviceObj.ISensor.FindSensorChannel(SensorParams);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   121
		alert(2);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   122
		var error = returnvalue["ErrorCode"];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   123
		var errmsg = returnvalue["ErrorMessage"];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   124
		if (!(error == 0 || error == 1012)) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   125
			var ex = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   126
				name: "Unable to find Sensor Channel: " + error,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   127
				message: errmsg
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   128
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   129
			throw ex;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   130
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   131
		var channelInfoMap = returnvalue["ReturnValue"][0];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   132
		var criteria = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   133
			ChannelInfoMap: channelInfoMap,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   134
			ListeningType: "ChannelData"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   135
		};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   136
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   137
		if (typeof(successCallback) != 'function') 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   138
			successCallback = function(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   139
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   140
		if (typeof(errorCallback) != 'function') 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   141
			errorCallback = function(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   142
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   143
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   144
		this.success_callback = successCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   145
		this.error_callback = errorCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   146
		//create a closure to persist this instance of Accelerometer into the RegisterForNofication callback
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   147
		var obj = this;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   148
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   149
		// TODO: this call crashes WRT, but there is no other way to read the accel sensor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   150
		// http://discussion.forum.nokia.com/forum/showthread.php?t=182151&highlight=memory+leak
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   151
		this.serviceObj.ISensor.RegisterForNotification(criteria, function(transId, eventCode, result){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   152
			try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   153
				alert(10);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   154
				var criteria = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   155
					TransactionID: transId
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   156
				};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   157
				obj.serviceObj.ISensor.Cancel(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   158
				
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   159
				var accel = new Acceleration(result.ReturnValue.XAxisData, result.ReturnValue.YAxisData, result.ReturnValue.ZAxisData);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   160
				Accelerometer.lastAcceleration = accel;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   161
				
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   162
				obj.success_callback(accel);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   163
				
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   164
			} 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   165
			catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   166
				obj.serviceObj.ISensor.Cancel(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   167
				obj.error_callback(ex);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   168
			}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   169
			
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   170
		});
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   171
		alert(4);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   172
	} catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   173
		alert(5);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   174
		errorCallback(ex);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   175
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   176
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   177
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   178
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   179
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   180
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   181
 * Asynchronously aquires the acceleration repeatedly at a given interval.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   182
 * @param {Function} successCallback The function to call each time the acceleration
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   183
 * data is available
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   184
 * @param {Function} errorCallback The function to call when there is an error 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   185
 * getting the acceleration data.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   186
 * @param {AccelerationOptions} options The options for getting the accelerometer data
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   187
 * such as timeout.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   188
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   189
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   190
Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallback, options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   191
	this.getCurrentAcceleration(successCallback, errorCallback, options);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   192
	// TODO: add the interval id to a list so we can clear all watches
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   193
 	var frequency = (options != undefined)? options.frequency : 10000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   194
	return setInterval(function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   195
		navigator.accelerometer.getCurrentAcceleration(successCallback, errorCallback, options);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   196
	}, frequency);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   197
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   198
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   199
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   200
 * Clears the specified accelerometer watch.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   201
 * @param {String} watchId The ID of the watch returned from #watchAcceleration.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   202
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   203
Accelerometer.prototype.clearWatch = function(watchId) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   204
	clearInterval(watchId);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   205
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   206
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   207
//gets the Acceleration Service Object from WRT
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   208
Accelerometer.prototype.getServiceObj = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   209
	var so;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   210
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   211
    try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   212
        so = device.getServiceObject("Service.Sensor", "ISensor");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   213
    } catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   214
		throw {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   215
			name: "DeviceError",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   216
			message: "Could not initialize accel service object (" + ex.name + ": " + ex.message + ")"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   217
		};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   218
    }		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   219
	return so;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   220
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   221
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   222
if (typeof navigator.accelerometer == "undefined") navigator.accelerometer = new Accelerometer();/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   223
 * This class provides access to the device camera.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   224
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   225
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   226
function Camera() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   227
	this.success_callback = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   228
	this.error_callback = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   229
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   230
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   231
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   232
 * We use the Platform Services 2.0 API here. So we must include a portion of the
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   233
 * PS 2.0 source code (camera API). 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   234
 * @param {Function} successCallback
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   235
 * @param {Function} errorCallback
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   236
 * @param {Object} options
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   237
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   238
Camera.prototype.getPicture = function(successCallback, errorCallback, options){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   239
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   240
		if (!this.serviceObj) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   241
			this.serviceObj = com.nokia.device.load("", "com.nokia.device.camera", "");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   242
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   243
		if (!this.serviceObj) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   244
			throw {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   245
				name: "CameraError",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   246
				message: "could not load camera service"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   247
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   248
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   249
		var obj = this;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   250
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   251
		obj.success_callback = successCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   252
		obj.error_callback = errorCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   253
		this.serviceObj.startCamera( function(transactionID, errorCode, outPut) { 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   254
			//outPut should be an array of image urls (local), or an error code
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   255
			if (errorCode == 0) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   256
				obj.success_callback(outPut);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   257
			}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   258
			else {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   259
				obj.error_callback({
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   260
					name: "CameraError",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   261
					message: errorCode
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   262
				});
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   263
			}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   264
		});
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   265
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   266
	} catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   267
		errorCallback.call(ex);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   268
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   269
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   270
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   271
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   272
if (typeof navigator.camera == "undefined") navigator.camera = new Camera();/*
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   273
Copyright © 2009 Nokia. All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   274
Code licensed under the BSD License:
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   275
Software License Agreement (BSD License) Copyright © 2009 Nokia.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   276
All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   277
Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   278
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   279
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   280
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. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   281
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. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   282
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.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   283
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   284
version: 1.0
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   285
*/
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   286
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   287
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   288
// utility.js
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   289
//
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   290
// This file contains some utility functions for S60 providers
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   291
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   292
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   293
// Start an application and wait for it to exit
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   294
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   295
//TBD: Get rid of this global, use closures instead
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   296
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   297
DeviceError.prototype = new Error(); //inheritance occurs here
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   298
DeviceError.prototype.constructor = DeviceError; //If this not present then, it uses default constructor of Error
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   299
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   300
//constructor for DeviceError.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   301
function DeviceError(message,code) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   302
{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   303
	this.toString = concatenate;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   304
	this.code = code;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   305
	this.name = "DeviceException";//we can even overwrite default name "Error"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   306
	this.message=message; 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   307
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   308
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   309
function concatenate()
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   310
{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   311
	return (this.name+":"+" "+this.message+" "+this.code);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   312
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   313
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   314
function splitErrorMessage(errmessage)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   315
{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   316
	if(errmessage.search(/:/)!=-1)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   317
	{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   318
		if((errmessage.split(":").length)==2)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   319
		{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   320
			return errmessage.split(":")[1];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   321
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   322
		if((errmessage.split(":").length)>2)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   323
		{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   324
			return errmessage.split(":")[2];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   325
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   326
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   327
	return errmessage;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   328
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   329
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   330
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   331
var __s60_start_and_wait_cb;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   332
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   333
function __s60_on_app_exit(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   334
  widget.onshow = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   335
  if(__s60_start_and_wait_cb != null){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   336
    __s60_start_and_wait_cb();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   337
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   338
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   339
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   340
function __s60_on_app_start(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   341
  widget.onhide = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   342
  widget.onshow = __s60_on_app_exit;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   343
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   344
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   345
// This function cannot actually force JS to wait,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   346
// but it does supply a callback the apps can use
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   347
// to continue processing on return from the app.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   348
// Apps should take care not to reinvoke this and
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   349
// should be careful about any other processing
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   350
// that might happen while the app is running.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   351
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   352
function __s60_start_and_wait(id, args, app_exit_cb){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   353
  __s60_start_and_wait_cb = app_exit_cb;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   354
  widget.onhide = __s60_on_app_start;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   355
  widget.openApplication(id, args);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   356
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   357
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   358
function __s60_api_not_supported(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   359
  throw(err_ServiceNotSupported);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   360
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   361
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   362
function __s60_enumerate_object(object, namespace, func, param){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   363
    var key;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   364
    for(key in object){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   365
       
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   366
        var propname;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   367
       	if(namespace){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   368
	    propname = namespace + "." + key;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   369
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   370
	else{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   371
	    propname = key;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   372
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   373
        var value = object[key];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   374
        if(typeof value == "object"){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   375
	  __s60_enumerate_object(value, propname, func, param);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   376
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   377
	else {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   378
	  func(propname,value, param);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   379
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   380
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   381
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   382
/*
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   383
Copyright © 2009 Nokia. All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   384
Code licensed under the BSD License:
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   385
Software License Agreement (BSD License) Copyright © 2009 Nokia.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   386
All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   387
Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   388
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   389
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   390
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. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   391
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. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   392
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.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   393
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   394
version: 1.0
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   395
*/
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   396
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   397
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   398
var __device_debug_on__ = true;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   399
var err_missing_argument = 1003;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   400
var event_cancelled = 3;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   401
var err_bad_argument = 1002;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   402
var err_InvalidService_Argument = 1000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   403
var err_ServiceNotReady = 1006;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   404
var err_ServiceNotSupported = 1004;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   405
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   406
function __device_debug(text){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   407
  //if(__device_debug_on__) alert(text);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   408
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   409
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   410
function __device_handle_exception(e, text){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   411
	__device_debug(text);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   412
	throw(e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   413
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   414
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   415
function __device_typeof(value)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   416
{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   417
	// First check to see if the value is undefined.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   418
	if (value == undefined) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   419
        return "undefined";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   420
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   421
	// Check for objects created with the "new" keyword.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   422
	if (value instanceof Object) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   423
		// Check whether it's a string object.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   424
		if (value instanceof String) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   425
			return "String";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   426
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   427
		// Check whether it's an array object/array literal.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   428
		else 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   429
			if (value instanceof Array) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   430
				return "Array";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   431
			}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   432
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   433
	// dealing with a literal.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   434
		if (typeof value) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   435
			if (typeof value == "object") {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   436
				if (typeof value == "object" && !value) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   437
					return "null";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   438
				}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   439
			}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   440
           // if not null check for other types
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   441
			
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   442
				// Check if it's a string literal.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   443
			else if (typeof value == "string") {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   444
					return "string";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   445
				}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   446
		}	 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   447
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   448
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   449
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   450
// The top-level service object. It would be nice to use a namespace here 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   451
// (com.nokia.device.service), but emulating namespaces still allows name clashes.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   452
/*
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   453
var sp_device = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   454
        //services: null; // TBD: Make the services list a member of this object?
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   455
	load: __device_service_load,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   456
        listServices: __device_service_list,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   457
        listInterfaces: __device_service_interfaces,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   458
        version: "0.1",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   459
        info: "device prototype"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   460
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   461
*/
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   462
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   463
if(undefined == com)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   464
    var com={};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   465
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   466
if( typeof com != "object")
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   467
    throw("com defined as non object");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   468
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   469
if(undefined == com.nokia)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   470
    com.nokia = {};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   471
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   472
if( typeof com.nokia != "object")
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   473
    throw("com.nokia defined as non object");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   474
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   475
if(undefined == com.nokia.device)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   476
    com.nokia.device = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   477
        load: __device_service_load,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   478
        listServices: __device_service_list,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   479
        listInterfaces: __device_service_interfaces,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   480
        version: "0.1",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   481
        info: "device prototype"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   482
        };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   483
else
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   484
    throw("com.nokia.device already defined");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   485
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   486
com.nokia.device.SORT_ASCENDING = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   487
com.nokia.device.SORT_DESCENDING = 1;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   488
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   489
com.nokia.device.SORT_BY_DATE = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   490
com.nokia.device.SORT_BY_SENDER = 1;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   491
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   492
com.nokia.device.STATUS_READ = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   493
com.nokia.device.STATUS_UNREAD = 1;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   494
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   495
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   496
// Configure the services offered.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   497
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   498
var __device_services_inited = false;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   499
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   500
var __device_services = [
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   501
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   502
  // For now, the only service is the base "device"" service
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   503
  {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   504
    "name":"com.nokia.device",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   505
    "version": 0.1, 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   506
    "interfaces": []
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   507
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   508
];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   509
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   510
// Initialize the configured services.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   511
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   512
function __device_services_init(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   513
  if(__device_services_inited){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   514
    return;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   515
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   516
  __device_services_inited = true;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   517
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   518
  // Get the service-specific service entries. Note that these
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   519
  // need to be individually wrapped by try/catch blocks so that the
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   520
  // interpreter gracefully handles missing services. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   521
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   522
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   523
    __device_services[0].interfaces.push(__device_geolocation_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   524
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   525
    __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   526
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   527
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   528
    __device_services[0].interfaces.push(__device_camera_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   529
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   530
    __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   531
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   532
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   533
    __device_services[0].interfaces.push(__device_media_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   534
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   535
//    __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   536
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   537
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   538
    __device_services[0].interfaces.push(__device_contacts_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   539
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   540
//    __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   541
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   542
 try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   543
    __device_services[0].interfaces.push(__device_messaging_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   544
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   545
      __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   546
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   547
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   548
    __device_services[0].interfaces.push(__device_calendar_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   549
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   550
      __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   551
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   552
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   553
    __device_services[0].interfaces.push(__device_landmarks_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   554
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   555
      __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   556
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   557
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   558
    __device_services[0].interfaces.push(__device_event_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   559
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   560
      __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   561
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   562
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   563
    __device_services[0].interfaces.push(__device_sysinfo_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   564
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   565
      __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   566
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   567
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   568
    __device_services[0].interfaces.push(__device_sensors_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   569
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   570
      __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   571
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   572
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   573
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   574
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   575
function __device_get_implementation(i){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   576
  //__device_debug("get_implementation: " + i);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   577
  return  new i.proto(new(i.providers[0].instance));
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   578
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   579
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   580
function __device_get_descriptor(i){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   581
  //__device_debug("get_descriptor: " + i);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   582
  return new i.descriptor(new(i.providers[0].descriptor));
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   583
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   584
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   585
function __device_get_interface(s, interfaceName, version){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   586
  //__device_debug("get_interface: " + s + " " + interfaceName);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   587
  var i = s.interfaces;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   588
  if((interfaceName == null) || (interfaceName == '')){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   589
    // Interface name not specified, get first interface, ignoring version
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   590
    return __device_get_implementation(i[0]);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   591
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   592
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   593
  // Find first match of name and version
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   594
  for (var d in i){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   595
  
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   596
    if(i[d].name == null){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   597
      __device_update_descriptor(i[d]);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   598
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   599
    if(i[d].name == undefined){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   600
      continue;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   601
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   602
    if (i[d].name == interfaceName){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   603
      // Match version if specified
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   604
      if ((version == null) || (version == '') || (i[d].version >= version)){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   605
	return __device_get_implementation(i[d]);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   606
      }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   607
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   608
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   609
  return null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   610
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   611
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   612
// Implemention of the load method
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   613
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   614
function __device_service_load(serviceName, interfaceName, version){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   615
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   616
  __device_services_init();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   617
  
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   618
  // Service name is specified
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   619
   if ((serviceName != null) && (serviceName != '') &&(serviceName != "*")){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   620
    for(var s in __device_services){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   621
      if (serviceName == __device_services[s].name){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   622
	return __device_get_interface(__device_services[s], interfaceName, version);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   623
      }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   624
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   625
  // Service name not specified, get first implementation 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   626
  } else {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   627
    //__device_debug("Trying to get interface implementations: ");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   628
    for(var s in __device_services){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   629
      //__device_debug("service_load: " + s + ":" +  __device_services[s].name + ": " + interfaceName);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   630
      var i = __device_get_interface(__device_services[s], interfaceName, version);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   631
      if (i != null){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   632
	return i;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   633
      }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   634
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   635
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   636
  return null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   637
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   638
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   639
// Lazily fill in the descriptor table
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   640
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   641
function __device_update_descriptor(i){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   642
  var d = __device_get_descriptor(i);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   643
  i.name = d.interfaceName;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   644
  i.version = d.version;  
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   645
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   646
// Get an array of interface descriptors for a service
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   647
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   648
function __device_interface_list(s){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   649
  var retval = new Array();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   650
  for(var i in s.interfaces){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   651
    if(s.interfaces[i].name == null){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   652
      __device_update_descriptor(s.interfaces[i]);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   653
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   654
    if(s.interfaces[i].name == undefined){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   655
      continue;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   656
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   657
    retval[i] = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   658
    retval[i].name = s.interfaces[i].name;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   659
    retval[i].version = s.interfaces[i].version;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   660
  }  
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   661
  return retval;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   662
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   663
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   664
// Get a service description
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   665
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   666
function __device_service_descriptor(s){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   667
  this.name = s.name;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   668
  this.version = s.version;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   669
  this.interfaces = __device_interface_list(s);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   670
  this.toString = __device_service_descriptor_to_string;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   671
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   672
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   673
function __device_service_descriptor_to_string(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   674
  var is = "\nInterfaces(s): ";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   675
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   676
  for (i in this.interfaces){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   677
    is += "\n" + this.interfaces[i].name + " " + this.interfaces[0].version;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   678
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   679
  return ("Service: " + this.name + is);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   680
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   681
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   682
// Implement the listServices method 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   683
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   684
function __device_service_list(serviceName, interfaceName, version){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   685
  //__device_debug("__device_service_list: " + serviceName + " " + interfaceName);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   686
  __device_services_init();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   687
  var retval = new Array();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   688
  var n = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   689
  
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   690
  //Treat empty service and interface names as wildcards
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   691
  if ((serviceName == null)|| (serviceName == '')/* || (serviceName == undefined)*/){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   692
    serviceName = ".*"; 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   693
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   694
  if ((interfaceName == null) || (interfaceName == '') /*|| (serviceName == undefined)*/){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   695
    interfaceName = ".*";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   696
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   697
 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   698
  if ((typeof serviceName != "string") || (typeof interfaceName != "string")) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   699
  	return retval;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   700
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   701
  
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   702
  // This method does regular expression matching of service and interface
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   703
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   704
  var sregx = new RegExp(serviceName);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   705
  var iregx = new RegExp(interfaceName);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   706
 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   707
  for(var s in __device_services){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   708
   //__device_debug (serviceName + "==" + __device_services[s].name + "?:" + sregx.test(__device_services[s].name));
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   709
    if (sregx.test(__device_services[s].name)){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   710
      // Find the first matching interface 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   711
        
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   712
      for(var i in __device_services[s].interfaces){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   713
        if(__device_services[s].interfaces[i].name == null){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   714
          __device_update_descriptor(__device_services[s].interfaces[i]);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   715
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   716
        if(__device_services[s].interfaces[i].name == undefined){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   717
	  continue;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   718
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   719
	//__device_debug (interfaceName + "==" + __device_services[s].interfaces[i].name + "?:" + iregx.test(__device_services[s].interfaces[i].name));
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   720
	if (iregx.test(__device_services[s].interfaces[i].name)){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   721
	  if ((version == null) || (version == '') || (__device_services[s].interfaces[i].version >= version)){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   722
            // An interface matched, we're done.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   723
            retval[n] = new __device_service_descriptor(__device_services[s]);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   724
            break; 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   725
	  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   726
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   727
      }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   728
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   729
    ++n;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   730
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   731
  return retval;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   732
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   733
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   734
// Implement the listInterfaces method
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   735
    
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   736
function __device_service_interfaces(serviceName){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   737
  __device_services_init();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   738
  if(serviceName==null||serviceName==undefined||serviceName==''){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   739
  	throw new DeviceError("Framework: listInterfaces: serviceName is missing", err_missing_argument);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   740
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   741
  for (var s in __device_services){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   742
    if(__device_services[s].name == serviceName){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   743
      return __device_interface_list(__device_services[s]);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   744
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   745
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   746
  return null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   747
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   748
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   749
function modifyObjectBaseProp(obj){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   750
  for (pro in obj) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   751
    if(typeof obj[pro] == "function" )
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   752
      obj[pro] = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   753
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   754
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   755
/*
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   756
Copyright © 2009 Nokia. All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   757
Code licensed under the BSD License:
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   758
Software License Agreement (BSD License) Copyright © 2009 Nokia.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   759
All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   760
Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   761
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   762
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   763
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. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   764
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. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   765
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.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   766
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   767
version: 1.0
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   768
*/
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   769
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   770
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   771
// S60 sp-based camera provider
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   772
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   773
function __sp_camera_descriptor(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   774
  //__device_debug("sp_camera_descriptor");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   775
  //Read-only properties
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   776
  this.interfaceName = "com.nokia.device.camera";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   777
  this.version = "0.1";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   778
  //Class-static properties 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   779
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   780
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   781
// TBD make local to closure funcs
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   782
var __sp_camera_start_date;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   783
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   784
function __sp_camera_instance(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   785
  //__device_debug("sp_camera_instance");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   786
  //Descriptor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   787
  this.descriptor = new __sp_camera_descriptor();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   788
  //Core methods
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   789
  this.startCamera = __sp_startCamera;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   790
  this.stopViewfinder = __s60_api_not_supported;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   791
  //Extended methods
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   792
  this.takePicture = __s60_api_not_supported;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   793
  //Private data
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   794
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   795
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   796
var CAMERA_APP_ID = 0x101f857a;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   797
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   798
//Apps should take care that this is not reinvoked
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   799
//while the viewfinder is running. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   800
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   801
function __sp_startCamera(camera_cb){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   802
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   803
	//If callback is null , then return missing argument error
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   804
    if( camera_cb == null )
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   805
        throw new DeviceError("Camera:startCamera:callback is missing", err_missing_argument);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   806
        
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   807
	//If the callback is not a function, then return bad type error
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   808
	if( typeof(camera_cb) != "function" )
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   809
	    throw new DeviceError("Camera:startCamera:callback is a non-function", err_bad_argument);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   810
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   811
  var finished = function (){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   812
    var invoker = function (arg1, arg2, arg3){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   813
      //__device_debug("invoker with: " + camera_cb);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   814
      var it = arg3.ReturnValue;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   815
      var item;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   816
      var items = new Array();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   817
      while (( item = it.getNext()) != undefined){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   818
          var d = new Date(Date.parse(item.FileDate));
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   819
          //__device_debug(item.FileName + " " + d );
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   820
          // Items returned in reverse date order, so stop iterating before
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   821
          // reaching initial date. (Should be able to do this more efficiently
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   822
          // with sp filter, but that doesn't seem to work right now.)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   823
          if (d > __sp_camera_start_date) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   824
              var pathname = item.FileNameAndPath.replace(/\\/g, "/");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   825
              var fileScheme = "file:///";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   826
              //Non-patched builds don't allow file scheme TBD: change this for patched builds
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   827
              items.unshift(fileScheme + pathname);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   828
          }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   829
      }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   830
      var dummyTransID = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   831
      var dummyStatusCode = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   832
      camera_cb(dummyTransID, dummyStatusCode, items);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   833
    };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   834
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   835
    
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   836
    //When camera returns, get the image(s) created
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   837
    try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   838
      var mso = device.getServiceObject("Service.MediaManagement", "IDataSource");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   839
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   840
    catch(e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   841
      __device_handle_exception (e, "media service not available : " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   842
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   843
    
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   844
    var criteria = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   845
	modifyObjectBaseProp(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   846
    criteria.Type = 'FileInfo';
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   847
    criteria.Filter = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   848
	modifyObjectBaseProp(criteria.Filter);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   849
    criteria.Filter.FileType = 'Image';
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   850
    //criteria.Filter.Key = 'FileDate';
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   851
    //criteria.Filter.StartRange = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   852
    //criteria.Filter.EndRange = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   853
    criteria.Sort = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   854
	modifyObjectBaseProp(criteria.Sort);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   855
    criteria.Sort.Key = 'FileDate';
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   856
    criteria.Sort.Order = 'Descending';
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   857
    
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   858
    try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   859
      var rval = mso.IDataSource.GetList(criteria, invoker);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   860
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   861
    catch (e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   862
      __device_handle_exception (e, "media service GetList failed: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   863
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   864
  };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   865
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   866
  __sp_camera_start_date = new Date();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   867
  __s60_start_and_wait(CAMERA_APP_ID, "", finished);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   868
  var dummyTid = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   869
  return dummyTid;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   870
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   871
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   872
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   873
/*
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   874
Copyright © 2009 Nokia. All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   875
Code licensed under the BSD License:
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   876
Software License Agreement (BSD License) Copyright © 2009 Nokia.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   877
All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   878
Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   879
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   880
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   881
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. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   882
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. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   883
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.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   884
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   885
version: 1.0
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   886
*/
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   887
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   888
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   889
// Camera service interface
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   890
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   891
var __device_camera_service_entry =  {"name": null, 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   892
					 "version": null,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   893
					 "proto": __device_camera,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   894
					 "descriptor": __device_camera_descriptor,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   895
					 "providers": [{"descriptor": __sp_camera_descriptor, "instance": __sp_camera_instance}]
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   896
					};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   897
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   898
function __device_camera_descriptor(provider){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   899
  this.interfaceName = provider.interfaceName;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   900
  this.version = provider.version;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   901
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   902
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   903
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   904
// Private camera  prototype: called from service factory
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   905
function __device_camera(provider){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   906
  //Private properties
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   907
  this.provider = provider;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   908
  //Read-only properties
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   909
  this.interfaceName = provider.descriptor.interfaceName;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   910
  this.version = provider.descriptor.version;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   911
 // this.supportedMediaTypes = provider.supportedMediaTypes;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   912
 // this.supportedSizes = provider.supportedSizes;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   913
  //Core methods
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   914
  this.startCamera = __device_camera_startCamera;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   915
  this.stopViewfinder = __device_camera_stopViewfinder;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   916
  //Extended methods
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   917
  this.takePicture = __device_camera_takePicture;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   918
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   919
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   920
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   921
//Why bother to define these methods? Because the camera
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   922
//object defines the contract for providers!
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   923
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   924
function __device_camera_startCamera(camera_cb){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   925
  return this.provider.startCamera(camera_cb);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   926
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   927
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   928
function __device_camera_stopViewfinder(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   929
  this.provider.stopViewfinder();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   930
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   931
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   932
function __device_camera_takePicture(format){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   933
  this.provider.takePicture(format);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   934
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   935
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   936
 * This class provides access to the device contacts.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   937
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   938
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   939
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   940
function Contacts() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   941
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   942
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   943
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   944
function Contact() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   945
	this.id = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   946
	this.name = { 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   947
		formatted: "",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   948
		givenName: "",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   949
		familyName: ""
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   950
	};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   951
    this.phones = [];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   952
    this.emails = [];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   953
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   954
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   955
Contact.prototype.displayName = function()
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   956
{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   957
    // TODO: can be tuned according to prefs
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   958
	return this.givenName + " " + this.familyName;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   959
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   960
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   961
/*
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   962
 * @param {ContactsFilter} filter Object with filter properties. filter.name only for now.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   963
 * @param {function} successCallback Callback function on success
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   964
 * @param {function} errorCallback Callback function on failure
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   965
 * @param {object} options Object with properties .page and .limit for paging
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   966
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   967
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   968
Contacts.prototype.find = function(filter, successCallback, errorCallback, options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   969
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   970
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   971
		this.contactsService = device.getServiceObject("Service.Contact", "IDataSource");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   972
		this.options = options;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   973
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   974
		var criteria = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   975
		criteria.Type = "Contact";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   976
		if (filter && filter.name)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   977
			criteria.Filter = { SearchVal: filter.name };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   978
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   979
		if (typeof(successCallback) != 'function') 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   980
			successCallback = function(){};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   981
		if (typeof(errorCallback) != 'function') 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   982
			errorCallback = function(){};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   983
		if (typeof options == 'object'){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   984
			if (isNaN(this.options.limit))
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   985
				this.options.limit = 200;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   986
			if (isNaN(this.options.page))
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   987
				this.options.page = 1;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   988
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   989
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   990
		//need a closure here to bind this method to this instance of the Contacts object
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   991
		this.global_success = successCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   992
		var obj = this;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   993
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   994
		//WRT: result.ReturnValue is an iterator of contacts
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   995
		this.contactsService.IDataSource.GetList(criteria, function(transId, eventCode, result){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   996
			obj.success_callback(result.ReturnValue);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   997
		});
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   998
	} 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   999
	catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1000
		errorCallback(ex);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1001
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1002
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1003
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1004
Contacts.prototype.success_callback = function(contacts_iterator) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1005
	var gapContacts = new Array();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1006
	contacts_iterator.reset();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1007
    var contact;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1008
	var i = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1009
	var end = this.options.page * this.options.limit;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1010
	var start = end - this.options.limit;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1011
	while ((contact = contacts_iterator.getNext()) != undefined && i < end) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1012
		try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1013
			if (i >= start) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1014
				var gapContact = new Contact();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1015
				gapContact.name.givenName = Contacts.GetValue(contact, "FirstName");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1016
				gapContact.name.familyName = Contacts.GetValue(contact, "LastName");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1017
				gapContact.name.formatted = gapContact.firstName + " " + gapContact.lastName;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1018
				gapContact.emails = Contacts.getEmailsList(contact);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1019
				gapContact.phones = Contacts.getPhonesList(contact);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1020
				gapContact.address = Contacts.getAddress(contact);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1021
				gapContact.id = Contacts.GetValue(contact, "id");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1022
				gapContacts.push(gapContact);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1023
			}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1024
			i++;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1025
		} catch (e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1026
			alert("ContactsError (" + e.name + ": " + e.message + ")");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1027
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1028
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1029
	this.contacts = gapContacts;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1030
	this.global_success(gapContacts);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1031
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1032
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1033
Contacts.getEmailsList = function(contact) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1034
	var emails = new Array();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1035
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1036
			emails[0] = { type:"General", address: Contacts.GetValue(contact, "EmailGen") };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1037
			emails[1] = { type:"Work", address: Contacts.GetValue(contact, "EmailWork") };		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1038
			emails[2] = { type:"Home", address: Contacts.GetValue(contact, "EmailHome") };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1039
	} catch (e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1040
		emails = [];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1041
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1042
	return emails;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1043
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1044
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1045
Contacts.getPhonesList = function(contact) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1046
	var phones = new Array();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1047
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1048
			phones[0] = { type:"Mobile", number: Contacts.GetValue(contact, "MobilePhoneGen") };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1049
			phones[1] = { type:"Home", number: Contacts.GetValue(contact, "LandPhoneGen") };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1050
			phones[2] = { type:"Fax", number: Contacts.GetValue(contact, "FaxNumberGen") };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1051
			phones[3] = { type:"Work", number: Contacts.GetValue(contact, "LandPhoneWork") };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1052
			phones[4] = { type:"WorkMobile", number: Contacts.GetValue(contact, "MobilePhoneWork") };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1053
	} catch (e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1054
		phones = [];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1055
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1056
	return phones;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1057
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1058
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1059
Contacts.getAddress = function(contact) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1060
	var address = "";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1061
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1062
		address = Contacts.GetValue(contact, "AddrLabelHome") + ", " + Contacts.GetValue(contact, "AddrStreetHome") + ", " +
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1063
				Contacts.GetValue(contact, "AddrLocalHome") + ", " + Contacts.GetValue(contact, "AddrRegionHome") + ", " + 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1064
				Contacts.GetValue(contact, "AddrPostCodeHome") + ", " + Contacts.GetValue(contact, "AddrCountryHome");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1065
	} catch (e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1066
		address = "";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1067
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1068
	return address;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1069
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1070
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1071
Contacts.GetValue = function(contactObj, key) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1072
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1073
		return contactObj[key]["Value"];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1074
	} catch (e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1075
		return "";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1076
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1077
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1078
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1079
if (typeof navigator.contacts == "undefined") navigator.contacts = new Contacts();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1080
PhoneGap.ExtendWrtDeviceObj = function(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1081
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1082
	if (!window.device)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1083
		window.device = {};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1084
	navigator.device = window.device;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1085
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1086
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1087
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1088
		if (window.menu)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1089
	    	window.menu.hideSoftkeys();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1090
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1091
		device.available = PhoneGap.available;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1092
		device.platform = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1093
		device.version = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1094
		device.name = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1095
		device.uuid = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1096
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1097
		var so = device.getServiceObject("Service.SysInfo", "ISysInfo");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1098
		var pf = PhoneGap.GetWrtPlatformVersion(so);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1099
		device.platform = pf.platform;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1100
		device.version = pf.version;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1101
		device.uuid = PhoneGap.GetWrtDeviceProperty(so, "IMEI");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1102
		device.name = PhoneGap.GetWrtDeviceProperty(so, "PhoneModel");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1103
	} 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1104
	catch (e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1105
		device.available = false;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1106
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1107
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1108
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1109
PhoneGap.GetWrtDeviceProperty = function(serviceObj, key) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1110
	var criteria = { "Entity": "Device", "Key": key };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1111
	var result = serviceObj.ISysInfo.GetInfo(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1112
	if (result.ErrorCode == 0) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1113
		return result.ReturnValue.StringData;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1114
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1115
	else {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1116
		return null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1117
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1118
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1119
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1120
PhoneGap.GetWrtPlatformVersion = function(serviceObj) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1121
	var criteria = { "Entity": "Device", "Key": "PlatformVersion" };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1122
	var result = serviceObj.ISysInfo.GetInfo(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1123
	if (result.ErrorCode == 0) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1124
		var version = {};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1125
		version.platform = result.ReturnValue.MajorVersion;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1126
		version.version = result.ReturnValue.MinorVersion;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1127
		return version;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1128
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1129
	else {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1130
		return null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1131
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1132
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1133
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1134
PhoneGap.ExtendWrtDeviceObj();/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1135
 * This class provides access to device GPS data.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1136
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1137
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1138
function Geolocation() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1139
    /**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1140
     * The last known GPS position.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1141
     */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1142
    this.lastPosition = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1143
    this.lastError = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1144
    this.callbacks = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1145
        onLocationChanged: [],
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1146
        onError:           []
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1147
    };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1148
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1149
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1150
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1151
 * Asynchronously aquires the current position.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1152
 * @param {Function} successCallback The function to call when the position
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1153
 * data is available
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1154
 * @param {Function} errorCallback The function to call when there is an error 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1155
 * getting the position data.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1156
 * @param {PositionOptions} options The options for getting the position data
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1157
 * such as timeout.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1158
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1159
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1160
    var referenceTime = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1161
    if (this.lastPosition)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1162
        referenceTime = this.lastPosition.timestamp;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1163
    else
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1164
        this.start(options);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1165
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1166
    var timeout = 20000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1167
    var interval = 500;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1168
    if (typeof(options) == 'object' && options.interval)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1169
        interval = options.interval;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1170
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1171
    if (typeof(successCallback) != 'function')
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1172
        successCallback = function() {};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1173
    if (typeof(errorCallback) != 'function')
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1174
        errorCallback = function() {};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1175
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1176
    var dis = this;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1177
    var delay = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1178
    var timer = setInterval(function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1179
        delay += interval;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1180
		//if we have a new position, call success and cancel the timer
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1181
        if (dis.lastPosition && dis.lastPosition.timestamp > referenceTime) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1182
            successCallback(dis.lastPosition);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1183
            clearInterval(timer);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1184
        } else if (delay >= timeout) { //else if timeout has occured then call error and cancel the timer
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1185
            errorCallback();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1186
            clearInterval(timer);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1187
        }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1188
		//else the interval gets called again
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1189
    }, interval);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1190
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1191
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1192
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1193
 * Asynchronously aquires the position repeatedly at a given interval.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1194
 * @param {Function} successCallback The function to call each time the position
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1195
 * data is available
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1196
 * @param {Function} errorCallback The function to call when there is an error 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1197
 * getting the position data.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1198
 * @param {PositionOptions} options The options for getting the position data
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1199
 * such as timeout and the frequency of the watch.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1200
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1201
Geolocation.prototype.watchPosition = function(successCallback, errorCallback, options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1202
	// Invoke the appropriate callback with a new Position object every time the implementation 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1203
	// determines that the position of the hosting device has changed. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1204
	this.getCurrentPosition(successCallback, errorCallback, options);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1205
	var frequency = 10000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1206
        if (typeof options == 'object' && options.frequency)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1207
            frequency = options.frequency;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1208
	var that = this;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1209
	return setInterval(function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1210
		that.getCurrentPosition(successCallback, errorCallback, options);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1211
	}, frequency);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1212
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1213
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1214
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1215
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1216
 * Clears the specified position watch.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1217
 * @param {String} watchId The ID of the watch returned from #watchPosition.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1218
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1219
Geolocation.prototype.clearWatch = function(watchId) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1220
	clearInterval(watchId);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1221
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1222
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1223
Geolocation.prototype.start = function(options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1224
	var so = device.getServiceObject("Service.Location", "ILocation");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1225
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1226
	//construct the criteria for our location request
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1227
	var updateOptions = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1228
	// Specify that location information need not be guaranteed. This helps in
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1229
	// that the widget doesn't need to wait for that information possibly indefinitely.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1230
	updateOptions.PartialUpdates = true;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1231
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1232
	//default 15 seconds
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1233
	if (typeof(options) == 'object' && options.timeout) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1234
		//options.timeout in in ms, updateOptions.UpdateTimeout in microsecs
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1235
		updateOptions.UpdateTimeOut = options.timeout * 1000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1236
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1237
	//default 1 second
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1238
	if (typeof(options) == 'object' && options.interval) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1239
		//options.timeout in in ms, updateOptions.UpdateTimeout in microsecs
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1240
		updateOptions.UpdateInterval = options.interval * 1000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1241
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1242
	// Initialize the criteria for the GetLocation call
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1243
	var trackCriteria = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1244
	// could use "BasicLocationInformation" or "GenericLocationInfo"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1245
	trackCriteria.LocationInformationClass = "GenericLocationInfo";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1246
	trackCriteria.Updateoptions = updateOptions;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1247
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1248
	var dis = this;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1249
	so.ILocation.Trace(trackCriteria, function(transId, eventCode, result) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1250
		var retVal = result.ReturnValue;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1251
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1252
		if (result.ErrorCode != 0 || isNaN(retVal.Latitude))
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1253
			return;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1254
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1255
		// heading options: retVal.TrueCourse, retVal.MagneticHeading, retVal.Heading, retVal.MagneticCourse
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1256
		// but retVal.Heading was the only field being returned with data on the test device (Nokia 5800)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1257
		// WRT does not provide accuracy
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1258
		var newCoords = new Coordinates(retVal.Latitude, retVal.Longitude, retVal.Altitude, null, retVal.Heading, retVal.HorizontalSpeed);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1259
		var positionObj = { coords: newCoords, timestamp: (new Date()).getTime() };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1260
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1261
		dis.lastPosition = positionObj;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1262
	});
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1263
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1264
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1265
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1266
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1267
if (typeof navigator.geolocation == "undefined") navigator.geolocation = new Geolocation();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1268
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1269
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1270
 * This class provides access to the device media, interfaces to both sound and video
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1271
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1272
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1273
function Media(src, successCallback, errorCallback) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1274
	this.src = src;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1275
	this.successCallback = successCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1276
	this.errorCallback = errorCallback;												
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1277
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1278
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1279
Media.prototype.record = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1280
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1281
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1282
Media.prototype.play = function(src) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1283
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1284
	if (document.getElementById('gapsound'))
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1285
		document.body.removeChild(document.getElementById('gapsound'));
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1286
	var obj;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1287
	obj = document.createElement("embed");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1288
	obj.setAttribute("id", "gapsound");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1289
	obj.setAttribute("type", "audio/x-mpeg");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1290
	obj.setAttribute("width", "0");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1291
	obj.setAttribute("width", "0");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1292
	obj.setAttribute("hidden", "true");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1293
	obj.setAttribute("autostart", "true");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1294
	obj.setAttribute("src", src);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1295
	document.body.appendChild(obj);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1296
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1297
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1298
Media.prototype.pause = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1299
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1300
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1301
Media.prototype.stop = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1302
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1303
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1304
if (typeof navigator.media == "undefined") navigator.media = new Media();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1305
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1306
 * This class provides access to notifications on the device.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1307
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1308
function Notification() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1309
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1310
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1311
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1312
Notification.prototype.vibrate = function(mills)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1313
{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1314
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1315
	if (!Notification.getSysinfoObject())
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1316
		Notification.embedSysinfoObject();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1317
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1318
	this.sysinfo = Notification.getSysinfoObject();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1319
	this.sysinfo.startvibra(mills, 100);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1320
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1321
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1322
//TODO: this is not beeping
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1323
Notification.prototype.beep = function(count, volume)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1324
{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1325
	if (!Notification.getSysinfoObject())
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1326
		Notification.embedSysinfoObject();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1327
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1328
	this.sysinfo = Notification.getSysinfoObject();	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1329
	this.sysinfo.beep(220,2000);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1330
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1331
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1332
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1333
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1334
 * Open a native alert dialog, with a customizable title and button text.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1335
 * @param {String} message Message to print in the body of the alert
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1336
 * @param {String} [title="Alert"] Title of the alert dialog (default: Alert)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1337
 * @param {String} [buttonLabel="OK"] Label of the close button (default: OK)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1338
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1339
Notification.prototype.alert = function(message, title, buttonLabel) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1340
    // Default is to use a browser alert; this will use "index.html" as the title though
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1341
    alert(message);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1342
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1343
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1344
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1345
 * Start spinning the activity indicator on the statusbar
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1346
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1347
Notification.prototype.activityStart = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1348
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1349
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1350
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1351
 * Stop spinning the activity indicator on the statusbar, if it's currently spinning
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1352
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1353
Notification.prototype.activityStop = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1354
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1355
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1356
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1357
 * Causes the device to blink a status LED.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1358
 * @param {Integer} count The number of blinks.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1359
 * @param {String} colour The colour of the light.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1360
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1361
Notification.prototype.blink = function(count, colour) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1362
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1363
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1364
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1365
Notification.embedSysinfoObject = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1366
	var el = document.createElement("embed");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1367
	el.setAttribute("type", "application/x-systeminfo-widget");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1368
	el.setAttribute("hidden", "yes");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1369
	document.getElementsByTagName("body")[0].appendChild(el);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1370
	return;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1371
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1372
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1373
Notification.getSysinfoObject = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1374
	return document.embeds[0];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1375
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1376
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1377
if (typeof navigator.notification == "undefined") navigator.notification = new Notification();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1378
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1379
 * This class provides access to the device orientation.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1380
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1381
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1382
function Orientation() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1383
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1384
	 * The current orientation, or null if the orientation hasn't changed yet.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1385
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1386
	this.currentOrientation = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1387
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1388
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1389
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1390
 * Set the current orientation of the phone.  This is called from the device automatically.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1391
 * 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1392
 * When the orientation is changed, the DOMEvent \c orientationChanged is dispatched against
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1393
 * the document element.  The event has the property \c orientation which can be used to retrieve
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1394
 * the device's current orientation, in addition to the \c Orientation.currentOrientation class property.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1395
 *
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1396
 * @param {Number} orientation The orientation to be set
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1397
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1398
Orientation.prototype.setOrientation = function(orientation) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1399
		if (orientation == this.currentOrientation) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1400
			return;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1401
		var old = this.currentOrientation;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1402
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1403
		this.currentOrientation = orientation;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1404
		var e = document.createEvent('Events');
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1405
		e.initEvent('orientationChanged', 'false', 'false');
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1406
		e.orientation = orientation;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1407
		e.oldOrientation = old;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1408
		document.dispatchEvent(e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1409
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1410
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1411
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1412
 * Asynchronously aquires the current orientation.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1413
 * @param {Function} successCallback The function to call when the orientation
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1414
 * is known.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1415
 * @param {Function} errorCallback The function to call when there is an error 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1416
 * getting the orientation.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1417
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1418
Orientation.prototype.getCurrentOrientation = function(successCallback, errorCallback) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1419
	// If the orientation is available then call success
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1420
	// If the orientation is not available then call error
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1421
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1422
		if (!this.serviceObj) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1423
			this.serviceObj = this.getServiceObj();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1424
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1425
		if (this.serviceObj == null) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1426
			errorCallback({
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1427
				name: "DeviceErr",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1428
				message: "Could not initialize service object"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1429
			});
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1430
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1431
		//get the sensor channel
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1432
		var SensorParams = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1433
			SearchCriterion: "Orientation"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1434
		};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1435
		var returnvalue = this.serviceObj.ISensor.FindSensorChannel(SensorParams);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1436
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1437
		var error = returnvalue["ErrorCode"];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1438
		var errmsg = returnvalue["ErrorMessage"];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1439
		if (!(error == 0 || error == 1012)) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1440
			var ex = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1441
				name: "Unable to find Sensor Channel: " + error,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1442
				message: errmsg
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1443
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1444
			errorCallback(ex);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1445
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1446
		var channelInfoMap = returnvalue["ReturnValue"][0];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1447
		var criteria = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1448
			ChannelInfoMap: channelInfoMap,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1449
			ListeningType: "ChannelData"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1450
		};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1451
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1452
		if (typeof(successCallback) != 'function') 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1453
			successCallback = function(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1454
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1455
		if (typeof(errorCallback) != 'function') 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1456
			errorCallback = function(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1457
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1458
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1459
		this.success_callback = successCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1460
		this.error_callback = errorCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1461
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1462
		//create a closure to persist this instance of orientation object into the RegisterForNofication callback
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1463
		var obj = this;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1464
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1465
		this.serviceObj.ISensor.RegisterForNotification(criteria, function(transId, eventCode, result){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1466
			alert(1);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1467
			var criteria = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1468
				TransactionID: transId
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1469
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1470
			try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1471
				var orientation = result.ReturnValue.DeviceOrientation;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1472
				obj.serviceObj.ISensor.Cancel(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1473
				
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1474
				obj.setOrientation(orientation);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1475
				
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1476
				obj.success_callback(orientation);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1477
				
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1478
			} 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1479
			catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1480
				obj.serviceObj.ISensor.Cancel(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1481
				obj.error_callback(ex);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1482
			}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1483
			
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1484
		});
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1485
	} catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1486
		errorCallback({ name: "OrientationError", message: ex.name + ": " + ex.message });
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1487
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1488
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1489
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1490
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1491
 * Asynchronously aquires the orientation repeatedly at a given interval.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1492
 * @param {Function} successCallback The function to call each time the orientation
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1493
 * data is available.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1494
 * @param {Function} errorCallback The function to call when there is an error 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1495
 * getting the orientation data.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1496
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1497
Orientation.prototype.watchOrientation = function(successCallback, errorCallback, options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1498
	// Invoke the appropriate callback with a new Position object every time the implementation 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1499
	// determines that the position of the hosting device has changed. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1500
	this.getCurrentOrientation(successCallback, errorCallback);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1501
	var frequency = (options != undefined)? options.frequency : 1000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1502
	return setInterval(function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1503
		navigator.orientation.getCurrentOrientation(successCallback, errorCallback);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1504
	}, frequency);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1505
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1506
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1507
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1508
 * Clears the specified orientation watch.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1509
 * @param {String} watchId The ID of the watch returned from #watchOrientation.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1510
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1511
Orientation.prototype.clearWatch = function(watchId) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1512
	clearInterval(watchId);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1513
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1514
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1515
//gets the Acceleration Service Object from WRT
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1516
Orientation.prototype.getServiceObj = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1517
	var so;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1518
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1519
    try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1520
        so = device.getServiceObject("Service.Sensor", "ISensor");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1521
    } catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1522
		throw {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1523
			name: "DeviceError",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1524
			message: ex.name + ": " + ex.message
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1525
		};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1526
    }		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1527
	return so;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1528
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1529
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1530
if (typeof navigator.orientation == "undefined") navigator.orientation = new Orientation();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1531
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1532
 * This class contains position information.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1533
 * @param {Object} lat
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1534
 * @param {Object} lng
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1535
 * @param {Object} acc
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1536
 * @param {Object} alt
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1537
 * @param {Object} altacc
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1538
 * @param {Object} head
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1539
 * @param {Object} vel
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1540
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1541
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1542
function Position(coords, timestamp) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1543
	this.coords = coords;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1544
        this.timestamp = new Date().getTime();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1545
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1546
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1547
function Coordinates(lat, lng, alt, acc, head, vel) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1548
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1549
	 * The latitude of the position.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1550
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1551
	this.latitude = lat;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1552
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1553
	 * The longitude of the position,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1554
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1555
	this.longitude = lng;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1556
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1557
	 * The accuracy of the position.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1558
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1559
	this.accuracy = acc;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1560
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1561
	 * The altitude of the position.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1562
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1563
	this.altitude = alt;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1564
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1565
	 * The direction the device is moving at the position.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1566
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1567
	this.heading = head;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1568
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1569
	 * The velocity with which the device is moving at the position.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1570
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1571
	this.speed = vel;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1572
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1573
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1574
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1575
 * This class specifies the options for requesting position data.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1576
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1577
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1578
function PositionOptions() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1579
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1580
	 * Specifies the desired position accuracy.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1581
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1582
	this.enableHighAccuracy = true;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1583
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1584
	 * The timeout after which if position data cannot be obtained the errorCallback
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1585
	 * is called.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1586
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1587
	this.timeout = 10000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1588
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1589
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1590
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1591
 * This class contains information about any GSP errors.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1592
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1593
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1594
function PositionError() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1595
	this.code = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1596
	this.message = "";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1597
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1598
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1599
PositionError.UNKNOWN_ERROR = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1600
PositionError.PERMISSION_DENIED = 1;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1601
PositionError.POSITION_UNAVAILABLE = 2;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1602
PositionError.TIMEOUT = 3;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1603
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1604
 * This class provides access to the device SMS functionality.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1605
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1606
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1607
function Sms() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1608
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1609
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1610
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1611
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1612
 * Sends an SMS message.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1613
 * @param {Integer} number The phone number to send the message to.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1614
 * @param {String} message The contents of the SMS message to send.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1615
 * @param {Function} successCallback The function to call when the SMS message is sent.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1616
 * @param {Function} errorCallback The function to call when there is an error sending the SMS message.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1617
 * @param {PositionOptions} options The options for accessing the GPS location such as timeout and accuracy.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1618
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1619
Sms.prototype.send = function(number, message, successCallback, errorCallback, options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1620
    try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1621
		if (!this.serviceObj)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1622
			this.serviceObj = this.getServiceObj();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1623
			
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1624
	    // Setup input params using dot syntax
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1625
	    var criteria = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1626
	    criteria.MessageType = 'SMS';
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1627
	    criteria.To = number;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1628
	    criteria.BodyText = message;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1629
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1630
      	var result = this.serviceObj.IMessaging.Send(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1631
    	if (result.ErrorCode != 0 && result.ErrorCode != "0")
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1632
		{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1633
			var exception = { name: "SMSError", message: result.ErrorMessage };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1634
			throw exception;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1635
		} else {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1636
			successCallback.call();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1637
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1638
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1639
  	catch(ex)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1640
  	{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1641
		errorCallback.call({ name: "SmsError", message: ex.name + ": " + ex.message });
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1642
  	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1643
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1644
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1645
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1646
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1647
//gets the Sms Service Object from WRT
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1648
Sms.prototype.getServiceObj = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1649
	var so;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1650
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1651
    try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1652
        so = device.getServiceObject("Service.Messaging", "IMessaging");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1653
    } catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1654
		throw {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1655
			name: "SmsError",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1656
			message: "Failed to load sms service (" + ex.name + ": " + ex.message + ")"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1657
		};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1658
    }		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1659
	return so;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1660
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1661
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1662
if (typeof navigator.sms == "undefined") navigator.sms = new Sms();/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1663
 * @author ryan
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1664
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1665
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1666
function Storage() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1667
	this.length = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1668
	this.available = true;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1669
	this.serialized = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1670
	this.items = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1671
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1672
	if (!window.widget) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1673
		this.available = false;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1674
		return;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1675
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1676
	var pref = window.widget.preferenceForKey(Storage.PREFERENCE_KEY);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1677
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1678
	//storage not yet created
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1679
	if (pref == "undefined" || pref == undefined) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1680
		this.length = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1681
		this.serialized = "({})";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1682
		this.items = {};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1683
		window.widget.setPreferenceForKey(this.serialized, Storage.PREFERENCE_KEY);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1684
	} else {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1685
		this.serialized = pref;'({"store_test": { "key": "store_test", "data": "asdfasdfs" },})';
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1686
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1687
		this.items = eval(this.serialized);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1688
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1689
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1690
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1691
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1692
Storage.PREFERENCE_KEY = "phonegap_storage_pref_key";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1693
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1694
Storage.prototype.index = function (key) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1695
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1696
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1697
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1698
Storage.prototype.getItem = function (key) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1699
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1700
		return this.items[key].data;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1701
	} catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1702
		return null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1703
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1704
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1705
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1706
Storage.prototype.setItem = function (key, data) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1707
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1708
	if (!this.items[key])
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1709
		this.length++;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1710
	this.items[key] = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1711
		"key": key,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1712
		"data": data
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1713
	};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1714
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1715
	this.serialize();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1716
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1717
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1718
Storage.prototype.removeItem = function (key) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1719
	if (this.items[key]) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1720
		this.items[key] = undefined;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1721
		this.length--;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1722
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1723
	this.serialize();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1724
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1725
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1726
Storage.prototype.clear = function () {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1727
	this.length = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1728
	this.serialized = "({})";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1729
	this.items = {};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1730
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1731
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1732
Storage.prototype.serialize = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1733
	var json = "";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1734
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1735
	for (key in this.items) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1736
		var item = this.items[key];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1737
		json += "\"" + item.key + "\": { \"key\": \"" + item.key + "\", \"data\": \"" + item.data + "\" }, ";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1738
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1739
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1740
	window.widget.setPreferenceForKey( "({" + json + "})", Storage.PREFERENCE_KEY);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1741
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1742
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1743
if (typeof navigator.storage == "undefined" ) navigator.storage = new Storage();