Browse Source

misc bag of clean-up

Felix Paul Kühne 10 years ago
parent
commit
33b6e3a3ec

+ 1 - 0
Sources/VLC for iOS-Prefix.pch

@@ -28,6 +28,7 @@
 #import "UIColor+Presets.h"
 #import "UIColor+Presets.h"
 #import "UIBarButtonItem+Theme.h"
 #import "UIBarButtonItem+Theme.h"
 #import "VLCAlertView.h"
 #import "VLCAlertView.h"
+#import "VLCNavigationController.h"
 
 
 #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
 #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
 
 

+ 0 - 2
Sources/VLCAppDelegate.h

@@ -14,7 +14,6 @@
  * Refer to the COPYING file of the official project for license.
  * Refer to the COPYING file of the official project for license.
  *****************************************************************************/
  *****************************************************************************/
 
 
-#import "VLCHTTPUploaderController.h"
 #import "GHRevealViewController.h"
 #import "GHRevealViewController.h"
 #import "VLCMenuTableViewController.h"
 #import "VLCMenuTableViewController.h"
 #import "VLCDownloadViewController.h"
 #import "VLCDownloadViewController.h"
@@ -50,7 +49,6 @@ extern NSString *const VLCDropboxSessionWasAuthorized;
 @property (nonatomic, strong) GHRevealViewController *revealController;
 @property (nonatomic, strong) GHRevealViewController *revealController;
 @property (nonatomic, strong) VLCMenuTableViewController *menuViewController;
 @property (nonatomic, strong) VLCMenuTableViewController *menuViewController;
 
 
-@property (nonatomic) VLCHTTPUploaderController *uploadController;
 @property (nonatomic, readonly) BOOL passcodeValidated;
 @property (nonatomic, readonly) BOOL passcodeValidated;
 
 
 @end
 @end

+ 1 - 1
Sources/VLCAppDelegate.m

@@ -117,7 +117,7 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize
     [self cleanCache];
     [self cleanCache];
 
 
     // Init the HTTP Server
     // Init the HTTP Server
-    self.uploadController = [[VLCHTTPUploaderController alloc] init];
+    [VLCHTTPUploaderController sharedInstance];
 
 
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
     // enable crash preventer
     // enable crash preventer

+ 3 - 2
Sources/VLCDownloadViewController.m

@@ -229,8 +229,9 @@
 - (void)downloadStarted
 - (void)downloadStarted
 {
 {
     [self.activityIndicator stopAnimating];
     [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.currentDownloadLabel.text = _humanReadableFilename;
     self.progressView.progress = 0.;
     self.progressView.progress = 0.;
     [self.progressPercent setText:@"0%%"];
     [self.progressPercent setText:@"0%%"];

+ 1 - 1
Sources/VLCFTPServerListViewController.m

@@ -20,7 +20,7 @@
 
 
 #import "WhiteRaccoon.h"
 #import "WhiteRaccoon.h"
 
 
-@interface VLCFTPServerListViewController () <WRRequestDelegate, VLCLocalNetworkListCell>
+@interface VLCFTPServerListViewController () <WRRequestDelegate, VLCLocalNetworkListCell, UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate>
 {
 {
     NSString *_ftpServerAddress;
     NSString *_ftpServerAddress;
     NSString *_ftpServerUserName;
     NSString *_ftpServerUserName;

+ 3 - 2
Sources/VLCHTTPConnection.m

@@ -24,6 +24,7 @@
 #import "VLCThumbnailsCache.h"
 #import "VLCThumbnailsCache.h"
 #import "NSString+SupportedMedia.h"
 #import "NSString+SupportedMedia.h"
 #import "UIDevice+VLC.h"
 #import "UIDevice+VLC.h"
+#import "VLCHTTPUploaderController.h"
 
 
 @interface VLCHTTPConnection()
 @interface VLCHTTPConnection()
 {
 {
@@ -177,7 +178,7 @@
         NSUInteger mediaCount = allMedia.count;
         NSUInteger mediaCount = allMedia.count;
         NSMutableArray *mediaInHtml = [[NSMutableArray alloc] initWithCapacity:mediaCount];
         NSMutableArray *mediaInHtml = [[NSMutableArray alloc] initWithCapacity:mediaCount];
         NSMutableArray *mediaInXml = [[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;
         NSString *duration;
 
 
         for (NSManagedObject *mo in allMedia) {
         for (NSManagedObject *mo in allMedia) {
@@ -487,7 +488,7 @@
 {
 {
     if (_filepath) {
     if (_filepath) {
         if (_filepath.length > 0)
         if (_filepath.length > 0)
-            [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate uploadController] moveFileFrom:_filepath];
+            [[VLCHTTPUploaderController sharedInstance] moveFileFrom:_filepath];
     }
     }
     return [super shouldDie];
     return [super shouldDie];
 }
 }

+ 6 - 5
Sources/VLCHTTPFileDownloader.m

@@ -63,8 +63,9 @@
         _downloadInProgress = NO;
         _downloadInProgress = NO;
     } else {
     } else {
         _downloadInProgress = YES;
         _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
 - (void)_downloadEnded
 {
 {
     _downloadInProgress = NO;
     _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);
     NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *libraryPath = searchPaths[0];
     NSString *libraryPath = searchPaths[0];
@@ -209,7 +211,6 @@
 
 
     if ([fileManager fileExistsAtPath:_filePath]) {
     if ([fileManager fileExistsAtPath:_filePath]) {
         [fileManager moveItemAtPath:_filePath toPath:finalFilePath error:nil];
         [fileManager moveItemAtPath:_filePath toPath:finalFilePath error:nil];
-        VLCAppDelegate * appDelegate = [UIApplication sharedApplication].delegate;
         [appDelegate performSelectorOnMainThread:@selector(updateMediaList) withObject:nil waitUntilDone:NO];
         [appDelegate performSelectorOnMainThread:@selector(updateMediaList) withObject:nil waitUntilDone:NO];
     }
     }
 
 

+ 2 - 0
Sources/VLCHTTPUploaderController.h

@@ -18,6 +18,8 @@
 
 
 @interface VLCHTTPUploaderController : NSObject
 @interface VLCHTTPUploaderController : NSObject
 
 
++ (instancetype)sharedInstance;
+
 @property (nonatomic, readonly) HTTPServer *httpServer;
 @property (nonatomic, readonly) HTTPServer *httpServer;
 
 
 - (BOOL)changeHTTPServerState:(BOOL)state;
 - (BOOL)changeHTTPServerState:(BOOL)state;

+ 15 - 4
Sources/VLCHTTPUploaderController.m

@@ -27,6 +27,18 @@
     UIBackgroundTaskIdentifier _backgroundTaskIdentifier;
     UIBackgroundTaskIdentifier _backgroundTaskIdentifier;
 }
 }
 
 
++ (instancetype)sharedInstance
+{
+    static VLCHTTPUploaderController *sharedInstance = nil;
+    static dispatch_once_t pred;
+
+    dispatch_once(&pred, ^{
+        sharedInstance = [self new];
+    });
+
+    return sharedInstance;
+}
+
 - (id)init
 - (id)init
 {
 {
     if (self = [super init]) {
     if (self = [super init]) {
@@ -193,11 +205,10 @@
         [fileManager removeItemAtPath:filepath error:nil];
         [fileManager removeItemAtPath:filepath error:nil];
     }
     }
 
 
-    [(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStopped];
-    [(VLCAppDelegate*)[UIApplication sharedApplication].delegate activateIdleTimer];
-
     /* update media library when file upload was completed */
     /* 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];
     [appDelegate performSelectorOnMainThread:@selector(updateMediaList) withObject:nil waitUntilDone:NO];
 }
 }
 
 

+ 2 - 0
Sources/VLCLocalNetworkListCell.m

@@ -85,6 +85,8 @@
 - (void)_updateIconFromURL
 - (void)_updateIconFromURL
 {
 {
     NSData* imageData = [[NSData alloc]initWithContentsOfURL:self.iconURL];
     NSData* imageData = [[NSData alloc]initWithContentsOfURL:self.iconURL];
+    if (!imageData)
+        return;
     UIImage* image = [[UIImage alloc] initWithData:imageData];
     UIImage* image = [[UIImage alloc] initWithData:imageData];
     [self setIcon:image];
     [self setIcon:image];
 }
 }

+ 1 - 1
Sources/VLCLocalNetworkListViewController.m

@@ -16,7 +16,7 @@
 
 
 #import "VLCAppDelegate.h"
 #import "VLCAppDelegate.h"
 
 
-@interface VLCLocalNetworkListViewController () <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate, UIActionSheetDelegate>
+@interface VLCLocalNetworkListViewController () <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate>
 {
 {
     NSMutableArray *_searchData;
     NSMutableArray *_searchData;
     UISearchBar *_searchBar;
     UISearchBar *_searchBar;

+ 16 - 27
Sources/VLCLocalServerListViewController.m

@@ -26,16 +26,10 @@
 #import "VLCSharedLibraryListViewController.h"
 #import "VLCSharedLibraryListViewController.h"
 #import "VLCSharedLibraryParser.h"
 #import "VLCSharedLibraryParser.h"
 
 
-#import <QuartzCore/QuartzCore.h>
-#import "GHRevealViewController.h"
-
 #import "VLCNetworkLoginViewController.h"
 #import "VLCNetworkLoginViewController.h"
-#import "VLCPlaylistViewController.h"
-
 #import "VLCHTTPUploaderController.h"
 #import "VLCHTTPUploaderController.h"
-#import "Reachability.h"
 
 
-#import "VLCNavigationController.h"
+#import "Reachability.h"
 
 
 #define kPlexServiceType @"_plexmediasvr._tcp."
 #define kPlexServiceType @"_plexmediasvr._tcp."
 
 
@@ -60,8 +54,6 @@
     VLCMediaDiscoverer *_sapDiscoverer;
     VLCMediaDiscoverer *_sapDiscoverer;
     VLCMediaDiscoverer *_dsmDiscoverer;
     VLCMediaDiscoverer *_dsmDiscoverer;
 
 
-    VLCNetworkLoginViewController *_loginViewController;
-
     VLCSharedLibraryParser *_httpParser;
     VLCSharedLibraryParser *_httpParser;
 
 
     UIRefreshControl *_refreshControl;
     UIRefreshControl *_refreshControl;
@@ -75,8 +67,6 @@
     BOOL _setup;
     BOOL _setup;
 }
 }
 
 
-@property (nonatomic) VLCHTTPUploaderController *uploadController;
-
 @end
 @end
 
 
 @implementation VLCLocalServerListViewController
 @implementation VLCLocalServerListViewController
@@ -118,7 +108,7 @@
 {
 {
     if (_reachability.currentReachabilityStatus == ReachableViaWiFi) {
     if (_reachability.currentReachabilityStatus == ReachableViaWiFi) {
         [self _startUPNPDiscovery];
         [self _startUPNPDiscovery];
-        [self performSelectorInBackground:@selector(_startSAPDiscovery) withObject:nil];
+        [self _startSAPDiscovery];
         [self _startDSMDiscovery];
         [self _startDSMDiscovery];
     }
     }
 }
 }
@@ -179,18 +169,12 @@
     [_refreshControl addTarget:self action:@selector(handleRefresh) forControlEvents:UIControlEventValueChanged];
     [_refreshControl addTarget:self action:@selector(handleRefresh) forControlEvents:UIControlEventValueChanged];
     [self.tableView addSubview:_refreshControl];
     [self.tableView addSubview:_refreshControl];
 
 
-    _loginViewController = [[VLCNetworkLoginViewController alloc] initWithNibName:@"VLCNetworkLoginViewController" bundle:nil];
-
-    _loginViewController.delegate = self;
-
     _reachability = [Reachability reachabilityForLocalWiFi];
     _reachability = [Reachability reachabilityForLocalWiFi];
     [_reachability startNotifier];
     [_reachability startNotifier];
 
 
     [self netReachabilityChanged:nil];
     [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];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachabilityChanged:) name:kReachabilityChangedNotification object:nil];
 }
 }
@@ -219,7 +203,7 @@
 {
 {
     if (_reachability.currentReachabilityStatus == ReachableViaWiFi) {
     if (_reachability.currentReachabilityStatus == ReachableViaWiFi) {
         [self _startUPNPDiscovery];
         [self _startUPNPDiscovery];
-        [self performSelectorInBackground:@selector(_startSAPDiscovery) withObject:nil];
+        [self _startSAPDiscovery];
         [self _startDSMDiscovery];
         [self _startDSMDiscovery];
     } else {
     } else {
         [self _stopUPNPDiscovery];
         [self _stopUPNPDiscovery];
@@ -411,22 +395,25 @@
             [[self navigationController] pushViewController:targetViewController animated:YES];
             [[self navigationController] pushViewController:targetViewController animated:YES];
         }
         }
     } else if (section == 2) {
     } 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;
         navCon.navigationBarHidden = NO;
 
 
         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
             navCon.modalPresentationStyle = UIModalPresentationFormSheet;
             navCon.modalPresentationStyle = UIModalPresentationFormSheet;
             [self presentViewController:navCon animated:YES completion:nil];
             [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
         } 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
         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
         else
-            _loginViewController.hostname = @"";
+            loginViewController.hostname = @"";
     } else if (section == 3) {
     } else if (section == 3) {
         NSString *name = [_httpServicesInfo[row] objectForKey:@"name"];
         NSString *name = [_httpServicesInfo[row] objectForKey:@"name"];
         NSString *hostName = [_httpServicesInfo[row] objectForKey:@"hostName"];
         NSString *hostName = [_httpServicesInfo[row] objectForKey:@"hostName"];
@@ -471,7 +458,7 @@
     [self.tableView reloadData];
     [self.tableView reloadData];
 
 
     [self _startUPNPDiscovery];
     [self _startUPNPDiscovery];
-    [self performSelectorInBackground:@selector(_startSAPDiscovery) withObject:nil];
+    [self _startSAPDiscovery];
     [self _startDSMDiscovery];
     [self _startDSMDiscovery];
 }
 }
 
 
@@ -570,6 +557,8 @@
         }
         }
     }  else if ([aNetService.type isEqualToString:@"_http._tcp."]) {
     }  else if ([aNetService.type isEqualToString:@"_http._tcp."]) {
         if ([[aNetService hostName] rangeOfString:_myHostName].location == NSNotFound) {
         if ([[aNetService hostName] rangeOfString:_myHostName].location == NSNotFound) {
+            if (!_httpParser)
+                _httpParser = [[VLCSharedLibraryParser alloc] init];
             [_httpParser checkNetserviceForVLCService:aNetService];
             [_httpParser checkNetserviceForVLCService:aNetService];
         }
         }
     }
     }

+ 9 - 12
Sources/VLCMenuTableViewController.m

@@ -48,8 +48,6 @@
     Reachability *_reachability;
     Reachability *_reachability;
 }
 }
 
 
-@property (nonatomic) VLCHTTPUploaderController *uploadController;
-
 @end
 @end
 
 
 @implementation VLCMenuTableViewController
 @implementation VLCMenuTableViewController
@@ -104,13 +102,10 @@
 
 
     [self netReachabilityChanged:nil];
     [self netReachabilityChanged:nil];
 
 
-    VLCAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
-    self.uploadController = appDelegate.uploadController;
-
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachabilityChanged:) name:kReachabilityChangedNotification object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachabilityChanged:) name:kReachabilityChangedNotification object:nil];
 
 
     BOOL isHTTPServerOn = [[NSUserDefaults standardUserDefaults] boolForKey:kVLCSettingSaveHTTPUploadServerStatus];
     BOOL isHTTPServerOn = [[NSUserDefaults standardUserDefaults] boolForKey:kVLCSettingSaveHTTPUploadServerStatus];
-    [self.uploadController changeHTTPServerState:isHTTPServerOn];
+    [[VLCHTTPUploaderController sharedInstance] changeHTTPServerState:isHTTPServerOn];
     [self updateHTTPServerAddress];
     [self updateHTTPServerAddress];
 }
 }
 
 
@@ -131,7 +126,7 @@
         _uploadButton.enabled = NO;
         _uploadButton.enabled = NO;
         [_uploadButton setImage:[UIImage imageNamed:@"WiFiUp"] forState:UIControlStateDisabled];
         [_uploadButton setImage:[UIImage imageNamed:@"WiFiUp"] forState:UIControlStateDisabled];
         _uploadLocationLabel.text = NSLocalizedString(@"HTTP_UPLOAD_NO_CONNECTIVITY", nil);
         _uploadLocationLabel.text = NSLocalizedString(@"HTTP_UPLOAD_NO_CONNECTIVITY", nil);
-        [self.uploadController changeHTTPServerState:NO];
+        [[VLCHTTPUploaderController sharedInstance] changeHTTPServerState:NO];
     }
     }
 }
 }
 
 
@@ -264,13 +259,14 @@
 
 
 - (void)updateHTTPServerAddress
 - (void)updateHTTPServerAddress
 {
 {
-    HTTPServer *server = self.uploadController.httpServer;
+    VLCHTTPUploaderController *uploadController = [VLCHTTPUploaderController sharedInstance];
+    HTTPServer *server = uploadController.httpServer;
     if (server.isRunning) {
     if (server.isRunning) {
         _uploadLocationLabel.numberOfLines = 0;
         _uploadLocationLabel.numberOfLines = 0;
         if (server.listeningPort != 80)
         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
         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];
         [_uploadButton setImage:[UIImage imageNamed:@"WifiUpOn"] forState:UIControlStateNormal];
     } else {
     } else {
         _uploadLocationLabel.text = NSLocalizedString(@"HTTP_UPLOAD_SERVER_OFF", nil);
         _uploadLocationLabel.text = NSLocalizedString(@"HTTP_UPLOAD_SERVER_OFF", nil);
@@ -281,10 +277,11 @@
 - (IBAction)toggleHTTPServer:(UIButton *)sender
 - (IBAction)toggleHTTPServer:(UIButton *)sender
 {
 {
     if (_uploadButton.enabled) {
     if (_uploadButton.enabled) {
-        BOOL futureHTTPServerState = !self.uploadController.httpServer.isRunning;
+        VLCHTTPUploaderController *uploadController = [VLCHTTPUploaderController sharedInstance];
+        BOOL futureHTTPServerState = !uploadController.httpServer.isRunning;
 
 
         [[NSUserDefaults standardUserDefaults] setBool:futureHTTPServerState forKey:kVLCSettingSaveHTTPUploadServerStatus];
         [[NSUserDefaults standardUserDefaults] setBool:futureHTTPServerState forKey:kVLCSettingSaveHTTPUploadServerStatus];
-        [self.uploadController changeHTTPServerState:futureHTTPServerState];
+        [uploadController changeHTTPServerState:futureHTTPServerState];
         [self updateHTTPServerAddress];
         [self updateHTTPServerAddress];
         [[NSUserDefaults standardUserDefaults] synchronize];
         [[NSUserDefaults standardUserDefaults] synchronize];
     }
     }

+ 51 - 49
Sources/VLCUPnPServerListViewController.m

@@ -25,7 +25,7 @@
 #import "MediaServer1Device.h"
 #import "MediaServer1Device.h"
 #import "BasicUPnPDevice+VLC.h"
 #import "BasicUPnPDevice+VLC.h"
 
 
-@interface VLCUPnPServerListViewController () <VLCLocalNetworkListCell>
+@interface VLCUPnPServerListViewController () <VLCLocalNetworkListCell, UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate>
 {
 {
     MediaServer1Device *_UPNPdevice;
     MediaServer1Device *_UPNPdevice;
     NSString *_UPNProotID;
     NSString *_UPNProotID;
@@ -132,7 +132,7 @@
         unsigned int durationInSeconds = 0;
         unsigned int durationInSeconds = 0;
         unsigned int bitrate = 0;
         unsigned int bitrate = 0;
 
 
-        if (tableView == self.searchDisplayController.searchResultsTableView) {
+        if (tableView == self.searchDisplayController.searchResultsTableView) {
             @synchronized(self) {
             @synchronized(self) {
                 mediaItem = _searchData[indexPath.row];
                 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)
     // 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++) {
     for (NSUInteger i = 0; i < count; i++) {
         position = [uriCollectionKeys[i] rangeOfString:@"http-get:*:video/"];
         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
     // 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