]>
Commit | Line | Data |
---|---|---|
62b2dbad JF |
1 | /* WinterBoard - Theme Manager for the iPhone |
2 | * Copyright (C) 2008 Jay Freeman (saurik) | |
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 <CoreGraphics/CGGeometry.h> | |
40 | #import <UIKit/UIKit.h> | |
41 | ||
42 | #define _trace() NSLog(@"_trace(%u)", __LINE__); | |
43 | ||
44 | @interface WBApplication : UIApplication < | |
45 | UITableViewDataSource, | |
46 | UITableViewDelegate | |
47 | > { | |
48 | UIWindow *window_; | |
49 | UITableView *themesTable_; | |
26c43b47 | 50 | NSMutableArray *themesArray_; |
62b2dbad JF |
51 | } |
52 | ||
53 | @end | |
54 | ||
55 | @implementation WBApplication | |
56 | ||
57 | - (void) dealloc { | |
58 | [window_ release]; | |
59 | [themesTable_ release]; | |
60 | [themesArray_ release]; | |
61 | [super dealloc]; | |
62 | } | |
63 | ||
64 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
65 | UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero] autorelease]; | |
66 | cell.text = [themesArray_ objectAtIndex:[indexPath row]]; | |
67 | return cell; | |
68 | } | |
69 | ||
70 | - (NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section { | |
71 | return [themesArray_ count]; | |
72 | } | |
73 | ||
74 | - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | |
75 | NSString *theme = [themesArray_ objectAtIndex:[indexPath row]]; | |
76 | ||
77 | [[NSDictionary dictionaryWithObjectsAndKeys: | |
78 | theme, @"Theme", | |
79 | nil] writeToFile:[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", | |
80 | NSHomeDirectory() | |
81 | ] atomically:YES]; | |
82 | ||
83 | if (fork() == 0) { | |
84 | execlp("killall", "killall", "SpringBoard", NULL); | |
85 | exit(0); | |
86 | } | |
87 | } | |
88 | ||
89 | - (void) applicationDidFinishLaunching:(id)unused { | |
90 | window_ = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; | |
91 | [window_ makeKeyAndVisible]; | |
92 | ||
26c43b47 | 93 | themesArray_ = [[NSMutableArray arrayWithCapacity:32] retain]; |
62b2dbad | 94 | NSFileManager *manager = [NSFileManager defaultManager]; |
26c43b47 JF |
95 | |
96 | [themesArray_ addObjectsFromArray:[manager contentsOfDirectoryAtPath:@"/Library/Themes" error:NULL]]; | |
97 | [themesArray_ addObjectsFromArray:[manager contentsOfDirectoryAtPath:[NSString stringWithFormat:@"%@/Library/SummerBoard/Themes", NSHomeDirectory()] error:NULL]]; | |
62b2dbad JF |
98 | |
99 | themesTable_ = [[UITableView alloc] initWithFrame:window_.bounds]; | |
100 | [window_ addSubview:themesTable_]; | |
101 | ||
102 | [themesTable_ setDataSource:self]; | |
103 | [themesTable_ setDelegate:self]; | |
104 | ||
105 | [themesTable_ setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; | |
106 | } | |
107 | ||
108 | @end | |
109 | ||
110 | int main(int argc, char *argv[]) { | |
111 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
112 | ||
113 | int value = UIApplicationMain(argc, argv, @"WBApplication", @"WBApplication"); | |
114 | ||
115 | [pool release]; | |
116 | return value; | |
117 | } |