Added my shared/others shared functionality.
[pithos-ios] / Classes / AccountHomeViewController.m
index dd05438..2084889 100755 (executable)
 #import "Reachability.h"
 #import "Image.h"
 #import "AccountGroupsViewController.h"
+#import "SharingAccountsViewController.h"
+#import "PithosImageViewController.h"
 
+#define kObjectStorage 0 
+#define kShared 1
+#define kSettings 2
 
 @implementation AccountHomeViewController
 
@@ -48,8 +53,7 @@
 
 - (void)viewDidLoad {
     [super viewDidLoad];
-    
-    
+        
     Reachability *reachability = [Reachability reachabilityForInternetConnection];
     if ([reachability currentReachabilityStatus] == kNotReachable) {
         self.account.hasBeenRefreshed = YES;
         [self failOnBadConnection];
     }
     
+    mySharedRow = 0;
+    othersSharedRow = 1;
+    accountSettingsRow = 0;
+    accountMetadataRow = 1;
+    
     authRetryFailedObserver = [[NSNotificationCenter defaultCenter] addObserverForName:[self.account.manager notificationName:@"authRetryFailed" identifier:0] object:nil
                                                                                queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification)
     {
     [super viewWillAppear:animated];
     self.navigationItem.title = self.account.username;    
     
+    account.shared = NO;
+    account.sharingAccount = nil;
+
     totalRows = 0;
     computeRow = (self.account.serversURL && [self.account.serversURL host]) ? totalRows++ : -1;
     storageRow = (self.account.filesURL && [self.account.filesURL host]) ? totalRows++ : -1;
     //    limitsRow = -1;
     //}
     limitsRow = -1;
-    accountSettingsRow = totalRows++;
-    accountMetadataRow = totalRows++;
     [self.tableView reloadData];
+    
+    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+        PithosImageViewController *vc = [[PithosImageViewController alloc] initWithNibName:@"PithosImageViewController" bundle:nil];
+        [self.navigationController presentPrimaryViewController:vc];
+        [vc release];
+    }
 }
 
 - (void)viewDidAppear:(BOOL)animated {
 #pragma mark Table view data source
 
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
-    return 1;
+    return 3;
 }
 
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-    return totalRows;
+    if (section == kObjectStorage)
+        return totalRows;
+    else 
+        return 2;
 }
 
 - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     
     cell.imageView.image = nil;
     
-    if (indexPath.row == computeRow) {
-        cell.textLabel.text = [self.account.provider isRackspace] ? @"Cloud Servers" : @"Compute";
-        cell.imageView.image = [self.account.provider isRackspace] ? [UIImage imageNamed:kCloudServersIcon] : [UIImage imageNamed:@"openstack-icon.png"];
-        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-    } else if (indexPath.row == storageRow) {
-        cell.textLabel.text = [self.account.provider isRackspace] ? @"Cloud Files" : @"Object Storage";
-        cell.imageView.image = [self.account.provider isRackspace] ? [UIImage imageNamed:@"cloud-files-icon.png"] : [UIImage imageNamed:@"pithos-solo-smallest.png"];
-    } else if (indexPath.row == loadBalancingRow) {
-        cell.textLabel.text = @"Load Balancers";
-        cell.imageView.image = [UIImage imageNamed:@"load-balancers-icon.png"];
-        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-    } else if (indexPath.row == rssFeedsRow) {
-        cell.textLabel.text = @"System Status";
-        cell.imageView.image = [UIImage imageNamed:@"rss-feeds-icon.png"];
-    } else if (indexPath.row == contactRow) {
-        cell.textLabel.text = @"Fanatical Support"; // @"Contact Information";
-        cell.imageView.image = [UIImage imageNamed:@"contact-rackspace-icon.png"];
-        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
-            cell.accessoryType = UITableViewCellAccessoryNone;
-        } else {
+    if (indexPath.section == kObjectStorage) {
+        if (indexPath.row == computeRow) {
+            cell.textLabel.text = [self.account.provider isRackspace] ? @"Cloud Servers" : @"Compute";
+            cell.imageView.image = [self.account.provider isRackspace] ? [UIImage imageNamed:kCloudServersIcon] : [UIImage imageNamed:@"openstack-icon.png"];
             cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-        }
+        } else if (indexPath.row == storageRow) {
+            cell.textLabel.text = [self.account.provider isRackspace] ? @"Cloud Files" : @"Object Storage";
+            cell.imageView.image = [self.account.provider isRackspace] ? [UIImage imageNamed:@"cloud-files-icon.png"] : [UIImage imageNamed:@"pithos-solo-smallest.png"];
+        } else if (indexPath.row == loadBalancingRow) {
+            cell.textLabel.text = @"Load Balancers";
+            cell.imageView.image = [UIImage imageNamed:@"load-balancers-icon.png"];
+            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
+        } else if (indexPath.row == rssFeedsRow) {
+            cell.textLabel.text = @"System Status";
+            cell.imageView.image = [UIImage imageNamed:@"rss-feeds-icon.png"];
+        } else if (indexPath.row == contactRow) {
+            cell.textLabel.text = @"Fanatical Support"; // @"Contact Information";
+            cell.imageView.image = [UIImage imageNamed:@"contact-rackspace-icon.png"];
+            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+                cell.accessoryType = UITableViewCellAccessoryNone;
+            } else {
+                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
+            }
 //    } else if (indexPath.row == kAPILogs) {
 //        cell.textLabel.text = @"API Logs";
-    } else if (indexPath.row == limitsRow) {
-        cell.textLabel.text = @"API Rate Limits";
-        cell.imageView.image = [UIImage imageNamed:@"api-rate-limits-icon.png"];
-        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
-            cell.accessoryType = UITableViewCellAccessoryNone;
-        } else {
-            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
+        } else if (indexPath.row == limitsRow) {
+            cell.textLabel.text = @"API Rate Limits";
+            cell.imageView.image = [UIImage imageNamed:@"api-rate-limits-icon.png"];
+            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+                cell.accessoryType = UITableViewCellAccessoryNone;
+            } else {
+                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
+            }
         }
-    } else if (indexPath.row == accountSettingsRow) {
-        cell.textLabel.text = @"Account Token";
-        cell.imageView.image = [UIImage imageNamed:@"account-settings-icon.png"];
-        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
-            cell.accessoryType = UITableViewCellAccessoryNone;
-        } else {
+    } else if (indexPath.section == kShared) {
+        if (indexPath.row == mySharedRow) {
+            cell.textLabel.text = @" My Shared";
+            cell.imageView.image = [UIImage imageNamed:@"myShared.png"];
             cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-        }
-    } else if (indexPath.row == accountMetadataRow) {
-        cell.textLabel.text = @"Account Metadata";
-        cell.imageView.image = [UIImage imageNamed:@"account-settings-icon.png"];
-        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
-            cell.accessoryType = UITableViewCellAccessoryNone;
-        } else {
+        } else if (indexPath.row == othersSharedRow) {
+            cell.textLabel.text = @"Others Shared";
+            cell.imageView.image = [UIImage imageNamed:@"othersShared.png"];
             cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
         }
-        
+    } else if (indexPath.section == kSettings) {
+        if (indexPath.row == accountSettingsRow) {
+            cell.textLabel.text = @"Account Token";
+            cell.imageView.image = [UIImage imageNamed:@"account-settings-icon.png"];
+            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+                cell.accessoryType = UITableViewCellAccessoryNone;
+            } else {
+                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
+            }
+        } else if (indexPath.row == accountMetadataRow) {
+            cell.textLabel.text = @"Account Metadata";
+            cell.imageView.image = [UIImage imageNamed:@"account-settings-icon.png"];
+            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+                cell.accessoryType = UITableViewCellAccessoryNone;
+            } else {
+                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
+            }
+        }
     }
     
     return cell;
     
     OpenStackAppDelegate *app = [[UIApplication sharedApplication] delegate];
     BOOL shouldHidePopover = NO;
-    if (indexPath.row == computeRow) {
-        ServersViewController *vc = [[ServersViewController alloc] initWithNibName:@"ServersViewController" bundle:nil];
-        vc.account = account;
-        vc.accountHomeViewController = self;
-        vc.comingFromAccountHome = YES;
-        [self.navigationController pushViewController:vc animated:YES];
-        [vc release];
-    } else if (indexPath.row == storageRow) {
-        ContainersViewController *vc = [[ContainersViewController alloc] initWithNibName:@"ContainersViewController" bundle:nil];
-        vc.account = account;
-        [self.navigationController pushViewController:vc animated:YES];
-        [vc refreshButtonPressed:nil];
-        [vc release];
-    } else if (indexPath.row == rssFeedsRow) {
-        RSSFeedsViewController *vc = [[RSSFeedsViewController alloc] initWithNibName:@"RSSFeedsViewController" bundle:nil];
-        vc.account = account;
-        vc.comingFromAccountHome = YES;
-        [self.navigationController pushViewController:vc animated:YES];
-        [vc release];
-    } else if (indexPath.row == contactRow) {
-        NSString *nibName = @"ContactInformationViewController";
-        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
-            nibName = @"ContactInformationViewController-iPad";
-        }
-        ContactInformationViewController *vc = [[ContactInformationViewController alloc] initWithNibName:nibName bundle:nil];
-        vc.provider = account.provider;
-        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
-            [self.navigationController presentPrimaryViewController:vc];
-            shouldHidePopover = YES;
-        } else {
+    
+    if (indexPath.section == kObjectStorage) {
+        if (indexPath.row == computeRow) {
+            ServersViewController *vc = [[ServersViewController alloc] initWithNibName:@"ServersViewController" bundle:nil];
+            vc.account = account;
+            vc.accountHomeViewController = self;
+            vc.comingFromAccountHome = YES;
             [self.navigationController pushViewController:vc animated:YES];
-        }
-        [vc release];
-//    } else if (indexPath.row == kAPILogs) {
-//        APILogsViewController *vc = [[APILogsViewController alloc] initWithNibName:@"APILogsViewController" bundle:nil];
-//        vc.account = account;
-//        [self.navigationController pushViewController:vc animated:YES];
-//        [vc release];
-    } else if (indexPath.row == limitsRow) {
-        LimitsViewController *vc = [[LimitsViewController alloc] initWithNibName:@"LimitsViewController" bundle:nil];
-        vc.account = account;
-        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
-            [self.navigationController presentPrimaryViewController:vc];
-            shouldHidePopover = YES;
-        } else {
+            [vc release];
+        } else if (indexPath.row == storageRow) {
+            ContainersViewController *vc = [[ContainersViewController alloc] initWithNibName:@"ContainersViewController" bundle:nil];
+            account.shared = NO;
+            vc.account = account;
+            vc.accountHomeViewController = self;
             [self.navigationController pushViewController:vc animated:YES];
-        }
-        [vc release];
-    } else if (indexPath.row == accountSettingsRow) {
-        AccountSettingsViewController *vc = [[AccountSettingsViewController alloc] initWithNibName:@"AccountSettingsViewController" bundle:nil];
-        vc.account = account;
-        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
-            [self.navigationController presentPrimaryViewController:vc];
-            shouldHidePopover = YES;
-        } else {
+            [vc refreshButtonPressed:nil];
+            [vc release];
+        } else if (indexPath.row == loadBalancingRow) {
+            LoadBalancersViewController *vc = [[LoadBalancersViewController alloc] initWithNibName:@"LoadBalancersViewController" bundle:nil];
+            vc.account = account;
             [self.navigationController pushViewController:vc animated:YES];
+            [vc release];
+        } else if (indexPath.row == rssFeedsRow) {
+            RSSFeedsViewController *vc = [[RSSFeedsViewController alloc] initWithNibName:@"RSSFeedsViewController" bundle:nil];
+            vc.account = account;
+            vc.comingFromAccountHome = YES;
+            [self.navigationController pushViewController:vc animated:YES];
+            [vc release];
+        } else if (indexPath.row == contactRow) {
+            NSString *nibName = @"ContactInformationViewController";
+            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+                nibName = @"ContactInformationViewController-iPad";
+            }
+            ContactInformationViewController *vc = [[ContactInformationViewController alloc] initWithNibName:nibName bundle:nil];
+            vc.provider = account.provider;
+            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+                [self.navigationController presentPrimaryViewController:vc];
+                shouldHidePopover = YES;
+            } else {
+                [self.navigationController pushViewController:vc animated:YES];
+            }
+            [vc release];
+//      } else if (indexPath.row == kAPILogs) {
+//          APILogsViewController *vc = [[APILogsViewController alloc] initWithNibName:@"   APILogsViewController" bundle:nil];
+//          vc.account = account;
+//          [self.navigationController pushViewController:vc animated:YES];
+//          [vc release];
+        } else if (indexPath.row == limitsRow) {
+            LimitsViewController *vc = [[LimitsViewController alloc] initWithNibName:@"LimitsViewController" bundle:nil];
+            vc.account = account;
+            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+                [self.navigationController presentPrimaryViewController:vc];
+                shouldHidePopover = YES;
+            } else {
+                [self.navigationController pushViewController:vc animated:YES];
+            }
+            [vc release];
         }
-        [vc release];
-    } else if (indexPath.row == accountMetadataRow) {
-        AccountGroupsViewController *vc = [[AccountGroupsViewController alloc] initWithNibName:@"AccountGroupsViewController" bundle:nil];
-        vc.account = self.account;
-        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
-            [self.navigationController presentPrimaryViewController:vc];
-            shouldHidePopover = YES;
-        } else {
+    } else if (indexPath.section == kShared) {
+        if (indexPath.row == mySharedRow) {
+            ContainersViewController *vc = [[ContainersViewController alloc] initWithNibName:@"ContainersViewController" bundle:nil];
+            account.shared = YES;
+            vc.account = account;
+            vc.accountHomeViewController = self;
             [self.navigationController pushViewController:vc animated:YES];
+            [vc refreshButtonPressed:nil];
+            [vc release];    
+        } else if (indexPath.row == othersSharedRow){
+            SharingAccountsViewController *vc = [[SharingAccountsViewController alloc] initWithNibName:@"SharingAccountsViewController" bundle:nil];
+            vc.account = account;
+            vc.accountHomeViewController = self;
+            [self.navigationController pushViewController:vc animated:YES];
+            [vc release];
+        }
+    } else if (indexPath.section == kSettings) {
+        if (indexPath.row == accountSettingsRow) {
+            AccountSettingsViewController *vc = [[AccountSettingsViewController alloc] initWithNibName:@"AccountSettingsViewController" bundle:nil];
+            vc.account = account;
+            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+                [self.navigationController presentPrimaryViewController:vc];
+                shouldHidePopover = YES;
+            } else {
+                [self.navigationController pushViewController:vc animated:YES];
+            }
+            [vc release];
+        } else if (indexPath.row == accountMetadataRow) {
+            AccountGroupsViewController *vc = [[AccountGroupsViewController alloc] initWithNibName:@"AccountGroupsViewController" bundle:nil];
+            vc.account = self.account;
+            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+                [self.navigationController presentPrimaryViewController:vc];
+                shouldHidePopover = YES;
+            } else {
+                [self.navigationController pushViewController:vc animated:YES];
+            }
+            [vc release];
         }
-        [vc release];
-    } else if (indexPath.row == loadBalancingRow) {
-        LoadBalancersViewController *vc = [[LoadBalancersViewController alloc] initWithNibName:@"LoadBalancersViewController" bundle:nil];
-        vc.account = account;
-        [self.navigationController pushViewController:vc animated:YES];
-        [vc release];
     }
     
     if (shouldHidePopover) {