NCCollectionViewCommon+Menu.swift 31 KB

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