VLCAddMediaViewController.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. } else {
  79. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  80. [appDelegate.playlistViewController openMovieFromURL:[NSURL URLWithString:self.openURLField.text]];
  81. [self _hideAnimated:YES];
  82. }
  83. }
  84. - (IBAction)downloadFromHTTPServer:(id)sender
  85. {
  86. //TODO
  87. }
  88. - (IBAction)showSettings:(id)sender
  89. {
  90. if (!self.settingsViewController)
  91. self.settingsViewController = [[VLCSettingsViewController alloc] initWithNibName:@"VLCSettingsViewController" bundle:nil];
  92. [self _hideAnimated:NO];
  93. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  94. self.settingsViewController.modalPresentationStyle = UIModalPresentationFormSheet;
  95. [appDelegate.playlistViewController.navigationController presentModalViewController:self.settingsViewController animated:YES];
  96. }
  97. - (NSString *)_currentIPAddress
  98. {
  99. NSString *address = @"";
  100. struct ifaddrs *interfaces = NULL;
  101. struct ifaddrs *temp_addr = NULL;
  102. int success = getifaddrs(&interfaces);
  103. if (success == 0) {
  104. temp_addr = interfaces;
  105. while(temp_addr != NULL) {
  106. if(temp_addr->ifa_addr->sa_family == AF_INET) {
  107. if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"])
  108. address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
  109. }
  110. temp_addr = temp_addr->ifa_next;
  111. }
  112. }
  113. // Free memory
  114. freeifaddrs(interfaces);
  115. return address;
  116. }
  117. - (IBAction)toggleHTTPServer:(UISwitch *)sender
  118. {
  119. _uploadController = [[VLCHTTPUploaderController alloc] init];
  120. [_uploadController changeHTTPServerState: sender.on];
  121. HTTPServer *server = _uploadController.httpServer;
  122. if (server.isRunning)
  123. self.httpUploadServerLocationLabel.text = [NSString stringWithFormat:@"http://%@:%i", [self _currentIPAddress], server.listeningPort];
  124. else
  125. self.httpUploadServerLocationLabel.text = NSLocalizedString(@"HTTP_UPLOAD_SERVER_OFF", @"");
  126. }
  127. @end