]>
Commit | Line | Data |
---|---|---|
224d48e3 | 1 | /* WinterBoard - Theme Manager for the iPhone |
43fd3a0b | 2 | * Copyright (C) 2009-2010 Jay Freeman (saurik) |
224d48e3 JF |
3 | */ |
4 | ||
5 | /* | |
6 | * Redistribution and use in source and binary | |
7 | * forms, with or without modification, are permitted | |
8 | * provided that the following conditions are met: | |
9 | * | |
10 | * 1. Redistributions of source code must retain the | |
11 | * above copyright notice, this list of conditions | |
12 | * and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the | |
14 | * above copyright notice, this list of conditions | |
15 | * and the following disclaimer in the documentation | |
16 | * and/or other materials provided with the | |
17 | * distribution. | |
18 | * 3. The name of the author may not be used to endorse | |
19 | * or promote products derived from this software | |
20 | * without specific prior written permission. | |
21 | * | |
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' | |
23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | |
24 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE | |
27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
33 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
35 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
36 | */ | |
37 | ||
38 | #import <Foundation/Foundation.h> | |
39 | #import <UIKit/UIKit.h> | |
b39b993d DH |
40 | #import <Preferences/PSRootController.h> |
41 | #import <Preferences/PSViewController.h> | |
224d48e3 JF |
42 | #import <Preferences/PSListController.h> |
43 | #import <Preferences/PSSpecifier.h> | |
44 | #import <Preferences/PSTableCell.h> | |
45 | #import <UIKit/UINavigationButton.h> | |
46 | ||
7c88a3f1 | 47 | #include <dlfcn.h> |
b39b993d | 48 | #include <objc/runtime.h> |
7c88a3f1 JF |
49 | |
50 | static BOOL (*IsIconHiddenDisplayId)(NSString *); | |
51 | static BOOL (*HideIconViaDisplayId)(NSString *); | |
52 | static BOOL (*UnHideIconViaDisplayId)(NSString *); | |
53 | ||
54 | static const NSString *WinterBoardDisplayID = @"com.saurik.WinterBoard"; | |
55 | ||
224d48e3 JF |
56 | extern NSString *PSTableCellKey; |
57 | extern "C" UIImage *_UIImageWithName(NSString *); | |
58 | ||
59 | static UIImage *checkImage; | |
60 | static UIImage *uncheckedImage; | |
61 | ||
62 | static BOOL settingsChanged; | |
63 | static NSMutableDictionary *_settings; | |
64 | static NSString *_plist; | |
65 | ||
265e19b2 JF |
66 | /* [NSObject yieldToSelector:(withObject:)] {{{*/ |
67 | @interface NSObject (wb$yieldToSelector) | |
68 | - (id) wb$yieldToSelector:(SEL)selector withObject:(id)object; | |
69 | - (id) wb$yieldToSelector:(SEL)selector; | |
70 | @end | |
71 | ||
72 | @implementation NSObject (Cydia) | |
73 | ||
74 | - (void) wb$doNothing { | |
75 | } | |
76 | ||
77 | - (void) wb$_yieldToContext:(NSMutableArray *)context { | |
78 | NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); | |
79 | ||
80 | SEL selector(reinterpret_cast<SEL>([[context objectAtIndex:0] pointerValue])); | |
81 | id object([[context objectAtIndex:1] nonretainedObjectValue]); | |
82 | volatile bool &stopped(*reinterpret_cast<bool *>([[context objectAtIndex:2] pointerValue])); | |
83 | ||
84 | /* XXX: deal with exceptions */ | |
85 | id value([self performSelector:selector withObject:object]); | |
86 | ||
87 | NSMethodSignature *signature([self methodSignatureForSelector:selector]); | |
88 | [context removeAllObjects]; | |
89 | if ([signature methodReturnLength] != 0 && value != nil) | |
90 | [context addObject:value]; | |
91 | ||
92 | stopped = true; | |
93 | ||
94 | [self | |
95 | performSelectorOnMainThread:@selector(wb$doNothing) | |
96 | withObject:nil | |
97 | waitUntilDone:NO | |
98 | ]; | |
99 | ||
100 | [pool release]; | |
101 | } | |
102 | ||
103 | - (id) wb$yieldToSelector:(SEL)selector withObject:(id)object { | |
104 | /*return [self performSelector:selector withObject:object];*/ | |
105 | ||
106 | volatile bool stopped(false); | |
107 | ||
108 | NSMutableArray *context([NSMutableArray arrayWithObjects: | |
109 | [NSValue valueWithPointer:selector], | |
110 | [NSValue valueWithNonretainedObject:object], | |
111 | [NSValue valueWithPointer:const_cast<bool *>(&stopped)], | |
112 | nil]); | |
113 | ||
114 | NSThread *thread([[[NSThread alloc] | |
115 | initWithTarget:self | |
116 | selector:@selector(wb$_yieldToContext:) | |
117 | object:context | |
118 | ] autorelease]); | |
119 | ||
120 | [thread start]; | |
121 | ||
122 | NSRunLoop *loop([NSRunLoop currentRunLoop]); | |
123 | NSDate *future([NSDate distantFuture]); | |
124 | ||
125 | while (!stopped && [loop runMode:NSDefaultRunLoopMode beforeDate:future]); | |
126 | ||
127 | return [context count] == 0 ? nil : [context objectAtIndex:0]; | |
128 | } | |
129 | ||
130 | - (id) wb$yieldToSelector:(SEL)selector { | |
131 | return [self wb$yieldToSelector:selector withObject:nil]; | |
132 | } | |
133 | ||
134 | @end | |
135 | /* }}} */ | |
136 | ||
224d48e3 JF |
137 | /* Theme Settings Controller {{{ */ |
138 | @interface WBSThemesController: PSViewController <UITableViewDelegate, UITableViewDataSource> { | |
139 | UITableView *_tableView; | |
140 | NSMutableArray *_themes; | |
141 | } | |
142 | ||
143 | @property (nonatomic, retain) NSMutableArray *themes; | |
144 | ||
145 | + (void) load; | |
146 | ||
147 | - (id) initForContentSize:(CGSize)size; | |
148 | - (id) view; | |
149 | - (id) navigationTitle; | |
150 | - (void) themesChanged; | |
151 | ||
152 | - (int) numberOfSectionsInTableView:(UITableView *)tableView; | |
153 | - (id) tableView:(UITableView *)tableView titleForHeaderInSection:(int)section; | |
154 | - (int) tableView:(UITableView *)tableView numberOfRowsInSection:(int)section; | |
155 | - (id) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; | |
156 | - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; | |
157 | - (void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath; | |
158 | - (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath; | |
159 | - (BOOL) tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath; | |
160 | - (BOOL) tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath; | |
7c88a3f1 | 161 | |
224d48e3 JF |
162 | @end |
163 | ||
164 | @implementation WBSThemesController | |
165 | ||
166 | @synthesize themes = _themes; | |
167 | ||
168 | + (void) load { | |
169 | NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); | |
170 | checkImage = [_UIImageWithName(@"UIPreferencesBlueCheck.png") retain]; | |
171 | uncheckedImage = [[UIImage imageWithContentsOfFile:@"/System/Library/PreferenceBundles/WinterBoardSettings.bundle/SearchResultsCheckmarkClear.png"] retain]; | |
172 | [pool release]; | |
173 | } | |
174 | ||
175 | - (id) initForContentSize:(CGSize)size { | |
176 | if ((self = [super initForContentSize:size]) != nil) { | |
177 | self.themes = [_settings objectForKey:@"Themes"]; | |
178 | if (!_themes) { | |
179 | if (NSString *theme = [_settings objectForKey:@"Theme"]) { | |
180 | self.themes = [NSMutableArray arrayWithObject: | |
181 | [NSMutableDictionary dictionaryWithObjectsAndKeys: | |
182 | theme, @"Name", | |
183 | [NSNumber numberWithBool:YES], @"Active", nil]]; | |
184 | [_settings removeObjectForKey:@"Theme"]; | |
185 | } | |
186 | if (!_themes) | |
187 | self.themes = [NSMutableArray array]; | |
188 | [_settings setObject:_themes forKey:@"Themes"]; | |
189 | } | |
190 | ||
191 | NSMutableArray *themesOnDisk([NSMutableArray array]); | |
192 | ||
193 | [themesOnDisk | |
194 | addObjectsFromArray:[[NSFileManager defaultManager] | |
195 | contentsOfDirectoryAtPath:@"/Library/Themes" error:NULL] | |
196 | ]; | |
197 | ||
198 | [themesOnDisk addObjectsFromArray:[[NSFileManager defaultManager] | |
199 | contentsOfDirectoryAtPath:[NSString stringWithFormat:@"%@/Library/SummerBoard/Themes", NSHomeDirectory()] | |
200 | error:NULL | |
201 | ]]; | |
202 | ||
203 | for (int i = 0, count = [themesOnDisk count]; i < count; i++) { | |
204 | NSString *theme = [themesOnDisk objectAtIndex:i]; | |
205 | if ([theme hasSuffix:@".theme"]) | |
206 | [themesOnDisk replaceObjectAtIndex:i withObject:[theme stringByDeletingPathExtension]]; | |
207 | } | |
208 | ||
209 | NSMutableSet *themesSet([NSMutableSet set]); | |
210 | ||
211 | for (int i = 0, count = [_themes count]; i < count; i++) { | |
212 | NSDictionary *theme([_themes objectAtIndex:i]); | |
213 | NSString *name([theme objectForKey:@"Name"]); | |
214 | ||
215 | if (!name || ![themesOnDisk containsObject:name]) { | |
216 | [_themes removeObjectAtIndex:i]; | |
217 | i--; | |
218 | count--; | |
219 | } else { | |
220 | [themesSet addObject:name]; | |
221 | } | |
222 | } | |
223 | ||
224 | for (NSString *theme in themesOnDisk) { | |
225 | if ([themesSet containsObject:theme]) | |
226 | continue; | |
227 | [themesSet addObject:theme]; | |
228 | ||
229 | [_themes insertObject:[NSMutableDictionary dictionaryWithObjectsAndKeys: | |
230 | theme, @"Name", | |
231 | [NSNumber numberWithBool:NO], @"Active", | |
232 | nil] atIndex:0]; | |
233 | } | |
234 | ||
235 | _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-64) style:UITableViewStyleGrouped]; | |
236 | [_tableView setDataSource:self]; | |
237 | [_tableView setDelegate:self]; | |
238 | [_tableView setEditing:YES]; | |
239 | [_tableView setAllowsSelectionDuringEditing:YES]; | |
b39b993d DH |
240 | if ([self respondsToSelector:@selector(setView:)]) |
241 | [self setView:_tableView]; | |
224d48e3 JF |
242 | } |
243 | return self; | |
244 | } | |
245 | ||
246 | - (void) dealloc { | |
247 | [_tableView release]; | |
248 | [_themes release]; | |
249 | [super dealloc]; | |
250 | } | |
251 | ||
252 | - (id) navigationTitle { | |
253 | return @"Themes"; | |
254 | } | |
255 | ||
256 | - (id) view { | |
257 | return _tableView; | |
258 | } | |
259 | ||
260 | - (void) themesChanged { | |
261 | settingsChanged = YES; | |
262 | } | |
263 | ||
264 | /* UITableViewDelegate / UITableViewDataSource Methods {{{ */ | |
265 | - (int) numberOfSectionsInTableView:(UITableView *)tableView { | |
266 | return 1; | |
267 | } | |
268 | ||
269 | - (id) tableView:(UITableView *)tableView titleForHeaderInSection:(int)section { | |
270 | return nil; | |
271 | } | |
272 | ||
273 | - (int) tableView:(UITableView *)tableView numberOfRowsInSection:(int)section { | |
274 | return _themes.count; | |
275 | } | |
276 | ||
277 | - (id) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
278 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ThemeCell"]; | |
279 | if (!cell) { | |
280 | cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 100, 100) reuseIdentifier:@"ThemeCell"] autorelease]; | |
281 | //[cell setTableViewStyle:UITableViewCellStyleDefault]; | |
282 | } | |
283 | ||
284 | NSDictionary *theme([_themes objectAtIndex:indexPath.row]); | |
285 | cell.text = [theme objectForKey:@"Name"]; | |
286 | cell.hidesAccessoryWhenEditing = NO; | |
287 | NSNumber *active([theme objectForKey:@"Active"]); | |
288 | BOOL inactive(active == nil || ![active boolValue]); | |
289 | [cell setImage:(inactive ? uncheckedImage : checkImage)]; | |
290 | return cell; | |
291 | } | |
292 | ||
293 | - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | |
294 | UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; | |
295 | NSMutableDictionary *theme = [_themes objectAtIndex:indexPath.row]; | |
296 | NSNumber *active = [theme objectForKey:@"Active"]; | |
297 | BOOL inactive = active == nil || ![active boolValue]; | |
298 | [theme setObject:[NSNumber numberWithBool:inactive] forKey:@"Active"]; | |
299 | [cell setImage:(!inactive ? uncheckedImage : checkImage)]; | |
300 | [tableView deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:YES]; | |
301 | [self themesChanged]; | |
302 | } | |
303 | ||
304 | - (void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { | |
305 | NSUInteger fromIndex = [fromIndexPath row]; | |
306 | NSUInteger toIndex = [toIndexPath row]; | |
307 | if (fromIndex == toIndex) | |
308 | return; | |
309 | NSMutableDictionary *theme = [[[_themes objectAtIndex:fromIndex] retain] autorelease]; | |
310 | [_themes removeObjectAtIndex:fromIndex]; | |
311 | [_themes insertObject:theme atIndex:toIndex]; | |
312 | [self themesChanged]; | |
313 | } | |
314 | ||
315 | - (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { | |
316 | return UITableViewCellEditingStyleNone; | |
317 | } | |
318 | ||
319 | - (BOOL) tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath { | |
320 | return NO; | |
321 | } | |
322 | ||
323 | - (BOOL) tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { | |
324 | return YES; | |
325 | } | |
326 | /* }}} */ | |
327 | @end | |
328 | /* }}} */ | |
329 | ||
024f98ea | 330 | @interface WBAdvancedController: PSListController { |
224d48e3 JF |
331 | } |
332 | ||
224d48e3 JF |
333 | - (id) specifiers; |
334 | - (void) settingsChanged; | |
224d48e3 JF |
335 | |
336 | @end | |
337 | ||
024f98ea | 338 | @implementation WBAdvancedController |
224d48e3 | 339 | |
024f98ea JF |
340 | - (id) specifiers { |
341 | if (!_specifiers) | |
342 | _specifiers = [[self loadSpecifiersFromPlistName:@"Advanced" target:self] retain]; | |
343 | return _specifiers; | |
7c88a3f1 JF |
344 | } |
345 | ||
024f98ea JF |
346 | - (void) settingsChanged { |
347 | settingsChanged = YES; | |
348 | } | |
7c88a3f1 | 349 | |
024f98ea JF |
350 | - (void) setPreferenceValue:(id)value specifier:(PSSpecifier *)spec { |
351 | NSString *key([spec propertyForKey:@"key"]); | |
352 | if ([[spec propertyForKey:@"negate"] boolValue]) | |
353 | value = [NSNumber numberWithBool:(![value boolValue])]; | |
354 | [_settings setValue:value forKey:key]; | |
355 | [self settingsChanged]; | |
224d48e3 JF |
356 | } |
357 | ||
024f98ea JF |
358 | - (id) readPreferenceValue:(PSSpecifier *)spec { |
359 | NSString *key([spec propertyForKey:@"key"]); | |
360 | id defaultValue([spec propertyForKey:@"default"]); | |
361 | id plistValue([_settings objectForKey:key]); | |
362 | if (!plistValue) | |
363 | return defaultValue; | |
364 | if ([[spec propertyForKey:@"negate"] boolValue]) | |
365 | plistValue = [NSNumber numberWithBool:(![plistValue boolValue])]; | |
366 | return plistValue; | |
224d48e3 JF |
367 | } |
368 | ||
43fd3a0b | 369 | - (void) __optimizeThemes { |
265e19b2 JF |
370 | system("/usr/libexec/winterboard/Optimize"); |
371 | } | |
372 | ||
373 | - (void) optimizeThemes { | |
54a4cf27 | 374 | UIAlertView *alert([[[UIAlertView alloc] |
43fd3a0b | 375 | initWithTitle:@"Optimize Themes" |
54a4cf27 | 376 | 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." |
43fd3a0b | 377 | delegate:self |
54a4cf27 JF |
378 | cancelButtonTitle:@"Cancel" |
379 | otherButtonTitles:@"Optimize", nil | |
43fd3a0b JF |
380 | ] autorelease]); |
381 | ||
54a4cf27 JF |
382 | [alert setContext:@"optimize"]; |
383 | [alert setNumberOfRows:1]; | |
384 | [alert show]; | |
43fd3a0b JF |
385 | } |
386 | ||
387 | - (void) _optimizeThemes { | |
265e19b2 JF |
388 | UIView *view([self view]); |
389 | UIWindow *window([view window]); | |
390 | ||
391 | UIProgressHUD *hud([[[UIProgressHUD alloc] initWithWindow:window] autorelease]); | |
392 | [hud setText:@"Reticulating Splines\nPlease Wait (Minutes)"]; | |
393 | ||
394 | [window setUserInteractionEnabled:NO]; | |
395 | ||
396 | [window addSubview:hud]; | |
397 | [hud show:YES]; | |
43fd3a0b | 398 | [self wb$yieldToSelector:@selector(__optimizeThemes)]; |
265e19b2 JF |
399 | [hud removeFromSuperview]; |
400 | ||
401 | [window setUserInteractionEnabled:YES]; | |
402 | ||
403 | [self settingsChanged]; | |
404 | } | |
405 | ||
54a4cf27 JF |
406 | - (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button { |
407 | NSString *context([alert context]); | |
43fd3a0b JF |
408 | |
409 | if ([context isEqualToString:@"optimize"]) { | |
54a4cf27 JF |
410 | if (button == [alert firstOtherButtonIndex]) { |
411 | [self performSelector:@selector(_optimizeThemes) withObject:nil afterDelay:0]; | |
43fd3a0b JF |
412 | } |
413 | ||
54a4cf27 JF |
414 | [alert dismissWithClickedButtonIndex:-1 animated:YES]; |
415 | } | |
416 | /*else if ([super respondsToSelector:@selector(alertView:clickedButtonAtIndex:)]) | |
417 | [super alertView:alert clickedButtonAtIndex:button];*/ | |
43fd3a0b JF |
418 | } |
419 | ||
024f98ea JF |
420 | @end |
421 | ||
422 | @interface WBSettingsController: PSListController { | |
423 | } | |
424 | ||
425 | - (id) initForContentSize:(CGSize)size; | |
426 | - (void) dealloc; | |
427 | - (void) suspend; | |
428 | - (void) navigationBarButtonClicked:(int)buttonIndex; | |
429 | - (void) viewWillRedisplay; | |
430 | - (void) pushController:(id)controller; | |
431 | - (id) specifiers; | |
432 | - (void) settingsChanged; | |
433 | - (NSString *) title; | |
434 | - (void) setPreferenceValue:(id)value specifier:(PSSpecifier *)spec; | |
435 | - (id) readPreferenceValue:(PSSpecifier *)spec; | |
436 | ||
437 | @end | |
438 | ||
439 | @implementation WBSettingsController | |
440 | ||
441 | + (void) load { | |
442 | void *libhide(dlopen("/usr/lib/hide.dylib", RTLD_LAZY)); | |
443 | IsIconHiddenDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "IsIconHiddenDisplayId")); | |
444 | HideIconViaDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "HideIconViaDisplayId")); | |
445 | UnHideIconViaDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "UnHideIconViaDisplayId")); | |
446 | } | |
447 | ||
448 | - (id) initForContentSize:(CGSize)size { | |
449 | if ((self = [super initForContentSize:size]) != nil) { | |
450 | _plist = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()] retain]; | |
451 | _settings = [([NSMutableDictionary dictionaryWithContentsOfFile:_plist] ?: [NSMutableDictionary dictionary]) retain]; | |
452 | ||
453 | [_settings setObject:[NSNumber numberWithBool:IsIconHiddenDisplayId(WinterBoardDisplayID)] forKey:@"IconHidden"]; | |
454 | } return self; | |
455 | } | |
456 | ||
457 | - (void) dealloc { | |
458 | [_settings release]; | |
459 | [_plist release]; | |
460 | [super dealloc]; | |
461 | } | |
462 | ||
224d48e3 JF |
463 | - (void) suspend { |
464 | if (!settingsChanged) | |
465 | return; | |
466 | ||
467 | NSData *data([NSPropertyListSerialization dataFromPropertyList:_settings format:NSPropertyListBinaryFormat_v1_0 errorDescription:NULL]); | |
468 | if (!data) | |
469 | return; | |
470 | if (![data writeToFile:_plist options:NSAtomicWrite error:NULL]) | |
471 | return; | |
472 | ||
7c88a3f1 JF |
473 | ([[_settings objectForKey:@"IconHidden"] boolValue] ? HideIconViaDisplayId : UnHideIconViaDisplayId)(WinterBoardDisplayID); |
474 | ||
224d48e3 JF |
475 | unlink("/User/Library/Caches/com.apple.springboard-imagecache-icons"); |
476 | unlink("/User/Library/Caches/com.apple.springboard-imagecache-icons.plist"); | |
477 | unlink("/User/Library/Caches/com.apple.springboard-imagecache-smallicons"); | |
478 | unlink("/User/Library/Caches/com.apple.springboard-imagecache-smallicons.plist"); | |
bbea033b | 479 | |
546a205b JF |
480 | unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen"); |
481 | unlink("/User/Library/Caches/com.apple.SpringBoard.notificationCenterLinen"); | |
bbea033b | 482 | |
546a205b JF |
483 | unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.0"); |
484 | unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.1"); | |
485 | unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.2"); | |
486 | unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.3"); | |
7c88a3f1 JF |
487 | |
488 | system("rm -rf /User/Library/Caches/SpringBoardIconCache"); | |
489 | system("rm -rf /User/Library/Caches/SpringBoardIconCache-small"); | |
f64efe8d | 490 | system("rm -rf /User/Library/Caches/com.apple.IconsCache"); |
546a205b | 491 | system("rm -rf /User/Library/Caches/com.apple.newsstand"); |
bbea033b | 492 | system("rm -rf /User/Library/Caches/com.apple.springboard.sharedimagecache"); |
7c88a3f1 | 493 | |
f64efe8d | 494 | system("killall lsd SpringBoard"); |
224d48e3 JF |
495 | } |
496 | ||
b39b993d DH |
497 | - (void) cancelChanges { |
498 | [_settings release]; | |
499 | [_plist release]; | |
500 | _plist = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()] retain]; | |
501 | _settings = [([NSMutableDictionary dictionaryWithContentsOfFile:_plist] ?: [NSMutableDictionary dictionary]) retain]; | |
502 | ||
503 | [_settings setObject:[NSNumber numberWithBool:IsIconHiddenDisplayId(WinterBoardDisplayID)] forKey:@"IconHidden"]; | |
504 | [self reloadSpecifiers]; | |
505 | if (![[PSViewController class] instancesRespondToSelector:@selector(showLeftButton:withStyle:rightButton:withStyle:)]) { | |
1d3b613f JF |
506 | [[self navigationItem] setLeftBarButtonItem:nil]; |
507 | [[self navigationItem] setRightBarButtonItem:nil]; | |
838dbf4c DH |
508 | } else { |
509 | [self showLeftButton:nil withStyle:0 rightButton:nil withStyle:0]; | |
b39b993d DH |
510 | } |
511 | settingsChanged = NO; | |
512 | } | |
513 | ||
224d48e3 JF |
514 | - (void) navigationBarButtonClicked:(int)buttonIndex { |
515 | if (!settingsChanged) { | |
516 | [super navigationBarButtonClicked:buttonIndex]; | |
517 | return; | |
518 | } | |
519 | ||
838dbf4c | 520 | if (buttonIndex == 0) { |
b39b993d | 521 | [self cancelChanges]; |
838dbf4c DH |
522 | return; |
523 | } | |
224d48e3 JF |
524 | |
525 | [self suspend]; | |
526 | [self.rootController popController]; | |
527 | } | |
528 | ||
b39b993d DH |
529 | - (void) settingsConfirmButtonClicked:(UIBarButtonItem *)button { |
530 | [self navigationBarButtonClicked:button.tag]; | |
531 | } | |
532 | ||
224d48e3 JF |
533 | - (void) viewWillRedisplay { |
534 | if (settingsChanged) | |
535 | [self settingsChanged]; | |
536 | [super viewWillRedisplay]; | |
537 | } | |
538 | ||
b39b993d DH |
539 | - (void) viewWillAppear:(BOOL)animated { |
540 | if (settingsChanged) | |
541 | [self settingsChanged]; | |
1d3b613f JF |
542 | if ([super respondsToSelector:@selector(viewWillAppear:)]) |
543 | [super viewWillAppear:animated]; | |
b39b993d DH |
544 | } |
545 | ||
224d48e3 JF |
546 | - (void) pushController:(id)controller { |
547 | [self hideNavigationBarButtons]; | |
548 | [super pushController:controller]; | |
549 | } | |
550 | ||
551 | - (id) specifiers { | |
552 | if (!_specifiers) | |
553 | _specifiers = [[self loadSpecifiersFromPlistName:@"WinterBoard" target:self] retain]; | |
554 | return _specifiers; | |
555 | } | |
556 | ||
557 | - (void) settingsChanged { | |
b39b993d DH |
558 | if (![[PSViewController class] instancesRespondToSelector:@selector(showLeftButton:withStyle:rightButton:withStyle:)]) { |
559 | UIBarButtonItem *respringButton([[UIBarButtonItem alloc] initWithTitle:@"Respring" style:UIBarButtonItemStyleDone target:self action:@selector(settingsConfirmButtonClicked:)]); | |
560 | UIBarButtonItem *cancelButton([[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(settingsConfirmButtonClicked:)]); | |
561 | cancelButton.tag = 0; | |
562 | respringButton.tag = 1; | |
1d3b613f JF |
563 | [[self navigationItem] setLeftBarButtonItem:respringButton]; |
564 | [[self navigationItem] setRightBarButtonItem:cancelButton]; | |
b39b993d DH |
565 | [respringButton release]; |
566 | [cancelButton release]; | |
567 | } else { | |
568 | [self showLeftButton:@"Respring" withStyle:2 rightButton:@"Cancel" withStyle:0]; | |
569 | } | |
224d48e3 JF |
570 | settingsChanged = YES; |
571 | } | |
572 | ||
573 | - (NSString *) title { | |
574 | return @"WinterBoard"; | |
575 | } | |
576 | ||
577 | - (void) setPreferenceValue:(id)value specifier:(PSSpecifier *)spec { | |
7c88a3f1 | 578 | NSString *key([spec propertyForKey:@"key"]); |
224d48e3 JF |
579 | if ([[spec propertyForKey:@"negate"] boolValue]) |
580 | value = [NSNumber numberWithBool:(![value boolValue])]; | |
7c88a3f1 | 581 | [_settings setValue:value forKey:key]; |
224d48e3 JF |
582 | [self settingsChanged]; |
583 | } | |
584 | ||
585 | - (id) readPreferenceValue:(PSSpecifier *)spec { | |
586 | NSString *key([spec propertyForKey:@"key"]); | |
587 | id defaultValue([spec propertyForKey:@"default"]); | |
588 | id plistValue([_settings objectForKey:key]); | |
589 | if (!plistValue) | |
590 | return defaultValue; | |
591 | if ([[spec propertyForKey:@"negate"] boolValue]) | |
592 | plistValue = [NSNumber numberWithBool:(![plistValue boolValue])]; | |
593 | return plistValue; | |
594 | } | |
595 | ||
596 | @end | |
b39b993d DH |
597 | |
598 | #define WBSAddMethod(_class, _sel, _imp, _type) \ | |
599 | if (![[_class class] instancesRespondToSelector:@selector(_sel)]) \ | |
600 | class_addMethod([_class class], @selector(_sel), (IMP)_imp, _type) | |
601 | void $PSRootController$popController(PSRootController *self, SEL _cmd) { | |
602 | [self popViewControllerAnimated:YES]; | |
603 | } | |
604 | ||
605 | void $PSViewController$hideNavigationBarButtons(PSRootController *self, SEL _cmd) { | |
606 | } | |
607 | ||
608 | id $PSViewController$initForContentSize$(PSRootController *self, SEL _cmd, CGRect contentSize) { | |
609 | return [self init]; | |
610 | } | |
611 | ||
612 | static __attribute__((constructor)) void __wbsInit() { | |
613 | WBSAddMethod(PSRootController, popController, $PSRootController$popController, "v@:"); | |
614 | WBSAddMethod(PSViewController, hideNavigationBarButtons, $PSViewController$hideNavigationBarButtons, "v@:"); | |
615 | WBSAddMethod(PSViewController, initForContentSize:, $PSViewController$initForContentSize$, "@@:{ff}"); | |
616 | } |