CCDetail.m 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. //
  2. // CCDetail.m
  3. // Nextcloud iOS
  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 "NCUchardet.h"
  27. #import "NCBridgeSwift.h"
  28. #define TOOLBAR_HEIGHT 49.0f
  29. #define alertRequestPasswordPDF 1
  30. @interface CCDetail () <CCActionsDeleteDelegate>
  31. {
  32. AppDelegate *appDelegate;
  33. UIToolbar *_toolbar;
  34. UIBarButtonItem *_buttonModifyTxt;
  35. UIBarButtonItem *_buttonAction;
  36. UIBarButtonItem *_buttonShare;
  37. UIBarButtonItem *_buttonDelete;
  38. NSInteger _indexNowVisible;
  39. NSString *_fileIDNowVisible;
  40. BOOL _reload;
  41. NSMutableOrderedSet *_dataSourceDirectoryID;
  42. NSString *_fileNameExtension;
  43. }
  44. @end
  45. @implementation CCDetail
  46. #pragma --------------------------------------------------------------------------------------------
  47. #pragma mark ===== init =====
  48. #pragma --------------------------------------------------------------------------------------------
  49. - (id)initWithCoder:(NSCoder *)aDecoder
  50. {
  51. if (self = [super initWithCoder:aDecoder]) {
  52. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  53. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  54. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backNavigationController) name:@"detailBack" object:nil];
  55. self.metadataDetail = [[tableMetadata alloc] init];
  56. self.photos = [[NSMutableArray alloc] init];
  57. self.thumbs = [[NSMutableArray alloc] init];
  58. self.dataSourceImagesVideos = [[NSMutableArray alloc] init];
  59. _dataSourceDirectoryID = [[NSMutableOrderedSet alloc] init];
  60. _indexNowVisible = -1;
  61. _fileIDNowVisible = nil;
  62. app.activeDetail = self;
  63. }
  64. return self;
  65. }
  66. #pragma --------------------------------------------------------------------------------------------
  67. #pragma mark ===== View =====
  68. #pragma --------------------------------------------------------------------------------------------
  69. - (void)viewDidLoad
  70. {
  71. [super viewDidLoad];
  72. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  73. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(insertGeocoderLocation:) name:@"insertGeocoderLocation" object:nil];
  74. self.imageBackground.image = [UIImage imageNamed:@"backgroundDetail"];
  75. if ([self.metadataDetail.fileName length] > 0 || [self.metadataDetail.directoryID length] > 0 || [self.metadataDetail.fileID length] > 0) {
  76. // open view
  77. [self viewFile];
  78. }
  79. }
  80. // Apparirà
  81. - (void)viewWillAppear:(BOOL)animated
  82. {
  83. [super viewWillAppear:animated];
  84. if (self.splitViewController.isCollapsed) {
  85. self.tabBarController.tabBar.hidden = YES;
  86. self.tabBarController.tabBar.translucent = YES;
  87. }
  88. if (self.splitViewController.isCollapsed)
  89. [app plusButtonVisibile:false];
  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. // Document
  109. if (_webView) {
  110. [_webView removeFromSuperview];
  111. _webView = nil;
  112. }
  113. // PDF
  114. if (_readerPDFViewController) {
  115. [_readerPDFViewController.view removeFromSuperview];
  116. _readerPDFViewController.delegate = nil;
  117. _readerPDFViewController = nil;
  118. }
  119. // Photo-Video-Audio
  120. if (_photoBrowser) {
  121. [_photos removeAllObjects];
  122. [_thumbs removeAllObjects];
  123. _photoBrowser.delegate = nil;
  124. _photoBrowser = nil;
  125. }
  126. // ToolBar
  127. if (_toolbar) {
  128. [_toolbar removeFromSuperview];
  129. _toolbar = nil;
  130. }
  131. // Title
  132. self.title = nil;
  133. }
  134. - (void)backNavigationController
  135. {
  136. [self removeAllView];
  137. [self.navigationController popViewControllerAnimated:NO];
  138. }
  139. - (void)changeToDisplayMode
  140. {
  141. if (_readerPDFViewController)
  142. [self.readerPDFViewController updateContentViews];
  143. }
  144. - (void)createToolbar
  145. {
  146. CGFloat safeAreaBottom = 0;
  147. if (@available(iOS 11, *)) {
  148. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  149. }
  150. _toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom, self.view.bounds.size.width, TOOLBAR_HEIGHT)];
  151. UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  152. UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
  153. fixedSpaceMini.width = 25;
  154. _buttonModifyTxt = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetModify"] style:UIBarButtonItemStylePlain target:self action:@selector(modifyTxtButtonPressed:)];
  155. _buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetOpenIn"] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
  156. _buttonShare = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetShare"] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
  157. _buttonDelete = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteButtonPressed:)];
  158. if ([_fileNameExtension isEqualToString:@"TXT"])
  159. [_toolbar setItems:[NSArray arrayWithObjects: _buttonModifyTxt, flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction, nil]];
  160. else
  161. [_toolbar setItems:[NSArray arrayWithObjects: flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction, nil]];
  162. [_toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  163. _toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  164. _toolbar.tintColor = [NCBrandColor sharedInstance].brand;
  165. [self.view addSubview:_toolbar];
  166. }
  167. - (void)changeTheming
  168. {
  169. [app changeTheming:self];
  170. if (_toolbar) {
  171. _toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  172. _toolbar.tintColor = [NCBrandColor sharedInstance].brand;
  173. }
  174. }
  175. #pragma --------------------------------------------------------------------------------------------
  176. #pragma mark ===== View File =====
  177. #pragma --------------------------------------------------------------------------------------------
  178. - (void)viewFile
  179. {
  180. // verifico se esiste l'icona e se la posso creare
  181. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, self.metadataDetail.fileID]] == NO) {
  182. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{
  183. [CCGraphics createNewImageFrom:self.metadataDetail.fileID directoryUser:app.directoryUser fileNameTo:self.metadataDetail.fileID extension:[self.metadataDetail.fileName pathExtension] size:@"m" imageForUpload:NO typeFile:self.metadataDetail.typeFile writePreview:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
  184. });
  185. }
  186. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_video] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  187. self.edgesForExtendedLayout = UIRectEdgeAll;
  188. [self viewImageVideoAudio];
  189. }
  190. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document]) {
  191. _fileNameExtension = [[self.metadataDetail.fileName pathExtension] uppercaseString];
  192. if ([_fileNameExtension isEqualToString:@"PDF"]) {
  193. self.edgesForExtendedLayout = UIRectEdgeBottom;
  194. [self viewPDF:@""];
  195. [self createToolbar];
  196. [app aspectNavigationControllerBar:self.navigationController.navigationBar online:[app.reachability isReachable] hidden:NO];
  197. } else {
  198. self.edgesForExtendedLayout = UIRectEdgeBottom;
  199. [self viewDocument];
  200. [self createToolbar];
  201. [app aspectNavigationControllerBar:self.navigationController.navigationBar online:[app.reachability isReachable] hidden:NO];
  202. }
  203. }
  204. }
  205. #pragma --------------------------------------------------------------------------------------------
  206. #pragma mark ===== View Document =====
  207. #pragma --------------------------------------------------------------------------------------------
  208. - (void)viewDocument
  209. {
  210. NSString *fileName;
  211. CGFloat safeAreaBottom = 0;
  212. if (@available(iOS 11, *)) {
  213. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  214. }
  215. if (_sourceDirectoryLocal) {
  216. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileName];
  217. } else {
  218. fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileName];
  219. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  220. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  221. }
  222. if ([[NSFileManager defaultManager] fileExistsAtPath:fileName] == NO) {
  223. [self backNavigationController];
  224. return;
  225. }
  226. NSURL *url = [NSURL fileURLWithPath:fileName];
  227. WKPreferences *wkPreferences = [[WKPreferences alloc] init];
  228. wkPreferences.javaScriptEnabled = true;
  229. WKWebViewConfiguration *wkConfig = [[WKWebViewConfiguration alloc] init];
  230. wkConfig.preferences = wkPreferences;
  231. self.webView = [[WKWebView alloc] initWithFrame:(CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom)) configuration:wkConfig];
  232. self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  233. [self.webView setBackgroundColor:[UIColor whiteColor]];
  234. [self.webView setOpaque:NO];
  235. if ( [_fileNameExtension isEqualToString:@"CSS"] || [_fileNameExtension isEqualToString:@"PY"] || [_fileNameExtension isEqualToString:@"XML"] || [_fileNameExtension isEqualToString:@"JS"] ) {
  236. NSString *dataFile = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:url] encoding:NSASCIIStringEncoding];
  237. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  238. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"40",@"Sans-Serif",dataFile] baseURL:nil];
  239. }else{
  240. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"20",@"Sans-Serif",dataFile] baseURL:nil];
  241. }
  242. } else if ([_fileNameExtension isEqualToString:@"TXT"]) {
  243. NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  244. NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:nil];
  245. NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:url];
  246. [headRequest setHTTPMethod:@"HEAD"];
  247. NSURLSessionDataTask *task = [session dataTaskWithRequest:headRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
  248. NSString *encodingName = [[NCUchardet sharedNUCharDet] encodingStringDetectWithData:data];
  249. [self.webView loadData:[NSData dataWithContentsOfURL: url] MIMEType:response.MIMEType characterEncodingName:encodingName baseURL:url];
  250. }];
  251. [task resume];
  252. } else {
  253. [self.webView loadRequest:[NSMutableURLRequest requestWithURL:url]];
  254. }
  255. [self.view addSubview:self.webView];
  256. }
  257. #pragma --------------------------------------------------------------------------------------------
  258. #pragma mark ===== View Image =====
  259. #pragma --------------------------------------------------------------------------------------------
  260. - (void)viewImageVideoAudio
  261. {
  262. self.photoBrowser = [[MWPhotoBrowser alloc] initWithDelegate:self];
  263. _reload = NO;
  264. _indexNowVisible = -1;
  265. _fileIDNowVisible = nil;
  266. [self.photos removeAllObjects];
  267. [self.thumbs removeAllObjects];
  268. [_dataSourceDirectoryID removeAllObjects];
  269. // if not images, exit
  270. if ([self.dataSourceImagesVideos count] == 0) return;
  271. NSUInteger index = 0;
  272. for (tableMetadata *metadata in self.dataSourceImagesVideos) {
  273. // start from here ?
  274. if (self.metadataDetail.fileID && [metadata.fileID isEqualToString:self.metadataDetail.fileID])
  275. [self.photoBrowser setCurrentPhotoIndex:index];
  276. [self.photos addObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownload"]]];
  277. MWPhoto *thumb = [MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownload"]];
  278. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video] || [metadata.typeFile isEqualToString: k_metadataTypeFile_audio]) thumb.isVideo = YES;
  279. [self.thumbs addObject:thumb];
  280. // add directory
  281. [_dataSourceDirectoryID addObject:metadata.directoryID];
  282. index++;
  283. }
  284. // PhotoBrowser
  285. self.photoBrowser.displayActionButton = YES;
  286. self.photoBrowser.displayDeleteButton = YES;
  287. self.photoBrowser.displayNavArrows = YES;
  288. self.photoBrowser.displaySelectionButtons = NO;
  289. self.photoBrowser.alwaysShowControls = NO;
  290. self.photoBrowser.zoomPhotosToFill = NO;
  291. self.photoBrowser.autoPlayOnAppear = NO;
  292. self.photoBrowser.delayToHideElements = 15;
  293. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  294. [self addChildViewController:self.photoBrowser];
  295. [self.view addSubview:self.photoBrowser.view];
  296. [self.photoBrowser didMoveToParentViewController:self];
  297. } else {
  298. [self.navigationController pushViewController:self.photoBrowser animated:NO];
  299. }
  300. }
  301. - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
  302. {
  303. return [self.dataSourceImagesVideos count];
  304. }
  305. - (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
  306. {
  307. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  308. NSString *titleDir = metadata.fileName;
  309. self.title = titleDir;
  310. return titleDir;
  311. }
  312. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
  313. {
  314. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  315. NSString *directory;
  316. _indexNowVisible = index;
  317. _fileIDNowVisible = metadata.fileID;
  318. photoBrowser.toolbar.hidden = NO;
  319. if (_sourceDirectoryLocal)
  320. directory = self.metadataDetail.directoryID;
  321. else
  322. directory = app.directoryUser;
  323. // Download image ?
  324. if (metadata) {
  325. tableMetadata *metadataDB = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadata.fileID]];
  326. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]] == NO && [metadataDB.session length] == 0)
  327. [self downloadPhotoBrowser:metadata];
  328. }
  329. // Title
  330. if (metadata)
  331. self.title = metadata.fileName;
  332. if (_reload) {
  333. [self.photoBrowser performSelector:@selector(reloadData) withObject:nil];
  334. _reload = NO;
  335. }
  336. }
  337. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
  338. {
  339. NSString *directory;
  340. UIImage *image;
  341. if (_sourceDirectoryLocal)
  342. directory = self.metadataDetail.directoryID;
  343. else
  344. directory = app.directoryUser;
  345. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  346. if (index < self.photos.count) {
  347. if (metadata.fileID) {
  348. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  349. NSString *fileImage = [NSString stringWithFormat:@"%@/%@", directory, metadata.fileID];
  350. NSString *ext = [CCUtility getExtension:metadata.fileName];
  351. if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  352. else image = [UIImage imageWithContentsOfFile:fileImage];
  353. if (image) {
  354. MWPhoto *photo = [MWPhoto photoWithImage:image];
  355. // Location ??
  356. [self setLocationCaptionPhoto:photo fileID:metadata.fileID];
  357. [self.photos replaceObjectAtIndex:index withObject:photo];
  358. } else {
  359. if ([metadata.sessionError length] > 0 ) {
  360. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  361. } else {
  362. image = [CCGraphics drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button1000x200"] colorText:[UIColor darkGrayColor] sizeOfFont:50];
  363. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:image]];
  364. }
  365. }
  366. }
  367. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  368. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]]) {
  369. // remove and make the simbolic link in temp
  370. NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileName];
  371. [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
  372. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID] toPath:toPath error:nil];
  373. NSURL *url = [NSURL fileURLWithPath:toPath];
  374. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  375. video.videoURL = url;
  376. [self.photos replaceObjectAtIndex:index withObject:video];
  377. } else {
  378. if ([metadata.sessionError length] > 0 ) {
  379. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  380. } else {
  381. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[CCGraphics drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button1000x200"] colorText:[UIColor darkGrayColor] sizeOfFont:50]]];
  382. }
  383. }
  384. }
  385. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  386. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]]) {
  387. MWPhoto *audio;
  388. UIImage *audioImage;
  389. // remove and make the simbolic link in temp
  390. NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileName];
  391. [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
  392. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID] toPath:toPath error:nil];
  393. NSURL *url = [NSURL fileURLWithPath:toPath];
  394. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", directory, metadata.fileID]]) {
  395. audioImage = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", directory, metadata.fileID]];
  396. } else {
  397. audioImage = [UIImage imageNamed:@"notaMusic"]; //[CCGraphics scaleImage:[UIImage imageNamed:@"notaMusic"] toSize:CGSizeMake(200, 200) isAspectRation:YES];
  398. }
  399. audio = [MWPhoto photoWithImage:audioImage];
  400. audio.videoURL = url;
  401. [self.photos replaceObjectAtIndex:index withObject:audio];
  402. } else {
  403. if ([metadata.sessionError length] > 0 ) {
  404. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  405. } else {
  406. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[CCGraphics drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button1000x200"] colorText:[UIColor darkGrayColor] sizeOfFont:50]]];
  407. }
  408. }
  409. }
  410. }
  411. // energy saving memory
  412. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  413. int iPrev = (int)index - 2;
  414. if (iPrev >= 0) {
  415. if ([self.photos objectAtIndex:iPrev] != nil)
  416. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  417. }
  418. int iNext = (int)index + 2;
  419. if (iNext < _photos.count) {
  420. if ([self.photos objectAtIndex:iNext] != nil)
  421. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  422. }
  423. });
  424. return [self.photos objectAtIndex:index];
  425. }
  426. return nil;
  427. }
  428. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index
  429. {
  430. NSString *directory;
  431. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  432. if (_sourceDirectoryLocal)
  433. directory = self.metadataDetail.directoryID;
  434. else
  435. directory = app.directoryUser;
  436. if (index < self.thumbs.count) {
  437. if (metadata.fileID) {
  438. UIImage *image;
  439. if (_sourceDirectoryLocal) {
  440. image = [CCGraphics createNewImageFrom:metadata.fileID directoryUser:directory fileNameTo:metadata.fileID extension:[metadata.fileName pathExtension] size:@"m" imageForUpload:NO typeFile:metadata.typeFile writePreview:NO optimizedFileName:[CCUtility getOptimizedPhoto]];
  441. } else {
  442. NSString *fileImage = [NSString stringWithFormat:@"%@/%@.ico", directory, metadata.fileID];
  443. image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  444. }
  445. if (image) {
  446. MWPhoto *thumb = [MWPhoto photoWithImage:image];
  447. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) thumb.isVideo = YES;
  448. [self.thumbs replaceObjectAtIndex:index withObject:thumb];
  449. }
  450. }
  451. return [self.thumbs objectAtIndex:index];
  452. }
  453. return nil;
  454. }
  455. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
  456. {
  457. NSString *filePath;
  458. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  459. if (metadata == nil) return;
  460. if (_sourceDirectoryLocal) {
  461. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileName];
  462. } else {
  463. filePath = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileName];
  464. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  465. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:filePath error:nil];
  466. }
  467. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  468. self.docController.delegate = self;
  469. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  470. [self.docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  471. [self.docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  472. }
  473. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  474. {
  475. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  476. [app.activeMain openWindowShare:metadata];
  477. }
  478. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  479. {
  480. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  481. if (metadata == nil || [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]] == NO) {
  482. [app messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  483. return;
  484. }
  485. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  486. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  487. style:UIAlertActionStyleDestructive
  488. handler:^(UIAlertAction *action) {
  489. [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
  490. }]];
  491. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  492. style:UIAlertActionStyleCancel
  493. handler:^(UIAlertAction *action) {
  494. [alertController dismissViewControllerAnimated:YES completion:nil];
  495. }]];
  496. alertController.popoverPresentationController.barButtonItem = deleteButton;
  497. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  498. [alertController.view layoutIfNeeded];
  499. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  500. }
  501. - (void)triggerProgressTask:(NSNotification *)notification
  502. {
  503. //NSDictionary *dict = notification.userInfo;
  504. //float progress = [[dict valueForKey:@"progress"] floatValue];
  505. }
  506. - (void)downloadPhotoBrowserFailure:(NSInteger)errorCode
  507. {
  508. [app messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  509. [self.photoBrowser reloadData];
  510. }
  511. - (void)downloadPhotoBrowserSuccess:(tableMetadata *)metadataVar selector:(NSString *)selector
  512. {
  513. NSUInteger index = 0;
  514. // if a message for a directory of these
  515. if (![_dataSourceDirectoryID containsObject:metadataVar.directoryID])
  516. return;
  517. for (NSUInteger i=0; i < [self.dataSourceImagesVideos count]; i++ ) {
  518. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:i];
  519. // search index
  520. if ([metadataVar.fileID isEqualToString:metadata.fileID]) {
  521. index = i;
  522. break;
  523. }
  524. }
  525. if ([metadataVar.fileID isEqualToString:_fileIDNowVisible]) {
  526. [self.photoBrowser reloadData];
  527. _reload = NO;
  528. } else {
  529. _reload = YES;
  530. }
  531. }
  532. - (void)downloadPhotoBrowser:(tableMetadata *)metadata
  533. {
  534. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  535. if (serverUrl)
  536. [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl selector:selectorLoadViewImage selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:app.activeMain];
  537. }
  538. - (void)insertGeocoderLocation:(NSNotification *)notification
  539. {
  540. if (notification.userInfo.count == 0)
  541. return;
  542. NSString *fileID = [[notification.userInfo allKeys] objectAtIndex:0];
  543. //NSDate *date = [[notification.userInfo allValues] objectAtIndex:0];
  544. // test [Chrash V 1.14,15]
  545. if (_indexNowVisible >= [self.photos count])
  546. return;
  547. if ([fileID isEqualToString:_fileIDNowVisible]) {
  548. MWPhoto *photo = [self.photos objectAtIndex:_indexNowVisible];
  549. [self setLocationCaptionPhoto:photo fileID:fileID];
  550. }
  551. }
  552. - (void)setLocationCaptionPhoto:(MWPhoto *)photo fileID:(NSString *)fileID
  553. {
  554. tableLocalFile *localFile;
  555. // read Geocoder
  556. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  557. if ([localFile.exifLatitude doubleValue] != 0 || [localFile.exifLongitude doubleValue] != 0) {
  558. // Fix BUG Geo latitude & longitude
  559. if ([localFile.exifLatitude doubleValue] == 9999 || [localFile.exifLongitude doubleValue] == 9999) {
  560. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  561. if (metadata) {
  562. [[CCExifGeo sharedInstance] setExifLocalTableEtag:metadata directoryUser:app.directoryUser activeAccount:app.activeAccount];
  563. }
  564. }
  565. [[CCExifGeo sharedInstance] setGeocoderEtag:fileID exifDate:localFile.exifDate latitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  566. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  567. if ([localFile.exifLatitude floatValue] != 0 || [localFile.exifLongitude floatValue] != 0) {
  568. NSString *location = [[NCManageDatabase sharedInstance] getLocationFromGeoLatitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  569. if ([localFile.exifDate isEqualToDate:[NSDate distantPast]] == NO && location) {
  570. NSString *localizedDateTime = [NSDateFormatter localizedStringFromDate:localFile.exifDate dateStyle:NSDateFormatterFullStyle timeStyle:NSDateFormatterMediumStyle];
  571. photo.caption = [NSString stringWithFormat:NSLocalizedString(@"%@\n%@", nil), localizedDateTime, location];
  572. }
  573. }
  574. }
  575. }
  576. #pragma --------------------------------------------------------------------------------------------
  577. #pragma mark ===== View PDF =====
  578. #pragma --------------------------------------------------------------------------------------------
  579. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  580. {
  581. [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
  582. [[alertView textFieldAtIndex:0] resignFirstResponder];
  583. if (alertView.tag == alertRequestPasswordPDF) [self performSelector:@selector(viewPDF:) withObject:[alertView textFieldAtIndex:0].text afterDelay:0.3];
  584. }
  585. - (void)viewPDF:(NSString *)password
  586. {
  587. NSString *fileName;
  588. if (_sourceDirectoryLocal) {
  589. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileName];
  590. } else {
  591. fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileName];
  592. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  593. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  594. }
  595. if ([[NSFileManager defaultManager] fileExistsAtPath:fileName isDirectory:nil] == NO) {
  596. // read file error
  597. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  598. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  599. [alertController addAction:okAction];
  600. [self presentViewController:alertController animated:YES completion:nil];
  601. }
  602. CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileName]);
  603. if (pdf) {
  604. // Encrypted
  605. if (CGPDFDocumentIsEncrypted(pdf) == YES) {
  606. // Try a blank password first, per Apple's Quartz PDF example
  607. if (CGPDFDocumentUnlockWithPassword(pdf, "") == YES) {
  608. // blank password
  609. [self readerPDF:fileName password:@""];
  610. } else {
  611. if ([password length] == 0) {
  612. // password request
  613. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_insert_password_pfd_",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  614. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  615. alertView.tag = alertRequestPasswordPDF;
  616. [alertView show];
  617. } else {
  618. const char *key = [password UTF8String];
  619. // failure
  620. if (CGPDFDocumentUnlockWithPassword(pdf, key) == NO) {
  621. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_password_pdf_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  622. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  623. [alertController addAction:okAction];
  624. [self presentViewController:alertController animated:YES completion:nil];
  625. } else {
  626. // pdf with password
  627. [self readerPDF:fileName password:password];
  628. }
  629. }
  630. }
  631. } else{
  632. // No password
  633. [self readerPDF:fileName password:@""];
  634. }
  635. } else {
  636. // read file error
  637. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  638. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  639. [alertController addAction:okAction];
  640. [self presentViewController:alertController animated:YES completion:nil];
  641. }
  642. }
  643. - (void)readerPDF:(NSString *)fileName password:(NSString *)password
  644. {
  645. ReaderDocument *documentPDF = [ReaderDocument withDocumentFilePath:fileName password:password];
  646. CGFloat safeAreaBottom = 0;
  647. if (@available(iOS 11, *)) {
  648. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  649. }
  650. if (documentPDF != nil) {
  651. self.readerPDFViewController = [[ReaderViewController alloc] initWithReaderDocument:documentPDF];
  652. self.readerPDFViewController.delegate = self;
  653. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  654. [self.readerPDFViewController updateContentViews];
  655. [self addChildViewController:self.readerPDFViewController];
  656. [self.view addSubview:self.readerPDFViewController.view];
  657. [self.readerPDFViewController didMoveToParentViewController:self];
  658. } else {
  659. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  660. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  661. [alertController addAction:okAction];
  662. [self presentViewController:alertController animated:YES completion:nil];
  663. }
  664. }
  665. - (void)handleSingleTapReader
  666. {
  667. UILayoutGuide *layoutGuide;
  668. CGFloat safeAreaTop = 0;
  669. CGFloat safeAreaBottom = 0;
  670. if (@available(iOS 11, *)) {
  671. layoutGuide = [UIApplication sharedApplication].delegate.window.safeAreaLayoutGuide;
  672. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;
  673. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  674. }
  675. self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
  676. _toolbar.hidden = !_toolbar.isHidden;
  677. if (_toolbar.isHidden) {
  678. self.readerPDFViewController.view.frame = CGRectMake(0, safeAreaTop, self.view.bounds.size.width, self.view.bounds.size.height - safeAreaTop - safeAreaBottom);
  679. } else {
  680. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  681. }
  682. [self.readerPDFViewController updateContentViews];
  683. }
  684. #pragma --------------------------------------------------------------------------------------------
  685. #pragma mark ===== Delete =====
  686. #pragma --------------------------------------------------------------------------------------------
  687. - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  688. {
  689. NSLog(@"[LOG] DeleteFileOrFolder failure error %lu, %@", (long)errorCode, message);
  690. }
  691. - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
  692. {
  693. // reload Main
  694. [app.activeMain reloadDatasource];
  695. // If removed document (web) or PDF close
  696. if (_webView || _readerPDFViewController)
  697. [self removeAllView];
  698. // if a message for a directory of these
  699. if (![_dataSourceDirectoryID containsObject:metadataNet.directoryID])
  700. return;
  701. // if we are not in browserPhoto and it's removed photo/video in preview then "< Back"
  702. if (!self.photoBrowser && [self.metadataDetail.fileID isEqualToString:metadataNet.fileID]) {
  703. NSArray *viewsToRemove = [self.view subviews];
  704. for (id element in viewsToRemove) {
  705. if ([element isMemberOfClass:[UIView class]] || [element isMemberOfClass:[UIToolbar class]])
  706. [element removeFromSuperview];
  707. }
  708. self.title = @"";
  709. [self.navigationController popViewControllerAnimated:YES];
  710. } else {
  711. // only photoBrowser if exists
  712. for (NSUInteger index=0; index < [self.dataSourceImagesVideos count] && _photoBrowser; index++ ) {
  713. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  714. // ricerca index
  715. if ([metadata.fileID isEqualToString:metadataNet.fileID]) {
  716. [self.dataSourceImagesVideos removeObjectAtIndex:index];
  717. [self.photos removeObjectAtIndex:index];
  718. [self.thumbs removeObjectAtIndex:index];
  719. [self.photoBrowser reloadData];
  720. // Title
  721. if ([self.dataSourceImagesVideos count] == 0) {
  722. self.title = @"";
  723. [self.navigationController popViewControllerAnimated:YES];
  724. }
  725. break;
  726. }
  727. }
  728. }
  729. }
  730. #pragma --------------------------------------------------------------------------------------------
  731. #pragma mark ===== ButtonPressed =====
  732. #pragma --------------------------------------------------------------------------------------------
  733. - (void)modifyTxtButtonPressed:(UIBarButtonItem *)sender
  734. {
  735. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"NCText" bundle:nil] instantiateViewControllerWithIdentifier:@"NCText"];
  736. NCText *viewController = (NCText *)navigationController.topViewController;
  737. viewController.metadata = self.metadataDetail;
  738. navigationController.modalPresentationStyle = UIModalPresentationPageSheet;
  739. navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  740. [self presentViewController:navigationController animated:YES completion:nil];
  741. }
  742. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  743. {
  744. NSString *filePath;
  745. if ([self.metadataDetail.fileName length] == 0) return;
  746. if (_sourceDirectoryLocal) {
  747. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileName];
  748. } else {
  749. filePath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), self.metadataDetail.fileName];
  750. }
  751. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  752. self.docController.delegate = self;
  753. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  754. [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  755. [self.docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  756. }
  757. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  758. {
  759. [app.activeMain openWindowShare:self.metadataDetail];
  760. }
  761. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  762. {
  763. if ([self.metadataDetail.fileName length] == 0) return;
  764. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  765. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  766. style:UIAlertActionStyleDestructive
  767. handler:^(UIAlertAction *action) {
  768. [[CCActions sharedInstance] deleteFileOrFolder:self.metadataDetail delegate:self];
  769. }]];
  770. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  771. style:UIAlertActionStyleCancel
  772. handler:^(UIAlertAction *action) {
  773. [alertController dismissViewControllerAnimated:YES completion:nil];
  774. }]];
  775. alertController.popoverPresentationController.barButtonItem = _buttonDelete;
  776. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  777. [alertController.view layoutIfNeeded];
  778. [self presentViewController:alertController animated:YES completion:NULL];
  779. }
  780. @end