CCMain+Menu.swift 31 KB

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