|
@@ -14,12 +14,16 @@
|
|
|
#import "UPnPManager.h"
|
|
|
#import "VLCLocalNetworkListCell.h"
|
|
|
#import "VLCLocalServerFolderListViewController.h"
|
|
|
+#import <QuartzCore/QuartzCore.h>
|
|
|
+#import "GHRevealViewController.h"
|
|
|
|
|
|
@interface VLCLocalServerListViewController () <UITableViewDataSource, UITableViewDelegate>
|
|
|
{
|
|
|
UIBarButtonItem *_backToMenuButton;
|
|
|
- NSArray *_filteredDevices;
|
|
|
- NSArray *_devices;
|
|
|
+ NSArray *_sectionHeaderTexts;
|
|
|
+
|
|
|
+ NSArray *_filteredUPNPDevices;
|
|
|
+ NSArray *_UPNPdevices;
|
|
|
}
|
|
|
|
|
|
@end
|
|
@@ -39,9 +43,24 @@
|
|
|
{
|
|
|
[super viewDidLoad];
|
|
|
|
|
|
+ _sectionHeaderTexts = @[@"Universal Plug'n'Play (UPNP)", @"File Transfer Protocol (FTP)"];
|
|
|
+
|
|
|
+ _backToMenuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(goBack:)];
|
|
|
+ self.navigationItem.leftBarButtonItem = _backToMenuButton;
|
|
|
+
|
|
|
+ self.tableView.separatorColor = [UIColor colorWithWhite:.122 alpha:1.];
|
|
|
+ self.view.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
|
|
|
+
|
|
|
+ self.title = NSLocalizedString(@"LOCAL_NETWORK", @"");
|
|
|
+
|
|
|
+ [self performSelectorInBackground:@selector(_startUPNPDiscovery) withObject:nil];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)_startUPNPDiscovery
|
|
|
+{
|
|
|
UPnPDB* db = [[UPnPManager GetInstance] DB];
|
|
|
|
|
|
- _devices = [db rootDevices]; //BasicUPnPDevice
|
|
|
+ _UPNPdevices = [db rootDevices]; //BasicUPnPDevice
|
|
|
|
|
|
[db addObserver:(UPnPDBObserver*)self];
|
|
|
|
|
@@ -50,14 +69,6 @@
|
|
|
|
|
|
//Search for UPnP Devices
|
|
|
[[[UPnPManager GetInstance] SSDP] searchSSDP];
|
|
|
-
|
|
|
- _backToMenuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(goBack:)];
|
|
|
- self.navigationItem.leftBarButtonItem = _backToMenuButton;
|
|
|
-
|
|
|
- self.tableView.separatorColor = [UIColor colorWithWhite:.122 alpha:1.];
|
|
|
- self.view.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
|
|
|
-
|
|
|
- self.title = NSLocalizedString(@"LOCAL_NETWORK", @"");
|
|
|
}
|
|
|
|
|
|
- (IBAction)goBack:(id)sender
|
|
@@ -74,12 +85,15 @@
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
|
{
|
|
|
- return 1;
|
|
|
+ return _sectionHeaderTexts.count;
|
|
|
}
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
|
{
|
|
|
- return _filteredDevices.count;
|
|
|
+ if (section == 0)
|
|
|
+ return _filteredUPNPDevices.count;
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
|
|
@@ -95,45 +109,86 @@
|
|
|
if (cell == nil)
|
|
|
cell = [VLCLocalNetworkListCell cellWithReuseIdentifier:CellIdentifier];
|
|
|
|
|
|
- BasicUPnPDevice *device = _filteredDevices[indexPath.row];
|
|
|
- [cell setTitle:[device friendlyName]];
|
|
|
- UIImage *icon = [device smallIcon];
|
|
|
- [cell setIcon:icon];
|
|
|
- [cell setIsDirectory:YES];
|
|
|
+ if (indexPath.section == 0) {
|
|
|
+ BasicUPnPDevice *device = _filteredUPNPDevices[indexPath.row];
|
|
|
+ [cell setTitle:[device friendlyName]];
|
|
|
+ [cell setIcon:[device smallIcon]];
|
|
|
+ [cell setIsDirectory:YES];
|
|
|
+ }
|
|
|
|
|
|
return cell;
|
|
|
}
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
{
|
|
|
- BasicUPnPDevice *device = _filteredDevices[indexPath.row];
|
|
|
- if ([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaServer:1"]) {
|
|
|
- MediaServer1Device *server = (MediaServer1Device*)device;
|
|
|
- VLCLocalServerFolderListViewController *targetViewController = [[VLCLocalServerFolderListViewController alloc] initWithDevice:server header:[device friendlyName] andRootID:@"0"];
|
|
|
- [[self navigationController] pushViewController:targetViewController animated:YES];
|
|
|
- } else if ([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaRenderer:1"]) {
|
|
|
- //FIXME: euh, we don't do rendering atm, at least not here.
|
|
|
+ if (indexPath.section == 0) {
|
|
|
+ BasicUPnPDevice *device = _filteredUPNPDevices[indexPath.row];
|
|
|
+ if ([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaServer:1"]) {
|
|
|
+ MediaServer1Device *server = (MediaServer1Device*)device;
|
|
|
+ VLCLocalServerFolderListViewController *targetViewController = [[VLCLocalServerFolderListViewController alloc] initWithDevice:server header:[device friendlyName] andRootID:@"0"];
|
|
|
+ [[self navigationController] pushViewController:targetViewController animated:YES];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#pragma mark - custom table view appearance
|
|
|
+
|
|
|
+- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
|
|
|
+ return 21.f;
|
|
|
+}
|
|
|
+
|
|
|
+- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
|
|
|
+ NSObject *headerText = NSLocalizedString(_sectionHeaderTexts[section], @"");
|
|
|
+ UIView *headerView = nil;
|
|
|
+ if (headerText != [NSNull null]) {
|
|
|
+ headerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.height, 21.0f)];
|
|
|
+ CAGradientLayer *gradient = [CAGradientLayer layer];
|
|
|
+ gradient.frame = headerView.bounds;
|
|
|
+ gradient.colors = @[
|
|
|
+ (id)[UIColor colorWithRed:(67.0f/255.0f) green:(74.0f/255.0f) blue:(94.0f/255.0f) alpha:1.0f].CGColor,
|
|
|
+ (id)[UIColor colorWithRed:(57.0f/255.0f) green:(64.0f/255.0f) blue:(82.0f/255.0f) alpha:1.0f].CGColor,
|
|
|
+ ];
|
|
|
+ [headerView.layer insertSublayer:gradient atIndex:0];
|
|
|
+
|
|
|
+ UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectInset(headerView.bounds, 12.0f, 5.0f)];
|
|
|
+ textLabel.text = (NSString *) headerText;
|
|
|
+ textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:([UIFont systemFontSize] * 0.8f)];
|
|
|
+ textLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
|
|
|
+ textLabel.shadowColor = [UIColor colorWithWhite:0.0f alpha:0.25f];
|
|
|
+ textLabel.textColor = [UIColor colorWithRed:(125.0f/255.0f) green:(129.0f/255.0f) blue:(146.0f/255.0f) alpha:1.0f];
|
|
|
+ textLabel.backgroundColor = [UIColor clearColor];
|
|
|
+ [headerView addSubview:textLabel];
|
|
|
+
|
|
|
+ UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)];
|
|
|
+ topLine.backgroundColor = [UIColor colorWithRed:(78.0f/255.0f) green:(86.0f/255.0f) blue:(103.0f/255.0f) alpha:1.0f];
|
|
|
+ [headerView addSubview:topLine];
|
|
|
+
|
|
|
+ UIView *bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 21.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)];
|
|
|
+ bottomLine.backgroundColor = [UIColor colorWithRed:(36.0f/255.0f) green:(42.0f/255.0f) blue:(5.0f/255.0f) alpha:1.0f];
|
|
|
+ [headerView addSubview:bottomLine];
|
|
|
+ }
|
|
|
+ return headerView;
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - UPNP details
|
|
|
//protocol UPnPDBObserver
|
|
|
-(void)UPnPDBWillUpdate:(UPnPDB*)sender{
|
|
|
- APLog(@"UPnPDBWillUpdate %d", _devices.count);
|
|
|
+ APLog(@"UPnPDBWillUpdate %d", _UPNPdevices.count);
|
|
|
}
|
|
|
|
|
|
-(void)UPnPDBUpdated:(UPnPDB*)sender{
|
|
|
- APLog(@"UPnPDBUpdated %d", _devices.count);
|
|
|
+ APLog(@"UPnPDBUpdated %d", _UPNPdevices.count);
|
|
|
|
|
|
- NSUInteger count = _devices.count;
|
|
|
+ NSUInteger count = _UPNPdevices.count;
|
|
|
BasicUPnPDevice *device;
|
|
|
NSMutableArray *mutArray = [[NSMutableArray alloc] init];
|
|
|
for (NSUInteger x = 0; x < count; x++) {
|
|
|
- device = _devices[x];
|
|
|
+ device = _UPNPdevices[x];
|
|
|
if ([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaServer:1"])
|
|
|
[mutArray addObject:device];
|
|
|
}
|
|
|
- _filteredDevices = nil;
|
|
|
- _filteredDevices = [NSArray arrayWithArray:mutArray];
|
|
|
+ _filteredUPNPDevices = nil;
|
|
|
+ _filteredUPNPDevices = [NSArray arrayWithArray:mutArray];
|
|
|
|
|
|
[self.tableView performSelectorOnMainThread : @ selector(reloadData) withObject:nil waitUntilDone:YES];
|
|
|
}
|