]>
Commit | Line | Data |
---|---|---|
62b2dbad | 1 | /* WinterBoard - Theme Manager for the iPhone |
224d48e3 | 2 | * Copyright (C) 2008-2009 Jay Freeman (saurik) |
62b2dbad JF |
3 | */ |
4 | ||
5 | /* | |
6 | * Redistribution and use in source and binary | |
7 | * forms, with or without modification, are permitted | |
8 | * provided that the following conditions are met: | |
9 | * | |
10 | * 1. Redistributions of source code must retain the | |
11 | * above copyright notice, this list of conditions | |
12 | * and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the | |
14 | * above copyright notice, this list of conditions | |
15 | * and the following disclaimer in the documentation | |
16 | * and/or other materials provided with the | |
17 | * distribution. | |
18 | * 3. The name of the author may not be used to endorse | |
19 | * or promote products derived from this software | |
20 | * without specific prior written permission. | |
21 | * | |
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' | |
23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | |
24 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE | |
27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
33 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
35 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
36 | */ | |
37 | ||
38 | #import <Foundation/Foundation.h> | |
39 | #import <CoreGraphics/CGGeometry.h> | |
40 | #import <UIKit/UIKit.h> | |
41 | ||
224d48e3 JF |
42 | #import <Preferences/PSRootController.h> |
43 | #import <Preferences/PSViewController.h> | |
44 | #import <Preferences/PSSpecifier.h> | |
d5fb6e01 | 45 | |
224d48e3 JF |
46 | @interface UIApplication (Private) |
47 | - (void) terminateWithSuccess; | |
48 | @end | |
d5fb6e01 | 49 | |
224d48e3 JF |
50 | @interface WBRootController : PSRootController { |
51 | PSViewController *_firstViewController; | |
d5fb6e01 JF |
52 | } |
53 | ||
224d48e3 | 54 | @property (readonly) PSViewController *firstViewController; |
d5fb6e01 | 55 | |
224d48e3 JF |
56 | - (void) setupRootListForSize:(CGSize)size; |
57 | - (BOOL) popController; | |
d5fb6e01 JF |
58 | |
59 | @end | |
62b2dbad | 60 | |
224d48e3 | 61 | @implementation WBRootController |
62b2dbad | 62 | |
224d48e3 | 63 | @synthesize firstViewController = _firstViewController; |
62b2dbad | 64 | |
224d48e3 JF |
65 | - (void) setupRootListForSize:(CGSize)size { |
66 | PSSpecifier *spec = [[PSSpecifier alloc] init]; | |
67 | [spec setTarget:self]; | |
68 | spec.name = @"WinterBoard"; | |
62b2dbad | 69 | |
224d48e3 JF |
70 | NSBundle *wbSettingsBundle = [NSBundle bundleWithPath:@"/System/Library/PreferenceBundles/WinterBoardSettings.bundle"]; |
71 | [wbSettingsBundle load]; | |
62b2dbad | 72 | |
224d48e3 JF |
73 | _firstViewController = [[[wbSettingsBundle principalClass] alloc] initForContentSize:size]; |
74 | _firstViewController.rootController = self; | |
75 | _firstViewController.parentController = self; | |
76 | [_firstViewController viewWillBecomeVisible:spec]; | |
d5fb6e01 | 77 | |
224d48e3 | 78 | [spec release]; |
62b2dbad | 79 | |
224d48e3 | 80 | [self pushController:_firstViewController]; |
d5fb6e01 JF |
81 | } |
82 | ||
224d48e3 JF |
83 | - (BOOL) popController { |
84 | // Pop the last controller = exit the application. | |
85 | // The only time the last controller should pop is when the user taps Respring/Cancel. | |
86 | // Which only gets displayed if the user has made changes. | |
87 | if([self lastController] == _firstViewController) | |
88 | [[UIApplication sharedApplication] terminateWithSuccess]; | |
89 | return [super popController]; | |
62b2dbad | 90 | } |
224d48e3 | 91 | @end |
62b2dbad | 92 | |
224d48e3 JF |
93 | @interface WBApplication : UIApplication { |
94 | WBRootController *_rootController; | |
d5fb6e01 | 95 | } |
62b2dbad | 96 | |
224d48e3 JF |
97 | @end |
98 | ||
99 | @implementation WBApplication | |
100 | ||
101 | - (void) dealloc { | |
102 | [_rootController release]; | |
103 | [super dealloc]; | |
d5fb6e01 | 104 | } |
62b2dbad | 105 | |
224d48e3 JF |
106 | - (void) applicationWillTerminate:(UIApplication *)application { |
107 | [_rootController.firstViewController suspend]; | |
62b2dbad JF |
108 | } |
109 | ||
110 | - (void) applicationDidFinishLaunching:(id)unused { | |
224d48e3 JF |
111 | UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; |
112 | _rootController = [[WBRootController alloc] initWithTitle:@"WinterBoard" identifier:[[NSBundle mainBundle] bundleIdentifier]]; | |
113 | [window addSubview:_rootController.contentView]; | |
114 | [window makeKeyAndVisible]; | |
62b2dbad JF |
115 | } |
116 | ||
117 | @end | |
118 | ||
119 | int main(int argc, char *argv[]) { | |
120 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
121 | ||
122 | int value = UIApplicationMain(argc, argv, @"WBApplication", @"WBApplication"); | |
123 | ||
124 | [pool release]; | |
125 | return value; | |
126 | } |