X-Git-Url: https://git.saurik.com/winterboard.git/blobdiff_plain/b39b993d525e618734bb3eaece87f77f0e5290d4..refs/heads/master:/Settings.mm?ds=sidebyside
diff --git a/Settings.mm b/Settings.mm
index edc0d3f..1f011fa 100644
--- a/Settings.mm
+++ b/Settings.mm
@@ -1,39 +1,23 @@
/* WinterBoard - Theme Manager for the iPhone
- * Copyright (C) 2009-2010 Jay Freeman (saurik)
+ * Copyright (C) 2008-2014 Jay Freeman (saurik)
*/
+/* GNU Lesser General Public License, Version 3 {{{ */
/*
- * Redistribution and use in source and binary
- * forms, with or without modification, are permitted
- * provided that the following conditions are met:
+ * WinterBoard is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
*
- * 1. Redistributions of source code must retain the
- * above copyright notice, this list of conditions
- * and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions
- * and the following disclaimer in the documentation
- * and/or other materials provided with the
- * distribution.
- * 3. The name of the author may not be used to endorse
- * or promote products derived from this software
- * without specific prior written permission.
+ * WinterBoard is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
- * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with WinterBoard. If not, see .
+**/
+/* }}} */
#import
#import
@@ -44,15 +28,10 @@
#import
#import
+#include
#include
#include
-static BOOL (*IsIconHiddenDisplayId)(NSString *);
-static BOOL (*HideIconViaDisplayId)(NSString *);
-static BOOL (*UnHideIconViaDisplayId)(NSString *);
-
-static const NSString *WinterBoardDisplayID = @"com.saurik.WinterBoard";
-
extern NSString *PSTableCellKey;
extern "C" UIImage *_UIImageWithName(NSString *);
@@ -63,6 +42,67 @@ static BOOL settingsChanged;
static NSMutableDictionary *_settings;
static NSString *_plist;
+void AddThemes(NSMutableArray *themesOnDisk, NSString *folder) {
+ NSArray *themes([[NSFileManager defaultManager] contentsOfDirectoryAtPath:folder error:NULL]);
+ for (NSString *theme in themes) {
+ if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/Info.plist", folder, theme]]) {
+ if (NSArray *version = [info objectForKey:@"CoreFoundationVersion"]) {
+ size_t count([version count]);
+ if (count == 0 || count > 2)
+ continue;
+
+ double lower([[version objectAtIndex:0] doubleValue]);
+ if (kCFCoreFoundationVersionNumber < lower)
+ continue;
+
+ if (count != 1) {
+ double upper([[version objectAtIndex:1] doubleValue]);
+ if (upper <= kCFCoreFoundationVersionNumber)
+ continue;
+ }
+ }
+ }
+
+ [themesOnDisk addObject:theme];
+ }
+}
+
+static void RestartSpringBoard() {
+ unlink("/User/Library/Caches/com.apple.springboard-imagecache-icons");
+ unlink("/User/Library/Caches/com.apple.springboard-imagecache-icons.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("rm -rf /User/Library/Caches/com.apple.UIStatusBar");
+
+ system("rm -rf /User/Library/Caches/BarDialer");
+ system("rm -rf /User/Library/Caches/BarDialer_selected");
+ system("rm -rf /User/Library/Caches/BarRecents");
+ system("rm -rf /User/Library/Caches/BarRecents_selected");
+ system("rm -rf /User/Library/Caches/BarVM");
+ system("rm -rf /User/Library/Caches/BarVM_selected");
+
+ system("killall -9 lsd");
+
+ if (kCFCoreFoundationVersionNumber > 700) // XXX: iOS 6.x
+ system("killall backboardd");
+ else
+ system("killall SpringBoard");
+}
+
/* [NSObject yieldToSelector:(withObject:)] {{{*/
@interface NSObject (wb$yieldToSelector)
- (id) wb$yieldToSelector:(SEL)selector withObject:(id)object;
@@ -135,6 +175,60 @@ static NSString *_plist;
/* }}} */
/* Theme Settings Controller {{{ */
+@interface WBSThemesTableViewCell : UITableViewCell {
+ UIImageView *checkmark_;
+ UIImageView *icon_;
+ UILabel *name_;
+}
+
+@end
+
+@implementation WBSThemesTableViewCell
+
+- (void) dealloc {
+ [checkmark_ release];
+ [icon_ release];
+ [name_ release];
+ [super dealloc];
+}
+
+- (id) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuse {
+ if ((self = [super initWithFrame:frame reuseIdentifier:reuse]) != nil) {
+ CGFloat border(48), check(40), icon(64);
+ UIView *content([self contentView]);
+ CGSize size([content frame].size);
+
+ checkmark_ = [[UIImageView alloc] initWithFrame:CGRectMake(std::floor((border - check) / 2), 0, check, size.height)];
+ [checkmark_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
+ [content addSubview:checkmark_];
+
+ name_ = [[UILabel alloc] initWithFrame:CGRectMake(border, 0, 0, size.height)];
+ [name_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+ [content addSubview:name_];
+
+ icon_ = [[UIImageView alloc] initWithFrame:CGRectMake(size.width - icon - 48, 0, icon, icon)];
+ [content addSubview:icon_];
+ } return self;
+}
+
+- (void) setCheck:(bool)inactive {
+ [self setImage:(inactive ? uncheckedImage : checkImage)];
+}
+
+- (void) setTheme:(NSDictionary *)theme {
+ [name_ setText:[theme objectForKey:@"Name"]];
+
+ NSNumber *active([theme objectForKey:@"Active"]);
+ BOOL inactive(active == nil || ![active boolValue]);
+ [self setCheck:inactive];
+
+ CGRect area([name_ frame]);
+ area.size.width = ([icon_ image] == nil ? self.contentView.frame.size.width : icon_.frame.origin.x) - area.origin.x - 9;
+ [name_ setFrame:area];
+}
+
+@end
+
@interface WBSThemesController: PSViewController {
UITableView *_tableView;
NSMutableArray *_themes;
@@ -142,8 +236,6 @@ static NSString *_plist;
@property (nonatomic, retain) NSMutableArray *themes;
-+ (void) load;
-
- (id) initForContentSize:(CGSize)size;
- (id) view;
- (id) navigationTitle;
@@ -165,7 +257,7 @@ static NSString *_plist;
@synthesize themes = _themes;
-+ (void) load {
++ (void) initialize {
NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
checkImage = [_UIImageWithName(@"UIPreferencesBlueCheck.png") retain];
uncheckedImage = [[UIImage imageWithContentsOfFile:@"/System/Library/PreferenceBundles/WinterBoardSettings.bundle/SearchResultsCheckmarkClear.png"] retain];
@@ -189,16 +281,8 @@ static NSString *_plist;
}
NSMutableArray *themesOnDisk([NSMutableArray array]);
-
- [themesOnDisk
- addObjectsFromArray:[[NSFileManager defaultManager]
- contentsOfDirectoryAtPath:@"/Library/Themes" error:NULL]
- ];
-
- [themesOnDisk addObjectsFromArray:[[NSFileManager defaultManager]
- contentsOfDirectoryAtPath:[NSString stringWithFormat:@"%@/Library/SummerBoard/Themes", NSHomeDirectory()]
- error:NULL
- ]];
+ AddThemes(themesOnDisk, @"/Library/Themes");
+ AddThemes(themesOnDisk, [NSString stringWithFormat:@"%@/Library/SummerBoard/Themes", NSHomeDirectory()]);
for (int i = 0, count = [themesOnDisk count]; i < count; i++) {
NSString *theme = [themesOnDisk objectAtIndex:i];
@@ -232,7 +316,8 @@ static NSString *_plist;
nil] atIndex:0];
}
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-64) style:UITableViewStyleGrouped];
+ _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-64) style:UITableViewStylePlain];
+ [_tableView setRowHeight:48];
[_tableView setDataSource:self];
[_tableView setDelegate:self];
[_tableView setEditing:YES];
@@ -275,18 +360,14 @@ static NSString *_plist;
}
- (id) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ThemeCell"];
+ WBSThemesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ThemeCell"];
if (!cell) {
- cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 100, 100) reuseIdentifier:@"ThemeCell"] autorelease];
+ cell = [[[WBSThemesTableViewCell alloc] initWithFrame:CGRectMake(0, 0, 100, 100) reuseIdentifier:@"ThemeCell"] autorelease];
//[cell setTableViewStyle:UITableViewCellStyleDefault];
}
NSDictionary *theme([_themes objectAtIndex:indexPath.row]);
- cell.text = [theme objectForKey:@"Name"];
- cell.hidesAccessoryWhenEditing = NO;
- NSNumber *active([theme objectForKey:@"Active"]);
- BOOL inactive(active == nil || ![active boolValue]);
- [cell setImage:(inactive ? uncheckedImage : checkImage)];
+ [cell setTheme:theme];
return cell;
}
@@ -327,45 +408,47 @@ 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(dlsym(libhide, "IsIconHiddenDisplayId"));
- HideIconViaDisplayId = reinterpret_cast(dlsym(libhide, "HideIconViaDisplayId"));
- UnHideIconViaDisplayId = reinterpret_cast(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) restartSpringBoard {
+ RestartSpringBoard();
}
- (void) __optimizeThemes {
@@ -373,18 +456,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 +488,69 @@ 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) _wb$loadSettings {
+ _plist = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()] retain];
+ _settings = [NSMutableDictionary dictionaryWithContentsOfFile:_plist];
+
+ bool set;
+ if (_settings != nil)
+ set = true;
+ else {
+ set = false;
+ _settings = [NSMutableDictionary dictionary];
+ }
+
+ _settings = [_settings retain];
+
+ if ([_settings objectForKey:@"SummerBoard"] == nil)
+ [_settings setObject:[NSNumber numberWithBool:set] forKey:@"SummerBoard"];
+}
+
+- (id) initForContentSize:(CGSize)size {
+ if ((self = [super initForContentSize:size]) != nil) {
+ [self _wb$loadSettings];
+ } return self;
+}
+
+- (void) dealloc {
+ [_settings release];
+ [_plist release];
+ [super dealloc];
}
- (void) suspend {
@@ -432,30 +563,21 @@ static NSString *_plist;
if (![data writeToFile:_plist options:NSAtomicWrite error:NULL])
return;
- ([[_settings objectForKey:@"IconHidden"] boolValue] ? HideIconViaDisplayId : UnHideIconViaDisplayId)(WinterBoardDisplayID);
-
- unlink("/User/Library/Caches/com.apple.springboard-imagecache-icons");
- unlink("/User/Library/Caches/com.apple.springboard-imagecache-icons.plist");
- unlink("/User/Library/Caches/com.apple.springboard-imagecache-smallicons");
- unlink("/User/Library/Caches/com.apple.springboard-imagecache-smallicons.plist");
-
- system("rm -rf /User/Library/Caches/SpringBoardIconCache");
- system("rm -rf /User/Library/Caches/SpringBoardIconCache-small");
-
- system("killall SpringBoard");
+ RestartSpringBoard();
}
- (void) cancelChanges {
[_settings release];
[_plist release];
- _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"];
+ [self _wb$loadSettings];
+
[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 +588,10 @@ static NSString *_plist;
return;
}
- if (buttonIndex == 0)
+ if (buttonIndex == 0) {
[self cancelChanges];
+ return;
+ }
[self suspend];
[self.rootController popController];
@@ -486,7 +610,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 {
@@ -495,8 +620,28 @@ static NSString *_plist;
}
- (id) specifiers {
- if (!_specifiers)
- _specifiers = [[self loadSpecifiersFromPlistName:@"WinterBoard" target:self] retain];
+ if (!_specifiers) {
+ NSMutableArray *specifiers([NSMutableArray array]);
+ for (PSSpecifier *specifier in [self loadSpecifiersFromPlistName:@"WinterBoard" target:self]) {
+ if (NSArray *version = [specifier propertyForKey:@"wb$filter"]) {
+ size_t count([version count]);
+ if (count == 0 || count > 2)
+ continue;
+
+ double lower([[version objectAtIndex:0] doubleValue]);
+ if (kCFCoreFoundationVersionNumber < lower)
+ continue;
+
+ if (count != 1) {
+ double upper([[version objectAtIndex:1] doubleValue]);
+ if (upper <= kCFCoreFoundationVersionNumber)
+ continue;
+ }
+ }
+ [specifiers addObject:specifier];
+ }
+ _specifiers = [specifiers retain];
+ }
return _specifiers;
}
@@ -506,8 +651,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 {