Fix bugs. Show version in settings. Update icons. Update version.
[pithos-ios] / Classes / AccountSettingsViewController.m
index 59d3c83..c793374 100755 (executable)
 - (void)authenticationSucceded:(OpenStackRequest *)request {
     
     [self.activityIndicatorView removeFromSuperview];
-    
+
     if ([request isSuccess]) {        
         account.authToken = [[request responseHeaders] objectForKey:@"X-Auth-Token"];
         account.serversURL = [NSURL URLWithString:[[request responseHeaders] objectForKey:@"X-Server-Management-Url"]];
         
-        if (![[request responseHeaders] objectForKey:@"X-Storage-URL"] && [account.provider isGRNet]) {
-            NSString *filesStorageURL = [NSString stringWithFormat:@"%@%@",
-                                         [[[NSBundle mainBundle] infoDictionary] objectForKey:@"GRNetStorageUrlPrefix"],
-                                         [self.account username]];
-            account.filesURL = [NSURL URLWithString:filesStorageURL];        
-        } else {
+        NSString *filesStorageURL;
+        if (![[request responseHeaders] objectForKey:@"X-Storage-URL"]) {
+            filesStorageURL = [NSString stringWithFormat:@"%@/v1/%@",
+                               [account.hostURL absoluteString],
+                               [account username]];
+            account.filesURL = [NSURL URLWithString:filesStorageURL];
+        }
+        else {
             account.filesURL = [NSURL URLWithString:[[request responseHeaders] objectForKey:@"X-Storage-Url"]];
-               }
+        }
+        
+        account.pithosPublicLinkURLPrefix = account.hostURL;
+        account.pithosLoginURLPrefix = [NSURL URLWithString:
+                                        [[account.hostURL absoluteString]
+                                         stringByAppendingString:@"/login"]];
 
         NSString *cdnStr = [[request responseHeaders] objectForKey:@"X-Cdn-Management-Url"];
         if (!cdnStr) {
@@ -65,6 +72,7 @@
 - (void)authenticationFailed:(OpenStackRequest *)request {
     [self.activityIndicatorView removeFromSuperview];
     self.navigationItem.rightBarButtonItem.enabled = YES;
+    self.account.containers = nil;
     if ([request responseStatusCode] == 401) {
         [self alert:@"Authentication Failure" message:@"Please check your User Name and Token."];
     } else {
     [super viewDidLoad];
     self.navigationItem.title = @"API Account Info";
     userDetailsSection = 0;
-    if ([self.account.provider isGRNet])
-        getTokenSection = 1;
-    else
-        getTokenSection = -1;
+    getTokenSection = 1;
     
-    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+    /*if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
         UIView *backgroundContainer = [[UIView alloc] init];
         backgroundContainer.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
         backgroundContainer.backgroundColor = [UIColor iPadTableBackgroundColor];
         [osLogo release];
         self.tableView.backgroundView = backgroundContainer;
         [backgroundContainer release];
-    }    
+    }   */ 
     
     [self addSaveButton];
 }
 
+
 - (void)viewDidAppear:(BOOL)animated {
-    [super viewDidAppear:animated];
+    [super viewDidAppear:animated];    
     //[usernameTextField becomeFirstResponder];
 }
 
 #pragma mark - Table view data source
 
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
-    if (getTokenSection > 0)
-        return 2;
-    else
-        return 1;
+    return 2;
 }
 
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     } else {
         cell = (RSTextFieldCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
         if (cell == nil) {
-            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
+            cell = [[[RSTextFieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
         }
         
         cell.textLabel.text = @"Get Token";
     }
-    
     return cell;
 }
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     if (indexPath.section == getTokenSection) {
-        NSProcessInfo *processInfo = [NSProcessInfo processInfo];
-        NSString *loginURL = [NSString stringWithFormat:@"%@?next=pithos://%@", 
-                              ((OpenStackAppDelegate *)[[UIApplication sharedApplication] delegate]).loginURLPrefix,
-                              [processInfo processName]]; 
-        
+        NSString *loginURL = [NSString stringWithFormat:@"%@?next=pithos://login&force=", account.pithosLoginURLPrefix];         
         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:loginURL]];
         [tableView deselectRowAtIndexPath:indexPath animated:NO];
     }