You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/08/03 17:18:02 UTC

[7/9] ios commit: Update CDVCamera and CDVCapture to new exec format.

Update CDVCamera and CDVCapture to new exec format.


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/886a4fc0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/886a4fc0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/886a4fc0

Branch: refs/heads/master
Commit: 886a4fc0283061abaaa7593befc8ff7767e4faf5
Parents: 01eb22d
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Aug 3 09:55:26 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Aug 3 11:16:58 2012 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/CDVCamera.h  |    4 +-
 CordovaLib/Classes/CDVCamera.m  |   52 +++++++++++++++++----------------
 CordovaLib/Classes/CDVCapture.h |   10 +++---
 CordovaLib/Classes/CDVCapture.m |   26 +++++++++--------
 4 files changed, 48 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/886a4fc0/CordovaLib/Classes/CDVCamera.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.h b/CordovaLib/Classes/CDVCamera.h
index d7f17ad..536b442 100644
--- a/CordovaLib/Classes/CDVCamera.h
+++ b/CordovaLib/Classes/CDVCamera.h
@@ -80,9 +80,9 @@ typedef NSUInteger CDVMediaType;
  * options:
  *	quality: integer between 1 and 100
  */
-- (void) takePicture:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void) takePicture:(CDVInvokedUrlCommand*)command;
 - (void) postImage:(UIImage*)anImage withFilename:(NSString*)filename toUrl:(NSURL*)url;
-- (void) cleanup:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void) cleanup:(CDVInvokedUrlCommand*)command;
 
 - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info;
 - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)image editingInfo:(NSDictionary*)editingInfo;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/886a4fc0/CordovaLib/Classes/CDVCamera.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.m b/CordovaLib/Classes/CDVCamera.m
index cc691a0..18cf26b 100644
--- a/CordovaLib/Classes/CDVCamera.m
+++ b/CordovaLib/Classes/CDVCamera.m
@@ -18,6 +18,7 @@
  */
 
 #import "CDVCamera.h"
+#import "NSArray+Comparisons.h"
 #import "NSData+Base64.h"
 #import "NSDictionary+Extensions.h"
 #import <MobileCoreServices/UTCoreTypes.h>
@@ -49,24 +50,25 @@ static NSSet* org_apache_cordova_validArrowDirections;
 
 /*  takePicture arguments:
  * INDEX   ARGUMENT
- *  0       callbackId
- *  1       quality
- *  2       destination type
- *  3       source type
- *  4       targetWidth
- *  5       targetHeight
- *  6       encodingType
- *  7       mediaType
- *  8       allowsEdit
- *  9       correctOrientation
- *  10      saveToPhotoAlbum
+ *  0       quality
+ *  1       destination type
+ *  2       source type
+ *  3       targetWidth
+ *  4       targetHeight
+ *  5       encodingType
+ *  6       mediaType
+ *  7       allowsEdit
+ *  8       correctOrientation
+ *  9       saveToPhotoAlbum
  */
-- (void) takePicture:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) takePicture:(CDVInvokedUrlCommand*)command
 {
-	NSString* callbackId = [arguments objectAtIndex:0];
+    NSString* callbackId = command.callbackId;
+    NSDictionary* options = [command.arguments objectAtIndex:0 withDefault:nil];
+    NSArray* arguments = command.arguments;
     self.hasPendingOperation = NO;
 
-	NSString* sourceTypeString = [arguments objectAtIndex:3];
+	NSString* sourceTypeString = [arguments objectAtIndex:2];
 	UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; // default
 	if (sourceTypeString != nil) 
 	{
@@ -82,10 +84,10 @@ static NSSet* org_apache_cordova_validArrowDirections;
         
 	} 
 
-    bool allowEdit = [[arguments objectAtIndex:8] boolValue];
-    NSNumber* targetWidth = [arguments objectAtIndex:4];
-    NSNumber* targetHeight = [arguments objectAtIndex:5];
-    NSNumber* mediaValue = [arguments objectAtIndex:7];
+    bool allowEdit = [[arguments objectAtIndex:7] boolValue];
+    NSNumber* targetWidth = [arguments objectAtIndex:3];
+    NSNumber* targetHeight = [arguments objectAtIndex:4];
+    NSNumber* mediaValue = [arguments objectAtIndex:6];
     CDVMediaType mediaType = (mediaValue) ? [mediaValue intValue] : MediaTypePicture;
     
     CGSize targetSize = CGSizeMake(0, 0);
@@ -106,13 +108,13 @@ static NSSet* org_apache_cordova_validArrowDirections;
     cameraPicker.webView = self.webView;
     cameraPicker.popoverSupported = [self popoverSupported];
     
-    cameraPicker.correctOrientation = [[arguments objectAtIndex:9] boolValue];
-    cameraPicker.saveToPhotoAlbum = [[arguments objectAtIndex:10] boolValue];
+    cameraPicker.correctOrientation = [[arguments objectAtIndex:8] boolValue];
+    cameraPicker.saveToPhotoAlbum = [[arguments objectAtIndex:9] boolValue];
     
-    cameraPicker.encodingType = ([arguments objectAtIndex:6]) ? [[arguments objectAtIndex:6] intValue] : EncodingTypeJPEG;
+    cameraPicker.encodingType = ([arguments objectAtIndex:5]) ? [[arguments objectAtIndex:5] intValue] : EncodingTypeJPEG;
     
-    cameraPicker.quality = ([arguments objectAtIndex:1]) ? [[arguments objectAtIndex:1] intValue] : 50;
-    cameraPicker.returnType = ([arguments objectAtIndex:2]) ? [[arguments objectAtIndex:2] intValue] : DestinationTypeFileUri;
+    cameraPicker.quality = ([arguments objectAtIndex:0]) ? [[arguments objectAtIndex:0] intValue] : 50;
+    cameraPicker.returnType = ([arguments objectAtIndex:1]) ? [[arguments objectAtIndex:1] intValue] : DestinationTypeFileUri;
    
     if (sourceType == UIImagePickerControllerSourceTypeCamera) {
         // we only allow taking pictures (no video) in this api
@@ -164,9 +166,9 @@ static NSSet* org_apache_cordova_validArrowDirections;
     self.hasPendingOperation = YES;
 }
 
-- (void) cleanup:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) cleanup:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = [arguments objectAtIndex:0];
+    NSString* callbackId = command.callbackId;
     
     // empty the tmp directory
     NSFileManager* fileMgr = [[NSFileManager alloc] init];

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/886a4fc0/CordovaLib/Classes/CDVCapture.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCapture.h b/CordovaLib/Classes/CDVCapture.h
index 5ade19d..896d7dd 100644
--- a/CordovaLib/Classes/CDVCapture.h
+++ b/CordovaLib/Classes/CDVCapture.h
@@ -51,13 +51,13 @@ typedef NSUInteger CDVCaptureError;
     BOOL inUse;
 }
 @property BOOL inUse;
-- (void) captureAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-- (void) captureImage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void) captureAudio:(CDVInvokedUrlCommand*)command;
+- (void) captureImage:(CDVInvokedUrlCommand*)command;
 -(NSString*) processImage: (UIImage*) image type: (NSString*) mimeType forCallbackId: (NSString*)callbackId;
-- (void) captureVideo:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void) captureVideo:(CDVInvokedUrlCommand*)command;
 -(NSString*) processVideo: (NSString*) moviePath forCallbackId: (NSString*) callbackId;
-- (void) getMediaModes: (NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-- (void) getFormatData: (NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void) getMediaModes:(CDVInvokedUrlCommand*)command;
+- (void) getFormatData:(CDVInvokedUrlCommand*)command;
 -(NSDictionary*) getMediaDictionaryFromPath: (NSString*) fullPath ofType: (NSString*) type;
 - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info;
 - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)image editingInfo:(NSDictionary*)editingInfo;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/886a4fc0/CordovaLib/Classes/CDVCapture.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCapture.m b/CordovaLib/Classes/CDVCapture.m
index 1627085..c33e90a 100644
--- a/CordovaLib/Classes/CDVCapture.m
+++ b/CordovaLib/Classes/CDVCapture.m
@@ -59,9 +59,10 @@
     }
     return self;
 }
-- (void) captureAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) captureAudio:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = [arguments objectAtIndex:0];
+    NSString* callbackId = command.callbackId;
+    NSDictionary* options = [command.arguments objectAtIndex:0];
     NSNumber* duration = [options objectForKey:@"duration"];
     // the default value of duration is 0 so use nil (no duration) if default value
     if (duration) {
@@ -94,9 +95,10 @@
     }
 }
 
-- (void) captureImage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) captureImage:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = [arguments objectAtIndex:0];
+    NSString* callbackId = command.callbackId;
+    NSDictionary* options = [command.arguments objectAtIndex:0];
     NSString* mode = [options objectForKey:@"mode"];
     
 	//options could contain limit and mode neither of which are supported at this time
@@ -193,9 +195,9 @@
     
     return jsString;
 }
-- (void) captureVideo:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) captureVideo:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = [arguments objectAtIndex:0];
+    NSString* callbackId = command.callbackId;
 	//options could contain limit, duration and mode, only duration is supported (but is not due to apple bug)
     // taking more than one video (limit) is only supported if provide own controls via cameraOverlayView property
     //NSNumber* duration = [options objectForKey:@"duration"];
@@ -278,7 +280,7 @@
     return jsString;
     
 }
-- (void) getMediaModes: (NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) getMediaModes:(CDVInvokedUrlCommand*)command
 {
    // NSString* callbackId = [arguments objectAtIndex:0];
     //NSMutableDictionary* imageModes = nil;
@@ -327,15 +329,15 @@
     
     
 }
-- (void) getFormatData: (NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) getFormatData:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = [arguments objectAtIndex:0];
+    NSString* callbackId = command.callbackId;
     // existence of fullPath checked on JS side
-    NSString* fullPath = [arguments objectAtIndex:1];
+    NSString* fullPath = [command.arguments objectAtIndex:0];
     // mimeType could be null
     NSString* mimeType = nil;
-    if ([arguments count] > 2) {
-        mimeType = [arguments objectAtIndex:2];
+    if ([command.arguments count] > 1) {
+        mimeType = [command.arguments objectAtIndex:1];
     }
     BOOL bError = NO;
     CDVCaptureError errorCode = CAPTURE_INTERNAL_ERR;