NCCollectionViewCommon+Menu.swift 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. //
  2. // NCCollectionViewCommon+Menu.swift
  3. // Nextcloud
  4. //
  5. // Created by Philippe Weidmann on 24.01.20.
  6. // Copyright © 2020 Philippe Weidmann. All rights reserved.
  7. // Copyright © 2020 Marino Faggiana All rights reserved.
  8. //
  9. // Author Philippe Weidmann
  10. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  11. //
  12. // This program is free software: you can redistribute it and/or modify
  13. // it under the terms of the GNU General Public License as published by
  14. // the Free Software Foundation, either version 3 of the License, or
  15. // (at your option) any later version.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU General Public License for more details.
  21. //
  22. // You should have received a copy of the GNU General Public License
  23. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. //
  25. import UIKit
  26. import FloatingPanel
  27. import NCCommunication
  28. import Queuer
  29. import SVGKit
  30. extension UIViewController {
  31. func handleProfileAction(_ action: NCHovercard.Action, for userId: String) {
  32. switch action.appId {
  33. case "email":
  34. guard let url = action.hyperlinkUrl,
  35. url.scheme == "mailto",
  36. let components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
  37. NCContentPresenter.shared.showGenericError(description: "_cannot_send_mail_error_")
  38. return
  39. }
  40. sendEmail(to: components.path)
  41. case "spreed":
  42. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  43. if let talkUrl = URL(string: "nextcloudtalk://open-conversation?server=\(appDelegate.urlBase)&user=\(userId)&withUser=\(appDelegate.userId)"),
  44. UIApplication.shared.canOpenURL(talkUrl) {
  45. UIApplication.shared.open(talkUrl, options: [.universalLinksOnly: true])
  46. } else if let url = action.hyperlinkUrl {
  47. UIApplication.shared.open(url, options: [:])
  48. }
  49. default:
  50. guard let url = action.hyperlinkUrl, UIApplication.shared.canOpenURL(url) else {
  51. NCContentPresenter.shared.showGenericError(description: "_open_url_error")
  52. return
  53. }
  54. UIApplication.shared.open(url, options: [:])
  55. }
  56. }
  57. func showProfileMenu(userId: String) {
  58. NCCommunication.shared.getHovercard(for: userId) { (card, errCode, err) in
  59. guard let card = card else {
  60. return
  61. }
  62. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  63. let personHeader = NCMenuAction(
  64. title: card.displayName,
  65. icon: NCUtility.shared.loadUserImage(for: userId, displayName: card.displayName, urlBase: appDelegate.urlBase),
  66. action: nil)
  67. let actions = card.actions.map { action -> NCMenuAction in
  68. var image = UIImage()
  69. if let url = URL(string: action.icon), let svg = SVGKImage(contentsOf: url) {
  70. image = svg.uiImage
  71. }
  72. return NCMenuAction(
  73. title: action.title,
  74. icon: image,
  75. action: { _ in self.handleProfileAction(action, for: userId) })
  76. }
  77. let allActions = [personHeader] + actions
  78. self.presentMenu(with: allActions)
  79. }
  80. }
  81. func sendEmail(to email: String) {
  82. guard MFMailComposeViewController.canSendMail() else {
  83. NCContentPresenter.shared.showGenericError(description: "_cannot_send_mail_error_")
  84. return
  85. }
  86. let mail = MFMailComposeViewController()
  87. mail.mailComposeDelegate = self
  88. mail.setToRecipients([email])
  89. present(mail, animated: true)
  90. }
  91. fileprivate func presentMenu(with actions: [NCMenuAction]) {
  92. let menuViewController = NCMenu.makeNCMenu(with: actions)
  93. let menuPanelController = NCMenuPanelController()
  94. menuPanelController.parentPresenter = self
  95. menuPanelController.delegate = menuViewController
  96. menuPanelController.set(contentViewController: menuViewController)
  97. menuPanelController.track(scrollView: menuViewController.tableView)
  98. present(menuPanelController, animated: true, completion: nil)
  99. }
  100. }
  101. extension UIViewController: MFMailComposeViewControllerDelegate {
  102. public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
  103. controller.dismiss(animated: true)
  104. }
  105. }
  106. extension NCCollectionViewCommon {
  107. func toggleMenu(metadata: tableMetadata, imageIcon: UIImage?) {
  108. var actions = [NCMenuAction]()
  109. guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(metadata.ocId) else { return }
  110. let serverUrl = metadata.serverUrl + "/" + metadata.fileName
  111. let isFolderEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account, urlBase: metadata.urlBase)
  112. let serverUrlHome = NCUtilityFileSystem.shared.getHomeServer(account: appDelegate.account)
  113. var isOffline = false
  114. var titleDelete = NSLocalizedString("_delete_", comment: "")
  115. if NCManageDatabase.shared.isMetadataShareOrMounted(metadata: metadata, metadataFolder: metadataFolder) {
  116. titleDelete = NSLocalizedString("_leave_share_", comment: "")
  117. } else if metadata.directory {
  118. titleDelete = NSLocalizedString("_delete_folder_", comment: "")
  119. } else {
  120. titleDelete = NSLocalizedString("_delete_file_", comment: "")
  121. }
  122. if let metadataFolder = metadataFolder {
  123. let isShare = metadata.permissions.contains(NCGlobal.shared.permissionShared) && !metadataFolder.permissions.contains(NCGlobal.shared.permissionShared)
  124. let isMounted = metadata.permissions.contains(NCGlobal.shared.permissionMounted) && !metadataFolder.permissions.contains(NCGlobal.shared.permissionMounted)
  125. if isShare || isMounted {
  126. titleDelete = NSLocalizedString("_leave_share_", comment: "")
  127. }
  128. }
  129. if metadata.directory {
  130. if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl)) {
  131. isOffline = directory.offline
  132. }
  133. } else {
  134. if let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) {
  135. isOffline = localFile.offline
  136. }
  137. }
  138. let editors = NCUtility.shared.isDirectEditing(account: metadata.account, contentType: metadata.contentType)
  139. let isRichDocument = NCUtility.shared.isRichDocument(metadata)
  140. var iconHeader: UIImage!
  141. if imageIcon != nil {
  142. iconHeader = imageIcon!
  143. } else {
  144. if metadata.directory {
  145. iconHeader = NCBrandColor.cacheImages.folder
  146. } else {
  147. iconHeader = NCBrandColor.cacheImages.file
  148. }
  149. }
  150. actions.append(
  151. NCMenuAction(
  152. title: metadata.fileNameView,
  153. icon: iconHeader,
  154. action: nil
  155. )
  156. )
  157. //
  158. // FAVORITE
  159. //
  160. actions.append(
  161. NCMenuAction(
  162. title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
  163. icon: NCUtility.shared.loadImage(named: "star.fill", color: NCBrandColor.shared.yellowFavorite),
  164. action: { menuAction in
  165. NCNetworking.shared.favoriteMetadata(metadata) { (errorCode, errorDescription) in
  166. if errorCode != 0 {
  167. NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
  168. }
  169. }
  170. }
  171. )
  172. )
  173. //
  174. // DETAIL
  175. //
  176. if !isFolderEncrypted && !appDelegate.disableSharesView {
  177. actions.append(
  178. NCMenuAction(
  179. title: NSLocalizedString("_details_", comment: ""),
  180. icon: NCUtility.shared.loadImage(named: "info"),
  181. action: { menuAction in
  182. NCFunctionCenter.shared.openShare(ViewController: self, metadata: metadata, indexPage: .activity)
  183. }
  184. )
  185. )
  186. }
  187. //
  188. // OFFLINE
  189. //
  190. if !isFolderEncrypted {
  191. actions.append(
  192. NCMenuAction(
  193. title: isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") : NSLocalizedString("_set_available_offline_", comment: ""),
  194. icon: NCUtility.shared.loadImage(named: "tray.and.arrow.down"),
  195. action: { menuAction in
  196. if isOffline {
  197. if metadata.directory {
  198. NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, offline: false, account: self.appDelegate.account)
  199. } else {
  200. NCManageDatabase.shared.setLocalFile(ocId: metadata.ocId, offline: false)
  201. }
  202. } else {
  203. if metadata.directory {
  204. NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, offline: true, account: self.appDelegate.account)
  205. NCOperationQueue.shared.synchronizationMetadata(metadata, selector: NCGlobal.shared.selectorDownloadAllFile)
  206. } else {
  207. NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadOffline) { (_) in }
  208. if let metadataLivePhoto = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
  209. NCNetworking.shared.download(metadata: metadataLivePhoto, selector: NCGlobal.shared.selectorLoadOffline) { (_) in }
  210. }
  211. }
  212. }
  213. self.reloadDataSource()
  214. }
  215. )
  216. )
  217. }
  218. //
  219. // OPEN with external editor
  220. //
  221. if metadata.classFile == NCCommunicationCommon.typeClassFile.document.rawValue && editors.contains(NCGlobal.shared.editorText) && ((editors.contains(NCGlobal.shared.editorOnlyoffice) || isRichDocument)) {
  222. var editor = ""
  223. var title = ""
  224. var icon: UIImage?
  225. if editors.contains(NCGlobal.shared.editorOnlyoffice) {
  226. editor = NCGlobal.shared.editorOnlyoffice
  227. title = NSLocalizedString("_open_in_onlyoffice_", comment: "")
  228. icon = NCUtility.shared.loadImage(named: "onlyoffice")
  229. } else if isRichDocument {
  230. editor = NCGlobal.shared.editorCollabora
  231. title = NSLocalizedString("_open_in_collabora_", comment: "")
  232. icon = NCUtility.shared.loadImage(named: "collabora")
  233. }
  234. if editor != "" {
  235. actions.append(
  236. NCMenuAction(
  237. title: title,
  238. icon: icon!,
  239. action: { menuAction in
  240. NCViewer.shared.view(viewController: self, metadata: metadata, metadatas: [metadata], imageIcon: imageIcon, editor: editor, isRichDocument: isRichDocument)
  241. }
  242. )
  243. )
  244. }
  245. }
  246. //
  247. // OPEN IN
  248. //
  249. if !metadata.directory && !NCBrandOptions.shared.disable_openin_file {
  250. actions.append(
  251. NCMenuAction(
  252. title: NSLocalizedString("_open_in_", comment: ""),
  253. icon: NCUtility.shared.loadImage(named: "square.and.arrow.up"),
  254. action: { menuAction in
  255. NCFunctionCenter.shared.openDownload(metadata: metadata, selector: NCGlobal.shared.selectorOpenIn)
  256. }
  257. )
  258. )
  259. }
  260. //
  261. // PRINT
  262. //
  263. if (metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue && metadata.contentType != "image/svg+xml") || metadata.contentType == "application/pdf" || metadata.contentType == "com.adobe.pdf" {
  264. actions.append(
  265. NCMenuAction(
  266. title: NSLocalizedString("_print_", comment: ""),
  267. icon: NCUtility.shared.loadImage(named: "printer"),
  268. action: { menuAction in
  269. NCFunctionCenter.shared.openDownload(metadata: metadata, selector: NCGlobal.shared.selectorPrint)
  270. }
  271. )
  272. )
  273. }
  274. //
  275. // SAVE
  276. //
  277. if (metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue && metadata.contentType != "image/svg+xml") || metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue {
  278. var title: String = NSLocalizedString("_save_selected_files_", comment: "")
  279. var icon = NCUtility.shared.loadImage(named: "square.and.arrow.down")
  280. let metadataMOV = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata)
  281. if metadataMOV != nil {
  282. title = NSLocalizedString("_livephoto_save_", comment: "")
  283. icon = NCUtility.shared.loadImage(named: "livephoto")
  284. }
  285. actions.append(
  286. NCMenuAction(
  287. title: title,
  288. icon: icon,
  289. action: { menuAction in
  290. if metadataMOV != nil {
  291. NCFunctionCenter.shared.saveLivePhoto(metadata: metadata, metadataMOV: metadataMOV!)
  292. } else {
  293. if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
  294. NCFunctionCenter.shared.saveAlbum(metadata: metadata)
  295. } else {
  296. NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorSaveAlbum)
  297. }
  298. }
  299. }
  300. )
  301. )
  302. }
  303. //
  304. // SAVE AS SCAN
  305. //
  306. if #available(iOS 13.0, *) {
  307. if (metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue && metadata.contentType != "image/svg+xml") {
  308. actions.append(
  309. NCMenuAction(
  310. title: NSLocalizedString("_save_as_scan_", comment: ""),
  311. icon: NCUtility.shared.loadImage(named: "viewfinder.circle"),
  312. action: { menuAction in
  313. NCFunctionCenter.shared.openDownload(metadata: metadata, selector: NCGlobal.shared.selectorSaveAsScan)
  314. }
  315. )
  316. )
  317. }
  318. }
  319. //
  320. // RENAME
  321. //
  322. if !(isFolderEncrypted && metadata.serverUrl == serverUrlHome) {
  323. actions.append(
  324. NCMenuAction(
  325. title: NSLocalizedString("_rename_", comment: ""),
  326. icon: NCUtility.shared.loadImage(named: "pencil"),
  327. action: { menuAction in
  328. if let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile {
  329. vcRename.metadata = metadata
  330. vcRename.imagePreview = imageIcon
  331. let popup = NCPopupViewController(contentController: vcRename, popupWidth: vcRename.width, popupHeight: vcRename.height)
  332. self.present(popup, animated: true)
  333. }
  334. }
  335. )
  336. )
  337. }
  338. //
  339. // COPY - MOVE
  340. //
  341. if !isFolderEncrypted && serverUrl != "" {
  342. actions.append(
  343. NCMenuAction(
  344. title: NSLocalizedString("_move_or_copy_", comment: ""),
  345. icon: NCUtility.shared.loadImage(named: "arrow.up.right.square"),
  346. action: { menuAction in
  347. NCFunctionCenter.shared.openSelectView(items: [metadata], viewController: self)
  348. }
  349. )
  350. )
  351. }
  352. //
  353. // COPY
  354. //
  355. if !metadata.directory {
  356. actions.append(
  357. NCMenuAction(
  358. title: NSLocalizedString("_copy_file_", comment: ""),
  359. icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
  360. action: { menuAction in
  361. self.appDelegate.pasteboardOcIds = [metadata.ocId];
  362. NCFunctionCenter.shared.copyPasteboard()
  363. }
  364. )
  365. )
  366. }
  367. //
  368. // VIEW IN FOLDER
  369. //
  370. if layoutKey == NCGlobal.shared.layoutViewRecent && appDelegate.activeFileViewInFolder == nil {
  371. actions.append(
  372. NCMenuAction(
  373. title: NSLocalizedString("_view_in_folder_", comment: ""),
  374. icon: NCUtility.shared.loadImage(named: "arrow.forward.square"),
  375. action: { menuAction in
  376. NCFunctionCenter.shared.openFileViewInFolder(serverUrl: metadata.serverUrl, fileName: metadata.fileName)
  377. }
  378. )
  379. )
  380. }
  381. /*
  382. //
  383. // USE AS BACKGROUND
  384. //
  385. if #available(iOS 13.0, *) {
  386. if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue && self.layoutKey == NCGlobal.shared.layoutViewFiles && !NCBrandOptions.shared.disable_background_image {
  387. actions.append(
  388. NCMenuAction(
  389. title: NSLocalizedString("_use_as_background_", comment: ""),
  390. icon: NCUtility.shared.loadImage(named: "text.below.photo"),
  391. action: { menuAction in
  392. if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
  393. NCFunctionCenter.shared.saveBackground(metadata: metadata)
  394. } else {
  395. NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorSaveBackground)
  396. }
  397. }
  398. )
  399. )
  400. }
  401. }
  402. */
  403. //
  404. // MODIFY
  405. //
  406. if #available(iOS 13.0, *) {
  407. if !isFolderEncrypted && metadata.contentType != "image/gif" && metadata.contentType != "image/svg+xml" && (metadata.contentType == "com.adobe.pdf" || metadata.contentType == "application/pdf" || metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue) {
  408. actions.append(
  409. NCMenuAction(
  410. title: NSLocalizedString("_modify_", comment: ""),
  411. icon: NCUtility.shared.loadImage(named: "pencil.tip.crop.circle"),
  412. action: { menuAction in
  413. NCFunctionCenter.shared.openDownload(metadata: metadata, selector: NCGlobal.shared.selectorLoadFileQuickLook)
  414. }
  415. )
  416. )
  417. }
  418. }
  419. //
  420. // DELETE
  421. //
  422. actions.append(
  423. NCMenuAction(
  424. title: titleDelete,
  425. icon: NCUtility.shared.loadImage(named: "trash"),
  426. action: { menuAction in
  427. let alertController = UIAlertController(title: "", message: metadata.fileNameView + "\n\n" + NSLocalizedString("_want_delete_", comment: ""), preferredStyle: .alert)
  428. alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (action:UIAlertAction) in
  429. NCOperationQueue.shared.delete(metadata: metadata, onlyLocalCache: false)
  430. })
  431. alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_local_file_", comment: ""), style: .default) { (action:UIAlertAction) in
  432. NCOperationQueue.shared.delete(metadata: metadata, onlyLocalCache: true)
  433. })
  434. alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_delete_", comment: ""), style: .default) { (action:UIAlertAction) in })
  435. self.present(alertController, animated: true, completion:nil)
  436. }
  437. )
  438. )
  439. //
  440. // SET FOLDER E2EE
  441. //
  442. if !metadata.e2eEncrypted && metadata.directory && CCUtility.isEnd(toEndEnabled: appDelegate.account) && metadata.serverUrl == serverUrlHome {
  443. actions.append(
  444. NCMenuAction(
  445. title: NSLocalizedString("_e2e_set_folder_encrypted_", comment: ""),
  446. icon:NCUtility.shared.loadImage(named: "lock"),
  447. action: { menuAction in
  448. NCCommunication.shared.markE2EEFolder(fileId: metadata.fileId, delete: false) { (account, errorCode, errorDescription) in
  449. if errorCode == 0 {
  450. NCManageDatabase.shared.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, serverUrl))
  451. NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: nil, ocId: nil, fileId: nil, encrypted: true, richWorkspace: nil, account: metadata.account)
  452. NCManageDatabase.shared.setMetadataEncrypted(ocId: metadata.ocId, encrypted: true)
  453. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeStatusFolderE2EE, userInfo: ["serverUrl":metadata.serverUrl])
  454. } else {
  455. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_mark_folder_", comment: ""), description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: .error, errorCode: errorCode)
  456. }
  457. }
  458. }
  459. )
  460. )
  461. }
  462. //
  463. // UNSET FOLDER E2EE
  464. //
  465. if metadata.e2eEncrypted && metadata.directory && CCUtility.isEnd(toEndEnabled: appDelegate.account) && metadata.serverUrl == serverUrlHome {
  466. actions.append(
  467. NCMenuAction(
  468. title: NSLocalizedString("_e2e_remove_folder_encrypted_", comment: ""),
  469. icon: NCUtility.shared.loadImage(named: "lock"),
  470. action: { menuAction in
  471. NCCommunication.shared.markE2EEFolder(fileId: metadata.fileId, delete: true) { (account, errorCode, errorDescription) in
  472. if errorCode == 0 {
  473. NCManageDatabase.shared.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, serverUrl))
  474. NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: nil, ocId: nil, fileId: nil, encrypted: false, richWorkspace: nil, account: metadata.account)
  475. NCManageDatabase.shared.setMetadataEncrypted(ocId: metadata.ocId, encrypted: false)
  476. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeStatusFolderE2EE, userInfo: ["serverUrl":metadata.serverUrl])
  477. } else {
  478. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_delete_mark_folder_", comment: ""), description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: .error, errorCode: errorCode)
  479. }
  480. }
  481. }
  482. )
  483. )
  484. }
  485. presentMenu(with: actions)
  486. }
  487. func toggleMenuSelect() {
  488. let menuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
  489. var actions = [NCMenuAction]()
  490. //
  491. // SELECT ALL
  492. //
  493. actions.append(
  494. NCMenuAction(
  495. title: NSLocalizedString("_select_all_", comment: ""),
  496. icon: NCUtility.shared.loadImage(named: "checkmark.circle.fill"),
  497. action: { menuAction in
  498. self.collectionViewSelectAll()
  499. }
  500. )
  501. )
  502. //
  503. // OPEN IN
  504. //
  505. actions.append(
  506. NCMenuAction(
  507. title: NSLocalizedString("_open_in_", comment: ""),
  508. icon: NCUtility.shared.loadImage(named: "square.and.arrow.up"),
  509. action: { menuAction in
  510. NCFunctionCenter.shared.openActivityViewController(selectOcId: self.selectOcId)
  511. self.tapSelect(sender: self)
  512. }
  513. )
  514. )
  515. //
  516. // SAVE TO PHOTO GALLERY
  517. //
  518. actions.append(
  519. NCMenuAction(
  520. title: NSLocalizedString("_save_selected_files_", comment: ""),
  521. icon: NCUtility.shared.loadImage(named: "square.and.arrow.down"),
  522. action: { menuAction in
  523. for ocId in self.selectOcId {
  524. if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  525. if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue {
  526. if let metadataMOV = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
  527. NCFunctionCenter.shared.saveLivePhoto(metadata: metadata, metadataMOV: metadataMOV)
  528. } else {
  529. if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
  530. NCFunctionCenter.shared.saveAlbum(metadata: metadata)
  531. } else {
  532. NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorSaveAlbum)
  533. }
  534. }
  535. }
  536. }
  537. }
  538. self.tapSelect(sender: self)
  539. }
  540. )
  541. )
  542. //
  543. // COPY - MOVE
  544. //
  545. actions.append(
  546. NCMenuAction(
  547. title: NSLocalizedString("_move_or_copy_selected_files_", comment: ""),
  548. icon: NCUtility.shared.loadImage(named: "arrow.up.right.square"),
  549. action: { menuAction in
  550. var meradatasSelect = [tableMetadata]()
  551. for ocId in self.selectOcId {
  552. if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  553. meradatasSelect.append(metadata)
  554. }
  555. }
  556. if meradatasSelect.count > 0 {
  557. NCFunctionCenter.shared.openSelectView(items: meradatasSelect, viewController: self)
  558. }
  559. self.tapSelect(sender: self)
  560. }
  561. )
  562. )
  563. //
  564. // COPY
  565. //
  566. actions.append(
  567. NCMenuAction(
  568. title: NSLocalizedString("_copy_file_", comment: ""),
  569. icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
  570. action: { menuAction in
  571. self.appDelegate.pasteboardOcIds.removeAll()
  572. for ocId in self.selectOcId {
  573. self.appDelegate.pasteboardOcIds.append(ocId)
  574. }
  575. NCFunctionCenter.shared.copyPasteboard()
  576. self.tapSelect(sender: self)
  577. }
  578. )
  579. )
  580. //
  581. // DELETE
  582. //
  583. actions.append(
  584. NCMenuAction(
  585. title: NSLocalizedString("_delete_selected_files_", comment: ""),
  586. icon: NCUtility.shared.loadImage(named: "trash"),
  587. action: { menuAction in
  588. let alertController = UIAlertController(title: "", message: NSLocalizedString("_want_delete_", comment: ""), preferredStyle: .alert)
  589. alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (action:UIAlertAction) in
  590. for ocId in self.selectOcId {
  591. if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  592. NCOperationQueue.shared.delete(metadata: metadata, onlyLocalCache: false)
  593. }
  594. }
  595. self.tapSelect(sender: self)
  596. })
  597. alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_local_file_", comment: ""), style: .default) { (action:UIAlertAction) in
  598. for ocId in self.selectOcId {
  599. if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  600. NCOperationQueue.shared.delete(metadata: metadata, onlyLocalCache: true)
  601. }
  602. }
  603. self.tapSelect(sender: self)
  604. })
  605. alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_delete_", comment: ""), style: .default) { (action:UIAlertAction) in })
  606. self.present(alertController, animated: true, completion:nil)
  607. }
  608. )
  609. )
  610. presentMenu(with: actions)
  611. }
  612. }