Remove more unnecessary code, refactor to make more readable, fix minor bugs, and improve business logic and memory use.
// The OpenStack project is provided under the Apache 2.0 license.
//
-#import <UIKit/UIKit.h>
-
@class Provider, RootViewController, OpenStackAccount, ActivityIndicatorView;
@interface AccountDetailsViewController : UITableViewController <UITextFieldDelegate> {
// interpreted as representing official policies, either expressed
// or implied, of GRNET S.A.
-#import <UIKit/UIKit.h>
-#import "OpenStackAccount.h"
-#import "ActivityIndicatorView.h"
+@class OpenStackAccount, ActivityIndicatorView;
@interface AccountGroupsViewController : UITableViewController {
OpenStackAccount *account;
// or implied, of GRNET S.A.
#import "AccountGroupsViewController.h"
+#import "OpenStackAccount.h"
+#import "ActivityIndicatorView.h"
#import "AccountManager.h"
#import "OpenStackRequest.h"
#import "EditAccountGroupsViewController.h"
#import "NSString+Conveniences.h"
#import "APICallback.h"
-
@implementation AccountGroupsViewController
@synthesize account, groups;
+#pragma mark - View lifecycle
-- (void)dealloc
-{
- [account release];
- [groups release];
- [metadata release];
- [activityIndicatorView release];
- [super dealloc];
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
+ return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
-
-#pragma mark - View lifecycle
-
-- (void)viewDidLoad
-{
- [super viewDidLoad];
+- (void)viewWillAppear:(BOOL)animated {
+ [super viewWillAppear:animated];
self.navigationItem.title = @"Groups";
groups = [[NSMutableDictionary alloc] init];
metadata = [[NSMutableDictionary alloc] init];
NSString *activityMessage = @"Loading..";
- [activityIndicatorView release];
activityIndicatorView = [[ActivityIndicatorView alloc] initWithFrame:[ActivityIndicatorView frameForText:activityMessage] text:activityMessage];
[activityIndicatorView addToView:self.view];
- [[self.account.manager getStorageAccountInfo]
+ [[self.account.manager getStorageAccountInfo]
success:^(OpenStackRequest *request) {
[activityIndicatorView removeFromSuperview];
for (NSString *key in request.responseHeaders) {
[metadata setObject:metadataValue forKey:metadataKey];
}
}
-
+
[self.tableView reloadData];
-
}
failure:^(OpenStackRequest *request) {
[activityIndicatorView removeFromSuperview];
}];
}
-- (void)viewDidUnload
-{
- [super viewDidUnload];
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
-}
-
-- (void)viewWillAppear:(BOOL)animated
-{
- [super viewWillAppear:animated];
- [self.tableView reloadData];
-}
-
-- (void)viewDidAppear:(BOOL)animated
-{
- [super viewDidAppear:animated];
-}
-
-- (void)viewWillDisappear:(BOOL)animated
-{
- [super viewWillDisappear:animated];
-}
-
-- (void)viewDidDisappear:(BOOL)animated
-{
- [super viewDidDisappear:animated];
-}
+#pragma mark - Memory management
-- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
- return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
+- (void)dealloc {
+ [account release];
+ [groups release];
+ [metadata release];
+ [activityIndicatorView release];
+ [super dealloc];
}
-#pragma mark - Table view data source
-
-- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
-{
- return 1;
-}
-
-- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-{
- return [groups count] + 1;
-}
+#pragma mark - Internal
- (CGFloat)findLabelHeight:(NSString*)text font:(UIFont *)font {
- CGSize textLabelSize;
+ CGSize textLabelSize;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// 616, 678
textLabelSize = CGSizeMake(596.0, 9000.0f);
return stringSize.height;
}
+#pragma mark - UITableViewDataSource
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ return [groups count] + 1;
+}
+
- (CGFloat)tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat result;
}
-- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-{
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.detailTextLabel.text = [groups objectForKey:groupName];
cell.detailTextLabel.numberOfLines = 0;
cell.detailTextLabel.lineBreakMode = UILineBreakModeCharacterWrap;
- }
- else {
+ } else {
cell.textLabel.text = @"Add Group";
cell.detailTextLabel.text = @"";
}
}
-#pragma mark - Table view delegate
+#pragma mark - UITableViewDelegate
-- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
-{
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
EditAccountGroupsViewController *vc = [[EditAccountGroupsViewController alloc] initWithNibName:@"EditAccountGroupsViewController" bundle:nil];
-
vc.account = self.account;
vc.metadata = metadata;
vc.groups = groups;
- if (indexPath.row < [groups count]) {
+ if (indexPath.row < [groups count]) {
NSString *groupName = [[groups allKeys] objectAtIndex:indexPath.row];
NSString *groupUsers = [groups objectForKey:groupName];
vc.groupName = groupName;
vc.groupUsers = groupUsers;
vc.navigationItem.title = @"Edit Group";
- }
- else {
+ } else {
vc.removeGroupEnabled = NO;
vc.groupName = @"";
vc.groupUsers = @"";
[vc release];
}
-
@end
@interface AccountHomeViewController : OpenStackViewController <UITableViewDelegate, UITableViewDataSource> {
OpenStackAccount *account;
RootViewController *rootViewController;
- NSArray *observers;
IBOutlet UITableView *tableView;
NSInteger refreshCount;
othersSharedRow = 1;
accountSettingsRow = 0;
accountMetadataRow = 1;
-
- id getContainersObserver = [[NSNotificationCenter defaultCenter]
- addObserverForName:@"getContainersSucceeded"
- object:self.account
- queue:[NSOperationQueue mainQueue]
- usingBlock:^(NSNotification *notification) {
- [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:storageRow inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
- [self incrementRefreshCount];
- }];
- id getContainersFailedObserver = [[NSNotificationCenter defaultCenter]
- addObserverForName:@"getContainersFailed"
- object:self.account
- queue:[NSOperationQueue mainQueue]
- usingBlock:^(NSNotification *notification) {
- [self incrementRefreshCount];
- }];
- id createContainerObserver = [[NSNotificationCenter defaultCenter]
- addObserverForName:@"createContainerSucceeded"
- object:self.account
- queue:[NSOperationQueue mainQueue]
- usingBlock:^(NSNotification *notification) {
- [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:storageRow inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
- }];
- id deleteContainerObserver = [[NSNotificationCenter defaultCenter]
- addObserverForName:@"deleteContainerSucceeded"
- object:self.account
- queue:[NSOperationQueue mainQueue]
- usingBlock:^(NSNotification *notification) {
- [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:storageRow inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
- }];
-
- observers = [[NSArray alloc] initWithObjects: getContainersObserver, getContainersFailedObserver, createContainerObserver, deleteContainerObserver, nil];
}
- (void)viewWillAppear:(BOOL)animated {
}
}
-- (void)viewDidUnload {
- for (id observer in observers) {
- [[NSNotificationCenter defaultCenter] removeObserver:observer];
- }
-
- [super viewDidUnload];
-}
-
#pragma mark - Memory management
- (void)dealloc {
[account release];
[rootViewController release];
- [observers release];
[tableView release];
[super dealloc];
}
-#pragma mark - Internal
-
-- (void)incrementRefreshCount {
- refreshCount++;
- self.account.hasBeenRefreshed = YES;
- [self hideToolbarActivityMessage];
-}
-
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
cell.textLabel.text = @"Account Token";
cell.imageView.image = [UIImage imageNamed:@"account-settings-icon.png"];
} else if (indexPath.row == accountMetadataRow) {
- cell.textLabel.text = @"Account Metadata";
+ cell.textLabel.text = @"Account Groups";
cell.imageView.image = [UIImage imageNamed:@"account-settings-icon.png"];
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
vc.account = account;
vc.accountHomeViewController = self;
[self.navigationController pushViewController:vc animated:YES];
- [vc refreshButtonPressed:nil];
[vc release];
}
} else if (indexPath.section == kShared) {
vc.account = account;
vc.accountHomeViewController = self;
[self.navigationController pushViewController:vc animated:YES];
- [vc refreshButtonPressed:nil];
- [vc release];
+ [vc release];
} else if (indexPath.row == othersSharedRow){
SharingAccountsViewController *vc = [[SharingAccountsViewController alloc] initWithNibName:@"SharingAccountsViewController" bundle:nil];
vc.account = account;
- (void)requestFinished:(OpenStackRequest *)request {
NSString *notificationName = [request.userInfo objectForKey:@"notificationName"];
- id notificationObject = [request.userInfo objectForKey:@"notificationObject"];
+ if (!notificationName)
+ return;
+ id notificationObject = [request.userInfo objectForKey:@"notificationObject"];
if ([request isSuccess]) {
NSNotification *notification = [NSNotification notificationWithName:[NSString stringWithFormat:@"%@Succeeded", notificationName] object:notificationObject];
[[NSNotificationCenter defaultCenter] postNotification:notification];
- (void)requestFailed:(OpenStackRequest *)request {
NSString *notificationName = [request.userInfo objectForKey:@"notificationName"];
+ if (!notificationName)
+ return;
+
id notificationObject = [request.userInfo objectForKey:@"notificationObject"];
NSNotification *notification = [NSNotification notificationWithName:[NSString stringWithFormat:@"%@Failed", notificationName] object:notificationObject userInfo:[NSDictionary dictionaryWithObject:request forKey:@"request"]];
[[NSNotificationCenter defaultCenter] postNotification:notification];
}
-- (void)sendRequest:(OpenStackRequest *)request name:(NSString *)name object:(id)notificationObject {
- request.delegate = self;
- request.userInfo = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:name, notificationObject, nil] forKeys:[NSArray arrayWithObjects:@"notificationName", @"notificationObject", nil]];
- [request startAsynchronous];
-}
-
- (void)notify:(NSString *)name request:(OpenStackRequest *)request {
NSNotification *notification = [NSNotification notificationWithName:name object:nil userInfo:[NSDictionary dictionaryWithObject:request forKey:@"request"]];
[[NSNotificationCenter defaultCenter] postNotification:notification];
// The OpenStack project is provided under the Apache 2.0 license.
//
-#import <UIKit/UIKit.h>
-#import "ActivityIndicatorView.h"
-
-@class OpenStackAccount;
+@class OpenStackAccount, ActivityIndicatorView;
@interface AccountSettingsViewController : UITableViewController <UITextFieldDelegate> {
UITextField *usernameTextField;
#import "AccountSettingsViewController.h"
#import "OpenStackAccount.h"
+#import "ActivityIndicatorView.h"
#import "Provider.h"
#import "RSTextFieldCell.h"
#import "UIColor+MoreColors.h"
// The OpenStack project is provided under the Apache 2.0 license.
//
-#import <UIKit/UIKit.h>
-
#define kFadeTime 0.25
#define kFontSize 14.0
#define kCornerRadius 7
#import <QuartzCore/QuartzCore.h>
#import "AnimatedProgressView.h"
-
@implementation ActivityIndicatorView
@synthesize progressView, spinner;
#import "AddPhotoViewController.h"
#import "UploadGenericFileViewController.h"
#import "AddTextFileViewController.h"
-
+#import <MobileCoreServices/MobileCoreServices.h>
@implementation AddFileViewController
popover = nil;
}
-
-/*
-- (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-}
-*/
-/*
-- (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
-}
-*/
-/*
-- (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
-}
-*/
-/*
-- (void)viewDidDisappear:(BOOL)animated {
- [super viewDidDisappear:animated];
-}
-*/
-/*
-// Override to allow orientations other than the default portrait orientation.
-- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // Return YES for supported orientations.
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
-}
-*/
-
-
#pragma mark -
#pragma mark Table view data source
} else if (indexPath.section == textFileSection) {
cell.textLabel.text = @"Text File";
+// NSString *emptyPath = [[NSBundle mainBundle] pathForResource:@"empty-file" ofType:@""];
+// UIDocumentInteractionController *udic = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:emptyPath]];
+// cell.imageView.image = [udic.icons objectAtIndex:0]; //[UIImage imageNamed:@"file-icon.png"];
+ CFStringRef mimeType = (CFStringRef)@"text/plain";
+ CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeType, NULL);
NSString *emptyPath = [[NSBundle mainBundle] pathForResource:@"empty-file" ofType:@""];
UIDocumentInteractionController *udic = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:emptyPath]];
- cell.imageView.image = [udic.icons objectAtIndex:0]; //[UIImage imageNamed:@"file-icon.png"];
+ if (((NSString *)uti).length > 0)
+ udic.UTI = (NSString *)uti;
+ if ([udic.icons count] > 0)
+ cell.imageView.image = [udic.icons objectAtIndex:0];
} else if (indexPath.section == audioSection) {
cell.textLabel.text = @"Record Audio";
cell.imageView.image = [UIImage imageNamed:@"audio-icon.png"];
#import "UIViewController+Conveniences.h"
#import "AddFolderViewController.h"
#import "AddFileViewController.h"
+#import <MobileCoreServices/MobileCoreServices.h>
#define kFolder 0
#define kFile 1
cell.imageView.image = [UIImage imageNamed:@"folder-icon.png"];
} else if (indexPath.section == kFile) {
cell.textLabel.text = @"Add a File";
+// NSString *emptyPath = [[NSBundle mainBundle] pathForResource:@"empty-file" ofType:@""];
+// UIDocumentInteractionController *udic = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:emptyPath]];
+// cell.imageView.image = [udic.icons objectAtIndex:0]; //[UIImage imageNamed:@"file-icon.png"];
+ CFStringRef mimeType = (CFStringRef)@"text/plain";
+ CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeType, NULL);
NSString *emptyPath = [[NSBundle mainBundle] pathForResource:@"empty-file" ofType:@""];
UIDocumentInteractionController *udic = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:emptyPath]];
- cell.imageView.image = [udic.icons objectAtIndex:0]; //[UIImage imageNamed:@"file-icon.png"];
+ if (((NSString *)uti).length > 0)
+ udic.UTI = (NSString *)uti;
+ if ([udic.icons count] > 0)
+ cell.imageView.image = [udic.icons objectAtIndex:0];
}
return cell;
// The OpenStack project is provided under the Apache 2.0 license.
//
-#import <Foundation/Foundation.h>
#import "ASIProgressDelegate.h"
-
@interface AnimatedProgressView : UIProgressView {
NSTimer *progressTimer;
CGFloat targetProgress;
// The OpenStack project is provided under the Apache 2.0 license.
//
-#import <Foundation/Foundation.h>
-
@class Folder;
@interface Container : NSObject <NSCoding> {
@property (nonatomic, assign) NSUInteger count;
@property (nonatomic, assign) unsigned long long bytes;
-//metadata
-@property (nonatomic, retain) NSMutableDictionary *metadata;
-
//policy
@property (nonatomic, retain) NSString *versioning;
@property (nonatomic) NSUInteger quota;
--(NSString *)humanizedSize;
+//metadata
+@property (nonatomic, retain) NSMutableDictionary *metadata;
+
+- (NSString *)humanizedSize;
- (NSString *)osxStyleHumanizedSize;
// CDN container attributes
#import "OpenStackViewController.h"
-@class OpenStackAccount;
-@class AccountHomeViewController;
-@class ContainerDetailViewController;
+@class OpenStackAccount, AccountHomeViewController, ContainerDetailViewController;
@interface ContainersViewController : OpenStackViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *tableView;
IBOutlet UIBarButtonItem *refreshButton;
- id getContainersSucceededObserver;
- id getContainersFailedObserver;
-
BOOL containersLoaded;
NSString *accountUsageInfo;
AccountHomeViewController *accountHomeViewController;
ContainerDetailViewController *containerDetailViewController;
-
}
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain) ContainerDetailViewController *containerDetailViewController;
- (void)refreshButtonPressed:(id)sender;
-- (NSString *)humanReadableSize:(unsigned long long)bytes;
-- (void)createContainerWithName:(NSString *)containerName;
@end
#import "Provider.h"
#import "AccountHomeViewController.h"
-
@implementation ContainersViewController
@synthesize tableView, account, accountUsageInfo, accountHomeViewController, containerDetailViewController;
-- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
- return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
-}
-
-#pragma mark -
-#pragma mark View lifecycle
+#pragma mark - View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"Containers";
[self addAddButton];
[self addHomeButton];
-
- if (!account.shared && !account.sharingAccount && containersLoaded) {
- if (![self.account.containers objectForKey:@"pithos"])
- [self createContainerWithName:@"pithos"];
- if (![self.account.containers objectForKey:@"trash"])
- [self createContainerWithName:@"trash"];
- }
-
}
- (void)viewWillAppear:(BOOL)animated {
}
}
- if (!containersLoaded && [self.account.containers count] == 0) {
- [self refreshButtonPressed:nil];
- }
+ [self refreshButtonPressed:nil];
+}
+
+#pragma mark - Memory management
+
+- (void)dealloc {
+ [accountUsageInfo release];
+ [tableView release];
+ [account release];
+ [containerDetailViewController release];
+ [super dealloc];
+}
+
+#pragma mark - Internal
+
+- (void)enableRefreshButton {
+ refreshButton.enabled = YES;
+ [self hideToolbarActivityMessage];
+ if (!account.sharingAccount)
+ [self showToolbarInfoMessage:accountUsageInfo];
}
-- (void)viewDidDisappear:(BOOL)animated {
- [super viewDidDisappear:animated];
+- (void)createContainerWithName:(NSString *)containerName {
+ [self hideToolbarInfoMessage];
+ [self showToolbarActivityMessage:@"Creating container..."];
+ Container *container = [[Container alloc] init];
+ container.name = containerName;
+ [[self.account.manager createContainer:container]
+ success:^(OpenStackRequest *request) {
+ [self hideToolbarActivityMessage];
+ if (!account.sharingAccount)
+ [self showToolbarInfoMessage:accountUsageInfo];
+ [self.tableView reloadData];
+ }
+ failure:^(OpenStackRequest *request) {
+ [self hideToolbarActivityMessage];
+ if (!account.sharingAccount)
+ [self showToolbarInfoMessage:accountUsageInfo];
+ [self alert:@"There was a problem creating your container." request:request];
+ }];
+ [container release];
}
-#pragma mark -
-#pragma mark Button Handlers
+#pragma mark - Button Handlers
- (void)addButtonPressed:(id)sender {
AddContainerViewController *vc = [[AddContainerViewController alloc] initWithNibName:@"AddContainerViewController" bundle:nil];
vc.containersViewController = self;
vc.account = account;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
- vc.modalPresentationStyle = UIModalPresentationFormSheet;
OpenStackAppDelegate *app = [[UIApplication sharedApplication] delegate];
- if (app.rootViewController.popoverController != nil) {
- [app.rootViewController.popoverController dismissPopoverAnimated:YES];
- }
- }
+ [app.rootViewController.popoverController dismissPopoverAnimated:YES];
+ }
[self presentModalViewControllerWithNavigation:vc];
[vc release];
}
[self.navigationController popToViewController:accountHomeViewController animated:YES];
}
-
-- (void)enableRefreshButton {
- refreshButton.enabled = YES;
- [self hideToolbarActivityMessage];
- if (!account.sharingAccount)
- [self showToolbarInfoMessage:accountUsageInfo];
-}
-
- (void)refreshButtonPressed:(id)sender {
refreshButton.enabled = NO;
- //BOOL hadZeroContainers = [self.account.containers count] == 0;
if (!account.sharingAccount)
[self hideToolbarInfoMessage];
[self showToolbarActivityMessage:@"Refreshing containers..."];
containersLoaded = YES;
[self enableRefreshButton];
[self.tableView reloadData];
- //GetCDNContainersRequest *cdnRequest = [GetCDNContainersRequest request:self.account];
- //[cdnRequest startAsynchronous];
-
+ if (!account.shared && !account.sharingAccount) {
+ if (![self.account.containers objectForKey:@"pithos"])
+ [self createContainerWithName:@"pithos"];
+ if (![self.account.containers objectForKey:@"trash"])
+ [self createContainerWithName:@"trash"];
+ }
} failure:^(OpenStackRequest *request) {
containersLoaded = NO;
[self enableRefreshButton];
}];
}
-#pragma mark -
-#pragma mark Table view data source
-
-- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
-}
+#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if ([self.account.containers count] == 0) {
return aTableView.rowHeight;
}
}
+
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (containersLoaded && [self.account.containers count] == 0) {
NSString *noContainersTitle = self.account.shared ? @"No shared containers" : @"No containers";
}
}
-#pragma mark -
-#pragma mark Table view delegate
+#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Container *container = nil;
[vc release];
}
-#pragma mark -
-#pragma mark Helper methods
-
-- (NSString *)humanReadableSize:(unsigned long long)bytes {
- NSString *sizeUnit = @"bytes";
-
- double sizeInBytes = bytes;
- if (bytes > 1023 && bytes < 1048576) {
- sizeInBytes = bytes / 1024.0;
- sizeUnit = @"Kb";
- }
- else if (bytes > 1048575 && bytes < 1073741824) {
- sizeInBytes = bytes / 1048576.0;
- sizeUnit = @"Mb";
- }
- else if (bytes > 1073741823) {
- sizeInBytes = bytes / 1073741824.0;
- sizeUnit = @"Gb";
- }
-
- NSString *humanReadableString = [NSString stringWithFormat:@"%.1f %@", sizeInBytes, sizeUnit];
- humanReadableString = [humanReadableString stringByReplacingOccurrencesOfString:@".0" withString:@""];
-
- return humanReadableString;
-}
-
-- (void)createContainerWithName:(NSString *)containerName {
- [self hideToolbarInfoMessage];
- [self showToolbarActivityMessage:@"Creating container..."];
- Container *container = [[Container alloc] init];
- container.name = containerName;
- [[self.account.manager createContainer:container]
- success:^(OpenStackRequest *request) {
- [self hideToolbarActivityMessage];
- if (!account.sharingAccount)
- [self showToolbarInfoMessage:accountUsageInfo];
- [self.tableView reloadData];
- }
- failure:^(OpenStackRequest *request) {
- [self hideToolbarActivityMessage];
- if (!account.sharingAccount)
- [self showToolbarInfoMessage:accountUsageInfo];
- [self alert:@"There was a problem creating your container." request:request];
- }];
- [container release];
-}
-
-
-#pragma mark -
-#pragma mark Memory management
-
-- (void)dealloc {
- [accountUsageInfo release];
- [tableView release];
- [account release];
- [containerDetailViewController release];
- [super dealloc];
-}
-
@end
// interpreted as representing official policies, either expressed
// or implied, of GRNET S.A.
-#import <UIKit/UIKit.h>
-#import "OpenStackAccount.h"
-#import "ActivityIndicatorView.h"
-
-
+@class OpenStackAccount, ActivityIndicatorView;
@interface EditAccountGroupsViewController : UITableViewController <UITextFieldDelegate> {
OpenStackAccount *account;
@property (nonatomic, retain) NSMutableDictionary *metadata;
@property (nonatomic) BOOL removeGroupEnabled;
-- (BOOL)userInputIsValid:(NSString *)input fieldName:(NSString *)fieldName;
-
@end
// or implied, of GRNET S.A.
#import "EditAccountGroupsViewController.h"
+#import "OpenStackAccount.h"
+#import "ActivityIndicatorView.h"
#import "UIViewController+Conveniences.h"
#import "AccountManager.h"
#import "OpenStackRequest.h"
@synthesize groupName, groupUsers, removeGroupEnabled;
@synthesize groups,metadata;
+#pragma mark - View lifecycle
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
+ return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+#pragma mark - Memory management
-- (void)dealloc
-{
+- (void)dealloc {
[groupName release];
[groupUsers release];
[account release];
[super dealloc];
}
+#pragma mark - Internal
-#pragma mark - View lifecycle
-
-- (void)viewDidLoad
-{
- [super viewDidLoad];
-}
-
-- (void)viewDidUnload
-{
- [super viewDidUnload];
-}
-
-- (void)viewWillAppear:(BOOL)animated
-{
- [super viewWillAppear:animated];
-}
-
-- (void)viewDidAppear:(BOOL)animated
-{
- [super viewDidAppear:animated];
-}
-
-- (void)viewWillDisappear:(BOOL)animated
-{
- [super viewWillDisappear:animated];
-}
-
-- (void)viewDidDisappear:(BOOL)animated
-{
- [super viewDidDisappear:animated];
-}
-
-- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
- return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
+- (BOOL)userInputIsValid:(NSString *)input fieldName:(NSString *)fieldName {
+ if (![input length] || ![[input stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]) {
+ [self alert:@"Invalid input" message:[NSString stringWithFormat:@"%@ field cannot be empty", fieldName]];
+ return NO;
+ }
+ NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"= "];
+ if ([input rangeOfCharacterFromSet:set].location != NSNotFound) {
+ [self alert:@"Invalid input" message:[NSString stringWithFormat:@"%@ field cannot contain '=' or whitespace characters", fieldName]];
+ return NO;
+ }
+ return YES;
}
-#pragma mark - Table view data source
+#pragma mark - UITableViewDataSource
-- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
-{
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (removeGroupEnabled)
return 3;
else
return 2;
}
-- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-{
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == kGroupDetails)
return 2;
else
return 1;
}
-- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-{
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
textField.placeholder = @"Group name";
textField.text = self.groupName;
textField.tag = 0;
- }
- else if (indexPath.row == 1) {
+ } else if (indexPath.row == 1) {
textField.returnKeyType = UIReturnKeyDefault;
textField.placeholder = @"Group users";
textField.text = self.groupUsers;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.contentView addSubview:textField];
- }
- else if (indexPath.section == kSave) {
+ } else if (indexPath.section == kSave) {
cell.textLabel.text = @"Save";
- }
- else if (indexPath.section == kRemove) {
+ } else if (indexPath.section == kRemove) {
cell.textLabel.text = @"Remove";
}
-
return cell;
}
-#pragma mark - Table view delegate
+#pragma mark - UITableViewDelegate
-- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
-{
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *activityMessage;
NSIndexPath *keyCellIndexPath;
NSIndexPath *valueCellIndexPath;
}
}
-#pragma mark - Textfield delegate
+#pragma mark - UITextFieldDelegate
-- (BOOL)textFieldShouldReturn:(UITextField *)textField
-{
-
- if ([textField returnKeyType] == UIReturnKeyNext)
- {
+- (BOOL)textFieldShouldReturn:(UITextField *)textField {
+ if ([textField returnKeyType] == UIReturnKeyNext) {
[self userInputIsValid:textField.text fieldName:@"Group name"];
NSInteger nextTag = [textField tag] + 1;
UIView *nextTextField = [self.tableView viewWithTag:nextTag];
[nextTextField becomeFirstResponder];
- }
- else
- {
+ } else {
[self userInputIsValid:textField.text fieldName:@"Group users"];
[textField resignFirstResponder];
}
return YES;
}
-#pragma mark - Helper methods
-
-- (BOOL)userInputIsValid:(NSString *)input fieldName:(NSString *)fieldName {
- if (![input length] || ![[input stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]) {
- [self alert:@"Invalid input" message:[NSString stringWithFormat:@"%@ field cannot be empty", fieldName]];
- return NO;
- }
- NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"= "];
- if ([input rangeOfCharacterFromSet:set].location != NSNotFound) {
- [self alert:@"Invalid input" message:[NSString stringWithFormat:@"%@ field cannot contain '=' or whitespace characters", fieldName]];
- return NO;
- }
-
- return YES;
-}
-
-
-
@end
// The OpenStack project is provided under the Apache 2.0 license.
//
-#import <Foundation/Foundation.h>
-
// there isn't really a folder resource in the API. this is an
// abstraction to simulate folders based on object names with
// slashes in them.
@interface Folder : NSObject <NSCoding> {
NSString *name;
Folder *parent;
- NSMutableDictionary *folders;
NSMutableDictionary *objects;
+ NSMutableDictionary *folders;
NSArray *sortedContents;
NSString *sharing;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) Folder *parent;
-@property (nonatomic, retain) NSMutableDictionary *folders;
@property (nonatomic, retain) NSMutableDictionary *objects;
+@property (nonatomic, retain) NSMutableDictionary *folders;
@property (readonly, retain) NSArray *sortedContents;
@property (nonatomic, retain) NSString *sharing;
@property (nonatomic, retain) NSMutableDictionary *metadata;
#import "NSObject+NSCoding.h"
#import "PithosUtilities.h"
-
@implementation Folder
-@synthesize name, parent, folders, objects, metadata, sharing, contentType;
-
-+ (id)folder {
- Folder *folder = [[[self alloc] init] autorelease];
- folder.folders = [[[NSMutableDictionary alloc] init] autorelease];
- folder.objects = [[[NSMutableDictionary alloc] init] autorelease];
- return folder;
-}
+@synthesize name, parent, objects, folders, sharing, metadata, contentType;
-#pragma mark -
-#pragma mark Serialization
+#pragma mark - Object lifecycle
- (id)init {
- if (self = [super init]) {
- self.folders = [[[NSMutableDictionary alloc] init] autorelease];
- self.objects = [[[NSMutableDictionary alloc] init] autorelease];
+ if ((self = [super init])) {
+ objects = [[NSMutableDictionary alloc] init];
+ folders = [[NSMutableDictionary alloc] init];
}
return self;
}
-- (void)encodeWithCoder:(NSCoder *)coder {
- [self autoEncodeWithCoder:coder];
- /*
- [coder encodeObject:name forKey:@"name"];
- [coder encodeObject:parent forKey:@"parent"];
- [coder encodeObject:folders forKey:@"folders"];
- [coder encodeObject:objects forKey:@"objects"];
- */
++ (id)folder {
+ return [[[self alloc] init] autorelease];
+}
+
+- (NSComparisonResult)compare:(Folder *)aFolder {
+ return [self.name caseInsensitiveCompare:aFolder.name];
}
+#pragma mark - Serialization
+
- (id)initWithCoder:(NSCoder *)coder {
- if (self = [super init]) {
+ if ((self = [super init])) {
[self autoDecode:coder];
- /*
- name = [[coder decodeObjectForKey:@"name"] retain];
- parent = [[coder decodeObjectForKey:@"parent"] retain];
- folders = [[coder decodeObjectForKey:@"folders"] retain];
- objects = [[coder decodeObjectForKey:@"objects"] retain];
- */
}
return self;
}
+- (void)encodeWithCoder:(NSCoder *)coder {
+ [self autoEncodeWithCoder:coder];
+}
+
+#pragma mark - Memory management
+
+-(void)dealloc {
+ [name release];
+ [parent release];
+ [folders release];
+ [sharing release];
+ [objects release];
+ [sortedContents release];
+ [contentType release];
+ [super dealloc];
+}
+
+#pragma mark - Properties
- (void)setObjects:(NSMutableDictionary *)objs {
- if (self.objects != objs) {
+ if (![objects isEqualToDictionary:objs]) {
[objects release];
- NSMutableDictionary *folderedFiles = [[NSMutableDictionary alloc] init];
- NSMutableDictionary *files = [[NSMutableDictionary alloc] init];
- folders = [[NSMutableDictionary alloc] init];
+ NSMutableDictionary *folderedFiles = [NSMutableDictionary dictionary];
+ NSMutableDictionary *files = [NSMutableDictionary dictionary];
+ self.folders = [[NSMutableDictionary alloc] init];
for (NSString *key in objs) {
StorageObject *object = [objs objectForKey:key];
object.name = [object.name substringToIndex:(object.name.length - 1)];
}
- NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"/" options:NSRegularExpressionCaseInsensitive error:nil];
- NSInteger matches = [regex numberOfMatchesInString:object.name options:0 range:NSMakeRange(0, [object.name length])];
-
- if (matches > 0) {
+ NSRange slashRange = [object.name rangeOfString:@"/"];
+ if (slashRange.location != NSNotFound) {
// build up the folder structure
- NSMutableArray *components = [NSMutableArray arrayWithArray:[object.name componentsSeparatedByString:@"/"]];
- NSString *folderName = [components objectAtIndex:0];
-
- object.name = [components lastObject];
+ NSString *folderName = [object.name substringToIndex:slashRange.location];
+ object.name = [object.name substringFromIndex:(slashRange.location + 1)];
if (objectHasTrailingSlash)
object.name = [object.name stringByAppendingString:@"/"];
- for (int i = [components count] - 2; i > 0; i--) {
- object.name = [NSString stringWithFormat:@"%@/%@", [components objectAtIndex:i], object.name];
- }
-
if (![folderedFiles objectForKey:folderName]) {
[folderedFiles setObject:[NSMutableDictionary dictionary] forKey:folderName];
}
NSMutableDictionary *folderFiles = [folderedFiles objectForKey:folderName];
[folderFiles setObject:object forKey:object.name];
} else if ([PithosUtilities isContentTypeDirectory:object.contentType]) {
- Folder *folder = [[Folder alloc] init];
+ Folder *folder = [Folder folder];
if (objectHasTrailingSlash)
- folder.name = [NSString stringWithFormat:@"%@/", object.name];
+ folder.name = [object.name stringByAppendingString:@"/"];
else
folder.name = object.name;
folder.parent = self;
folder.sharing = object.sharing;
folder.contentType = object.contentType;
[self.folders setObject:folder forKey:folder.name];
- [folder release];
} else {
// put the files in this folder
if (objectHasTrailingSlash)
}
// take the foldered files and recursively build the rest of the folder structure
- NSArray *keys = [folderedFiles allKeys];
- for (int i = 0; i < [keys count]; i++) {
- NSString *folderName = [keys objectAtIndex:i];
+ for (NSString *folderName in [folderedFiles allKeys]) {
NSMutableDictionary *folderFiles = [folderedFiles objectForKey:folderName];
- Folder *folder = [[Folder alloc] init];
+ Folder *folder = [Folder folder];
folder.name = folderName;
folder.parent = self;
folder.objects = folderFiles;
StorageObject *object = [objs objectForKey:folderName];
- if ([PithosUtilities isContentTypeDirectory:object.contentType]) {
+ if (object && [PithosUtilities isContentTypeDirectory:object.contentType]) {
folder.metadata = object.metadata;
folder.sharing = object.sharing;
folder.contentType = object.contentType;
folder.metadata = [NSMutableDictionary dictionary];
}
[self.folders setObject:folder forKey:folder.name];
- [folder release];
}
- [folderedFiles release];
- objects = files;
+ objects = [files retain];
+ [sortedContents release];
+ sortedContents = nil;
}
}
- (NSArray *)sortedContents {
- NSMutableArray *contents = [[NSMutableArray alloc] initWithArray:[self.folders allValues]];
-
- [contents addObjectsFromArray:[self.objects allValues]];
- if (!sortedContents || ![sortedContents isEqualToArray:contents]) {
+ if (!sortedContents) {
+ NSMutableArray *contents = [[NSMutableArray alloc] initWithArray:[self.folders allValues]];
+ [contents addObjectsFromArray:[self.objects allValues]];
sortedContents = [[NSArray alloc] initWithArray:[contents sortedArrayUsingSelector:@selector(compare:)]];
}
- [contents release];
return sortedContents;
}
-- (NSComparisonResult)compare:(Folder *)aFolder {
- return [self.name caseInsensitiveCompare:aFolder.name];
-}
+#pragma mark - Actions
- (NSString *)fullPath {
- NSString *result = self.name;
- if (parent) {
- result = [NSString stringWithFormat:@"%@/%@", [parent fullPath], self.name];
+ if (self.parent) {
+ return [[self.parent fullPath] stringByAppendingFormat:@"/%@", self.name];
+ } else if (self.name) {
+ return self.name;
+ } else {
+ return @"";
}
- if (!result) {
- result = @"";
- }
- return result;
-}
-
--(void)dealloc {
- [name release];
- [parent release];
- [folders release];
- [sharing release];
- [objects release];
- [sortedContents release];
- [contentType release];
- [super dealloc];
}
@end
// The OpenStack project is provided under the Apache 2.0 license.
//
-#import <UIKit/UIKit.h>
#import "OpenStackViewController.h"
@class OpenStackAccount, Container, Folder, ActivityIndicatorView, ContainersViewController, FolderDetailViewController, StorageObjectViewController;
@interface FolderViewController : OpenStackViewController <UITableViewDelegate, UITableViewDataSource, UIActionSheetDelegate> {
-
OpenStackAccount *account;
Container *container;
Folder *folder;
#import <MobileCoreServices/MobileCoreServices.h>
#import "ComputeModel.h"
-
@implementation FolderViewController
@synthesize account, container, folder, containersViewController, selectedContainerIndexPath, contentsLoaded, parentFolderViewController, selectedFolderIndexPath, tableView, needsRefreshing, folderHasBeenRemoved, refreshWhenAppeared, folderDetailVC, selectedObjectViewController, refreshButton;
-- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
- return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
-}
-
-#pragma mark -
-#pragma mark View lifecycle
+#pragma mark - View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
[self addAddButton];
[self addHomeButton];
-
- deleteActionSheet = [[UIActionSheet alloc] initWithTitle:@"Are you sure you want to delete this folder? This operation cannot be undone." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete Folder" otherButtonTitles:nil];
+ deleteActionSheet = [[UIActionSheet alloc] initWithTitle:@"Are you sure you want to delete this folder? This operation cannot be undone." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete Folder" otherButtonTitles:nil];
}
- (void)viewWillAppear:(BOOL)animated {
if (needsRefreshing)
self.parentFolderViewController.needsRefreshing = YES;
[self.navigationController popViewControllerAnimated:YES];
+ } else {
+ [self refreshButtonPressed:nil];
}
- else
+ } else if (self.needsRefreshing) {
+ self.parentFolderViewController.needsRefreshing = YES;
+ if (refreshWhenAppeared) {
[self refreshButtonPressed:nil];
- } else {
- if (self.needsRefreshing) {
- self.parentFolderViewController.needsRefreshing = YES;
- if (refreshWhenAppeared) {
- [self refreshButtonPressed:nil];
- refreshWhenAppeared = NO;
- }
- if (account.shared && ([folder.folders count] + [folder.objects count] == 0)) {
- [self.navigationController popViewControllerAnimated:YES];
- }
+ refreshWhenAppeared = NO;
+ }
+ if (account.shared && ([folder.folders count] + [folder.objects count] == 0)) {
+ [self.navigationController popViewControllerAnimated:YES];
}
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
- if (![self.navigationController.viewControllers containsObject:self]) {
- if (self.parentViewController && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
- [parentFolderViewController setDetailViewController];
- }
- if (!(folder.name && ![@"" isEqualToString:folder.name])) {
-// [self.containersViewController.tableView deselectRowAtIndexPath:self.selectedContainerIndexPath animated:YES];
+ if (![self.navigationController.viewControllers containsObject:self] &&
+ self.parentViewController &&
+ (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)) {
+ [parentFolderViewController setDetailViewController];
}
}
+#pragma mark - Memory management
+
+- (void)dealloc {
+ [account release];
+ [container release];
+ [folder release];
+ [containersViewController release];
+ [selectedContainerIndexPath release];
+ [deleteActionSheet release];
+ [parentFolderViewController release];
+ [selectedFolderIndexPath release];
+ [refreshButton release];
+ [super dealloc];
+}
+
+#pragma mark - Actions
+
- (void)setDetailViewController {
if ([self.folder isEqual:self.container.rootFolder]) {
ContainerDetailViewController *vc = [[ContainerDetailViewController alloc] initWithNibName:@"ContainerDetailViewController" bundle:nil];
self.containersViewController.containerDetailViewController = vc;
[vc release];
} else {
- FolderDetailViewController *folderDetailViewController = [[FolderDetailViewController alloc] initWithNibName:@"FolderDetailViewController" bundle:nil];
- folderDetailViewController.account = account;
- folderDetailViewController.container = container;
- folderDetailViewController.folder = self.folder;
- folderDetailViewController.folderViewController = self.parentFolderViewController;
- [self presentPrimaryViewController:folderDetailViewController];
- self.parentFolderViewController.folderDetailVC = folderDetailViewController;
- [folderDetailViewController release];
+ FolderDetailViewController *vc = [[FolderDetailViewController alloc] initWithNibName:@"FolderDetailViewController" bundle:nil];
+ vc.account = self.account;
+ vc.container = self.container;
+ vc.folder = self.folder;
+ vc.folderViewController = self.parentFolderViewController;
+ [self presentPrimaryViewController:vc];
+ self.parentFolderViewController.folderDetailVC = vc;
+ [vc release];
}
}
-
-- (void)reloadFolderViewControllers
-{
+- (void)reloadFolderViewControllers {
NSArray *viewControllers = [self.navigationController viewControllers];
int rootFolderControllerIndex = [viewControllers indexOfObject:self.containersViewController] + 1;
folderViewController.folder = [parentFolder.folders objectForKey:folderViewController.folder.name];
if (folderViewController.folder) {
[folderViewController.tableView reloadData];
- }
- else {
+ } else {
folderViewController.folderHasBeenRemoved = YES;
}
}
self.parentFolderViewController.needsRefreshing = YES;
}
[self.navigationController popViewControllerAnimated:YES];
- } else {
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && account.shared)
- [self setDetailViewController];
+ } else if ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) && account.shared) {
+ [self setDetailViewController];
}
}
-
-
-#pragma mark -
-#pragma mark Table view data source
-
-- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView {
- return 1;
-}
-
+#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
return MAX(contentsLoaded ? 1 : 0, [folder.objects count] + [folder.folders count]);
}
}
-
-// Customize the appearance of table view cells.
-
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([folder.objects count] + [folder.folders count] == 0) {
NSString *noFoldersTitle = (self.account.shared || self.account.sharingAccount) ?
}
}
-#pragma mark -
-#pragma mark Table view delegate
+#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([folder.objects count] + [folder.folders count] > 0) {
[vc release];
}
-#pragma mark -
-#pragma mark Buttons
+#pragma mark - Button Handlers
- (IBAction)homeButtonPressed:(id)sender {
[self.navigationController popToViewController:containersViewController.accountHomeViewController animated:YES];
[activityIndicatorView addToView:self.view];
[self.account.manager getObjects:self.container];
- successObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"getObjectsSucceeded" object:self.container
- queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* notification)
- {
- [activityIndicatorView removeFromSuperviewAndRelease];
- contentsLoaded = YES;
- [self.containersViewController refreshButtonPressed:nil];
- [self reloadFolderViewControllers];
- needsRefreshing = NO;
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
- if (self.selectedObjectViewController) {
- [self.selectedObjectViewController reloadMetadataSection];
- } else if ([self.folder isEqual:container.rootFolder]) {
- [containersViewController.containerDetailViewController reloadMetadataSection];
- } else if ([parentFolderViewController.folderDetailVC.navigationController.topViewController
- isEqual:parentFolderViewController.folderDetailVC]) {
- [parentFolderViewController.folderDetailVC reloadMetadataSection];
- }
- }
- [[NSNotificationCenter defaultCenter] removeObserver:successObserver];
- }];
-
- failureObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"getObjectsFailed" object:self.container
- queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* notification)
- {
- needsRefreshing = NO;
- [self.tableView reloadData];
- [activityIndicatorView removeFromSuperviewAndRelease];
- [self alert:@"Error" message:@"Failed to retrieve files from server"];
- [[NSNotificationCenter defaultCenter] removeObserver:failureObserver];
- }];
-
-
+ successObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"getObjectsSucceeded"
+ object:self.container
+ queue:[NSOperationQueue mainQueue]
+ usingBlock:^(NSNotification* notification)
+ {
+ [activityIndicatorView removeFromSuperviewAndRelease];
+ contentsLoaded = YES;
+ [self reloadFolderViewControllers];
+ needsRefreshing = NO;
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+ if (self.selectedObjectViewController) {
+ [self.selectedObjectViewController reloadMetadataSection];
+ } else if ([self.folder isEqual:container.rootFolder]) {
+ [containersViewController.containerDetailViewController reloadMetadataSection];
+ } else if ([parentFolderViewController.folderDetailVC.navigationController.topViewController
+ isEqual:parentFolderViewController.folderDetailVC]) {
+ [parentFolderViewController.folderDetailVC reloadMetadataSection];
+ }
+ }
+ [[NSNotificationCenter defaultCenter] removeObserver:successObserver];
+ }];
+ failureObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"getObjectsFailed"
+ object:self.container
+ queue:[NSOperationQueue mainQueue]
+ usingBlock:^(NSNotification* notification)
+ {
+ needsRefreshing = NO;
+ [self.tableView reloadData];
+ [activityIndicatorView removeFromSuperviewAndRelease];
+ [self alert:@"Error" message:@"Failed to retrieve files from server"];
+ [[NSNotificationCenter defaultCenter] removeObserver:failureObserver];
+ }];
}
- (void)addButtonPressed:(id)sender {
[deleteActionSheet showInView:appDelegate.masterNavigationController.view];
}
-#pragma mark -
-#pragma mark Action Sheet Delegate
+#pragma mark - UIActionSheetDelegate
- (void)deleteFolderRow {
[self.parentFolderViewController.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:selectedFolderIndexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
}
-#pragma mark -
-#pragma mark Memory management
-
-- (void)dealloc {
- [account release];
- [container release];
- [folder release];
- [containersViewController release];
- [selectedContainerIndexPath release];
- [deleteActionSheet release];
- [parentFolderViewController release];
- [selectedFolderIndexPath release];
- [refreshButton release];
- [super dealloc];
-}
-
-
@end
}
+ (id)filesRequest:(OpenStackAccount *)account method:(NSString *)method path:(NSString *)path {
- NSString *now = [[[NSDate date] description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@?format=json%@&now=%@",
+ NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@?format=json%@",
account.filesURL,
path,
- account.shared ? @"&shared=" : @"",
- now]];
+ account.shared ? @"&shared=" : @""]];
return [GetContainersRequest request:account method:method url:url];
}
}
+ (id)filesRequest:(OpenStackAccount *)account method:(NSString *)method path:(NSString *)path marker:(NSString *)marker {
- NSString *now = [[[NSDate date] description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
NSString *filesUrl;
NSString *urlString = [account.filesURL description];
if (account.sharingAccount) {
} else
filesUrl = urlString;
- NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@?format=json%@%@&now=%@",
+ NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@?format=json%@%@",
filesUrl,
path,
account.shared ? @"&shared=" : @"",
- marker ? [NSString stringWithFormat:@"&marker=%@", marker] : @"",
- now]];
+ marker ? [NSString stringWithFormat:@"&marker=%@", marker] : @""]];
return [GetObjectsRequest request:account method:method url:url];
}
// Created by Mike Mayo on 8/3/10.
//
-#import <Foundation/Foundation.h>
-
@interface NSObject (Conveniences)
+ (NSString *)stringWithUUID;
// The OpenStack project is provided under the Apache 2.0 license.
//
-#import <Foundation/Foundation.h>
-
@interface NSObject (NSCoding)
- (void)autoEncodeWithCoder:(NSCoder *)coder;
// The OpenStack project is provided under the Apache 2.0 license.
//
-#import <Foundation/Foundation.h>
-
-
@interface NSString (Conveniences)
- (BOOL)isURL;
#import "NSString+Conveniences.h"
-
@implementation NSString (Conveniences)
- (BOOL)isURL {
}
+ (id)filesRequest:(OpenStackAccount *)account method:(NSString *)method path:(NSString *)path {
- NSString *now = [[[NSDate date] description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
NSString *urlString = [account.filesURL description];
if (account.sharingAccount) {
NSRange authUserRange = [urlString rangeOfString:account.username];
urlString = [NSString stringWithFormat:@"%@%@", [urlString substringToIndex:authUserRange.location], account.sharingAccount];
}
- NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@?format=json%@&now=%@",
+ NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@?format=json%@",
urlString,
path,
- account.shared ? @"&shared=" : @"",
- now]];
+ account.shared ? @"&shared=" : @""]];
return [OpenStackRequest request:account method:method url:url];
}
// interpreted as representing official policies, either expressed
// or implied, of GRNET S.A.
-#import <UIKit/UIKit.h>
-
@interface PithosImageViewController : UIViewController {
}
// The OpenStack project is provided under the Apache 2.0 license.
//
-#import <UIKit/UIKit.h>
-
@class RootViewController;
@interface ProvidersViewController : UITableViewController {
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
-#import <UIKit/UIKit.h>
-
-
@interface RSTextFieldCell : UITableViewCell {
UITextField *textField;
UIModalPresentationStyle modalPresentationStyle;
#import "RSTextFieldCell.h"
#import "UIColor+MoreColors.h"
-
@implementation RSTextFieldCell
@synthesize textField, modalPresentationStyle, fixedTextLabel;
// The OpenStack project is provided under the Apache 2.0 license.
//
-#import <Foundation/Foundation.h>
-
-
@interface StorageObject : NSObject <NSCoding> {
NSString *name;
NSString *fullPath;
@property (nonatomic, retain) NSString *lastModifiedString;
@property (nonatomic, retain) NSMutableDictionary *metadata;
-- (NSString *)humanizedBytes;
+ (StorageObject *)fromJSON:(NSDictionary *)dict;
- (void)setPropertiesfromResponseHeaders:(NSDictionary *)headers;
-
+- (NSString *)humanizedBytes;
- (BOOL)isPlayableMedia;
@end
@synthesize name, fullPath, hash, bytes, contentType, lastModified, data, publicURI, sharing, metadata, iso8601DateString, lastModifiedString;
-#pragma mark -
-#pragma mark Serialization
-
-- (void)encodeWithCoder:(NSCoder *)coder {
- [self autoEncodeWithCoder:coder];
- /*
- [coder encodeObject:name forKey:@"name"];
- [coder encodeObject:fullPath forKey:@"fullPath"];
- [coder encodeObject:hash forKey:@"hash"];
- [coder encodeInt:bytes forKey:@"bytes"];
- [coder encodeObject:contentType forKey:@"contentType"];
- [coder encodeObject:lastModified forKey:@"lastModified"];
- // not persisting data to save space
- [coder encodeObject:metadata forKey:@"metadata"];
- */
-}
-
-- (id)initWithCoder:(NSCoder *)coder {
- self = [super init];
- if (self) {
- [self autoDecode:coder];
- /*
- name = [[coder decodeObjectForKey:@"name"] retain];
- fullPath = [[coder decodeObjectForKey:@"fullPath"] retain];
- hash = [[coder decodeObjectForKey:@"hash"] retain];
- bytes = [coder decodeIntForKey:@"bytes"];
- contentType = [[coder decodeObjectForKey:@"contentType"] retain];
- lastModified = [[coder decodeObjectForKey:@"lastModified"] retain];
- data = [[coder decodeObjectForKey:@"data"] retain];
- metadata = [[coder decodeObjectForKey:@"metadata"] retain];
- */
- }
- return self;
-}
-
-#pragma mark -
-#pragma mark JSON
+#pragma mark - Object lifecycle
+ (StorageObject *)fromJSON:(NSDictionary *)dict {
StorageObject *object = [[[StorageObject alloc] init] autorelease];
object.iso8601DateString = [dict objectForKey:@"last_modified"];
object.publicURI = [dict objectForKey:@"x_object_public"];
object.sharing = [dict objectForKey:@"x_object_sharing"];
- object.metadata = nil;
+ object.metadata = nil;
return object;
}
+- (NSComparisonResult)compare:(StorageObject *)anObject {
+ return [self.name caseInsensitiveCompare:anObject.name];
+}
+
+#pragma mark - Serialization
+
+- (id)initWithCoder:(NSCoder *)coder {
+ if ((self = [super init])) {
+ [self autoDecode:coder];
+ }
+ return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)coder {
+ [self autoEncodeWithCoder:coder];
+}
+
+#pragma mark - Memory Management
+
+-(void)dealloc {
+ [name release];
+ [fullPath release];
+ [hash release];
+ [contentType release];
+ [lastModified release];
+ [data release];
+ [metadata release];
+ [iso8601DateString release];
+ [lastModifiedString release];
+ [super dealloc];
+}
+
+#pragma mark - Properties
+
+- (NSString *)lastModifiedString {
+ if (!lastModifiedString) {
+ if (!self.lastModified && [self.iso8601DateString length])
+ self.lastModified = [ComputeModel dateFromString:self.iso8601DateString];
+ if (self.lastModified)
+ lastModifiedString = [[ComputeModel localDateDescriptionFromDate:self.lastModified] retain];
+ }
+ return lastModifiedString;
+}
+
+#pragma mark - Actions
+
- (void)setPropertiesfromResponseHeaders:(NSDictionary *)headers {
self.hash = [headers objectForKey:@"X-Object-Hash"];
self.bytes = [[headers objectForKey:@"Content-Length"] intValue];
}
}
-#pragma mark -
-#pragma mark Presentation
-
-(NSString *)humanizedBytes {
NSString *result;
if (self.bytes >= 1024000000) {
}
- (BOOL)isPlayableMedia {
-
// check file extension
NSString *extensionPattern = @"^.+\\.((mov)|(m4a)|(mp3)|(wav)|(aiff)|(aac)|(aif)|(aifc)|(amr)|(caf)|(m2a)|(m4p)|(mp4)|(mpv)|(3gp))$";
NSRegularExpression *extensionRegex = [NSRegularExpression regularExpressionWithPattern:extensionPattern options:NSRegularExpressionCaseInsensitive error:nil];
return matches > 0;
}
-- (NSComparisonResult)compare:(StorageObject *)anObject {
- return [self.name caseInsensitiveCompare:anObject.name];
-}
-
-#pragma mark -
-#pragma mark Properties
-
-- (NSString *)lastModifiedString {
- if (!lastModifiedString) {
- if (!self.lastModified && [self.iso8601DateString length])
- self.lastModified = [ComputeModel dateFromString:self.iso8601DateString];
- if (self.lastModified)
- lastModifiedString = [[ComputeModel localDateDescriptionFromDate:self.lastModified] retain];
- }
- return lastModifiedString;
-}
-
-#pragma mark -
-#pragma mark Memory Management
-
--(void)dealloc {
- [name release];
- [fullPath release];
- [hash release];
- [contentType release];
- [lastModified release];
- [data release];
- [metadata release];
- [iso8601DateString release];
- [lastModifiedString release];
- [super dealloc];
-}
-
@end
// The OpenStack project is provided under the Apache 2.0 license.
//
-#import <UIKit/UIKit.h>
-
-
@interface TextViewCell : UITableViewCell {
UITextView *textView;
}
#import "TextViewCell.h"
-
@implementation TextViewCell
@synthesize textView;
return self;
}
-
//- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
//
// [super setSelected:selected animated:animated];
// }
//}
-
- (void)dealloc {
[textView release];
[super dealloc];
// The OpenStack project is provided under the Apache 2.0 license.
//
-#import <Foundation/Foundation.h>
-
-
@interface UIColor (MoreColors)
+ (UIColor *)value1DetailTextLabelColor;
#import "UIColor+MoreColors.h"
-
@implementation UIColor (MoreColors)
+ (UIColor *)value1DetailTextLabelColor {
// Created by Mike Mayo on 7/21/10.
//
-#import <Foundation/Foundation.h>
-
@class OpenStackRequest;
@interface UIViewController (Conveniences) <UIAlertViewDelegate>
// The OpenStack project is provided under the Apache 2.0 license.
//
-#import <UIKit/UIKit.h>
-
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);