CCMain+Menu.swift 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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_reloadDataSource), 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_reloadDataSource), 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_reloadDataSource), 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_reloadDataSource), 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. NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_reloadDataSource), object: nil, userInfo: ["ocId":metadata.ocId,"serverUrl":metadata.serverUrl])
  282. }
  283. )
  284. )
  285. }
  286. if (!metadata.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.activeAccount)) {
  287. actions.append(
  288. NCMenuAction(
  289. title: NSLocalizedString("_e2e_set_folder_encrypted_", comment: ""),
  290. icon: CCGraphics.changeThemingColorImage(UIImage(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  291. action: { menuAction in
  292. NCCommunication.shared.markE2EEFolder(fileId: metadata.fileId, delete: false) { (account, errorCode, errorDescription) in
  293. if errorCode == 0 {
  294. let serverUrl = self.serverUrl + "/" + metadata.fileName
  295. NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl))
  296. NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: nil, ocId: nil, fileId: nil, encrypted: true, richWorkspace: nil, account: metadata.account)
  297. NCManageDatabase.sharedInstance.setMetadataEncrypted(ocId: metadata.ocId, encrypted: true)
  298. NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_reloadDataSource), object: nil, userInfo: ["ocId":metadata.ocId,"serverUrl":metadata.serverUrl])
  299. } else {
  300. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_mark_folder_", comment: ""), description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: errorCode)
  301. }
  302. }
  303. }
  304. )
  305. )
  306. }
  307. if (metadata.e2eEncrypted && !metadataFolder.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.activeAccount)) {
  308. actions.append(
  309. NCMenuAction(
  310. title: NSLocalizedString("_e2e_remove_folder_encrypted_", comment: ""),
  311. icon: CCGraphics.changeThemingColorImage(UIImage(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  312. action: { menuAction in
  313. NCCommunication.shared.markE2EEFolder(fileId: metadata.fileId, delete: true) { (account, errorCode, errorDescription) in
  314. if errorCode == 0 {
  315. let serverUrl = self.serverUrl + "/" + metadata.fileName
  316. NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, "\(self.serverUrl ?? "")/\(metadata.fileName)"))
  317. NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: nil, ocId: nil, fileId: nil, encrypted: false, richWorkspace: nil, account: metadata.account)
  318. NCManageDatabase.sharedInstance.setMetadataEncrypted(ocId: metadata.ocId, encrypted: false)
  319. NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_reloadDataSource), object: nil, userInfo: ["ocId":metadata.ocId,"serverUrl":metadata.serverUrl])
  320. } else {
  321. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_delete_mark_folder_", comment: ""), description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: errorCode)
  322. }
  323. }
  324. }
  325. )
  326. )
  327. }
  328. } else {
  329. var iconHeader: UIImage!
  330. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) {
  331. iconHeader = icon
  332. } else {
  333. iconHeader = UIImage(named: metadata.iconName)
  334. }
  335. let isEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account)
  336. actions.append(
  337. NCMenuAction(
  338. title: metadata.fileNameView,
  339. icon: iconHeader,
  340. action: nil
  341. )
  342. )
  343. actions.append(
  344. NCMenuAction(
  345. title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
  346. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  347. action: { menuAction in
  348. NCNetworking.shared.favoriteMetadata(metadata, url: appDelegate.activeUrl) { (errorCode, errorDescription) in }
  349. }
  350. )
  351. )
  352. if (!isEncrypted) {
  353. actions.append(
  354. NCMenuAction(
  355. title: NSLocalizedString("_details_", comment: ""),
  356. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  357. action: { menuAction in
  358. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  359. }
  360. )
  361. )
  362. }
  363. if(!NCBrandOptions.sharedInstance.disable_openin_file) {
  364. actions.append(
  365. NCMenuAction(title: NSLocalizedString("_open_in_", comment: ""),
  366. icon: CCGraphics.changeThemingColorImage(UIImage(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  367. action: { menuAction in
  368. self.tableView.setEditing(false, animated: true)
  369. NCMainCommon.sharedInstance.downloadOpen(metadata: metadata, selector: selectorOpenIn)
  370. }
  371. )
  372. )
  373. }
  374. actions.append(
  375. NCMenuAction(
  376. title: NSLocalizedString("_rename_", comment: ""),
  377. icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  378. action: { menuAction in
  379. let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
  380. alertController.addTextField { (textField) in
  381. textField.text = metadata.fileNameView
  382. textField.delegate = self as? UITextFieldDelegate
  383. textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
  384. ), for: UIControl.Event.editingChanged)
  385. }
  386. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  387. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  388. let fileNameNew = alertController.textFields![0].text
  389. NCNetworking.shared.renameMetadata(metadata, fileNameNew: fileNameNew!, url: appDelegate.activeUrl, viewController: self) { (errorCode, errorDescription) in }
  390. })
  391. okAction.isEnabled = false
  392. alertController.addAction(cancelAction)
  393. alertController.addAction(okAction)
  394. self.present(alertController, animated: true, completion: nil)
  395. }
  396. )
  397. )
  398. if (!isEncrypted) {
  399. actions.append(
  400. NCMenuAction(
  401. title: NSLocalizedString("_move_or_copy_", comment: ""),
  402. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  403. action: { menuAction in
  404. self.moveOpenWindow([indexPath])
  405. }
  406. )
  407. )
  408. }
  409. if (!isEncrypted) {
  410. let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  411. var title: String!
  412. if (localFile == nil || localFile!.offline == false) {
  413. title = NSLocalizedString("_set_available_offline_", comment: "")
  414. } else {
  415. title = NSLocalizedString("_remove_available_offline_", comment: "")
  416. }
  417. actions.append(
  418. NCMenuAction(
  419. title: title,
  420. icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  421. action: { menuAction in
  422. if (localFile == nil || !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView)) {
  423. NCNetworking.shared.download(metadata: metadata, selector: selectorLoadOffline) { (_) in }
  424. if let metadataLivePhoto = NCUtility.sharedInstance.isLivePhoto(metadata: metadata) {
  425. NCNetworking.shared.download(metadata: metadataLivePhoto, selector: selectorLoadOffline) { (_) in }
  426. }
  427. } else {
  428. NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: !localFile!.offline)
  429. NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_reloadDataSource), object: nil, userInfo: ["ocId":metadata.ocId,"serverUrl":metadata.serverUrl])
  430. }
  431. }
  432. )
  433. )
  434. }
  435. }
  436. actions.append(
  437. NCMenuAction(
  438. title: NSLocalizedString("_delete_", comment: ""),
  439. icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
  440. action: { menuAction in
  441. self.actionDelete(indexPath)
  442. }
  443. )
  444. )
  445. return actions
  446. }
  447. }