1 /* WinterBoard - Theme Manager for the iPhone
2 * Copyright (C) 2008 Jay Freeman (saurik)
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
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
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.
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.
38 #define _trace() NSLog(@"WB:_trace(%u)", __LINE__);
41 #include <substrate.h>
43 #import <CoreFoundation/CoreFoundation.h>
44 #import <Foundation/Foundation.h>
45 #import <CoreGraphics/CoreGraphics.h>
47 #import <UIKit/UIColor.h>
48 #import <UIKit/UIFont.h>
49 #import <UIKit/UIImage.h>
50 #import <UIKit/UIImageView.h>
51 #import <UIKit/UINavigationBar.h>
52 #import <UIKit/UINavigationBarBackground.h>
53 #import <UIKit/UIToolbar.h>
54 #import <UIKit/UIWebDocumentView.h>
56 #import <UIKit/NSString-UIStringDrawing.h>
57 #import <UIKit/NSString-UIStringDrawingDeprecated.h>
59 #import <UIKit/UIImage-UIImageDeprecated.h>
61 #import <UIKit/UIView-Geometry.h>
62 #import <UIKit/UIView-Hierarchy.h>
63 #import <UIKit/UIView-Rendering.h>
65 #import <SpringBoard/SBApplication.h>
66 #import <SpringBoard/SBApplicationIcon.h>
67 #import <SpringBoard/SBAppWindow.h>
68 #import <SpringBoard/SBBookmarkIcon.h>
69 #import <SpringBoard/SBButtonBar.h>
70 #import <SpringBoard/SBCalendarIconContentsView.h>
71 #import <SpringBoard/SBContentLayer.h>
72 #import <SpringBoard/SBIconController.h>
73 #import <SpringBoard/SBIconLabel.h>
74 #import <SpringBoard/SBSlidingAlertDisplay.h>
75 #import <SpringBoard/SBStatusBarContentsView.h>
76 #import <SpringBoard/SBStatusBarController.h>
77 #import <SpringBoard/SBStatusBarTimeView.h>
78 #import <SpringBoard/SBUIController.h>
80 #import <MediaPlayer/MPVideoView.h>
81 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
83 #import <CoreGraphics/CGGeometry.h>
85 extern "C" void __clear_cache (char *beg, char *end);
92 Class $UIWebDocumentView;
94 @interface NSDictionary (WinterBoard)
95 - (UIColor *) colorForKey:(NSString *)key;
96 - (BOOL) boolForKey:(NSString *)key;
99 @implementation NSDictionary (WinterBoard)
101 - (UIColor *) colorForKey:(NSString *)key {
102 NSString *value = [self objectForKey:key];
109 - (BOOL) boolForKey:(NSString *)key {
110 if (NSString *value = [self objectForKey:key])
111 return [value boolValue];
118 bool Engineer_ = false;
120 /* WinterBoard Backend {{{ */
121 void WBInject(const char *classname, const char *oldname, IMP newimp, const char *type) {
122 Class _class = objc_getClass(classname);
125 if (!class_addMethod(_class, sel_registerName(oldname), newimp, type))
126 NSLog(@"WB:Error: failed to inject [%s %s]", classname, oldname);
131 @protocol WinterBoard
132 - (NSString *) wb_localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)table;
133 - (id) wb_initWithBadge:(id)badge;
134 - (void) wb_cacheImageForIcon:(SBIcon *)icon;
135 - (UIImage *) wb_getCachedImagedForIcon:(SBIcon *)icon;
136 - (CGSize) wb_renderedSizeOfNode:(id)node constrainedToWidth:(float)width;
138 - (void) wb_updateDesktopImage:(UIImage *)image;
139 - (UIImage *) wb_defaultDesktopImage;
140 - (NSString *) wb_bundlePath;
141 - (NSString *) wb_pathForIcon;
142 - (NSString *) wb_pathForResource:(NSString *)resource ofType:(NSString *)type;
145 - (id) wb_initWithSize:(CGSize)size;
146 - (id) wb_initWithSize:(CGSize)size label:(NSString *)label;
147 - (id) wb_initWithFrame:(CGRect)frame;
148 - (id) wb_initWithCoder:(NSCoder *)coder;
149 - (void) wb_setFrame:(CGRect)frame;
150 - (void) wb_drawRect:(CGRect)rect;
151 - (void) wb_setBackgroundColor:(id)color;
152 - (void) wb_setAlpha:(float)value;
153 - (void) wb_setBarStyle:(int)style;
154 - (id) wb_initWithFrame:(CGRect)frame withBarStyle:(int)style withTintColor:(UIColor *)color;
155 - (void) wb_setOpaque:(BOOL)opaque;
156 - (void) wb_setInDock:(BOOL)docked;
157 - (void) wb_didMoveToSuperview;
158 + (UIImage *) wb_imageNamed:(NSString *)name inBundle:(NSBundle *)bundle;
159 + (UIImage *) wb_applicationImageNamed:(NSString *)name;
160 - (NSDictionary *) wb_infoDictionary;
161 - (UIImage *) wb_icon;
162 - (void) wb_appendIconList:(SBIconList *)list;
163 - (id) wb_initWithStatusBar:(id)bar mode:(int)mode;
164 - (id) wb_initWithMode:(int)mode orientation:(int)orientation;
165 - (id) wb_imageAtPath:(NSString *)path;
166 - (id) wb_initWithContentsOfFile:(NSString *)file;
167 - (id) wb_initWithContentsOfFile:(NSString *)file cache:(BOOL)cache;
168 - (void) wb_setStatusBarMode:(int)mode orientation:(int)orientation duration:(float)duration fenceID:(int)id animation:(int)animation;
171 static NSMutableDictionary **__mappedImages;
172 static NSMutableDictionary *UIImages_;
173 static NSMutableDictionary *PathImages_;
175 static NSFileManager *Manager_;
176 static NSDictionary *English_;
177 static NSMutableDictionary *Info_;
178 static NSMutableArray *themes_;
180 static NSString *$getTheme$(NSArray *files) {
181 for (NSString *theme in themes_)
182 for (NSString *file in files) {
183 NSString *path([NSString stringWithFormat:@"%@/%@", theme, file]);
184 if ([Manager_ fileExistsAtPath:path])
191 static NSString *$pathForIcon$(SBApplication<WinterBoard> *self) {
192 for (NSString *theme in themes_) {
193 NSString *identifier = [self bundleIdentifier];
194 NSString *folder = [[self path] lastPathComponent];
195 NSString *dname = [self displayName];
196 NSString *didentifier = [self displayIdentifier];
199 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
201 #define testForIcon(Name) \
202 if (NSString *name = Name) { \
203 NSString *path = [NSString stringWithFormat:@"%@/Icons/%@.png", theme, name]; \
204 if ([Manager_ fileExistsAtPath:path]) \
208 if (identifier != nil) {
209 NSString *path = [NSString stringWithFormat:@"%@/Bundles/%@/icon.png", theme, identifier];
210 if ([Manager_ fileExistsAtPath:path])
215 NSString *path = [NSString stringWithFormat:@"%@/Folders/%@/icon.png", theme, folder];
216 if ([Manager_ fileExistsAtPath:path])
220 testForIcon(identifier);
223 if (didentifier != nil) {
224 testForIcon([English_ objectForKey:didentifier]);
226 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
227 if ([parts count] != 1)
228 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[[self path] stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
229 testForIcon([english objectForKey:[parts lastObject]]);
236 static NSMutableDictionary *Cache_;
238 static void SBIconModel$cacheImageForIcon$(SBIconModel<WinterBoard> *self, SEL sel, SBIcon *icon) {
239 [self wb_cacheImageForIcon:icon];
240 NSString *key([icon displayIdentifier]);
241 if (UIImage *value = [icon icon])
242 [Cache_ setObject:value forKey:key];
245 static UIImage *SBIconModel$getCachedImagedForIcon$(SBIconModel<WinterBoard> *self, SEL sel, SBIcon *icon) {
246 NSString *key([icon displayIdentifier]);
247 if (UIImage *image = [Cache_ objectForKey:key])
250 return [self wb_getCachedImagedForIcon:icon];
253 static UIImage *SBApplicationIcon$icon(SBApplicationIcon<WinterBoard> *self, SEL sel) {
254 if (![Info_ boolForKey:@"ComposeStoreIcons"])
255 if (NSString *path = $pathForIcon$([self application]))
256 return [$UIImage imageWithContentsOfFile:path];
257 return [self wb_icon];
260 static UIImage *SBBookmarkIcon$icon(SBBookmarkIcon<WinterBoard> *self, SEL sel) {
262 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
263 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
264 return [$UIImage imageWithContentsOfFile:path];
265 return [self wb_icon];
268 static NSString *SBApplication$pathForIcon(SBApplication<WinterBoard> *self, SEL sel) {
269 if (NSString *path = $pathForIcon$(self))
271 return [self wb_pathForIcon];
274 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle<WinterBoard> *bundle, bool ui) {
275 for (NSString *theme in themes_) {
276 NSString *identifier = [bundle bundleIdentifier];
278 if (identifier != nil) {
279 NSString *path = [NSString stringWithFormat:@"%@/Bundles/%@/%@", theme, identifier, file];
280 if ([Manager_ fileExistsAtPath:path])
284 if (NSString *folder = [[bundle wb_bundlePath] lastPathComponent]) {
285 NSString *path = [NSString stringWithFormat:@"%@/Folders/%@/%@", theme, folder, file];
286 if ([Manager_ fileExistsAtPath:path])
290 #define remapResourceName(oldname, newname) \
291 else if ([file isEqualToString:oldname]) { \
292 NSString *path = [NSString stringWithFormat:@"%@/%@.png", theme, newname]; \
293 if ([Manager_ fileExistsAtPath:path]) \
297 if (identifier == nil || ![identifier isEqualToString:@"com.apple.springboard"]);
298 remapResourceName(@"FSO_BG.png", @"StatusBar")
299 remapResourceName(@"SBDockBG.png", @"Dock")
300 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
303 NSString *path = [NSString stringWithFormat:@"%@/UIImages/%@", theme, file];
304 if ([Manager_ fileExistsAtPath:path])
312 static UIImage *CachedImageAtPath(NSString *path) {
313 UIImage *image = [PathImages_ objectForKey:path];
315 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
316 image = [[$UIImage alloc] wb_initWithContentsOfFile:path cache:true];
318 image = [image autorelease];
319 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
323 static UIImage *UIImage$imageNamed$inBundle$(Class<WinterBoard> self, SEL sel, NSString *name, NSBundle *bundle) {
324 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
325 UIImage *image = [PathImages_ objectForKey:key];
327 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
329 NSLog(@"WB:Debug: [UIImage(%@) imageNamed:\"%@\"]", [bundle bundleIdentifier], name);
330 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
331 image = CachedImageAtPath(path);
333 image = [self wb_imageNamed:name inBundle:bundle];
334 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
338 static UIImage *UIImage$imageNamed$(Class<WinterBoard> self, SEL sel, NSString *name) {
339 return UIImage$imageNamed$inBundle$(self, sel, name, [NSBundle mainBundle]);
342 static UIImage *UIImage$applicationImageNamed$(Class<WinterBoard> self, SEL sel, NSString *name) {
343 NSBundle *bundle = [NSBundle mainBundle];
345 NSLog(@"WB:Debug: [UIImage(%@) applicationImageNamed:\"%@\"]", [bundle bundleIdentifier], name);
346 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
347 return CachedImageAtPath(path);
348 return [self wb_applicationImageNamed:name];
351 @interface NSString (WinterBoard)
352 - (NSString *) wb_themedPath;
355 @implementation NSString (WinterBoard)
357 - (NSString *) wb_themedPath {
359 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
365 static NSMutableDictionary *Files_;
367 #define WBDelegate(delegate) \
368 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
370 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
371 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
373 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
377 - (void) forwardInvocation:(NSInvocation*)inv { \
378 SEL sel = [inv selector]; \
379 if ([delegate respondsToSelector:sel]) \
380 [inv invokeWithTarget:delegate]; \
382 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
385 /*@interface WBBundlePath : NSProxy {
386 NSBundle<WinterBoard> *bundle_;
390 - (id) initWithBundle:(NSBundle *)bundle path:(NSString *)path;
392 - (NSString *) wb_themedPath;
396 @implementation WBBundlePath
404 - (id) initWithBundle:(NSBundle *)bundle path:(NSString *)path {
405 bundle_ = [bundle retain];
406 path_ = [path retain];
412 - (NSString *) stringByAppendingPathComponent:(NSString *)component {
413 NSLog(@"WB:Debug:app:%@:%@", path_, component);
414 return [[[WBBundlePath alloc] initWithBundle:bundle_ path:[path_ stringByAppendingPathComponent:component]] autorelease];
417 - (NSString *) stringByAppendingPathExtension:(NSString *)extension {
418 return [[[WBBundlePath alloc] initWithBundle:bundle_ path:[path_ stringByAppendingPathExtension:extension]] autorelease];
421 - (const char *) UTF8String {
422 const char *string = [path_ UTF8String];
423 NSLog(@"WB:Debug:UTF=%s", string);
427 - (NSString *) description {
428 return [path_ description];
431 - (NSString *) wb_themedPath {
433 NSString *path = [Files_ objectForKey:path_];
435 NSString *path = [bundle_ wb_bundlePath];
436 if (![path_ hasPrefix:path]) {
437 NSLog(@"WB:Error:![@\"%@\" hasPrefix:@\"%@\"]", path_, path);
440 path = [path_ substringFromIndex:([path length] + 1)];
441 path = $pathForFile$inBundle$(path, bundle_, false);
443 path = reinterpret_cast<NSString *>([NSNull null]);
444 [Files_ setObject:path forKey:path_];
446 NSLog(@"WB:Debug:ThemePath(\"%@\")->\"%@\"", path_, path);
448 if (reinterpret_cast<id>(path) == [NSNull null])
450 NSLog(@"WB:Debug:ThemePath=%@", path);
456 static NSString *NSBundle$bundlePath$(NSBundle<WinterBoard> *self, SEL sel) {
457 //return [[WBBundlePath alloc] initWithBundle:self path:[self wb_bundlePath]];
458 return [self wb_bundlePath];
461 static NSString *NSBundle$pathForResource$ofType$(NSBundle<WinterBoard> *self, SEL sel, NSString *resource, NSString *type) {
462 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
464 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
465 if (NSString *path = $pathForFile$inBundle$(file, self, false))
467 return [self wb_pathForResource:resource ofType:type];
470 static bool $setBarStyle$_(NSString *name, UIView<WinterBoard> *self, int style) {
472 NSLog(@"WB:Debug:%@Style:%d", name, style);
473 NSNumber *number = nil;
475 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
477 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
481 style = [number intValue];
483 NSLog(@"WB:Debug:%@Style=%d", name, style);
484 [self wb_setBarStyle:style];
489 static void SBCalendarIconContentsView$drawRect$(SBCalendarIconContentsView<WinterBoard> *self, SEL sel, CGRect rect) {
490 CFLocaleRef locale(CFLocaleCopyCurrent());
491 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
494 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
496 CFDateFormatterSetFormat(formatter, CFSTR("d"));
497 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
498 CFDateFormatterSetFormat(formatter, CFSTR("EEEE"));
499 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
503 CFRelease(formatter);
505 NSString *datestyle(@""
506 "font-family: Helvetica; "
507 "font-weight: bold; "
513 NSString *daystyle(@""
514 "font-family: Helvetica; "
515 "font-weight: bold; "
518 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
521 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
522 datestyle = [datestyle stringByAppendingString:style];
523 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
524 daystyle = [daystyle stringByAppendingString:style];
526 float width([self bounds].size.width);
527 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:width];
528 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:width];
530 [(NSString *)date drawAtPoint:CGPointMake(
531 (width - datesize.width) / 2, (71 - datesize.height) / 2
532 ) withStyle:datestyle];
534 [(NSString *)day drawAtPoint:CGPointMake(
535 (width - daysize.width) / 2, (16 - daysize.height) / 2
536 ) withStyle:daystyle];
542 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
545 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
546 style = [number intValue];
548 if (UIColor *color = [Info_ colorForKey:@"NavigationBarTint"])
551 return [self wb_initWithFrame:frame withBarStyle:style withTintColor:tint];
554 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
555 self = [self wb_initWithCoder:coder];
558 UINavigationBar$setBarStyle$_(self);
562 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
563 self = [self wb_initWithFrame:frame];
566 UINavigationBar$setBarStyle$_(self);
570 static void UIToolbar$setBarStyle$(UIToolbar<WinterBoard> *self, SEL sel, int style) {
571 if ($setBarStyle$_(@"Toolbar", self, style))
573 return [self wb_setBarStyle:style];
576 static void UINavigationBar$setBarStyle$(UINavigationBar<WinterBoard> *self, SEL sel, int style) {
577 if ($setBarStyle$_(@"NavigationBar", self, style))
579 return [self wb_setBarStyle:style];
582 static void $didMoveToSuperview(SBButtonBar<WinterBoard> *self, SEL sel) {
583 [[self superview] setBackgroundColor:[$UIColor clearColor]];
584 [self wb_didMoveToSuperview];
587 static id UIImage$imageAtPath$(NSObject<WinterBoard> *self, SEL sel, NSString *path) {
588 return [self wb_imageAtPath:[path wb_themedPath]];
591 static id $initWithContentsOfFile$(NSObject<WinterBoard> *self, SEL sel, NSString *file) {
592 return [self wb_initWithContentsOfFile:[file wb_themedPath]];
595 static id UIImage$initWithContentsOfFile$cache$(UIImage<WinterBoard> *self, SEL sel, NSString *file, BOOL cache) {
596 return [self wb_initWithContentsOfFile:[file wb_themedPath] cache:cache];
599 static UIImage *UIImage$defaultDesktopImage$(UIImage<WinterBoard> *self, SEL sel) {
601 NSLog(@"WB:Debug:DefaultDesktopImage");
602 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
603 return [$UIImage imageWithContentsOfFile:path];
604 return [self wb_defaultDesktopImage];
607 static UIImageView *WallpaperImage_;
608 static UIWebDocumentView *WallpaperPage_;
609 static NSURL *WallpaperURL_;
611 static id SBContentLayer$initWithSize$(SBContentLayer<WinterBoard> *self, SEL sel, CGSize size) {
612 self = [self wb_initWithSize:size];
616 if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"])) {
617 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[self bounds]] autorelease];
618 [video setMovieWithPath:path];
619 [video setRepeatMode:1];
620 [video setRepeatGap:0];
621 [self addSubview:video];
622 [video playFromBeginning];;
626 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"Wallpaper.png", @"Wallpaper.jpg", nil])) {
627 image = [[$UIImage alloc] wb_initWithContentsOfFile:path];
629 image = [image autorelease];
632 if (WallpaperImage_ != nil)
633 [WallpaperImage_ release];
634 WallpaperImage_ = [[$UIImageView alloc] initWithImage:image];
635 [self addSubview:WallpaperImage_];
637 if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Wallpaper.html"])) {
638 CGRect bounds = [self bounds];
640 UIWebDocumentView *view([[[$UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
641 [view setAutoresizes:true];
643 if (WallpaperPage_ != nil)
644 [WallpaperPage_ release];
645 WallpaperPage_ = [view retain];
647 if (WallpaperURL_ != nil)
648 [WallpaperURL_ release];
649 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
651 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
653 [[view webView] setDrawsBackground:false];
654 [view setBackgroundColor:[$UIColor clearColor]];
656 [self addSubview:view];
662 static void SBSlidingAlertDisplay$updateDesktopImage$(SBSlidingAlertDisplay<WinterBoard> *self, SEL sel, UIImage *image) {
663 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
667 object_getInstanceVariable(self, "_backgroundView", reinterpret_cast<void **>(&background));
668 if (background != nil)
672 [self wb_updateDesktopImage:image];
675 CGRect bounds = [self bounds];
677 UIWebDocumentView *view([[[$UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
678 [view setAutoresizes:true];
680 if (WallpaperPage_ != nil)
681 [WallpaperPage_ release];
682 WallpaperPage_ = [view retain];
684 if (WallpaperURL_ != nil)
685 [WallpaperURL_ release];
686 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
688 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
690 [[view webView] setDrawsBackground:false];
691 [view setBackgroundColor:[$UIColor clearColor]];
694 object_getInstanceVariable(self, "_backgroundView", reinterpret_cast<void **>(&background));
695 NSLog(@"back:%@", background);
697 [self insertSubview:view aboveSubview:background];
701 static unsigned *__currentContextCount;
702 static void ***__currentContextStack;
704 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
705 extern "C" CGColorRef CGGStateGetFillColor(void *);
706 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
707 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
709 /* WBTimeLabel {{{ */
710 @interface WBTimeLabel : NSProxy {
712 _transient SBStatusBarTimeView *view_;
715 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
719 @implementation WBTimeLabel
726 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
727 time_ = [time retain];
734 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
735 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
737 object_getInstanceVariable(view_, "_mode", reinterpret_cast<void **>(&mode));
739 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
740 "font-family: Helvetica; "
741 "font-weight: bold; "
744 "%@", mode ? @"white" : @"black", custom]];
749 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
754 /* WBBadgeLabel {{{ */
755 @interface WBBadgeLabel : NSProxy {
759 - (id) initWithBadge:(NSString *)badge;
763 @implementation WBBadgeLabel
770 - (id) initWithBadge:(NSString *)badge {
771 badge_ = [badge retain];
777 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
778 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
779 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
780 "font-family: Helvetica; "
781 "font-weight: bold; "
789 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
795 static id SBIconBadge$initWithBadge$(SBIconBadge<WinterBoard> *self, SEL sel, NSString *badge) {
796 if ((self = [self wb_initWithBadge:badge]) != nil) {
798 object_getInstanceVariable(self, "_badge", reinterpret_cast<void **>(&label));
800 if ((label = [[WBBadgeLabel alloc] initWithBadge:[label autorelease]]) != nil)
801 object_setInstanceVariable(self, "_badge", reinterpret_cast<void *>(label));
805 static void SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(SBStatusBarController<WinterBoard> *self, SEL sel, int mode, int orientation, float duration, int id, int animation) {
807 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
808 if (mode < 100) // 104:hidden 105:glowing
809 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
810 mode = [number intValue];
811 return [self wb_setStatusBarMode:mode orientation:orientation duration:duration fenceID:id animation:animation];
814 /*static id SBStatusBar$initWithMode$orientation$(SBStatusBar<WinterBoard> *self, SEL sel, int mode, int orientation) {
815 return [self wb_initWithMode:mode orientation:orientation];
818 static id SBStatusBarContentsView$initWithStatusBar$mode$(SBStatusBarContentsView<WinterBoard> *self, SEL sel, id bar, int mode) {
819 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
820 mode = [number intValue];
821 return [self wb_initWithStatusBar:bar mode:mode];
824 static void SBStatusBarTimeView$drawRect$(SBStatusBarTimeView<WinterBoard> *self, SEL sel, CGRect rect) {
826 object_getInstanceVariable(self, "_time", reinterpret_cast<void **>(&time));
827 if (time != nil && [time class] != [WBTimeLabel class])
828 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[time autorelease] view:self]));
829 return [self wb_drawRect:rect];
832 static void SBIconController$appendIconList$(SBIconController<WinterBoard> *self, SEL sel, SBIconList *list) {
834 NSLog(@"appendIconList:%@", list);
835 return [self wb_appendIconList:list];
838 static id SBIconLabel$initWithSize$label$(SBIconLabel<WinterBoard> *self, SEL sel, CGSize size, NSString *label) {
839 self = [self wb_initWithSize:size label:label];
841 [self setClipsToBounds:NO];
845 static void SBIconLabel$setInDock$(SBIconLabel<WinterBoard> *self, SEL sel, BOOL docked) {
847 object_getInstanceVariable(self, "_label", reinterpret_cast<void **>(&label));
848 if (![Info_ boolForKey:@"UndockedIconLabels"])
850 if (label != nil && [label respondsToSelector:@selector(setInDock:)])
851 [label setInDock:docked];
852 return [self wb_setInDock:docked];
855 static NSMutableDictionary *Strings_;
857 static NSString *NSBundle$localizedStringForKey$value$table$(NSBundle<WinterBoard> *self, SEL sel, NSString *key, NSString *value, NSString *table) {
858 NSString *identifier = [self bundleIdentifier];
859 NSLocale *locale = [NSLocale currentLocale];
860 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
862 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
863 NSString *file = table == nil ? @"Localizable" : table;
864 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
865 NSDictionary *strings;
866 if ((strings = [Strings_ objectForKey:name]) != nil) {
867 if (static_cast<id>(strings) != [NSNull null]) strings:
868 if (NSString *value = [strings objectForKey:key])
870 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
873 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
874 [Strings_ setObject:[strings autorelease] forKey:name];
878 [Strings_ setObject:[NSNull null] forKey:name];
879 return [self wb_localizedStringForKey:key value:value table:table];
882 @class WebCoreFrameBridge;
883 static CGSize WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(WebCoreFrameBridge<WinterBoard> *self, SEL sel, id node, float width) {
886 void **core(reinterpret_cast<void **>([node _node]));
887 if (core == NULL || core[6] == NULL)
889 return [self wb_renderedSizeOfNode:node constrainedToWidth:width];
892 static void SBIconLabel$drawRect$(SBIconLabel<WinterBoard> *self, SEL sel, CGRect rect) {
893 CGRect bounds = [self bounds];
895 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
898 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
899 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
902 object_getInstanceVariable(self, "_label", reinterpret_cast<void **>(&label));
904 NSString *style = [NSString stringWithFormat:@""
905 "font-family: Helvetica; "
906 "font-weight: bold; "
909 "", docked ? @"white" : @"#b3b3b3"];
912 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
913 float max = 75, width = [label sizeWithStyle:style forWidth:320].width;
915 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", ((width - max) / ([label length] - 1))]];
916 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
917 style = [style stringByAppendingString:custom];
919 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
920 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
923 extern "C" void FindMappedImages(void);
924 extern "C" NSData *UIImagePNGRepresentation(UIImage *);
926 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
927 static CGImageRef *(*_UIImageRefAtPath)(NSString *path, bool cache, UIImageOrientation *orientation);
928 static UIImage *(*_UIImageWithName)(NSString *name);
929 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
930 static NSBundle *(*_UIKitBundle)();
931 static void (*_UISharedImageInitialize)(bool);
932 static int (*_UISharedImageNameGetIdentifier)(NSString *);
933 static UIImage *(*_UISharedImageWithIdentifier)(int);
935 static UIImage *$_UIImageWithName(NSString *name) {
936 int id(_UISharedImageNameGetIdentifier(name));
938 NSLog(@"WB:Debug: UIImageWithName(\"%@\", %d)", name, id);
941 return _UIImageAtPath(name, _UIKitBundle());
943 NSNumber *key([NSNumber numberWithInt:id]);
944 UIImage *image = [UIImages_ objectForKey:key];
946 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
947 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
948 image = [[$UIImage alloc] wb_initWithContentsOfFile:path];
953 image = _UISharedImageWithIdentifier(id);
954 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
959 static UIImage *$_UIImageWithNameInDomain(NSString *name, NSString *domain) {
960 NSString *key = [NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name];
961 UIImage *image = [PathImages_ objectForKey:key];
963 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
965 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
966 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
967 image = [[$UIImage alloc] wb_initWithContentsOfFile:path];
972 image = _UIImageWithNameInDomain(name, domain);
973 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
977 template <typename Type_>
978 static void WBReplace(Type_ *symbol, Type_ *replace) {
979 return WBReplace(symbol, replace, static_cast<Type_ **>(NULL));
982 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
983 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
985 /*static void UIWebDocumentView$setViewportSize$forDocumentTypes$(UIWebDocumentView *self, SEL sel, CGSize size, int type) {
986 NSLog(@"WB:Examine: %f:%f:%u", size.width, size.height, type);
989 static bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long, char *, bool &);
991 static bool $_Z24GetFileNameForThisActionmPcRb(unsigned long a0, char *a1, bool &a2) {
992 bool value = _Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
994 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
997 NSString *path = [NSString stringWithUTF8String:a1];
998 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
999 NSString *file = [path substringFromIndex:31];
1001 for (NSString *theme in themes_) {
1002 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1003 if ([Manager_ fileExistsAtPath:path]) {
1004 strcpy(a1, [path UTF8String]);
1013 static void ChangeWallpaper(
1014 CFNotificationCenterRef center,
1018 CFDictionaryRef info
1021 NSLog(@"WB:Debug:ChangeWallpaper!");
1024 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"Wallpaper.png", @"Wallpaper.jpg", nil])) {
1025 image = [[$UIImage alloc] wb_initWithContentsOfFile:path];
1027 image = [image autorelease];
1030 if (WallpaperImage_ != nil)
1031 [WallpaperImage_ setImage:image];
1032 if (WallpaperPage_ != nil)
1033 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1037 void WBRename(bool instance, const char *name, SEL sel, IMP imp) {
1038 Class _class = objc_getClass(name);
1039 if (_class == nil) {
1041 NSLog(@"WB:Warning: cannot find class [%s]", name);
1045 _class = object_getClass(_class);
1046 MSHookMessage(_class, sel, imp, "wb_");
1049 extern "C" void WBInitialize() {
1050 if (dlopen(UIKit, RTLD_LAZY | RTLD_NOLOAD) == NULL)
1052 NSLog(@"WB:Notice: Installing WinterBoard...");
1054 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1056 NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"];
1057 if (MediaPlayer != nil)
1060 $MPVideoView = objc_getClass("MPVideoView");
1062 $UIColor = objc_getClass("UIColor");
1063 $UIImage = objc_getClass("UIImage");
1064 $UIImageView = objc_getClass("UIImageView");
1065 $UIWebDocumentView = objc_getClass("UIWebDocumentView");
1067 struct nlist nl[12];
1068 memset(nl, 0, sizeof(nl));
1070 nl[0].n_un.n_name = (char *) "___currentContextCount";
1071 nl[1].n_un.n_name = (char *) "___currentContextStack";
1072 nl[2].n_un.n_name = (char *) "___mappedImages";
1073 nl[3].n_un.n_name = (char *) "__UIImageAtPath";
1074 nl[4].n_un.n_name = (char *) "__UIImageRefAtPath";
1075 nl[5].n_un.n_name = (char *) "__UIImageWithName";
1076 nl[6].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1077 nl[7].n_un.n_name = (char *) "__UIKitBundle";
1078 nl[8].n_un.n_name = (char *) "__UISharedImageInitialize";
1079 nl[9].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1080 nl[10].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1084 __currentContextCount = (unsigned *) nl[0].n_value;
1085 __currentContextStack = (void ***) nl[1].n_value;
1086 __mappedImages = (id *) nl[2].n_value;
1087 _UIImageAtPath = (UIImage *(*)(NSString *, NSBundle *)) nl[3].n_value;
1088 _UIImageRefAtPath = (CGImageRef *(*)(NSString *, bool, UIImageOrientation *)) nl[4].n_value;
1089 _UIImageWithName = (UIImage *(*)(NSString *)) nl[5].n_value;
1090 _UIImageWithNameInDomain = (UIImage *(*)(NSString *, NSString *)) nl[6].n_value;
1091 _UIKitBundle = (NSBundle *(*)()) nl[7].n_value;
1092 _UISharedImageInitialize = (void (*)(bool)) nl[8].n_value;
1093 _UISharedImageNameGetIdentifier = (int (*)(NSString *)) nl[9].n_value;
1094 _UISharedImageWithIdentifier = (UIImage *(*)(int)) nl[10].n_value;
1096 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &_UIImageWithName);
1097 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &_UIImageWithNameInDomain);
1099 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1101 memset(nl, 0, sizeof(nl));
1102 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1103 nlist(AudioToolbox, nl);
1104 _Z24GetFileNameForThisActionmPcRb = (bool (*)(unsigned long, char *, bool &)) nl[0].n_value;
1105 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &_Z24GetFileNameForThisActionmPcRb);
1108 WBRename(false, "UIImage", @selector(applicationImageNamed:), (IMP) &UIImage$applicationImageNamed$);
1109 WBRename(false, "UIImage", @selector(defaultDesktopImage), (IMP) &UIImage$defaultDesktopImage$);
1110 WBRename(false, "UIImage", @selector(imageAtPath:), (IMP) &UIImage$imageAtPath$);
1111 WBRename(false, "UIImage", @selector(imageNamed:), (IMP) &UIImage$imageNamed$);
1112 WBRename(false, "UIImage", @selector(imageNamed:inBundle:), (IMP) &UIImage$imageNamed$inBundle$);
1114 //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
1115 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1116 //WBRename(true, "SBStatusBar", @selector(initWithMode:orientation:", (IMP) &SBStatusBar$initWithMode$orientation$);
1117 //WBRename(true, "UIWebDocumentView", @selector(setViewportSize:forDocumentTypes:", (IMP) &UIWebDocumentView$setViewportSize$forDocumentTypes$);
1119 WBRename(true, "NSBundle", @selector(bundlePath), (IMP) &NSBundle$bundlePath$);
1120 WBRename(true, "NSBundle", @selector(localizedStringForKey:value:table:), (IMP) &NSBundle$localizedStringForKey$value$table$);
1121 WBRename(true, "NSBundle", @selector(pathForResource:ofType:), (IMP) &NSBundle$pathForResource$ofType$);
1123 WBRename(true, "UIImage", @selector(initWithContentsOfFile:), (IMP) &$initWithContentsOfFile$);
1124 WBRename(true, "UIImage", @selector(initWithContentsOfFile:cache:), (IMP) &UIImage$initWithContentsOfFile$cache$);
1125 WBRename(true, "UINavigationBar", @selector(setBarStyle:), (IMP) &UINavigationBar$setBarStyle$);
1126 WBRename(true, "UIToolbar", @selector(setBarStyle:), (IMP) &UIToolbar$setBarStyle$);
1128 WBRename(true, "WebCoreFrameBridge", @selector(renderedSizeOfNode:constrainedToWidth:), (IMP) &WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$);
1130 WBRename(true, "SBApplication", @selector(pathForIcon), (IMP) &SBApplication$pathForIcon);
1131 WBRename(true, "SBApplicationIcon", @selector(icon), (IMP) &SBApplicationIcon$icon);
1132 WBRename(true, "SBBookmarkIcon", @selector(icon), (IMP) &SBBookmarkIcon$icon);
1133 WBRename(true, "SBButtonBar", @selector(didMoveToSuperview), (IMP) &$didMoveToSuperview);
1134 WBRename(true, "SBCalendarIconContentsView", @selector(drawRect:), (IMP) &SBCalendarIconContentsView$drawRect$);
1135 WBRename(true, "SBContentLayer", @selector(initWithSize:), (IMP) &SBContentLayer$initWithSize$);
1136 WBRename(true, "SBIconBadge", @selector(initWithBadge:), (IMP) &SBIconBadge$initWithBadge$);
1137 WBRename(true, "SBIconController", @selector(appendIconList:), (IMP) &SBIconController$appendIconList$);
1138 WBRename(true, "SBIconLabel", @selector(drawRect:), (IMP) &SBIconLabel$drawRect$);
1139 WBRename(true, "SBIconLabel", @selector(initWithSize:label:), (IMP) &SBIconLabel$initWithSize$label$);
1140 WBRename(true, "SBIconLabel", @selector(setInDock:), (IMP) &SBIconLabel$setInDock$);
1141 WBRename(true, "SBIconModel", @selector(cacheImageForIcon:), (IMP) &SBIconModel$cacheImageForIcon$);
1142 WBRename(true, "SBIconModel", @selector(getCachedImagedForIcon:), (IMP) &SBIconModel$getCachedImagedForIcon$);
1144 WBRename(true, "SBSlidingAlertDisplay", @selector(updateDesktopImage:), (IMP) &SBSlidingAlertDisplay$updateDesktopImage$);
1145 WBRename(true, "SBStatusBarContentsView", @selector(didMoveToSuperview), (IMP) &$didMoveToSuperview);
1146 WBRename(true, "SBStatusBarContentsView", @selector(initWithStatusBar:mode:), (IMP) &SBStatusBarContentsView$initWithStatusBar$mode$);
1147 WBRename(true, "SBStatusBarController", @selector(setStatusBarMode:orientation:duration:fenceID:animation:), (IMP) &SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$);
1148 WBRename(true, "SBStatusBarTimeView", @selector(drawRect:), (IMP) &SBStatusBarTimeView$drawRect$);
1150 _UISharedImageInitialize(false);
1152 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1153 if (English_ != nil)
1154 English_ = [English_ retain];
1156 Manager_ = [[NSFileManager defaultManager] retain];
1157 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1158 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1159 Files_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1160 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1161 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1163 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1165 if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1166 [settings autorelease];
1168 if (NSNumber *debug = [settings objectForKey:@"Debug"])
1169 Debug_ = [debug boolValue];
1171 NSArray *themes = [settings objectForKey:@"Themes"];
1173 if (NSString *theme = [settings objectForKey:@"Theme"])
1174 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1176 [NSNumber numberWithBool:true], @"Active",
1179 for (NSDictionary *theme in themes) {
1180 NSNumber *active = [theme objectForKey:@"Active"];
1181 if (![active boolValue])
1184 NSString *name = [theme objectForKey:@"Name"];
1188 NSString *theme = nil;
1190 #define testForTheme(format...) \
1191 if (theme == nil) { \
1192 NSString *path = [NSString stringWithFormat:format]; \
1193 if ([Manager_ fileExistsAtPath:path]) { \
1194 [themes_ addObject:path]; \
1199 testForTheme(@"/Library/Themes/%@.theme", name)
1200 testForTheme(@"/Library/Themes/%@", name)
1201 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1205 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1207 for (NSString *theme in themes_)
1208 if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
1209 for (NSString *key in [info allKeys])
1210 if ([Info_ objectForKey:key] == nil)
1211 [Info_ setObject:[info objectForKey:key] forKey:key];
1213 if (objc_getClass("SpringBoard") != nil)
1214 CFNotificationCenterAddObserver(
1215 CFNotificationCenterGetDarwinNotifyCenter(),
1216 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1219 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1220 [Info_ setObject:[NSNumber numberWithBool:(
1221 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1222 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1223 )] forKey:@"UndockedIconLabels"];
1225 if (![Info_ boolForKey:@"UndockedIconLabels"])
1227 NSLog(@"WB:Debug:Info = %@", [Info_ description]);