CCDetail.m 45 KB

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