]> git.saurik.com Git - winterboard.git/blame - Application.mm
Duplicate the PSTitleValueCell labels into the footerText properties of their associa...
[winterboard.git] / Application.mm
CommitLineData
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>
b44f5c22 44#import <Preferences/PSListController.h>
224d48e3 45#import <Preferences/PSSpecifier.h>
d5fb6e01 46
b44f5c22
DH
47static NSBundle *wbSettingsBundle;
48static Class $WBSettingsController;
49
224d48e3
JF
50@interface UIApplication (Private)
51- (void) terminateWithSuccess;
52@end
d5fb6e01 53
b44f5c22
DH
54@interface UIDevice (Private)
55- (BOOL) isWildcat;
56@end
57
58@interface PSRootController (Compatibility)
59- (id) _popController; // < 3.2
60- (id) contentView; // < 3.2
61- (id) lastController; // < 3.2
62- (id) topViewController; // >= 3.2
63@end
64
65@interface PSListController (Compatibility)
66- (void) viewWillBecomeVisible:(void *)specifier; // < 3.2
67- (void) viewWillAppear:(BOOL)a; // >= 3.2
68- (void) setSpecifier:(PSSpecifier *)spec; // >= 3.2
69@end
70
224d48e3 71@interface WBRootController : PSRootController {
b44f5c22 72 PSListController *_rootListController;
d5fb6e01
JF
73}
74
b44f5c22 75@property (readonly) PSListController *rootListController;
d5fb6e01 76
224d48e3 77- (void) setupRootListForSize:(CGSize)size;
b44f5c22 78- (id) topViewController;
d5fb6e01 79@end
62b2dbad 80
224d48e3 81@implementation WBRootController
62b2dbad 82
b44f5c22 83@synthesize rootListController = _rootListController;
62b2dbad 84
b44f5c22 85// < 3.2
224d48e3 86- (void) setupRootListForSize:(CGSize)size {
b44f5c22 87 PSSpecifier *spec([[PSSpecifier alloc] init]);
224d48e3
JF
88 [spec setTarget:self];
89 spec.name = @"WinterBoard";
62b2dbad 90
b44f5c22
DH
91 _rootListController = [[$WBSettingsController alloc] initForContentSize:size];
92 _rootListController.rootController = self;
93 _rootListController.parentController = self;
94 [_rootListController viewWillBecomeVisible:spec];
d5fb6e01 95
224d48e3 96 [spec release];
62b2dbad 97
b44f5c22 98 [self pushController:_rootListController];
d5fb6e01
JF
99}
100
b44f5c22
DH
101// >= 3.2
102- (void) loadView {
103 [super loadView];
104 [self pushViewController:[self rootListController] animated:NO];
105}
106
107- (PSListController *) rootListController {
108 if(!_rootListController) {
109 PSSpecifier *spec([[PSSpecifier alloc] init]);
110 [spec setTarget:self];
111 spec.name = @"WinterBoard";
112 _rootListController = [[$WBSettingsController alloc] initForContentSize:CGSizeZero];
113 _rootListController.rootController = self;
114 _rootListController.parentController = self;
115 [_rootListController setSpecifier:spec];
116 [spec release];
117 }
118 return _rootListController;
119}
120
121- (id) contentView {
122 if ([[PSRootController class] instancesRespondToSelector:@selector(contentView)]) {
123 return [super contentView];
124 } else {
125 return [super view];
126 }
127}
128
129- (id) topViewController {
130 if ([[PSRootController class] instancesRespondToSelector:@selector(topViewController)]) {
131 return [super topViewController];
132 } else {
133 return [super lastController];
134 }
135}
136
137- (id) _popController {
224d48e3
JF
138 // Pop the last controller = exit the application.
139 // The only time the last controller should pop is when the user taps Respring/Cancel.
140 // Which only gets displayed if the user has made changes.
b44f5c22 141 if ([self topViewController] == _rootListController)
224d48e3 142 [[UIApplication sharedApplication] terminateWithSuccess];
b44f5c22 143 return [super _popController];
62b2dbad 144}
b44f5c22 145
224d48e3 146@end
62b2dbad 147
224d48e3
JF
148@interface WBApplication : UIApplication {
149 WBRootController *_rootController;
d5fb6e01 150}
62b2dbad 151
224d48e3
JF
152@end
153
154@implementation WBApplication
155
156- (void) dealloc {
157 [_rootController release];
158 [super dealloc];
d5fb6e01 159}
62b2dbad 160
224d48e3 161- (void) applicationWillTerminate:(UIApplication *)application {
b44f5c22 162 [_rootController.rootListController suspend];
62b2dbad
JF
163}
164
165- (void) applicationDidFinishLaunching:(id)unused {
b44f5c22
DH
166 wbSettingsBundle = [NSBundle bundleWithPath:@"/System/Library/PreferenceBundles/WinterBoardSettings.bundle"];
167 [wbSettingsBundle load];
168 $WBSettingsController = [wbSettingsBundle principalClass];
169
170 CGRect applicationFrame(([UIDevice instancesRespondToSelector:@selector(isWildcat)]
171 && [[UIDevice currentDevice] isWildcat])
172 ? [UIScreen mainScreen].bounds
173 : [UIScreen mainScreen].applicationFrame);
174 UIWindow *window([[UIWindow alloc] initWithFrame:applicationFrame]);
224d48e3 175 _rootController = [[WBRootController alloc] initWithTitle:@"WinterBoard" identifier:[[NSBundle mainBundle] bundleIdentifier]];
b44f5c22 176 [window addSubview:[_rootController contentView]];
224d48e3 177 [window makeKeyAndVisible];
62b2dbad
JF
178}
179
180@end
181
182int main(int argc, char *argv[]) {
b44f5c22 183 NSAutoreleasePool *pool( [[NSAutoreleasePool alloc] init]);
62b2dbad
JF
184
185 int value = UIApplicationMain(argc, argv, @"WBApplication", @"WBApplication");
186
187 [pool release];
188 return value;
189}