Commit 6bc029e4 authored by Felix Paul Kühne's avatar Felix Paul Kühne

http file downloader: add a proper class taking care of this and use the...

http file downloader: add a proper class taking care of this and use the circular progress indicator for visualization in the popover
parent 441a760a
......@@ -9,6 +9,7 @@
#import <UIKit/UIKit.h>
@class VLCSettingsViewController;
@class VLCCircularProgressIndicator;
@interface VLCAddMediaViewController : UIViewController
......@@ -17,6 +18,7 @@
@property (strong, nonatomic) IBOutlet UIButton *dismissButton;
@property (strong, nonatomic) IBOutlet UIButton *aboutButton;
@property (strong, nonatomic) IBOutlet UIButton *openNetworkStreamButton;
@property (strong, nonatomic) IBOutlet VLCCircularProgressIndicator *httpDownloadProgressIndicator;
@property (strong, nonatomic) IBOutlet UIButton *downloadFromHTTPServerButton;
@property (strong, nonatomic) IBOutlet UIButton *settingsButton;
@property (strong, nonatomic) IBOutlet UISwitch *httpUploadServerSwitch;
......
......@@ -15,6 +15,7 @@
#import "VLCSettingsViewController.h"
#import "HTTPServer.h"
#import "Reachability.h"
#import "VLCHTTPFileDownloader.h"
#import <ifaddrs.h>
#import <arpa/inet.h>
......@@ -22,6 +23,7 @@
@interface VLCAddMediaViewController () {
VLCHTTPUploaderController *_uploadController;
Reachability *_reachability;
VLCHTTPFileDownloader *_httpDownloader;
}
@end
......@@ -121,6 +123,8 @@
}
if (self.openURLView.superview)
[self.openURLView removeFromSuperview];
[self.openURLButton removeTarget:nil action:NULL forControlEvents:UIControlEventTouchUpInside];
[self.openURLButton addTarget:self action:@selector(openNetworkStream:) forControlEvents:UIControlEventTouchUpInside];
[self.openNetworkStreamButton addSubview:self.openURLView];
} else {
VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
......@@ -131,6 +135,11 @@
- (IBAction)downloadFromHTTPServer:(id)sender
{
if (_httpDownloader) {
if (_httpDownloader.downloadInProgress)
return;
}
if (sender == self.downloadFromHTTPServerButton) {
if ([[UIPasteboard generalPasteboard] containsPasteboardTypes:@[@"public.url", @"public.text"]]) {
NSURL *pasteURL = [[UIPasteboard generalPasteboard] valueForPasteboardType:@"public.url"];
......@@ -144,12 +153,22 @@
}
if (self.openURLView.superview)
[self.openURLView removeFromSuperview];
[self.openURLButton removeTarget:nil action:NULL forControlEvents:UIControlEventTouchUpInside];
[self.openURLButton addTarget:self action:@selector(downloadFromHTTPServer:) forControlEvents:UIControlEventTouchUpInside];
[self.downloadFromHTTPServerButton addSubview:self.openURLView];
} else {
VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
NSURL *URLtoSave = [NSURL URLWithString:self.openURLField.text];
if ([URLtoSave.scheme isEqualToString:@"http"] || [URLtoSave.scheme isEqualToString:@"https"])
[appDelegate application:[UIApplication sharedApplication] openURL:URLtoSave sourceApplication:@"self" annotation:nil];
if (([URLtoSave.scheme isEqualToString:@"http"] || [URLtoSave.scheme isEqualToString:@"https"]) && ![URLtoSave.lastPathComponent.pathExtension isEqualToString:@""]) {
if (!_httpDownloader) {
_httpDownloader = [[VLCHTTPFileDownloader alloc] init];
_httpDownloader.mediaViewController = self;
}
[_httpDownloader downloadFileFromURL:URLtoSave];
[self.openURLView removeFromSuperview];
} else {
APLog(@"URL is not a file download");
[self _hideAnimated:YES];
}
}
}
......
......@@ -12,6 +12,7 @@
- (void)drawRect:(CGRect)rect
{
NSLog(@"draw Rect");
self.backgroundColor = [UIColor clearColor];
CGContextClearRect(UIGraphicsGetCurrentContext(), rect);
......
//
// VLCHTTPFileDownloader.h
// VLC for iOS
//
// Created by Felix Paul Kühne on 20.05.13.
// Copyright (c) 2013 VideoLAN. All rights reserved.
//
@class VLCAddMediaViewController;
@interface VLCHTTPFileDownloader : NSObject
@property (nonatomic, retain) VLCAddMediaViewController *mediaViewController;
@property (nonatomic, readonly) BOOL downloadInProgress;
- (void)downloadFileFromURL:(NSURL *)url;
@end
//
// VLCHTTPFileDownloader.m
// VLC for iOS
//
// Created by Felix Paul Kühne on 20.05.13.
// Copyright (c) 2013 VideoLAN. All rights reserved.
//
#import "VLCHTTPFileDownloader.h"
#import "VLCAddMediaViewController.h"
#import "VLCCircularProgressIndicator.h"
#import "VLCAppDelegate.h"
@interface VLCHTTPFileDownloader ()
{
VLCCircularProgressIndicator *_progressIndicator;
NSString *_filePath;
NSUInteger _expectedDownloadSize;
NSUInteger _receivedDataSize;
}
@end
@implementation VLCHTTPFileDownloader
- (void)downloadFileFromURL:(NSURL *)url
{
_progressIndicator = self.mediaViewController.httpDownloadProgressIndicator;
_progressIndicator.progress = 0.;
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
_filePath = [searchPaths[0] stringByAppendingPathComponent:url.lastPathComponent];
_expectedDownloadSize = _receivedDataSize = 0;
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (!theConnection) {
APLog(@"failed to establish connection");
_downloadInProgress = NO;
} else {
_downloadInProgress = YES;
_progressIndicator.hidden = NO;
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response
{
NSUInteger statusCode = [response statusCode];
if (statusCode == 200) {
_expectedDownloadSize = [response expectedContentLength];
APLog(@"expected download size: %i", _expectedDownloadSize);
}
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:_filePath];
if (!fileHandle) {
// create file
[[NSFileManager defaultManager] createFileAtPath:_filePath contents:nil attributes:nil];
fileHandle = [NSFileHandle fileHandleForWritingAtPath:_filePath];
if (!fileHandle) {
APLog(@"file creation failed, no data was saved");
return;
}
}
@try {
[fileHandle seekToEndOfFile];
[fileHandle writeData:data];
_receivedDataSize = _receivedDataSize + data.length;
_progressIndicator.progress = (float)_receivedDataSize / (float)_expectedDownloadSize;
}
@catch (NSException * e) {
APLog(@"exception when writing to file %@", _filePath);
}
[fileHandle closeFile];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
APLog(@"http file download complete");
_downloadInProgress = NO;
_progressIndicator.hidden = YES;
VLCAppDelegate * appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate updateMediaList];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
APLog(@"http file download failed (%i)", error.code);
_downloadInProgress = NO;
_progressIndicator.hidden = YES;
}
@end
......@@ -228,6 +228,19 @@
<reference key="IBUIBackgroundColor" ref="937037271"/>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIView" id="438150818">
<reference key="NSNextResponder" ref="892317093"/>
<int key="NSvFlags">-2147483348</int>
<string key="NSFrame">{{10, 78}, {40, 40}}</string>
<reference key="NSSuperview" ref="892317093"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MCAwAA</bytes>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
</array>
<string key="NSFrameSize">{320, 348}</string>
<reference key="NSSuperview"/>
......@@ -394,6 +407,14 @@
</object>
<int key="connectionID">62</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">httpDownloadProgressIndicator</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="438150818"/>
</object>
<int key="connectionID">64</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">openNetworkStream:</string>
......@@ -477,6 +498,7 @@
<reference ref="775197480"/>
<reference ref="665933893"/>
<reference ref="1021636329"/>
<reference ref="438150818"/>
</array>
<reference key="parent" ref="0"/>
</object>
......@@ -545,6 +567,11 @@
<reference key="object" ref="446179656"/>
<reference key="parent" ref="775197480"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">63</int>
<reference key="object" ref="438150818"/>
<reference key="parent" ref="892317093"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
......@@ -564,12 +591,14 @@
<string key="55.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="56.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="61.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="63.CustomClassName">VLCCircularProgressIndicator</string>
<string key="63.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">62</int>
<int key="maxID">64</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
......@@ -614,6 +643,7 @@
<string key="aboutButton">UIButton</string>
<string key="dismissButton">UIButton</string>
<string key="downloadFromHTTPServerButton">UIButton</string>
<string key="httpDownloadProgressIndicator">VLCCircularProgressIndicator</string>
<string key="httpUploadServerLocationLabel">UILabel</string>
<string key="httpUploadServerSwitch">UISwitch</string>
<string key="openNetworkStreamButton">UIButton</string>
......@@ -635,6 +665,10 @@
<string key="name">downloadFromHTTPServerButton</string>
<string key="candidateClassName">UIButton</string>
</object>
<object class="IBToOneOutletInfo" key="httpDownloadProgressIndicator">
<string key="name">httpDownloadProgressIndicator</string>
<string key="candidateClassName">VLCCircularProgressIndicator</string>
</object>
<object class="IBToOneOutletInfo" key="httpUploadServerLocationLabel">
<string key="name">httpUploadServerLocationLabel</string>
<string key="candidateClassName">UILabel</string>
......@@ -669,6 +703,14 @@
<string key="minorKey">./Classes/VLCAddMediaViewController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">VLCCircularProgressIndicator</string>
<string key="superclassName">UIProgressView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/VLCCircularProgressIndicator.h</string>
</object>
</object>
</array>
</object>
<int key="IBDocument.localizationMode">0</int>
......
......@@ -85,7 +85,7 @@
<string key="NSFrame">{{0, 120}, {320, 60}}</string>
<reference key="NSSuperview" ref="892317093"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="485650876"/>
<reference key="NSNextKeyView" ref="839269668"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<reference key="IBUIBackgroundColor" ref="937037271"/>
<bool key="IBUIOpaque">NO</bool>
......@@ -108,6 +108,7 @@
<string key="NSFrame">{{0, 340}, {320, 60}}</string>
<reference key="NSSuperview" ref="892317093"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<reference key="IBUIBackgroundColor" ref="937037271"/>
<bool key="IBUIOpaque">NO</bool>
......@@ -257,6 +258,20 @@
<reference key="IBUIBackgroundColor" ref="937037271"/>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIView" id="839269668">
<reference key="NSNextResponder" ref="892317093"/>
<int key="NSvFlags">-2147483348</int>
<string key="NSFrame">{{9, 130}, {40, 40}}</string>
<reference key="NSSuperview" ref="892317093"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="485650876"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MCAwAA</bytes>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
</array>
<string key="NSFrameSize">{320, 400}</string>
<reference key="NSSuperview"/>
......@@ -312,6 +327,7 @@
<string key="NSFrame">{{229, 8}, {70, 44}}</string>
<reference key="NSSuperview" ref="574364168"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
......@@ -421,6 +437,14 @@
</object>
<int key="connectionID">70</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">httpDownloadProgressIndicator</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="839269668"/>
</object>
<int key="connectionID">74</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">openNetworkStream:</string>
......@@ -513,6 +537,7 @@
<reference ref="485650876"/>
<reference ref="1021636329"/>
<reference ref="205209326"/>
<reference ref="839269668"/>
</array>
<reference key="parent" ref="0"/>
</object>
......@@ -600,6 +625,11 @@
<reference key="object" ref="892025683"/>
<reference key="parent" ref="485650876"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">73</int>
<reference key="object" ref="839269668"/>
<reference key="parent" ref="892317093"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
......@@ -622,12 +652,14 @@
<string key="63.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="64.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="69.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="73.CustomClassName">VLCCircularProgressIndicator</string>
<string key="73.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">70</int>
<int key="maxID">74</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
......@@ -635,7 +667,6 @@
<string key="className">VLCAddMediaViewController</string>
<string key="superclassName">UIViewController</string>
<dictionary class="NSMutableDictionary" key="actions">
<string key="dismiss:">id</string>
<string key="downloadFromHTTPServer:">id</string>
<string key="openAboutPanel:">id</string>
<string key="openNetworkStream:">id</string>
......@@ -643,10 +674,6 @@
<string key="toggleHTTPServer:">id</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="actionInfosByName">
<object class="IBActionInfo" key="dismiss:">
<string key="name">dismiss:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="downloadFromHTTPServer:">
<string key="name">downloadFromHTTPServer:</string>
<string key="candidateClassName">id</string>
......@@ -672,6 +699,7 @@
<string key="aboutButton">UIButton</string>
<string key="dismissButton">UIButton</string>
<string key="downloadFromHTTPServerButton">UIButton</string>
<string key="httpDownloadProgressIndicator">VLCCircularProgressIndicator</string>
<string key="httpUploadServerLocationLabel">UILabel</string>
<string key="httpUploadServerSwitch">UISwitch</string>
<string key="openNetworkStreamButton">UIButton</string>
......@@ -693,6 +721,10 @@
<string key="name">downloadFromHTTPServerButton</string>
<string key="candidateClassName">UIButton</string>
</object>
<object class="IBToOneOutletInfo" key="httpDownloadProgressIndicator">
<string key="name">httpDownloadProgressIndicator</string>
<string key="candidateClassName">VLCCircularProgressIndicator</string>
</object>
<object class="IBToOneOutletInfo" key="httpUploadServerLocationLabel">
<string key="name">httpUploadServerLocationLabel</string>
<string key="candidateClassName">UILabel</string>
......@@ -727,6 +759,14 @@
<string key="minorKey">./Classes/VLCAddMediaViewController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">VLCCircularProgressIndicator</string>
<string key="superclassName">UIProgressView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/VLCCircularProgressIndicator.h</string>
</object>
</object>
</array>
</object>
<int key="IBDocument.localizationMode">0</int>
......
......@@ -70,6 +70,7 @@
7D3EB000174A265C002062C2 /* vlcetix144.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D3EAFFC174A265C002062C2 /* vlcetix144.png */; };
7D3EB012174A3530002062C2 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D3EB011174A3530002062C2 /* Reachability.m */; };
7D3EB014174A353E002062C2 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D3EB013174A353E002062C2 /* SystemConfiguration.framework */; };
7D3EB017174A46FB002062C2 /* VLCHTTPFileDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D3EB016174A46FB002062C2 /* VLCHTTPFileDownloader.m */; };
7D6B07BC1716C9B8003280C4 /* AQGridView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D6B07A61716C9B8003280C4 /* AQGridView.m */; };
7D6B07BD1716C9B8003280C4 /* AQGridViewAnimatorItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D6B07AA1716C9B8003280C4 /* AQGridViewAnimatorItem.m */; };
7D6B07BE1716C9B8003280C4 /* AQGridViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D6B07AC1716C9B8003280C4 /* AQGridViewCell.m */; };
......@@ -239,6 +240,8 @@
7D3EB010174A3530002062C2 /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = "<group>"; };
7D3EB011174A3530002062C2 /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = "<group>"; };
7D3EB013174A353E002062C2 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
7D3EB015174A46FB002062C2 /* VLCHTTPFileDownloader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCHTTPFileDownloader.h; sourceTree = "<group>"; };
7D3EB016174A46FB002062C2 /* VLCHTTPFileDownloader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCHTTPFileDownloader.m; sourceTree = "<group>"; };
7D6B07A51716C9B8003280C4 /* AQGridView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AQGridView.h; path = ImportedSources/AQGridView/Classes/AQGridView.h; sourceTree = SOURCE_ROOT; };
7D6B07A61716C9B8003280C4 /* AQGridView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AQGridView.m; path = ImportedSources/AQGridView/Classes/AQGridView.m; sourceTree = SOURCE_ROOT; };
7D6B07A71716C9B8003280C4 /* AQGridView+CellLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "AQGridView+CellLayout.h"; path = "ImportedSources/AQGridView/Classes/AQGridView+CellLayout.h"; sourceTree = SOURCE_ROOT; };
......@@ -682,6 +685,8 @@
A7DA16D0171083DF00D6FED9 /* VLCExternalDisplayController.m */,
7D6BA1141748EFE100C0E203 /* VLCAddMediaViewController.h */,
7D6BA1151748EFE100C0E203 /* VLCAddMediaViewController.m */,
7D3EB015174A46FB002062C2 /* VLCHTTPFileDownloader.h */,
7D3EB016174A46FB002062C2 /* VLCHTTPFileDownloader.m */,
7D6BA10B1747F26300C0E203 /* VLCPasscodeLockViewController.h */,
7D6BA10C1747F26300C0E203 /* VLCPasscodeLockViewController.m */,
7D6BA11B17491F5F00C0E203 /* VLCSettingsViewController.h */,
......@@ -965,6 +970,7 @@
29CE2D44174912C600922D8F /* VLCHTTPUploaderController.m in Sources */,
7D6BA11E17491F5F00C0E203 /* VLCSettingsViewController.m in Sources */,
7D3EB012174A3530002062C2 /* Reachability.m in Sources */,
7D3EB017174A46FB002062C2 /* VLCHTTPFileDownloader.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
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