CCDetail.m 44 KB

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