Commit e587eba9 authored by Tobias's avatar Tobias

Remove view controller from VLCLocalNetworkService

parent fc761876
......@@ -10,8 +10,18 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import <Foundation/Foundation.h>
#import "VLCNetworkServerBrowser-Protocol.h"
NS_ASSUME_NONNULL_BEGIN
@protocol VLCNetworkServerLoginInformation <NSObject>
@property (nonatomic) NSString *username;
@property (nonatomic) NSString *password;
@property (nonatomic) NSString *address;
@property (nonatomic) NSNumber *port;
@property (nonatomic) NSString *protocolIdentifier;
@end
@protocol VLCLocalNetworkService <NSObject>
@required
......@@ -19,10 +29,10 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) NSString *title;
@optional
- (nullable UIViewController *)detailViewController;
- (nullable id<VLCNetworkServerBrowser>)serverBrowser;
- (NSURL *)directPlaybackURL;
- (nullable id<VLCNetworkServerLoginInformation>)loginInformation;
typedef void (^VLCLocalNetworkServiceActionBlock)(void);
@property (nonatomic, readonly) VLCLocalNetworkServiceActionBlock action;
@end
NS_ASSUME_NONNULL_END
......@@ -12,6 +12,15 @@
#import "VLCLocalNetworkService-Protocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface VLCNetworkServerLoginInformation : NSObject
@property (nonatomic) NSString *username;
@property (nonatomic) NSString *password;
@property (nonatomic) NSString *address;
@property (nonatomic) NSNumber *port;
@property (nonatomic) NSString *protocolIdentifier;
@end
#pragma mark - item
@interface VLCLocalNetworkServiceItem : NSObject <VLCLocalNetworkService>
......@@ -29,9 +38,11 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithNetService:(NSNetService *)service;
@end
extern NSString *const VLCNetworkServerProtocolIdentifierPlex;
@interface VLCLocalNetworkServicePlex : VLCLocalNetworkServiceNetService
@end
extern NSString *const VLCNetworkServerProtocolIdentifierFTP;
@interface VLCLocalNetworkServiceFTP : VLCLocalNetworkServiceNetService
@end
......@@ -44,6 +55,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithMediaItem:(VLCMedia *)mediaItem;
@end
extern NSString *const VLCNetworkServerProtocolIdentifierSMB;
@interface VLCLocalNetworkServiceDSM: VLCLocalNetworkServiceVLCMedia
@end
......
......@@ -11,8 +11,10 @@
*****************************************************************************/
#import "VLCLocalNetworkService.h"
#import "VLCNetworkServerBrowserViewController.h"
@implementation VLCNetworkServerLoginInformation
@end
@interface VLCLocalNetworkServiceItem ()
@property (nonatomic, strong) NSString *title;
......@@ -31,8 +33,6 @@
}
@end
#import "VLCNetworkLoginViewController.h"
@implementation VLCLocalNetworkServiceItemLogin
- (instancetype)init
......@@ -45,10 +45,9 @@
return self;
}
- (UIViewController *)detailViewController {
VLCNetworkLoginViewController *loginViewController = [[VLCNetworkLoginViewController alloc] initWithNibName:@"VLCNetworkLoginViewController" bundle:nil];
loginViewController.serverProtocol = VLCServerProtocolUndefined;
return loginViewController;
- (VLCNetworkServerLoginInformation *)loginInformation {
return [[VLCNetworkServerLoginInformation alloc] init];
}
@end
......@@ -75,18 +74,19 @@
- (UIImage *)icon {
return nil;
}
- (UIViewController *)detailViewController {
- (id<VLCNetworkServerBrowser>)serverBrowser {
return nil;
}
@end
#import "VLCNetworkServerBrowserPlex.h"
NSString *const VLCNetworkServerProtocolIdentifierPlex = @"plex";
@implementation VLCLocalNetworkServicePlex
- (UIImage *)icon {
return [UIImage imageNamed:@"PlexServerIcon"];
}
- (UIViewController *)detailViewController {
- (id<VLCNetworkServerBrowser>)serverBrowser {
NSNetService *service = self.netService;
if (service.hostName == nil || service.port == 0) {
......@@ -98,20 +98,23 @@
NSUInteger portNum = service.port;
VLCNetworkServerBrowserPlex *serverBrowser = [[VLCNetworkServerBrowserPlex alloc] initWithName:name host:hostName portNumber:@(portNum) path:@"" authentificication:@""];
VLCNetworkServerBrowserViewController *targetViewController = [[VLCNetworkServerBrowserViewController alloc] initWithServerBrowser:serverBrowser];
return targetViewController;
return serverBrowser;
}
@end
NSString *const VLCNetworkServerProtocolIdentifierFTP = @"ftp";
@implementation VLCLocalNetworkServiceFTP
- (UIImage *)icon {
return [UIImage imageNamed:@"serverIcon"];
}
- (UIViewController *)detailViewController {
VLCNetworkLoginViewController *loginViewController = [[VLCNetworkLoginViewController alloc] initWithNibName:@"VLCNetworkLoginViewController" bundle:nil];
loginViewController.serverProtocol = VLCServerProtocolFTP;
loginViewController.hostname = self.netService.hostName;
return loginViewController;
- (VLCNetworkServerLoginInformation *)loginInformation
{
VLCNetworkServerLoginInformation *login = [[VLCNetworkServerLoginInformation alloc] init];
login.address = self.netService.hostName;
login.protocolIdentifier = VLCNetworkServerProtocolIdentifierFTP;
return login;
}
@end
......@@ -120,7 +123,7 @@
- (UIImage *)icon {
return [UIImage imageNamed:@"menuCone"];
}
- (UIViewController *)detailViewController {
- (id<VLCNetworkServerBrowser>)serverBrowser {
NSNetService *service = self.netService;
if (service.hostName == nil || service.port == 0) {
......@@ -131,9 +134,7 @@
NSString *hostName = service.hostName;
NSUInteger portNum = service.port;
VLCNetworkServerBrowserSharedLibrary *serverBrowser = [[VLCNetworkServerBrowserSharedLibrary alloc] initWithName:name host:hostName portNumber:portNum];
VLCNetworkServerBrowserViewController *targetViewController = [[VLCNetworkServerBrowserViewController alloc] initWithServerBrowser:serverBrowser];
return targetViewController;
return serverBrowser;
}
@end
......@@ -158,19 +159,23 @@
}
@end
NSString *const VLCNetworkServerProtocolIdentifierSMB = @"smb";
@implementation VLCLocalNetworkServiceDSM
- (UIImage *)icon {
return [UIImage imageNamed:@"serverIcon"];
}
- (UIViewController *)detailViewController {
- (VLCNetworkServerLoginInformation *)loginInformation {
VLCMedia *media = self.mediaItem;
if (media.mediaType != VLCMediaTypeDirectory)
return nil;
VLCNetworkLoginViewController *loginViewController = [[VLCNetworkLoginViewController alloc] initWithNibName:@"VLCNetworkLoginViewController" bundle:nil];
loginViewController.serverProtocol = VLCServerProtocolSMB;
loginViewController.hostname = self.mediaItem.url.host;
return loginViewController;
VLCNetworkServerLoginInformation *login = [[VLCNetworkServerLoginInformation alloc] init];
login.address = self.mediaItem.url.host;
login.protocolIdentifier = VLCNetworkServerProtocolIdentifierSMB;
return login;
}
@end
......@@ -180,17 +185,13 @@
- (UIImage *)icon {
return [UIImage imageNamed:@"TVBroadcastIcon"];
}
- (VLCLocalNetworkServiceActionBlock)action {
__weak typeof(self) weakSelf = self;
return ^{
VLCMedia *cellMedia = weakSelf.mediaItem;
- (NSURL *)directPlaybackURL {
VLCMediaType mediaType = cellMedia.mediaType;
if (cellMedia && mediaType != VLCMediaTypeDirectory && mediaType != VLCMediaTypeDisc) {
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:[cellMedia url] successCallback:nil errorCallback:nil];
}
};
VLCMediaType mediaType = self.mediaItem.mediaType;
if (mediaType != VLCMediaTypeDirectory && mediaType != VLCMediaTypeDisc) {
return [self.mediaItem url];
}
return nil;
}
@end
......@@ -220,17 +221,14 @@
- (UIImage *)icon {
return [self.device smallIcon] ?: [UIImage imageNamed:@"serverIcon"];
}
- (UIViewController *)detailViewController {
- (id<VLCNetworkServerBrowser>)serverBrowser {
BasicUPnPDevice *device = self.device;
if (device != nil) {
if ([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaServer:1"]) {
MediaServer1Device *server = (MediaServer1Device*)device;
VLCNetworkServerBrowserUPnP *serverBrowser = [[VLCNetworkServerBrowserUPnP alloc] initWithUPNPDevice:server header:[device friendlyName] andRootID:@"0"];
VLCNetworkServerBrowserViewController *targetViewController = [[VLCNetworkServerBrowserViewController alloc] initWithServerBrowser:serverBrowser];
return targetViewController;
}
if ([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaServer:1"]) {
MediaServer1Device *server = (MediaServer1Device*)device;
VLCNetworkServerBrowserUPnP *serverBrowser = [[VLCNetworkServerBrowserUPnP alloc] initWithUPNPDevice:server header:[device friendlyName] andRootID:@"0"];
return serverBrowser;
}
return nil;
}
......
......@@ -152,33 +152,60 @@
id<VLCLocalNetworkService> service = [_discoveryController networkServiceForIndexPath:indexPath];
if ([service respondsToSelector:@selector(action)]) {
service.action();
}
if ([service respondsToSelector:@selector(detailViewController)]) {
UIViewController *controller = [service detailViewController];
// TODO: refactor this out
if ([controller isKindOfClass:[VLCNetworkLoginViewController class]]) {
VLCNetworkLoginViewController *loginViewController = (id)controller;
loginViewController.delegate = self;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UINavigationController *navCon = [[VLCNavigationController alloc] initWithRootViewController:loginViewController];
navCon.navigationBarHidden = NO;
navCon.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navCon animated:YES completion:nil];
if (loginViewController.navigationItem.leftBarButtonItem == nil)
loginViewController.navigationItem.leftBarButtonItem = [UIBarButtonItem themedDarkToolbarButtonWithTitle:NSLocalizedString(@"BUTTON_DONE", nil) target:loginViewController andSelector:@selector(_dismiss)];
} else
[self.navigationController pushViewController:loginViewController animated:YES];
if ([service respondsToSelector:@selector(serverBrowser)]) {
id<VLCNetworkServerBrowser> serverBrowser = [service serverBrowser];
if (serverBrowser) {
VLCNetworkServerBrowserViewController *vc = [[VLCNetworkServerBrowserViewController alloc] initWithServerBrowser:serverBrowser];
[self.navigationController pushViewController:vc animated:YES];
return;
}
// end TODO
else if (controller) {
[self.navigationController pushViewController:controller animated:YES];
}
if ([service respondsToSelector:@selector(directPlaybackURL)]) {
NSURL *playbackURL = [service directPlaybackURL];
if (playbackURL) {
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:playbackURL successCallback:nil errorCallback:nil];
return;
}
}
VLCNetworkServerLoginInformation *login;
if ([service respondsToSelector:@selector(loginInformation)]) {
login = [service loginInformation];
}
VLCNetworkLoginViewController *loginViewController = [[VLCNetworkLoginViewController alloc] initWithNibName:@"VLCNetworkLoginViewController" bundle:nil];
VLCServerProtocol protocol = VLCServerProtocolUndefined;
NSString *protocolIdentifier = login.protocolIdentifier;
if ([protocolIdentifier isEqualToString:VLCNetworkServerProtocolIdentifierFTP]) {
protocol = VLCServerProtocolFTP;
} else if ([protocolIdentifier isEqualToString:VLCNetworkServerProtocolIdentifierPlex]) {
protocol = VLCServerProtocolPLEX;
} else if ([protocolIdentifier isEqualToString:VLCNetworkServerProtocolIdentifierSMB]) {
protocol = VLCServerProtocolSMB;
}
loginViewController.serverProtocol = protocol;
loginViewController.hostname = login.address;
loginViewController.username = login.username;
loginViewController.password = login.password;
loginViewController.port = login.port.stringValue;
loginViewController.delegate = self;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UINavigationController *navCon = [[VLCNavigationController alloc] initWithRootViewController:loginViewController];
navCon.navigationBarHidden = NO;
navCon.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navCon animated:YES completion:nil];
if (loginViewController.navigationItem.leftBarButtonItem == nil)
loginViewController.navigationItem.leftBarButtonItem = [UIBarButtonItem themedDarkToolbarButtonWithTitle:NSLocalizedString(@"BUTTON_DONE", nil) target:loginViewController andSelector:@selector(_dismiss)];
} else {
[self.navigationController pushViewController:loginViewController animated:YES];
}
}
#pragma mark - Refresh
......
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