forked from TimOliver/TOSMBClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTOFilesTableViewController.m
More file actions
95 lines (73 loc) · 3.04 KB
/
TOFilesTableViewController.m
File metadata and controls
95 lines (73 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// TOFilesViewControllerTableViewController.m
// TOSMBClientExample
//
// Created by Tim Oliver on 8/5/15.
// Copyright (c) 2015 TimOliver. All rights reserved.
//
#import "TOFilesTableViewController.h"
#import <TOSMBClient/TOSMBClient.h>
#import "TORootViewController.h"
@interface TOFilesTableViewController ()
@property (nonatomic, copy) NSString *directoryTitle;
@property (nonatomic, strong) TOSMBSession *session;
@end
@implementation TOFilesTableViewController
- (instancetype)initWithSession:(TOSMBSession *)session title:(NSString *)title
{
if (self = [super initWithStyle:UITableViewStylePlain]) {
_directoryTitle = title;
_session = session;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"Loading...";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.files.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
}
TOSMBSessionFile *file = self.files[indexPath.row];
cell.textLabel.text = file.name;
cell.detailTextLabel.text = file.directory ? @"Directory" : [NSString stringWithFormat:@"File | Size: %ld", (long)file.fileSize];
cell.accessoryType = file.directory ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
TOSMBSessionFile *file = self.files[indexPath.row];
if (file.directory == NO) {
[self.rootController downloadFileFromSession:self.session atFilePath:file.fullPath];
return;
}
TOFilesTableViewController *controller = [[TOFilesTableViewController alloc] initWithSession:self.session title:file.name];
controller.rootController = self.rootController;
controller.navigationItem.rightBarButtonItem = self.navigationItem.rightBarButtonItem;
[self.navigationController pushViewController:controller animated:YES];
[self.session contentsOfDirectoryAtPath:file.fullPath success:^(NSArray *files) {
controller.files = files;
} error:^(NSError *error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"SMB Client Error" message:error.localizedDescription delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}];
}
- (void)setFiles:(NSArray *)files
{
_files = files;
self.navigationItem.title = self.directoryTitle;
[self.tableView reloadData];
}
@end