// // AccountHomeViewController.m // OpenStack // // Created by Mike Mayo on 10/7/10. // The OpenStack project is provided under the Apache 2.0 license. // #import "AccountHomeViewController.h" #import "OpenStackAccount.h" #import "Provider.h" #import "NSObject+Conveniences.h" #import "RootViewController.h" #import "Container.h" #import "ContainersViewController.h" #import "AccountManager.h" #import "AccountSettingsViewController.h" #import "UIViewController+Conveniences.h" #import "Keychain.h" #import "OpenStackAppDelegate.h" #import "Reachability.h" #import "AccountGroupsViewController.h" #import "SharingAccountsViewController.h" #import "PithosImageViewController.h" #define kObjectStorage 0 #define kShared 1 #define kSettings 2 @implementation AccountHomeViewController @synthesize account, rootViewController, tableView; #pragma mark - View lifecycle - (void)viewDidLoad { [super viewDidLoad]; Reachability *reachability = [Reachability reachabilityForInternetConnection]; if ([reachability currentReachabilityStatus] == kNotReachable) { self.account.hasBeenRefreshed = YES; [self failOnBadConnection]; } storageRow = 0; mySharedRow = 0; othersSharedRow = 1; accountSettingsRow = 0; accountMetadataRow = 1; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.navigationItem.title = self.account.username; account.shared = NO; account.sharingAccount = nil; [self.tableView reloadData]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { PithosImageViewController *vc = [[PithosImageViewController alloc] initWithNibName:@"PithosImageViewController" bundle:nil]; [self presentPrimaryViewController:vc]; [vc release]; } } #pragma mark - Memory management - (void)dealloc { [account release]; [rootViewController release]; [tableView release]; [super dealloc]; } #pragma mark - UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 3; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == kObjectStorage) { return 1; } else { return 2; } } - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } cell.imageView.image = nil; if (indexPath.section == kObjectStorage) { if (indexPath.row == storageRow) { cell.textLabel.text = @"Object Storage"; cell.imageView.image = [UIImage imageNamed:@"pithos-solo-smallest.png"]; } } else if (indexPath.section == kShared) { if (indexPath.row == mySharedRow) { cell.textLabel.text = @" Shared By Me"; cell.imageView.image = [UIImage imageNamed:@"myShared.png"]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } else if (indexPath.row == othersSharedRow) { cell.textLabel.text = @"Shared To Me"; 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"]; } else if (indexPath.row == accountMetadataRow) { cell.textLabel.text = @"Account Groups"; cell.imageView.image = [UIImage imageNamed:@"account-settings-icon.png"]; } if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { cell.accessoryType = UITableViewCellAccessoryNone; } else { cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } } return cell; } #pragma mark - UITableViewDelegate - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { BOOL shouldHidePopover = NO; if (indexPath.section == kObjectStorage) { 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.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 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; [self presentPrimaryViewController:vc]; shouldHidePopover = YES; [vc release]; } else if (indexPath.row == accountMetadataRow) { AccountGroupsViewController *vc = [[AccountGroupsViewController alloc] initWithNibName:@"AccountGroupsViewController" bundle:nil]; vc.account = self.account; [self presentPrimaryViewController:vc]; shouldHidePopover = YES; [vc release]; } } if (shouldHidePopover && (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)) { OpenStackAppDelegate *app = [[UIApplication sharedApplication] delegate]; [app.rootViewController.popoverController dismissPopoverAnimated:YES]; } } @end