org.symbian.tools.wrttools/libraries/phonegap.js
author Eugene Ostroukhov <eugeneo@symbian.org>
Tue, 08 Jun 2010 15:33:30 -0700
changeset 359 dceb3fa18927
parent 340 740921999de7
child 442 980aaebb8022
permissions -rw-r--r--
Added support to open function from variables view
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
		if (!this.serviceObj) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   107
			this.serviceObj = this.getServiceObj();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   108
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   109
		if (this.serviceObj == null) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   110
			throw {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   111
				name: "DeviceErr",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   112
				message: "Could not initialize service object"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   113
			};
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
		//get the sensor channel
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   116
		var SensorParams = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   117
			SearchCriterion: "AccelerometerAxis"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   118
		};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   119
		var returnvalue = this.serviceObj.ISensor.FindSensorChannel(SensorParams);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   120
		var error = returnvalue["ErrorCode"];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   121
		var errmsg = returnvalue["ErrorMessage"];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   122
		if (!(error == 0 || error == 1012)) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   123
			var ex = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   124
				name: "Unable to find Sensor Channel: " + error,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   125
				message: errmsg
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   126
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   127
			throw ex;
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
		var channelInfoMap = returnvalue["ReturnValue"][0];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   130
		var criteria = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   131
			ChannelInfoMap: channelInfoMap,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   132
			ListeningType: "ChannelData"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   133
		};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   134
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   135
		if (typeof(successCallback) != 'function') 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   136
			successCallback = function(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   137
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   138
		if (typeof(errorCallback) != 'function') 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   139
			errorCallback = function(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   140
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   141
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   142
		this.success_callback = successCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   143
		this.error_callback = errorCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   144
		//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
   145
		var obj = this;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   146
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   147
		// 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
   148
		// 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
   149
		this.serviceObj.ISensor.RegisterForNotification(criteria, function(transId, eventCode, result){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   150
			try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   151
				var criteria = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   152
					TransactionID: transId
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   153
				};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   154
				obj.serviceObj.ISensor.Cancel(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   155
				
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   156
				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
   157
				Accelerometer.lastAcceleration = accel;
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
				obj.success_callback(accel);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   160
				
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
			catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   163
				obj.serviceObj.ISensor.Cancel(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   164
				obj.error_callback(ex);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   165
			}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   166
			
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   167
		});
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   168
	} catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   169
		errorCallback(ex);
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   172
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   173
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   174
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
 * Asynchronously aquires the acceleration repeatedly at a given interval.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   177
 * @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
   178
 * data is available
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   179
 * @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
   180
 * getting the acceleration data.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   181
 * @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
   182
 * such as timeout.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   183
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   184
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   185
Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallback, options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   186
	this.getCurrentAcceleration(successCallback, errorCallback, options);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   187
	// 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
   188
 	var frequency = (options != undefined)? options.frequency : 10000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   189
	return setInterval(function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   190
		navigator.accelerometer.getCurrentAcceleration(successCallback, errorCallback, options);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   191
	}, frequency);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   192
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   193
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   194
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   195
 * Clears the specified accelerometer watch.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   196
 * @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
   197
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   198
Accelerometer.prototype.clearWatch = function(watchId) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   199
	clearInterval(watchId);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   200
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   201
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   202
//gets the Acceleration Service Object from WRT
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   203
Accelerometer.prototype.getServiceObj = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   204
	var so;
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
    try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   207
        so = device.getServiceObject("Service.Sensor", "ISensor");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   208
    } catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   209
		throw {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   210
			name: "DeviceError",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   211
			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
   212
		};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   213
    }		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   214
	return so;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   215
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   216
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   217
if (typeof navigator.accelerometer == "undefined") navigator.accelerometer = new Accelerometer();/**
321
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   218
 * This class provides access to the device media, interfaces to both sound and video
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   219
 * @constructor
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   220
 */
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   221
function Audio(src, successCallback, errorCallback) {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   222
	this.src = src;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   223
	this.successCallback = successCallback;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   224
	this.errorCallback = errorCallback;												
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   225
}
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   226
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   227
Audio.prototype.record = function() {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   228
};
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   229
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   230
Audio.prototype.play = function() {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   231
try {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   232
	if (document.getElementById('gapsound'))
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   233
		document.body.removeChild(document.getElementById('gapsound'));
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   234
	var obj;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   235
	obj = document.createElement("embed");
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   236
	obj.setAttribute("id", "gapsound");
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   237
	obj.setAttribute("type", "audio/x-mpeg");
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   238
	obj.setAttribute("width", "0");
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   239
	obj.setAttribute("width", "0");
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   240
	obj.setAttribute("hidden", "true");
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   241
	obj.setAttribute("autostart", "true");
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   242
	obj.setAttribute("src", this.src);
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   243
	document.body.appendChild(obj);
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   244
} catch (ex) { debug.log(ex.name + ": " + ex.message); }
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   245
};
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   246
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   247
Audio.prototype.pause = function() {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   248
};
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   249
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   250
Audio.prototype.stop = function() {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   251
	document.body.removeChild(document.getElementById('gapsound'));
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   252
};
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
   253
/**
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   254
 * This class provides access to the device camera.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   255
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   256
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   257
function Camera() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   258
	this.success_callback = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   259
	this.error_callback = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   260
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   261
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
 * 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
   264
 * PS 2.0 source code (camera API). 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   265
 * @param {Function} successCallback
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   266
 * @param {Function} errorCallback
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   267
 * @param {Object} options
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
Camera.prototype.getPicture = function(successCallback, errorCallback, options){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   270
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   271
		if (!this.serviceObj) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   272
			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
   273
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   274
		if (!this.serviceObj) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   275
			throw {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   276
				name: "CameraError",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   277
				message: "could not load camera service"
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
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   280
		var obj = this;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   281
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   282
		obj.success_callback = successCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   283
		obj.error_callback = errorCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   284
		this.serviceObj.startCamera( function(transactionID, errorCode, outPut) { 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   285
			//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
   286
			if (errorCode == 0) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   287
				obj.success_callback(outPut);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   288
			}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   289
			else {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   290
				obj.error_callback({
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   291
					name: "CameraError",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   292
					message: errorCode
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   293
				});
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
		});
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
	} catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   298
		errorCallback.call(ex);
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
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   301
};
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
if (typeof navigator.camera == "undefined") navigator.camera = new Camera();/*
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   304
Copyright © 2009 Nokia. All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   305
Code licensed under the BSD License:
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   306
Software License Agreement (BSD License) Copyright © 2009 Nokia.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   307
All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   308
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
   309
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   310
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
   311
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
   312
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
   313
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
   314
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   315
version: 1.0
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   316
*/
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   319
// utility.js
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   320
//
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   321
// This file contains some utility functions for S60 providers
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   322
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
// Start an application and wait for it to exit
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
//TBD: Get rid of this global, use closures instead
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   327
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   328
DeviceError.prototype = new Error(); //inheritance occurs here
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   329
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
   330
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   331
//constructor for DeviceError.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   332
function DeviceError(message,code) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   333
{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   334
	this.toString = concatenate;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   335
	this.code = code;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   336
	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
   337
	this.message=message; 
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 concatenate()
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   341
{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   342
	return (this.name+":"+" "+this.message+" "+this.code);
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
function splitErrorMessage(errmessage)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   346
{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   347
	if(errmessage.search(/:/)!=-1)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   348
	{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   349
		if((errmessage.split(":").length)==2)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   350
		{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   351
			return errmessage.split(":")[1];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   352
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   353
		if((errmessage.split(":").length)>2)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   354
		{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   355
			return errmessage.split(":")[2];
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
	return errmessage;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   359
}
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
var __s60_start_and_wait_cb;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   363
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   364
function __s60_on_app_exit(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   365
  widget.onshow = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   366
  if(__s60_start_and_wait_cb != null){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   367
    __s60_start_and_wait_cb();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   368
  }
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   371
function __s60_on_app_start(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   372
  widget.onhide = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   373
  widget.onshow = __s60_on_app_exit;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   374
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   375
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   376
// This function cannot actually force JS to wait,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   377
// 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
   378
// to continue processing on return from the app.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   379
// Apps should take care not to reinvoke this and
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   380
// should be careful about any other processing
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   381
// that might happen while the app is running.
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
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
   384
  __s60_start_and_wait_cb = app_exit_cb;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   385
  widget.onhide = __s60_on_app_start;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   386
  widget.openApplication(id, args);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   387
}
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
function __s60_api_not_supported(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   390
  throw(err_ServiceNotSupported);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   391
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   392
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   393
function __s60_enumerate_object(object, namespace, func, param){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   394
    var key;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   395
    for(key in object){
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
        var propname;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   398
       	if(namespace){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   399
	    propname = namespace + "." + key;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   400
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   401
	else{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   402
	    propname = key;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   403
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   404
        var value = object[key];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   405
        if(typeof value == "object"){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   406
	  __s60_enumerate_object(value, propname, func, param);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   407
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   408
	else {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   409
	  func(propname,value, param);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   410
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   411
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   412
}
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
Copyright © 2009 Nokia. All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   415
Code licensed under the BSD License:
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   416
Software License Agreement (BSD License) Copyright © 2009 Nokia.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   417
All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   418
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
   419
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   420
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
   421
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
   422
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
   423
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
   424
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   425
version: 1.0
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   428
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   429
var __device_debug_on__ = true;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   430
var err_missing_argument = 1003;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   431
var event_cancelled = 3;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   432
var err_bad_argument = 1002;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   433
var err_InvalidService_Argument = 1000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   434
var err_ServiceNotReady = 1006;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   435
var err_ServiceNotSupported = 1004;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   436
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   437
function __device_debug(text){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   438
  //if(__device_debug_on__) alert(text);
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   441
function __device_handle_exception(e, text){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   442
	__device_debug(text);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   443
	throw(e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   444
}
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
function __device_typeof(value)
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
	// First check to see if the value is undefined.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   449
	if (value == undefined) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   450
        return "undefined";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   451
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   452
	// Check for objects created with the "new" keyword.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   453
	if (value instanceof Object) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   454
		// Check whether it's a string object.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   455
		if (value instanceof String) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   456
			return "String";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   457
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   458
		// Check whether it's an array object/array literal.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   459
		else 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   460
			if (value instanceof Array) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   461
				return "Array";
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
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   464
	// dealing with a literal.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   465
		if (typeof value) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   466
			if (typeof value == "object") {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   467
				if (typeof value == "object" && !value) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   468
					return "null";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   469
				}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   470
			}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   471
           // if not null check for other types
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   472
			
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   473
				// Check if it's a string literal.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   474
			else if (typeof value == "string") {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   475
					return "string";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   476
				}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   477
		}	 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   478
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   479
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   480
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   481
// 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
   482
// (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
   483
/*
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   484
var sp_device = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   485
        //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
   486
	load: __device_service_load,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   487
        listServices: __device_service_list,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   488
        listInterfaces: __device_service_interfaces,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   489
        version: "0.1",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   490
        info: "device prototype"
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
*/
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   493
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   494
if(undefined == com)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   495
    var com={};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   496
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   497
if( typeof com != "object")
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   498
    throw("com defined as non object");
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
if(undefined == com.nokia)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   501
    com.nokia = {};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   502
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   503
if( typeof com.nokia != "object")
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   504
    throw("com.nokia defined as non object");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   505
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   506
if(undefined == com.nokia.device)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   507
    com.nokia.device = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   508
        load: __device_service_load,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   509
        listServices: __device_service_list,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   510
        listInterfaces: __device_service_interfaces,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   511
        version: "0.1",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   512
        info: "device prototype"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   513
        };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   514
else
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   515
    throw("com.nokia.device already defined");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   516
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   517
com.nokia.device.SORT_ASCENDING = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   518
com.nokia.device.SORT_DESCENDING = 1;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   519
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   520
com.nokia.device.SORT_BY_DATE = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   521
com.nokia.device.SORT_BY_SENDER = 1;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   522
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   523
com.nokia.device.STATUS_READ = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   524
com.nokia.device.STATUS_UNREAD = 1;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   525
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
// Configure the services offered.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   528
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   529
var __device_services_inited = false;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   530
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   531
var __device_services = [
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   532
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   533
  // 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
   534
  {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   535
    "name":"com.nokia.device",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   536
    "version": 0.1, 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   537
    "interfaces": []
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   538
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   539
];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   540
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   541
// Initialize the configured services.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   542
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   543
function __device_services_init(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   544
  if(__device_services_inited){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   545
    return;
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
  __device_services_inited = true;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   548
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   549
  // Get the service-specific service entries. Note that these
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   550
  // 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
   551
  // interpreter gracefully handles missing services. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   552
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   553
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   554
    __device_services[0].interfaces.push(__device_geolocation_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   555
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   556
    __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   557
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   558
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   559
    __device_services[0].interfaces.push(__device_camera_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   560
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   561
    __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   562
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   563
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   564
    __device_services[0].interfaces.push(__device_media_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   565
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   566
//    __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   567
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   568
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   569
    __device_services[0].interfaces.push(__device_contacts_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   570
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   571
//    __device_debug("Missing library implementation: " + e);
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
 try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   574
    __device_services[0].interfaces.push(__device_messaging_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   575
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   576
      __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   577
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   578
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   579
    __device_services[0].interfaces.push(__device_calendar_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   580
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   581
      __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   582
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   583
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   584
    __device_services[0].interfaces.push(__device_landmarks_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   585
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   586
      __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   587
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   588
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   589
    __device_services[0].interfaces.push(__device_event_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   590
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   591
      __device_debug("Missing library implementation: " + e);
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
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   594
    __device_services[0].interfaces.push(__device_sysinfo_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   595
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   596
      __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   597
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   598
  try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   599
    __device_services[0].interfaces.push(__device_sensors_service_entry);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   600
  }catch (e){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   601
      __device_debug("Missing library implementation: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   602
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   603
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   604
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   605
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   606
function __device_get_implementation(i){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   607
  //__device_debug("get_implementation: " + i);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   608
  return  new i.proto(new(i.providers[0].instance));
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   609
}
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
function __device_get_descriptor(i){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   612
  //__device_debug("get_descriptor: " + i);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   613
  return new i.descriptor(new(i.providers[0].descriptor));
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   614
}
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
function __device_get_interface(s, interfaceName, version){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   617
  //__device_debug("get_interface: " + s + " " + interfaceName);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   618
  var i = s.interfaces;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   619
  if((interfaceName == null) || (interfaceName == '')){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   620
    // Interface name not specified, get first interface, ignoring version
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   621
    return __device_get_implementation(i[0]);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   622
  }
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
  // Find first match of name and version
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   625
  for (var d in i){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   626
  
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   627
    if(i[d].name == null){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   628
      __device_update_descriptor(i[d]);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   629
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   630
    if(i[d].name == undefined){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   631
      continue;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   632
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   633
    if (i[d].name == interfaceName){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   634
      // Match version if specified
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   635
      if ((version == null) || (version == '') || (i[d].version >= version)){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   636
	return __device_get_implementation(i[d]);
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
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   640
  return null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   641
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   642
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   643
// Implemention of the load method
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   644
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   645
function __device_service_load(serviceName, interfaceName, version){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   646
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   647
  __device_services_init();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   648
  
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   649
  // Service name is specified
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   650
   if ((serviceName != null) && (serviceName != '') &&(serviceName != "*")){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   651
    for(var s in __device_services){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   652
      if (serviceName == __device_services[s].name){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   653
	return __device_get_interface(__device_services[s], interfaceName, version);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   654
      }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   655
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   656
  // Service name not specified, get first implementation 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   657
  } else {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   658
    //__device_debug("Trying to get interface implementations: ");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   659
    for(var s in __device_services){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   660
      //__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
   661
      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
   662
      if (i != null){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   663
	return i;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   664
      }
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
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   667
  return null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   668
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   669
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   670
// Lazily fill in the descriptor table
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
function __device_update_descriptor(i){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   673
  var d = __device_get_descriptor(i);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   674
  i.name = d.interfaceName;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   675
  i.version = d.version;  
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   676
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   677
// Get an array of interface descriptors for a service
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
function __device_interface_list(s){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   680
  var retval = new Array();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   681
  for(var i in s.interfaces){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   682
    if(s.interfaces[i].name == null){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   683
      __device_update_descriptor(s.interfaces[i]);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   684
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   685
    if(s.interfaces[i].name == undefined){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   686
      continue;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   687
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   688
    retval[i] = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   689
    retval[i].name = s.interfaces[i].name;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   690
    retval[i].version = s.interfaces[i].version;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   691
  }  
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   692
  return retval;
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   695
// Get a service description
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
function __device_service_descriptor(s){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   698
  this.name = s.name;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   699
  this.version = s.version;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   700
  this.interfaces = __device_interface_list(s);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   701
  this.toString = __device_service_descriptor_to_string;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   702
}
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
function __device_service_descriptor_to_string(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   705
  var is = "\nInterfaces(s): ";
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 (i in this.interfaces){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   708
    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
   709
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   710
  return ("Service: " + this.name + is);
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   713
// Implement the listServices method 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   714
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   715
function __device_service_list(serviceName, interfaceName, version){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   716
  //__device_debug("__device_service_list: " + serviceName + " " + interfaceName);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   717
  __device_services_init();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   718
  var retval = new Array();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   719
  var n = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   720
  
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   721
  //Treat empty service and interface names as wildcards
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   722
  if ((serviceName == null)|| (serviceName == '')/* || (serviceName == undefined)*/){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   723
    serviceName = ".*"; 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   724
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   725
  if ((interfaceName == null) || (interfaceName == '') /*|| (serviceName == undefined)*/){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   726
    interfaceName = ".*";
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
  if ((typeof serviceName != "string") || (typeof interfaceName != "string")) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   730
  	return retval;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   731
  }
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
  // 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
   734
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   735
  var sregx = new RegExp(serviceName);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   736
  var iregx = new RegExp(interfaceName);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   737
 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   738
  for(var s in __device_services){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   739
   //__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
   740
    if (sregx.test(__device_services[s].name)){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   741
      // Find the first matching interface 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   742
        
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   743
      for(var i in __device_services[s].interfaces){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   744
        if(__device_services[s].interfaces[i].name == null){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   745
          __device_update_descriptor(__device_services[s].interfaces[i]);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   746
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   747
        if(__device_services[s].interfaces[i].name == undefined){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   748
	  continue;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   749
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   750
	//__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
   751
	if (iregx.test(__device_services[s].interfaces[i].name)){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   752
	  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
   753
            // An interface matched, we're done.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   754
            retval[n] = new __device_service_descriptor(__device_services[s]);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   755
            break; 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   756
	  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   757
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   758
      }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   759
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   760
    ++n;
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
  return retval;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   763
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   764
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   765
// Implement the listInterfaces method
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
function __device_service_interfaces(serviceName){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   768
  __device_services_init();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   769
  if(serviceName==null||serviceName==undefined||serviceName==''){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   770
  	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
   771
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   772
  for (var s in __device_services){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   773
    if(__device_services[s].name == serviceName){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   774
      return __device_interface_list(__device_services[s]);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   775
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   776
  }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   777
  return null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   778
}
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
function modifyObjectBaseProp(obj){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   781
  for (pro in obj) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   782
    if(typeof obj[pro] == "function" )
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   783
      obj[pro] = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   784
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   785
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   786
/*
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   787
Copyright © 2009 Nokia. All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   788
Code licensed under the BSD License:
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   789
Software License Agreement (BSD License) Copyright © 2009 Nokia.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   790
All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   791
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
   792
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   793
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
   794
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
   795
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
   796
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
   797
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   798
version: 1.0
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   799
*/
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   802
// S60 sp-based camera provider
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   803
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   804
function __sp_camera_descriptor(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   805
  //__device_debug("sp_camera_descriptor");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   806
  //Read-only properties
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   807
  this.interfaceName = "com.nokia.device.camera";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   808
  this.version = "0.1";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   809
  //Class-static properties 
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   812
// TBD make local to closure funcs
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   813
var __sp_camera_start_date;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   814
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   815
function __sp_camera_instance(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   816
  //__device_debug("sp_camera_instance");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   817
  //Descriptor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   818
  this.descriptor = new __sp_camera_descriptor();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   819
  //Core methods
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   820
  this.startCamera = __sp_startCamera;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   821
  this.stopViewfinder = __s60_api_not_supported;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   822
  //Extended methods
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   823
  this.takePicture = __s60_api_not_supported;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   824
  //Private data
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   825
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   826
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   827
var CAMERA_APP_ID = 0x101f857a;
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
//Apps should take care that this is not reinvoked
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   830
//while the viewfinder is running. 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   831
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   832
function __sp_startCamera(camera_cb){
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
	//If callback is null , then return missing argument error
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   835
    if( camera_cb == null )
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   836
        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
   837
        
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   838
	//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
   839
	if( typeof(camera_cb) != "function" )
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   840
	    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
   841
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   842
  var finished = function (){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   843
    var invoker = function (arg1, arg2, arg3){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   844
      //__device_debug("invoker with: " + camera_cb);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   845
      var it = arg3.ReturnValue;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   846
      var item;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   847
      var items = new Array();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   848
      while (( item = it.getNext()) != undefined){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   849
          var d = new Date(Date.parse(item.FileDate));
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   850
          //__device_debug(item.FileName + " " + d );
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   851
          // 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
   852
          // 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
   853
          // 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
   854
          if (d > __sp_camera_start_date) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   855
              var pathname = item.FileNameAndPath.replace(/\\/g, "/");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   856
              var fileScheme = "file:///";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   857
              //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
   858
              items.unshift(fileScheme + pathname);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   859
          }
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
      var dummyTransID = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   862
      var dummyStatusCode = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   863
      camera_cb(dummyTransID, dummyStatusCode, items);
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
    
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   867
    //When camera returns, get the image(s) created
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   868
    try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   869
      var mso = device.getServiceObject("Service.MediaManagement", "IDataSource");
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
    catch(e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   872
      __device_handle_exception (e, "media service not available : " + e);
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
    
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   875
    var criteria = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   876
	modifyObjectBaseProp(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   877
    criteria.Type = 'FileInfo';
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   878
    criteria.Filter = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   879
	modifyObjectBaseProp(criteria.Filter);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   880
    criteria.Filter.FileType = 'Image';
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   881
    //criteria.Filter.Key = 'FileDate';
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   882
    //criteria.Filter.StartRange = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   883
    //criteria.Filter.EndRange = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   884
    criteria.Sort = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   885
	modifyObjectBaseProp(criteria.Sort);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   886
    criteria.Sort.Key = 'FileDate';
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   887
    criteria.Sort.Order = 'Descending';
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
    try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   890
      var rval = mso.IDataSource.GetList(criteria, invoker);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   891
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   892
    catch (e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   893
      __device_handle_exception (e, "media service GetList failed: " + e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   894
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   895
  };
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
  __sp_camera_start_date = new Date();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   898
  __s60_start_and_wait(CAMERA_APP_ID, "", finished);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   899
  var dummyTid = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   900
  return dummyTid;
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
/*
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   905
Copyright © 2009 Nokia. All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   906
Code licensed under the BSD License:
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   907
Software License Agreement (BSD License) Copyright © 2009 Nokia.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   908
All rights reserved.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   909
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
   910
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   911
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
   912
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
   913
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
   914
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
   915
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   916
version: 1.0
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   917
*/
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
// Camera service interface
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   921
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   922
var __device_camera_service_entry =  {"name": null, 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   923
					 "version": null,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   924
					 "proto": __device_camera,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   925
					 "descriptor": __device_camera_descriptor,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   926
					 "providers": [{"descriptor": __sp_camera_descriptor, "instance": __sp_camera_instance}]
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   929
function __device_camera_descriptor(provider){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   930
  this.interfaceName = provider.interfaceName;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   931
  this.version = provider.version;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   932
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   933
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
// Private camera  prototype: called from service factory
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   936
function __device_camera(provider){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   937
  //Private properties
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   938
  this.provider = provider;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   939
  //Read-only properties
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   940
  this.interfaceName = provider.descriptor.interfaceName;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   941
  this.version = provider.descriptor.version;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   942
 // this.supportedMediaTypes = provider.supportedMediaTypes;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   943
 // this.supportedSizes = provider.supportedSizes;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   944
  //Core methods
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   945
  this.startCamera = __device_camera_startCamera;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   946
  this.stopViewfinder = __device_camera_stopViewfinder;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   947
  //Extended methods
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   948
  this.takePicture = __device_camera_takePicture;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   949
}
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   952
//Why bother to define these methods? Because the camera
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   953
//object defines the contract for providers!
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
function __device_camera_startCamera(camera_cb){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   956
  return this.provider.startCamera(camera_cb);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   957
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   958
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   959
function __device_camera_stopViewfinder(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   960
  this.provider.stopViewfinder();
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   963
function __device_camera_takePicture(format){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   964
  this.provider.takePicture(format);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   965
}
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
 * This class provides access to the device contacts.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   968
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   969
 */
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
function Contacts() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   972
	
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   975
function Contact() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   976
	this.id = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   977
	this.name = { 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   978
		formatted: "",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   979
		givenName: "",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   980
		familyName: ""
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   981
	};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   982
    this.phones = [];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   983
    this.emails = [];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   984
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   985
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   986
Contact.prototype.displayName = function()
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   987
{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   988
    // TODO: can be tuned according to prefs
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   989
	return this.givenName + " " + this.familyName;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   990
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   991
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   992
/*
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   993
 * @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
   994
 * @param {function} successCallback Callback function on success
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   995
 * @param {function} errorCallback Callback function on failure
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   996
 * @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
   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
Contacts.prototype.find = function(filter, successCallback, errorCallback, options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1000
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1001
		this.contactsService = device.getServiceObject("Service.Contact", "IDataSource");
340
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1002
		if (typeof options == 'object')
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1003
			this.options = options;
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1004
		else
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1005
			this.options = {};
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1006
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1007
		var criteria = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1008
		criteria.Type = "Contact";
340
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1009
		if (filter && filter.name) {
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1010
			var searchTerm = '';
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1011
			if (filter.name.givenName && filter.name.givenName.length > 0) {
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1012
				searchTerm += filter.name.givenName;
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1013
			}
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1014
			if (filter.name.familyName && filter.name.familyName.length > 0) {
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1015
				searchTerm += searchTerm.length > 0 ? ' ' + filter.name.familyName : filter.name.familyName;
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1016
			}
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1017
			if (!filter.name.familyName && !filter.name.givenName && filter.name.formatted) {
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1018
				searchTerm = filter.name.formatted;
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1019
			}
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1020
			criteria.Filter = { SearchVal: searchTerm };
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1021
		}
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1022
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1023
		if (typeof(successCallback) != 'function') 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1024
			successCallback = function(){};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1025
		if (typeof(errorCallback) != 'function') 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1026
			errorCallback = function(){};
340
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1027
		if (isNaN(this.options.limit))
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1028
			this.options.limit = 200;
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1029
		if (isNaN(this.options.page))
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1030
			this.options.page = 1;
310
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
		//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
  1033
		this.global_success = successCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1034
		var obj = this;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1035
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1036
		//WRT: result.ReturnValue is an iterator of contacts
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1037
		this.contactsService.IDataSource.GetList(criteria, function(transId, eventCode, result){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1038
			obj.success_callback(result.ReturnValue);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1039
		});
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1040
	} 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1041
	catch (ex) {
340
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1042
		alert(ex.name + ": " + ex.message);
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1043
		errorCallback(ex);
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
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1046
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1047
Contacts.prototype.success_callback = function(contacts_iterator) {
340
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1048
	try {
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1049
	var gapContacts = new Array();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1050
	contacts_iterator.reset();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1051
    var contact;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1052
	var i = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1053
	var end = this.options.page * this.options.limit;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1054
	var start = end - this.options.limit;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1055
	while ((contact = contacts_iterator.getNext()) != undefined && i < end) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1056
		try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1057
			if (i >= start) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1058
				var gapContact = new Contact();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1059
				gapContact.name.givenName = Contacts.GetValue(contact, "FirstName");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1060
				gapContact.name.familyName = Contacts.GetValue(contact, "LastName");
321
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1061
				gapContact.name.formatted = gapContact.name.givenName + " " + gapContact.name.familyName;
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1062
				gapContact.emails = Contacts.getEmailsList(contact);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1063
				gapContact.phones = Contacts.getPhonesList(contact);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1064
				gapContact.address = Contacts.getAddress(contact);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1065
				gapContact.id = Contacts.GetValue(contact, "id");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1066
				gapContacts.push(gapContact);
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
			i++;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1069
		} catch (e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1070
			alert("ContactsError (" + e.name + ": " + e.message + ")");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1071
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1072
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1073
	this.contacts = gapContacts;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1074
	this.global_success(gapContacts);
340
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1075
	} catch (ex) { alert(ex.name + ": " + ex.message); }
310
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
Contacts.getEmailsList = function(contact) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1079
	var emails = new Array();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1080
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1081
			emails[0] = { type:"General", address: Contacts.GetValue(contact, "EmailGen") };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1082
			emails[1] = { type:"Work", address: Contacts.GetValue(contact, "EmailWork") };		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1083
			emails[2] = { type:"Home", address: Contacts.GetValue(contact, "EmailHome") };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1084
	} catch (e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1085
		emails = [];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1086
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1087
	return emails;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1088
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1089
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1090
Contacts.getPhonesList = function(contact) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1091
	var phones = new Array();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1092
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1093
			phones[0] = { type:"Mobile", number: Contacts.GetValue(contact, "MobilePhoneGen") };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1094
			phones[1] = { type:"Home", number: Contacts.GetValue(contact, "LandPhoneGen") };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1095
			phones[2] = { type:"Fax", number: Contacts.GetValue(contact, "FaxNumberGen") };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1096
			phones[3] = { type:"Work", number: Contacts.GetValue(contact, "LandPhoneWork") };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1097
			phones[4] = { type:"WorkMobile", number: Contacts.GetValue(contact, "MobilePhoneWork") };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1098
	} catch (e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1099
		phones = [];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1100
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1101
	return phones;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1102
};
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
Contacts.getAddress = function(contact) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1105
	var address = "";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1106
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1107
		address = Contacts.GetValue(contact, "AddrLabelHome") + ", " + Contacts.GetValue(contact, "AddrStreetHome") + ", " +
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1108
				Contacts.GetValue(contact, "AddrLocalHome") + ", " + Contacts.GetValue(contact, "AddrRegionHome") + ", " + 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1109
				Contacts.GetValue(contact, "AddrPostCodeHome") + ", " + Contacts.GetValue(contact, "AddrCountryHome");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1110
	} catch (e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1111
		address = "";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1112
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1113
	return address;
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1116
Contacts.GetValue = function(contactObj, key) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1117
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1118
		return contactObj[key]["Value"];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1119
	} catch (e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1120
		return "";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1121
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1122
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1123
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1124
if (typeof navigator.contacts == "undefined") navigator.contacts = new Contacts();
321
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1125
/**
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1126
 * This class provides access to the debugging console.
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1127
 * @constructor
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1128
 */
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1129
function DebugConsole() {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1130
}
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1131
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1132
/**
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1133
 * Print a normal log message to the console
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1134
 * @param {Object|String} message Message or object to print to the console
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1135
 */
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1136
DebugConsole.prototype.log = function(message) {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1137
	
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1138
	//This ends up in C:\jslog_widget.log on the device
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1139
	console.log(message);
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1140
};
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1141
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1142
/**
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1143
 * Print a warning message to the console
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1144
 * @param {Object|String} message Message or object to print to the console
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1145
 */
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1146
DebugConsole.prototype.warn = function(message) {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1147
};
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1148
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1149
/**
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1150
 * Print an error message to the console
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1151
 * @param {Object|String} message Message or object to print to the console
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1152
 */
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1153
DebugConsole.prototype.error = function(message) {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1154
};
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1155
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1156
if (typeof window.debug == "undefined") window.debug = new DebugConsole();
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1157
PhoneGap.ExtendWrtDeviceObj = function(){
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
	if (!window.device)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1160
		window.device = {};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1161
	navigator.device = window.device;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1162
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1163
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1164
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1165
		if (window.menu)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1166
	    	window.menu.hideSoftkeys();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1167
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1168
		device.available = PhoneGap.available;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1169
		device.platform = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1170
		device.version = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1171
		device.name = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1172
		device.uuid = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1173
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1174
		var so = device.getServiceObject("Service.SysInfo", "ISysInfo");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1175
		var pf = PhoneGap.GetWrtPlatformVersion(so);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1176
		device.platform = pf.platform;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1177
		device.version = pf.version;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1178
		device.uuid = PhoneGap.GetWrtDeviceProperty(so, "IMEI");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1179
		device.name = PhoneGap.GetWrtDeviceProperty(so, "PhoneModel");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1180
	} 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1181
	catch (e) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1182
		device.available = false;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1183
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1184
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1185
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1186
PhoneGap.GetWrtDeviceProperty = function(serviceObj, key) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1187
	var criteria = { "Entity": "Device", "Key": key };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1188
	var result = serviceObj.ISysInfo.GetInfo(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1189
	if (result.ErrorCode == 0) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1190
		return result.ReturnValue.StringData;
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
	else {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1193
		return null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1194
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1195
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1196
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1197
PhoneGap.GetWrtPlatformVersion = function(serviceObj) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1198
	var criteria = { "Entity": "Device", "Key": "PlatformVersion" };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1199
	var result = serviceObj.ISysInfo.GetInfo(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1200
	if (result.ErrorCode == 0) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1201
		var version = {};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1202
		version.platform = result.ReturnValue.MajorVersion;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1203
		version.version = result.ReturnValue.MinorVersion;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1204
		return version;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1205
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1206
	else {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1207
		return null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1208
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1209
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1210
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1211
PhoneGap.ExtendWrtDeviceObj();/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1212
 * This class provides access to device GPS data.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1213
 * @constructor
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
function Geolocation() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1216
    /**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1217
     * The last known GPS position.
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
    this.lastPosition = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1220
    this.lastError = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1221
    this.callbacks = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1222
        onLocationChanged: [],
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1223
        onError:           []
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1224
    };
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1227
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1228
 * Asynchronously aquires the current position.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1229
 * @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
  1230
 * data is available
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1231
 * @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
  1232
 * getting the position data.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1233
 * @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
  1234
 * such as timeout.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1235
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1236
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1237
    var referenceTime = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1238
    if (this.lastPosition)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1239
        referenceTime = this.lastPosition.timestamp;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1240
    else
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1241
        this.start(options);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1242
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1243
    var timeout = 20000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1244
    var interval = 500;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1245
    if (typeof(options) == 'object' && options.interval)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1246
        interval = options.interval;
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
    if (typeof(successCallback) != 'function')
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1249
        successCallback = function() {};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1250
    if (typeof(errorCallback) != 'function')
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1251
        errorCallback = function() {};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1252
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1253
    var dis = this;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1254
    var delay = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1255
    var timer = setInterval(function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1256
        delay += interval;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1257
		//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
  1258
        if (dis.lastPosition && dis.lastPosition.timestamp > referenceTime) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1259
            successCallback(dis.lastPosition);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1260
            clearInterval(timer);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1261
        } 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
  1262
            errorCallback();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1263
            clearInterval(timer);
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
		//else the interval gets called again
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1266
    }, interval);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1267
};
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
 * Asynchronously aquires the position repeatedly at a given interval.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1271
 * @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
  1272
 * data is available
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1273
 * @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
  1274
 * getting the position data.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1275
 * @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
  1276
 * such as timeout and the frequency of the watch.
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
Geolocation.prototype.watchPosition = function(successCallback, errorCallback, options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1279
	// 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
  1280
	// 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
  1281
	this.getCurrentPosition(successCallback, errorCallback, options);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1282
	var frequency = 10000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1283
        if (typeof options == 'object' && options.frequency)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1284
            frequency = options.frequency;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1285
	var that = this;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1286
	return setInterval(function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1287
		that.getCurrentPosition(successCallback, errorCallback, options);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1288
	}, frequency);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1289
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1290
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1291
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1292
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1293
 * Clears the specified position watch.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1294
 * @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
  1295
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1296
Geolocation.prototype.clearWatch = function(watchId) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1297
	clearInterval(watchId);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1298
};
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
Geolocation.prototype.start = function(options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1301
	var so = device.getServiceObject("Service.Location", "ILocation");
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
	//construct the criteria for our location request
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1304
	var updateOptions = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1305
	// 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
  1306
	// 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
  1307
	updateOptions.PartialUpdates = true;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1308
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1309
	//default 15 seconds
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1310
	if (typeof(options) == 'object' && options.timeout) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1311
		//options.timeout in in ms, updateOptions.UpdateTimeout in microsecs
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1312
		updateOptions.UpdateTimeOut = options.timeout * 1000;
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
	//default 1 second
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1315
	if (typeof(options) == 'object' && options.interval) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1316
		//options.timeout in in ms, updateOptions.UpdateTimeout in microsecs
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1317
		updateOptions.UpdateInterval = options.interval * 1000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1318
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1319
	// Initialize the criteria for the GetLocation call
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1320
	var trackCriteria = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1321
	// could use "BasicLocationInformation" or "GenericLocationInfo"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1322
	trackCriteria.LocationInformationClass = "GenericLocationInfo";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1323
	trackCriteria.Updateoptions = updateOptions;
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
	var dis = this;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1326
	so.ILocation.Trace(trackCriteria, function(transId, eventCode, result) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1327
		var retVal = result.ReturnValue;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1328
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1329
		if (result.ErrorCode != 0 || isNaN(retVal.Latitude))
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1330
			return;
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
		// 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
  1333
		// 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
  1334
		// WRT does not provide accuracy
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1335
		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
  1336
		var positionObj = { coords: newCoords, timestamp: (new Date()).getTime() };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1337
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1338
		dis.lastPosition = positionObj;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1339
	});
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1340
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1341
};
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
if (typeof navigator.geolocation == "undefined") navigator.geolocation = new Geolocation();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1345
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1346
/**
321
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1347
 * This class provides access to native mapping applications on the device.
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1348
 */
321
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1349
function Map() {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1350
	
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1351
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1352
321
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1353
/**
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1354
 * Shows a native map on the device with pins at the given positions.
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1355
 * @param {Array} positions
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1356
 */
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1357
Map.prototype.show = function(positions) {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1358
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1359
	var err = "map api is unimplemented on symbian.wrt";
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1360
	debug.log(err);
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1361
	return { name: "MapError", message: err };
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1362
310
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
321
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1365
if (typeof navigator.map == "undefined") navigator.map = new Map();
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1366
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1367
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1368
 * This class provides access to notifications on the device.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1369
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1370
function Notification() {
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
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1374
Notification.prototype.vibrate = function(mills)
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 (!Notification.getSysinfoObject())
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1378
		Notification.embedSysinfoObject();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1379
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1380
	this.sysinfo = Notification.getSysinfoObject();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1381
	this.sysinfo.startvibra(mills, 100);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1382
};
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
//TODO: this is not beeping
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1385
Notification.prototype.beep = function(count, volume)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1386
{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1387
	if (!Notification.getSysinfoObject())
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1388
		Notification.embedSysinfoObject();
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
	this.sysinfo = Notification.getSysinfoObject();	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1391
	this.sysinfo.beep(220,2000);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1392
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1393
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1394
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
 * 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
  1397
 * @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
  1398
 * @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
  1399
 * @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
  1400
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1401
Notification.prototype.alert = function(message, title, buttonLabel) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1402
    // 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
  1403
    alert(message);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1404
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1405
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1406
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1407
 * Start spinning the activity indicator on the statusbar
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1408
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1409
Notification.prototype.activityStart = function() {
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
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1413
 * 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
  1414
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1415
Notification.prototype.activityStop = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1416
};
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
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1419
 * Causes the device to blink a status LED.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1420
 * @param {Integer} count The number of blinks.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1421
 * @param {String} colour The colour of the light.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1422
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1423
Notification.prototype.blink = function(count, colour) {
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
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1426
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1427
Notification.embedSysinfoObject = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1428
	var el = document.createElement("embed");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1429
	el.setAttribute("type", "application/x-systeminfo-widget");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1430
	el.setAttribute("hidden", "yes");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1431
	document.getElementsByTagName("body")[0].appendChild(el);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1432
	return;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1433
};
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
Notification.getSysinfoObject = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1436
	return document.embeds[0];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1437
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1438
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1439
if (typeof navigator.notification == "undefined") navigator.notification = new Notification();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1440
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1441
 * This class provides access to the device orientation.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1442
 * @constructor
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
function Orientation() {
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
	 * 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
  1447
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1448
	this.currentOrientation = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1449
}
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
 * 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
  1453
 * 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1454
 * 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
  1455
 * 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
  1456
 * 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
  1457
 *
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1458
 * @param {Number} orientation The orientation to be set
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1459
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1460
Orientation.prototype.setOrientation = function(orientation) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1461
		if (orientation == this.currentOrientation) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1462
			return;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1463
		var old = this.currentOrientation;
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.currentOrientation = orientation;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1466
		var e = document.createEvent('Events');
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1467
		e.initEvent('orientationChanged', 'false', 'false');
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1468
		e.orientation = orientation;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1469
		e.oldOrientation = old;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1470
		document.dispatchEvent(e);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1471
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1472
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
 * Asynchronously aquires the current orientation.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1475
 * @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
  1476
 * is known.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1477
 * @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
  1478
 * getting the orientation.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1479
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1480
Orientation.prototype.getCurrentOrientation = function(successCallback, errorCallback) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1481
	// If the orientation is available then call success
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1482
	// If the orientation is not available then call error
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1483
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1484
		if (!this.serviceObj) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1485
			this.serviceObj = this.getServiceObj();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1486
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1487
		if (this.serviceObj == null) 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1488
			errorCallback({
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1489
				name: "DeviceErr",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1490
				message: "Could not initialize service object"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1491
			});
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1492
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1493
		//get the sensor channel
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1494
		var SensorParams = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1495
			SearchCriterion: "Orientation"
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
		var returnvalue = this.serviceObj.ISensor.FindSensorChannel(SensorParams);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1498
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1499
		var error = returnvalue["ErrorCode"];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1500
		var errmsg = returnvalue["ErrorMessage"];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1501
		if (!(error == 0 || error == 1012)) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1502
			var ex = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1503
				name: "Unable to find Sensor Channel: " + error,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1504
				message: errmsg
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
			errorCallback(ex);
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
		var channelInfoMap = returnvalue["ReturnValue"][0];
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1509
		var criteria = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1510
			ChannelInfoMap: channelInfoMap,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1511
			ListeningType: "ChannelData"
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1512
		};
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
		if (typeof(successCallback) != 'function') 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1515
			successCallback = function(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1516
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1517
		if (typeof(errorCallback) != 'function') 
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1518
			errorCallback = function(){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1519
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1520
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1521
		this.success_callback = successCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1522
		this.error_callback = errorCallback;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1523
		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1524
		//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
  1525
		var obj = this;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1526
		
321
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1527
		// TODO: this call crashes WRT, but there is no other way to read the orientation sensor
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1528
		// http://discussion.forum.nokia.com/forum/showthread.php?t=182151&highlight=memory+leak
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1529
		this.serviceObj.ISensor.RegisterForNotification(criteria, function(transId, eventCode, result){
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1530
			var criteria = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1531
				TransactionID: transId
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1532
			};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1533
			try {
321
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1534
				//var orientation = result.ReturnValue.DeviceOrientation;
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1535
				obj.serviceObj.ISensor.Cancel(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1536
				
321
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1537
				var orientation = null;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1538
				switch (result.ReturnValue.DeviceOrientation) {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1539
					case "DisplayUpwards": orientation = DisplayOrientation.FACE_UP; break;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1540
					case "DisplayDownwards": orientation = DisplayOrientation.FACE_DOWN; break;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1541
					case "DisplayUp": orientation = DisplayOrientation.PORTRAIT; break;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1542
					case "DisplayDown": orientation = DisplayOrientation.REVERSE_PORTRAIT; break;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1543
					case "DisplayRightUp": orientation = DisplayOrientation.LANDSCAPE_RIGHT_UP; break;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1544
					case "DisplayLeftUp": orientation = DisplayOrientation.LANDSCAPE_LEFT_UP; break;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1545
					
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1546
				}
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1547
				
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1548
				obj.setOrientation(orientation);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1549
				
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1550
				obj.success_callback(orientation);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1551
				
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
			catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1554
				obj.serviceObj.ISensor.Cancel(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1555
				obj.error_callback(ex);
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
			
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
	} catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1560
		errorCallback({ name: "OrientationError", message: ex.name + ": " + ex.message });
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1561
	}
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
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
 * Asynchronously aquires the orientation repeatedly at a given interval.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1566
 * @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
  1567
 * data is available.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1568
 * @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
  1569
 * getting the orientation data.
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
Orientation.prototype.watchOrientation = function(successCallback, errorCallback, options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1572
	// 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
  1573
	// 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
  1574
	this.getCurrentOrientation(successCallback, errorCallback);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1575
	var frequency = (options != undefined)? options.frequency : 1000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1576
	return setInterval(function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1577
		navigator.orientation.getCurrentOrientation(successCallback, errorCallback);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1578
	}, frequency);
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
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
 * Clears the specified orientation watch.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1583
 * @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
  1584
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1585
Orientation.prototype.clearWatch = function(watchId) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1586
	clearInterval(watchId);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1587
};
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
//gets the Acceleration Service Object from WRT
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1590
Orientation.prototype.getServiceObj = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1591
	var so;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1592
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1593
    try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1594
        so = device.getServiceObject("Service.Sensor", "ISensor");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1595
    } catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1596
		throw {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1597
			name: "DeviceError",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1598
			message: ex.name + ": " + ex.message
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1599
		};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1600
    }		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1601
	return so;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1602
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1603
321
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1604
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1605
/**
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1606
 * This class encapsulates the possible orientation values.
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1607
 * @constructor
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1608
 */
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1609
function DisplayOrientation() {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1610
	this.code = null;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1611
	this.message = "";
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1612
}
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1613
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1614
DisplayOrientation.PORTRAIT = 0;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1615
DisplayOrientation.REVERSE_PORTRAIT = 1;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1616
DisplayOrientation.LANDSCAPE_LEFT_UP = 2;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1617
DisplayOrientation.LANDSCAPE_RIGHT_UP = 3;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1618
DisplayOrientation.FACE_UP = 4;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1619
DisplayOrientation.FACE_DOWN = 5;
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1620
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1621
if (typeof navigator.orientation == "undefined") navigator.orientation = new Orientation();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1622
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1623
 * This class contains position information.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1624
 * @param {Object} lat
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1625
 * @param {Object} lng
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1626
 * @param {Object} acc
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1627
 * @param {Object} alt
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1628
 * @param {Object} altacc
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1629
 * @param {Object} head
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1630
 * @param {Object} vel
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1631
 * @constructor
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
function Position(coords, timestamp) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1634
	this.coords = coords;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1635
        this.timestamp = new Date().getTime();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1636
}
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
function Coordinates(lat, lng, alt, acc, head, vel) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1639
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1640
	 * The latitude of the position.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1641
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1642
	this.latitude = lat;
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
	 * The longitude of the position,
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
	this.longitude = lng;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1647
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1648
	 * The accuracy of the position.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1649
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1650
	this.accuracy = acc;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1651
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1652
	 * The altitude of the position.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1653
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1654
	this.altitude = alt;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1655
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1656
	 * The direction the device is moving at the position.
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
	this.heading = head;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1659
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1660
	 * 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
  1661
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1662
	this.speed = vel;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1663
}
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
 * This class specifies the options for requesting position data.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1667
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1668
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1669
function PositionOptions() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1670
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1671
	 * Specifies the desired position accuracy.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1672
	 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1673
	this.enableHighAccuracy = true;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1674
	/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1675
	 * 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
  1676
	 * is called.
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
	this.timeout = 10000;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1679
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1680
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1681
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1682
 * This class contains information about any GSP errors.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1683
 * @constructor
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1684
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1685
function PositionError() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1686
	this.code = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1687
	this.message = "";
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
PositionError.UNKNOWN_ERROR = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1691
PositionError.PERMISSION_DENIED = 1;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1692
PositionError.POSITION_UNAVAILABLE = 2;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1693
PositionError.TIMEOUT = 3;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1694
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1695
 * This class provides access to the device SMS functionality.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1696
 * @constructor
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
function Sms() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1699
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1700
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1701
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1702
/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1703
 * Sends an SMS message.
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1704
 * @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
  1705
 * @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
  1706
 * @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
  1707
 * @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
  1708
 * @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
  1709
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1710
Sms.prototype.send = function(number, message, successCallback, errorCallback, options) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1711
    try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1712
		if (!this.serviceObj)
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1713
			this.serviceObj = this.getServiceObj();
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
	    // Setup input params using dot syntax
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1716
	    var criteria = new Object();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1717
	    criteria.MessageType = 'SMS';
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1718
	    criteria.To = number;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1719
	    criteria.BodyText = message;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1720
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1721
      	var result = this.serviceObj.IMessaging.Send(criteria);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1722
    	if (result.ErrorCode != 0 && result.ErrorCode != "0")
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1723
		{
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1724
			var exception = { name: "SMSError", message: result.ErrorMessage };
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1725
			throw exception;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1726
		} else {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1727
			successCallback.call();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1728
		}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1729
    }
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1730
  	catch(ex)
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
		errorCallback.call({ name: "SmsError", message: ex.name + ": " + ex.message });
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1733
  	}
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
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1736
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1737
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1738
//gets the Sms Service Object from WRT
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1739
Sms.prototype.getServiceObj = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1740
	var so;
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
    try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1743
        so = device.getServiceObject("Service.Messaging", "IMessaging");
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1744
    } catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1745
		throw {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1746
			name: "SmsError",
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1747
			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
  1748
		};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1749
    }		
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1750
	return so;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1751
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1752
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1753
if (typeof navigator.sms == "undefined") navigator.sms = new Sms();/**
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1754
 * @author ryan
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1755
 */
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1756
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1757
function Storage() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1758
	this.available = true;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1759
	this.serialized = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1760
	this.items = null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1761
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1762
	if (!window.widget) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1763
		this.available = false;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1764
		return;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1765
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1766
	var pref = window.widget.preferenceForKey(Storage.PREFERENCE_KEY);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1767
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1768
	//storage not yet created
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1769
	if (pref == "undefined" || pref == undefined) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1770
		this.length = 0;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1771
		this.serialized = "({})";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1772
		this.items = {};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1773
		window.widget.setPreferenceForKey(this.serialized, Storage.PREFERENCE_KEY);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1774
	} else {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1775
		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
  1776
		this.items = eval(this.serialized);
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1777
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1778
}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1779
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1780
Storage.PREFERENCE_KEY = "phonegap_storage_pref_key";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1781
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1782
Storage.prototype.index = function (key) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1783
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1784
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1785
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1786
Storage.prototype.getItem = function (key) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1787
	try {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1788
		return this.items[key].data;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1789
	} catch (ex) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1790
		return null;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1791
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1792
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1793
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1794
Storage.prototype.setItem = function (key, data) {
340
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1795
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1796
	this.items[key] = {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1797
		"key": key,
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1798
		"data": data
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1799
	};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1800
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1801
	this.serialize();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1802
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1803
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1804
Storage.prototype.removeItem = function (key) {
340
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1805
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1806
	if (this.items[key]) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1807
		this.items[key] = undefined;
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1808
	}
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1809
	this.serialize();
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1810
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1811
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1812
Storage.prototype.clear = function () {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1813
	this.serialized = "({})";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1814
	this.items = {};
340
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1815
	this.serialize();
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1816
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1817
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1818
Storage.prototype.serialize = function() {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1819
	var json = "";
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1820
	
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1821
	for (key in this.items) {
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1822
		var item = this.items[key];
340
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1823
		if (typeof item != "undefined") {
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1824
			json += "\"" + item.key + "\": { \"key\": \"" + item.key + "\", \"data\": \"" + item.data + "\" }, ";
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1825
		}
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1826
	}
340
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1827
	this.serialized = "({" + json + "})";
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1828
340
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1829
	window.widget.setPreferenceForKey( this.serialized, Storage.PREFERENCE_KEY);
310
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1830
};
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1831
e9484be98cfe UI to add libraries was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
  1832
if (typeof navigator.storage == "undefined" ) navigator.storage = new Storage();
321
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1833
/**
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1834
 * This class provides access to the telephony features of the device.
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1835
 * @constructor
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1836
 */
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1837
function Telephony() {
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1838
	this.number = "";
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1839
}
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1840
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1841
/**
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1842
 * Calls the specifed number.
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1843
 * @param {Integer} number The number to be called.
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1844
 */
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1845
Telephony.prototype.send = function(number) {
340
740921999de7 Bug 2784 - Update bundled PhoneGap libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 321
diff changeset
  1846
	widget.openURL('tel:+' + number);
321
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1847
};
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1848
b99b8311285c PhoneGap library was updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 310
diff changeset
  1849
if (typeof navigator.telephony == "undefined") navigator.telephony = new Telephony();