Revision 64929bae Classes/SettingsViewController.m

b/Classes/SettingsViewController.m
14 14
#import "SettingsPluginHandler.h"
15 15
#import "SettingsPlugin.h"
16 16
#import "AboutViewController.h"
17
#import "OpenStackAppDelegate.h"
18
#import "PithosUtilities.h"
17 19

  
18 20
#define kPasscodeLock 0
19 21

  
......
37 39
    self.navigationItem.title = @"Settings";
38 40
    
39 41
    //aboutSection = 1 + [[SettingsPluginHandler plugins] count];
40
    aboutSection = 1;
42
    cacheSection = 1;
43
    aboutSection = 2;
41 44
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
42 45
    self.navigationItem.rightBarButtonItem = doneButton;
43 46
    [doneButton release];
......
47 50
#pragma mark Table view data source
48 51

  
49 52
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
50
    if (section > kPasscodeLock && section < aboutSection) {
53
    if (section > kPasscodeLock && section < cacheSection) {
51 54
        id <SettingsPlugin> plugin = [[SettingsPluginHandler plugins] objectAtIndex:section - 1];
52 55
        return [plugin tableView:tableView titleForFooterInSection:section];
53 56
    } else {
......
57 60

  
58 61
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
59 62
    //return 2 + [[SettingsPluginHandler plugins] count];
60
    return 2;
63
    return 3;
61 64
}
62 65

  
63 66

  
......
86 89
    if (cell == nil) {
87 90
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
88 91
    }
92
    cell.userInteractionEnabled = YES;
93
    cell.textLabel.textColor = [UIColor blackColor];
89 94
    
90 95
    // Configure the cell...
91 96
    if (indexPath.section == kPasscodeLock) {
......
110 115
        }
111 116
        
112 117
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
118
    } else if (indexPath.section == cacheSection) {
119
        OpenStackAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
120
        NSString *cacheSize = [PithosUtilities humanReadableSize:[PithosUtilities sizeOfDirectory:appDelegate.cacheDirectoryPath]];
121
        if ([cacheSize hasPrefix:@"0"]) {
122
            cell.textLabel.textColor = [UIColor grayColor];
123
            cell.userInteractionEnabled = NO;
124
        }
125
        cell.textLabel.text = [NSString stringWithFormat:@"Clear Cache  (%@)", cacheSize];
126
        cell.detailTextLabel.text = @"";
127
        cell.accessoryType = UITableViewCellAccessoryNone;
113 128
    } else if (indexPath.section == aboutSection) {
114 129
        cell.textLabel.text = @"About This App";
115 130
        cell.detailTextLabel.text = @"";
......
138 153
        vc.settingsViewController = self;
139 154
        [self.navigationController pushViewController:vc animated:YES];
140 155
        [vc release];
156
    } else if (indexPath.section == cacheSection) {
157
        OpenStackAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
158
        NSFileManager *fileManager = [NSFileManager defaultManager];
159
        NSError *error = nil;
160
        NSString *file;
161
        NSDirectoryEnumerator *directoryEnumerator = [fileManager enumeratorAtPath:appDelegate.cacheDirectoryPath];
162
        @synchronized(appDelegate.cachedObjectsDictionary) {
163
            while (file = [directoryEnumerator nextObject]) {
164
                [fileManager removeItemAtPath:[NSString stringWithFormat:@"%@/%@",appDelegate.cacheDirectoryPath,file] error:&error];
165
                if (error) {
166
                    [self alert:@"Error" message:[NSString stringWithFormat:@"Error in removing cached file, %@", error.localizedDescription]];
167
                } else {
168
                    for (NSString *key in [appDelegate.cachedObjectsDictionary allKeys])
169
                        if ([[appDelegate.cachedObjectsDictionary objectForKey:key] isEqualToString:file])
170
                            [appDelegate.cachedObjectsDictionary removeObjectForKey:key];
171
                }        
172
            }
173
        }
174
        [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
175
        [self.tableView reloadData];
141 176
    } else if (indexPath.section == aboutSection) {
142 177
        //This currently is a link to the pithos docs page. It might change in the future to use the AboutViewController;
143 178
        NSString *aboutURLString = [[NSUserDefaults standardUserDefaults] objectForKey:@"aboutURL"];
......
146 181
        /*AboutViewController *vc = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil];
147 182
        [self.navigationController pushViewController:vc animated:YES];
148 183
        [vc release];*/
149
    } else {
184
    }  else {
150 185
        id <SettingsPlugin> plugin = [[SettingsPluginHandler plugins] objectAtIndex:indexPath.section - 1];
151 186
        return [plugin tableView:tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath];
152 187
    }

Also available in: Unified diff