Skip to content

Commit

Permalink
* Method to create an NSURLRequest from a TTURLRequest
Browse files Browse the repository at this point in the history
* Method to load a request in a TTWebController
* Bug fixes in search bars
  • Loading branch information
joehewitt committed Jun 10, 2009
1 parent b789448 commit b5e86f3
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 35 deletions.
1 change: 0 additions & 1 deletion src/TTGlobal.m
Expand Up @@ -109,7 +109,6 @@ BOOL TTOSVersionIsAtLeast(float version) {
return NO;
}


NSLocale* TTCurrentLocale() {
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSArray* languages = [defaults objectForKey:@"AppleLanguages"];
Expand Down
5 changes: 3 additions & 2 deletions src/TTSearchBar.m
Expand Up @@ -70,8 +70,9 @@ - (void)scrollToTop {
UIScrollView* scrollView = (UIScrollView*)[self firstParentOfClass:[UIScrollView class]];
if (scrollView) {
CGPoint offset = scrollView.contentOffset;
if (offset.y != self.top) {
[scrollView setContentOffset:CGPointMake(offset.x, self.top) animated:YES];
CGPoint myOffset = [self offsetFromView:scrollView];
if (offset.y != myOffset.y) {
[scrollView setContentOffset:CGPointMake(offset.x, myOffset.y) animated:YES];
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/TTSearchTextField.m
Expand Up @@ -63,10 +63,6 @@ - (void)textFieldDidEndEditing:(UITextField *)textField {
if ([_delegate respondsToSelector:@selector(textFieldDidEndEditing:)]) {
[_delegate textFieldDidEndEditing:textField];
}

if (_textField.dataSource) {
textField.text = @"";
}
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range
Expand Down Expand Up @@ -104,7 +100,7 @@ - (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (!_textField.searchesAutomatically) {
[_textField search];
} else {
[_textField resignFirstResponder];
[_textField performSelector:@selector(doneAction)];
}
}
return shouldReturn;
Expand Down Expand Up @@ -222,6 +218,7 @@ - (void)autoSearch {
[self search];
}
}

- (void)dispatchUpdate:(NSTimer*)timer {
_searchTimer = nil;
[self autoSearch];
Expand Down Expand Up @@ -253,6 +250,10 @@ - (void)screenAnimationDidStop {

- (void)doneAction {
[self resignFirstResponder];

if (self.dataSource) {
self.text = @"";
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/TTThumbsViewController.m
Expand Up @@ -221,7 +221,7 @@ - (void)loadView {
CGFloat y = TTOSVersionIsAtLeast(3.0) ? 0 : -CHROME_HEIGHT;
CGRect innerFrame = CGRectMake(0, y,
screenFrame.size.width, screenFrame.size.height + CHROME_HEIGHT);
UIView* innerView = [[UIView alloc] initWithFrame:innerFrame];
UIView* innerView = [[[UIView alloc] initWithFrame:innerFrame] autorelease];
innerView.backgroundColor = TTSTYLEVAR(backgroundColor);
[self.view addSubview:innerView];

Expand Down
4 changes: 4 additions & 0 deletions src/TTURLRequest.m
Expand Up @@ -206,6 +206,10 @@ - (void)cancel {
[[TTURLRequestQueue mainQueue] cancelRequest:self];
}

- (NSURLRequest*)createNSURLRequest {
return [[TTURLRequestQueue mainQueue] createNSURLRequest:self url:nil];
}

@end

//////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
58 changes: 34 additions & 24 deletions src/TTURLRequestQueue.m
Expand Up @@ -87,31 +87,9 @@ - (void)connectToURL:(NSURL*)url {
TTLOG(@"Connecting to %@", _url);
TTNetworkRequestStarted();

NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:kTimeout];
[urlRequest setValue:_queue.userAgent forHTTPHeaderField:@"User-Agent"];
TTURLRequest* request = _requests.count == 1 ? [_requests objectAtIndex:0] : nil;
NSURLRequest *urlRequest = [_queue createNSURLRequest:request url:url];

if (_requests.count == 1) {
TTURLRequest* request = [_requests objectAtIndex:0];
[urlRequest setHTTPShouldHandleCookies:request.shouldHandleCookies];

NSString* method = request.httpMethod;
if (method) {
[urlRequest setHTTPMethod:method];
}

NSString* contentType = request.contentType;
if (contentType) {
[urlRequest setValue:contentType forHTTPHeaderField:@"Content-Type"];
}

NSData* body = request.httpBody;
if (body) {
[urlRequest setHTTPBody:body];
}
}

_connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
}

Expand Down Expand Up @@ -611,4 +589,36 @@ - (void)cancelAllRequests {
}
}

- (NSURLRequest*)createNSURLRequest:(TTURLRequest*)request url:(NSURL*)url {
if (!url) {
url = [NSURL URLWithString:request.url];
}

NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:kTimeout];
[urlRequest setValue:self.userAgent forHTTPHeaderField:@"User-Agent"];

if (request) {
[urlRequest setHTTPShouldHandleCookies:request.shouldHandleCookies];

NSString* method = request.httpMethod;
if (method) {
[urlRequest setHTTPMethod:method];
}

NSString* contentType = request.contentType;
if (contentType) {
[urlRequest setValue:contentType forHTTPHeaderField:@"Content-Type"];
}

NSData* body = request.httpBody;
if (body) {
[urlRequest setHTTPBody:body];
}
}

return urlRequest;
}

@end
8 changes: 6 additions & 2 deletions src/TTWebController.m
Expand Up @@ -169,6 +169,11 @@ - (NSURL*)url {
return _webView.request.URL;
}

- (void)openRequest:(NSURLRequest*)request {
self.view;
[_webView loadRequest:request];
}

- (void)setHeaderView:(UIView*)headerView {
if (headerView != _headerView) {
BOOL addingHeader = !_headerView && headerView;
Expand All @@ -195,9 +200,8 @@ - (void)setHeaderView:(UIView*)headerView {
}

- (void)openURL:(NSURL*)url {
self.view;
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
[_webView loadRequest:request];
[self openRequest:request];
}

@end
2 changes: 2 additions & 0 deletions src/Three20/TTURLRequest.h
Expand Up @@ -101,6 +101,8 @@
*/
- (void)cancel;

- (NSURLRequest*)createNSURLRequest;

@end

///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
5 changes: 5 additions & 0 deletions src/Three20/TTURLRequestQueue.h
Expand Up @@ -76,4 +76,9 @@
*/
- (void)cancelAllRequests;

/**
* Creates a Cocoa URL request from a Three20 URL request.
*/
- (NSURLRequest*)createNSURLRequest:(TTURLRequest*)request url:(NSURL*)url;

@end
1 change: 1 addition & 0 deletions src/Three20/TTWebController.h
Expand Up @@ -19,6 +19,7 @@
@property(nonatomic,retain) UIView* headerView;

- (void)openURL:(NSURL*)url;
- (void)openRequest:(NSURLRequest*)request;

@end

Expand Down

0 comments on commit b5e86f3

Please sign in to comment.