Added orphaned iOS core plugins.

This commit is contained in:
shazron
2011-07-11 17:20:36 -07:00
parent 0f52e63e69
commit c443dd0dc6
5 changed files with 389 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
/*
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) 2005-2010, Nitobi Software Inc.
*/
#import <Foundation/Foundation.h>
#import "PGPlugin.h"
@interface PGImage : PGPlugin {
IBOutlet UIWindow *window;
UIImagePickerController *picker; // added by urbian
NSString *photoUploadUrl; // added by urbian
NSString *lastUploadedPhoto; // added by urbian
NSURLConnection *conn; // added by urbian
NSMutableData *receivedData; // added by urbian
}
@property (nonatomic, retain) UIImagePickerController *picker;
@property (nonatomic, retain) UIWindow *window;
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image2 editingInfo:(NSDictionary *)editingInfo;
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker;
@end

158
iPhone/__orphanage/Image.m Normal file
View File

@@ -0,0 +1,158 @@
/*
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) 2005-2010, Nitobi Software Inc.
*/
#import "Image.h"
@implementation PGImage
@synthesize window;
@synthesize picker;
// TODO Move to Image.m
- (void)imagePickerController:(UIImagePickerController *)thePicker didFinishPickingImage:(UIImage *)theImage editingInfo:(NSDictionary *)editingInfo
{
//modified by urbian.org - g.mueller @urbian.org
NSLog(@"photo: picked image");
NSData * imageData = UIImageJPEGRepresentation(theImage, 0.75);
NSString *urlString = [@"http://" stringByAppendingString:photoUploadUrl]; // upload the photo to this url
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
// ---------
//Add the header info
NSString *stringBoundary = [NSString stringWithString:@"0xKhTmLbOuNdArY"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",stringBoundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
//create the body
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
//add data field and file data
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"photo_0\"; filename=\"photo\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[NSData dataWithData:imageData]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
// ---------
[request setHTTPBody:postBody];
//NSURLConnection *
conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if(conn) {
receivedData=[[NSMutableData data] retain];
NSString *sourceSt = [[NSString alloc] initWithBytes:[receivedData bytes] length:[receivedData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@", [@"photo: connection sucess" stringByAppendingString:sourceSt]);
[sourceSt release];
} else {
NSLog(@"photo: upload failed!");
}
[[thePicker parentViewController] dismissModalViewControllerAnimated:YES];
self.webView.hidden = NO;
[window bringSubviewToFront:self.webView];
}
// TODO Move to Image.m
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)thePicker
{
// Dismiss the image selection and close the program
[[thePicker parentViewController] dismissModalViewControllerAnimated:YES];
//added by urbian - the webapp should know when the user canceled
NSString * jsCallBack = nil;
jsCallBack = [[NSString alloc] initWithFormat:@"gotPhoto('CANCEL');", lastUploadedPhoto];
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
[jsCallBack release];
// Hide the imagePicker and bring the web page back into focus
NSLog(@"Photo Cancel Request");
self.webView.hidden = NO;
[window bringSubviewToFront:self.webView];
}
// TODO Move to Image.m
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"photo: upload finished!");
//added by urbian.org - g.mueller
NSString *aStr = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
//upload.php should return "filename=<filename>"
NSLog(@"%@", aStr);
NSArray * parts = [aStr componentsSeparatedByString:@"="];
//set filename
lastUploadedPhoto = (NSString *)[parts objectAtIndex:1];
//now the callback: return lastUploadedPhoto
NSString * jsCallBack = nil;
if(lastUploadedPhoto == nil) lastUploadedPhoto = @"ERROR";
jsCallBack = [[NSString alloc] initWithFormat:@"gotPhoto('%@');", lastUploadedPhoto];
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);
NSLog(@"%@", jsCallBack);
// release the connection, and the data object
[conn release];
[receivedData release];
[jsCallBack release];
[aStr release];
}
// TODO Move to Image.m
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *) response {
//added by urbian.org
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSLog(@"HTTP Status Code: %i", [httpResponse statusCode]);
[receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// append the new data to the receivedData
// receivedData is declared as a method instance elsewhere
[receivedData appendData:data];
NSLog(@"photo: progress");
}
/*
* Failed with Error
*/
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"%@", [@"photo: upload failed! " stringByAppendingString:[error description]]);
}
@end

38
iPhone/__orphanage/Movie.h Executable file
View File

@@ -0,0 +1,38 @@
/*
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) 2005-2010, Nitobi Software Inc.
*/
#import "PGPlugin.h"
#import <AudioToolbox/AudioServices.h>
#import <MediaPlayer/MediaPlayer.h>
@interface PGMovie : PGPlugin {
BOOL stopReceived;
BOOL repeat;
MPMoviePlayerController *theMovie;
}
- (void) play:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
- (void) stop:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
void propListener (
void *inClientData,
AudioSessionPropertyID inID,
UInt32 inDataSize,
const void *inData
);
void interruptionListener (
void *inClientData,
UInt32 inInterruptionState
);
@property (nonatomic, retain ) MPMoviePlayerController *theMovie;
@property (nonatomic ) BOOL stopReceived;
@property (nonatomic ) BOOL repeat;
@end

148
iPhone/__orphanage/Movie.m Executable file
View File

@@ -0,0 +1,148 @@
/*
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) 2005-2010, Nitobi Software Inc.
*/
#import "Movie.h"
#import <AudioToolbox/AudioServices.h>
#import <MediaPlayer/MediaPlayer.h>
@implementation PGMovie
@synthesize theMovie,stopReceived,repeat;
- (PGPlugin*) initWithWebView:(UIWebView*)theWebView
{
self = (PGMovie*)[super initWithWebView:(UIWebView*)theWebView];
if (self) {
stopReceived = false;
repeat = false;
}
return self;
}
- (void) play:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
NSBundle * mainBundle = [NSBundle mainBundle];
NSMutableArray *directoryParts = [NSMutableArray arrayWithArray:[(NSString*)[arguments objectAtIndex:0] componentsSeparatedByString:@"/"]];
NSString *filename = [directoryParts lastObject];
[directoryParts removeLastObject];
NSMutableArray *filenameParts = [NSMutableArray arrayWithArray:[filename componentsSeparatedByString:@"."]];
NSString *directoryStr = [directoryParts componentsJoinedByString:@"/"];
NSString *filePath = [mainBundle pathForResource:(NSString*)[filenameParts objectAtIndex:0]
ofType:(NSString*)[filenameParts objectAtIndex:1]
inDirectory:directoryStr];
if (filePath == nil) {
filePath = [mainBundle pathForResource:(NSString*)[filenameParts objectAtIndex:0]
ofType:(NSString*)[filenameParts objectAtIndex:1]];
if (filePath == nil) {
NSLog(@"Can't find filename %@ in the app bundle", [arguments objectAtIndex:0]);
return;
}
}
// TODO Create a system facilitating handling callback responses in JavaScript easily, and no
// longer in an ad-hoc fashion. Getting error results of whether or not the Movie played, or
// other errors occurring in the system is important.
OSStatus error = AudioSessionInitialize(NULL, NULL, interruptionListener, self);
if (error) {
NSLog(@"ERROR INITIALIZING AUDIO SESSION! %d\n", error);
return;
}
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty ( kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory );
error = AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, propListener, self);
if (error) {
NSLog(@"ERROR Adding Property Listener %d\n", error);
return;
}
// AudioSessionSetActive (true);
theMovie = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath: filePath]];
NSLog(@"theMovie description = %@", [(NSObject *)theMovie description]);
//[theMovie setOrientation:UIDeviceOrientationPortrait animated:NO]; // TODO: remove? no such selector
theMovie.scalingMode = MPMovieScalingModeAspectFill;
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_3_2
theMovie.movieControlMode = MPMovieControlModeDefault;
#endif
// Register for the playback finished notification.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
// Movie playback is asynchronous, so this method returns immediately.
[theMovie play];
}
- (void) stop:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
NSLog(@"Stop the movie!");
stopReceived = true;
NSLog(@"theMovie description = %@", [(NSObject *)theMovie description]);
[theMovie stop];
NSLog(@"Finished stopping the movie.");
}
#pragma mark AudioSession listeners
void interruptionListener (
void *inClientData,
UInt32 inInterruptionState
)
{
if (inInterruptionState == kAudioSessionBeginInterruption) {}
NSLog(@"Movie: interruptionListener");
}
void propListener( void * inClientData,
AudioSessionPropertyID inID,
UInt32 inDataSize,
const void * inData)
{
NSLog(@"Movie: audio prop Listener");
}
- (void) myMovieFinishedCallback:(NSNotification*)aNotification
{
NSLog(@"myMovieFinishedCallback");
MPMoviePlayerController* myMovie = [aNotification object];
NSLog(@"myMovie description = %@, theMovie description = %@, stopReceived = %d", [(NSObject *)myMovie description], theMovie, stopReceived);
if(stopReceived) {
[theMovie stop];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:myMovie];
}
if(repeat) {
[myMovie play];
}
}
- (void) dealloc
{
[theMovie release];
[super dealloc];
}
@end

View File

@@ -0,0 +1,16 @@
# The PhoneGap Plugin Orphanage #
These are plugins that never had a JavaScript interface, never was documented nor cross-platform, but they existed in core PhoneGap. They have been removed for 1.0.0. They need a good home and lots of tender loving care (and a JS interface for their 1st birthday) - until they become adults and can live on their own.
## LICENSE ##
The MIT License
Copyright (c) 2010 Nitobi Software Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.