CCDetail.m 45 KB

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