]> git.saurik.com Git - winterboard.git/blobdiff - Settings.mm
Support NSAttributedString for iOS 9 calendar day.
[winterboard.git] / Settings.mm
index 2423d56e2811ded4637af305803e22728ea362ce..1f011fa10593dfec02ba79842dc8b5246f92c48d 100644 (file)
 #import <Preferences/PSTableCell.h>
 #import <UIKit/UINavigationButton.h>
 
 #import <Preferences/PSTableCell.h>
 #import <UIKit/UINavigationButton.h>
 
+#include <cmath>
 #include <dlfcn.h>
 #include <objc/runtime.h>
 
 #include <dlfcn.h>
 #include <objc/runtime.h>
 
-static void *libhide;
-static BOOL (*IsIconHiddenDisplayId)(NSString *);
-static BOOL (*HideIconViaDisplayId)(NSString *);
-static BOOL (*UnHideIconViaDisplayId)(NSString *);
-
-static NSString *WinterBoardDisplayID = @"com.saurik.WinterBoard";
-
 extern NSString *PSTableCellKey;
 extern "C" UIImage *_UIImageWithName(NSString *);
 
 extern NSString *PSTableCellKey;
 extern "C" UIImage *_UIImageWithName(NSString *);
 
@@ -73,6 +67,42 @@ void AddThemes(NSMutableArray *themesOnDisk, NSString *folder) {
     }
 }
 
     }
 }
 
+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;
 /* [NSObject yieldToSelector:(withObject:)] {{{*/
 @interface NSObject (wb$yieldToSelector)
 - (id) wb$yieldToSelector:(SEL)selector withObject:(id)object;
@@ -145,6 +175,60 @@ void AddThemes(NSMutableArray *themesOnDisk, NSString *folder) {
 /* }}} */
 
 /* Theme Settings Controller {{{ */
 /* }}} */
 
 /* 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 <UITableViewDelegate, UITableViewDataSource> {
     UITableView *_tableView;
     NSMutableArray *_themes;
 @interface WBSThemesController: PSViewController <UITableViewDelegate, UITableViewDataSource> {
     UITableView *_tableView;
     NSMutableArray *_themes;
@@ -232,7 +316,8 @@ void AddThemes(NSMutableArray *themesOnDisk, NSString *folder) {
             nil] atIndex:0];
         }
 
             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];
         [_tableView setDataSource:self];
         [_tableView setDelegate:self];
         [_tableView setEditing:YES];
@@ -275,18 +360,14 @@ void AddThemes(NSMutableArray *themesOnDisk, NSString *folder) {
 }
 
 - (id) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 }
 
 - (id) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ThemeCell"];
+    WBSThemesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ThemeCell"];
     if (!cell) {
     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 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;
 }
 
     return cell;
 }
 
@@ -366,6 +447,10 @@ void AddThemes(NSMutableArray *themesOnDisk, NSString *folder) {
     return plistValue;
 }
 
     return plistValue;
 }
 
+- (void) restartSpringBoard {
+    RestartSpringBoard();
+}
+
 - (void) __optimizeThemes {
     system("/usr/libexec/winterboard/Optimize");
 }
 - (void) __optimizeThemes {
     system("/usr/libexec/winterboard/Optimize");
 }
@@ -438,13 +523,6 @@ void AddThemes(NSMutableArray *themesOnDisk, NSString *folder) {
 
 @implementation WBSettingsController
 
 
 @implementation WBSettingsController
 
-+ (void) load {
-    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"));
-}
-
 - (void) _wb$loadSettings {
     _plist = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()] retain];
     _settings = [NSMutableDictionary dictionaryWithContentsOfFile:_plist];
 - (void) _wb$loadSettings {
     _plist = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()] retain];
     _settings = [NSMutableDictionary dictionaryWithContentsOfFile:_plist];
@@ -461,9 +539,6 @@ void AddThemes(NSMutableArray *themesOnDisk, NSString *folder) {
 
     if ([_settings objectForKey:@"SummerBoard"] == nil)
         [_settings setObject:[NSNumber numberWithBool:set] forKey:@"SummerBoard"];
 
     if ([_settings objectForKey:@"SummerBoard"] == nil)
         [_settings setObject:[NSNumber numberWithBool:set] forKey:@"SummerBoard"];
-
-    if (libhide != NULL)
-        [_settings setObject:[NSNumber numberWithBool:IsIconHiddenDisplayId(WinterBoardDisplayID)] forKey:@"IconHidden"];
 }
 
 - (id) initForContentSize:(CGSize)size {
 }
 
 - (id) initForContentSize:(CGSize)size {
@@ -488,41 +563,7 @@ void AddThemes(NSMutableArray *themesOnDisk, NSString *folder) {
     if (![data writeToFile:_plist options:NSAtomicWrite error:NULL])
         return;
 
     if (![data writeToFile:_plist options:NSAtomicWrite error:NULL])
         return;
 
-    if (libhide != NULL)
-        ([[_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");
-
-    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/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");
+    RestartSpringBoard();
 }
 
 - (void) cancelChanges {
 }
 
 - (void) cancelChanges {