VLCLocalServerFolderListViewController.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /*****************************************************************************
  2. * VLCLocalServerFolderListViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Pierre SAGASPE <pierre.sagaspe # me.com>
  10. *
  11. * Refer to the COPYING file of the official project for license.
  12. *****************************************************************************/
  13. #import "VLCLocalServerFolderListViewController.h"
  14. #import "MediaServerBasicObjectParser.h"
  15. #import "MediaServer1ItemObject.h"
  16. #import "MediaServer1ContainerObject.h"
  17. #import "MediaServer1Device.h"
  18. #import "VLCLocalNetworkListCell.h"
  19. #import "VLCAppDelegate.h"
  20. #import "VLCPlaylistViewController.h"
  21. #import "UINavigationController+Theme.h"
  22. #import "VLCDownloadViewController.h"
  23. #import "WhiteRaccoon.h"
  24. #import "NSString+SupportedMedia.h"
  25. #import "VLCStatusLabel.h"
  26. #define kVLCServerTypeUPNP 0
  27. #define kVLCServerTypeFTP 1
  28. @interface VLCLocalServerFolderListViewController () <UITableViewDataSource, UITableViewDelegate, WRRequestDelegate, VLCLocalNetworkListCell, UISearchBarDelegate, UISearchDisplayDelegate>
  29. {
  30. /* UI */
  31. UIBarButtonItem *_backButton;
  32. /* generic data storage */
  33. NSString *_listTitle;
  34. NSArray *_objectList;
  35. NSMutableArray *_mutableObjectList;
  36. NSUInteger _serverType;
  37. /* UPNP specifics */
  38. MediaServer1Device *_UPNPdevice;
  39. NSString *_UPNProotID;
  40. /* FTP specifics */
  41. NSString *_ftpServerAddress;
  42. NSString *_ftpServerUserName;
  43. NSString *_ftpServerPassword;
  44. NSString *_ftpServerPath;
  45. WRRequestListDirectory *_FTPListDirRequest;
  46. NSMutableArray *_searchData;
  47. UISearchBar *_searchBar;
  48. UISearchDisplayController *_searchDisplayController;
  49. }
  50. @end
  51. @implementation VLCLocalServerFolderListViewController
  52. - (void)loadView
  53. {
  54. _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
  55. _tableView.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
  56. _tableView.delegate = self;
  57. _tableView.dataSource = self;
  58. _tableView.rowHeight = [VLCLocalNetworkListCell heightOfCell];
  59. self.view = _tableView;
  60. }
  61. - (id)initWithUPNPDevice:(MediaServer1Device*)device header:(NSString*)header andRootID:(NSString*)rootID
  62. {
  63. self = [super init];
  64. if (self) {
  65. _UPNPdevice = device;
  66. _listTitle = header;
  67. _UPNProotID = rootID;
  68. _serverType = kVLCServerTypeUPNP;
  69. _mutableObjectList = [[NSMutableArray alloc] init];
  70. }
  71. return self;
  72. }
  73. - (id)initWithFTPServer:(NSString *)serverAddress userName:(NSString *)username andPassword:(NSString *)password atPath:(NSString *)path
  74. {
  75. self = [super init];
  76. if (self) {
  77. _ftpServerAddress = serverAddress;
  78. _ftpServerUserName = username;
  79. _ftpServerPassword = password;
  80. _ftpServerPath = path;
  81. _serverType = kVLCServerTypeFTP;
  82. }
  83. return self;
  84. }
  85. - (void)viewDidLoad
  86. {
  87. [super viewDidLoad];
  88. if (_serverType == kVLCServerTypeUPNP) {
  89. NSMutableString *outResult = [[NSMutableString alloc] init];
  90. NSMutableString *outNumberReturned = [[NSMutableString alloc] init];
  91. NSMutableString *outTotalMatches = [[NSMutableString alloc] init];
  92. NSMutableString *outUpdateID = [[NSMutableString alloc] init];
  93. [[_UPNPdevice contentDirectory] BrowseWithObjectID:_UPNProotID BrowseFlag:@"BrowseDirectChildren" Filter:@"*" StartingIndex:@"0" RequestedCount:@"0" SortCriteria:@"+dc:title" OutResult:outResult OutNumberReturned:outNumberReturned OutTotalMatches:outTotalMatches OutUpdateID:outUpdateID];
  94. [_mutableObjectList removeAllObjects];
  95. NSData *didl = [outResult dataUsingEncoding:NSUTF8StringEncoding];
  96. MediaServerBasicObjectParser *parser = [[MediaServerBasicObjectParser alloc] initWithMediaObjectArray:_mutableObjectList itemsOnly:NO];
  97. [parser parseFromData:didl];
  98. } else if (_serverType == kVLCServerTypeFTP) {
  99. if ([_ftpServerPath isEqualToString:@"/"])
  100. _listTitle = _ftpServerAddress;
  101. else
  102. _listTitle = [_ftpServerPath lastPathComponent];
  103. [self _listFTPDirectory];
  104. }
  105. self.tableView.separatorColor = [UIColor colorWithWhite:.122 alpha:1.];
  106. self.view.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
  107. self.title = _listTitle;
  108. _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
  109. _searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
  110. _searchDisplayController.delegate = self;
  111. _searchDisplayController.searchResultsDataSource = self;
  112. _searchDisplayController.searchResultsDelegate = self;
  113. _searchDisplayController.searchBar.searchBarStyle = UIBarStyleBlack;
  114. _searchBar.delegate = self;
  115. self.tableView.tableHeaderView = _searchBar; //this line add the searchBar on the top of tableView.
  116. _searchData = [[NSMutableArray alloc] init];
  117. [_searchData removeAllObjects];
  118. }
  119. - (BOOL)shouldAutorotate
  120. {
  121. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  122. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  123. return NO;
  124. return YES;
  125. }
  126. #pragma mark - Table view data source
  127. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  128. {
  129. return 1;
  130. }
  131. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  132. {
  133. if (tableView == self.searchDisplayController.searchResultsTableView)
  134. return _searchData.count;
  135. else {
  136. if (_serverType == kVLCServerTypeUPNP)
  137. return _mutableObjectList.count;
  138. return _objectList.count;
  139. }
  140. }
  141. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  142. {
  143. static NSString *CellIdentifier = @"LocalNetworkCellDetail";
  144. VLCLocalNetworkListCell *cell = (VLCLocalNetworkListCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  145. if (cell == nil)
  146. cell = [VLCLocalNetworkListCell cellWithReuseIdentifier:CellIdentifier];
  147. if (_serverType == kVLCServerTypeUPNP) {
  148. MediaServer1BasicObject *item;
  149. if (tableView == self.searchDisplayController.searchResultsTableView)
  150. item = _searchData[indexPath.row];
  151. else
  152. item = _mutableObjectList[indexPath.row];
  153. if (![item isContainer]) {
  154. MediaServer1ItemObject *mediaItem;
  155. long long mediaSize = 0;
  156. unsigned int durationInSeconds = 0;
  157. unsigned int bitrate = 0;
  158. if (tableView == self.searchDisplayController.searchResultsTableView)
  159. mediaItem = _searchData[indexPath.row];
  160. else
  161. mediaItem = _mutableObjectList[indexPath.row];
  162. MediaServer1ItemRes *resource = nil;
  163. NSEnumerator *e = [[mediaItem resources] objectEnumerator];
  164. while((resource = (MediaServer1ItemRes*)[e nextObject])){
  165. if (resource.bitrate > 0 && resource.durationInSeconds > 0) {
  166. mediaSize = resource.size;
  167. durationInSeconds = resource.durationInSeconds;
  168. bitrate = resource.bitrate;
  169. }
  170. }
  171. NSURL *itemURL;
  172. NSArray *uriCollectionKeys = [[mediaItem uriCollection] allKeys];
  173. NSUInteger count = uriCollectionKeys.count;
  174. NSRange position;
  175. NSUInteger correctIndex = 0;
  176. for (NSUInteger i = 0; i < count; i++) {
  177. position = [uriCollectionKeys[i] rangeOfString:@"http-get:*:video/"];
  178. if (position.location != NSNotFound)
  179. correctIndex = i;
  180. }
  181. NSArray *uriCollectionObjects = [[mediaItem uriCollection] allValues];
  182. itemURL = [NSURL URLWithString:uriCollectionObjects[correctIndex]];
  183. cell.downloadURL = itemURL;
  184. if (mediaSize < 1)
  185. mediaSize = [mediaItem.size longLongValue];
  186. if (mediaSize < 1)
  187. mediaSize = (bitrate * durationInSeconds);
  188. [cell setSubtitle: [NSString stringWithFormat:@"%@ (%@)", [NSByteCountFormatter stringFromByteCount:mediaSize countStyle:NSByteCountFormatterCountStyleFile], [VLCTime timeWithInt:durationInSeconds * 1000].stringValue]];
  189. [cell setIsDirectory:NO];
  190. cell.isDownloadable = YES;
  191. if (![mediaItem.albumArt isEqualToString:NULL])
  192. [cell setIconURL:[NSURL URLWithString:mediaItem.albumArt]];
  193. [cell setIcon:[UIImage imageNamed:@"blank"]];
  194. cell.delegate = self;
  195. } else {
  196. [cell setIsDirectory:YES];
  197. [cell setIcon:[UIImage imageNamed:@"folder"]];
  198. }
  199. [cell setTitle:[item title]];
  200. } else if (_serverType == kVLCServerTypeFTP) {
  201. NSMutableArray *ObjList = [[NSMutableArray alloc] init];
  202. [ObjList removeAllObjects];
  203. if (tableView == self.searchDisplayController.searchResultsTableView)
  204. [ObjList addObjectsFromArray:_searchData];
  205. else
  206. [ObjList addObjectsFromArray:_objectList];
  207. NSString *rawFileName = [ObjList[indexPath.row] objectForKey:(id)kCFFTPResourceName];
  208. NSData *flippedData = [rawFileName dataUsingEncoding:NSMacOSRomanStringEncoding];
  209. cell.title = [[NSString alloc] initWithData:flippedData encoding:NSUTF8StringEncoding];
  210. if ([[ObjList[indexPath.row] objectForKey:(id)kCFFTPResourceType] intValue] == 4) {
  211. cell.isDirectory = YES;
  212. cell.icon = [UIImage imageNamed:@"folder"];
  213. } else {
  214. cell.isDirectory = NO;
  215. cell.icon = [UIImage imageNamed:@"blank"];
  216. cell.subtitle = [NSString stringWithFormat:@"%0.2f MB", (float)([[ObjList[indexPath.row] objectForKey:(id)kCFFTPResourceSize] intValue] / 1e6)];
  217. cell.isDownloadable = YES;
  218. cell.delegate = self;
  219. }
  220. }
  221. return cell;
  222. }
  223. #pragma mark - Table view delegate
  224. - (void)tableView:(UITableView *)tableView willDisplayCell:(VLCLocalNetworkListCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  225. {
  226. UIColor *color = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor colorWithWhite:.122 alpha:1.];
  227. cell.contentView.backgroundColor = cell.titleLabel.backgroundColor = cell.folderTitleLabel.backgroundColor = cell.subtitleLabel.backgroundColor = color;
  228. }
  229. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  230. {
  231. if (_serverType == kVLCServerTypeUPNP) {
  232. MediaServer1BasicObject *item;
  233. if (tableView == self.searchDisplayController.searchResultsTableView)
  234. item = _searchData[indexPath.row];
  235. else
  236. item = _mutableObjectList[indexPath.row];
  237. if ([item isContainer]) {
  238. MediaServer1ContainerObject *container;
  239. if (tableView == self.searchDisplayController.searchResultsTableView)
  240. container = _searchData[indexPath.row];
  241. else
  242. container = _mutableObjectList[indexPath.row];
  243. VLCLocalServerFolderListViewController *targetViewController = [[VLCLocalServerFolderListViewController alloc] initWithUPNPDevice:_UPNPdevice header:[container title] andRootID:[container objectID]];
  244. [[self navigationController] pushViewController:targetViewController animated:YES];
  245. } else {
  246. MediaServer1ItemObject *mediaItem;
  247. if (tableView == self.searchDisplayController.searchResultsTableView)
  248. mediaItem = _searchData[indexPath.row];
  249. else
  250. mediaItem = _mutableObjectList[indexPath.row];
  251. NSURL *itemURL;
  252. NSArray *uriCollectionKeys = [[mediaItem uriCollection] allKeys];
  253. NSUInteger count = uriCollectionKeys.count;
  254. NSRange position;
  255. NSUInteger correctIndex = 0;
  256. for (NSUInteger i = 0; i < count; i++) {
  257. position = [uriCollectionKeys[i] rangeOfString:@"http-get:*:video/"];
  258. if (position.location != NSNotFound)
  259. correctIndex = i;
  260. }
  261. NSArray *uriCollectionObjects = [[mediaItem uriCollection] allValues];
  262. itemURL = [NSURL URLWithString:uriCollectionObjects[correctIndex]];
  263. if (itemURL) {
  264. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  265. [appDelegate openMovieFromURL:itemURL];
  266. }
  267. }
  268. } else if (_serverType == kVLCServerTypeFTP) {
  269. NSMutableArray *ObjList = [[NSMutableArray alloc] init];
  270. [ObjList removeAllObjects];
  271. if (tableView == self.searchDisplayController.searchResultsTableView)
  272. [ObjList addObjectsFromArray:_searchData];
  273. else
  274. [ObjList addObjectsFromArray:_objectList];
  275. if ([[ObjList[indexPath.row] objectForKey:(id)kCFFTPResourceType] intValue] == 4) {
  276. NSString *newPath = [NSString stringWithFormat:@"%@/%@", _ftpServerPath, [ObjList[indexPath.row] objectForKey:(id)kCFFTPResourceName]];
  277. VLCLocalServerFolderListViewController *targetViewController = [[VLCLocalServerFolderListViewController alloc] initWithFTPServer:_ftpServerAddress userName:_ftpServerUserName andPassword:_ftpServerPassword atPath:newPath];
  278. [self.navigationController pushViewController:targetViewController animated:YES];
  279. } else {
  280. NSString *rawObjectName = [ObjList[indexPath.row] objectForKey:(id)kCFFTPResourceName];
  281. NSData *flippedData = [rawObjectName dataUsingEncoding:NSMacOSRomanStringEncoding];
  282. NSString *properObjectName = [[NSString alloc] initWithData:flippedData encoding:NSUTF8StringEncoding];
  283. if (![properObjectName isSupportedFormat]) {
  284. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", @"") message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", @""), properObjectName] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"") otherButtonTitles:nil];
  285. [alert show];
  286. } else
  287. [self _streamFTPFile:properObjectName];
  288. }
  289. }
  290. [tableView deselectRowAtIndexPath:indexPath animated:NO];
  291. }
  292. #pragma mark - FTP specifics
  293. - (void)_listFTPDirectory
  294. {
  295. if (_FTPListDirRequest)
  296. return;
  297. _FTPListDirRequest = [[WRRequestListDirectory alloc] init];
  298. _FTPListDirRequest.delegate = self;
  299. _FTPListDirRequest.hostname = _ftpServerAddress;
  300. _FTPListDirRequest.username = _ftpServerUserName;
  301. _FTPListDirRequest.password = _ftpServerPassword;
  302. _FTPListDirRequest.path = _ftpServerPath;
  303. _FTPListDirRequest.passive = YES;
  304. [_FTPListDirRequest start];
  305. }
  306. - (NSString *)_credentials
  307. {
  308. NSString * cred;
  309. if (_ftpServerUserName.length > 0) {
  310. if (_ftpServerPassword.length > 0)
  311. cred = [NSString stringWithFormat:@"%@:%@@", _ftpServerUserName, _ftpServerPassword];
  312. else
  313. cred = [NSString stringWithFormat:@"%@@", _ftpServerPassword];
  314. } else
  315. cred = @"";
  316. return [cred stringByStandardizingPath];
  317. }
  318. - (void)_downloadFTPFile:(NSString *)fileName
  319. {
  320. NSURL *URLToQueue = [NSURL URLWithString:[[@"ftp" stringByAppendingFormat:@"://%@%@/%@/%@", [self _credentials], _ftpServerAddress, _ftpServerPath, fileName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  321. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate downloadViewController] addURLToDownloadList:URLToQueue fileNameOfMedia:nil];
  322. }
  323. - (void)_downloadUPNPFile:(NSURL *)url fileNameOfMedia:(NSString*) fileName;
  324. {
  325. fileName = [[fileName stringByAppendingString:@"."] stringByAppendingString:[[url absoluteString] pathExtension]];
  326. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate downloadViewController] addURLToDownloadList:url fileNameOfMedia:fileName];
  327. }
  328. - (void)requestCompleted:(WRRequest *)request
  329. {
  330. if (request == _FTPListDirRequest) {
  331. NSMutableArray *filteredList = [[NSMutableArray alloc] init];
  332. NSArray *rawList = [(WRRequestListDirectory*)request filesInfo];
  333. NSUInteger count = rawList.count;
  334. for (NSUInteger x = 0; x < count; x++) {
  335. if (![[rawList[x] objectForKey:(id)kCFFTPResourceName] hasPrefix:@"."])
  336. [filteredList addObject:rawList[x]];
  337. }
  338. _objectList = [NSArray arrayWithArray:filteredList];
  339. [self.tableView reloadData];
  340. } else
  341. APLog(@"unknown request %@ completed", request);
  342. }
  343. - (void)requestFailed:(WRRequest *)request
  344. {
  345. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"LOCAL_SERVER_CONNECTION_FAILED_TITLE", nil) message:NSLocalizedString(@"LOCAL_SERVER_CONNECTION_FAILED_MESSAGE", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"") otherButtonTitles:nil];
  346. [alert show];
  347. APLog(@"request %@ failed with error %i", request, request.error.errorCode);
  348. }
  349. #pragma mark - VLCLocalNetworkListCell delegation
  350. - (void)triggerDownloadForCell:(VLCLocalNetworkListCell *)cell
  351. {
  352. if (_serverType == kVLCServerTypeUPNP) {
  353. MediaServer1ItemObject *item;
  354. if ([self.searchDisplayController isActive])
  355. item = _searchData[[self.searchDisplayController.searchResultsTableView indexPathForCell:cell].row];
  356. else
  357. item = _mutableObjectList[[self.tableView indexPathForCell:cell].row];
  358. MediaServer1ItemRes *resource = nil;
  359. NSEnumerator *e = [[item resources] objectEnumerator];
  360. NSURL *itemURL;
  361. while((resource = (MediaServer1ItemRes*)[e nextObject])){
  362. itemURL = [NSURL URLWithString:[[item uri] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  363. }
  364. if (![[item uri] isSupportedFormat]) {
  365. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", @"") message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", @""), [item uri]] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"") otherButtonTitles:nil];
  366. [alert show];
  367. } else {
  368. [self _downloadUPNPFile:itemURL fileNameOfMedia:[item title]];
  369. [cell.statusLabel showStatusMessage:NSLocalizedString(@"DOWNLOADING", @"")];
  370. }
  371. }else if (_serverType == kVLCServerTypeFTP) {
  372. NSString *rawObjectName;
  373. NSMutableArray *ObjList = [[NSMutableArray alloc] init];
  374. [ObjList removeAllObjects];
  375. if ([self.searchDisplayController isActive]) {
  376. [ObjList addObjectsFromArray:_searchData];
  377. rawObjectName = [ObjList[[self.searchDisplayController.searchResultsTableView indexPathForCell:cell].row] objectForKey:(id)kCFFTPResourceName];
  378. } else {
  379. [ObjList addObjectsFromArray:_objectList];
  380. rawObjectName = [ObjList[[self.tableView indexPathForCell:cell].row] objectForKey:(id)kCFFTPResourceName];
  381. }
  382. NSData *flippedData = [rawObjectName dataUsingEncoding:NSMacOSRomanStringEncoding];
  383. NSString *properObjectName = [[NSString alloc] initWithData:flippedData encoding:NSUTF8StringEncoding];
  384. if (![properObjectName isSupportedFormat]) {
  385. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", @"") message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", @""), properObjectName] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"") otherButtonTitles:nil];
  386. [alert show];
  387. } else {
  388. [self _downloadFTPFile:properObjectName];
  389. [cell.statusLabel showStatusMessage:NSLocalizedString(@"DOWNLOADING", @"")];
  390. }
  391. }
  392. }
  393. #pragma mark - communication with playback engine
  394. - (void)_streamFTPFile:(NSString *)fileName
  395. {
  396. NSURL *URLToPlay = [NSURL URLWithString:[[@"ftp" stringByAppendingFormat:@"://%@%@/%@/%@", [self _credentials], _ftpServerAddress, _ftpServerPath, fileName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  397. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  398. [appDelegate openMovieFromURL:URLToPlay];
  399. }
  400. #pragma mark - Search Display Controller Delegate
  401. - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
  402. {
  403. MediaServer1BasicObject *item;
  404. NSInteger listCount = 0;
  405. [_searchData removeAllObjects];
  406. if (_serverType == kVLCServerTypeUPNP)
  407. listCount = _mutableObjectList.count;
  408. else if (_serverType == kVLCServerTypeFTP)
  409. listCount = _objectList.count;
  410. for (int i = 0; i < listCount; i++) {
  411. NSRange nameRange;
  412. if (_serverType == kVLCServerTypeUPNP) {
  413. item = _mutableObjectList[i];
  414. nameRange = [[item title] rangeOfString:searchString options:NSCaseInsensitiveSearch];
  415. } else if (_serverType == kVLCServerTypeFTP) {
  416. NSString *rawObjectName = [_objectList[i] objectForKey:(id)kCFFTPResourceName];
  417. NSData *flippedData = [rawObjectName dataUsingEncoding:NSMacOSRomanStringEncoding];
  418. NSString *properObjectName = [[NSString alloc] initWithData:flippedData encoding:NSUTF8StringEncoding];
  419. nameRange = [properObjectName rangeOfString:searchString options:NSCaseInsensitiveSearch];
  420. }
  421. if (nameRange.location != NSNotFound) {
  422. if (_serverType == kVLCServerTypeUPNP)
  423. [_searchData addObject:_mutableObjectList[i]];
  424. else
  425. [_searchData addObject:_objectList[i]];
  426. }
  427. }
  428. return YES;
  429. }
  430. - (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
  431. {
  432. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  433. tableView.rowHeight = 80.0f;
  434. else
  435. tableView.rowHeight = 68.0f;
  436. tableView.backgroundColor = [UIColor blackColor];
  437. }
  438. @end