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