CCDetail.m 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. //
  2. // CCDetail.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 16/01/15.
  6. // Copyright (c) 2017 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. #import "NCBridgeSwift.h"
  27. #define TOOLBAR_HEIGHT 49.0f
  28. #define alertRequestPasswordPDF 1
  29. @interface CCDetail () <CCActionsDeleteDelegate>
  30. {
  31. UIToolbar *_toolbar;
  32. UIBarButtonItem *_buttonAction;
  33. UIBarButtonItem *_buttonShare;
  34. UIBarButtonItem *_buttonDelete;
  35. BOOL _reload;
  36. NSMutableOrderedSet *_dataSourceDirectoryID;
  37. }
  38. @end
  39. @implementation CCDetail
  40. #pragma --------------------------------------------------------------------------------------------
  41. #pragma mark ===== init =====
  42. #pragma --------------------------------------------------------------------------------------------
  43. - (id)initWithCoder:(NSCoder *)aDecoder
  44. {
  45. if (self = [super initWithCoder:aDecoder]) {
  46. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  47. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  48. self.metadataDetail = [[tableMetadata alloc] init];
  49. self.photos = [[NSMutableArray alloc] init];
  50. self.thumbs = [[NSMutableArray alloc] init];
  51. self.dataSourceImagesVideos = [[NSMutableArray alloc] init];
  52. _dataSourceDirectoryID = [[NSMutableOrderedSet alloc] init];
  53. self.indexNowVisible = 0;
  54. self.fileIDNowVisible = nil;
  55. app.activeDetail = self;
  56. }
  57. return self;
  58. }
  59. #pragma --------------------------------------------------------------------------------------------
  60. #pragma mark ===== View =====
  61. #pragma --------------------------------------------------------------------------------------------
  62. - (void)viewDidLoad
  63. {
  64. [super viewDidLoad];
  65. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(insertGeocoderLocation:) name:@"insertGeocoderLocation" object:nil];
  66. self.imageBackground.image = [UIImage imageNamed:@"backgroundDetail"];
  67. if ([self.metadataDetail.fileName length] > 0 || [self.metadataDetail.directoryID length] > 0 || [self.metadataDetail.fileID length] > 0) {
  68. // open view
  69. [self viewFile];
  70. }
  71. }
  72. // Apparirà
  73. - (void)viewWillAppear:(BOOL)animated
  74. {
  75. [super viewWillAppear:animated];
  76. if (self.splitViewController.isCollapsed) {
  77. self.tabBarController.tabBar.hidden = YES;
  78. self.tabBarController.tabBar.translucent = YES;
  79. }
  80. if (self.splitViewController.isCollapsed)
  81. [app plusButtonVisibile:false];
  82. }
  83. // E' scomparso
  84. - (void)viewDidDisappear:(BOOL)animated
  85. {
  86. [super viewDidDisappear:animated];
  87. // remove all
  88. if (self.isMovingFromParentViewController)
  89. [self removeAllView];
  90. }
  91. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  92. {
  93. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  94. }];
  95. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  96. }
  97. // remove all view
  98. - (void)removeAllView
  99. {
  100. // Audio
  101. if (app.player)
  102. [app.player removeFromSuperview];
  103. // Document
  104. if (_webView) {
  105. [_webView removeFromSuperview];
  106. _webView = nil;
  107. }
  108. // PDF
  109. if (_readerPDFViewController) {
  110. [_readerPDFViewController.view removeFromSuperview];
  111. _readerPDFViewController.delegate = nil;
  112. _readerPDFViewController = nil;
  113. }
  114. // Photo-Video
  115. if (_photoBrowser) {
  116. [_photos removeAllObjects];
  117. [_thumbs removeAllObjects];
  118. _photoBrowser.delegate = nil;
  119. _photoBrowser = nil;
  120. }
  121. [self.navigationController popToRootViewControllerAnimated:NO];
  122. self.navigationController.navigationBarHidden = YES;
  123. }
  124. - (void)changeToDisplayMode
  125. {
  126. if (_readerPDFViewController)
  127. [self.readerPDFViewController updateContentViews];
  128. }
  129. - (void)createToolbar
  130. {
  131. _toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - TOOLBAR_HEIGHT, self.view.bounds.size.width, TOOLBAR_HEIGHT)];
  132. UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  133. UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
  134. fixedSpaceMini.width = 25;
  135. _buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetOpenIn"] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
  136. _buttonShare = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetShare"] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
  137. _buttonDelete = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteButtonPressed:)];
  138. [_toolbar setItems:[NSArray arrayWithObjects: flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction, nil]];
  139. [_toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  140. _toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  141. [self.view addSubview:_toolbar];
  142. }
  143. - (void)changeTheming
  144. {
  145. if (self.isViewLoaded && self.view.window)
  146. [app changeTheming:self];
  147. }
  148. #pragma --------------------------------------------------------------------------------------------
  149. #pragma mark ===== UIDocumentInteractionControllerDelegate =====
  150. #pragma --------------------------------------------------------------------------------------------
  151. - (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller
  152. {
  153. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  154. // evitiamo il rimando della eventuale photo e/o video
  155. if (tableAccount.cameraUpload) {
  156. [[NCManageDatabase sharedInstance] setAccountCameraUploadDateAssetType:PHAssetMediaTypeImage assetDate:[NSDate date]];
  157. [[NCManageDatabase sharedInstance] setAccountCameraUploadDateAssetType:PHAssetMediaTypeVideo assetDate:[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. [app 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. [app 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. [app 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 = [NCBrandOptions sharedInstance].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 (tableMetadata *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:@"filePreviewDownloadCrypto"]]];
  299. [self.thumbs addObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownloadCrypto"]]];
  300. } else {
  301. [self.photos addObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownload"]]];
  302. MWPhoto *thumb = [MWPhoto photoWithImage:[UIImage imageNamed:@"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. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  336. NSString *titleDir = metadata.fileNamePrint;
  337. self.title = titleDir;
  338. return titleDir;
  339. }
  340. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
  341. {
  342. tableMetadata *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. tableMetadata *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. [self.photos replaceObjectAtIndex:index withObject:photo];
  384. } else {
  385. if ([metadata.sessionError length] > 0 ) {
  386. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  387. } else {
  388. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[CCUtility drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button"] colorText:[UIColor lightGrayColor]]]];
  389. }
  390. }
  391. }
  392. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  393. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]]) {
  394. // remove and make the simbolic link in temp
  395. NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint];
  396. [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
  397. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID] toPath:toPath error:nil];
  398. NSURL *url = [NSURL fileURLWithPath:toPath];
  399. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  400. video.videoURL = url;
  401. [self.photos replaceObjectAtIndex:index withObject:video];
  402. } else {
  403. if ([metadata.sessionError length] > 0 ) {
  404. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  405. } else {
  406. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[CCUtility drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button"] colorText:[UIColor lightGrayColor]]]];
  407. }
  408. }
  409. }
  410. }
  411. // energy saving memory
  412. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  413. int iPrev = (int)index - 2;
  414. if (iPrev >= 0) {
  415. if ([self.photos objectAtIndex:iPrev] != nil)
  416. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  417. }
  418. int iNext = (int)index + 2;
  419. if (iNext < _photos.count) {
  420. if ([self.photos objectAtIndex:iNext] != nil)
  421. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  422. }
  423. });
  424. return [self.photos objectAtIndex:index];
  425. }
  426. return nil;
  427. }
  428. - (void)gridWillAppear:(MWPhotoBrowser *)photoBrowser
  429. {
  430. // reload [BUG]
  431. [self.photoBrowser reloadData];
  432. // in grid clear all MWPhoto : energy saving memory
  433. if (self.photos.count > 1 && [self.dataSourceImagesVideos count] > 0) {
  434. for(int index=0; index < self.photos.count; index++)
  435. [_photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:nil]];
  436. }
  437. self.title = [NSString stringWithFormat:@"Album %lu %@", (unsigned long)_photos.count, NSLocalizedString(@"photos", nil)];
  438. }
  439. - (void)gridWillDisappear:(MWPhotoBrowser *)photoBrowser
  440. {
  441. //
  442. photoBrowser.toolbar.hidden = NO;
  443. }
  444. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index
  445. {
  446. NSString *directory;
  447. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  448. if (_sourceDirectoryLocal)
  449. directory = self.metadataDetail.directoryID;
  450. else
  451. directory = app.directoryUser;
  452. if (index < self.thumbs.count) {
  453. if (metadata.fileID) {
  454. UIImage *image;
  455. if (_sourceDirectoryLocal) {
  456. 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]];
  457. } else {
  458. NSString *fileImage = [NSString stringWithFormat:@"%@/%@.ico", directory, metadata.fileID];
  459. image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  460. }
  461. if (image) {
  462. MWPhoto *thumb = [MWPhoto photoWithImage:image];
  463. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) thumb.isVideo = YES;
  464. [self.thumbs replaceObjectAtIndex:index withObject:thumb];
  465. }
  466. }
  467. return [self.thumbs objectAtIndex:index];
  468. }
  469. return nil;
  470. }
  471. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
  472. {
  473. NSString *filePath;
  474. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  475. if (metadata == nil) return;
  476. if (_sourceDirectoryLocal) {
  477. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  478. } else {
  479. filePath = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  480. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  481. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:filePath error:nil];
  482. }
  483. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  484. self.docController.delegate = self;
  485. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) [self.docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  486. [self.docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  487. }
  488. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  489. {
  490. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  491. [app.activeMain openWindowShare:metadata];
  492. }
  493. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  494. {
  495. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  496. if (metadata == nil || [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]] == NO) {
  497. [app messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  498. return;
  499. }
  500. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  501. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  502. style:UIAlertActionStyleDestructive
  503. handler:^(UIAlertAction *action) {
  504. [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
  505. }]];
  506. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  507. style:UIAlertActionStyleCancel
  508. handler:^(UIAlertAction *action) {
  509. [alertController dismissViewControllerAnimated:YES completion:nil];
  510. }]];
  511. alertController.popoverPresentationController.barButtonItem = deleteButton;
  512. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  513. [alertController.view layoutIfNeeded];
  514. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  515. }
  516. - (void)triggerProgressTask:(NSNotification *)notification
  517. {
  518. NSDictionary *dict = notification.userInfo;
  519. float progress = [[dict valueForKey:@"progress"] floatValue];
  520. if (progress == 0)
  521. [self.navigationController cancelCCProgress];
  522. else
  523. [self.navigationController setCCProgressPercentage:progress*100 andTintColor:[NCBrandColor sharedInstance].navigationBarProgress];
  524. }
  525. - (void)downloadPhotoBrowserFailure:(NSInteger)errorCode
  526. {
  527. [app messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  528. [self.photoBrowser reloadData];
  529. }
  530. - (void)downloadPhotoBrowserSuccess:(tableMetadata *)metadataVar selector:(NSString *)selector
  531. {
  532. NSUInteger index = 0;
  533. // if a message for a directory of these
  534. if (![_dataSourceDirectoryID containsObject:metadataVar.directoryID])
  535. return;
  536. for (NSUInteger i=0; i < [self.dataSourceImagesVideos count]; i++ ) {
  537. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:i];
  538. // search index
  539. if ([metadataVar.fileID isEqualToString:metadata.fileID]) {
  540. index = i;
  541. break;
  542. }
  543. }
  544. // do not reload is Video on air
  545. if (_photoBrowser.currentVideoPlayerViewController.isViewLoaded && _photoBrowser.currentVideoPlayerViewController.view.window) return;
  546. //NSLog(@"[LOG] Add Download Photo Browser");
  547. if ([metadataVar.fileID isEqualToString:self.fileIDNowVisible] || [self.photoBrowser isGridReload:index]) {
  548. [self.photoBrowser reloadData];
  549. _reload = NO;
  550. } else {
  551. _reload = YES;
  552. }
  553. }
  554. - (void)downloadPhotoBrowser:(tableMetadata *)metadata
  555. {
  556. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  557. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadViewImage selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:nil];
  558. }
  559. - (void)insertGeocoderLocation:(NSNotification *)notification
  560. {
  561. if (notification.userInfo.count == 0)
  562. return;
  563. NSString *fileID = [[notification.userInfo allKeys] objectAtIndex:0];
  564. //NSDate *date = [[notification.userInfo allValues] objectAtIndex:0];
  565. // test [Chrash V 1.14,15]
  566. if (self.indexNowVisible >= [self.photos count])
  567. return;
  568. if ([fileID isEqualToString:self.fileIDNowVisible]) {
  569. MWPhoto *photo = [self.photos objectAtIndex:self.indexNowVisible];
  570. [self setLocationCaptionPhoto:photo fileID:fileID];
  571. if (![self.photoBrowser isGridController]) {
  572. //[self.photoBrowser hideControls];
  573. //[self.photoBrowser showControls];
  574. }
  575. }
  576. }
  577. - (void)setLocationCaptionPhoto:(MWPhoto *)photo fileID:(NSString *)fileID
  578. {
  579. TableLocalFile *localFile;
  580. // read Geocoder
  581. localFile = [CCCoreData getLocalFileWithFileID:fileID activeAccount:app.activeAccount];
  582. if ([localFile.exifLatitude doubleValue] != 0 || [localFile.exifLongitude doubleValue] != 0) {
  583. // Fix BUG Geo latitude & longitude
  584. if ([localFile.exifLatitude doubleValue] == 9999 || [localFile.exifLongitude doubleValue] == 9999) {
  585. tableMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount] context:nil];
  586. [CCExifGeo setExifLocalTableFileID:metadata directoryUser:app.directoryUser activeAccount:app.activeAccount];
  587. }
  588. [CCExifGeo setGeocoderFileID:fileID exifDate:localFile.exifDate latitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  589. localFile = [CCCoreData getLocalFileWithFileID:fileID activeAccount:app.activeAccount];
  590. if ([localFile.exifLatitude floatValue] != 0 || [localFile.exifLongitude floatValue] != 0) {
  591. NSString *location = [[NCManageDatabase sharedInstance] getLocationFromGeoLatitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  592. if ([localFile.exifDate isEqualToDate:[NSDate distantPast]] == NO && location) {
  593. NSString *localizedDateTime = [NSDateFormatter localizedStringFromDate:localFile.exifDate dateStyle:NSDateFormatterFullStyle timeStyle:NSDateFormatterMediumStyle];
  594. photo.caption = [NSString stringWithFormat:NSLocalizedString(@"%@\n%@", nil), localizedDateTime, location];
  595. }
  596. }
  597. }
  598. }
  599. #pragma --------------------------------------------------------------------------------------------
  600. #pragma mark ===== View PDF =====
  601. #pragma --------------------------------------------------------------------------------------------
  602. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  603. {
  604. [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
  605. [[alertView textFieldAtIndex:0] resignFirstResponder];
  606. if (alertView.tag == alertRequestPasswordPDF) [self performSelector:@selector(viewPDF:) withObject:[alertView textFieldAtIndex:0].text afterDelay:0.3];
  607. }
  608. - (void)viewPDF:(NSString *)password
  609. {
  610. NSString *fileName;
  611. if (_sourceDirectoryLocal) {
  612. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  613. } else {
  614. fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNamePrint];
  615. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  616. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  617. }
  618. if ([[NSFileManager defaultManager] fileExistsAtPath:fileName isDirectory:nil] == NO) {
  619. // read file error
  620. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  621. [alertView show];
  622. }
  623. CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileName]);
  624. if (pdf) {
  625. // Encrypted
  626. if (CGPDFDocumentIsEncrypted(pdf) == YES) {
  627. // Try a blank password first, per Apple's Quartz PDF example
  628. if (CGPDFDocumentUnlockWithPassword(pdf, "") == YES) {
  629. // blank password
  630. [self readerPDF:fileName password:@""];
  631. } else {
  632. if ([password length] == 0) {
  633. // password request
  634. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_insert_password_pfd_",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  635. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  636. alertView.tag = alertRequestPasswordPDF;
  637. [alertView show];
  638. } else {
  639. const char *key = [password UTF8String];
  640. // failure
  641. if (CGPDFDocumentUnlockWithPassword(pdf, key) == NO) {
  642. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_password_pdf_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  643. [alertView show];
  644. } else {
  645. // pdf with password
  646. [self readerPDF:fileName password:password];
  647. }
  648. }
  649. }
  650. } else{
  651. // No password
  652. [self readerPDF:fileName password:@""];
  653. }
  654. } else {
  655. // read file error
  656. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  657. [alertView show];
  658. }
  659. }
  660. - (void)readerPDF:(NSString *)fileName password:(NSString *)password
  661. {
  662. ReaderDocument *documentPDF = [ReaderDocument withDocumentFilePath:fileName password:password];
  663. if (documentPDF != nil) {
  664. self.readerPDFViewController = [[ReaderViewController alloc] initWithReaderDocument:documentPDF];
  665. self.readerPDFViewController.delegate = self;
  666. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  667. [self.readerPDFViewController updateContentViews];
  668. [self addChildViewController:self.readerPDFViewController];
  669. [self.view addSubview:self.readerPDFViewController.view];
  670. [self.readerPDFViewController didMoveToParentViewController:self];
  671. } else {
  672. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  673. [alertView show];
  674. }
  675. }
  676. - (void)handleSingleTapReader
  677. {
  678. self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
  679. _toolbar.hidden = !_toolbar.isHidden;
  680. if (_toolbar.isHidden) {
  681. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
  682. } else {
  683. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  684. }
  685. [self.readerPDFViewController updateContentViews];
  686. }
  687. #pragma --------------------------------------------------------------------------------------------
  688. #pragma mark ===== Delete =====
  689. #pragma --------------------------------------------------------------------------------------------
  690. - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  691. {
  692. NSLog(@"[LOG] delete failure");
  693. }
  694. - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
  695. {
  696. // reload Main
  697. [app.activeMain reloadDatasource];
  698. // If removed document (web) or PDF close
  699. if (_webView || _readerPDFViewController)
  700. [self removeAllView];
  701. // if a message for a directory of these
  702. if (![_dataSourceDirectoryID containsObject:metadataNet.metadata.directoryID])
  703. return;
  704. // if we are not in browserPhoto and it's removed photo/video in preview then "< Back"
  705. if (!self.photoBrowser && [self.metadataDetail.fileID isEqualToString:metadataNet.metadata.fileID]) {
  706. if ([metadataNet.metadata.typeFile isEqualToString: k_metadataTypeFile_audio])
  707. [app.player.mediaPlayer stop];
  708. NSArray *viewsToRemove = [self.view subviews];
  709. for (id element in viewsToRemove) {
  710. if ([element isMemberOfClass:[UIView class]] || [element isMemberOfClass:[UIToolbar class]] || [element isMemberOfClass:[LMMediaPlayerView class]])
  711. [element removeFromSuperview];
  712. }
  713. self.title = @"";
  714. [self.navigationController popViewControllerAnimated:YES];
  715. } else {
  716. // only photoBrowser if exists
  717. for (NSUInteger index=0; index < [self.dataSourceImagesVideos count] && _photoBrowser; index++ ) {
  718. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  719. // ricerca index
  720. if ([metadataNet.metadata.fileID isEqualToString:metadata.fileID]) {
  721. [self.dataSourceImagesVideos removeObjectAtIndex:index];
  722. [self.photos removeObjectAtIndex:index];
  723. [self.thumbs removeObjectAtIndex:index];
  724. [self.photoBrowser reloadData];
  725. // Title
  726. if ([self.dataSourceImagesVideos count] == 0) {
  727. self.title = @"";
  728. [self.navigationController popViewControllerAnimated:YES];
  729. }
  730. break;
  731. }
  732. }
  733. }
  734. }
  735. #pragma --------------------------------------------------------------------------------------------
  736. #pragma mark ===== ButtonPressed =====
  737. #pragma --------------------------------------------------------------------------------------------
  738. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  739. {
  740. NSString *filePath;
  741. if ([self.metadataDetail.fileNamePrint length] == 0) return;
  742. if (_sourceDirectoryLocal) {
  743. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  744. } else {
  745. filePath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), self.metadataDetail.fileNamePrint];
  746. }
  747. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  748. self.docController.delegate = self;
  749. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  750. [self.docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  751. }
  752. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  753. {
  754. [app.activeMain openWindowShare:self.metadataDetail];
  755. }
  756. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  757. {
  758. if ([self.metadataDetail.fileNamePrint length] == 0) return;
  759. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  760. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  761. style:UIAlertActionStyleDestructive
  762. handler:^(UIAlertAction *action) {
  763. [[CCActions sharedInstance] deleteFileOrFolder:self.metadataDetail delegate:self];
  764. }]];
  765. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  766. style:UIAlertActionStyleCancel
  767. handler:^(UIAlertAction *action) {
  768. [alertController dismissViewControllerAnimated:YES completion:nil];
  769. }]];
  770. alertController.popoverPresentationController.barButtonItem = _buttonDelete;
  771. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  772. [alertController.view layoutIfNeeded];
  773. [self presentViewController:alertController animated:YES completion:NULL];
  774. }
  775. @end