CCDetail.m 44 KB

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