#define _pooled _H<NSAutoreleasePool> _pool([[NSAutoreleasePool alloc] init], true);
+void NSLogPoint(const char *fix, const CGPoint &point) {
+ NSLog(@"%s(%g,%g)", fix, point.x, point.y);
+}
+
void NSLogRect(const char *fix, const CGRect &rect) {
NSLog(@"%s(%g,%g)+(%g,%g)", fix, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}
#define ForRelease 0
#define ForSaurik 1 && !ForRelease
#define RecycleWebViews 0
-#define AlwaysReload 1 && !ForRelease
+#define AlwaysReload 0 && !ForRelease
/* Radix Sort {{{ */
@interface NSMutableArray (Radix)
@end
/* }}} */
+/* Apple Bug Fixes {{{ */
+@implementation UIWebDocumentView (Cydia)
+
+- (void) _setScrollerOffset:(CGPoint)offset {
+ UIScroller *scroller([self _scroller]);
+
+ CGSize size([scroller contentSize]);
+ CGSize bounds([scroller bounds].size);
+
+ CGPoint max;
+ max.x = size.width - bounds.width;
+ max.y = size.height - bounds.height;
+
+ // wtf Apple?!
+ if (max.x < 0)
+ max.x = 0;
+ if (max.y < 0)
+ max.y = 0;
+
+ offset.x = offset.x < 0 ? 0 : offset.x > max.x ? max.x : offset.x;
+ offset.y = offset.y < 0 ? 0 : offset.y > max.y ? max.y : offset.y;
+
+ [scroller setOffset:offset];
+}
+
+@end
+/* }}} */
+
typedef enum {
kUIControlEventMouseDown = 1 << 0,
kUIControlEventMouseMovedInside = 1 << 2, // mouse moved inside control target
}
- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
- NSString *context = [sheet context];
+ NSString *context([sheet context]);
- if ([context isEqualToString:@"remove"])
+ if ([context isEqualToString:@"remove"]) {
switch (button) {
case 1:
[self cancel];
default:
_assert(false);
}
- else if ([context isEqualToString:@"unable"])
- [self cancel];
- [sheet dismiss];
+ [sheet dismiss];
+ } else if ([context isEqualToString:@"unable"]) {
+ [self cancel];
+ [sheet dismiss];
+ } else
+ [super alertSheet:sheet buttonClicked:button];
}
- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
}
- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
- NSString *context = [sheet context];
+ NSString *context([sheet context]);
+
if ([context isEqualToString:@"conffile"]) {
FILE *input = [database_ input];
default:
_assert(false);
}
- }
- [sheet dismiss];
+ [sheet dismiss];
+ }
}
- (void) closeButtonPushed {
}
- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
- int count = [buttons_ count];
- _assert(count != 0);
- _assert(button <= count + 1);
+ NSString *context([sheet context]);
- if (count != button - 1)
- [self _clickButtonWithName:[buttons_ objectAtIndex:(button - 1)]];
+ if ([context isEqualToString:@"modify"]) {
+ int count = [buttons_ count];
+ _assert(count != 0);
+ _assert(button <= count + 1);
- [sheet dismiss];
+ if (count != button - 1)
+ [self _clickButtonWithName:[buttons_ objectAtIndex:(button - 1)]];
+
+ [sheet dismiss];
+ } else
+ [super alertSheet:sheet buttonClicked:button];
}
- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
buttons:buttons
defaultButtonIndex:2
delegate:self
- context:@"manage"
+ context:@"modify"
] autorelease]];
}
}
}
- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
- NSString *context = [sheet context];
- if ([context isEqualToString:@"source"])
+ NSString *context([sheet context]);
+
+ if ([context isEqualToString:@"source"]) {
switch (button) {
case 1: {
NSString *href = [[sheet textField] text];
_assert(false);
}
- [sheet dismiss];
+ [sheet dismiss];
+ }
}
- (id) initWithBook:(RVBook *)book database:(Database *)database {
context:@"source"
] autorelease];
+ [sheet setNumberOfRows:1];
+
[sheet addTextFieldWithValue:@"http://" label:@""];
UITextInputTraits *traits = [[sheet textField] textInputTraits];
[traits setAutocapitalizationType:0];
- [traits setKeyboardType:3];
+ [traits setKeyboardType:UIKeyboardTypeURL];
[traits setAutocorrectionType:1];
[sheet popupAlertAnimated:YES];
@implementation HomeView
- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
- [sheet dismiss];
+ NSString *context([sheet context]);
+
+ if ([context isEqualToString:@"about"])
+ [sheet dismiss];
+ else
+ [super alertSheet:sheet buttonClicked:button];
}
- (void) _leftButtonClicked {
return @"Settings";
}
+#if !AlwaysReload
- (NSString *) _rightButtonTitle {
return nil;
}
+#endif
@end
/* }}} */
@implementation BrowserView
- (void) dealloc {
+ if (challenge_ != nil)
+ [challenge_ release];
+
WebView *webview = [webview_ webView];
[webview setFrameLoadDelegate:nil];
[webview setResourceLoadDelegate:nil];
[book_ pushPage:self];
}
-- (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)dataSource {
+- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
+ NSString *context([sheet context]);
+
+ if ([context isEqualToString:@"challenge"]) {
+ id<NSURLAuthenticationChallengeSender> sender([challenge_ sender]);
+
+ switch (button) {
+ case 1: {
+ NSString *username([[sheet textFieldAtIndex:0] text]);
+ NSString *password([[sheet textFieldAtIndex:1] text]);
+
+ NSURLCredential *credential([NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]);
+
+ [sender useCredential:credential forAuthenticationChallenge:challenge_];
+ } break;
+
+ case 2:
+ [sender cancelAuthenticationChallenge:challenge_];
+ break;
+
+ default:
+ _assert(false);
+ }
+
+ [challenge_ release];
+ challenge_ = nil;
+
+ [sheet dismiss];
+ }
+}
+
+- (void) webView:(WebView *)sender resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source {
+ challenge_ = [challenge retain];
+
+ NSURLProtectionSpace *space([challenge protectionSpace]);
+ NSString *realm([space realm]);
+ if (realm == nil)
+ realm = @"";
+
+ UIActionSheet *sheet = [[[UIActionSheet alloc]
+ initWithTitle:realm
+ buttons:[NSArray arrayWithObjects:@"Login", @"Cancel", nil]
+ defaultButtonIndex:0
+ delegate:self
+ context:@"challenge"
+ ] autorelease];
+
+ [sheet setNumberOfRows:1];
+
+ [sheet addTextFieldWithValue:@"" label:@"username"];
+ [sheet addTextFieldWithValue:@"" label:@"password"];
+
+ UITextField *username([sheet textFieldAtIndex:0]); {
+ UITextInputTraits *traits([username textInputTraits]);
+ [traits setAutocapitalizationType:0];
+ [traits setAutocorrectionType:1];
+ }
+
+ UITextField *password([sheet textFieldAtIndex:1]); {
+ UITextInputTraits *traits([password textInputTraits]);
+ [traits setAutocapitalizationType:0];
+ [traits setAutocorrectionType:1];
+ }
+
+ [sheet popupAlertAnimated:YES];
+}
+
+- (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
NSURL *url = [request URL];
if ([self getSpecial:url])
return nil;
[webview_ setZoomsFocusedFormControl:YES];
[webview_ setContentsPosition:7];
[webview_ setEnabledGestures:0xa];
- [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:0x4];
- [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:0x7];
+ [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeIsZoomRubberBandEnabled];
+ [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeUpdatesScroller];
[webview_ setSmoothsFonts:YES];
}
- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
- NSString *context = [sheet context];
- if ([context isEqualToString:@"fixhalf"])
+ NSString *context([sheet context]);
+
+ if ([context isEqualToString:@"fixhalf"]) {
switch (button) {
case 1:
@synchronized (self) {
default:
_assert(false);
}
- else if ([context isEqualToString:@"role"]) {
+
+ [sheet dismiss];
+ } else if ([context isEqualToString:@"role"]) {
switch (button) {
case 1: Role_ = @"User"; break;
case 2: Role_ = @"Hacker"; break;
[self updateData];
else
[self finish];
- } else if ([context isEqualToString:@"upgrade"])
+
+ [sheet dismiss];
+ } else if ([context isEqualToString:@"upgrade"]) {
switch (button) {
case 1:
@synchronized (self) {
_assert(false);
}
- [sheet dismiss];
+ [sheet dismiss];
+ }
}
- (void) reorganize { _pooled
[self setIdleTimerDisabled:YES];
hud_ = [self addProgressHUD];
- [hud_ setText:@"Reorganizing\n\nWill Automatically\nRestart When Done"];
+ [hud_ setText:@"Reorganizing\n\nWill Automatically\nClose When Done"];
[self setStatusBarShowsProgress:YES];
setuid(0);
setgid(0);
-#if 0 /* XXX: this costs 1.4s of startup performance */
+#if 1 /* XXX: this costs 1.4s of startup performance */
if (unlink("/var/cache/apt/pkgcache.bin") == -1)
_assert(errno == ENOENT);
if (unlink("/var/cache/apt/srcpkgcache.bin") == -1)