CCDetail.m 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. //
  2. // CCDetail.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 16/01/15.
  6. // Copyright (c) 2014 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCDetail.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #ifdef CUSTOM_BUILD
  27. #import "CustomSwift.h"
  28. #else
  29. #import "Nextcloud-Swift.h"
  30. #endif
  31. #define TOOLBAR_HEIGHT 49.0f
  32. #define alertRequestPasswordPDF 1
  33. @interface CCDetail () <CCActionsDeleteDelegate>
  34. {
  35. UIToolbar *_toolbar;
  36. UIBarButtonItem *_buttonAction;
  37. UIBarButtonItem *_buttonShare;
  38. UIBarButtonItem *_buttonDelete;
  39. BOOL _reload;
  40. NSMutableOrderedSet *_dataSourceDirectoryID;
  41. }
  42. @end
  43. @implementation CCDetail
  44. #pragma --------------------------------------------------------------------------------------------
  45. #pragma mark ===== init =====
  46. #pragma --------------------------------------------------------------------------------------------
  47. - (id)initWithCoder:(NSCoder *)aDecoder
  48. {
  49. if (self = [super initWithCoder:aDecoder]) {
  50. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(insertGeocoderLocation:) name:@"insertGeocoderLocation" object:nil];
  51. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  52. self.metadataDetail = [[CCMetadata alloc] init];
  53. self.photos = [[NSMutableArray alloc] init];
  54. self.thumbs = [[NSMutableArray alloc] init];
  55. self.dataSourceImagesVideos = [[NSMutableArray alloc] init];
  56. _dataSourceDirectoryID = [[NSMutableOrderedSet alloc] init];
  57. self.indexNowVisible = 0;
  58. self.fileIDNowVisible = nil;
  59. app.activeDetail = self;
  60. }
  61. return self;
  62. }
  63. #pragma --------------------------------------------------------------------------------------------
  64. #pragma mark ===== View =====
  65. #pragma --------------------------------------------------------------------------------------------
  66. - (void)viewDidLoad
  67. {
  68. [super viewDidLoad];
  69. self.imageBackground.image = [UIImage imageNamed:image_brandBackgroundLite];
  70. if ([self.metadataDetail.fileName length] > 0 || [self.metadataDetail.directoryID length] > 0 || [self.metadataDetail.fileID length] > 0) {
  71. // open view
  72. [self viewFile];
  73. }
  74. }
  75. // Apparirà
  76. - (void)viewWillAppear:(BOOL)animated
  77. {
  78. [super viewWillAppear:animated];
  79. if (self.splitViewController.isCollapsed) {
  80. self.tabBarController.tabBar.hidden = YES;
  81. self.tabBarController.tabBar.translucent = YES;
  82. }
  83. if (self.splitViewController.isCollapsed)
  84. [app plusButtonVisibile:false];
  85. }
  86. - (void)viewDidAppear:(BOOL)animated
  87. {
  88. [super viewDidAppear:animated];
  89. }
  90. // E' scomparso
  91. - (void)viewDidDisappear:(BOOL)animated
  92. {
  93. [super viewDidDisappear:animated];
  94. // remove all
  95. if (self.isMovingFromParentViewController)
  96. [self removeAllView];
  97. }
  98. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  99. {
  100. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  101. }];
  102. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  103. }
  104. // remove all view
  105. - (void)removeAllView
  106. {
  107. // Audio
  108. if (app.player)
  109. [app.player removeFromSuperview];
  110. // Document
  111. if (_webView) {
  112. [_webView removeFromSuperview];
  113. _webView = nil;
  114. }
  115. // PDF
  116. if (_readerPDFViewController) {
  117. [_readerPDFViewController.view removeFromSuperview];
  118. _readerPDFViewController.delegate = nil;
  119. _readerPDFViewController = nil;
  120. }
  121. // Photo-Video
  122. if (_photoBrowser) {
  123. [_photos removeAllObjects];
  124. [_thumbs removeAllObjects];
  125. _photoBrowser.delegate = nil;
  126. _photoBrowser = nil;
  127. }
  128. [self.navigationController popToRootViewControllerAnimated:NO];
  129. self.navigationController.navigationBarHidden = YES;
  130. }
  131. - (void)changeToDisplayMode
  132. {
  133. if (_readerPDFViewController)
  134. [self.readerPDFViewController updateContentViews];
  135. }
  136. - (void)createToolbar
  137. {
  138. _toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - TOOLBAR_HEIGHT, self.view.bounds.size.width, TOOLBAR_HEIGHT)];
  139. UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  140. UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
  141. fixedSpaceMini.width = 25;
  142. _buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:image_actionSheetOpenIn] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
  143. _buttonShare = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:image_actionSheetShare] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
  144. _buttonDelete = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteButtonPressed:)];
  145. [_toolbar setItems:[NSArray arrayWithObjects: flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction, nil]];
  146. [_toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  147. [self.view addSubview:_toolbar];
  148. }
  149. #pragma --------------------------------------------------------------------------------------------
  150. #pragma mark ===== UIDocumentInteractionControllerDelegate =====
  151. #pragma --------------------------------------------------------------------------------------------
  152. - (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller
  153. {
  154. // evitiamo il rimando della eventuale photo e/o video
  155. if ([CCCoreData getCameraUploadActiveAccount:app.activeAccount]) {
  156. [CCCoreData setCameraUploadDatePhoto:[NSDate date]];
  157. [CCCoreData setCameraUploadDateVideo:[NSDate date]];
  158. }
  159. }
  160. #pragma --------------------------------------------------------------------------------------------
  161. #pragma mark ===== View File =====
  162. #pragma --------------------------------------------------------------------------------------------
  163. - (void)viewFile
  164. {
  165. // verifico se esiste l'icona e se la posso creare
  166. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, self.metadataDetail.fileID]] == NO) {
  167. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{
  168. [CCGraphics createNewImageFrom:self.metadataDetail.fileID directoryUser:app.directoryUser fileNameTo:self.metadataDetail.fileID fileNamePrint:self.metadataDetail.fileNamePrint size:@"m" imageForUpload:NO typeFile:self.metadataDetail.typeFile writePreview:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
  169. });
  170. }
  171. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_video]) {
  172. self.edgesForExtendedLayout = UIRectEdgeAll;
  173. [self viewImage];
  174. }
  175. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  176. self.edgesForExtendedLayout = UIRectEdgeBottom;
  177. [self viewAudio];
  178. [self createToolbar];
  179. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  180. }
  181. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document]) {
  182. NSString *ext = [[self.metadataDetail.fileNamePrint pathExtension] lowercaseString];
  183. if ([ext isEqualToString:@"pdf"]) {
  184. self.edgesForExtendedLayout = UIRectEdgeBottom;
  185. [self viewPDF:@""];
  186. [self createToolbar];
  187. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  188. } else {
  189. self.edgesForExtendedLayout = UIRectEdgeBottom;
  190. [self viewDocument];
  191. [self createToolbar];
  192. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  193. }
  194. }
  195. }
  196. #pragma --------------------------------------------------------------------------------------------
  197. #pragma mark ===== View Audio =====
  198. #pragma --------------------------------------------------------------------------------------------
  199. - (void)viewAudio
  200. {
  201. NSString *fileName;
  202. if (_sourceDirectoryLocal) {
  203. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  204. } else {
  205. fileName = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryAudio], self.metadataDetail.fileNamePrint];
  206. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  207. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  208. }
  209. app.player.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  210. app.player.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  211. app.player.nextButton.hidden = true;
  212. app.player.previousButton.hidden = true;
  213. app.player.fullscreenButton_.hidden = true;
  214. LMMediaItem *item = [[LMMediaItem alloc] initWithInfo:@{LMMediaItemInfoURLKey:[NSURL fileURLWithPath:fileName], LMMediaItemInfoContentTypeKey:@(LMMediaItemContentTypeVideo)}];
  215. item.title = self.metadataDetail.fileNamePrint;
  216. item.artist = k_brand;
  217. [app.player.mediaPlayer removeAllMediaInQueue];
  218. [app.player.mediaPlayer addMedia:item];
  219. [app.player.mediaPlayer play];
  220. // Info
  221. NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
  222. [songInfo setObject:app.player.mediaPlayer.nowPlayingItem.title forKey:MPMediaItemPropertyTitle];
  223. [songInfo setObject:app.player.mediaPlayer.nowPlayingItem.artist forKey:MPMediaItemPropertyArtist];
  224. [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
  225. [self.view addSubview:app.player];
  226. }
  227. #pragma --------------------------------------------------------------------------------------------
  228. #pragma mark ===== View Document =====
  229. #pragma --------------------------------------------------------------------------------------------
  230. - (void)viewDocument
  231. {
  232. NSString *fileName;
  233. if (_sourceDirectoryLocal) {
  234. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  235. } else {
  236. fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNamePrint];
  237. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  238. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  239. }
  240. NSString *ext=@"";
  241. ext = [CCUtility getExtension:self.metadataDetail.fileNamePrint];
  242. WKPreferences *wkPreferences = [[WKPreferences alloc] init];
  243. wkPreferences.javaScriptEnabled = false;
  244. WKWebViewConfiguration *wkConfig = [[WKWebViewConfiguration alloc] init];
  245. wkConfig.preferences = wkPreferences;
  246. self.webView = [[WKWebView alloc] initWithFrame:(CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT)) configuration:wkConfig];
  247. self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  248. [self.webView setBackgroundColor:[UIColor whiteColor]];
  249. [self.webView setOpaque:NO];
  250. if ( [ext isEqualToString:@"CSS"] || [ext isEqualToString:@"PY"] || [ext isEqualToString:@"XML"] || [ext isEqualToString:@"JS"] ) {
  251. NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]];
  252. [headRequest setHTTPMethod:@"HEAD"];
  253. NSHTTPURLResponse *headResponse;
  254. NSError *error = nil;
  255. [NSURLConnection sendSynchronousRequest:headRequest returningResponse:&headResponse error:&error];
  256. if (error != nil) {
  257. NSLog(@"[LOG] loadURLWithString %@",[error localizedDescription]);
  258. }
  259. NSString *dataFile = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL fileURLWithPath:fileName]] encoding:NSASCIIStringEncoding];
  260. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  261. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"40",@"Sans-Serif",dataFile] baseURL:nil];
  262. }else{
  263. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"20",@"Sans-Serif",dataFile] baseURL:nil];
  264. }
  265. } else if ([ext isEqualToString:@"TXT"] ) {
  266. NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]];
  267. [headRequest setHTTPMethod:@"HEAD"];
  268. NSHTTPURLResponse *headResponse;
  269. NSError *error = nil;
  270. [NSURLConnection sendSynchronousRequest:headRequest returningResponse:&headResponse error:&error];
  271. if (error != nil) {
  272. NSLog(@"[LOG] loadURLWithString %@",[error localizedDescription]);
  273. }
  274. [self.webView loadRequest:[NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]]];
  275. } else {
  276. [self.webView loadRequest:[NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]]];
  277. }
  278. [self.view addSubview:self.webView];
  279. }
  280. #pragma --------------------------------------------------------------------------------------------
  281. #pragma mark ===== View Image =====
  282. #pragma --------------------------------------------------------------------------------------------
  283. - (void)viewImage
  284. {
  285. self.photoBrowser = [[MWPhotoBrowser alloc] initWithDelegate:self];
  286. _reload = NO;
  287. [self.photos removeAllObjects];
  288. [self.thumbs removeAllObjects];
  289. [_dataSourceDirectoryID removeAllObjects];
  290. // if not images, exit
  291. if ([self.dataSourceImagesVideos count] == 0) return;
  292. NSUInteger index = 0;
  293. for (CCMetadata *metadata in self.dataSourceImagesVideos) {
  294. // start from here ?
  295. if (self.metadataDetail.fileID && [metadata.fileID isEqualToString:self.metadataDetail.fileID])
  296. [self.photoBrowser setCurrentPhotoIndex:index];
  297. if (metadata.cryptated) {
  298. [self.photos addObject:[MWPhoto photoWithImage:[UIImage imageNamed:image_filePreviewDownloadCrypto]]];
  299. [self.thumbs addObject:[MWPhoto photoWithImage:[UIImage imageNamed:image_filePreviewDownloadCrypto]]];
  300. } else {
  301. [self.photos addObject:[MWPhoto photoWithImage:[UIImage imageNamed:image_filePreviewDownload]]];
  302. MWPhoto *thumb = [MWPhoto photoWithImage:[UIImage imageNamed:image_filePreviewDownload]];
  303. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) thumb.isVideo = YES;
  304. [self.thumbs addObject:thumb];
  305. }
  306. // add directory
  307. [_dataSourceDirectoryID addObject:metadata.directoryID];
  308. index++;
  309. }
  310. // PhotoBrowser
  311. self.photoBrowser.displayActionButton = YES;
  312. self.photoBrowser.displayDeleteButton = YES;
  313. self.photoBrowser.displayNavArrows = YES;
  314. self.photoBrowser.displaySelectionButtons = NO;
  315. self.photoBrowser.alwaysShowControls = NO;
  316. self.photoBrowser.zoomPhotosToFill = NO;
  317. self.photoBrowser.startOnGrid = NO;
  318. self.photoBrowser.autoPlayOnAppear = NO;
  319. self.photoBrowser.delayToHideElements = 15;
  320. self.photoBrowser.enableGrid = YES;
  321. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  322. [self addChildViewController:self.photoBrowser];
  323. [self.view addSubview:self.photoBrowser.view];
  324. [self.photoBrowser didMoveToParentViewController:self];
  325. } else {
  326. [self.navigationController pushViewController:self.photoBrowser animated:NO];
  327. }
  328. }
  329. - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
  330. {
  331. return [self.dataSourceImagesVideos count];
  332. }
  333. - (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
  334. {
  335. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  336. NSString *titleDir = metadata.fileNamePrint; //[NSString stringWithFormat:@"%lu %@ %lu", (unsigned long)index+1, NSLocalizedString(@"of", nil), (unsigned long)self.photos.count];
  337. self.title = titleDir;
  338. return titleDir;
  339. }
  340. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
  341. {
  342. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  343. NSString *directory;
  344. self.indexNowVisible = index;
  345. self.fileIDNowVisible = metadata.fileID;
  346. photoBrowser.toolbar.hidden = NO;
  347. if (_reload) {
  348. [self.photoBrowser performSelector:@selector(reloadData) withObject:nil afterDelay:0.1];
  349. _reload = NO;
  350. }
  351. if (_sourceDirectoryLocal)
  352. directory = self.metadataDetail.directoryID;
  353. else
  354. directory = app.directoryUser;
  355. // Download
  356. if (metadata && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]] == NO && [metadata.session length] == 0)
  357. [self performSelector:@selector(downloadPhotoBrowser:) withObject:metadata afterDelay:0.1];
  358. // Title
  359. if (metadata && !photoBrowser.isGridController)
  360. self.title = metadata.fileNamePrint;
  361. }
  362. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
  363. {
  364. NSString *directory;
  365. UIImage *image;
  366. if (_sourceDirectoryLocal)
  367. directory = self.metadataDetail.directoryID;
  368. else
  369. directory = app.directoryUser;
  370. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  371. //NSLog(@"[LOG] photoBrowser: photoAtIndex : %lu ---- di totali photo : %lu", (unsigned long)index, (unsigned long)_photos.count);
  372. if (index < self.photos.count) {
  373. if (metadata.fileID) {
  374. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  375. NSString *fileImage = [NSString stringWithFormat:@"%@/%@", directory, metadata.fileID];
  376. NSString *ext = [CCUtility getExtension:metadata.fileNamePrint];
  377. if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  378. else image = [UIImage imageWithContentsOfFile:fileImage];
  379. if (image) {
  380. MWPhoto *photo = [MWPhoto photoWithImage:image];
  381. // Location ??
  382. [self setLocationCaptionPhoto:photo fileID:metadata.fileID];
  383. if (!photo.caption) {
  384. // Remove title foto caption
  385. //photo.caption = metadata.fileNamePrint;
  386. }
  387. [self.photos replaceObjectAtIndex:index withObject:photo];
  388. } else {
  389. if ([metadata.sessionError length] > 0 ) {
  390. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:image_filePreviewError]]];
  391. } else {
  392. NSURL *url = [[NSBundle mainBundle] URLForResource:@"loading" withExtension:@"gif"];
  393. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage animatedImageWithAnimatedGIFURL:url]]];
  394. }
  395. }
  396. }
  397. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  398. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]]) {
  399. // remove and make the simbolic link in temp
  400. NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint];
  401. [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
  402. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID] toPath:toPath error:nil];
  403. NSURL *url = [NSURL fileURLWithPath:toPath];
  404. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  405. video.caption = metadata.fileNamePrint;
  406. video.videoURL = url;
  407. [self.photos replaceObjectAtIndex:index withObject:video];
  408. } else {
  409. if ([metadata.sessionError length] > 0 ) {
  410. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:image_filePreviewError]]];
  411. } else {
  412. NSURL *url = [[NSBundle mainBundle] URLForResource:@"loading" withExtension:@"gif"];
  413. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage animatedImageWithAnimatedGIFURL:url]]];
  414. }
  415. }
  416. }
  417. }
  418. // energy saving memory
  419. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  420. int iPrev = (int)index - 2;
  421. if (iPrev >= 0) {
  422. if ([self.photos objectAtIndex:iPrev] != nil)
  423. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  424. }
  425. int iNext = (int)index + 2;
  426. if (iNext < _photos.count) {
  427. if ([self.photos objectAtIndex:iNext] != nil)
  428. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  429. }
  430. });
  431. return [self.photos objectAtIndex:index];
  432. }
  433. return nil;
  434. }
  435. - (void)gridWillAppear:(MWPhotoBrowser *)photoBrowser
  436. {
  437. // reload [BUG]
  438. [self.photoBrowser reloadData];
  439. // in grid clear all MWPhoto : energy saving memory
  440. if (self.photos.count > 1 && [self.dataSourceImagesVideos count] > 0) {
  441. for(int index=0; index < self.photos.count; index++)
  442. [_photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:nil]];
  443. }
  444. self.title = [NSString stringWithFormat:@"Album %lu %@", (unsigned long)_photos.count, NSLocalizedString(@"photos", nil)];
  445. }
  446. - (void)gridWillDisappear:(MWPhotoBrowser *)photoBrowser
  447. {
  448. //
  449. photoBrowser.toolbar.hidden = NO;
  450. }
  451. - (void)setControlsHidden:(BOOL)hidden animated:(BOOL)animated permanent:(BOOL)permanent
  452. {
  453. // Control Center
  454. if (self.splitViewController.isCollapsed)
  455. [app.controlCenter setControlCenterHidden:hidden];
  456. self.navigationController.navigationBar.hidden = hidden;
  457. }
  458. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index
  459. {
  460. NSString *directory;
  461. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  462. if (_sourceDirectoryLocal)
  463. directory = self.metadataDetail.directoryID;
  464. else
  465. directory = app.directoryUser;
  466. if (index < self.thumbs.count) {
  467. if (metadata.fileID) {
  468. UIImage *image;
  469. if (_sourceDirectoryLocal) {
  470. image = [CCGraphics createNewImageFrom:metadata.fileID directoryUser:directory fileNameTo:metadata.fileID fileNamePrint:metadata.fileNamePrint size:@"m" imageForUpload:NO typeFile:metadata.typeFile writePreview:NO optimizedFileName:[CCUtility getOptimizedPhoto]];
  471. } else {
  472. NSString *fileImage = [NSString stringWithFormat:@"%@/%@.ico", directory, metadata.fileID];
  473. image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  474. }
  475. if (image) {
  476. MWPhoto *thumb = [MWPhoto photoWithImage:image];
  477. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) thumb.isVideo = YES;
  478. [self.thumbs replaceObjectAtIndex:index withObject:thumb];
  479. }
  480. }
  481. return [self.thumbs objectAtIndex:index];
  482. }
  483. return nil;
  484. }
  485. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
  486. {
  487. NSString *filePath;
  488. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  489. if (metadata == nil) return;
  490. if (_sourceDirectoryLocal) {
  491. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  492. } else {
  493. filePath = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  494. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  495. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:filePath error:nil];
  496. }
  497. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  498. self.docController.delegate = self;
  499. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) [self.docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  500. [self.docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  501. }
  502. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  503. {
  504. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  505. [app.activeMain openWindowShare:metadata];
  506. }
  507. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  508. {
  509. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  510. if (metadata == nil || [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]] == NO) {
  511. [app messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  512. return;
  513. }
  514. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  515. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  516. style:UIAlertActionStyleDestructive
  517. handler:^(UIAlertAction *action) {
  518. [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
  519. }]];
  520. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  521. style:UIAlertActionStyleCancel
  522. handler:^(UIAlertAction *action) {
  523. [alertController dismissViewControllerAnimated:YES completion:nil];
  524. }]];
  525. alertController.popoverPresentationController.barButtonItem = deleteButton;
  526. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  527. [alertController.view layoutIfNeeded];
  528. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  529. }
  530. - (void)triggerProgressTask:(NSNotification *)notification
  531. {
  532. NSDictionary *dict = notification.userInfo;
  533. float progress = [[dict valueForKey:@"progress"] floatValue];
  534. if (progress == 0)
  535. [self.navigationController cancelCCProgress];
  536. else
  537. [self.navigationController setCCProgressPercentage:progress*100 andTintColor:COLOR_NAVIGATIONBAR_PROGRESS];
  538. }
  539. - (void)downloadPhotoBrowserFailure:(NSInteger)errorCode
  540. {
  541. [app messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  542. [self.photoBrowser reloadData];
  543. }
  544. - (void)downloadPhotoBrowserSuccess:(CCMetadata *)metadataVar selector:(NSString *)selector
  545. {
  546. NSUInteger index = 0;
  547. // if a message for a directory of these
  548. if (![_dataSourceDirectoryID containsObject:metadataVar.directoryID])
  549. return;
  550. for (NSUInteger i=0; i < [self.dataSourceImagesVideos count]; i++ ) {
  551. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:i];
  552. // search index
  553. if ([metadataVar.fileID isEqualToString:metadata.fileID]) {
  554. index = i;
  555. break;
  556. }
  557. }
  558. // do not reload is Video on air
  559. if (_photoBrowser.currentVideoPlayerViewController.isViewLoaded && _photoBrowser.currentVideoPlayerViewController.view.window) return;
  560. //NSLog(@"[LOG] Add Download Photo Browser");
  561. if ([metadataVar.fileID isEqualToString:self.fileIDNowVisible] || [self.photoBrowser isGridReload:index]) {
  562. [self.photoBrowser reloadData];
  563. _reload = NO;
  564. } else {
  565. _reload = YES;
  566. }
  567. }
  568. - (void)downloadPhotoBrowser:(CCMetadata *)metadata
  569. {
  570. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  571. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadViewImage selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:nil];
  572. }
  573. - (void)insertGeocoderLocation:(NSNotification *)notification
  574. {
  575. NSString *fileID = [[notification.userInfo allKeys] objectAtIndex:0];
  576. //NSDate *date = [[notification.userInfo allValues] objectAtIndex:0];
  577. // test [Chrash V 1.14,15]
  578. if (self.indexNowVisible >= [self.photos count])
  579. return;
  580. dispatch_async(dispatch_get_main_queue(), ^{
  581. if ([fileID isEqualToString:self.fileIDNowVisible]) {
  582. MWPhoto *photo = [self.photos objectAtIndex:self.indexNowVisible];
  583. [self setLocationCaptionPhoto:photo fileID:fileID];
  584. if (![self.photoBrowser isGridController]) {
  585. [self.photoBrowser hideControls];
  586. [self.photoBrowser showControls];
  587. }
  588. }
  589. });
  590. }
  591. - (void)setLocationCaptionPhoto:(MWPhoto *)photo fileID:(NSString *)fileID
  592. {
  593. TableLocalFile *localFile;
  594. // read Geocoder
  595. localFile = [CCCoreData getLocalFileWithFileID:fileID activeAccount:app.activeAccount];
  596. if ([localFile.exifLatitude doubleValue] != 0 || [localFile.exifLongitude doubleValue] != 0) {
  597. // Fix BUG Geo latitude & longitude
  598. if ([localFile.exifLatitude doubleValue] == 9999 || [localFile.exifLongitude doubleValue] == 9999) {
  599. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount] context:nil];
  600. [CCExifGeo setExifLocalTableFileID:metadata directoryUser:app.directoryUser activeAccount:app.activeAccount];
  601. }
  602. [CCExifGeo setGeocoderFileID:fileID exifDate:localFile.exifDate latitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  603. localFile = [CCCoreData getLocalFileWithFileID:fileID activeAccount:app.activeAccount];
  604. if ([localFile.exifLatitude floatValue] != 0 || [localFile.exifLongitude floatValue] != 0) {
  605. NSString *location = [CCCoreData getLocationFromGeoLatitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  606. if ([localFile.exifDate isEqualToDate:[NSDate distantPast]] == NO && location) {
  607. NSString *localizedDateTime = [NSDateFormatter localizedStringFromDate:localFile.exifDate dateStyle:NSDateFormatterFullStyle timeStyle:NSDateFormatterMediumStyle];
  608. photo.caption = [NSString stringWithFormat:NSLocalizedString(@"%@\n%@", nil), localizedDateTime, location];
  609. }
  610. }
  611. }
  612. }
  613. #pragma --------------------------------------------------------------------------------------------
  614. #pragma mark ===== View PDF =====
  615. #pragma --------------------------------------------------------------------------------------------
  616. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  617. {
  618. [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
  619. [[alertView textFieldAtIndex:0] resignFirstResponder];
  620. if (alertView.tag == alertRequestPasswordPDF) [self performSelector:@selector(viewPDF:) withObject:[alertView textFieldAtIndex:0].text afterDelay:0.3];
  621. }
  622. - (void)viewPDF:(NSString *)password
  623. {
  624. NSString *fileName;
  625. if (_sourceDirectoryLocal) {
  626. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  627. } else {
  628. fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNamePrint];
  629. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  630. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  631. }
  632. if ([[NSFileManager defaultManager] fileExistsAtPath:fileName isDirectory:nil] == NO) {
  633. // read file error
  634. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  635. [alertView show];
  636. }
  637. CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileName]);
  638. if (pdf) {
  639. // Encrypted
  640. if (CGPDFDocumentIsEncrypted(pdf) == YES) {
  641. // Try a blank password first, per Apple's Quartz PDF example
  642. if (CGPDFDocumentUnlockWithPassword(pdf, "") == YES) {
  643. // blank password
  644. [self readerPDF:fileName password:@""];
  645. } else {
  646. if ([password length] == 0) {
  647. // password request
  648. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_insert_password_pfd_",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  649. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  650. alertView.tag = alertRequestPasswordPDF;
  651. [alertView show];
  652. } else {
  653. const char *key = [password UTF8String];
  654. // failure
  655. if (CGPDFDocumentUnlockWithPassword(pdf, key) == NO) {
  656. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_password_pdf_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  657. [alertView show];
  658. } else {
  659. // pdf with password
  660. [self readerPDF:fileName password:password];
  661. }
  662. }
  663. }
  664. } else{
  665. // No password
  666. [self readerPDF:fileName password:@""];
  667. }
  668. } else {
  669. // read file error
  670. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  671. [alertView show];
  672. }
  673. }
  674. - (void)readerPDF:(NSString *)fileName password:(NSString *)password
  675. {
  676. ReaderDocument *documentPDF = [ReaderDocument withDocumentFilePath:fileName password:password];
  677. if (documentPDF != nil) {
  678. self.readerPDFViewController = [[ReaderViewController alloc] initWithReaderDocument:documentPDF];
  679. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  680. [self.readerPDFViewController updateContentViews];
  681. [self addChildViewController:self.readerPDFViewController];
  682. [self.view addSubview:self.readerPDFViewController.view];
  683. [self.readerPDFViewController didMoveToParentViewController:self];
  684. } else {
  685. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  686. [alertView show];
  687. }
  688. }
  689. #pragma --------------------------------------------------------------------------------------------
  690. #pragma mark ===== Delete =====
  691. #pragma --------------------------------------------------------------------------------------------
  692. - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  693. {
  694. NSLog(@"[LOG] delete failure");
  695. }
  696. - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
  697. {
  698. // if a message for a directory of these
  699. if (![_dataSourceDirectoryID containsObject:metadataNet.metadata.directoryID])
  700. return;
  701. // if we are not in browserPhoto and it's removed photo/video in preview then "< Back"
  702. if (!self.photoBrowser && [self.metadataDetail.fileID isEqualToString:metadataNet.metadata.fileID]) {
  703. if ([metadataNet.metadata.typeFile isEqualToString: k_metadataTypeFile_audio])
  704. [app.player.mediaPlayer stop];
  705. NSArray *viewsToRemove = [self.view subviews];
  706. for (id element in viewsToRemove) {
  707. if ([element isMemberOfClass:[UIView class]] || [element isMemberOfClass:[UIToolbar class]] || [element isMemberOfClass:[LMMediaPlayerView class]])
  708. [element removeFromSuperview];
  709. }
  710. self.title = @"";
  711. [self.navigationController popViewControllerAnimated:YES];
  712. } else {
  713. // only photoBrowser if exists
  714. for (NSUInteger index=0; index < [self.dataSourceImagesVideos count] && _photoBrowser; index++ ) {
  715. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  716. // ricerca index
  717. if ([metadataNet.metadata.fileID isEqualToString:metadata.fileID]) {
  718. [self.dataSourceImagesVideos removeObjectAtIndex:index];
  719. [self.photos removeObjectAtIndex:index];
  720. [self.thumbs removeObjectAtIndex:index];
  721. [self.photoBrowser reloadData];
  722. // Title
  723. if ([self.dataSourceImagesVideos count] == 0) {
  724. self.title = @"";
  725. [self.navigationController popViewControllerAnimated:YES];
  726. }
  727. break;
  728. }
  729. }
  730. }
  731. }
  732. #pragma --------------------------------------------------------------------------------------------
  733. #pragma mark ===== ButtonPressed =====
  734. #pragma --------------------------------------------------------------------------------------------
  735. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  736. {
  737. NSString *filePath;
  738. if ([self.metadataDetail.fileNamePrint length] == 0) return;
  739. if (_sourceDirectoryLocal) {
  740. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  741. } else {
  742. filePath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), self.metadataDetail.fileNamePrint];
  743. }
  744. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  745. self.docController.delegate = self;
  746. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  747. [self.docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  748. }
  749. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  750. {
  751. [app.activeMain openWindowShare:self.metadataDetail];
  752. }
  753. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  754. {
  755. if ([self.metadataDetail.fileNamePrint length] == 0) return;
  756. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  757. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  758. style:UIAlertActionStyleDestructive
  759. handler:^(UIAlertAction *action) {
  760. [[CCActions sharedInstance] deleteFileOrFolder:self.metadataDetail delegate:self];
  761. }]];
  762. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  763. style:UIAlertActionStyleCancel
  764. handler:^(UIAlertAction *action) {
  765. [alertController dismissViewControllerAnimated:YES completion:nil];
  766. }]];
  767. alertController.popoverPresentationController.barButtonItem = _buttonDelete;
  768. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  769. [alertController.view layoutIfNeeded];
  770. [self presentViewController:alertController animated:YES completion:NULL];
  771. }
  772. @end