]> git.saurik.com Git - cydia.git/blobdiff - Cydia.mm
Commit (chpwn): good-bye-uiactionsheet.patch
[cydia.git] / Cydia.mm
index 176ea870ad3e37bd4bb6d4515b9c51919efb09af..f792200194afb041200d02057256f2b9cb03becd 100644 (file)
--- a/Cydia.mm
+++ b/Cydia.mm
@@ -292,6 +292,7 @@ static _finline NSString *CydiaURL(NSString *path) {
 
 - (id) initWithTitle:(NSString *)title buttons:(NSArray *)buttons defaultButtonIndex:(int)index {
     if ((self = [super init])) {
+               [self setTitle:title];
                [self setDelegate:self];
                for (NSString *button in buttons) [self addButtonWithTitle:button];
                [self setCancelButtonIndex:index];
@@ -302,9 +303,13 @@ static _finline NSString *CydiaURL(NSString *path) {
     button_ = buttonIndex + 1;
 }
 
+- (void) dismiss {
+       [self dismissWithClickedButtonIndex:-1 animated:YES];
+}
+
 - (int) yieldToPopupAlertAnimated:(BOOL)animated {
     button_ = 0;
-    [self popupAlertAnimated:animated];
+    [self show];
     NSRunLoop *loop([NSRunLoop currentRunLoop]);
     NSDate *future([NSDate distantFuture]);
     while (button_ == 0 && [loop runMode:NSDefaultRunLoopMode beforeDate:future]);
@@ -3968,7 +3973,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 @interface ConfirmationView : CydiaBrowserView {
     _transient Database *database_;
-    UIActionSheet *essential_;
+    UIAlertView *essential_;
     NSArray *changes_;
     NSArray *issues_;
     NSArray *sizes_;
@@ -3996,28 +4001,25 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [book_ popFromSuperviewAnimated:YES];
 }
 
-- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
-    NSString *context([sheet context]);
+- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
+    NSString *context([alert context]);
 
     if ([context isEqualToString:@"remove"]) {
-        switch (button) {
-            case 1:
+               if (button == [alert cancelButtonIndex]) {
                 [self cancel];
-                break;
-            case 2:
+        } else if (button == [alert firstOtherButtonIndex]) {
                 if (substrate_)
                     Finish_ = 2;
                 [delegate_ confirm];
-                break;
-            _nodefault
         }
 
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     } else if ([context isEqualToString:@"unable"]) {
         [self cancel];
-        [sheet dismiss];
-    } else
-        [super alertSheet:sheet buttonClicked:button];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
+    } else {
+               [super alertView:alert clickedButtonAtIndex:button];
+       }
 }
 
 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
@@ -4072,33 +4074,25 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         else if (Advanced_) {
             NSString *parenthetical(UCLocalize("PARENTHETICAL"));
 
-            essential_ = [[UIActionSheet alloc]
+            essential_ = [[UIAlertView alloc]
                 initWithTitle:UCLocalize("REMOVING_ESSENTIALS")
-                buttons:[NSArray arrayWithObjects:
-                    [NSString stringWithFormat:parenthetical, UCLocalize("CANCEL_OPERATION"), UCLocalize("SAFE")],
-                    [NSString stringWithFormat:parenthetical, UCLocalize("FORCE_REMOVAL"), UCLocalize("UNSAFE")],
-                nil]
-                defaultButtonIndex:0
-                delegate:self
-                context:@"remove"
-            ];
+                               message:UCLocalize("REMOVING_ESSENTIALS_EX")
+                               delegate:self
+                               cancelButtonTitle:[NSString stringWithFormat:parenthetical, UCLocalize("CANCEL_OPERATION"), UCLocalize("SAFE")]
+                               otherButtonTitles:[NSString stringWithFormat:parenthetical, UCLocalize("FORCE_REMOVAL"), UCLocalize("UNSAFE")], nil
+                       ];
 
-            [essential_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
-            [essential_ setDestructiveButtonIndex:1];
-            [essential_ setBodyText:UCLocalize("REMOVING_ESSENTIALS_EX")];
+            [essential_ setContext:@"remove"];
         } else {
-            essential_ = [[UIActionSheet alloc]
+            essential_ = [[UIAlertView alloc]
                 initWithTitle:UCLocalize("UNABLE_TO_COMPLY")
-                buttons:[NSArray arrayWithObjects:UCLocalize("OKAY"), nil]
-                defaultButtonIndex:0
-                delegate:self
-                context:@"unable"
+                               message:UCLocalize("UNABLE_TO_COMPLY_EX")
+                               delegate:self
+                               cancelButtonTitle:UCLocalize("OKAY")
+                               otherButtonTitles:nil
             ];
 
-            [essential_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
-            [essential_ setBodyText:UCLocalize("UNABLE_TO_COMPLY_EX")];
+                       [essential_ setContext:@"unable"];
         }
 
         changes_ = [[NSArray alloc] initWithObjects:
@@ -4373,25 +4367,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [transition_ transition:6 toView:view_];
 }
 
-- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
-    NSString *context([sheet context]);
+- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
+    NSString *context([alert context]);
 
     if ([context isEqualToString:@"conffile"]) {
-        FILE *input = [database_ input];
-
-        switch (button) {
-            case 1:
-                fprintf(input, "N\n");
-                fflush(input);
-                break;
-            case 2:
-                fprintf(input, "Y\n");
-                fflush(input);
-                break;
-            _nodefault
-        }
-
-        [sheet dismiss];
+               FILE *input = [database_ input];
+        if (button == [alert cancelButtonIndex]) fprintf(input, "N\n");
+        else if (button == [alert firstOtherButtonIndex]) fprintf(input, "Y\n");
+               fflush(input);
+               
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     }
 }
 
@@ -4565,7 +4550,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         defaultButtonIndex:0
     ] autorelease]);
 
-    [sheet setBodyText:error];
+    [sheet setMessage:error];
     [sheet yieldToPopupAlertAnimated:YES];
     [sheet dismiss];
 }
@@ -4612,22 +4597,18 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     NSString *ofile = conffile_r[1];
     //NSString *nfile = conffile_r[2];
 
-    UIActionSheet *sheet = [[[UIActionSheet alloc]
+    UIAlertView *alert = [[[UIAlertView alloc]
         initWithTitle:UCLocalize("CONFIGURATION_UPGRADE")
-        buttons:[NSArray arrayWithObjects:
-            UCLocalize("KEEP_OLD_COPY"),
-            UCLocalize("ACCEPT_NEW_COPY"),
-            // XXX: UCLocalize("SEE_WHAT_CHANGED"),
-        nil]
-        defaultButtonIndex:0
-        delegate:self
-        context:@"conffile"
-    ] autorelease];
-
-    [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
-    [sheet setBodyText:[NSString stringWithFormat:@"%@\n\n%@", UCLocalize("CONFIGURATION_UPGRADE_EX"), ofile]];
-    [sheet popupAlertAnimated:YES];
+               message:[NSString stringWithFormat:@"%@\n\n%@", UCLocalize("CONFIGURATION_UPGRADE_EX"), ofile]
+               delegate:self
+               cancelButtonTitle:UCLocalize("KEEP_OLD_COPY")
+               otherButtonTitles:UCLocalize("ACCEPT_NEW_COPY"),
+        // XXX: UCLocalize("SEE_WHAT_CHANGED"),
+               nil
+       ] autorelease];
+
+       [alert setContext:@"conffile"];
+    [alert show];
 }
 
 - (void) _setProgressTitle:(NSString *)title {
@@ -4700,6 +4681,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     delegate_ = delegate;
 }
 
+/* Fix landscape: redraw when frame changes. */
+- (void) setFrame:(CGRect)frame {
+       [super setFrame:frame];
+       [self setNeedsDisplay];
+}
+
 - (void) drawRect:(CGRect)rect {
     [super drawRect:rect];
     [delegate_ drawContentRect:rect];
@@ -5892,47 +5879,41 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
             if (NSString *warning = [self yieldToSelector:@selector(getWarning)]) {
                 defer = true;
 
-                UIActionSheet *sheet = [[[UIActionSheet alloc]
+                UIAlertView *alert = [[[UIAlertView alloc]
                     initWithTitle:UCLocalize("SOURCE_WARNING")
-                    buttons:[NSArray arrayWithObjects:UCLocalize("ADD_ANYWAY"), UCLocalize("CANCEL"), nil]
-                    defaultButtonIndex:0
-                    delegate:self
-                    context:@"warning"
+                                       message:warning
+                                       delegate:self
+                                       cancelButtonTitle:UCLocalize("CANCEL")
+                    otherButtonTitles:UCLocalize("ADD_ANYWAY"), nil
                 ] autorelease];
 
-                [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
-                [sheet setNumberOfRows:1];
-                [sheet setBodyText:warning];
-                [sheet popupAlertAnimated:YES];
+                               [alert setContext:@"warning"];
+                [alert setNumberOfRows:1];
+                [alert show];
             } else
                 [self complete];
         } else if (error_ != nil) {
-            UIActionSheet *sheet = [[[UIActionSheet alloc]
+            UIAlertView *alert = [[[UIAlertView alloc]
                 initWithTitle:UCLocalize("VERIFICATION_ERROR")
-                buttons:[NSArray arrayWithObjects:UCLocalize("OK"), nil]
-                defaultButtonIndex:0
-                delegate:self
-                context:@"urlerror"
+                               message:[error_ localizedDescription]
+                               delegate:self
+                               cancelButtonTitle:UCLocalize("OK")
+                otherButtonTitles:nil
             ] autorelease];
 
-            [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
-            [sheet setBodyText:[error_ localizedDescription]];
-            [sheet popupAlertAnimated:YES];
+                       [alert setContext:@"urlerror"];
+            [alert show];
         } else {
-            UIActionSheet *sheet = [[[UIActionSheet alloc]
+            UIAlertView *alert = [[[UIAlertView alloc]
                 initWithTitle:UCLocalize("NOT_REPOSITORY")
-                buttons:[NSArray arrayWithObjects:UCLocalize("OK"), nil]
-                defaultButtonIndex:0
-                delegate:self
-                context:@"trivial"
+                               message:UCLocalize("NOT_REPOSITORY_EX")
+                               delegate:self
+                               cancelButtonTitle:UCLocalize("OK")
+                otherButtonTitles:nil
             ] autorelease];
 
-            [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
-            [sheet setBodyText:UCLocalize("NOT_REPOSITORY_EX")];
-            [sheet popupAlertAnimated:YES];
+                       [alert setContext:@"trivial"];
+            [alert show];
         }
 
         [delegate_ setStatusBarShowsProgress:NO];
@@ -5990,13 +5971,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     return [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
 }
 
-- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
-    NSString *context([sheet context]);
+- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
+    NSString *context([alert context]);
 
     if ([context isEqualToString:@"source"]) {
         switch (button) {
             case 1: {
-                NSString *href = [[sheet textField] text];
+                NSString *href = [[alert textField] text];
 
                 //installer_ = [[self _requestHRef:href method:@"GET"] retain];
 
@@ -6017,24 +5998,24 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
                 [hud_ setText:UCLocalize("VERIFYING_URL")];
             } break;
 
-            case 2:
+            case 0:
             break;
 
             _nodefault
         }
 
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     } else if ([context isEqualToString:@"trivial"])
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     else if ([context isEqualToString:@"urlerror"])
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     else if ([context isEqualToString:@"warning"]) {
         switch (button) {
             case 1:
                 [self complete];
             break;
 
-            case 2:
+            case 0:
             break;
 
             _nodefault
@@ -6043,7 +6024,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         [href_ release];
         href_ = nil;
 
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     }
 }
 
@@ -6108,27 +6089,28 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         database:database_
     ] autorelease]];*/
 
-    UIActionSheet *sheet = [[[UIActionSheet alloc]
+    UIAlertView *alert = [[[UIAlertView alloc]
         initWithTitle:UCLocalize("ENTER_APT_URL")
-        buttons:[NSArray arrayWithObjects:UCLocalize("ADD_SOURCE"), UCLocalize("CANCEL"), nil]
-        defaultButtonIndex:0
-        delegate:self
-        context:@"source"
+               message:nil
+               delegate:self
+               cancelButtonTitle:UCLocalize("CANCEL")
+               otherButtonTitles:UCLocalize("ADD_SOURCE"), nil
     ] autorelease];
 
-    [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+       [alert setContext:@"source"];
+       [alert setTransform:CGAffineTransformTranslate([alert transform], 0.0, 100.0)];
 
-    [sheet setNumberOfRows:1];
-    [sheet addTextFieldWithValue:@"http://" label:@""];
+    [alert setNumberOfRows:1];
+    [alert addTextFieldWithValue:@"http://" label:@""];
 
-    UITextInputTraits *traits = [[sheet textField] textInputTraits];
+    UITextInputTraits *traits = [[alert textField] textInputTraits];
     [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
     [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
     [traits setKeyboardType:UIKeyboardTypeURL];
     // XXX: UIReturnKeyDone
     [traits setReturnKeyType:UIReturnKeyNext];
 
-    [sheet popupAlertAnimated:YES];
+    [alert show];
 }
 
 - (void) _rightButtonClicked {
@@ -6241,15 +6223,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 @implementation HomeView
 
-- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
-    NSString *context([sheet context]);
-
-    if ([context isEqualToString:@"about"])
-        [sheet dismiss];
-    else
-        [super alertSheet:sheet buttonClicked:button];
-}
-
 - (void) _setMoreHeaders:(NSMutableURLRequest *)request {
     [super _setMoreHeaders:request];
     if (ChipID_ != nil)
@@ -7671,40 +7644,29 @@ static _finline void _setHomePage(Cydia *self) {
     if ([broken_ count] != 0) {
         int count = [broken_ count];
 
-        UIActionSheet *sheet = [[[UIActionSheet alloc]
+        UIAlertView *alert = [[[UIAlertView alloc]
             initWithTitle:(count == 1 ? UCLocalize("HALFINSTALLED_PACKAGE") : [NSString stringWithFormat:UCLocalize("HALFINSTALLED_PACKAGES"), count])
-            buttons:[NSArray arrayWithObjects:
-                UCLocalize("FORCIBLY_CLEAR"),
-                UCLocalize("TEMPORARY_IGNORE"),
-            nil]
-            defaultButtonIndex:0
-            delegate:self
-            context:@"fixhalf"
+                       message:UCLocalize("HALFINSTALLED_PACKAGE_EX")
+                       delegate:self
+                       cancelButtonTitle:UCLocalize("FORCIBLY_CLEAR")
+                       otherButtonTitles:UCLocalize("TEMPORARY_IGNORE"), nil
         ] autorelease];
 
-        [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
-        [sheet setBodyText:UCLocalize("HALFINSTALLED_PACKAGE_EX")];
-        [sheet popupAlertAnimated:YES];
+        [alert setContext:@"fixhalf"];
+        [alert show];
     } else if (!Ignored_ && [essential_ count] != 0) {
         int count = [essential_ count];
 
-        UIActionSheet *sheet = [[[UIActionSheet alloc]
+        UIAlertView *alert = [[[UIAlertView alloc]
             initWithTitle:(count == 1 ? UCLocalize("ESSENTIAL_UPGRADE") : [NSString stringWithFormat:UCLocalize("ESSENTIAL_UPGRADES"), count])
-            buttons:[NSArray arrayWithObjects:
-                UCLocalize("UPGRADE_ESSENTIAL"),
-                UCLocalize("COMPLETE_UPGRADE"),
-                UCLocalize("TEMPORARY_IGNORE"),
-            nil]
-            defaultButtonIndex:0
-            delegate:self
-            context:@"upgrade"
+                       message:UCLocalize("ESSENTIAL_UPGRADE_EX")
+                       delegate:self
+                       cancelButtonTitle:UCLocalize("TEMPORARY_IGNORE")
+            otherButtonTitles:UCLocalize("UPGRADE_ESSENTIAL"), UCLocalize("COMPLETE_UPGRADE"), nil
         ] autorelease];
 
-        [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
-        [sheet setBodyText:UCLocalize("ESSENTIAL_UPGRADE_EX")];
-        [sheet popupAlertAnimated:YES];
+        [alert setContext:@"upgrade"];
+        [alert show];
     }
 }
 
@@ -8048,7 +8010,7 @@ static _finline void _setHomePage(Cydia *self) {
         defaultButtonIndex:-1
     ] autorelease]);
 
-    [role setBodyText:UCLocalize("ROLE_EX")];
+    [role setMessage:UCLocalize("ROLE_EX")];
 
     int button([role yieldToPopupAlertAnimated:YES]);
 
@@ -8143,58 +8105,50 @@ static _finline void _setHomePage(Cydia *self) {
                 confirm_ = nil;
             }
         }
-    } else if ([context isEqualToString:@"fixhalf"]) {
-        switch (button) {
-            case 1:
-                @synchronized (self) {
-                    for (Package *broken in broken_) {
-                        [broken remove];
-
-                        NSString *id = [broken id];
-                        unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.prerm", id] UTF8String]);
-                        unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.postrm", id] UTF8String]);
-                        unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.preinst", id] UTF8String]);
-                        unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.postinst", id] UTF8String]);
-                    }
-
-                    [self resolve];
-                    [self perform];
+    } 
+}
+
+- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
+       NSString *context([alert context]);
+       
+       if ([context isEqualToString:@"fixhalf"]) {
+               if (button == [alert firstOtherButtonIndex]) {
+            @synchronized (self) {
+                for (Package *broken in broken_) {
+                    [broken remove];
+
+                    NSString *id = [broken id];
+                    unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.prerm", id] UTF8String]);
+                    unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.postrm", id] UTF8String]);
+                    unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.preinst", id] UTF8String]);
+                    unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.postinst", id] UTF8String]);
                 }
-            break;
 
-            case 2:
-                [broken_ removeAllObjects];
-                [self _loaded];
-            break;
-
-            _nodefault
+                [self resolve];
+                [self perform];
+            }
+               } else if (button == [alert cancelButtonIndex]) {
+            [broken_ removeAllObjects];
+            [self _loaded];
         }
 
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     } else if ([context isEqualToString:@"upgrade"]) {
-        switch (button) {
-            case 1:
-                @synchronized (self) {
-                    for (Package *essential in essential_)
-                        [essential install];
-
-                    [self resolve];
-                    [self perform];
-                }
-            break;
-
-            case 2:
-                [self distUpgrade];
-            break;
-
-            case 3:
-                Ignored_ = YES;
-            break;
+        if (button == [alert firstOtherButtonIndex]) {
+            @synchronized (self) {
+                for (Package *essential in essential_)
+                    [essential install];
 
-            _nodefault
+                [self resolve];
+                [self perform];
+            }
+        } else if (button == [alert firstOtherButtonIndex] + 1) {
+            [self distUpgrade];
+        } else if (button == [alert cancelButtonIndex]) {
+            Ignored_ = YES;
         }
 
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     }
 }