]> git.saurik.com Git - winterboard.git/blob - Application.mm
2e129d75c7d9a64052b74e51d9701af77a8649b4
[winterboard.git] / Application.mm
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_;
50 NSArray *themesArray_;
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
93 NSFileManager *manager = [NSFileManager defaultManager];
94 themesArray_ = [[manager contentsOfDirectoryAtPath:@"/Library/Themes" error:nil] retain];
95
96 themesTable_ = [[UITableView alloc] initWithFrame:window_.bounds];
97 [window_ addSubview:themesTable_];
98
99 [themesTable_ setDataSource:self];
100 [themesTable_ setDelegate:self];
101
102 [themesTable_ setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
103 }
104
105 @end
106
107 int main(int argc, char *argv[]) {
108 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
109
110 int value = UIApplicationMain(argc, argv, @"WBApplication", @"WBApplication");
111
112 [pool release];
113 return value;
114 }