NCCollectionViewCommon+Menu.swift 31 KB

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