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