CCDetail.m 45 KB

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