forked from schacon/ShowOffPad
/
ShowOffPadAppDelegate.m
121 lines (95 loc) · 3.48 KB
/
ShowOffPadAppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// ShowOffPadAppDelegate.m
// ShowOffPad
//
// Created by Scott Chacon on 5/5/10.
// Copyright GitHub 2010. All rights reserved.
//
#import "ShowOffPadAppDelegate.h"
#import "ShowOffPadViewController.h"
#import "ShowOffPadPresentController.h"
#import "NewFormController.h"
#import "RootController.h"
@implementation ShowOffPadAppDelegate
@synthesize window, extWindow;
@synthesize viewController, presentController, rootController;
@synthesize splitViewController;
- (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];
viewController = [[ShowOffPadViewController alloc]
initWithNibName:@"ShowOffPadViewController"
bundle:nil];
presentController = [[ShowOffPadPresentController alloc]
initWithNibName:@"ShowOffPadPresentController"
bundle:nil];
viewController.extDisplay = presentController;
[window addSubview:splitViewController.view];
[window makeKeyAndVisible];
if([[UIScreen screens]count] > 1) //if there are more than 1 screens connected to the device
{
UIScreenMode *bestScreenMode;
BOOL screenChoosen = FALSE;
for(int i = 0; i < [[[[UIScreen screens] objectAtIndex:1] availableModes]count]; i++)
{
UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:i];
if (!screenChoosen) {
bestScreenMode = current;
}
if (current.size.width == 1024.0) {
bestScreenMode = current;
}
}
//Now we have the highest mode. Turn the external display to use that mode.
UIScreen *external = [[UIScreen screens] objectAtIndex:1];
external.currentMode = bestScreenMode;
//Boom! Now the external display is set to the proper mode. We need to now set the screen of a new UIWindow to the external screen
//extWindow = [[UIWindow alloc] init];
extWindow = [[UIWindow alloc] initWithFrame:[external bounds]];
extWindow.screen = external;
[extWindow addSubview:presentController.view];
[extWindow makeKeyAndVisible];
}
// 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);
}
*/
return YES;
}
- (void) showPresentation {
CGRect contentRect = CGRectMake(0, 0, 1024, 748);
viewController.view.frame = contentRect;
[self.splitViewController.view addSubview:viewController.view];
[self.splitViewController.view bringSubviewToFront:viewController.view];
}
- (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];
[window release];
[extWindow release];
[super dealloc];
}
@end