]>
Commit | Line | Data |
---|---|---|
a4ccf03b JF |
1 | /* UIKit Tools - command-line utilities for UIKit |
2 | * Copyright (C) 2008-2012 Jay Freeman (saurik) | |
3 | */ | |
4 | ||
5 | /* Modified BSD License {{{ */ | |
6 | /* | |
7 | * Redistribution and use in source and binary | |
8 | * forms, with or without modification, are permitted | |
9 | * provided that the following conditions are met: | |
10 | * | |
11 | * 1. Redistributions of source code must retain the | |
12 | * above copyright notice, this list of conditions | |
13 | * and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the | |
15 | * above copyright notice, this list of conditions | |
16 | * and the following disclaimer in the documentation | |
17 | * and/or other materials provided with the | |
18 | * distribution. | |
19 | * 3. The name of the author may not be used to endorse | |
20 | * or promote products derived from this software | |
21 | * without specific prior written permission. | |
22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' | |
24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | |
25 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE | |
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
30 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
34 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
36 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
37 | */ | |
38 | /* }}} */ | |
39 | ||
d4e26d1d JF |
40 | #import <Foundation/Foundation.h> |
41 | #import <UIKit/UIKit.h> | |
42 | ||
a60b86de | 43 | #include <unistd.h> |
d4e26d1d | 44 | #include <cstdlib> |
a60b86de JF |
45 | |
46 | int argc_; | |
47 | char **argv_; | |
48 | ||
e8653a29 JF |
49 | @interface AlertSheet : UIApplication |
50 | #ifdef __OBJC2__ | |
51 | <UIModalViewDelegate> | |
52 | #endif | |
53 | { | |
a60b86de JF |
54 | } |
55 | ||
e8653a29 JF |
56 | #ifdef __OBJC2__ |
57 | - (void) modalView:(UIModalView *)modalView didDismissWithButtonIndex:(NSInteger)buttonIndex; | |
58 | #else | |
a60b86de | 59 | - (void) alertSheet:(UIAlertSheet *)sheet buttonClicked:(int)button; |
e8653a29 JF |
60 | #endif |
61 | ||
a60b86de JF |
62 | - (void) applicationDidFinishLaunching:(id)unused; |
63 | @end | |
64 | ||
65 | @implementation AlertSheet | |
66 | ||
e8653a29 JF |
67 | #ifdef __OBJC2__ |
68 | - (void) modalView:(UIModalView *)modalView didDismissWithButtonIndex:(NSInteger)buttonIndex { | |
69 | exit(buttonIndex); | |
70 | } | |
71 | #else | |
72 | - (void) alertSheet:(UIAlertSheet *)alertSheet buttonClicked:(int)button { | |
73 | [alertSheet dismiss]; | |
a60b86de JF |
74 | exit(button); |
75 | } | |
e8653a29 | 76 | #endif |
a60b86de JF |
77 | |
78 | - (void) applicationDidFinishLaunching:(id)unused { | |
79 | NSMutableArray *buttons = [NSMutableArray arrayWithCapacity:(argc_ - 3)]; | |
80 | for (size_t i(0); i != argc_ - 3; ++i) | |
81 | [buttons addObject:[NSString stringWithCString:argv_[i + 3]]]; | |
82 | ||
e8653a29 JF |
83 | #ifdef __OBJC2__ |
84 | UIAlertView *alert = [[[UIAlertView alloc] | |
85 | initWithTitle:[NSString stringWithCString:argv_[1]] | |
86 | message:[NSString stringWithCString:argv_[2]] | |
87 | delegate:self | |
88 | cancelButtonTitle:nil | |
89 | otherButtonTitles:nil | |
90 | ] autorelease]; | |
91 | ||
92 | [alert show]; | |
93 | #else | |
a60b86de JF |
94 | UIAlertSheet *sheet = [[[UIAlertSheet alloc] |
95 | initWithTitle:[NSString stringWithCString:argv_[1]] | |
96 | buttons:buttons | |
97 | defaultButtonIndex:0 | |
98 | delegate:self | |
99 | context:self | |
100 | ] autorelease]; | |
101 | ||
102 | [sheet setBodyText:[NSString stringWithCString:argv_[2]]]; | |
103 | ||
104 | [sheet setShowsOverSpringBoardAlerts:YES]; | |
105 | [sheet popupAlertAnimated:YES]; | |
e8653a29 | 106 | #endif |
a60b86de JF |
107 | } |
108 | ||
109 | @end | |
110 | ||
111 | int main(int argc, char *argv[]) { | |
112 | argc_ = argc; | |
113 | argv_ = argv; | |
114 | ||
115 | char *args[] = { | |
d4e26d1d | 116 | (char *) "AlertSheet", NULL |
a60b86de JF |
117 | }; |
118 | ||
119 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
e8653a29 JF |
120 | #ifdef __OBJC2__ |
121 | UIApplicationMain(1, args, nil, @"AlertSheet"); | |
122 | #else | |
a60b86de | 123 | UIApplicationMain(1, args, [AlertSheet class]); |
e8653a29 | 124 | #endif |
a60b86de JF |
125 | [pool release]; |
126 | return 0; | |
127 | } |