Commit 99eb0828 authored by Pierre SAGASPE's avatar Pierre SAGASPE Committed by Felix Paul Kühne

Add Download via UPNP

Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent 52c62b5a
......@@ -23,5 +23,5 @@
- (IBAction)downloadAction:(id)sender;
- (IBAction)cancelDownload:(id)sender;
- (void)addURLToDownloadList:(NSURL *)aURL;
- (void)addURLToDownloadList:(NSURL *)aURL fileNameOfMedia:(NSString*) fileName;;
@end
......@@ -25,6 +25,7 @@
NSMutableArray *_currentDownloads;
NSUInteger _currentDownloadType;
NSString *_humanReadableFilename;
NSString *_MediaFilename;
VLCHTTPFileDownloader *_httpDownloader;
......@@ -134,8 +135,13 @@
if (!_httpDownloader.downloadInProgress) {
_currentDownloadType = kVLCDownloadViaHTTP;
if (_MediaFilename) {
[_httpDownloader downloadFileFromURLwithFileName:_currentDownloads[0] fileNameOfMedia:_MediaFilename];
_humanReadableFilename = _MediaFilename;
} else {
[_httpDownloader downloadFileFromURL:_currentDownloads[0]];
_humanReadableFilename = _httpDownloader.userReadableDownloadName;
}
}
} else if ([downloadScheme isEqualToString:@"ftp"]) {
_currentDownloadType = kVLCDownloadViaFTP;
......@@ -174,6 +180,7 @@
- (void)downloadStarted
{
[self.activityIndicator stopAnimating];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
self.currentDownloadLabel.text = _humanReadableFilename;
self.progressView.progress = 0.;
self.currentDownloadLabel.hidden = NO;
......@@ -184,6 +191,7 @@
- (void)downloadEnded
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
self.currentDownloadLabel.hidden = YES;
self.progressView.hidden = YES;
self.cancelButton.hidden = YES;
......@@ -293,9 +301,10 @@
}
#pragma mark - communication with other VLC objects
- (void)addURLToDownloadList:(NSURL *)aURL
- (void)addURLToDownloadList:(NSURL *)aURL fileNameOfMedia:(NSString*) fileName
{
[_currentDownloads addObject:aURL];
_MediaFilename = fileName;
[self.downloadsTable reloadData];
[self _triggerNextDownload];
}
......
......@@ -28,5 +28,6 @@
- (void)cancelDownload;
- (void)downloadFileFromURL:(NSURL *)url;
- (void)downloadFileFromURLwithFileName:(NSURL *)url fileNameOfMedia:(NSString*) fileName;
@end
......@@ -47,6 +47,24 @@
}
}
- (void)downloadFileFromURLwithFileName:(NSURL *)url fileNameOfMedia:(NSString*) fileName
{
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
_fileName = fileName;
_filePath = [searchPaths[0] stringByAppendingPathComponent:_fileName];
_expectedDownloadSize = _receivedDataSize = 0;
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
_urlConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (!_urlConnection) {
APLog(@"failed to establish connection");
_downloadInProgress = NO;
} else {
_downloadInProgress = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate disableIdleTimer];
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response
{
NSUInteger statusCode = [response statusCode];
......
......@@ -158,14 +158,15 @@
MediaServer1ItemObject *mediaItem = _mutableObjectList[indexPath.row];
[cell setSubtitle: [NSString stringWithFormat:@"%0.2f MB (%@)", (float)([mediaItem.size intValue] / 1e6), mediaItem.duration]];
[cell setIsDirectory:NO];
cell.isDownloadable = YES;
if (![mediaItem.albumArt isEqualToString:NULL]) {
NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mediaItem.albumArt]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
[cell setIcon:image];
cell.delegate = self;
}
else
[cell setIcon:[UIImage imageNamed:@"blank"]];
cell.delegate = self;
} else {
[cell setIsDirectory:YES];
[cell setIcon:[UIImage imageNamed:@"folder"]];
......@@ -278,7 +279,13 @@
{
NSURL *URLToQueue = [NSURL URLWithString:[[@"ftp" stringByAppendingFormat:@"://%@%@/%@/%@", [self _credentials], _ftpServerAddress, _ftpServerPath, fileName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[(VLCAppDelegate*)[UIApplication sharedApplication].delegate downloadViewController] addURLToDownloadList:URLToQueue];
[[(VLCAppDelegate*)[UIApplication sharedApplication].delegate downloadViewController] addURLToDownloadList:URLToQueue fileNameOfMedia:nil];
}
- (void)_downloadUPNPFile:(NSURL *)url fileNameOfMedia:(NSString*) fileName;
{
fileName = [[fileName stringByAppendingString:@"."] stringByAppendingString:[[url absoluteString] pathExtension]];
[[(VLCAppDelegate*)[UIApplication sharedApplication].delegate downloadViewController] addURLToDownloadList:url fileNameOfMedia:fileName];
}
- (void)requestCompleted:(WRRequest *)request
......@@ -310,7 +317,22 @@
#pragma mark - VLCLocalNetworkListCell delegation
- (void)triggerDownloadForCell:(VLCLocalNetworkListCell *)cell
{
if (_serverType == kVLCFTPServer) {
if (_serverType == kVLCUPNPFileServer) {
MediaServer1ItemObject *item = _mutableObjectList[[self.tableView indexPathForCell:cell].row];
MediaServer1ItemRes *resource = nil;
NSEnumerator *e = [[item resources] objectEnumerator];
NSURL *itemURL;
while((resource = (MediaServer1ItemRes*)[e nextObject])){
itemURL = [NSURL URLWithString:[[item uri] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}
if (![[item uri] isSupportedFormat]) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", @"") message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", @""), [item uri]] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"") otherButtonTitles:nil];
[alert show];
} else {
[self _downloadUPNPFile:itemURL fileNameOfMedia:[item title]];
[cell.statusLabel showStatusMessage:NSLocalizedString(@"DOWNLOADING", @"")];
}
}else if (_serverType == kVLCFTPServer) {
NSString *objectName = [_objectList[[self.tableView indexPathForCell:cell].row] objectForKey:(id)kCFFTPResourceName];
if (![objectName isSupportedFormat]) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", @"") message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", @""), objectName] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"") otherButtonTitles:nil];
......
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