]> git.saurik.com Git - winterboard.git/blobdiff - Settings.mm
Commit @3x logic (as it is getting in my way :/).
[winterboard.git] / Settings.mm
index 5f1ab8cf93e17d61809f17ed0aa8da16159c727a..c2599a0fffac7229a18f895006340e8eedd35296 100644 (file)
@@ -48,6 +48,31 @@ 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];
+    }
+}
+
 /* [NSObject yieldToSelector:(withObject:)] {{{*/
 @interface NSObject (wb$yieldToSelector)
 - (id) wb$yieldToSelector:(SEL)selector withObject:(id)object;
@@ -120,6 +145,28 @@ static NSString *_plist;
 /* }}} */
 
 /* Theme Settings Controller {{{ */
+@interface WBSThemesTableViewCell : UITableViewCell {
+}
+
+@end
+
+@implementation WBSThemesTableViewCell
+
+- (id) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuse {
+    if ((self = [super initWithFrame:frame reuseIdentifier:reuse]) != nil) {
+    } return self;
+}
+
+- (void) setTheme:(NSDictionary *)theme {
+    self.text = [theme objectForKey:@"Name"];
+    self.hidesAccessoryWhenEditing = NO;
+    NSNumber *active([theme objectForKey:@"Active"]);
+    BOOL inactive(active == nil || ![active boolValue]);
+    [self setImage:(inactive ? uncheckedImage : checkImage)];
+}
+
+@end
+
 @interface WBSThemesController: PSViewController <UITableViewDelegate, UITableViewDataSource> {
     UITableView *_tableView;
     NSMutableArray *_themes;
@@ -127,8 +174,6 @@ static NSString *_plist;
 
 @property (nonatomic, retain) NSMutableArray *themes;
 
-+ (void) load;
-
 - (id) initForContentSize:(CGSize)size;
 - (id) view;
 - (id) navigationTitle;
@@ -150,7 +195,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];
@@ -174,16 +219,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];
@@ -260,18 +297,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;
 }
 
@@ -494,6 +527,14 @@ static NSString *_plist;
     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");
 
@@ -557,8 +598,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;
 }