]> git.saurik.com Git - winterboard.git/blob - Settings.mm
Add the new @3x 29x29 and 60x60 icon from Surenix.
[winterboard.git] / Settings.mm
1 /* WinterBoard - Theme Manager for the iPhone
2 * Copyright (C) 2008-2014 Jay Freeman (saurik)
3 */
4
5 /* GNU Lesser General Public License, Version 3 {{{ */
6 /*
7 * WinterBoard is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * WinterBoard is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with WinterBoard. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #import <Foundation/Foundation.h>
23 #import <UIKit/UIKit.h>
24 #import <Preferences/PSRootController.h>
25 #import <Preferences/PSViewController.h>
26 #import <Preferences/PSListController.h>
27 #import <Preferences/PSSpecifier.h>
28 #import <Preferences/PSTableCell.h>
29 #import <UIKit/UINavigationButton.h>
30
31 #include <dlfcn.h>
32 #include <objc/runtime.h>
33
34 static void *libhide;
35 static BOOL (*IsIconHiddenDisplayId)(NSString *);
36 static BOOL (*HideIconViaDisplayId)(NSString *);
37 static BOOL (*UnHideIconViaDisplayId)(NSString *);
38
39 static NSString *WinterBoardDisplayID = @"com.saurik.WinterBoard";
40
41 extern NSString *PSTableCellKey;
42 extern "C" UIImage *_UIImageWithName(NSString *);
43
44 static UIImage *checkImage;
45 static UIImage *uncheckedImage;
46
47 static BOOL settingsChanged;
48 static NSMutableDictionary *_settings;
49 static NSString *_plist;
50
51 void AddThemes(NSMutableArray *themesOnDisk, NSString *folder) {
52 NSArray *themes([[NSFileManager defaultManager] contentsOfDirectoryAtPath:folder error:NULL]);
53 for (NSString *theme in themes) {
54 if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/Info.plist", folder, theme]]) {
55 if (NSArray *version = [info objectForKey:@"CoreFoundationVersion"]) {
56 size_t count([version count]);
57 if (count == 0 || count > 2)
58 continue;
59
60 double lower([[version objectAtIndex:0] doubleValue]);
61 if (kCFCoreFoundationVersionNumber < lower)
62 continue;
63
64 if (count != 1) {
65 double upper([[version objectAtIndex:1] doubleValue]);
66 if (upper <= kCFCoreFoundationVersionNumber)
67 continue;
68 }
69 }
70 }
71
72 [themesOnDisk addObject:theme];
73 }
74 }
75
76 /* [NSObject yieldToSelector:(withObject:)] {{{*/
77 @interface NSObject (wb$yieldToSelector)
78 - (id) wb$yieldToSelector:(SEL)selector withObject:(id)object;
79 - (id) wb$yieldToSelector:(SEL)selector;
80 @end
81
82 @implementation NSObject (Cydia)
83
84 - (void) wb$doNothing {
85 }
86
87 - (void) wb$_yieldToContext:(NSMutableArray *)context {
88 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
89
90 SEL selector(reinterpret_cast<SEL>([[context objectAtIndex:0] pointerValue]));
91 id object([[context objectAtIndex:1] nonretainedObjectValue]);
92 volatile bool &stopped(*reinterpret_cast<bool *>([[context objectAtIndex:2] pointerValue]));
93
94 /* XXX: deal with exceptions */
95 id value([self performSelector:selector withObject:object]);
96
97 NSMethodSignature *signature([self methodSignatureForSelector:selector]);
98 [context removeAllObjects];
99 if ([signature methodReturnLength] != 0 && value != nil)
100 [context addObject:value];
101
102 stopped = true;
103
104 [self
105 performSelectorOnMainThread:@selector(wb$doNothing)
106 withObject:nil
107 waitUntilDone:NO
108 ];
109
110 [pool release];
111 }
112
113 - (id) wb$yieldToSelector:(SEL)selector withObject:(id)object {
114 /*return [self performSelector:selector withObject:object];*/
115
116 volatile bool stopped(false);
117
118 NSMutableArray *context([NSMutableArray arrayWithObjects:
119 [NSValue valueWithPointer:selector],
120 [NSValue valueWithNonretainedObject:object],
121 [NSValue valueWithPointer:const_cast<bool *>(&stopped)],
122 nil]);
123
124 NSThread *thread([[[NSThread alloc]
125 initWithTarget:self
126 selector:@selector(wb$_yieldToContext:)
127 object:context
128 ] autorelease]);
129
130 [thread start];
131
132 NSRunLoop *loop([NSRunLoop currentRunLoop]);
133 NSDate *future([NSDate distantFuture]);
134
135 while (!stopped && [loop runMode:NSDefaultRunLoopMode beforeDate:future]);
136
137 return [context count] == 0 ? nil : [context objectAtIndex:0];
138 }
139
140 - (id) wb$yieldToSelector:(SEL)selector {
141 return [self wb$yieldToSelector:selector withObject:nil];
142 }
143
144 @end
145 /* }}} */
146
147 /* Theme Settings Controller {{{ */
148 @interface WBSThemesTableViewCell : UITableViewCell {
149 }
150
151 @end
152
153 @implementation WBSThemesTableViewCell
154
155 - (id) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuse {
156 if ((self = [super initWithFrame:frame reuseIdentifier:reuse]) != nil) {
157 } return self;
158 }
159
160 - (void) setTheme:(NSDictionary *)theme {
161 self.text = [theme objectForKey:@"Name"];
162 self.hidesAccessoryWhenEditing = NO;
163 NSNumber *active([theme objectForKey:@"Active"]);
164 BOOL inactive(active == nil || ![active boolValue]);
165 [self setImage:(inactive ? uncheckedImage : checkImage)];
166 }
167
168 @end
169
170 @interface WBSThemesController: PSViewController <UITableViewDelegate, UITableViewDataSource> {
171 UITableView *_tableView;
172 NSMutableArray *_themes;
173 }
174
175 @property (nonatomic, retain) NSMutableArray *themes;
176
177 - (id) initForContentSize:(CGSize)size;
178 - (id) view;
179 - (id) navigationTitle;
180 - (void) themesChanged;
181
182 - (int) numberOfSectionsInTableView:(UITableView *)tableView;
183 - (id) tableView:(UITableView *)tableView titleForHeaderInSection:(int)section;
184 - (int) tableView:(UITableView *)tableView numberOfRowsInSection:(int)section;
185 - (id) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
186 - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
187 - (void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath;
188 - (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
189 - (BOOL) tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath;
190 - (BOOL) tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
191
192 @end
193
194 @implementation WBSThemesController
195
196 @synthesize themes = _themes;
197
198 + (void) initialize {
199 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
200 checkImage = [_UIImageWithName(@"UIPreferencesBlueCheck.png") retain];
201 uncheckedImage = [[UIImage imageWithContentsOfFile:@"/System/Library/PreferenceBundles/WinterBoardSettings.bundle/SearchResultsCheckmarkClear.png"] retain];
202 [pool release];
203 }
204
205 - (id) initForContentSize:(CGSize)size {
206 if ((self = [super initForContentSize:size]) != nil) {
207 self.themes = [_settings objectForKey:@"Themes"];
208 if (!_themes) {
209 if (NSString *theme = [_settings objectForKey:@"Theme"]) {
210 self.themes = [NSMutableArray arrayWithObject:
211 [NSMutableDictionary dictionaryWithObjectsAndKeys:
212 theme, @"Name",
213 [NSNumber numberWithBool:YES], @"Active", nil]];
214 [_settings removeObjectForKey:@"Theme"];
215 }
216 if (!_themes)
217 self.themes = [NSMutableArray array];
218 [_settings setObject:_themes forKey:@"Themes"];
219 }
220
221 NSMutableArray *themesOnDisk([NSMutableArray array]);
222 AddThemes(themesOnDisk, @"/Library/Themes");
223 AddThemes(themesOnDisk, [NSString stringWithFormat:@"%@/Library/SummerBoard/Themes", NSHomeDirectory()]);
224
225 for (int i = 0, count = [themesOnDisk count]; i < count; i++) {
226 NSString *theme = [themesOnDisk objectAtIndex:i];
227 if ([theme hasSuffix:@".theme"])
228 [themesOnDisk replaceObjectAtIndex:i withObject:[theme stringByDeletingPathExtension]];
229 }
230
231 NSMutableSet *themesSet([NSMutableSet set]);
232
233 for (int i = 0, count = [_themes count]; i < count; i++) {
234 NSDictionary *theme([_themes objectAtIndex:i]);
235 NSString *name([theme objectForKey:@"Name"]);
236
237 if (!name || ![themesOnDisk containsObject:name]) {
238 [_themes removeObjectAtIndex:i];
239 i--;
240 count--;
241 } else {
242 [themesSet addObject:name];
243 }
244 }
245
246 for (NSString *theme in themesOnDisk) {
247 if ([themesSet containsObject:theme])
248 continue;
249 [themesSet addObject:theme];
250
251 [_themes insertObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
252 theme, @"Name",
253 [NSNumber numberWithBool:NO], @"Active",
254 nil] atIndex:0];
255 }
256
257 _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-64) style:UITableViewStyleGrouped];
258 [_tableView setDataSource:self];
259 [_tableView setDelegate:self];
260 [_tableView setEditing:YES];
261 [_tableView setAllowsSelectionDuringEditing:YES];
262 if ([self respondsToSelector:@selector(setView:)])
263 [self setView:_tableView];
264 }
265 return self;
266 }
267
268 - (void) dealloc {
269 [_tableView release];
270 [_themes release];
271 [super dealloc];
272 }
273
274 - (id) navigationTitle {
275 return @"Themes";
276 }
277
278 - (id) view {
279 return _tableView;
280 }
281
282 - (void) themesChanged {
283 settingsChanged = YES;
284 }
285
286 /* UITableViewDelegate / UITableViewDataSource Methods {{{ */
287 - (int) numberOfSectionsInTableView:(UITableView *)tableView {
288 return 1;
289 }
290
291 - (id) tableView:(UITableView *)tableView titleForHeaderInSection:(int)section {
292 return nil;
293 }
294
295 - (int) tableView:(UITableView *)tableView numberOfRowsInSection:(int)section {
296 return _themes.count;
297 }
298
299 - (id) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
300 WBSThemesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ThemeCell"];
301 if (!cell) {
302 cell = [[[WBSThemesTableViewCell alloc] initWithFrame:CGRectMake(0, 0, 100, 100) reuseIdentifier:@"ThemeCell"] autorelease];
303 //[cell setTableViewStyle:UITableViewCellStyleDefault];
304 }
305
306 NSDictionary *theme([_themes objectAtIndex:indexPath.row]);
307 [cell setTheme:theme];
308 return cell;
309 }
310
311 - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
312 UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
313 NSMutableDictionary *theme = [_themes objectAtIndex:indexPath.row];
314 NSNumber *active = [theme objectForKey:@"Active"];
315 BOOL inactive = active == nil || ![active boolValue];
316 [theme setObject:[NSNumber numberWithBool:inactive] forKey:@"Active"];
317 [cell setImage:(!inactive ? uncheckedImage : checkImage)];
318 [tableView deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:YES];
319 [self themesChanged];
320 }
321
322 - (void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
323 NSUInteger fromIndex = [fromIndexPath row];
324 NSUInteger toIndex = [toIndexPath row];
325 if (fromIndex == toIndex)
326 return;
327 NSMutableDictionary *theme = [[[_themes objectAtIndex:fromIndex] retain] autorelease];
328 [_themes removeObjectAtIndex:fromIndex];
329 [_themes insertObject:theme atIndex:toIndex];
330 [self themesChanged];
331 }
332
333 - (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
334 return UITableViewCellEditingStyleNone;
335 }
336
337 - (BOOL) tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
338 return NO;
339 }
340
341 - (BOOL) tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
342 return YES;
343 }
344 /* }}} */
345 @end
346 /* }}} */
347
348 @interface WBAdvancedController: PSListController {
349 }
350
351 - (id) specifiers;
352 - (void) settingsChanged;
353
354 @end
355
356 @implementation WBAdvancedController
357
358 - (id) specifiers {
359 if (!_specifiers)
360 _specifiers = [[self loadSpecifiersFromPlistName:@"Advanced" target:self] retain];
361 return _specifiers;
362 }
363
364 - (void) settingsChanged {
365 settingsChanged = YES;
366 }
367
368 - (void) setPreferenceValue:(id)value specifier:(PSSpecifier *)spec {
369 NSString *key([spec propertyForKey:@"key"]);
370 if ([[spec propertyForKey:@"negate"] boolValue])
371 value = [NSNumber numberWithBool:(![value boolValue])];
372 [_settings setValue:value forKey:key];
373 [self settingsChanged];
374 }
375
376 - (id) readPreferenceValue:(PSSpecifier *)spec {
377 NSString *key([spec propertyForKey:@"key"]);
378 id defaultValue([spec propertyForKey:@"default"]);
379 id plistValue([_settings objectForKey:key]);
380 if (!plistValue)
381 return defaultValue;
382 if ([[spec propertyForKey:@"negate"] boolValue])
383 plistValue = [NSNumber numberWithBool:(![plistValue boolValue])];
384 return plistValue;
385 }
386
387 - (void) __optimizeThemes {
388 system("/usr/libexec/winterboard/Optimize");
389 }
390
391 - (void) optimizeThemes {
392 UIAlertView *alert([[[UIAlertView alloc]
393 initWithTitle:@"Optimize Themes"
394 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."
395 delegate:self
396 cancelButtonTitle:@"Cancel"
397 otherButtonTitles:@"Optimize", nil
398 ] autorelease]);
399
400 [alert setContext:@"optimize"];
401 [alert setNumberOfRows:1];
402 [alert show];
403 }
404
405 - (void) _optimizeThemes {
406 UIView *view([self view]);
407 UIWindow *window([view window]);
408
409 UIProgressHUD *hud([[[UIProgressHUD alloc] initWithWindow:window] autorelease]);
410 [hud setText:@"Reticulating Splines\nPlease Wait (Minutes)"];
411
412 [window setUserInteractionEnabled:NO];
413
414 [window addSubview:hud];
415 [hud show:YES];
416 [self wb$yieldToSelector:@selector(__optimizeThemes)];
417 [hud removeFromSuperview];
418
419 [window setUserInteractionEnabled:YES];
420
421 [self settingsChanged];
422 }
423
424 - (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
425 NSString *context([alert context]);
426
427 if ([context isEqualToString:@"optimize"]) {
428 if (button == [alert firstOtherButtonIndex]) {
429 [self performSelector:@selector(_optimizeThemes) withObject:nil afterDelay:0];
430 }
431
432 [alert dismissWithClickedButtonIndex:-1 animated:YES];
433 }
434 /*else if ([super respondsToSelector:@selector(alertView:clickedButtonAtIndex:)])
435 [super alertView:alert clickedButtonAtIndex:button];*/
436 }
437
438 @end
439
440 @interface WBSettingsController: PSListController {
441 }
442
443 - (id) initForContentSize:(CGSize)size;
444 - (void) dealloc;
445 - (void) suspend;
446 - (void) navigationBarButtonClicked:(int)buttonIndex;
447 - (void) viewWillRedisplay;
448 - (void) pushController:(id)controller;
449 - (id) specifiers;
450 - (void) settingsChanged;
451 - (NSString *) title;
452 - (void) setPreferenceValue:(id)value specifier:(PSSpecifier *)spec;
453 - (id) readPreferenceValue:(PSSpecifier *)spec;
454
455 @end
456
457 @implementation WBSettingsController
458
459 + (void) load {
460 libhide = dlopen("/usr/lib/hide.dylib", RTLD_LAZY);
461 IsIconHiddenDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "IsIconHiddenDisplayId"));
462 HideIconViaDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "HideIconViaDisplayId"));
463 UnHideIconViaDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "UnHideIconViaDisplayId"));
464 }
465
466 - (void) _wb$loadSettings {
467 _plist = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()] retain];
468 _settings = [NSMutableDictionary dictionaryWithContentsOfFile:_plist];
469
470 bool set;
471 if (_settings != nil)
472 set = true;
473 else {
474 set = false;
475 _settings = [NSMutableDictionary dictionary];
476 }
477
478 _settings = [_settings retain];
479
480 if ([_settings objectForKey:@"SummerBoard"] == nil)
481 [_settings setObject:[NSNumber numberWithBool:set] forKey:@"SummerBoard"];
482
483 if (libhide != NULL)
484 [_settings setObject:[NSNumber numberWithBool:IsIconHiddenDisplayId(WinterBoardDisplayID)] forKey:@"IconHidden"];
485 }
486
487 - (id) initForContentSize:(CGSize)size {
488 if ((self = [super initForContentSize:size]) != nil) {
489 [self _wb$loadSettings];
490 } return self;
491 }
492
493 - (void) dealloc {
494 [_settings release];
495 [_plist release];
496 [super dealloc];
497 }
498
499 - (void) suspend {
500 if (!settingsChanged)
501 return;
502
503 NSData *data([NSPropertyListSerialization dataFromPropertyList:_settings format:NSPropertyListBinaryFormat_v1_0 errorDescription:NULL]);
504 if (!data)
505 return;
506 if (![data writeToFile:_plist options:NSAtomicWrite error:NULL])
507 return;
508
509 if (libhide != NULL)
510 ([[_settings objectForKey:@"IconHidden"] boolValue] ? HideIconViaDisplayId : UnHideIconViaDisplayId)(WinterBoardDisplayID);
511
512 unlink("/User/Library/Caches/com.apple.springboard-imagecache-icons");
513 unlink("/User/Library/Caches/com.apple.springboard-imagecache-icons.plist");
514 unlink("/User/Library/Caches/com.apple.springboard-imagecache-smallicons");
515 unlink("/User/Library/Caches/com.apple.springboard-imagecache-smallicons.plist");
516
517 unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen");
518 unlink("/User/Library/Caches/com.apple.SpringBoard.notificationCenterLinen");
519
520 unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.0");
521 unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.1");
522 unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.2");
523 unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.3");
524
525 system("rm -rf /User/Library/Caches/SpringBoardIconCache");
526 system("rm -rf /User/Library/Caches/SpringBoardIconCache-small");
527 system("rm -rf /User/Library/Caches/com.apple.IconsCache");
528 system("rm -rf /User/Library/Caches/com.apple.newsstand");
529 system("rm -rf /User/Library/Caches/com.apple.springboard.sharedimagecache");
530 system("rm -rf /User/Library/Caches/com.apple.UIStatusBar");
531
532 system("rm -rf /User/Library/Caches/BarDialer");
533 system("rm -rf /User/Library/Caches/BarDialer_selected");
534 system("rm -rf /User/Library/Caches/BarRecents");
535 system("rm -rf /User/Library/Caches/BarRecents_selected");
536 system("rm -rf /User/Library/Caches/BarVM");
537 system("rm -rf /User/Library/Caches/BarVM_selected");
538
539 system("killall -9 lsd");
540
541 if (kCFCoreFoundationVersionNumber > 700) // XXX: iOS 6.x
542 system("killall backboardd");
543 else
544 system("killall SpringBoard");
545 }
546
547 - (void) cancelChanges {
548 [_settings release];
549 [_plist release];
550
551 [self _wb$loadSettings];
552
553 [self reloadSpecifiers];
554 if (![[PSViewController class] instancesRespondToSelector:@selector(showLeftButton:withStyle:rightButton:withStyle:)]) {
555 [[self navigationItem] setLeftBarButtonItem:nil];
556 [[self navigationItem] setRightBarButtonItem:nil];
557 } else {
558 [self showLeftButton:nil withStyle:0 rightButton:nil withStyle:0];
559 }
560 settingsChanged = NO;
561 }
562
563 - (void) navigationBarButtonClicked:(int)buttonIndex {
564 if (!settingsChanged) {
565 [super navigationBarButtonClicked:buttonIndex];
566 return;
567 }
568
569 if (buttonIndex == 0) {
570 [self cancelChanges];
571 return;
572 }
573
574 [self suspend];
575 [self.rootController popController];
576 }
577
578 - (void) settingsConfirmButtonClicked:(UIBarButtonItem *)button {
579 [self navigationBarButtonClicked:button.tag];
580 }
581
582 - (void) viewWillRedisplay {
583 if (settingsChanged)
584 [self settingsChanged];
585 [super viewWillRedisplay];
586 }
587
588 - (void) viewWillAppear:(BOOL)animated {
589 if (settingsChanged)
590 [self settingsChanged];
591 if ([super respondsToSelector:@selector(viewWillAppear:)])
592 [super viewWillAppear:animated];
593 }
594
595 - (void) pushController:(id)controller {
596 [self hideNavigationBarButtons];
597 [super pushController:controller];
598 }
599
600 - (id) specifiers {
601 if (!_specifiers) {
602 NSMutableArray *specifiers([NSMutableArray array]);
603 for (PSSpecifier *specifier in [self loadSpecifiersFromPlistName:@"WinterBoard" target:self]) {
604 if (NSArray *version = [specifier propertyForKey:@"wb$filter"]) {
605 size_t count([version count]);
606 if (count == 0 || count > 2)
607 continue;
608
609 double lower([[version objectAtIndex:0] doubleValue]);
610 if (kCFCoreFoundationVersionNumber < lower)
611 continue;
612
613 if (count != 1) {
614 double upper([[version objectAtIndex:1] doubleValue]);
615 if (upper <= kCFCoreFoundationVersionNumber)
616 continue;
617 }
618 }
619 [specifiers addObject:specifier];
620 }
621 _specifiers = [specifiers retain];
622 }
623 return _specifiers;
624 }
625
626 - (void) settingsChanged {
627 if (![[PSViewController class] instancesRespondToSelector:@selector(showLeftButton:withStyle:rightButton:withStyle:)]) {
628 UIBarButtonItem *respringButton([[UIBarButtonItem alloc] initWithTitle:@"Respring" style:UIBarButtonItemStyleDone target:self action:@selector(settingsConfirmButtonClicked:)]);
629 UIBarButtonItem *cancelButton([[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(settingsConfirmButtonClicked:)]);
630 cancelButton.tag = 0;
631 respringButton.tag = 1;
632 [[self navigationItem] setLeftBarButtonItem:respringButton];
633 [[self navigationItem] setRightBarButtonItem:cancelButton];
634 [respringButton release];
635 [cancelButton release];
636 } else {
637 [self showLeftButton:@"Respring" withStyle:2 rightButton:@"Cancel" withStyle:0];
638 }
639 settingsChanged = YES;
640 }
641
642 - (NSString *) title {
643 return @"WinterBoard";
644 }
645
646 - (void) setPreferenceValue:(id)value specifier:(PSSpecifier *)spec {
647 NSString *key([spec propertyForKey:@"key"]);
648 if ([[spec propertyForKey:@"negate"] boolValue])
649 value = [NSNumber numberWithBool:(![value boolValue])];
650 [_settings setValue:value forKey:key];
651 [self settingsChanged];
652 }
653
654 - (id) readPreferenceValue:(PSSpecifier *)spec {
655 NSString *key([spec propertyForKey:@"key"]);
656 id defaultValue([spec propertyForKey:@"default"]);
657 id plistValue([_settings objectForKey:key]);
658 if (!plistValue)
659 return defaultValue;
660 if ([[spec propertyForKey:@"negate"] boolValue])
661 plistValue = [NSNumber numberWithBool:(![plistValue boolValue])];
662 return plistValue;
663 }
664
665 @end
666
667 #define WBSAddMethod(_class, _sel, _imp, _type) \
668 if (![[_class class] instancesRespondToSelector:@selector(_sel)]) \
669 class_addMethod([_class class], @selector(_sel), (IMP)_imp, _type)
670 void $PSRootController$popController(PSRootController *self, SEL _cmd) {
671 [self popViewControllerAnimated:YES];
672 }
673
674 void $PSViewController$hideNavigationBarButtons(PSRootController *self, SEL _cmd) {
675 }
676
677 id $PSViewController$initForContentSize$(PSRootController *self, SEL _cmd, CGRect contentSize) {
678 return [self init];
679 }
680
681 static __attribute__((constructor)) void __wbsInit() {
682 WBSAddMethod(PSRootController, popController, $PSRootController$popController, "v@:");
683 WBSAddMethod(PSViewController, hideNavigationBarButtons, $PSViewController$hideNavigationBarButtons, "v@:");
684 WBSAddMethod(PSViewController, initForContentSize:, $PSViewController$initForContentSize$, "@@:{ff}");
685 }