NCCollectionViewCommon+Menu.swift 31 KB

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