]> git.saurik.com Git - winterboard.git/blobdiff - Application.mm
Add backwards compatibility mode for Icons/SMS.png, remove English_ in not SummerBoar...
[winterboard.git] / Application.mm
index a7c72ad0696a47c9ae996fca57123316e37e6440..cd383d31d7984a878cc205eb3ad9324a977faecc 100644 (file)
@@ -1,5 +1,5 @@
 /* WinterBoard - Theme Manager for the iPhone
- * Copyright (C) 2008  Jay Freeman (saurik)
+ * Copyright (C) 2008-2009  Jay Freeman (saurik)
 */
 
 /*
 #import <CoreGraphics/CGGeometry.h>
 #import <UIKit/UIKit.h>
 
-#define _trace() NSLog(@"_trace(%u)", __LINE__);
+#import <Preferences/PSRootController.h>
+#import <Preferences/PSViewController.h>
+#import <Preferences/PSSpecifier.h>
 
-@interface WBApplication : UIApplication <
-    UITableViewDataSource,
-    UITableViewDelegate
-> {
-    UIWindow *window_;
-    UITableView *themesTable_;
-    NSMutableArray *themesArray_;
+@interface UIApplication (Private)
+- (void) terminateWithSuccess;
+@end
+
+@interface WBRootController : PSRootController {
+    PSViewController *_firstViewController;
 }
 
+@property (readonly) PSViewController *firstViewController;
+
+- (void) setupRootListForSize:(CGSize)size;
+- (BOOL) popController;
+
 @end
 
-@implementation WBApplication
+@implementation WBRootController
 
-- (void) dealloc {
-    [window_ release];
-    [themesTable_ release];
-    [themesArray_ release];
-    [super dealloc];
-}
+@synthesize firstViewController = _firstViewController;
 
-- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-    UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero] autorelease];
-    cell.text = [themesArray_ objectAtIndex:[indexPath row]];
-    return cell;
-}
+- (void) setupRootListForSize:(CGSize)size {
+    PSSpecifier *spec = [[PSSpecifier alloc] init];
+    [spec setTarget:self];
+    spec.name = @"WinterBoard";
 
-- (NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
-    return [themesArray_ count];
-}
+    NSBundle *wbSettingsBundle = [NSBundle bundleWithPath:@"/System/Library/PreferenceBundles/WinterBoardSettings.bundle"];
+    [wbSettingsBundle load];
 
-- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-    NSString *theme = [themesArray_ objectAtIndex:[indexPath row]];
+    _firstViewController = [[[wbSettingsBundle principalClass] alloc] initForContentSize:size];
+    _firstViewController.rootController = self;
+    _firstViewController.parentController = self;
+    [_firstViewController viewWillBecomeVisible:spec];
 
-    [[NSDictionary dictionaryWithObjectsAndKeys:
-        theme, @"Theme",
-    nil] writeToFile:[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist",
-        NSHomeDirectory()
-    ] atomically:YES];
+    [spec release];
 
-    if (fork() == 0) {
-        execlp("killall", "killall", "SpringBoard", NULL);
-        exit(0);
-    }
+    [self pushController:_firstViewController];
 }
 
-- (void) applicationDidFinishLaunching:(id)unused {
-    window_ = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
-    [window_ makeKeyAndVisible];
+- (BOOL) popController {
+    // Pop the last controller = exit the application.
+    // The only time the last controller should pop is when the user taps Respring/Cancel.
+    // Which only gets displayed if the user has made changes.
+    if([self lastController] == _firstViewController)
+        [[UIApplication sharedApplication] terminateWithSuccess];
+    return [super popController];
+}
+@end
 
-    themesArray_ = [[NSMutableArray arrayWithCapacity:32] retain];
-    NSFileManager *manager = [NSFileManager defaultManager];
+@interface WBApplication : UIApplication {
+    WBRootController *_rootController;
+}
 
-    [themesArray_ addObjectsFromArray:[manager contentsOfDirectoryAtPath:@"/Library/Themes" error:NULL]];
-    [themesArray_ addObjectsFromArray:[manager contentsOfDirectoryAtPath:[NSString stringWithFormat:@"%@/Library/SummerBoard/Themes", NSHomeDirectory()] error:NULL]];
+@end
 
-    themesTable_ = [[UITableView alloc] initWithFrame:window_.bounds];
-    [window_ addSubview:themesTable_];
+@implementation WBApplication
 
-    [themesTable_ setDataSource:self];
-    [themesTable_ setDelegate:self];
+- (void) dealloc {
+    [_rootController release];
+    [super dealloc];
+}
 
-    [themesTable_ setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
+- (void) applicationWillTerminate:(UIApplication *)application {
+    [_rootController.firstViewController suspend];
+}
+
+- (void) applicationDidFinishLaunching:(id)unused {
+    UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
+    _rootController = [[WBRootController alloc] initWithTitle:@"WinterBoard" identifier:[[NSBundle mainBundle] bundleIdentifier]];
+    [window addSubview:_rootController.contentView];
+    [window makeKeyAndVisible];
 }
 
 @end