MainMenuManager.swift 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. //
  2. // MainMenuManager.swift
  3. // Nextcloud
  4. //
  5. // Created by Philippe Weidmann on 16.01.20.
  6. // Copyright © 2020 TWS. All rights reserved.
  7. //
  8. import FloatingPanel
  9. extension AppDelegate {
  10. private func initMenu() -> [MenuAction] {
  11. var actions = [MenuAction]()
  12. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  13. var isNextcloudTextAvailable = false
  14. if appDelegate.reachability.isReachable() && NCBrandBeta.shared.directEditing && NCManageDatabase.sharedInstance.getDirectEditingCreators(account: appDelegate.activeAccount) != nil {
  15. isNextcloudTextAvailable = true
  16. }
  17. actions.append(MenuAction(title: NSLocalizedString("_upload_photos_videos_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "file_photo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  18. appDelegate.activeMain.openAssetsPickerController()
  19. }))
  20. actions.append(MenuAction(title: NSLocalizedString("_upload_file_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "file"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  21. action: { menuAction in
  22. appDelegate.activeMain.openImportDocumentPicker()
  23. }))
  24. if NCBrandOptions.sharedInstance.use_imi_viewer {
  25. actions.append(MenuAction(title: NSLocalizedString("_im_create_new_file", tableName: "IMLocalizable", bundle: Bundle.main, value: "", comment: ""), icon: CCGraphics.scale(UIImage.init(named: "imagemeter"), to: CGSize(width: 25, height: 25), isAspectRation: true), action: { menuAction in
  26. _ = IMCreate.init(serverUrl: appDelegate.activeMain.serverUrl)
  27. }))
  28. }
  29. if isNextcloudTextAvailable {
  30. actions.append(MenuAction(title: NSLocalizedString("_create_nextcloudtext_document_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "file_txt"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  31. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  32. return
  33. }
  34. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  35. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  36. viewController.typeTemplate = k_nextcloudtext_document
  37. viewController.serverUrl = appDelegate.activeMain.serverUrl
  38. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  39. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  40. }))
  41. } else {
  42. actions.append(MenuAction(title: NSLocalizedString("_upload_file_text_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "file_txt"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  43. let storyboard = UIStoryboard(name: "NCText", bundle: nil)
  44. let controller = storyboard.instantiateViewController(withIdentifier: "NCText")
  45. controller.modalPresentationStyle = UIModalPresentationStyle.pageSheet
  46. appDelegate.activeMain.present(controller, animated: true, completion: nil)
  47. }))
  48. }
  49. #if !targetEnvironment(simulator)
  50. if #available(iOS 11.0, *) {
  51. actions.append(MenuAction(title: NSLocalizedString("_scans_document_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "scan"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)), action: { menuAction in
  52. if #available(iOS 11.0, *) {
  53. NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: appDelegate.activeMain)
  54. }
  55. })
  56. }
  57. #endif
  58. actions.append(MenuAction(title: NSLocalizedString("_create_voice_memo_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "microphone"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  59. NCMainCommon.sharedInstance.startAudioRecorder()
  60. }))
  61. actions.append(MenuAction(title: NSLocalizedString("_create_folder_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  62. appDelegate.activeMain.createFolder()
  63. }))
  64. if let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getRichdocumentsMimetypes(account: appDelegate.activeAccount) {
  65. if richdocumentsMimetypes.count > 0 {
  66. actions.append(MenuAction(title: NSLocalizedString("_create_new_document_", comment: ""), icon: UIImage.init(named: "create_file_document")!,
  67. action: { menuAction in
  68. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  69. return
  70. }
  71. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  72. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  73. viewController.typeTemplate = k_richdocument_document
  74. viewController.serverUrl = appDelegate.activeMain.serverUrl
  75. viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
  76. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  77. }))
  78. actions.append(MenuAction(title: NSLocalizedString("_create_new_spreadsheet_", comment: ""), icon: UIImage(named: "create_file_xls")!,
  79. action: { menuAction in
  80. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  81. return
  82. }
  83. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  84. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  85. viewController.typeTemplate = k_richdocument_spreadsheet
  86. viewController.serverUrl = appDelegate.activeMain.serverUrl
  87. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  88. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  89. }))
  90. actions.append(MenuAction(title: NSLocalizedString("_create_new_presentation_", comment: ""), icon: UIImage(named: "create_file_ppt")!,
  91. action: { menuAction in
  92. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  93. return
  94. }
  95. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  96. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  97. viewController.typeTemplate = k_richdocument_presentation
  98. viewController.serverUrl = appDelegate.activeMain.serverUrl
  99. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  100. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  101. }))
  102. }
  103. }
  104. return actions
  105. }
  106. @objc public func showMenuIn(viewController: UIViewController) {
  107. let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
  108. mainMenuViewController.actions = self.initMenu()
  109. let menuPanelController = MenuPanelController()
  110. menuPanelController.panelWidth = Int(viewController.view.frame.width)
  111. menuPanelController.delegate = mainMenuViewController
  112. menuPanelController.set(contentViewController: mainMenuViewController)
  113. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  114. viewController.present(menuPanelController, animated: true, completion: nil)
  115. }
  116. }
  117. extension CCMain {
  118. private func initSortMenu() -> [MenuAction] {
  119. var actions = [MenuAction]()
  120. actions.append(MenuAction(
  121. title: NSLocalizedString("_order_by_name_a_z_", comment: ""),
  122. icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortFileNameAZ"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  123. onTitle: NSLocalizedString("_order_by_name_z_a_", comment: ""),
  124. onIcon: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortFileNameZA"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  125. selected: CCUtility.getOrderSettings() == "fileName",
  126. on: CCUtility.getAscendingSettings(),
  127. action: { menuAction in
  128. if(CCUtility.getOrderSettings() == "fileName" && CCUtility.getAscendingSettings()) {
  129. CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
  130. } else {
  131. CCUtility.setOrderSettings("fileName")
  132. CCUtility.setAscendingSettings(true)
  133. }
  134. NotificationCenter.default.post(name: Notification.Name.init(rawValue: "clearDateReadDataSource"), object: nil)
  135. }))
  136. actions.append(MenuAction(
  137. title: NSLocalizedString("_order_by_date_more_recent_", comment: ""),
  138. icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortDateMoreRecent"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  139. onTitle: NSLocalizedString("_order_by_date_less_recent_", comment: ""),
  140. onIcon: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortDateLessRecent"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  141. selected: CCUtility.getOrderSettings() == "date",
  142. on: CCUtility.getAscendingSettings(),
  143. action: { menuAction in
  144. if(CCUtility.getOrderSettings() == "date" && CCUtility.getAscendingSettings()) {
  145. CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
  146. } else {
  147. CCUtility.setOrderSettings("date")
  148. CCUtility.setAscendingSettings(true)
  149. }
  150. NotificationCenter.default.post(name: Notification.Name.init(rawValue: "clearDateReadDataSource"), object: nil)
  151. }))
  152. actions.append(MenuAction(
  153. title: NSLocalizedString("_order_by_size_smallest_", comment: ""),
  154. icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortSmallest"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  155. onTitle: NSLocalizedString("_order_by_size_largest_", comment: ""),
  156. onIcon: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortLargest"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  157. selected: CCUtility.getOrderSettings() == "size",
  158. on: CCUtility.getAscendingSettings(),
  159. action: { menuAction in
  160. if(CCUtility.getOrderSettings() == "size" && CCUtility.getAscendingSettings()) {
  161. CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
  162. } else {
  163. CCUtility.setOrderSettings("size")
  164. CCUtility.setAscendingSettings(true)
  165. }
  166. NotificationCenter.default.post(name: Notification.Name.init(rawValue: "clearDateReadDataSource"), object: nil)
  167. }))
  168. actions.append(MenuAction(
  169. title: NSLocalizedString("_directory_on_top_no_", comment: ""),
  170. icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "foldersOnTop"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  171. selected: CCUtility.getDirectoryOnTop(),
  172. on: CCUtility.getDirectoryOnTop(),
  173. action: { menuAction in
  174. CCUtility.setDirectoryOnTop(!CCUtility.getDirectoryOnTop())
  175. NotificationCenter.default.post(name: Notification.Name.init(rawValue: "clearDateReadDataSource"), object: nil)
  176. }))
  177. return actions
  178. }
  179. @objc func toggleMenu(viewController: UIViewController) {
  180. let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
  181. mainMenuViewController.actions = self.initSortMenu()
  182. let menuPanelController = MenuPanelController()
  183. menuPanelController.panelWidth = Int(viewController.view.frame.width)
  184. menuPanelController.delegate = mainMenuViewController
  185. menuPanelController.set(contentViewController: mainMenuViewController)
  186. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  187. viewController.present(menuPanelController, animated: true, completion: nil)
  188. }
  189. @objc func toggleSelectMenu(viewController: UIViewController) {
  190. let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
  191. mainMenuViewController.actions = self.initSelectMenu()
  192. let menuPanelController = MenuPanelController()
  193. menuPanelController.panelWidth = Int(viewController.view.frame.width)
  194. menuPanelController.delegate = mainMenuViewController
  195. menuPanelController.set(contentViewController: mainMenuViewController)
  196. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  197. viewController.present(menuPanelController, animated: true, completion: nil)
  198. }
  199. private func initSelectMenu() -> [MenuAction] {
  200. var actions = [MenuAction]()
  201. actions.append(MenuAction(title: NSLocalizedString("_select_all_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "selectFull"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  202. self.didSelectAll()
  203. }))
  204. actions.append(MenuAction(title: NSLocalizedString("_move_selected_files_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  205. self.moveOpenWindow(self.tableView.indexPathsForSelectedRows)
  206. }))
  207. actions.append(MenuAction(title: NSLocalizedString("_download_selected_files_folders_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "downloadSelectedFiles"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  208. self.downloadSelectedFilesFolders()
  209. }))
  210. actions.append(MenuAction(title: NSLocalizedString("_save_selected_files_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "saveSelectedFiles"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  211. self.saveSelectedFiles()
  212. }))
  213. actions.append(MenuAction(title: NSLocalizedString("_delete_selected_files_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  214. self.deleteFile()
  215. }))
  216. return actions
  217. }
  218. private func initMoreMenu(indexPath: IndexPath, metadata: tableMetadata, metadataFolder: tableMetadata) -> [MenuAction] {
  219. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  220. let autoUploadFileName = NCManageDatabase.sharedInstance.getAccountAutoUploadFileName()
  221. let autoUploadDirectory = NCManageDatabase.sharedInstance.getAccountAutoUploadDirectory(appDelegate.activeUrl)
  222. var actions = [MenuAction]()
  223. if (metadata.directory) {
  224. var lockDirectory = false
  225. var isOffline = false
  226. let isFolderEncrypted = CCUtility.isFolderEncrypted("\(self.serverUrl ?? "")/\(metadata.fileName)", account: appDelegate.activeAccount)
  227. var passcodeTitle = NSLocalizedString("_protect_passcode_", comment: "")
  228. let dirServerUrl = CCUtility.stringAppendServerUrl(self.metadata.serverUrl, addFileName: metadata.fileName)!
  229. if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, dirServerUrl)) {
  230. if (CCUtility.getBlockCode() != nil && appDelegate.sessionePasscodeLock == nil) {
  231. lockDirectory = true
  232. }
  233. if (directory.lock) {
  234. passcodeTitle = NSLocalizedString("_protect_passcode_", comment: "")
  235. }
  236. isOffline = directory.offline
  237. }
  238. actions.append(MenuAction(title: metadata.fileNameView, icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement), action: { menuAction in
  239. }))
  240. actions.append(MenuAction(title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite), action: { menuAction in
  241. self.settingFavorite(metadata, favorite: !metadata.favorite)
  242. }))
  243. if (!lockDirectory && !isFolderEncrypted) {
  244. actions.append(MenuAction(title: NSLocalizedString("_details_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  245. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  246. }))
  247. }
  248. if(!(metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory) && !lockDirectory && !metadata.e2eEncrypted) {
  249. actions.append(MenuAction(title: NSLocalizedString("_rename_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  250. let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
  251. alertController.addTextField { (textField) in
  252. textField.text = metadata.fileNameView
  253. textField.delegate = self as? UITextFieldDelegate
  254. textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
  255. ), for: UIControl.Event.editingChanged)
  256. }
  257. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  258. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  259. let fileName = alertController.textFields![0].text
  260. self.perform(#selector(self.renameFile(_:)), on: .main, with: [metadata, fileName!], waitUntilDone: false)
  261. })
  262. okAction.isEnabled = false
  263. alertController.addAction(cancelAction)
  264. alertController.addAction(okAction)
  265. self.present(alertController, animated: true, completion: nil)
  266. }))
  267. }
  268. if (!(metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory) && !lockDirectory && !isFolderEncrypted) {
  269. actions.append(MenuAction(title: NSLocalizedString("_move_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  270. self.moveOpenWindow([indexPath])
  271. }))
  272. }
  273. if (!isFolderEncrypted) {
  274. actions.append(MenuAction(title: isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") : NSLocalizedString("_set_available_offline_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  275. NCManageDatabase.sharedInstance.setDirectory(serverUrl: dirServerUrl, offline: !isOffline, account: appDelegate.activeAccount)
  276. if(isOffline) {
  277. CCSynchronize.shared()?.readFolder(dirServerUrl, selector: selectorReadFolderWithDownload, account: appDelegate.activeAccount)
  278. }
  279. DispatchQueue.main.async {
  280. self.tableView.reloadRows(at: [indexPath], with: .none)
  281. }
  282. }))
  283. }
  284. actions.append(MenuAction(title: passcodeTitle, icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "settingsPasscodeYES"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  285. self.perform(#selector(self.comandoLockPassword))
  286. }))
  287. if (!metadata.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.activeAccount)) {
  288. actions.append(MenuAction(title: NSLocalizedString("_remove_available_offline_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  289. DispatchQueue.global(qos: .userInitiated).async {
  290. let error = NCNetworkingEndToEnd.sharedManager()?.markFolderEncrypted(onServerUrl: "\(self.serverUrl ?? "")/\(metadata.fileName)", ocId: metadata.ocId, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl)
  291. DispatchQueue.main.async {
  292. if(error != nil) {
  293. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_mark_folder_", comment: ""), description: error?.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: (error! as NSError).code)
  294. } else {
  295. NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, "\(self.serverUrl ?? "")/\(metadata.fileName)"))
  296. self.readFolder(self.serverUrl)
  297. }
  298. }
  299. }
  300. }))
  301. }
  302. if (metadata.e2eEncrypted && !metadataFolder.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.activeAccount)) {
  303. actions.append(MenuAction(title: NSLocalizedString("_e2e_remove_folder_encrypted_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  304. DispatchQueue.global(qos: .userInitiated).async {
  305. let error = NCNetworkingEndToEnd.sharedManager()?.deletemarkEndToEndFolderEncrypted(onServerUrl: "\(self.serverUrl ?? "")/\(metadata.fileName)", ocId: metadata.ocId, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl)
  306. DispatchQueue.main.async {
  307. if(error != nil) {
  308. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_delete_mark_folder_", comment: ""), description: error?.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: (error! as NSError).code)
  309. } else {
  310. NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, "\(self.serverUrl ?? "")/\(metadata.fileName)"))
  311. self.readFolder(self.serverUrl)
  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(MenuAction(title: metadata.fileNameView, icon: iconHeader, action: { menuAction in
  325. }))
  326. actions.append(MenuAction(title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite), action: { menuAction in
  327. self.settingFavorite(metadata, favorite: !metadata.favorite)
  328. }))
  329. if (!metadataFolder.e2eEncrypted) {
  330. actions.append(MenuAction(title: NSLocalizedString("_details_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  331. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  332. }))
  333. }
  334. if(!NCBrandOptions.sharedInstance.disable_openin_file) {
  335. actions.append(MenuAction(title: NSLocalizedString("_open_in_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  336. self.perform(#selector(self.openinFile(_:)))
  337. }))
  338. }
  339. actions.append(MenuAction(title: NSLocalizedString("_rename_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  340. let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
  341. alertController.addTextField { (textField) in
  342. textField.text = metadata.fileNameView
  343. textField.delegate = self as? UITextFieldDelegate
  344. textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
  345. ), for: UIControl.Event.editingChanged)
  346. }
  347. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  348. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  349. let fileName = alertController.textFields![0].text
  350. self.perform(#selector(self.renameFile(_:)), on: .main, with: [metadata, fileName!], waitUntilDone: false)
  351. })
  352. okAction.isEnabled = false
  353. alertController.addAction(cancelAction)
  354. alertController.addAction(okAction)
  355. self.present(alertController, animated: true, completion: nil)
  356. }))
  357. if (!metadataFolder.e2eEncrypted) {
  358. actions.append(MenuAction(title: NSLocalizedString("_move_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  359. self.moveOpenWindow([indexPath])
  360. }))
  361. }
  362. if(NCUtility.sharedInstance.isEditImage(metadata.fileNameView as NSString) != nil && !metadataFolder.e2eEncrypted && metadata.status == k_metadataStatusNormal) {
  363. actions.append(MenuAction(title: NSLocalizedString("_modify_photo_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "modifyPhoto"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  364. metadata.session = k_download_session
  365. metadata.sessionError = ""
  366. metadata.sessionSelector = selectorDownloadEditPhoto
  367. metadata.status = Int(k_metadataStatusWaitDownload)
  368. _ = NCManageDatabase.sharedInstance.addMetadata(metadata)
  369. appDelegate.startLoadAutoDownloadUpload()
  370. }))
  371. }
  372. if (!metadataFolder.e2eEncrypted) {
  373. let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  374. var title: String!
  375. if (localFile == nil || localFile!.offline == false) {
  376. title = NSLocalizedString("_set_available_offline_", comment: "")
  377. } else {
  378. title = NSLocalizedString("_remove_available_offline_", comment: "");
  379. }
  380. actions.append(MenuAction(title: title, icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  381. if (localFile == nil || !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView)) {
  382. metadata.session = k_download_session
  383. metadata.sessionError = ""
  384. metadata.sessionSelector = selectorLoadOffline
  385. metadata.status = Int(k_metadataStatusWaitDownload)
  386. _ = NCManageDatabase.sharedInstance.addMetadata(metadata)
  387. NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: self.serverUrl, ocId: metadata.ocId, action: k_action_MOD)
  388. appDelegate.startLoadAutoDownloadUpload()
  389. } else {
  390. NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: !localFile!.offline)
  391. DispatchQueue.main.async {
  392. self.tableView.reloadRows(at: [indexPath], with: .none)
  393. }
  394. }
  395. }))
  396. }
  397. }
  398. actions.append(MenuAction(title: NSLocalizedString("_delete_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), width: 50, height: 50, color: .red), action: { menuAction in
  399. self.actionDelete(indexPath)
  400. }))
  401. return actions
  402. }
  403. @objc func toggleMoreMenu(viewController: UIViewController, indexPath: IndexPath, metadata: tableMetadata, metadataFolder: tableMetadata) {
  404. let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
  405. mainMenuViewController.actions = self.initMoreMenu(indexPath: indexPath, metadata: metadata, metadataFolder: metadataFolder)
  406. let menuPanelController = MenuPanelController()
  407. menuPanelController.panelWidth = Int(viewController.view.frame.width)
  408. menuPanelController.delegate = mainMenuViewController
  409. menuPanelController.set(contentViewController: mainMenuViewController)
  410. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  411. viewController.present(menuPanelController, animated: true, completion: nil)
  412. }
  413. }
  414. extension CCFavorites {
  415. private func initMoreMenu(indexPath: IndexPath, metadata: tableMetadata) -> [MenuAction] {
  416. var actions = [MenuAction]()
  417. var iconHeader: UIImage!
  418. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) {
  419. iconHeader = icon
  420. } else {
  421. if(metadata.directory){
  422. iconHeader = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  423. } else {
  424. iconHeader = UIImage(named: metadata.iconName)
  425. }
  426. }
  427. actions.append(MenuAction(title: metadata.fileNameView, icon: iconHeader, action: { menuAction in
  428. }))
  429. if(self.serverUrl == nil) {
  430. actions.append(MenuAction(title: NSLocalizedString("_remove_favorites_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite), action: { menuAction in
  431. self.settingFavorite(metadata, favorite: false)
  432. }))
  433. }
  434. actions.append(MenuAction(title: NSLocalizedString("_details_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  435. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  436. }))
  437. if(!metadata.directory && !NCBrandOptions.sharedInstance.disable_openin_file) {
  438. actions.append(MenuAction(title: NSLocalizedString("_open_in_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  439. self.tableView.setEditing(false, animated: true)
  440. NCMainCommon.sharedInstance.downloadOpen(metadata: metadata, selector: selectorOpenIn)
  441. }))
  442. }
  443. actions.append(MenuAction(title: NSLocalizedString("_delete_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  444. self.actionDelete(indexPath)
  445. }))
  446. return actions
  447. }
  448. @objc func toggleMoreMenu(viewController: UIViewController, indexPath: IndexPath, metadata: tableMetadata) {
  449. let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
  450. mainMenuViewController.actions = self.initMoreMenu(indexPath: indexPath, metadata: metadata)
  451. let menuPanelController = MenuPanelController()
  452. menuPanelController.panelWidth = Int(viewController.view.frame.width)
  453. menuPanelController.delegate = mainMenuViewController
  454. menuPanelController.set(contentViewController: mainMenuViewController)
  455. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  456. viewController.present(menuPanelController, animated: true, completion: nil)
  457. }
  458. }