Pārlūkot izejas kodu

Implement a basic version of 'Download-from-HTTP-Server'

Felix Paul Kühne 12 gadi atpakaļ
vecāks
revīzija
d22f35d1c0

+ 22 - 1
AspenProject/VLCAddMediaViewController.m

@@ -119,6 +119,8 @@
             if (pasteURL && ![[pasteURL scheme] isEqualToString:@""] && ![[pasteURL absoluteString] isEqualToString:@""])
                 self.openURLField.text = [pasteURL absoluteString];
         }
+        if (self.openURLView.superview)
+            [self.openURLView removeFromSuperview];
         [self.openNetworkStreamButton addSubview:self.openURLView];
     } else {
         VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
@@ -129,7 +131,26 @@
 
 - (IBAction)downloadFromHTTPServer:(id)sender
 {
-    //TODO
+    if (sender == self.downloadFromHTTPServerButton) {
+        if ([[UIPasteboard generalPasteboard] containsPasteboardTypes:@[@"public.url", @"public.text"]]) {
+            NSURL *pasteURL = [[UIPasteboard generalPasteboard] valueForPasteboardType:@"public.url"];
+            if (!pasteURL || [[pasteURL absoluteString] isEqualToString:@""]) {
+                NSString *pasteString = [[UIPasteboard generalPasteboard] valueForPasteboardType:@"public.text"];
+                pasteURL = [NSURL URLWithString:pasteString];
+            }
+
+            if (pasteURL && ![[pasteURL scheme] isEqualToString:@""] && ![[pasteURL absoluteString] isEqualToString:@""])
+                self.openURLField.text = [pasteURL absoluteString];
+        }
+        if (self.openURLView.superview)
+            [self.openURLView removeFromSuperview];
+        [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];
+    }
 }
 
 - (IBAction)showSettings:(id)sender

+ 1 - 1
AspenProject/VLCAppDelegate.m

@@ -43,7 +43,7 @@
     if (_playlistViewController && url != nil) {
         APLog(@"%@ requested %@ to be opened", sourceApplication, url);
 
-        if (url.isFileURL) {
+        if (url.isFileURL || [url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"]) {
             UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"SAVE_FILE", @"") message:[NSString stringWithFormat:NSLocalizedString(@"SAVE_FILE_LONG", @""), url.lastPathComponent] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"") otherButtonTitles:NSLocalizedString(@"BUTTON_SAVE", @""), nil];
             _tempURL = url;
             [alert show];