CCMain+Menu.swift 29 KB

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