Permalink
Browse files

can copy presentations locally

  • Loading branch information...
1 parent 96ed1d4 commit ceb77edadd138b4a5cc3f1e9a34659b964fe3827 @schacon committed May 11, 2010
@@ -0,0 +1,40 @@
+//
+// NewFormController.h
+// ShowOffPad
+//
+// Created by Scott Chacon on 5/11/10.
+// Copyright 2010 GitHub. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "ASINetworkQueue.h"
+
+@interface NewFormController : UIViewController {
+ UIButton *goButton;
+ UITextField *presName;
+ UITextField *presUrl;
+
+ UILabel *importStatus;
+ UIActivityIndicatorView *importActivity;
+ UIProgressView *importProgress;
+
+ ASINetworkQueue *networkQueue;
+
+ NSUInteger assetCount;
+ NSString *presBasePath;
+}
+
+@property (retain) ASINetworkQueue *networkQueue;
+@property (assign, readwrite) NSUInteger assetCount;
+@property (retain) NSString *presBasePath;
+
+@property (nonatomic, retain) IBOutlet UIButton *goButton;
+@property (nonatomic, retain) IBOutlet UITextField *presName;
+@property (nonatomic, retain) IBOutlet UITextField *presUrl;
+@property (nonatomic, retain) IBOutlet UILabel *importStatus;
+@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *importActivity;
+@property (nonatomic, retain) IBOutlet UIProgressView *importProgress;
+
+- (IBAction)importPres:(id) sender;
+
+@end
@@ -0,0 +1,163 @@
+ //
+// NewFormController.m
+// ShowOffPad
+//
+// Created by Scott Chacon on 5/11/10.
+// Copyright 2010 GitHub. All rights reserved.
+//
+
+#import "NewFormController.h"
+#import "ASIHTTPRequest.h"
+
+@implementation NewFormController
+
+@synthesize goButton, presName, presUrl;
+@synthesize importStatus, importActivity, importProgress;
+@synthesize networkQueue, assetCount, presBasePath;
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+}
+
+- (IBAction)importPres:(id) sender {
+ importProgress.progress = 0.0;
+ [importActivity startAnimating];
+
+ importActivity.hidden = FALSE;
+ importProgress.hidden = FALSE;
+ importStatus.hidden = FALSE;
+
+ NSString *uriBase = self.presUrl.text;
+ NSString *assets = [uriBase stringByAppendingString:@"assets_needed"];
+ NSURL *url = [NSURL URLWithString:assets];
+
+ ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
+ [request startSynchronous];
+
+ NSError *error = [request error];
+ if (!error) {
+
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+
+ NSString *pbPath = @"";
+ pbPath = [NSString stringWithString:[[paths objectAtIndex:0] stringByAppendingPathComponent:@"showoff"]];
+ NSString *presNameStr = presName.text;
+ presBasePath = [pbPath stringByAppendingPathComponent:presNameStr];
+ [presBasePath retain];
+
+ NSString *response = [request responseString];
+ NSArray *assetsNeeded = [response componentsSeparatedByString:@"\n"];
+ NSLog(@"FU: %@", assetsNeeded);
+ assetCount = [assetsNeeded count];
+
+ // Stop anything already in the queue before removing it
+ [[self networkQueue] cancelAllOperations];
+
+ // Creating a new queue each time we use it means we don't have to worry about clearing delegates or resetting progress tracking
+ [self setNetworkQueue:[ASINetworkQueue queue]];
+ [[self networkQueue] setDelegate:self];
+ [[self networkQueue] setRequestDidFinishSelector:@selector(requestFinished:)];
+ [[self networkQueue] setRequestDidFailSelector:@selector(requestFailed:)];
+ [[self networkQueue] setQueueDidFinishSelector:@selector(queueFinished:)];
+
+ NSEnumerator *enumerator = [assetsNeeded objectEnumerator];
+ NSString *anAsset;
+ NSString *assetUrl;
+
+ while (anAsset = [enumerator nextObject]) {
+ assetUrl = [uriBase stringByAppendingString:anAsset];
+ url = [NSURL URLWithString:assetUrl];
+ ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
+ [[self networkQueue] addOperation:request];
+ }
+
+ [[self networkQueue] go];
+ }
+}
+
+- (void)requestFinished:(ASIHTTPRequest *)request
+{
+ NSString *response = [request responseString];
+
+ NSData* aData;
+ aData = [response dataUsingEncoding: NSASCIIStringEncoding];
+
+ NSString *base = [[request url] path];
+ NSString *filePath = [presBasePath stringByAppendingPathComponent:base];
+ NSError *error;
+ NSFileManager *fm = [NSFileManager defaultManager];
+
+ NSString *dirPath = [filePath stringByDeletingLastPathComponent];
+ [fm createDirectoryAtPath:dirPath withIntermediateDirectories:TRUE attributes:nil error:&error];
+ [fm createFileAtPath:filePath contents:aData attributes:nil];
+
+ NSLog(@"FU: %@", filePath);
+ importStatus.text = [NSString stringWithFormat:@"Downloading %@", base];
+
+ int reqCount = [[self networkQueue] requestsCount];
+ float left = (int)assetCount - reqCount;
+ float done = left / (float)assetCount;
+ importProgress.progress = done;
+ NSLog(@"FU: %5.2f", done);
+
+ if ([[self networkQueue] requestsCount] == 0) {
+
+ // Since this is a retained property, setting it to nil will release it
+ // This is the safest way to handle releasing things - most of the time you only ever need to release in your accessors
+ // And if you an Objective-C 2.0 property for the queue (as in this example) the accessor is generated automatically for you
+ [self setNetworkQueue:nil];
+ }
+
+ //... Handle success
+ NSLog(@"Request finished");
+}
+
+- (void)requestFailed:(ASIHTTPRequest *)request
+{
+ // You could release the queue here if you wanted
+ if ([[self networkQueue] requestsCount] == 0) {
+ [self setNetworkQueue:nil];
+ }
+
+ //... Handle failure
+ NSLog(@"Request failed");
+}
+
+
+- (void)queueFinished:(ASINetworkQueue *)queue
+{
+ // You could release the queue here if you wanted
+ if ([[self networkQueue] requestsCount] == 0) {
+ [self setNetworkQueue:nil];
+ }
+ NSLog(@"Queue finished");
+
+ [importActivity stopAnimating];
+ importActivity.hidden = TRUE;
+ importProgress.hidden = TRUE;
+ importStatus.hidden = TRUE;
+}
+
+
+
+- (void)didReceiveMemoryWarning {
+ // Releases the view if it doesn't have a superview.
+ [super didReceiveMemoryWarning];
+
+ // Release any cached data, images, etc that aren't in use.
+}
+
+- (void)viewDidUnload {
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
+}
+
+
+- (void)dealloc {
+ [networkQueue release];
+ [super dealloc];
+}
+
+
+@end
@@ -0,0 +1,20 @@
+//
+// RootController.h
+// ShowOffPad
+//
+// Created by Scott Chacon on 5/11/10.
+// Copyright 2010 GitHub. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+
+@interface RootController : UIViewController {
+ UIBarButtonItem *newButton;
+ UIView *mainView;
+}
+
+@property (nonatomic, retain) IBOutlet UIBarButtonItem *newButton;
+@property (nonatomic, retain) IBOutlet UIView *mainView;
+
+@end
@@ -0,0 +1,47 @@
+ //
+// RootController.m
+// ShowOffPad
+//
+// Created by Scott Chacon on 5/11/10.
+// Copyright 2010 GitHub. All rights reserved.
+//
+
+#import "RootController.h"
+#import "NewFormController.h"
+
+
+@implementation RootController
+
+@synthesize newButton, mainView;
+
+- (void)viewDidLoad {
+ NewFormController *newForm = [[NewFormController alloc]
+ initWithNibName:@"NewFormController"
+ bundle:nil];
+ [self.mainView addSubview:newForm.view];
+
+ paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+ presoPath = [NSString stringWithString:[[paths objectAtIndex:0] stringByAppendingPathComponent:@"showoff"]];
+ [presoPath retain];
+
+ [super viewDidLoad];
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
+ return YES;
+}
+
+- (void)didReceiveMemoryWarning {
+ [super didReceiveMemoryWarning];
+}
+
+- (void)viewDidUnload {
+ [super viewDidUnload];
+}
+
+- (void)dealloc {
+ [super dealloc];
+}
+
+
+@end
@@ -10,10 +10,12 @@
@class ShowOffPadViewController;
@class ShowOffPadPresentController;
+@class RootController;
@interface ShowOffPadAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UIWindow *extWindow;
+ RootController *rootController;
ShowOffPadViewController *viewController;
ShowOffPadPresentController *presentController;
}
@@ -22,6 +24,9 @@
@property (nonatomic, retain) UIWindow *extWindow;
@property (nonatomic, retain) IBOutlet ShowOffPadViewController *viewController;
@property (nonatomic, retain) IBOutlet ShowOffPadPresentController *presentController;
+@property (nonatomic, retain) IBOutlet RootController *rootController;
+
+- (NSString *) ensurePresoPath;
@end
@@ -9,17 +9,25 @@
#import "ShowOffPadAppDelegate.h"
#import "ShowOffPadViewController.h"
#import "ShowOffPadPresentController.h"
+#import "NewFormController.h"
+#import "RootController.h"
@implementation ShowOffPadAppDelegate
@synthesize window, extWindow;
-@synthesize viewController, presentController;
+@synthesize viewController, presentController, rootController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Code to detect if an external display is connected to the iPad.
NSLog(@"Number of screens: %d", [[UIScreen screens]count]);
+
+ NSString *presoPath = [self ensurePresoPath];
+ rootController = [[RootController alloc]
+ initWithNibName:@"RootController"
+ bundle:nil];
+
presentController = [[ShowOffPadPresentController alloc]
initWithNibName:@"ShowOffPadPresentController"
bundle:nil];
@@ -54,13 +62,43 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
extWindow.screen = external;
}
- [window addSubview:viewController.view];
+ // start the server
+ /*
+ httpServer = [HTTPServer new];
+ [httpServer setType:@"_http._tcp."];
+ [httpServer setConnectionClass:[ShowOffHTTPConnection class]];
+ [httpServer setDocumentRoot:[NSURL fileURLWithPath:presoPath]];
+ [httpServer setPort:8082];
+
+ NSError *error;
+ if(![httpServer start:&error])
+ {
+ NSLog(@"Error starting HTTP Server: %@", error);
+ }
+ */
+
+ [window addSubview:rootController.view];
[window makeKeyAndVisible];
-
return YES;
}
+- (NSString *) ensurePresoPath {
+ NSArray *paths;
+ NSString *presoPath = @"";
+
+ paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+ presoPath = [NSString stringWithString:[[paths objectAtIndex:0] stringByAppendingPathComponent:@"showoff"]];
+ [presoPath retain];
+
+ BOOL isDir;
+ NSFileManager *fm = [NSFileManager defaultManager];
+ if (![fm fileExistsAtPath:presoPath isDirectory:&isDir] && isDir) {
+ [fm createDirectoryAtPath:presoPath attributes:nil];
+ }
+ return presoPath;
+}
+
- (void)dealloc {
[viewController release];
[presentController release];
@@ -0,0 +1,28 @@
+//
+// ASIAuthenticationDialog.h
+// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
+//
+// Created by Ben Copsey on 21/08/2009.
+// Copyright 2009 All-Seeing Interactive. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+@class ASIHTTPRequest;
+
+typedef enum _ASIAuthenticationType {
+ ASIStandardAuthenticationType = 0,
+ ASIProxyAuthenticationType = 1
+} ASIAuthenticationType;
+
+@interface ASIAuthenticationDialog : NSObject <UIActionSheetDelegate, UITableViewDelegate, UITableViewDataSource> {
+ ASIHTTPRequest *request;
+ UIActionSheet *loginDialog;
+ ASIAuthenticationType type;
+}
++ (void)presentAuthenticationDialogForRequest:(ASIHTTPRequest *)request;
++ (void)presentProxyAuthenticationDialogForRequest:(ASIHTTPRequest *)request;
+
+@property (retain) ASIHTTPRequest *request;
+@property (retain) UIActionSheet *loginDialog;
+@property (assign) ASIAuthenticationType type;
+@end
Oops, something went wrong.

0 comments on commit ceb77ed

Please sign in to comment.