static NSString *plist_;
static NSMutableDictionary *settings_;
+static BOOL changed_;
@interface WBThemeTableViewCell : UITableViewCell {
UILabel *label;
}
- (void) applicationWillTerminate:(UIApplication *)application {
- [settings_ writeToFile:plist_ atomically:YES];
- system("killall SpringBoard");
+ if (changed_) {
+ if (![settings_ writeToFile:plist_ atomically:YES])
+ NSLog(@"WB:Error:writeToFile");
+ system("killall SpringBoard");
+ }
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[theme setObject:[NSNumber numberWithBool:inactive] forKey:@"Active"];
cell.accessoryType = inactive ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
[themesTable_ deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:YES];
+ changed_ = YES;
}
- (NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
NSMutableDictionary *theme = [[[themesArray_ objectAtIndex:fromIndex] retain] autorelease];
[themesArray_ removeObjectAtIndex:fromIndex];
[themesArray_ insertObject:theme atIndex:toIndex];
+ changed_ = YES;
}
- (BOOL) tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
] retain];
settings_ = [[NSMutableDictionary alloc] initWithContentsOfFile:plist_];
+ if (settings_ == nil)
+ settings_ = [[NSMutableDictionary alloc] initWithCapacity:16];
themesArray_ = [settings_ objectForKey:@"Themes"];
if (themesArray_ == nil) {
[themes addObjectsFromArray:[manager contentsOfDirectoryAtPath:@"/Library/Themes" error:NULL]];
[themes addObjectsFromArray:[manager contentsOfDirectoryAtPath:[NSString stringWithFormat:@"%@/Library/SummerBoard/Themes", NSHomeDirectory()] error:NULL]];
- for (NSString *theme in themes) {
+ for (NSUInteger i(0), e([themes count]); i != e; ++i) {
+ NSString *theme = [themes objectAtIndex:i];
if ([theme hasSuffix:@".theme"])
- theme = [theme substringWithRange:NSMakeRange(0, [theme length] - 6)];
+ [themes replaceObjectAtIndex:i withObject:[theme substringWithRange:NSMakeRange(0, [theme length] - 6)]];
+ }
+
+ for (NSUInteger i(0), e([themesArray_ count]); i != e; ++i) {
+ NSMutableDictionary *theme = [themesArray_ objectAtIndex:i];
+ NSString *name = [theme objectForKey:@"Name"];
+ if (name == nil || ![themes containsObject:name]) {
+ [themesArray_ removeObjectAtIndex:i];
+ --i; --e;
+ }
+ }
+
+ for (NSString *theme in themes) {
if ([themesSet containsObject:theme])
continue;
[themesSet addObject:theme];