Changeset 672
- Timestamp:
- 01/19/10 15:57:59 (8 weeks ago)
- Location:
- apps/iphone/my.tel/trunk/Classes
- Files:
-
- 5 modified
-
AccountEditController.h (modified) (2 diffs)
-
AccountEditController.m (modified) (4 diffs)
-
AlertRenameView.m (modified) (5 diffs)
-
MyTelConnect.h (modified) (2 diffs)
-
MyTelConnect.m (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
apps/iphone/my.tel/trunk/Classes/AccountEditController.h
r593 r672 9 9 #import <UIKit/UIKit.h> 10 10 #import "MyTelConnect.h" 11 #import "DnsResolver.h" 11 #import "TextFieldCell.h" 12 #import "AlertRenameView.h" 12 13 13 #import "TextFieldCell.h" 14 15 @interface AccountEditController : UITableViewController <UITextFieldDelegate> { 14 @interface AccountEditController : UITableViewController <UITextFieldDelegate, UIAlertViewDelegate> { 16 15 TextFieldCell *cellAccountLabel; // user-created label for the account (optional) 17 16 TextFieldCell *cellDomainName; // name of a domain in the account (any domain in the account will do) … … 25 24 - (void)didPressSave; 26 25 - (void)didPressCancel; 27 - (NSString *)apiUrlForDomain:(NSString *)aDomain withError:(NSError **)error;28 26 29 27 @property (nonatomic, retain) IBOutlet TextFieldCell *cellAccountLabel; -
apps/iphone/my.tel/trunk/Classes/AccountEditController.m
r667 r672 168 168 break; 169 169 case 2: 170 return @" There should be no need to modify this section.";170 return @"Modify items in this section only if necessary."; 171 171 break; 172 172 default: … … 210 210 case 2: 211 211 cell = cellApiRootUrl; 212 cell.textLabel.text = @" API RootURL";212 cell.textLabel.text = @"TelHosting API URL"; 213 213 cell.textField.placeholder = @"http://telhosting/g2/json"; 214 214 break; … … 282 282 if (!self.apiRootUrl || [self.apiRootUrl isEqualToString:@""]) { 283 283 NSError *loginError = nil; 284 self.apiRootUrl = [self apiUrlForDomain:self.domainName withError:&loginError]; 285 } 286 284 self.apiRootUrl = [[MyTelConnect sharedInstance] apiUrlForDomain:self.domainName withError:&loginError]; 285 if (loginError != nil) { 286 // Can't get autoprovision, ask for .tel provider URL 287 NSString *alertTitle = [NSString stringWithFormat:@"Unknown TelHosting URL for %@", self.domainName]; 288 NSMutableString *fullMessage = [NSMutableString stringWithString:@"Enter the TelHosting URL given by your .tel provider"]; 289 AlertRenameView *alert = [[AlertRenameView alloc] initWithTitle:alertTitle 290 message:fullMessage 291 delegate:self 292 cancelButtonTitle:@"Cancel" 293 otherButtonTitles:@"OK", nil]; 294 alert.uiStringField.minimumFontSize = 14.0f; 295 alert.uiStringField.font = [alert.uiStringField.font fontWithSize:14.0f]; 296 alert.uiStringField.placeholder = @"https://telhosting.provider.com"; 297 [alert show]; 298 [alert release]; 299 self.navigationItem.rightBarButtonItem = origButton; 300 [origButton release]; 301 return; 302 } 303 } 304 // All was well 287 305 [self.delegate dataDidChangeInController:self]; 288 self.navigationItem.rightBarButtonItem = origButton;289 [origButton release];290 306 [self.navigationController popViewControllerAnimated:YES]; 291 307 } … … 295 311 } 296 312 297 - (NSString *)apiUrlForDomain:(NSString *)aDomain withError:(NSError **)error { 298 if (!aDomain) 299 return nil; 300 // try to autoprovision apiRootUrl 301 [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; 302 NSMutableArray *naptrArray = [NSMutableArray arrayWithCapacity:1]; 303 NSString *autoProvisionDomain = [@"_https._nsp._apps." stringByAppendingString:aDomain]; 304 DnsResolver *resolver =[[DnsResolver alloc] init]; 305 [resolver getNAPTRForTel:autoProvisionDomain inArray:naptrArray withError:error]; 306 if ([naptrArray count] == 0) { 307 // couldn't find anything, try in http mode 308 NSString *autoProvisionDomainHttp = [@"_http._nsp._apps." stringByAppendingString:aDomain]; 309 [resolver getNAPTRForTel:autoProvisionDomainHttp inArray:naptrArray withError:error]; 310 } 311 [resolver release]; 312 [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; 313 if ([naptrArray count] > 0) { 314 // we have autoprovision of the Telhosting URL, let's tweak it to get the JSON API 315 RecordNaptr *theRec = [naptrArray objectAtIndex:0]; 316 return ([theRec.uriContent stringByAppendingString:@"/g2/json"]); 317 } 318 // Still found nothing, no autoprovisioning possible 319 return @""; 313 #pragma mark - 314 #pragma mark UIAlertViewDelegate methods 315 316 - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex { 317 if (buttonIndex == alertView.cancelButtonIndex) { 318 return; 319 } 320 NSMutableString *apiRoot = [NSMutableString stringWithString:((AlertRenameView *)alertView).uiStringField.text]; 321 if (apiRoot == nil) { 322 [apiRoot setString:@""]; 323 } 324 if (![apiRoot hasPrefix:@"http"]) { 325 [apiRoot insertString:@"https://" atIndex:0]; 326 } 327 if (![apiRoot hasSuffix:@"/g2/json"]) { 328 [apiRoot appendString:@"/g2/json"]; 329 } 330 self.apiRootUrl = ((AlertRenameView *)alertView).uiStringField.text = apiRoot; 320 331 } 321 332 -
apps/iphone/my.tel/trunk/Classes/AlertRenameView.m
r593 r672 13 13 #define kARTextFieldDiff 50 14 14 // Height of text field 15 #define kARTextFieldHeight 32 15 #define kARTextFieldHeight 28 16 // Height of bottom buttons of UIAlertView, including margins 17 #define kARButtonsHeight 75 16 18 17 19 @implementation AlertRenameView … … 32 34 theField.borderStyle = UITextBorderStyleRoundedRect; 33 35 theField.minimumFontSize = 16; 36 theField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 34 37 theField.clearButtonMode = UITextFieldViewModeAlways; 35 38 theField.autocorrectionType = UITextAutocorrectionTypeNo; … … 38 41 uiStringField = theField; 39 42 [self addSubview:uiStringField]; 40 41 self.message = @"\n\n"; // No messages here, only space for the entry field42 43 } 43 44 return self; 45 } 46 47 - (void)setMessage:(NSString *)aMessage { 48 // add space for the entry field. Height depends on whether there's text or not 49 if ((aMessage != nil) && (aMessage != @"\n\n") && ([aMessage length] > 0)) { 50 [super setMessage:[aMessage stringByAppendingString:@"\n\n\n"]]; 51 } else { 52 [super setMessage:@"\n\n"]; 53 } 44 54 } 45 55 … … 49 59 CGRect textRect = boundsRect; 50 60 textRect.size = CGSizeMake(rect.size.width - kARTextFieldDiff, kARTextFieldHeight); 51 textRect = CGRectOffset(textRect, kARTextFieldDiff/2 , kARTextFieldHeight+18);61 textRect = CGRectOffset(textRect, kARTextFieldDiff/2 , rect.size.height - (kARTextFieldHeight + kARButtonsHeight)); 52 62 uiStringField.frame = textRect; 53 63 } … … 66 76 } 67 77 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 68 self.frame = CGRectOffset(self.frame, 0, -( 48+kARTextFieldHeight));78 self.frame = CGRectOffset(self.frame, 0, -(52+kARTextFieldHeight)); 69 79 return YES; 70 80 } 71 81 - (void)textFieldDidEndEditing:(UITextField *)textField { 72 self.frame = CGRectOffset(self.frame, 0, 48+kARTextFieldHeight);82 self.frame = CGRectOffset(self.frame, 0, 52+kARTextFieldHeight); 73 83 } 74 84 @end -
apps/iphone/my.tel/trunk/Classes/MyTelConnect.h
r612 r672 11 11 #import "JSON/JSON.h" 12 12 #import "Profile.h" 13 #import "DnsResolver.h" 14 15 enum MyTelConnect_enum_status { 16 MYTELCONNECT_STATUS_NXAPIURL 17 }; 13 18 14 19 // Shorthand for getting localized strings … … 44 49 45 50 - (NSString *)topDomainFromDomain:(NSString *)aDomain; 51 - (NSString *)apiUrlForDomain:(NSString *)aDomain withError:(NSError **)error; 46 52 47 53 @property (nonatomic, retain) NSArray *profilesInDomain; -
apps/iphone/my.tel/trunk/Classes/MyTelConnect.m
r639 r672 103 103 } 104 104 105 - (NSString *)apiUrlForDomain:(NSString *)aDomain withError:(NSError **)error { 106 if (!aDomain) 107 return nil; 108 // try to autoprovision apiRootUrl 109 [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; 110 NSMutableArray *naptrArray = [NSMutableArray arrayWithCapacity:1]; 111 NSString *autoProvisionDomain = [@"_https._nsp._apps." stringByAppendingString:aDomain]; 112 DnsResolver *resolver =[[DnsResolver alloc] init]; 113 [resolver getNAPTRForTel:autoProvisionDomain inArray:naptrArray withError:error]; 114 if ([naptrArray count] == 0) { 115 // couldn't find anything, try in http mode 116 NSString *autoProvisionDomainHttp = [@"_http._nsp._apps." stringByAppendingString:aDomain]; 117 [resolver getNAPTRForTel:autoProvisionDomainHttp inArray:naptrArray withError:error]; 118 } 119 [resolver release]; 120 [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; 121 if ([naptrArray count] > 0) { 122 // we have autoprovision of the Telhosting URL, let's tweak it to get the JSON API 123 RecordNaptr *theRec = [naptrArray objectAtIndex:0]; 124 return ([theRec.uriContent stringByAppendingString:@"/g2/json"]); 125 } 126 // Still found nothing, no autoprovisioning possible 127 NSDictionary *dict = [NSDictionary dictionaryWithObject:@"Please verify that your domain name is correct" 128 forKey:NSLocalizedDescriptionKey]; 129 130 if (error != NULL) 131 *error = [NSError errorWithDomain:@"my.tel" code:MYTELCONNECT_STATUS_NXAPIURL userInfo:dict]; 132 return @""; 133 } 134 105 135 #pragma mark - 106 136 #pragma mark singleton object methods








