]> git.saurik.com Git - winterboard.git/blobdiff - Settings.mm
Drop ~iphone from ~iphone.app.
[winterboard.git] / Settings.mm
index edc0d3f5bc8db0ed13a393780b10abb93b9042e4..442e97cbc2464c4401839155a88958a3b09b622c 100644 (file)
@@ -327,45 +327,43 @@ static NSString *_plist;
 @end
 /* }}} */
 
-@interface WBSettingsController: PSListController {
+@interface WBAdvancedController: PSListController {
 }
 
-- (id) initForContentSize:(CGSize)size;
-- (void) dealloc;
-- (void) suspend;
-- (void) navigationBarButtonClicked:(int)buttonIndex;
-- (void) viewWillRedisplay;
-- (void) pushController:(id)controller;
 - (id) specifiers;
 - (void) settingsChanged;
-- (NSString *) title;
-- (void) setPreferenceValue:(id)value specifier:(PSSpecifier *)spec;
-- (id) readPreferenceValue:(PSSpecifier *)spec;
 
 @end
 
-@implementation WBSettingsController
+@implementation WBAdvancedController
 
-+ (void) load {
-    void *libhide(dlopen("/usr/lib/hide.dylib", RTLD_LAZY));
-    IsIconHiddenDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "IsIconHiddenDisplayId"));
-    HideIconViaDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "HideIconViaDisplayId"));
-    UnHideIconViaDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "UnHideIconViaDisplayId"));
+- (id) specifiers {
+    if (!_specifiers)
+        _specifiers = [[self loadSpecifiersFromPlistName:@"Advanced" target:self] retain];
+    return _specifiers;
 }
 
-- (id) initForContentSize:(CGSize)size {
-    if ((self = [super initForContentSize:size]) != nil) {
-        _plist = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()] retain];
-        _settings = [([NSMutableDictionary dictionaryWithContentsOfFile:_plist] ?: [NSMutableDictionary dictionary]) retain];
+- (void) settingsChanged {
+    settingsChanged = YES;
+}
 
-        [_settings setObject:[NSNumber numberWithBool:IsIconHiddenDisplayId(WinterBoardDisplayID)] forKey:@"IconHidden"];
-    } return self;
+- (void) setPreferenceValue:(id)value specifier:(PSSpecifier *)spec {
+    NSString *key([spec propertyForKey:@"key"]);
+    if ([[spec propertyForKey:@"negate"] boolValue])
+        value = [NSNumber numberWithBool:(![value boolValue])];
+    [_settings setValue:value forKey:key];
+    [self settingsChanged];
 }
 
-- (void) dealloc {
-    [_settings release];
-    [_plist release];
-    [super dealloc];
+- (id) readPreferenceValue:(PSSpecifier *)spec {
+    NSString *key([spec propertyForKey:@"key"]);
+    id defaultValue([spec propertyForKey:@"default"]);
+    id plistValue([_settings objectForKey:key]);
+    if (!plistValue)
+        return defaultValue;
+    if ([[spec propertyForKey:@"negate"] boolValue])
+        plistValue = [NSNumber numberWithBool:(![plistValue boolValue])];
+    return plistValue;
 }
 
 - (void) __optimizeThemes {
@@ -373,18 +371,17 @@ static NSString *_plist;
 }
 
 - (void) optimizeThemes {
-    UIActionSheet *sheet([[[UIActionSheet alloc]
+    UIAlertView *alert([[[UIAlertView alloc]
         initWithTitle:@"Optimize Themes"
-        buttons:[NSArray arrayWithObjects:@"Optimize", @"Cancel", nil]
-        defaultButtonIndex:1
+        message:@"Please note that this setting /replaces/ the PNG files that came with the theme. PNG files that have been iPhone-optimized cannot be viewed on a normal computer unless they are first deoptimized. You can use Cydia to reinstall themes that have been optimized in order to revert to the original PNG files."
         delegate:self
-        context:@"optimize"
+        cancelButtonTitle:@"Cancel"
+        otherButtonTitles:@"Optimize", nil
     ] autorelease]);
 
-    [sheet setBodyText:@"Please note that this setting /replaces/ the PNG files that came with the theme. PNG files that have been iPhone-optimized cannot be viewed on a normal computer unless they are first deoptimized. You can use Cydia to reinstall themes that have been optimized in order to revert to the original PNG files."];
-    [sheet setNumberOfRows:1];
-    [sheet setDestructiveButtonIndex:0];
-    [sheet popupAlertAnimated:YES];
+    [alert setContext:@"optimize"];
+    [alert setNumberOfRows:1];
+    [alert show];
 }
 
 - (void) _optimizeThemes {
@@ -406,20 +403,61 @@ static NSString *_plist;
     [self settingsChanged];
 }
 
-- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
-    NSString *context([sheet context]);
+- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
+    NSString *context([alert context]);
 
     if ([context isEqualToString:@"optimize"]) {
-        switch (button) {
-            case 1:
-                [self performSelector:@selector(_optimizeThemes) withObject:nil afterDelay:0];
-            break;
+        if (button == [alert firstOtherButtonIndex]) {
+            [self performSelector:@selector(_optimizeThemes) withObject:nil afterDelay:0];
         }
 
-        [sheet dismiss];
-    } else
-        [super alertSheet:sheet buttonClicked:button];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
+    }
+    /*else if ([super respondsToSelector:@selector(alertView:clickedButtonAtIndex:)])
+        [super alertView:alert clickedButtonAtIndex:button];*/
+}
+
+@end
 
+@interface WBSettingsController: PSListController {
+}
+
+- (id) initForContentSize:(CGSize)size;
+- (void) dealloc;
+- (void) suspend;
+- (void) navigationBarButtonClicked:(int)buttonIndex;
+- (void) viewWillRedisplay;
+- (void) pushController:(id)controller;
+- (id) specifiers;
+- (void) settingsChanged;
+- (NSString *) title;
+- (void) setPreferenceValue:(id)value specifier:(PSSpecifier *)spec;
+- (id) readPreferenceValue:(PSSpecifier *)spec;
+
+@end
+
+@implementation WBSettingsController
+
++ (void) load {
+    void *libhide(dlopen("/usr/lib/hide.dylib", RTLD_LAZY));
+    IsIconHiddenDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "IsIconHiddenDisplayId"));
+    HideIconViaDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "HideIconViaDisplayId"));
+    UnHideIconViaDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "UnHideIconViaDisplayId"));
+}
+
+- (id) initForContentSize:(CGSize)size {
+    if ((self = [super initForContentSize:size]) != nil) {
+        _plist = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()] retain];
+        _settings = [([NSMutableDictionary dictionaryWithContentsOfFile:_plist] ?: [NSMutableDictionary dictionary]) retain];
+
+        [_settings setObject:[NSNumber numberWithBool:IsIconHiddenDisplayId(WinterBoardDisplayID)] forKey:@"IconHidden"];
+    } return self;
+}
+
+- (void) dealloc {
+    [_settings release];
+    [_plist release];
+    [super dealloc];
 }
 
 - (void) suspend {
@@ -439,10 +477,21 @@ static NSString *_plist;
     unlink("/User/Library/Caches/com.apple.springboard-imagecache-smallicons");
     unlink("/User/Library/Caches/com.apple.springboard-imagecache-smallicons.plist");
 
+    unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen");
+    unlink("/User/Library/Caches/com.apple.SpringBoard.notificationCenterLinen");
+
+    unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.0");
+    unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.1");
+    unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.2");
+    unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.3");
+
     system("rm -rf /User/Library/Caches/SpringBoardIconCache");
     system("rm -rf /User/Library/Caches/SpringBoardIconCache-small");
+    system("rm -rf /User/Library/Caches/com.apple.IconsCache");
+    system("rm -rf /User/Library/Caches/com.apple.newsstand");
+    system("rm -rf /User/Library/Caches/com.apple.springboard.sharedimagecache");
 
-    system("killall SpringBoard");
+    system("killall lsd SpringBoard");
 }
 
 - (void) cancelChanges {
@@ -454,8 +503,10 @@ static NSString *_plist;
     [_settings setObject:[NSNumber numberWithBool:IsIconHiddenDisplayId(WinterBoardDisplayID)] forKey:@"IconHidden"];
     [self reloadSpecifiers];
     if (![[PSViewController class] instancesRespondToSelector:@selector(showLeftButton:withStyle:rightButton:withStyle:)]) {
-        self.navigationItem.leftBarButtonItem = nil;
-        self.navigationItem.rightBarButtonItem = nil;
+        [[self navigationItem] setLeftBarButtonItem:nil];
+        [[self navigationItem] setRightBarButtonItem:nil];
+    } else {
+        [self showLeftButton:nil withStyle:0 rightButton:nil withStyle:0];
     }
     settingsChanged = NO;
 }
@@ -466,8 +517,10 @@ static NSString *_plist;
         return;
     }
 
-    if (buttonIndex == 0)
+    if (buttonIndex == 0) {
         [self cancelChanges];
+        return;
+    }
 
     [self suspend];
     [self.rootController popController];
@@ -486,7 +539,8 @@ static NSString *_plist;
 - (void) viewWillAppear:(BOOL)animated {
     if (settingsChanged)
         [self settingsChanged];
-    [super viewWillAppear:animated];
+    if ([super respondsToSelector:@selector(viewWillAppear:)])
+        [super viewWillAppear:animated];
 }
 
 - (void) pushController:(id)controller {
@@ -506,8 +560,8 @@ static NSString *_plist;
         UIBarButtonItem *cancelButton([[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(settingsConfirmButtonClicked:)]);
         cancelButton.tag = 0;
         respringButton.tag = 1;
-        self.navigationItem.leftBarButtonItem = respringButton;
-        self.navigationItem.rightBarButtonItem = cancelButton;
+        [[self navigationItem] setLeftBarButtonItem:respringButton];
+        [[self navigationItem] setRightBarButtonItem:cancelButton];
         [respringButton release];
         [cancelButton release];
     } else {