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