Commit 33b6e3a3 authored by Felix Paul Kühne's avatar Felix Paul Kühne

misc bag of clean-up

parent fc833023
......@@ -28,6 +28,7 @@
#import "UIColor+Presets.h"
#import "UIBarButtonItem+Theme.h"
#import "VLCAlertView.h"
#import "VLCNavigationController.h"
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
......
......@@ -14,7 +14,6 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCHTTPUploaderController.h"
#import "GHRevealViewController.h"
#import "VLCMenuTableViewController.h"
#import "VLCDownloadViewController.h"
......@@ -50,7 +49,6 @@ extern NSString *const VLCDropboxSessionWasAuthorized;
@property (nonatomic, strong) GHRevealViewController *revealController;
@property (nonatomic, strong) VLCMenuTableViewController *menuViewController;
@property (nonatomic) VLCHTTPUploaderController *uploadController;
@property (nonatomic, readonly) BOOL passcodeValidated;
@end
......@@ -117,7 +117,7 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize
[self cleanCache];
// Init the HTTP Server
self.uploadController = [[VLCHTTPUploaderController alloc] init];
[VLCHTTPUploaderController sharedInstance];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// enable crash preventer
......
......@@ -229,8 +229,9 @@
- (void)downloadStarted
{
[self.activityIndicator stopAnimating];
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStopped];
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStarted];
VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate networkActivityStopped];
[appDelegate networkActivityStarted];
self.currentDownloadLabel.text = _humanReadableFilename;
self.progressView.progress = 0.;
[self.progressPercent setText:@"0%%"];
......
......@@ -20,7 +20,7 @@
#import "WhiteRaccoon.h"
@interface VLCFTPServerListViewController () <WRRequestDelegate, VLCLocalNetworkListCell>
@interface VLCFTPServerListViewController () <WRRequestDelegate, VLCLocalNetworkListCell, UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate>
{
NSString *_ftpServerAddress;
NSString *_ftpServerUserName;
......
......@@ -24,6 +24,7 @@
#import "VLCThumbnailsCache.h"
#import "NSString+SupportedMedia.h"
#import "UIDevice+VLC.h"
#import "VLCHTTPUploaderController.h"
@interface VLCHTTPConnection()
{
......@@ -177,7 +178,7 @@
NSUInteger mediaCount = allMedia.count;
NSMutableArray *mediaInHtml = [[NSMutableArray alloc] initWithCapacity:mediaCount];
NSMutableArray *mediaInXml = [[NSMutableArray alloc] initWithCapacity:mediaCount];
NSString *hostName = [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate uploadController] hostname];
NSString *hostName = [[VLCHTTPUploaderController sharedInstance] hostname];
NSString *duration;
for (NSManagedObject *mo in allMedia) {
......@@ -487,7 +488,7 @@
{
if (_filepath) {
if (_filepath.length > 0)
[[(VLCAppDelegate*)[UIApplication sharedApplication].delegate uploadController] moveFileFrom:_filepath];
[[VLCHTTPUploaderController sharedInstance] moveFileFrom:_filepath];
}
return [super shouldDie];
}
......
......@@ -63,8 +63,9 @@
_downloadInProgress = NO;
} else {
_downloadInProgress = YES;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStarted];
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate disableIdleTimer];
VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate networkActivityStarted];
[appDelegate disableIdleTimer];
}
}
......@@ -198,8 +199,9 @@
- (void)_downloadEnded
{
_downloadInProgress = NO;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStopped];
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate activateIdleTimer];
VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate networkActivityStopped];
[appDelegate activateIdleTimer];
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *libraryPath = searchPaths[0];
......@@ -209,7 +211,6 @@
if ([fileManager fileExistsAtPath:_filePath]) {
[fileManager moveItemAtPath:_filePath toPath:finalFilePath error:nil];
VLCAppDelegate * appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate performSelectorOnMainThread:@selector(updateMediaList) withObject:nil waitUntilDone:NO];
}
......
......@@ -18,6 +18,8 @@
@interface VLCHTTPUploaderController : NSObject
+ (instancetype)sharedInstance;
@property (nonatomic, readonly) HTTPServer *httpServer;
- (BOOL)changeHTTPServerState:(BOOL)state;
......
......@@ -27,6 +27,18 @@
UIBackgroundTaskIdentifier _backgroundTaskIdentifier;
}
+ (instancetype)sharedInstance
{
static VLCHTTPUploaderController *sharedInstance = nil;
static dispatch_once_t pred;
dispatch_once(&pred, ^{
sharedInstance = [self new];
});
return sharedInstance;
}
- (id)init
{
if (self = [super init]) {
......@@ -193,11 +205,10 @@
[fileManager removeItemAtPath:filepath error:nil];
}
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStopped];
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate activateIdleTimer];
/* update media library when file upload was completed */
VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate networkActivityStopped];
[appDelegate activateIdleTimer];
[appDelegate performSelectorOnMainThread:@selector(updateMediaList) withObject:nil waitUntilDone:NO];
}
......
......@@ -85,6 +85,8 @@
- (void)_updateIconFromURL
{
NSData* imageData = [[NSData alloc]initWithContentsOfURL:self.iconURL];
if (!imageData)
return;
UIImage* image = [[UIImage alloc] initWithData:imageData];
[self setIcon:image];
}
......
......@@ -16,7 +16,7 @@
#import "VLCAppDelegate.h"
@interface VLCLocalNetworkListViewController () <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate, UIActionSheetDelegate>
@interface VLCLocalNetworkListViewController () <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate>
{
NSMutableArray *_searchData;
UISearchBar *_searchBar;
......
......@@ -26,16 +26,10 @@
#import "VLCSharedLibraryListViewController.h"
#import "VLCSharedLibraryParser.h"
#import <QuartzCore/QuartzCore.h>
#import "GHRevealViewController.h"
#import "VLCNetworkLoginViewController.h"
#import "VLCPlaylistViewController.h"
#import "VLCHTTPUploaderController.h"
#import "Reachability.h"
#import "VLCNavigationController.h"
#import "Reachability.h"
#define kPlexServiceType @"_plexmediasvr._tcp."
......@@ -60,8 +54,6 @@
VLCMediaDiscoverer *_sapDiscoverer;
VLCMediaDiscoverer *_dsmDiscoverer;
VLCNetworkLoginViewController *_loginViewController;
VLCSharedLibraryParser *_httpParser;
UIRefreshControl *_refreshControl;
......@@ -75,8 +67,6 @@
BOOL _setup;
}
@property (nonatomic) VLCHTTPUploaderController *uploadController;
@end
@implementation VLCLocalServerListViewController
......@@ -118,7 +108,7 @@
{
if (_reachability.currentReachabilityStatus == ReachableViaWiFi) {
[self _startUPNPDiscovery];
[self performSelectorInBackground:@selector(_startSAPDiscovery) withObject:nil];
[self _startSAPDiscovery];
[self _startDSMDiscovery];
}
}
......@@ -179,18 +169,12 @@
[_refreshControl addTarget:self action:@selector(handleRefresh) forControlEvents:UIControlEventValueChanged];
[self.tableView addSubview:_refreshControl];
_loginViewController = [[VLCNetworkLoginViewController alloc] initWithNibName:@"VLCNetworkLoginViewController" bundle:nil];
_loginViewController.delegate = self;
_reachability = [Reachability reachabilityForLocalWiFi];
[_reachability startNotifier];
[self netReachabilityChanged:nil];
self.uploadController = [[VLCHTTPUploaderController alloc] init];
_myHostName = [self.uploadController hostname];
_httpParser = [[VLCSharedLibraryParser alloc] init];
_myHostName = [[VLCHTTPUploaderController sharedInstance] hostname];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachabilityChanged:) name:kReachabilityChangedNotification object:nil];
}
......@@ -219,7 +203,7 @@
{
if (_reachability.currentReachabilityStatus == ReachableViaWiFi) {
[self _startUPNPDiscovery];
[self performSelectorInBackground:@selector(_startSAPDiscovery) withObject:nil];
[self _startSAPDiscovery];
[self _startDSMDiscovery];
} else {
[self _stopUPNPDiscovery];
......@@ -411,22 +395,25 @@
[[self navigationController] pushViewController:targetViewController animated:YES];
}
} else if (section == 2) {
UINavigationController *navCon = [[VLCNavigationController alloc] initWithRootViewController:_loginViewController];
VLCNetworkLoginViewController *loginViewController = [[VLCNetworkLoginViewController alloc] initWithNibName:@"VLCNetworkLoginViewController" bundle:nil];
loginViewController.delegate = self;
UINavigationController *navCon = [[VLCNavigationController alloc] initWithRootViewController:loginViewController];
navCon.navigationBarHidden = NO;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
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(dismissWithAnimation:)];
if (loginViewController.navigationItem.leftBarButtonItem == nil)
loginViewController.navigationItem.leftBarButtonItem = [UIBarButtonItem themedDarkToolbarButtonWithTitle:NSLocalizedString(@"BUTTON_DONE", nil) target:loginViewController andSelector:@selector(dismissWithAnimation:)];
} else
[self.navigationController pushViewController:_loginViewController animated:YES];
[self.navigationController pushViewController:loginViewController animated:YES];
if (row != 0 && [_ftpServices[row] hostName].length > 0) // FTP Connect To Server Special Item and hostname is long enough
_loginViewController.hostname = [_ftpServices[row] hostName];
loginViewController.hostname = [_ftpServices[row] hostName];
else
_loginViewController.hostname = @"";
loginViewController.hostname = @"";
} else if (section == 3) {
NSString *name = [_httpServicesInfo[row] objectForKey:@"name"];
NSString *hostName = [_httpServicesInfo[row] objectForKey:@"hostName"];
......@@ -471,7 +458,7 @@
[self.tableView reloadData];
[self _startUPNPDiscovery];
[self performSelectorInBackground:@selector(_startSAPDiscovery) withObject:nil];
[self _startSAPDiscovery];
[self _startDSMDiscovery];
}
......@@ -570,6 +557,8 @@
}
} else if ([aNetService.type isEqualToString:@"_http._tcp."]) {
if ([[aNetService hostName] rangeOfString:_myHostName].location == NSNotFound) {
if (!_httpParser)
_httpParser = [[VLCSharedLibraryParser alloc] init];
[_httpParser checkNetserviceForVLCService:aNetService];
}
}
......
......@@ -48,8 +48,6 @@
Reachability *_reachability;
}
@property (nonatomic) VLCHTTPUploaderController *uploadController;
@end
@implementation VLCMenuTableViewController
......@@ -104,13 +102,10 @@
[self netReachabilityChanged:nil];
VLCAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
self.uploadController = appDelegate.uploadController;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachabilityChanged:) name:kReachabilityChangedNotification object:nil];
BOOL isHTTPServerOn = [[NSUserDefaults standardUserDefaults] boolForKey:kVLCSettingSaveHTTPUploadServerStatus];
[self.uploadController changeHTTPServerState:isHTTPServerOn];
[[VLCHTTPUploaderController sharedInstance] changeHTTPServerState:isHTTPServerOn];
[self updateHTTPServerAddress];
}
......@@ -131,7 +126,7 @@
_uploadButton.enabled = NO;
[_uploadButton setImage:[UIImage imageNamed:@"WiFiUp"] forState:UIControlStateDisabled];
_uploadLocationLabel.text = NSLocalizedString(@"HTTP_UPLOAD_NO_CONNECTIVITY", nil);
[self.uploadController changeHTTPServerState:NO];
[[VLCHTTPUploaderController sharedInstance] changeHTTPServerState:NO];
}
}
......@@ -264,13 +259,14 @@
- (void)updateHTTPServerAddress
{
HTTPServer *server = self.uploadController.httpServer;
VLCHTTPUploaderController *uploadController = [VLCHTTPUploaderController sharedInstance];
HTTPServer *server = uploadController.httpServer;
if (server.isRunning) {
_uploadLocationLabel.numberOfLines = 0;
if (server.listeningPort != 80)
_uploadLocationLabel.text = [NSString stringWithFormat:@"http://%@:%i\nhttp://%@:%i", [self.uploadController currentIPAddress], server.listeningPort, [self.uploadController hostname], server.listeningPort];
_uploadLocationLabel.text = [NSString stringWithFormat:@"http://%@:%i\nhttp://%@:%i", [uploadController currentIPAddress], server.listeningPort, [uploadController hostname], server.listeningPort];
else
_uploadLocationLabel.text = [NSString stringWithFormat:@"http://%@\nhttp://%@", [self.uploadController currentIPAddress], [self.uploadController hostname]];
_uploadLocationLabel.text = [NSString stringWithFormat:@"http://%@\nhttp://%@", [uploadController currentIPAddress], [uploadController hostname]];
[_uploadButton setImage:[UIImage imageNamed:@"WifiUpOn"] forState:UIControlStateNormal];
} else {
_uploadLocationLabel.text = NSLocalizedString(@"HTTP_UPLOAD_SERVER_OFF", nil);
......@@ -281,10 +277,11 @@
- (IBAction)toggleHTTPServer:(UIButton *)sender
{
if (_uploadButton.enabled) {
BOOL futureHTTPServerState = !self.uploadController.httpServer.isRunning;
VLCHTTPUploaderController *uploadController = [VLCHTTPUploaderController sharedInstance];
BOOL futureHTTPServerState = !uploadController.httpServer.isRunning;
[[NSUserDefaults standardUserDefaults] setBool:futureHTTPServerState forKey:kVLCSettingSaveHTTPUploadServerStatus];
[self.uploadController changeHTTPServerState:futureHTTPServerState];
[uploadController changeHTTPServerState:futureHTTPServerState];
[self updateHTTPServerAddress];
[[NSUserDefaults standardUserDefaults] synchronize];
}
......
......@@ -25,7 +25,7 @@
#import "MediaServer1Device.h"
#import "BasicUPnPDevice+VLC.h"
@interface VLCUPnPServerListViewController () <VLCLocalNetworkListCell>
@interface VLCUPnPServerListViewController () <VLCLocalNetworkListCell, UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate>
{
MediaServer1Device *_UPNPdevice;
NSString *_UPNProotID;
......@@ -132,7 +132,7 @@
unsigned int durationInSeconds = 0;
unsigned int bitrate = 0;
if (tableView == self.searchDisplayController.searchResultsTableView) {
if (tableView == self.searchDisplayController.searchResultsTableView) {
@synchronized(self) {
mediaItem = _searchData[indexPath.row];
}
......@@ -358,62 +358,64 @@
// Provide users with a descriptive action sheet for them to choose based on the multiple resources advertised by DLNA devices (HDHomeRun for example)
for (NSUInteger i = 0; i < count; i++) {
position = [uriCollectionKeys[i] rangeOfString:@"http-get:*:video/"];
if (position.location != NSNotFound) {
NSString *orgPNValue;
NSString *transcodeValue;
// Attempt to parse DLNA.ORG_PN first
NSString *protocolInfo = uriCollectionKeys[i];
NSArray *components = [protocolInfo componentsSeparatedByString:@";"];
NSArray *nonFlagsComponents = [components[0] componentsSeparatedByString:@":"];
NSString *orgPN = [nonFlagsComponents lastObject];
// Check to see if we are where we should be
NSRange orgPNRange = [orgPN rangeOfString:@"DLNA.ORG_PN="];
if (orgPNRange.location == 0) {
orgPNValue = [orgPN substringFromIndex:orgPNRange.length];
}
// HDHomeRun: Get the transcode profile from the HTTP API if possible
if ([_UPNPdevice VLC_isHDHomeRunMediaServer]) {
NSRange transcodeRange = [uriCollectionObjects[i] rangeOfString:@"transcode="];
if (transcodeRange.location != NSNotFound) {
transcodeValue = [uriCollectionObjects[i] substringFromIndex:transcodeRange.location + transcodeRange.length];
// Check that there are no more parameters
NSRange ampersandRange = [transcodeValue rangeOfString:@"&"];
if (ampersandRange.location != NSNotFound) {
transcodeValue = [transcodeValue substringToIndex:transcodeRange.location];
}
if (position.location == NSNotFound)
continue;
NSString *orgPNValue;
NSString *transcodeValue;
// Attempt to parse DLNA.ORG_PN first
NSString *protocolInfo = uriCollectionKeys[i];
NSArray *components = [protocolInfo componentsSeparatedByString:@";"];
NSArray *nonFlagsComponents = [components[0] componentsSeparatedByString:@":"];
NSString *orgPN = [nonFlagsComponents lastObject];
// Check to see if we are where we should be
NSRange orgPNRange = [orgPN rangeOfString:@"DLNA.ORG_PN="];
if (orgPNRange.location == 0) {
orgPNValue = [orgPN substringFromIndex:orgPNRange.length];
}
transcodeValue = [transcodeValue capitalizedString];
// HDHomeRun: Get the transcode profile from the HTTP API if possible
if ([_UPNPdevice VLC_isHDHomeRunMediaServer]) {
NSRange transcodeRange = [uriCollectionObjects[i] rangeOfString:@"transcode="];
if (transcodeRange.location != NSNotFound) {
transcodeValue = [uriCollectionObjects[i] substringFromIndex:transcodeRange.location + transcodeRange.length];
// Check that there are no more parameters
NSRange ampersandRange = [transcodeValue rangeOfString:@"&"];
if (ampersandRange.location != NSNotFound) {
transcodeValue = [transcodeValue substringToIndex:transcodeRange.location];
}
transcodeValue = [transcodeValue capitalizedString];
}
}
// Fallbacks to get the most descriptive resource title
NSString *profileTitle;
if ([transcodeValue length] && [orgPNValue length]) {
profileTitle = [NSString stringWithFormat:@"%@ (%@)", transcodeValue, orgPNValue];
// Fallbacks to get the most descriptive resource title
NSString *profileTitle;
if ([transcodeValue length] && [orgPNValue length]) {
profileTitle = [NSString stringWithFormat:@"%@ (%@)", transcodeValue, orgPNValue];
// The extra whitespace is to get UIActionSheet to render the text better (this bug has been fixed in iOS 8)
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
profileTitle = [NSString stringWithFormat:@" %@ ", profileTitle];
}
// The extra whitespace is to get UIActionSheet to render the text better (this bug has been fixed in iOS 8)
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
profileTitle = [NSString stringWithFormat:@" %@ ", profileTitle];
}
} else if ([transcodeValue length]) {
profileTitle = transcodeValue;
} else if ([orgPNValue length]) {
profileTitle = orgPNValue;
} else if ([uriCollectionKeys[i] length]) {
profileTitle = uriCollectionKeys[i];
} else if ([uriCollectionObjects[i] length]) {
profileTitle = uriCollectionObjects[i];
} else {
profileTitle = NSLocalizedString(@"UNKNOWN", nil);
}
[actionSheet addButtonWithTitle:profileTitle];
} else if ([transcodeValue length]) {
profileTitle = transcodeValue;
} else if ([orgPNValue length]) {
profileTitle = orgPNValue;
} else if ([uriCollectionKeys[i] length]) {
profileTitle = uriCollectionKeys[i];
} else if ([uriCollectionObjects[i] length]) {
profileTitle = uriCollectionObjects[i];
} else {
profileTitle = NSLocalizedString(@"UNKNOWN", nil);
}
[actionSheet addButtonWithTitle:profileTitle];
}
// If no resources are found, an empty action sheet will be presented, but the fact that we got here implies that we have playable resources, so no special handling for this case is included
......
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