VLCAddMediaViewController.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // VLCAddMediaViewController.m
  3. // VLC for iOS
  4. //
  5. // Created by Felix Paul Kühne on 19.05.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. #import "VLCAddMediaViewController.h"
  9. #import "VLCAppDelegate.h"
  10. #import "VLCPlaylistViewController.h"
  11. #import "VLCAboutViewController.h"
  12. #import "VLCMovieViewController.h"
  13. #import "VLCHTTPUploaderController.h"
  14. #import "VLCSettingsViewController.h"
  15. #import "HTTPServer.h"
  16. #import <ifaddrs.h>
  17. #import <arpa/inet.h>
  18. @interface VLCAddMediaViewController () {
  19. VLCHTTPUploaderController *_uploadController;
  20. }
  21. @end
  22. @implementation VLCAddMediaViewController
  23. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  24. {
  25. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  26. return self;
  27. }
  28. - (void)viewDidLoad
  29. {
  30. [super viewDidLoad];
  31. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  32. [self.dismissButton setTitle:NSLocalizedString(@"BUTTON_DONE", @"") forState:UIControlStateNormal];
  33. [self.aboutButton setTitle:NSLocalizedString(@"ABOUT_APP", @"") forState:UIControlStateNormal];
  34. [self.openNetworkStreamButton setTitle:NSLocalizedString(@"OPEN_NETWORK", @"") forState:UIControlStateNormal];
  35. [self.downloadFromHTTPServerButton setTitle:NSLocalizedString(@"DOWNLOAD_FROM_HTTP", @"") forState:UIControlStateNormal];
  36. [self.openURLButton setTitle:NSLocalizedString(@"BUTTON_OPEN", @"") forState:UIControlStateNormal];
  37. }
  38. - (void)viewWillAppear:(BOOL)animated
  39. {
  40. [self.openURLButton sizeToFit];
  41. if (self.openURLView.superview)
  42. [self.openURLView removeFromSuperview];
  43. [super viewWillAppear:animated];
  44. }
  45. - (void)_hideAnimated:(BOOL)animated
  46. {
  47. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  48. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  49. [appDelegate.playlistViewController.addMediaPopoverController dismissPopoverAnimated:YES];
  50. } else
  51. [self dismissViewControllerAnimated:animated completion:NULL];
  52. }
  53. - (IBAction)dismiss:(id)sender
  54. {
  55. [self _hideAnimated:YES];
  56. }
  57. - (IBAction)openAboutPanel:(id)sender
  58. {
  59. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  60. if (!appDelegate.playlistViewController.aboutViewController)
  61. appDelegate.playlistViewController.aboutViewController = [[VLCAboutViewController alloc] initWithNibName:@"VLCAboutViewController" bundle:nil];
  62. [appDelegate.playlistViewController.navigationController pushViewController:appDelegate.playlistViewController.aboutViewController animated:YES];
  63. [self _hideAnimated:NO];
  64. }
  65. - (IBAction)openNetworkStream:(id)sender
  66. {
  67. if (sender == self.openNetworkStreamButton) {
  68. if ([[UIPasteboard generalPasteboard] containsPasteboardTypes:[NSArray arrayWithObjects:@"public.url", @"public.text", nil]]) {
  69. NSURL *pasteURL = [[UIPasteboard generalPasteboard] valueForPasteboardType:@"public.url"];
  70. if (!pasteURL || [[pasteURL absoluteString] isEqualToString:@""]) {
  71. NSString *pasteString = [[UIPasteboard generalPasteboard] valueForPasteboardType:@"public.text"];
  72. pasteURL = [NSURL URLWithString:pasteString];
  73. }
  74. if (pasteURL && ![[pasteURL scheme] isEqualToString:@""] && ![[pasteURL absoluteString] isEqualToString:@""]) {
  75. self.openURLField.text = [pasteURL absoluteString];
  76. }
  77. [self.openNetworkStreamButton addSubview:self.openURLView];
  78. }
  79. } else {
  80. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  81. [appDelegate.playlistViewController openMovieFromURL:[NSURL URLWithString:self.openURLField.text]];
  82. [self _hideAnimated:YES];
  83. }
  84. }
  85. - (IBAction)downloadFromHTTPServer:(id)sender
  86. {
  87. //TODO
  88. }
  89. - (IBAction)showSettings:(id)sender
  90. {
  91. if (!self.settingsViewController)
  92. self.settingsViewController = [[VLCSettingsViewController alloc] initWithNibName:@"VLCSettingsViewController" bundle:nil];
  93. [self _hideAnimated:NO];
  94. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  95. self.settingsViewController.modalPresentationStyle = UIModalPresentationFormSheet;
  96. [appDelegate.playlistViewController.navigationController presentModalViewController:self.settingsViewController animated:YES];
  97. }
  98. - (NSString *)_currentIPAddress
  99. {
  100. NSString *address = @"";
  101. struct ifaddrs *interfaces = NULL;
  102. struct ifaddrs *temp_addr = NULL;
  103. int success = getifaddrs(&interfaces);
  104. if (success == 0) {
  105. temp_addr = interfaces;
  106. while(temp_addr != NULL) {
  107. if(temp_addr->ifa_addr->sa_family == AF_INET) {
  108. if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"])
  109. address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
  110. }
  111. temp_addr = temp_addr->ifa_next;
  112. }
  113. }
  114. // Free memory
  115. freeifaddrs(interfaces);
  116. return address;
  117. }
  118. - (IBAction)toggleHTTPServer:(UISwitch *)sender
  119. {
  120. _uploadController = [[VLCHTTPUploaderController alloc] init];
  121. [_uploadController changeHTTPServerState: sender.on];
  122. HTTPServer *server = _uploadController.httpServer;
  123. if (server.isRunning)
  124. self.httpUploadServerLocationLabel.text = [NSString stringWithFormat:@"http://%@:%i", [self _currentIPAddress], server.listeningPort];
  125. else
  126. self.httpUploadServerLocationLabel.text = NSLocalizedString(@"HTTP_UPLOAD_SERVER_OFF", @"");
  127. }
  128. @end