VLCLocalServerListViewController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0 , 11.0f, self.navigationController.view.frame.size.width, 21.0f)];
  48. [_titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];
  49. [_titleLabel setBackgroundColor:[UIColor clearColor]];
  50. [_titleLabel setTextColor:[UIColor colorWithRed:255.0 green:255.0 blue:255.0 alpha:1.0]];
  51. [_titleLabel setText:@"Local Servers"];
  52. [_titleLabel setTextAlignment:UITextAlignmentCenter];
  53. self.navigationItem.titleView = _titleLabel;
  54. }
  55. - (IBAction)goBack:(id)sender
  56. {
  57. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  58. }
  59. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
  60. {
  61. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  62. return NO;
  63. return YES;
  64. }
  65. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  66. {
  67. return 1;
  68. }
  69. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  70. {
  71. return _devices.count;
  72. }
  73. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  74. {
  75. cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor colorWithWhite:.122 alpha:1.];
  76. }
  77. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  78. {
  79. static NSString *CellIdentifier = @"LocalNetworkCell";
  80. VLCLocalNetworkListCell *cell = (VLCLocalNetworkListCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  81. if (cell == nil)
  82. cell = [VLCLocalNetworkListCell cellWithReuseIdentifier:CellIdentifier];
  83. BasicUPnPDevice *device = _devices[indexPath.row];
  84. [cell setTitle:[device friendlyName]];
  85. if([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaServer:1"])
  86. [cell setIsDirectory:YES];
  87. return cell;
  88. }
  89. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  90. {
  91. /*
  92. BasicUPnPDevice *device = _devices[indexPath.row];
  93. if([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaServer:1"]){
  94. MediaServer1Device *server = (MediaServer1Device*)device;
  95. FolderViewController *targetViewController = [[FolderViewController alloc] initWithMediaDevice:server andHeader:@"root" andRootId:@"0"];
  96. [[self navigationController] pushViewController:targetViewController animated:YES];
  97. [[PlayBack GetInstance] setServer:server];
  98. }else if([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaRenderer:1"]){
  99. [self.titleLabel setText:[device friendlyName]];
  100. MediaRenderer1Device *render = (MediaRenderer1Device*)device;
  101. [[PlayBack GetInstance] setRenderer:render];
  102. }*/
  103. }
  104. //protocol UPnPDBObserver
  105. -(void)UPnPDBWillUpdate:(UPnPDB*)sender{
  106. APLog(@"UPnPDBWillUpdate %d", _devices.count);
  107. }
  108. -(void)UPnPDBUpdated:(UPnPDB*)sender{
  109. APLog(@"UPnPDBUpdated %d", _devices.count);
  110. [self.tableView performSelectorOnMainThread : @ selector(reloadData) withObject:nil waitUntilDone:YES];
  111. }
  112. @end