incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From becka...@apache.org
Subject [35/50] git commit: added source and target to error object for upload and download
Date Fri, 13 Jan 2012 15:59:07 GMT
added source and target to error object for upload and download


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/0ecbea15
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/0ecbea15
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/0ecbea15

Branch: refs/heads/master
Commit: 0ecbea15849b79cbdc4e53b08f0807cce4a1f088
Parents: 78aa7f1
Author: Alexander Keller <ak@aflx.de>
Authored: Wed Nov 30 09:43:58 2011 +0100
Committer: Alexander Keller <ak@aflx.de>
Committed: Wed Nov 30 09:43:58 2011 +0100

----------------------------------------------------------------------
 PhoneGapLib/Classes/FileTransfer.h |    7 ++++-
 PhoneGapLib/Classes/FileTransfer.m |   39 +++++++++++++++++++++---------
 2 files changed, 33 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/0ecbea15/PhoneGapLib/Classes/FileTransfer.h
----------------------------------------------------------------------
diff --git a/PhoneGapLib/Classes/FileTransfer.h b/PhoneGapLib/Classes/FileTransfer.h
index 5a0428a..6b331ba 100644
--- a/PhoneGapLib/Classes/FileTransfer.h
+++ b/PhoneGapLib/Classes/FileTransfer.h
@@ -28,19 +28,24 @@ typedef int FileTransferError;
 -(void) downloadFile:(NSMutableArray*)arguments;
 -(void) downloadSuccess:(NSMutableArray*)arguments; 
 -(void) downloadFail:(NSMutableArray*)arguments; 
+
+-(NSMutableDictionary*) createFileTransferError:(NSString*)code AndSource:(NSString*)source
AndTarget:(NSString*)target;
 @end
 
 
 @interface FileTransferDelegate : NSObject {
 	PGFileTransfer* command;
 	NSString* callbackId;
+	NSString* source;
+	NSString* target;
     NSInteger bytesWritten;
-    
 }
 
 @property (nonatomic, retain) NSMutableData* responseData;
 @property (nonatomic, retain) PGFileTransfer* command;
 @property (nonatomic, retain) NSString* callbackId;
+@property (nonatomic, retain) NSString* source;
+@property (nonatomic, retain) NSString* target;
 @property NSInteger bytesWritten;
 
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/0ecbea15/PhoneGapLib/Classes/FileTransfer.m
----------------------------------------------------------------------
diff --git a/PhoneGapLib/Classes/FileTransfer.m b/PhoneGapLib/Classes/FileTransfer.m
index b1050df..9587874 100644
--- a/PhoneGapLib/Classes/FileTransfer.m
+++ b/PhoneGapLib/Classes/FileTransfer.m
@@ -63,7 +63,10 @@
     }
     
     if(errorCode > 0) {
-        result = [PluginResult resultWithStatus: PGCommandStatus_OK messageAsInt: INVALID_URL_ERR
cast: @"navigator.fileTransfer._castTransferError"];
+        //result = [PluginResult resultWithStatus: PGCommandStatus_OK messageAsInt: INVALID_URL_ERR
cast: @"navigator.fileTransfer._castTransferError"];
+        
+        result = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsDictionary: [self
createFileTransferError:[NSString stringWithFormat:@"%d", errorCode] AndSource:filePath AndTarget:server]];
+        
         [self writeJavascript:[result toErrorCallbackString:callbackId]];
         return;
     }
@@ -130,6 +133,8 @@
 	FileTransferDelegate* delegate = [[[FileTransferDelegate alloc] init] autorelease];
 	delegate.command = self;
     delegate.callbackId = callbackId;
+    delegate.source = server;
+    delegate.target = filePath;
 	
 	[NSURLConnection connectionWithRequest:req delegate:delegate];
     
@@ -163,7 +168,7 @@
         
         if ( response == NO ) {
         	// send our results back to the main thread
-            results = [NSArray arrayWithObjects: callbackId, [error description], nil];
+            results = [NSArray arrayWithObjects: callbackId, [NSString stringWithFormat:@"%d",
INVALID_URL_ERR], sourceUrl, filePath, nil];
         	[self performSelectorOnMainThread:@selector(downloadFail:) withObject:results waitUntilDone:YES];
     	} else {
         	// jump back to main thread
@@ -172,10 +177,9 @@
     	}
     }
     @catch (id exception) {
-        NSLog(@"File Transfer Error %@", [error description]);
-            
         // jump back to main thread
-        [self performSelectorOnMainThread:@selector(fail:) withObject:[error description]
waitUntilDone:YES];
+        results = [NSArray arrayWithObjects: callbackId, [NSString stringWithFormat:@"%d",
FILE_NOT_FOUND_ERR], sourceUrl, filePath, nil];
+        [self performSelectorOnMainThread:@selector(downloadFail:) withObject:results waitUntilDone:YES];
     }
     
     [pool drain];
@@ -199,22 +203,33 @@
 -(void) downloadFail:(NSMutableArray *)arguments 
 {
     NSString * callbackId = [arguments objectAtIndex:0];
-    NSString * error = [arguments objectAtIndex:1];
-    
-    NSLog(@"File Transfer Error: %@", [error description]);
+    NSString * code = [arguments objectAtIndex:1];
+    NSString * source = [arguments objectAtIndex:2];
+    NSString * target = [arguments objectAtIndex:3];
+
+    NSLog(@"File Transfer Error: %@", source);
     
-    PluginResult* pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString:

-                                    [error stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
+    PluginResult* pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsDictionary:
[self createFileTransferError:code AndSource:source AndTarget:target]];
                                     
     [self writeJavascript: [pluginResult toErrorCallbackString:callbackId]];
 }
 
+-(NSMutableDictionary*) createFileTransferError:(NSString*)code AndSource:(NSString*)source
AndTarget:(NSString*)target
+{
+    NSMutableDictionary* result = [NSMutableDictionary dictionaryWithCapacity:3];
+    [result setObject: code forKey:@"code"];
+	[result setObject: source forKey:@"source"];
+	[result setObject: target forKey:@"target"];
+    
+    return result;
+}
+
 @end
 
 
 @implementation FileTransferDelegate
 
-@synthesize callbackId, responseData, command, bytesWritten;
+@synthesize callbackId, source, target, responseData, command, bytesWritten;
 
 
 - (void)connectionDidFinishLoading:(NSURLConnection *)connection 
@@ -232,7 +247,7 @@
 
 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
 {
-    PluginResult* result = [PluginResult resultWithStatus: PGCommandStatus_OK messageAsInt:
CONNECTION_ERR cast: @"navigator.fileTransfer._castTransferError"];
+    PluginResult* result = [PluginResult resultWithStatus: PGCommandStatus_OK messageAsDictionary:
[command createFileTransferError: [NSString stringWithFormat: @"%d", CONNECTION_ERR] AndSource:source
AndTarget:target]];
     NSLog(@"File Transfer Error: %@", [error localizedDescription]);
     [command writeJavascript:[result toErrorCallbackString: callbackId]];
 }


Mime
View raw message