VLCLocalServerListViewController.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // VLCLocalServerListViewController.m
  3. // VLC for iOS
  4. //
  5. // Created by Felix Paul Kühne on 10.08.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. // Refer to the COPYING file of the official project for license.
  9. //
  10. #import "VLCLocalServerListViewController.h"
  11. #import "UIBarButtonItem+Theme.h"
  12. #import "VLCAppDelegate.h"
  13. #import "UPnPManager.h"
  14. #import "VLCLocalNetworkListCell.h"
  15. @interface VLCLocalServerListViewController () <UITableViewDataSource, UITableViewDelegate>
  16. {
  17. UIBarButtonItem *_backButton;
  18. UIBarButtonItem *_backToMenuButton;
  19. UILabel *_titleLabel;
  20. NSArray *_devices;
  21. }
  22. @end
  23. @implementation VLCLocalServerListViewController
  24. - (void)loadView
  25. {
  26. _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
  27. _tableView.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
  28. _tableView.delegate = self;
  29. _tableView.dataSource = self;
  30. self.view = _tableView;
  31. }
  32. - (void)viewDidLoad
  33. {
  34. [super viewDidLoad];
  35. UPnPDB* db = [[UPnPManager GetInstance] DB];
  36. _devices = [db rootDevices]; //BasicUPnPDevice
  37. [db addObserver:(UPnPDBObserver*)self];
  38. //Optional; set User Agent
  39. [[[UPnPManager GetInstance] SSDP] setUserAgentProduct:[NSString stringWithFormat:@"VLC for iOS/%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]] andOS:@"iOS"];
  40. //Search for UPnP Devices
  41. [[[UPnPManager GetInstance] SSDP] searchSSDP];
  42. _backButton = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(goBack:)];
  43. _backToMenuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(goBack:)];
  44. self.navigationItem.leftBarButtonItem = _backToMenuButton;
  45. self.tableView.separatorColor = [UIColor colorWithWhite:.122 alpha:1.];
  46. self.view.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
  47. self.title = @"Local Servers";
  48. self.navigationItem.titleView = _titleLabel;
  49. }
  50. - (IBAction)goBack:(id)sender
  51. {
  52. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  53. }
  54. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
  55. {
  56. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  57. return NO;
  58. return YES;
  59. }
  60. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  61. {
  62. return 1;
  63. }
  64. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  65. {
  66. return _devices.count;
  67. }
  68. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  69. {
  70. cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor colorWithWhite:.122 alpha:1.];
  71. }
  72. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  73. {
  74. static NSString *CellIdentifier = @"LocalNetworkCell";
  75. VLCLocalNetworkListCell *cell = (VLCLocalNetworkListCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  76. if (cell == nil)
  77. cell = [VLCLocalNetworkListCell cellWithReuseIdentifier:CellIdentifier];
  78. BasicUPnPDevice *device = _devices[indexPath.row];
  79. [cell setTitle:[device friendlyName]];
  80. if([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaServer:1"])
  81. [cell setIsDirectory:YES];
  82. return cell;
  83. }
  84. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  85. {
  86. /*
  87. BasicUPnPDevice *device = _devices[indexPath.row];
  88. if([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaServer:1"]){
  89. MediaServer1Device *server = (MediaServer1Device*)device;
  90. FolderViewController *targetViewController = [[FolderViewController alloc] initWithMediaDevice:server andHeader:@"root" andRootId:@"0"];
  91. [[self navigationController] pushViewController:targetViewController animated:YES];
  92. [[PlayBack GetInstance] setServer:server];
  93. }else if([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaRenderer:1"]){
  94. [self.titleLabel setText:[device friendlyName]];
  95. MediaRenderer1Device *render = (MediaRenderer1Device*)device;
  96. [[PlayBack GetInstance] setRenderer:render];
  97. }*/
  98. }
  99. //protocol UPnPDBObserver
  100. -(void)UPnPDBWillUpdate:(UPnPDB*)sender{
  101. APLog(@"UPnPDBWillUpdate %d", _devices.count);
  102. }
  103. -(void)UPnPDBUpdated:(UPnPDB*)sender{
  104. APLog(@"UPnPDBUpdated %d", _devices.count);
  105. [self.tableView performSelectorOnMainThread : @ selector(reloadData) withObject:nil waitUntilDone:YES];
  106. }
  107. @end