CCMain+Menu.swift 30 KB

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