CCMain+Menu.swift 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. //
  2. // CCMain+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 <philippe.weidmann@infomaniak.com>
  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 FloatingPanel
  26. extension CCMain {
  27. private func initSortMenu() -> [NCMenuAction] {
  28. var actions = [NCMenuAction]()
  29. actions.append(
  30. NCMenuAction(
  31. title: NSLocalizedString("_order_by_name_a_z_", comment: ""),
  32. icon: CCGraphics.changeThemingColorImage(UIImage(named: "sortFileNameAZ"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  33. onTitle: NSLocalizedString("_order_by_name_z_a_", comment: ""),
  34. onIcon: CCGraphics.changeThemingColorImage(UIImage(named: "sortFileNameZA"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  35. selected: CCUtility.getOrderSettings() == "fileName",
  36. on: CCUtility.getAscendingSettings(),
  37. action: { menuAction in
  38. if(CCUtility.getOrderSettings() == "fileName") {
  39. CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
  40. } else {
  41. CCUtility.setOrderSettings("fileName")
  42. }
  43. NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_clearDateReadDataSource), object: nil)
  44. }
  45. )
  46. )
  47. actions.append(
  48. NCMenuAction(
  49. title: NSLocalizedString("_order_by_date_more_recent_", comment: ""),
  50. icon: CCGraphics.changeThemingColorImage(UIImage(named: "sortDateMoreRecent"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  51. onTitle: NSLocalizedString("_order_by_date_less_recent_", comment: ""),
  52. onIcon: CCGraphics.changeThemingColorImage(UIImage(named: "sortDateLessRecent"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  53. selected: CCUtility.getOrderSettings() == "date",
  54. on: CCUtility.getAscendingSettings(),
  55. action: { menuAction in
  56. if(CCUtility.getOrderSettings() == "date") {
  57. CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
  58. } else {
  59. CCUtility.setOrderSettings("date")
  60. }
  61. NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_clearDateReadDataSource), object: nil)
  62. }
  63. )
  64. )
  65. actions.append(
  66. NCMenuAction(
  67. title: NSLocalizedString("_order_by_size_smallest_", comment: ""),
  68. icon: CCGraphics.changeThemingColorImage(UIImage(named: "sortSmallest"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  69. onTitle: NSLocalizedString("_order_by_size_largest_", comment: ""),
  70. onIcon: CCGraphics.changeThemingColorImage(UIImage(named: "sortLargest"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  71. selected: CCUtility.getOrderSettings() == "size",
  72. on: CCUtility.getAscendingSettings(),
  73. action: { menuAction in
  74. if(CCUtility.getOrderSettings() == "size") {
  75. CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
  76. } else {
  77. CCUtility.setOrderSettings("size")
  78. }
  79. NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_clearDateReadDataSource), object: nil)
  80. }
  81. )
  82. )
  83. actions.append(
  84. NCMenuAction(
  85. title: NSLocalizedString("_directory_on_top_no_", comment: ""),
  86. icon: CCGraphics.changeThemingColorImage(UIImage(named: "foldersOnTop"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  87. selected: CCUtility.getDirectoryOnTop(),
  88. on: CCUtility.getDirectoryOnTop(),
  89. action: { menuAction in
  90. CCUtility.setDirectoryOnTop(!CCUtility.getDirectoryOnTop())
  91. NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_clearDateReadDataSource), object: nil)
  92. }
  93. )
  94. )
  95. return actions
  96. }
  97. @objc func toggleMenu(viewController: UIViewController) {
  98. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  99. mainMenuViewController.actions = self.initSortMenu()
  100. let menuPanelController = NCMenuPanelController()
  101. menuPanelController.parentPresenter = viewController
  102. menuPanelController.delegate = mainMenuViewController
  103. menuPanelController.set(contentViewController: mainMenuViewController)
  104. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  105. viewController.present(menuPanelController, animated: true, completion: nil)
  106. }
  107. @objc func toggleSelectMenu(viewController: UIViewController) {
  108. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  109. mainMenuViewController.actions = self.initSelectMenu()
  110. let menuPanelController = NCMenuPanelController()
  111. menuPanelController.parentPresenter = viewController
  112. menuPanelController.delegate = mainMenuViewController
  113. menuPanelController.set(contentViewController: mainMenuViewController)
  114. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  115. viewController.present(menuPanelController, animated: true, completion: nil)
  116. }
  117. private func initSelectMenu() -> [NCMenuAction] {
  118. var actions = [NCMenuAction]()
  119. actions.append(
  120. NCMenuAction(
  121. title: NSLocalizedString("_select_all_", comment: ""),
  122. icon: CCGraphics.changeThemingColorImage(UIImage(named: "selectFull"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  123. action: { menuAction in
  124. self.didSelectAll()
  125. }
  126. )
  127. )
  128. actions.append(
  129. NCMenuAction(
  130. title: NSLocalizedString("_move_or_copy_selected_files_", comment: ""),
  131. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  132. action: { menuAction in
  133. self.moveOpenWindow(self.tableView.indexPathsForSelectedRows)
  134. }
  135. )
  136. )
  137. actions.append(
  138. NCMenuAction(
  139. title: NSLocalizedString("_download_selected_files_folders_", comment: ""),
  140. icon: CCGraphics.changeThemingColorImage(UIImage(named: "downloadSelectedFiles"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  141. action: { menuAction in
  142. self.downloadSelectedFilesFolders()
  143. }
  144. )
  145. )
  146. actions.append(
  147. NCMenuAction(
  148. title: NSLocalizedString("_save_selected_files_", comment: ""),
  149. icon: CCGraphics.changeThemingColorImage(UIImage(named: "saveSelectedFiles"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  150. action: { menuAction in
  151. self.saveSelectedFiles()
  152. }
  153. )
  154. )
  155. actions.append(
  156. NCMenuAction(
  157. title: NSLocalizedString("_delete_selected_files_", comment: ""),
  158. icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
  159. action: { menuAction in
  160. self.deleteMetadatas()
  161. }
  162. )
  163. )
  164. return actions
  165. }
  166. private func initMoreMenu(indexPath: IndexPath, metadata: tableMetadata, metadataFolder: tableMetadata) -> [NCMenuAction] {
  167. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  168. let autoUploadFileName = NCManageDatabase.sharedInstance.getAccountAutoUploadFileName()
  169. let autoUploadDirectory = NCManageDatabase.sharedInstance.getAccountAutoUploadDirectory(appDelegate.activeUrl)
  170. var actions = [NCMenuAction]()
  171. if (metadata.directory) {
  172. var isDirectoryLock = false
  173. var isOffline = false
  174. let isFolderEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl+"/"+metadata.fileName, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account)
  175. if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!)) {
  176. if (directory.lock && CCUtility.getBlockCode() != nil && appDelegate.sessionePasscodeLock == nil) {
  177. isDirectoryLock = true
  178. }
  179. isOffline = directory.offline
  180. }
  181. actions.append(
  182. NCMenuAction(
  183. title: metadata.fileNameView,
  184. icon: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement),
  185. action: nil
  186. )
  187. )
  188. actions.append(
  189. NCMenuAction(
  190. title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
  191. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  192. action: { menuAction in
  193. NCNetworking.sharedInstance.favoriteMetadata(metadata, url: appDelegate.activeUrl) { (errorCode, errorDescription) in }
  194. }
  195. )
  196. )
  197. if (!isDirectoryLock && !isFolderEncrypted) {
  198. actions.append(
  199. NCMenuAction(
  200. title: NSLocalizedString("_details_", comment: ""),
  201. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  202. action: { menuAction in
  203. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  204. }
  205. )
  206. )
  207. }
  208. if(!(metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory) && !isDirectoryLock && !metadata.e2eEncrypted) {
  209. actions.append(
  210. NCMenuAction(
  211. title: NSLocalizedString("_rename_", comment: ""),
  212. icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  213. action: { menuAction in
  214. let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
  215. alertController.addTextField { (textField) in
  216. textField.text = metadata.fileNameView
  217. textField.delegate = self as? UITextFieldDelegate
  218. textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
  219. ), for: UIControl.Event.editingChanged)
  220. }
  221. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  222. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  223. let fileNameNew = alertController.textFields![0].text
  224. NCNetworking.sharedInstance.renameMetadata(metadata, fileNameNew: fileNameNew!, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl, viewController: self) { (errorCode, errorDescription) in }
  225. })
  226. okAction.isEnabled = false
  227. alertController.addAction(cancelAction)
  228. alertController.addAction(okAction)
  229. self.present(alertController, animated: true, completion: nil)
  230. }
  231. )
  232. )
  233. }
  234. if (!(metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory) && !isDirectoryLock && !isFolderEncrypted) {
  235. actions.append(
  236. NCMenuAction(
  237. title: NSLocalizedString("_move_or_copy_", comment: ""),
  238. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  239. action: { menuAction in
  240. self.moveOpenWindow([indexPath])
  241. }
  242. )
  243. )
  244. }
  245. if (!isFolderEncrypted) {
  246. actions.append(
  247. NCMenuAction(
  248. title: isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") : NSLocalizedString("_set_available_offline_", comment: ""),
  249. icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  250. action: { menuAction in
  251. let serverUrl = CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!
  252. NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, offline: !isOffline, account: appDelegate.activeAccount)
  253. if(isOffline) {
  254. CCSynchronize.shared()?.readFolder(serverUrl, selector: selectorReadFolderWithDownload, account: appDelegate.activeAccount)
  255. }
  256. DispatchQueue.main.async {
  257. self.tableView.reloadRows(at: [indexPath], with: .none)
  258. }
  259. }
  260. )
  261. )
  262. }
  263. actions.append(
  264. NCMenuAction(
  265. title: isDirectoryLock ? NSLocalizedString("_remove_passcode_", comment: "") : NSLocalizedString("_protect_passcode_", comment: ""),
  266. icon: CCGraphics.changeThemingColorImage(UIImage(named: "settingsPasscodeYES"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  267. action: { menuAction in
  268. self.perform(#selector(self.comandoLockPassword))
  269. }
  270. )
  271. )
  272. if (!metadata.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.activeAccount)) {
  273. actions.append(
  274. NCMenuAction(
  275. title: NSLocalizedString("_e2e_set_folder_encrypted_", comment: ""),
  276. icon: CCGraphics.changeThemingColorImage(UIImage(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  277. action: { menuAction in
  278. DispatchQueue.global(qos: .userInitiated).async {
  279. let serverUrl = self.serverUrl + "/" + metadata.fileName
  280. let error = NCNetworkingEndToEnd.sharedManager()?.markFolderEncrypted(onServerUrl: serverUrl, fileId: metadata.fileId, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl)
  281. DispatchQueue.main.async {
  282. if (error != nil) {
  283. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_mark_folder_", comment: ""), description: error?.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: (error! as NSError).code)
  284. } else {
  285. NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl))
  286. NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: nil, ocId: nil, fileId: nil, encrypted: true, richWorkspace: nil, account: metadata.account)
  287. NCManageDatabase.sharedInstance.setMetadataEncrypted(ocId: metadata.ocId, encrypted: true)
  288. NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: self.serverUrl, ocId: metadata.ocId, action: k_action_MOD)
  289. }
  290. }
  291. }
  292. }
  293. )
  294. )
  295. }
  296. if (metadata.e2eEncrypted && !metadataFolder.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.activeAccount)) {
  297. actions.append(
  298. NCMenuAction(
  299. title: NSLocalizedString("_e2e_remove_folder_encrypted_", comment: ""),
  300. icon: CCGraphics.changeThemingColorImage(UIImage(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  301. action: { menuAction in
  302. DispatchQueue.global(qos: .userInitiated).async {
  303. let serverUrl = self.serverUrl + "/" + metadata.fileName
  304. let error = NCNetworkingEndToEnd.sharedManager()?.deletemarkEndToEndFolderEncrypted(onServerUrl: serverUrl, fileId: metadata.fileId, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl)
  305. DispatchQueue.main.async {
  306. if (error != nil) {
  307. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_delete_mark_folder_", comment: ""), description: error?.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: (error! as NSError).code)
  308. } else {
  309. NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, "\(self.serverUrl ?? "")/\(metadata.fileName)"))
  310. NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: nil, ocId: nil, fileId: nil, encrypted: false, richWorkspace: nil, account: metadata.account)
  311. NCManageDatabase.sharedInstance.setMetadataEncrypted(ocId: metadata.ocId, encrypted: false)
  312. NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: self.serverUrl, ocId: metadata.ocId, action: k_action_MOD)
  313. }
  314. }
  315. }
  316. }
  317. )
  318. )
  319. }
  320. } else {
  321. var iconHeader: UIImage!
  322. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) {
  323. iconHeader = icon
  324. } else {
  325. iconHeader = UIImage(named: metadata.iconName)
  326. }
  327. let isEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account)
  328. actions.append(
  329. NCMenuAction(
  330. title: metadata.fileNameView,
  331. icon: iconHeader,
  332. action: nil
  333. )
  334. )
  335. actions.append(
  336. NCMenuAction(
  337. title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
  338. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  339. action: { menuAction in
  340. NCNetworking.sharedInstance.favoriteMetadata(metadata, url: appDelegate.activeUrl) { (errorCode, errorDescription) in }
  341. }
  342. )
  343. )
  344. if (!isEncrypted) {
  345. actions.append(
  346. NCMenuAction(
  347. title: NSLocalizedString("_details_", comment: ""),
  348. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  349. action: { menuAction in
  350. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  351. }
  352. )
  353. )
  354. }
  355. if(!NCBrandOptions.sharedInstance.disable_openin_file) {
  356. actions.append(
  357. NCMenuAction(title: NSLocalizedString("_open_in_", comment: ""),
  358. icon: CCGraphics.changeThemingColorImage(UIImage(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  359. action: { menuAction in
  360. self.tableView.setEditing(false, animated: true)
  361. NCMainCommon.sharedInstance.downloadOpen(metadata: metadata, selector: selectorOpenIn)
  362. }
  363. )
  364. )
  365. }
  366. actions.append(
  367. NCMenuAction(
  368. title: NSLocalizedString("_rename_", comment: ""),
  369. icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  370. action: { menuAction in
  371. let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
  372. alertController.addTextField { (textField) in
  373. textField.text = metadata.fileNameView
  374. textField.delegate = self as? UITextFieldDelegate
  375. textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
  376. ), for: UIControl.Event.editingChanged)
  377. }
  378. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  379. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  380. let fileNameNew = alertController.textFields![0].text
  381. NCNetworking.sharedInstance.renameMetadata(metadata, fileNameNew: fileNameNew!, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl, viewController: self) { (errorCode, errorDescription) in }
  382. })
  383. okAction.isEnabled = false
  384. alertController.addAction(cancelAction)
  385. alertController.addAction(okAction)
  386. self.present(alertController, animated: true, completion: nil)
  387. }
  388. )
  389. )
  390. if (!isEncrypted) {
  391. actions.append(
  392. NCMenuAction(
  393. title: NSLocalizedString("_move_or_copy_", comment: ""),
  394. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  395. action: { menuAction in
  396. self.moveOpenWindow([indexPath])
  397. }
  398. )
  399. )
  400. }
  401. if (!isEncrypted) {
  402. let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  403. var title: String!
  404. if (localFile == nil || localFile!.offline == false) {
  405. title = NSLocalizedString("_set_available_offline_", comment: "")
  406. } else {
  407. title = NSLocalizedString("_remove_available_offline_", comment: "")
  408. }
  409. actions.append(
  410. NCMenuAction(
  411. title: title,
  412. icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  413. action: { menuAction in
  414. if (localFile == nil || !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView)) {
  415. metadata.session = k_download_session
  416. metadata.sessionError = ""
  417. metadata.sessionSelector = selectorLoadOffline
  418. metadata.status = Int(k_metadataStatusWaitDownload)
  419. NCManageDatabase.sharedInstance.addMetadata(metadata)
  420. if let metadataLivePhoto = NCUtility.sharedInstance.isLivePhoto(metadata: metadata) {
  421. metadataLivePhoto.session = k_download_session
  422. metadataLivePhoto.sessionError = ""
  423. metadataLivePhoto.sessionSelector = selectorLoadOffline
  424. metadataLivePhoto.status = Int(k_metadataStatusWaitDownload)
  425. NCManageDatabase.sharedInstance.addMetadata(metadataLivePhoto)
  426. }
  427. NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: self.serverUrl, ocId: metadata.ocId, action: k_action_MOD)
  428. appDelegate.startLoadAutoDownloadUpload()
  429. } else {
  430. NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: !localFile!.offline)
  431. DispatchQueue.main.async {
  432. self.tableView.reloadRows(at: [indexPath], with: .none)
  433. }
  434. }
  435. }
  436. )
  437. )
  438. }
  439. }
  440. actions.append(
  441. NCMenuAction(
  442. title: NSLocalizedString("_delete_", comment: ""),
  443. icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
  444. action: { menuAction in
  445. self.actionDelete(indexPath)
  446. }
  447. )
  448. )
  449. return actions
  450. }
  451. @objc func toggleMoreMenu(viewController: UIViewController, indexPath: IndexPath, metadata: tableMetadata, metadataFolder: tableMetadata) {
  452. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  453. mainMenuViewController.actions = self.initMoreMenu(indexPath: indexPath, metadata: metadata, metadataFolder: metadataFolder)
  454. let menuPanelController = NCMenuPanelController()
  455. menuPanelController.parentPresenter = viewController
  456. menuPanelController.delegate = mainMenuViewController
  457. menuPanelController.set(contentViewController: mainMenuViewController)
  458. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  459. viewController.present(menuPanelController, animated: true, completion: nil)
  460. }
  461. }