Commit 92515f7c authored by Felix Paul Kühne's avatar Felix Paul Kühne

local network: add SMB/CIFS discovery via Bonjour

parent b9b09368
......@@ -25,7 +25,7 @@
#import "VLCPlaylistViewController.h"
#import "Reachability.h"
@interface VLCLocalServerListViewController () <UITableViewDataSource, UITableViewDelegate, NSNetServiceBrowserDelegate, VLCNetworkLoginViewController, NSNetServiceDelegate, VLCMediaListDelegate>
@interface VLCLocalServerListViewController () <UITableViewDataSource, UITableViewDelegate, NSNetServiceBrowserDelegate, VLCNetworkLoginViewController, NSNetServiceDelegate, VLCMediaListDelegate, UPnPDBObserver>
{
UIBarButtonItem *_backToMenuButton;
NSArray *_sectionHeaderTexts;
......@@ -33,6 +33,8 @@
NSNetServiceBrowser *_ftpNetServiceBrowser;
NSMutableArray *_rawNetServices;
NSMutableArray *_ftpServices;
NSNetServiceBrowser *_smbNetServiceBrowser;
NSMutableArray *_smbServices;
NSArray *_filteredUPNPDevices;
NSArray *_UPNPdevices;
......@@ -80,7 +82,7 @@
/* if (SYSTEM_RUNS_IOS7_OR_LATER)
_sectionHeaderTexts = @[@"Universal Plug'n'Play (UPNP)", @"File Transfer Protocol (FTP)", @"Network Streams (SAP)"];
else*/
_sectionHeaderTexts = @[@"Universal Plug'n'Play (UPNP)", @"File Transfer Protocol (FTP)"];
_sectionHeaderTexts = @[@"Universal Plug'n'Play (UPNP)", @"SMB/CIFS", @"File Transfer Protocol (FTP)"];
_backToMenuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(goBack:)];
self.navigationItem.leftBarButtonItem = _backToMenuButton;
......@@ -99,7 +101,9 @@
_ftpNetServiceBrowser = [[NSNetServiceBrowser alloc] init];
_ftpNetServiceBrowser.delegate = self;
[self _triggerNetServiceBrowser];
_smbServices = [[NSMutableArray alloc] init];
_smbNetServiceBrowser = [[NSNetServiceBrowser alloc] init];
_smbNetServiceBrowser.delegate = self;
_refreshControl = [[UIRefreshControl alloc] init];
[_refreshControl addTarget:self action:@selector(handleRefresh) forControlEvents:UIControlEventValueChanged];
......@@ -125,11 +129,13 @@
[super viewWillDisappear:animated];
[_activityIndicator stopAnimating];
[_ftpNetServiceBrowser stop];
[_smbNetServiceBrowser stop];
}
- (void)viewWillAppear:(BOOL)animated
{
[_ftpNetServiceBrowser searchForServicesOfType:@"_ftp._tcp." inDomain:@""];
[_smbNetServiceBrowser searchForServicesOfType:@"_smb._tcp." inDomain:@""];
[_activityIndicator stopAnimating];
[super viewWillAppear:animated];
......@@ -222,8 +228,10 @@
if (section == 0)
return _filteredUPNPDevices.count;
else if (section == 1)
return _ftpServices.count;
return _smbServices.count;
else if (section == 2)
return _ftpServices.count;
else if (section == 3)
return _sapDiscoverer.discoveredMedia.count;
return 0;
......@@ -258,13 +266,16 @@
}
[cell setIcon:icon != nil ? icon : [UIImage imageNamed:@"serverIcon"]];
} else if (section == 1) {
[cell setTitle:[_smbServices[row] name]];
[cell setIcon:[UIImage imageNamed:@"serverIcon"]];
} else if (section == 2) {
if (row == 0)
[cell setTitle:_ftpServices[row]];
else {
[cell setTitle:[_ftpServices[row] name]];
[cell setIcon:[UIImage imageNamed:@"serverIcon"]];
}
} else if (section == 2)
} else if (section == 3)
[cell setTitle:[[_sapDiscoverer.discoveredMedia mediaAtIndex:row] metadataForKey: VLCMetaInformationTitle]];
return cell;
......@@ -289,6 +300,9 @@
[self.navigationController pushViewController:targetViewController animated:YES];
}
} else if (section == 1) {
//FIXME: connect to SMB servers here
APLog(@"SMB connectivity not implemented");
} else if (section == 2) {
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_loginViewController];
[navCon loadTheme];
navCon.navigationBarHidden = NO;
......@@ -309,7 +323,7 @@
_loginViewController.hostname = [_ftpServices[row] hostName];
else
_loginViewController.hostname = @"";
} else if (section == 2) {
} else if (section == 3) {
VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate openMovieFromURL:[[_sapDiscoverer.discoveredMedia mediaAtIndex:row] url]];
}
......@@ -412,6 +426,8 @@
[_rawNetServices removeObject:aNetService];
if ([aNetService.type isEqualToString:@"_ftp._tcp."])
[_ftpServices removeObject:aNetService];
if ([aNetService.type isEqualToString:@"_smb._tcp."])
[_smbServices removeObject:aNetService];
if (!moreComing)
[self.tableView reloadData];
}
......@@ -421,7 +437,11 @@
if ([aNetService.type isEqualToString:@"_ftp._tcp."]) {
if (![_ftpServices containsObject:aNetService])
[_ftpServices addObject:aNetService];
} else if ([aNetService.type isEqualToString:@"_smb._tcp."]) {
if (![_smbServices containsObject:aNetService])
[_smbServices addObject:aNetService];
}
[_rawNetServices removeObject:aNetService];
[self.tableView reloadData];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment