Statistics
| Branch: | Tag: | Revision:

root / Classes / FolderDetailViewController.m @ 38d59b6c

History | View | Annotate | Download (7.3 kB)

1
//
2
//  FolderDetailViewController.m
3
//  pithos-ios
4
//
5
// Copyright 2011 GRNET S.A. All rights reserved.
6
//
7
// Redistribution and use in source and binary forms, with or
8
// without modification, are permitted provided that the following
9
// conditions are met:
10
// 
11
//   1. Redistributions of source code must retain the above
12
//      copyright notice, this list of conditions and the following
13
//      disclaimer.
14
// 
15
//   2. Redistributions in binary form must reproduce the above
16
//      copyright notice, this list of conditions and the following
17
//      disclaimer in the documentation and/or other materials
18
//      provided with the distribution.
19
// 
20
// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
21
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
24
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
// POSSIBILITY OF SUCH DAMAGE.
32
// 
33
// The views and conclusions contained in the software and
34
// documentation are those of the authors and should not be
35
// interpreted as representing official policies, either expressed
36
// or implied, of GRNET S.A.
37

    
38
#import "FolderDetailViewController.h"
39
#import "EditMetadataViewController.h"
40

    
41
#define kOverview 0
42
#define kMetadata 1
43

    
44
#define maxMetadataViewableLength 12
45

    
46

    
47
@implementation FolderDetailViewController
48

    
49
@synthesize account, container, folder;
50

    
51
- (id)initWithStyle:(UITableViewStyle)style
52
{
53
    self = [super initWithStyle:style];
54
    if (self) {
55
        // Custom initialization
56
    }
57
    return self;
58
}
59

    
60
- (void)dealloc
61
{
62
    [folder release];
63
    [super dealloc];
64
}
65

    
66
- (void)didReceiveMemoryWarning
67
{
68
    // Releases the view if it doesn't have a superview.
69
    [super didReceiveMemoryWarning];
70
    
71
    // Release any cached data, images, etc that aren't in use.
72
}
73

    
74
#pragma mark - View lifecycle
75

    
76
- (void)viewDidLoad
77
{
78
    [super viewDidLoad];
79
}
80

    
81
- (void)viewDidUnload
82
{
83
    [super viewDidUnload];
84
}
85

    
86
- (void)viewWillAppear:(BOOL)animated
87
{
88
    [super viewWillAppear:animated];
89
    
90
    [self.tableView reloadData];
91
}
92

    
93
- (void)viewDidAppear:(BOOL)animated
94
{
95
    [super viewDidAppear:animated];
96
}
97

    
98
- (void)viewWillDisappear:(BOOL)animated
99
{
100
    [super viewWillDisappear:animated];
101
}
102

    
103
- (void)viewDidDisappear:(BOOL)animated
104
{
105
    [super viewDidDisappear:animated];
106
}
107

    
108
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
109
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
110
}
111

    
112
#pragma mark - Table view data source
113

    
114
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
115
{
116
    return 2;
117
}
118

    
119
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
120
{
121
    if (section == kOverview)
122
        return 2;
123
    else 
124
        return 1 + [folder.metadata count];
125
}
126

    
127
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
128
{
129
    static NSString *CellIdentifier = @"Cell";
130
    
131
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
132
    if (cell == nil) {
133
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
134

    
135
        cell.textLabel.backgroundColor = [UIColor clearColor];
136
        cell.detailTextLabel.backgroundColor = [UIColor clearColor];
137
        cell.detailTextLabel.numberOfLines = 0;
138
        cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
139
        cell.detailTextLabel.textAlignment = UITextAlignmentRight;
140
    }
141
    
142
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
143
        cell.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.8];
144
    }
145
    
146
    if (indexPath.section == kOverview) {
147
        cell.accessoryType = UITableViewCellAccessoryNone;
148
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
149
        cell.accessoryView = nil;
150
        if (indexPath.row == 0) {
151
            cell.textLabel.text = @"Name";
152
            cell.detailTextLabel.text = folder.name;
153
        } else if (indexPath.row == 1) {
154
            cell.textLabel.text = @"Full Path";
155
            cell.detailTextLabel.text = [folder fullPath];
156
        }
157
    } else if (indexPath.section == kMetadata) {
158
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
159
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
160
        cell.accessoryView = nil;
161
        if (indexPath.row == [folder.metadata count]) {
162
            cell.textLabel.text = @"Add Metadata";
163
            cell.detailTextLabel.text = @"";
164
        } else {
165
            NSString *key = [[folder.metadata allKeys] objectAtIndex:indexPath.row];
166
            NSString *value = [folder.metadata objectForKey:key];
167
            NSString *metadataKeyCellText = key;
168
            NSString *metadataValueCellText = value;
169
            if ([metadataKeyCellText length] > maxMetadataViewableLength) {
170
                metadataKeyCellText = [metadataKeyCellText substringToIndex:(maxMetadataViewableLength - 3)];
171
                metadataKeyCellText = [metadataKeyCellText stringByAppendingString:@"..."];
172
            }
173
            if ([metadataValueCellText length] > maxMetadataViewableLength) {
174
                metadataValueCellText = [metadataValueCellText substringToIndex:(maxMetadataViewableLength - 3)];
175
                metadataValueCellText = [metadataValueCellText stringByAppendingString:@"..."];
176
            }
177

    
178
            cell.textLabel.text = metadataKeyCellText;
179
            cell.detailTextLabel.text = metadataValueCellText;
180
        }
181
    }
182

    
183
    return cell;
184
}
185

    
186

    
187
#pragma mark - Table view delegate
188

    
189
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
190
{
191
    if (indexPath.section == kMetadata) {
192
        EditMetadataViewController *vc = [[EditMetadataViewController alloc] initWithNibName:@"EditMetadataViewController" bundle:nil];
193
        NSString *metadataKey;
194
        NSString *metadataValue;
195
        
196
        if (indexPath.row == [self.folder.metadata count]) {
197
            metadataKey = @"";
198
            metadataValue = @"";
199
            vc.deleteEnabled = FALSE;
200
            vc.navigationItem.title = @"Add Metadata";
201
        }
202
        else {
203
            metadataKey = [[self.folder.metadata allKeys] objectAtIndex:indexPath.row];
204
            metadataValue = [self.folder.metadata objectForKey:metadataKey];
205
            vc.deleteEnabled = TRUE;
206
            vc.navigationItem.title = @"Edit Metadata";
207
        }
208
        
209
        StorageObject *object = [[[StorageObject alloc] init] autorelease];
210
        object.name = folder.name;
211
        object.metadata = folder.metadata;
212
        object.fullPath = [folder fullPath];
213
        
214
        vc.metadataKey = metadataKey;
215
        vc.metadataValue = metadataValue;
216
        vc.account = account;
217
        vc.container = container;
218
        vc.object = object;
219

    
220
        [self.navigationController pushViewController:vc animated:YES];
221
        [vc release];
222
    }
223
}
224

    
225
@end