<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
paddingBottom="0"
paddingLeft="0"
paddingRight="0"
paddingTop="0" creationComplete="init()" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import configure;
import progress;
public var so:SharedObject = SharedObject.getLocal("user_options");
import com.adobe.air.notification.*;
private var purr:Purr = new Purr(1);
static private var filesUploading:Number = 0;
public namespace atom = "http://www.w3.org/2005/Atom";
use namespace atom;
public function init():void {
NativeApplication.nativeApplication.setAsDefaultApplication('doc');
NativeApplication.nativeApplication.setAsDefaultApplication('xls');
NativeApplication.nativeApplication.setAsDefaultApplication('ppt');
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, invoked);
if(!so.data.auth){
configure.open();
}
}
public function invoked(e:InvokeEvent):void {
if(e.arguments && so.data.auth){
for(var i:int=0; i < e.arguments.length; i++){
uploadFile(e.arguments[i]);
}
}
}
public function exitUnlessFilesUploading():void {
if(filesUploading == 0) {
setInterval(NativeApplication.nativeApplication.exit, 5)
}
}
public function uploadFile(path:String):void {
filesUploading += 1;
var file:File = new File();
file.nativePath = path;
this.purr.addTextNotificationByParams('Airdoc', 'Uploading ' + truncate(file.name, 25));
this.purr.alert(NotificationType.INFORMATIONAL, null);
file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, function(e:DataEvent):void{
var data:XML = new XML(e.data);
navigateToURL(new URLRequest(data.atom::link.(@rel=='alternate').@href));
filesUploading -= 1;
exitUnlessFilesUploading();
});
var ct:String = file.type;
switch(file.extension){
case 'doc':
ct = 'application/msword';
break;
case 'xls':
ct = 'application/vnd.ms-excel';
break;
case 'ppt':
ct = 'application/vnd.ms-powerpoint';
break;
}
var upR:URLRequest = new URLRequest('http://docs.google.com/feeds/documents/private/full')
var header1:URLRequestHeader = new URLRequestHeader('Authorization', 'GoogleLogin auth=' + this.so.data.auth);
var header2:URLRequestHeader = new URLRequestHeader('Slug', file.name);
var header3:URLRequestHeader = new URLRequestHeader('Content-Type', ct);
upR.requestHeaders = [header1, header2, header3];
upR.followRedirects = true;
upR.method = URLRequestMethod.POST;
file.uploadUnencoded(upR);
}
private function truncate(txt:String, len:Number):String {
if(txt.length > len){
return txt.substr(0, len - 3) + '...'
} else {
return txt
}
}
]]>
</mx:Script>
</mx:Application>