CCDetail.m 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. //
  2. // CCDetail.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 16/01/15.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCDetail.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #import "NCBridgeSwift.h"
  27. #define TOOLBAR_HEIGHT 49.0f
  28. #define alertRequestPasswordPDF 1
  29. @interface CCDetail () <CCActionsDeleteDelegate>
  30. {
  31. AppDelegate *appDelegate;
  32. UIToolbar *_toolbar;
  33. UIBarButtonItem *_buttonAction;
  34. UIBarButtonItem *_buttonShare;
  35. UIBarButtonItem *_buttonDelete;
  36. NSInteger _indexNowVisible;
  37. NSString *_fileIDNowVisible;
  38. BOOL _reload;
  39. NSMutableOrderedSet *_dataSourceDirectoryID;
  40. }
  41. @end
  42. @implementation CCDetail
  43. #pragma --------------------------------------------------------------------------------------------
  44. #pragma mark ===== init =====
  45. #pragma --------------------------------------------------------------------------------------------
  46. - (id)initWithCoder:(NSCoder *)aDecoder
  47. {
  48. if (self = [super initWithCoder:aDecoder]) {
  49. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  50. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  51. self.metadataDetail = [[tableMetadata alloc] init];
  52. self.photos = [[NSMutableArray alloc] init];
  53. self.thumbs = [[NSMutableArray alloc] init];
  54. self.dataSourceImagesVideos = [[NSMutableArray alloc] init];
  55. _dataSourceDirectoryID = [[NSMutableOrderedSet alloc] init];
  56. _indexNowVisible = -1;
  57. _fileIDNowVisible = nil;
  58. app.activeDetail = self;
  59. }
  60. return self;
  61. }
  62. #pragma --------------------------------------------------------------------------------------------
  63. #pragma mark ===== View =====
  64. #pragma --------------------------------------------------------------------------------------------
  65. - (void)viewDidLoad
  66. {
  67. [super viewDidLoad];
  68. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  69. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(insertGeocoderLocation:) name:@"insertGeocoderLocation" object:nil];
  70. self.imageBackground.image = [UIImage imageNamed:@"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. // 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 (appDelegate.player)
  106. [appDelegate.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. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  158. // evitiamo il rimando della eventuale photo e/o video
  159. if (tableAccount.autoUpload) {
  160. [[NCManageDatabase sharedInstance] setAccountAutoUploadDateAssetType:PHAssetMediaTypeImage assetDate:[NSDate date]];
  161. [[NCManageDatabase sharedInstance] setAccountAutoUploadDateAssetType:PHAssetMediaTypeVideo assetDate:[NSDate date]];
  162. }
  163. }
  164. #pragma --------------------------------------------------------------------------------------------
  165. #pragma mark ===== View File =====
  166. #pragma --------------------------------------------------------------------------------------------
  167. - (void)viewFile
  168. {
  169. // verifico se esiste l'icona e se la posso creare
  170. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, self.metadataDetail.fileID]] == NO) {
  171. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{
  172. [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]];
  173. });
  174. }
  175. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_video]) {
  176. self.edgesForExtendedLayout = UIRectEdgeAll;
  177. [self viewImage];
  178. }
  179. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  180. self.edgesForExtendedLayout = UIRectEdgeBottom;
  181. [self viewAudio];
  182. [self createToolbar];
  183. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  184. }
  185. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document]) {
  186. NSString *ext = [[self.metadataDetail.fileNamePrint pathExtension] lowercaseString];
  187. if ([ext isEqualToString:@"pdf"]) {
  188. self.edgesForExtendedLayout = UIRectEdgeBottom;
  189. [self viewPDF:@""];
  190. [self createToolbar];
  191. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  192. } else {
  193. self.edgesForExtendedLayout = UIRectEdgeBottom;
  194. [self viewDocument];
  195. [self createToolbar];
  196. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  197. }
  198. }
  199. }
  200. #pragma --------------------------------------------------------------------------------------------
  201. #pragma mark ===== View Audio =====
  202. #pragma --------------------------------------------------------------------------------------------
  203. - (void)viewAudio
  204. {
  205. NSString *fileName;
  206. if (_sourceDirectoryLocal) {
  207. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  208. } else {
  209. fileName = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryAudio], self.metadataDetail.fileNamePrint];
  210. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  211. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  212. }
  213. appDelegate.player.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  214. appDelegate.player.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  215. appDelegate.player.nextButton.hidden = true;
  216. appDelegate.player.previousButton.hidden = true;
  217. appDelegate.player.fullscreenButton_.hidden = true;
  218. LMMediaItem *item = [[LMMediaItem alloc] initWithInfo:@{LMMediaItemInfoURLKey:[NSURL fileURLWithPath:fileName], LMMediaItemInfoContentTypeKey:@(LMMediaItemContentTypeVideo)}];
  219. item.title = self.metadataDetail.fileNamePrint;
  220. item.artist = [NCBrandOptions sharedInstance].brand;
  221. [appDelegate.player.mediaPlayer removeAllMediaInQueue];
  222. [appDelegate.player.mediaPlayer addMedia:item];
  223. [appDelegate.player.mediaPlayer play];
  224. // Info
  225. NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
  226. [songInfo setObject:app.player.mediaPlayer.nowPlayingItem.title forKey:MPMediaItemPropertyTitle];
  227. [songInfo setObject:app.player.mediaPlayer.nowPlayingItem.artist forKey:MPMediaItemPropertyArtist];
  228. [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
  229. [self.view addSubview:appDelegate.player];
  230. }
  231. #pragma --------------------------------------------------------------------------------------------
  232. #pragma mark ===== View Document =====
  233. #pragma --------------------------------------------------------------------------------------------
  234. - (void)viewDocument
  235. {
  236. NSString *fileName;
  237. if (_sourceDirectoryLocal) {
  238. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  239. } else {
  240. fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNamePrint];
  241. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  242. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  243. }
  244. NSString *ext=@"";
  245. ext = [CCUtility getExtension:self.metadataDetail.fileNamePrint];
  246. WKPreferences *wkPreferences = [[WKPreferences alloc] init];
  247. wkPreferences.javaScriptEnabled = false;
  248. WKWebViewConfiguration *wkConfig = [[WKWebViewConfiguration alloc] init];
  249. wkConfig.preferences = wkPreferences;
  250. self.webView = [[WKWebView alloc] initWithFrame:(CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT)) configuration:wkConfig];
  251. self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  252. [self.webView setBackgroundColor:[UIColor whiteColor]];
  253. [self.webView setOpaque:NO];
  254. if ( [ext isEqualToString:@"CSS"] || [ext isEqualToString:@"PY"] || [ext isEqualToString:@"XML"] || [ext isEqualToString:@"JS"] ) {
  255. NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]];
  256. [headRequest setHTTPMethod:@"HEAD"];
  257. NSHTTPURLResponse *headResponse;
  258. NSError *error = nil;
  259. [NSURLConnection sendSynchronousRequest:headRequest returningResponse:&headResponse error:&error];
  260. if (error != nil) {
  261. NSLog(@"[LOG] loadURLWithString %@",[error localizedDescription]);
  262. }
  263. NSString *dataFile = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL fileURLWithPath:fileName]] encoding:NSASCIIStringEncoding];
  264. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  265. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"40",@"Sans-Serif",dataFile] baseURL:nil];
  266. }else{
  267. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"20",@"Sans-Serif",dataFile] baseURL:nil];
  268. }
  269. } else if ([ext isEqualToString:@"TXT"] ) {
  270. NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]];
  271. [headRequest setHTTPMethod:@"HEAD"];
  272. NSHTTPURLResponse *headResponse;
  273. NSError *error = nil;
  274. [NSURLConnection sendSynchronousRequest:headRequest returningResponse:&headResponse error:&error];
  275. if (error != nil) {
  276. NSLog(@"[LOG] loadURLWithString %@",[error localizedDescription]);
  277. }
  278. [self.webView loadRequest:[NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]]];
  279. } else {
  280. [self.webView loadRequest:[NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]]];
  281. }
  282. [self.view addSubview:self.webView];
  283. }
  284. #pragma --------------------------------------------------------------------------------------------
  285. #pragma mark ===== View Image =====
  286. #pragma --------------------------------------------------------------------------------------------
  287. - (void)viewImage
  288. {
  289. self.photoBrowser = [[MWPhotoBrowser alloc] initWithDelegate:self];
  290. _reload = NO;
  291. _indexNowVisible = -1;
  292. _fileIDNowVisible = nil;
  293. [self.photos removeAllObjects];
  294. [self.thumbs removeAllObjects];
  295. [_dataSourceDirectoryID removeAllObjects];
  296. // if not images, exit
  297. if ([self.dataSourceImagesVideos count] == 0) return;
  298. NSUInteger index = 0;
  299. for (tableMetadata *metadata in self.dataSourceImagesVideos) {
  300. // start from here ?
  301. if (self.metadataDetail.fileID && [metadata.fileID isEqualToString:self.metadataDetail.fileID])
  302. [self.photoBrowser setCurrentPhotoIndex:index];
  303. if (metadata.cryptated) {
  304. [self.photos addObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownloadCrypto"]]];
  305. [self.thumbs addObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownloadCrypto"]]];
  306. } else {
  307. [self.photos addObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownload"]]];
  308. MWPhoto *thumb = [MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownload"]];
  309. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) thumb.isVideo = YES;
  310. [self.thumbs addObject:thumb];
  311. }
  312. // add directory
  313. [_dataSourceDirectoryID addObject:metadata.directoryID];
  314. index++;
  315. }
  316. // PhotoBrowser
  317. self.photoBrowser.displayActionButton = YES;
  318. self.photoBrowser.displayDeleteButton = YES;
  319. self.photoBrowser.displayNavArrows = YES;
  320. self.photoBrowser.displaySelectionButtons = NO;
  321. self.photoBrowser.alwaysShowControls = NO;
  322. self.photoBrowser.zoomPhotosToFill = NO;
  323. self.photoBrowser.startOnGrid = NO;
  324. self.photoBrowser.autoPlayOnAppear = NO;
  325. self.photoBrowser.delayToHideElements = 15;
  326. self.photoBrowser.enableGrid = YES;
  327. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  328. [self addChildViewController:self.photoBrowser];
  329. [self.view addSubview:self.photoBrowser.view];
  330. [self.photoBrowser didMoveToParentViewController:self];
  331. } else {
  332. [self.navigationController pushViewController:self.photoBrowser animated:NO];
  333. }
  334. }
  335. - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
  336. {
  337. return [self.dataSourceImagesVideos count];
  338. }
  339. - (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
  340. {
  341. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  342. NSString *titleDir = metadata.fileNamePrint;
  343. self.title = titleDir;
  344. return titleDir;
  345. }
  346. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
  347. {
  348. if (index != _indexNowVisible) {
  349. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  350. NSString *directory;
  351. NSString *fileID = metadata.fileID;
  352. _indexNowVisible = index;
  353. _fileIDNowVisible = metadata.fileID;
  354. photoBrowser.toolbar.hidden = NO;
  355. if (_sourceDirectoryLocal)
  356. directory = self.metadataDetail.directoryID;
  357. else
  358. directory = app.directoryUser;
  359. // Download
  360. if (fileID) {
  361. metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  362. if (metadata && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]] == NO && [metadata.session length] == 0)
  363. [self performSelector:@selector(downloadPhotoBrowser:) withObject:metadata afterDelay:0.1];
  364. // Title
  365. if (metadata && !photoBrowser.isGridController)
  366. self.title = metadata.fileNamePrint;
  367. }
  368. }
  369. if (_reload) {
  370. [self.photoBrowser performSelector:@selector(reloadData) withObject:nil];
  371. _reload = NO;
  372. }
  373. }
  374. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
  375. {
  376. NSString *directory;
  377. UIImage *image;
  378. if (_sourceDirectoryLocal)
  379. directory = self.metadataDetail.directoryID;
  380. else
  381. directory = app.directoryUser;
  382. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  383. //NSLog(@"[LOG] photoBrowser: photoAtIndex : %lu ---- di totali photo : %lu", (unsigned long)index, (unsigned long)_photos.count);
  384. if (index < self.photos.count) {
  385. if (metadata.fileID) {
  386. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  387. NSString *fileImage = [NSString stringWithFormat:@"%@/%@", directory, metadata.fileID];
  388. NSString *ext = [CCUtility getExtension:metadata.fileNamePrint];
  389. if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  390. else image = [UIImage imageWithContentsOfFile:fileImage];
  391. if (image) {
  392. MWPhoto *photo = [MWPhoto photoWithImage:image];
  393. // Location ??
  394. [self setLocationCaptionPhoto:photo fileID:metadata.fileID];
  395. [self.photos replaceObjectAtIndex:index withObject:photo];
  396. } else {
  397. if ([metadata.sessionError length] > 0 ) {
  398. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  399. } else {
  400. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[CCUtility drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button1000x200"] colorText:[UIColor darkGrayColor] sizeOfFont:50]]];
  401. }
  402. }
  403. }
  404. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  405. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]]) {
  406. // remove and make the simbolic link in temp
  407. NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint];
  408. [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
  409. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID] toPath:toPath error:nil];
  410. NSURL *url = [NSURL fileURLWithPath:toPath];
  411. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  412. video.videoURL = url;
  413. [self.photos replaceObjectAtIndex:index withObject:video];
  414. } else {
  415. if ([metadata.sessionError length] > 0 ) {
  416. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  417. } else {
  418. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[CCUtility drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button1000x200"] colorText:[UIColor darkGrayColor] sizeOfFont:50]]];
  419. }
  420. }
  421. }
  422. }
  423. // energy saving memory
  424. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  425. int iPrev = (int)index - 2;
  426. if (iPrev >= 0) {
  427. if ([self.photos objectAtIndex:iPrev] != nil)
  428. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  429. }
  430. int iNext = (int)index + 2;
  431. if (iNext < _photos.count) {
  432. if ([self.photos objectAtIndex:iNext] != nil)
  433. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  434. }
  435. });
  436. return [self.photos objectAtIndex:index];
  437. }
  438. return nil;
  439. }
  440. - (void)gridWillAppear:(MWPhotoBrowser *)photoBrowser
  441. {
  442. // reload [BUG]
  443. [self.photoBrowser reloadData];
  444. // in grid clear all MWPhoto : energy saving memory
  445. if (self.photos.count > 1 && [self.dataSourceImagesVideos count] > 0) {
  446. for(int index=0; index < self.photos.count; index++)
  447. [_photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:nil]];
  448. }
  449. self.title = [NSString stringWithFormat:@"Album %lu %@", (unsigned long)_photos.count, NSLocalizedString(@"photos", nil)];
  450. }
  451. - (void)gridWillDisappear:(MWPhotoBrowser *)photoBrowser
  452. {
  453. //
  454. photoBrowser.toolbar.hidden = NO;
  455. }
  456. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index
  457. {
  458. NSString *directory;
  459. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  460. if (_sourceDirectoryLocal)
  461. directory = self.metadataDetail.directoryID;
  462. else
  463. directory = app.directoryUser;
  464. if (index < self.thumbs.count) {
  465. if (metadata.fileID) {
  466. UIImage *image;
  467. if (_sourceDirectoryLocal) {
  468. 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]];
  469. } else {
  470. NSString *fileImage = [NSString stringWithFormat:@"%@/%@.ico", directory, metadata.fileID];
  471. image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  472. }
  473. if (image) {
  474. MWPhoto *thumb = [MWPhoto photoWithImage:image];
  475. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) thumb.isVideo = YES;
  476. [self.thumbs replaceObjectAtIndex:index withObject:thumb];
  477. }
  478. }
  479. return [self.thumbs objectAtIndex:index];
  480. }
  481. return nil;
  482. }
  483. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
  484. {
  485. NSString *filePath;
  486. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  487. if (metadata == nil) return;
  488. if (_sourceDirectoryLocal) {
  489. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  490. } else {
  491. filePath = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  492. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  493. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:filePath error:nil];
  494. }
  495. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  496. self.docController.delegate = self;
  497. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) [self.docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  498. [self.docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  499. }
  500. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  501. {
  502. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  503. [app.activeMain openWindowShare:metadata];
  504. }
  505. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  506. {
  507. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  508. if (metadata == nil || [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]] == NO) {
  509. [app messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  510. return;
  511. }
  512. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  513. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  514. style:UIAlertActionStyleDestructive
  515. handler:^(UIAlertAction *action) {
  516. [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
  517. }]];
  518. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  519. style:UIAlertActionStyleCancel
  520. handler:^(UIAlertAction *action) {
  521. [alertController dismissViewControllerAnimated:YES completion:nil];
  522. }]];
  523. alertController.popoverPresentationController.barButtonItem = deleteButton;
  524. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  525. [alertController.view layoutIfNeeded];
  526. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  527. }
  528. - (void)triggerProgressTask:(NSNotification *)notification
  529. {
  530. NSDictionary *dict = notification.userInfo;
  531. float progress = [[dict valueForKey:@"progress"] floatValue];
  532. if (progress == 0)
  533. [self.navigationController cancelCCProgress];
  534. else
  535. [self.navigationController setCCProgressPercentage:progress*100 andTintColor:[NCBrandColor sharedInstance].navigationBarProgress];
  536. }
  537. - (void)downloadPhotoBrowserFailure:(NSInteger)errorCode
  538. {
  539. [app messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  540. [self.photoBrowser reloadData];
  541. }
  542. - (void)downloadPhotoBrowserSuccess:(tableMetadata *)metadataVar selector:(NSString *)selector
  543. {
  544. NSUInteger index = 0;
  545. // if a message for a directory of these
  546. if (![_dataSourceDirectoryID containsObject:metadataVar.directoryID])
  547. return;
  548. for (NSUInteger i=0; i < [self.dataSourceImagesVideos count]; i++ ) {
  549. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:i];
  550. // search index
  551. if ([metadataVar.fileID isEqualToString:metadata.fileID]) {
  552. index = i;
  553. break;
  554. }
  555. }
  556. // do not reload is Video on air
  557. if (_photoBrowser.currentVideoPlayerViewController.isViewLoaded && _photoBrowser.currentVideoPlayerViewController.view.window) return;
  558. //NSLog(@"[LOG] Add Download Photo Browser");
  559. if ([metadataVar.fileID isEqualToString:_fileIDNowVisible] || [self.photoBrowser isGridReload:index]) {
  560. [self.photoBrowser reloadData];
  561. _reload = NO;
  562. } else {
  563. _reload = YES;
  564. }
  565. }
  566. - (void)downloadPhotoBrowser:(tableMetadata *)metadata
  567. {
  568. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  569. [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadViewImage selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:nil];
  570. }
  571. - (void)insertGeocoderLocation:(NSNotification *)notification
  572. {
  573. if (notification.userInfo.count == 0)
  574. return;
  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 (_indexNowVisible >= [self.photos count])
  579. return;
  580. if ([fileID isEqualToString:_fileIDNowVisible]) {
  581. MWPhoto *photo = [self.photos objectAtIndex:_indexNowVisible];
  582. [self setLocationCaptionPhoto:photo fileID:fileID];
  583. if (![self.photoBrowser isGridController]) {
  584. //[self.photoBrowser hideControls];
  585. //[self.photoBrowser showControls];
  586. }
  587. }
  588. }
  589. - (void)setLocationCaptionPhoto:(MWPhoto *)photo fileID:(NSString *)fileID
  590. {
  591. tableLocalFile *localFile;
  592. // read Geocoder
  593. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  594. if ([localFile.exifLatitude doubleValue] != 0 || [localFile.exifLongitude doubleValue] != 0) {
  595. // Fix BUG Geo latitude & longitude
  596. if ([localFile.exifLatitude doubleValue] == 9999 || [localFile.exifLongitude doubleValue] == 9999) {
  597. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  598. if (metadata) {
  599. [CCExifGeo setExifLocalTableEtag:metadata directoryUser:app.directoryUser activeAccount:app.activeAccount];
  600. }
  601. }
  602. [CCExifGeo setGeocoderEtag:fileID exifDate:localFile.exifDate latitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  603. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  604. if ([localFile.exifLatitude floatValue] != 0 || [localFile.exifLongitude floatValue] != 0) {
  605. NSString *location = [[NCManageDatabase sharedInstance] 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. // reload Main
  711. [app.activeMain reloadDatasource];
  712. // If removed document (web) or PDF close
  713. if (_webView || _readerPDFViewController)
  714. [self removeAllView];
  715. // if a message for a directory of these
  716. if (![_dataSourceDirectoryID containsObject:metadataNet.directoryID])
  717. return;
  718. // if we are not in browserPhoto and it's removed photo/video in preview then "< Back"
  719. if (!self.photoBrowser && [self.metadataDetail.fileID isEqualToString:metadataNet.fileID]) {
  720. [app.player.mediaPlayer stop];
  721. NSArray *viewsToRemove = [self.view subviews];
  722. for (id element in viewsToRemove) {
  723. if ([element isMemberOfClass:[UIView class]] || [element isMemberOfClass:[UIToolbar class]] || [element isMemberOfClass:[LMMediaPlayerView class]])
  724. [element removeFromSuperview];
  725. }
  726. self.title = @"";
  727. [self.navigationController popViewControllerAnimated:YES];
  728. } else {
  729. // only photoBrowser if exists
  730. for (NSUInteger index=0; index < [self.dataSourceImagesVideos count] && _photoBrowser; index++ ) {
  731. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  732. // ricerca index
  733. if ([metadata.fileID isEqualToString:metadataNet.fileID]) {
  734. [self.dataSourceImagesVideos removeObjectAtIndex:index];
  735. [self.photos removeObjectAtIndex:index];
  736. [self.thumbs removeObjectAtIndex:index];
  737. [self.photoBrowser reloadData];
  738. // Title
  739. if ([self.dataSourceImagesVideos count] == 0) {
  740. self.title = @"";
  741. [self.navigationController popViewControllerAnimated:YES];
  742. }
  743. break;
  744. }
  745. }
  746. }
  747. }
  748. #pragma --------------------------------------------------------------------------------------------
  749. #pragma mark ===== ButtonPressed =====
  750. #pragma --------------------------------------------------------------------------------------------
  751. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  752. {
  753. NSString *filePath;
  754. if ([self.metadataDetail.fileNamePrint length] == 0) return;
  755. if (_sourceDirectoryLocal) {
  756. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  757. } else {
  758. filePath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), self.metadataDetail.fileNamePrint];
  759. }
  760. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  761. self.docController.delegate = self;
  762. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  763. [self.docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  764. }
  765. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  766. {
  767. [app.activeMain openWindowShare:self.metadataDetail];
  768. }
  769. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  770. {
  771. if ([self.metadataDetail.fileNamePrint length] == 0) return;
  772. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  773. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  774. style:UIAlertActionStyleDestructive
  775. handler:^(UIAlertAction *action) {
  776. [[CCActions sharedInstance] deleteFileOrFolder:self.metadataDetail delegate:self];
  777. }]];
  778. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  779. style:UIAlertActionStyleCancel
  780. handler:^(UIAlertAction *action) {
  781. [alertController dismissViewControllerAnimated:YES completion:nil];
  782. }]];
  783. alertController.popoverPresentationController.barButtonItem = _buttonDelete;
  784. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  785. [alertController.view layoutIfNeeded];
  786. [self presentViewController:alertController animated:YES completion:NULL];
  787. }
  788. @end