CCMain+Menu.swift 29 KB

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