/* Copyright 2009 Palm, Inc.  All rights reserved. */

Weave.Services.ApplicationInstaller = 
{
	_target: 'palm://com.palm.appinstaller',
	
	validateInstall: function(appid, size, uncomprSize, callback)
	{
		uncomprSize = (uncomprSize && uncomprSize != 0) ? Math.ceil(uncomprSize/1024): undefined;
		size = Math.ceil(size/1024);
		Mojo.Log.info("Weave.Services.ApplicationInstaller.validateInstall appid %s, size %s, uncomprSize %d", appid,size,uncomprSize );
		var self = this;
		this._pendingreq = Weave.Services.request(self._target, 
		{
			method: 'queryInstallCapacity',
			parameters: 
			{
				appId: appid,
				size: size,
				uncompressedSize: uncomprSize,
			},
		},
		function(response)
		{
			if (response.result == 0 || response.result == 4  || PalmSystem.version.match("desktop")) 
			{
				callback(true);
			}
			else
			{
				Mojo.Log.error("Weave.Services.ApplicationInstaller.validateInstall failed %j", response);
				callback(false, response);
			}
		},
		function(response)
		{
			Mojo.Log.error("Weave.Services.ApplicationInstaller.validateInstall failed %j", response);
			callback(false);
		});
	},
	
};