CCMain+Menu.swift 29 KB

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