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. 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 isDirectoryLock = false
  203. var isOffline = false
  204. let isFolderEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl+"/"+metadata.fileName, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account)
  205. if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!)) {
  206. if (directory.lock && CCUtility.getBlockCode() != nil && appDelegate.sessionePasscodeLock == nil) {
  207. isDirectoryLock = true
  208. }
  209. isOffline = directory.offline
  210. }
  211. actions.append(
  212. NCMenuAction(
  213. title: metadata.fileNameView,
  214. icon: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement),
  215. action: nil
  216. )
  217. )
  218. actions.append(
  219. NCMenuAction(
  220. title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
  221. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  222. action: { menuAction in
  223. NCNetworking.sharedInstance.favoriteMetadata(metadata, url: appDelegate.activeUrl) { (errorCode, errorDescription) in }
  224. }
  225. )
  226. )
  227. if (!isDirectoryLock && !isFolderEncrypted) {
  228. actions.append(
  229. NCMenuAction(
  230. title: NSLocalizedString("_details_", comment: ""),
  231. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  232. action: { menuAction in
  233. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  234. }
  235. )
  236. )
  237. }
  238. if(!(metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory) && !isDirectoryLock && !metadata.e2eEncrypted) {
  239. actions.append(
  240. NCMenuAction(
  241. title: NSLocalizedString("_rename_", comment: ""),
  242. icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  243. action: { menuAction in
  244. let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
  245. alertController.addTextField { (textField) in
  246. textField.text = metadata.fileNameView
  247. textField.delegate = self as? UITextFieldDelegate
  248. textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
  249. ), for: UIControl.Event.editingChanged)
  250. }
  251. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  252. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  253. let fileNameNew = alertController.textFields![0].text
  254. NCNetworking.sharedInstance.renameMetadata(metadata, fileNameNew: fileNameNew!, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl, viewController: self) { (errorCode, errorDescription) in }
  255. })
  256. okAction.isEnabled = false
  257. alertController.addAction(cancelAction)
  258. alertController.addAction(okAction)
  259. self.present(alertController, animated: true, completion: nil)
  260. }
  261. )
  262. )
  263. }
  264. if (!(metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory) && !isDirectoryLock && !isFolderEncrypted) {
  265. actions.append(
  266. NCMenuAction(
  267. title: NSLocalizedString("_move_or_copy_", comment: ""),
  268. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  269. action: { menuAction in
  270. self.moveOpenWindow([indexPath])
  271. }
  272. )
  273. )
  274. }
  275. if (!isFolderEncrypted) {
  276. actions.append(
  277. NCMenuAction(
  278. title: isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") : NSLocalizedString("_set_available_offline_", comment: ""),
  279. icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  280. action: { menuAction in
  281. let serverUrl = CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!
  282. NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, offline: !isOffline, account: appDelegate.activeAccount)
  283. if(isOffline) {
  284. CCSynchronize.shared()?.readFolder(serverUrl, selector: selectorReadFolderWithDownload, account: appDelegate.activeAccount)
  285. }
  286. DispatchQueue.main.async {
  287. self.tableView.reloadRows(at: [indexPath], with: .none)
  288. }
  289. }
  290. )
  291. )
  292. }
  293. actions.append(
  294. NCMenuAction(
  295. title: isDirectoryLock ? NSLocalizedString("_remove_passcode_", comment: "") : NSLocalizedString("_protect_passcode_", comment: ""),
  296. icon: CCGraphics.changeThemingColorImage(UIImage(named: "settingsPasscodeYES"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  297. action: { menuAction in
  298. self.perform(#selector(self.comandoLockPassword))
  299. }
  300. )
  301. )
  302. if (!metadata.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.activeAccount)) {
  303. actions.append(
  304. NCMenuAction(
  305. title: NSLocalizedString("_e2e_set_folder_encrypted_", comment: ""),
  306. icon: CCGraphics.changeThemingColorImage(UIImage(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  307. action: { menuAction in
  308. DispatchQueue.global(qos: .userInitiated).async {
  309. let serverUrl = self.serverUrl + "/" + metadata.fileName
  310. let error = NCNetworkingEndToEnd.sharedManager()?.markFolderEncrypted(onServerUrl: serverUrl, fileId: metadata.fileId, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl)
  311. DispatchQueue.main.async {
  312. if (error != nil) {
  313. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_mark_folder_", comment: ""), description: error?.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: (error! as NSError).code)
  314. } else {
  315. NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl))
  316. NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: nil, ocId: nil, fileId: nil, encrypted: true, richWorkspace: nil, account: metadata.account)
  317. NCManageDatabase.sharedInstance.setMetadataEncrypted(ocId: metadata.ocId, encrypted: true)
  318. NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: self.serverUrl, ocId: metadata.ocId, action: k_action_MOD)
  319. }
  320. }
  321. }
  322. }
  323. )
  324. )
  325. }
  326. if (metadata.e2eEncrypted && !metadataFolder.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.activeAccount)) {
  327. actions.append(
  328. NCMenuAction(
  329. title: NSLocalizedString("_e2e_remove_folder_encrypted_", comment: ""),
  330. icon: CCGraphics.changeThemingColorImage(UIImage(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  331. action: { menuAction in
  332. DispatchQueue.global(qos: .userInitiated).async {
  333. let serverUrl = self.serverUrl + "/" + metadata.fileName
  334. let error = NCNetworkingEndToEnd.sharedManager()?.deletemarkEndToEndFolderEncrypted(onServerUrl: serverUrl, fileId: metadata.fileId, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl)
  335. DispatchQueue.main.async {
  336. if (error != nil) {
  337. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_delete_mark_folder_", comment: ""), description: error?.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: (error! as NSError).code)
  338. } else {
  339. NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, "\(self.serverUrl ?? "")/\(metadata.fileName)"))
  340. NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: nil, ocId: nil, fileId: nil, encrypted: false, richWorkspace: nil, account: metadata.account)
  341. NCManageDatabase.sharedInstance.setMetadataEncrypted(ocId: metadata.ocId, encrypted: false)
  342. NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: self.serverUrl, ocId: metadata.ocId, action: k_action_MOD)
  343. }
  344. }
  345. }
  346. }
  347. )
  348. )
  349. }
  350. } else {
  351. var iconHeader: UIImage!
  352. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) {
  353. iconHeader = icon
  354. } else {
  355. iconHeader = UIImage(named: metadata.iconName)
  356. }
  357. let isEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account)
  358. actions.append(
  359. NCMenuAction(
  360. title: metadata.fileNameView,
  361. icon: iconHeader,
  362. action: nil
  363. )
  364. )
  365. actions.append(
  366. NCMenuAction(
  367. title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
  368. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  369. action: { menuAction in
  370. NCNetworking.sharedInstance.favoriteMetadata(metadata, url: appDelegate.activeUrl) { (errorCode, errorDescription) in }
  371. }
  372. )
  373. )
  374. if (!isEncrypted) {
  375. actions.append(
  376. NCMenuAction(
  377. title: NSLocalizedString("_details_", comment: ""),
  378. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  379. action: { menuAction in
  380. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  381. }
  382. )
  383. )
  384. }
  385. if(!NCBrandOptions.sharedInstance.disable_openin_file) {
  386. actions.append(
  387. NCMenuAction(title: NSLocalizedString("_open_in_", comment: ""),
  388. icon: CCGraphics.changeThemingColorImage(UIImage(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  389. action: { menuAction in
  390. self.tableView.setEditing(false, animated: true)
  391. NCMainCommon.sharedInstance.downloadOpen(metadata: metadata, selector: selectorOpenIn)
  392. }
  393. )
  394. )
  395. }
  396. actions.append(
  397. NCMenuAction(
  398. title: NSLocalizedString("_rename_", comment: ""),
  399. icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  400. action: { menuAction in
  401. let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
  402. alertController.addTextField { (textField) in
  403. textField.text = metadata.fileNameView
  404. textField.delegate = self as? UITextFieldDelegate
  405. textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
  406. ), for: UIControl.Event.editingChanged)
  407. }
  408. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  409. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  410. let fileNameNew = alertController.textFields![0].text
  411. NCNetworking.sharedInstance.renameMetadata(metadata, fileNameNew: fileNameNew!, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl, viewController: self) { (errorCode, errorDescription) in }
  412. })
  413. okAction.isEnabled = false
  414. alertController.addAction(cancelAction)
  415. alertController.addAction(okAction)
  416. self.present(alertController, animated: true, completion: nil)
  417. }
  418. )
  419. )
  420. if (!isEncrypted) {
  421. actions.append(
  422. NCMenuAction(
  423. title: NSLocalizedString("_move_or_copy_", comment: ""),
  424. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  425. action: { menuAction in
  426. self.moveOpenWindow([indexPath])
  427. }
  428. )
  429. )
  430. }
  431. if (!isEncrypted) {
  432. let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  433. var title: String!
  434. if (localFile == nil || localFile!.offline == false) {
  435. title = NSLocalizedString("_set_available_offline_", comment: "")
  436. } else {
  437. title = NSLocalizedString("_remove_available_offline_", comment: "")
  438. }
  439. actions.append(
  440. NCMenuAction(
  441. title: title,
  442. icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  443. action: { menuAction in
  444. if (localFile == nil || !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView)) {
  445. metadata.session = k_download_session
  446. metadata.sessionError = ""
  447. metadata.sessionSelector = selectorLoadOffline
  448. metadata.status = Int(k_metadataStatusWaitDownload)
  449. NCManageDatabase.sharedInstance.addMetadata(metadata)
  450. if let metadataLivePhoto = NCUtility.sharedInstance.isLivePhoto(metadata: metadata) {
  451. metadataLivePhoto.session = k_download_session
  452. metadataLivePhoto.sessionError = ""
  453. metadataLivePhoto.sessionSelector = selectorLoadOffline
  454. metadataLivePhoto.status = Int(k_metadataStatusWaitDownload)
  455. NCManageDatabase.sharedInstance.addMetadata(metadataLivePhoto)
  456. }
  457. NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: self.serverUrl, ocId: metadata.ocId, action: k_action_MOD)
  458. appDelegate.startLoadAutoDownloadUpload()
  459. } else {
  460. NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: !localFile!.offline)
  461. DispatchQueue.main.async {
  462. self.tableView.reloadRows(at: [indexPath], with: .none)
  463. }
  464. }
  465. }
  466. )
  467. )
  468. }
  469. }
  470. actions.append(
  471. NCMenuAction(
  472. title: NSLocalizedString("_delete_", comment: ""),
  473. icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
  474. action: { menuAction in
  475. self.actionDelete(indexPath)
  476. }
  477. )
  478. )
  479. return actions
  480. }
  481. }