CCMain+Menu.swift 30 KB

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