CCDetail.m 45 KB

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