NCCapabilitiesViewController.swift 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. //
  2. // NCCapabilitiesViewController.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 28/07/2020.
  6. // Copyright © 2020 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import UIKit
  24. import NCCommunication
  25. class NCCapabilitiesViewController: UIViewController, UIDocumentInteractionControllerDelegate {
  26. @IBOutlet weak var textView: UITextView!
  27. @IBOutlet weak var imageFileSharing: UIImageView!
  28. @IBOutlet weak var statusFileSharing: UILabel!
  29. @IBOutlet weak var imageExternalSite: UIImageView!
  30. @IBOutlet weak var statusExternalSite: UILabel!
  31. @IBOutlet weak var imageEndToEndEncryption: UIImageView!
  32. @IBOutlet weak var statusEndToEndEncryption: UILabel!
  33. @IBOutlet weak var imageActivity: UIImageView!
  34. @IBOutlet weak var statusActivity: UILabel!
  35. @IBOutlet weak var imageNotification: UIImageView!
  36. @IBOutlet weak var statusNotification: UILabel!
  37. @IBOutlet weak var imageDeletedFiles: UIImageView!
  38. @IBOutlet weak var statusDeletedFiles: UILabel!
  39. @IBOutlet weak var imageUserStatus: UIImageView!
  40. @IBOutlet weak var statusUserStatus: UILabel!
  41. @IBOutlet weak var imageText: UIImageView!
  42. @IBOutlet weak var statusText: UILabel!
  43. @IBOutlet weak var imageCollabora: UIImageView!
  44. @IBOutlet weak var statusCollabora: UILabel!
  45. @IBOutlet weak var imageOnlyOffice: UIImageView!
  46. @IBOutlet weak var statusOnlyOffice: UILabel!
  47. @IBOutlet weak var homeImage: UIImageView!
  48. @IBOutlet weak var homeServer: UILabel!
  49. @IBOutlet weak var davImage: UIImageView!
  50. @IBOutlet weak var davFiles: UILabel!
  51. private let appDelegate = UIApplication.shared.delegate as! AppDelegate
  52. private var documentController: UIDocumentInteractionController?
  53. private var account: String = ""
  54. private var capabilitiesText = ""
  55. //private var timer: Timer?
  56. override func viewDidLoad() {
  57. super.viewDidLoad()
  58. self.title = NSLocalizedString("_capabilities_", comment: "")
  59. let shareImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "shareFill"), width: 50, height: 50, color: .gray)
  60. self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: shareImage, style: UIBarButtonItem.Style.plain, target: self, action: #selector(share))
  61. self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_done_", comment: ""), style: UIBarButtonItem.Style.plain, target: self, action: #selector(close))
  62. textView.layer.cornerRadius = 15
  63. textView.backgroundColor = NCBrandColor.sharedInstance.graySoft
  64. statusFileSharing.layer.cornerRadius = 12.5
  65. statusFileSharing.layer.borderWidth = 0.5
  66. statusFileSharing.layer.borderColor = NCBrandColor.sharedInstance.textView.cgColor
  67. statusFileSharing.layer.backgroundColor = NCBrandColor.sharedInstance.graySoft.withAlphaComponent(0.3).cgColor
  68. statusExternalSite.layer.cornerRadius = 12.5
  69. statusExternalSite.layer.borderWidth = 0.5
  70. statusExternalSite.layer.borderColor = NCBrandColor.sharedInstance.textView.cgColor
  71. statusExternalSite.layer.backgroundColor = NCBrandColor.sharedInstance.graySoft.withAlphaComponent(0.3).cgColor
  72. statusEndToEndEncryption.layer.cornerRadius = 12.5
  73. statusEndToEndEncryption.layer.borderWidth = 0.5
  74. statusEndToEndEncryption.layer.borderColor = NCBrandColor.sharedInstance.textView.cgColor
  75. statusEndToEndEncryption.layer.backgroundColor = NCBrandColor.sharedInstance.graySoft.withAlphaComponent(0.3).cgColor
  76. statusActivity.layer.cornerRadius = 12.5
  77. statusActivity.layer.borderWidth = 0.5
  78. statusActivity.layer.borderColor = NCBrandColor.sharedInstance.textView.cgColor
  79. statusActivity.layer.backgroundColor = NCBrandColor.sharedInstance.graySoft.withAlphaComponent(0.3).cgColor
  80. statusNotification.layer.cornerRadius = 12.5
  81. statusNotification.layer.borderWidth = 0.5
  82. statusNotification.layer.borderColor = NCBrandColor.sharedInstance.textView.cgColor
  83. statusNotification.layer.backgroundColor = NCBrandColor.sharedInstance.graySoft.withAlphaComponent(0.3).cgColor
  84. statusDeletedFiles.layer.cornerRadius = 12.5
  85. statusDeletedFiles.layer.borderWidth = 0.5
  86. statusDeletedFiles.layer.borderColor = NCBrandColor.sharedInstance.textView.cgColor
  87. statusDeletedFiles.layer.backgroundColor = NCBrandColor.sharedInstance.graySoft.withAlphaComponent(0.3).cgColor
  88. statusText.layer.cornerRadius = 12.5
  89. statusText.layer.borderWidth = 0.5
  90. statusText.layer.borderColor = NCBrandColor.sharedInstance.textView.cgColor
  91. statusText.layer.backgroundColor = NCBrandColor.sharedInstance.graySoft.withAlphaComponent(0.3).cgColor
  92. statusCollabora.layer.cornerRadius = 12.5
  93. statusCollabora.layer.borderWidth = 0.5
  94. statusCollabora.layer.borderColor = NCBrandColor.sharedInstance.textView.cgColor
  95. statusCollabora.layer.backgroundColor = NCBrandColor.sharedInstance.graySoft.withAlphaComponent(0.3).cgColor
  96. statusOnlyOffice.layer.cornerRadius = 12.5
  97. statusOnlyOffice.layer.borderWidth = 0.5
  98. statusOnlyOffice.layer.borderColor = NCBrandColor.sharedInstance.textView.cgColor
  99. statusOnlyOffice.layer.backgroundColor = NCBrandColor.sharedInstance.graySoft.withAlphaComponent(0.3).cgColor
  100. statusUserStatus.layer.cornerRadius = 12.5
  101. statusUserStatus.layer.borderWidth = 0.5
  102. statusUserStatus.layer.borderColor = NCBrandColor.sharedInstance.textView.cgColor
  103. statusUserStatus.layer.backgroundColor = NCBrandColor.sharedInstance.graySoft.withAlphaComponent(0.3).cgColor
  104. imageFileSharing.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 100, height: 100, color: .gray)
  105. imageExternalSite.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "externalsites"), width: 100, height: 100, color: .gray)
  106. imageEndToEndEncryption.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "lock"), width: 100, height: 100, color: .gray)
  107. imageActivity.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "activity"), width: 100, height: 100, color: .gray)
  108. imageNotification.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "notification"), width: 100, height: 100, color: .gray)
  109. imageDeletedFiles.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "delete"), width: 100, height: 100, color: .gray)
  110. imageText.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "text"), width: 100, height: 100, color: .gray)
  111. imageCollabora.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "collabora"), width: 100, height: 100, color: .gray)
  112. imageOnlyOffice.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "onlyoffice"), width: 100, height: 100, color: .gray)
  113. imageUserStatus.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "userStatusAway"), width: 100, height: 100, color: .gray)
  114. guard let account = NCManageDatabase.sharedInstance.getAccountActive() else { return }
  115. self.account = account.account
  116. if let text = NCManageDatabase.sharedInstance.getCapabilities(account: account.account) {
  117. capabilitiesText = text
  118. updateCapabilities()
  119. } else {
  120. NCContentPresenter.shared.messageNotification("_error_", description: "_no_capabilities_found_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: Int(k_CCErrorInternalError), forced: true)
  121. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  122. self.dismiss(animated: true, completion: nil)
  123. }
  124. }
  125. homeImage.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "home"), width: 100, height: 100, color: .gray)
  126. homeServer.text = NCUtility.shared.getHomeServer(urlBase: appDelegate.urlBase, account: appDelegate.account) + "/"
  127. davImage.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "dav"), width: 100, height: 100, color: .gray)
  128. davFiles.text = appDelegate.urlBase + "/" + NCUtility.shared.getDAV() + "/files/" + appDelegate.user + "/"
  129. }
  130. @objc func updateCapabilities() {
  131. NCCommunication.shared.getCapabilities() { (account, data, errorCode, errorDescription) in
  132. if errorCode == 0 && data != nil {
  133. NCManageDatabase.sharedInstance.addCapabilitiesJSon(data!, account: account)
  134. // EDITORS
  135. let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerInt(account: account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
  136. if serverVersionMajor >= k_nextcloud_version_18_0 {
  137. NCCommunication.shared.NCTextObtainEditorDetails() { (account, editors, creators, errorCode, errorMessage) in
  138. if errorCode == 0 && account == self.appDelegate.account {
  139. NCManageDatabase.sharedInstance.addDirectEditing(account: account, editors: editors, creators: creators)
  140. self.readCapabilities()
  141. }
  142. if self.view.window != nil {
  143. //self.timer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(self.updateCapabilities), userInfo: nil, repeats: false)
  144. }
  145. }
  146. } else {
  147. if self.view.window != nil {
  148. //self.timer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(self.updateCapabilities), userInfo: nil, repeats: false)
  149. }
  150. }
  151. if let text = NCManageDatabase.sharedInstance.getCapabilities(account: account) {
  152. self.capabilitiesText = text
  153. }
  154. self.readCapabilities()
  155. }
  156. }
  157. readCapabilities()
  158. }
  159. @objc func share() {
  160. //timer?.invalidate()
  161. self.dismiss(animated: true) {
  162. let fileURL = NSURL.fileURL(withPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent("capabilities.txt")
  163. do {
  164. try self.capabilitiesText.write(to: fileURL, atomically: true, encoding: .utf8)
  165. if let view = self.appDelegate.window?.rootViewController?.view {
  166. self.documentController = UIDocumentInteractionController(url: fileURL)
  167. self.documentController?.delegate = self
  168. self.documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
  169. }
  170. } catch { }
  171. }
  172. }
  173. @objc func close() {
  174. //timer?.invalidate()
  175. self.dismiss(animated: true, completion: nil)
  176. }
  177. func readCapabilities() {
  178. textView.text = capabilitiesText
  179. if NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false) {
  180. statusFileSharing.text = "✓ " + NSLocalizedString("_available_", comment: "")
  181. } else {
  182. statusFileSharing.text = NSLocalizedString("_not_available_", comment: "")
  183. }
  184. if NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesExternalSitesExists, exists: true) {
  185. statusExternalSite.text = "✓ " + NSLocalizedString("_available_", comment: "")
  186. } else {
  187. statusExternalSite.text = NSLocalizedString("_not_available_", comment: "")
  188. }
  189. let isE2EEEnabled = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesE2EEEnabled, exists: false)
  190. //let versionE2EE = NCManageDatabase.sharedInstance.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesE2EEApiVersion)
  191. if isE2EEEnabled {
  192. statusEndToEndEncryption.text = "✓ " + NSLocalizedString("_available_", comment: "")
  193. } else {
  194. statusEndToEndEncryption.text = NSLocalizedString("_not_available_", comment: "")
  195. }
  196. let activity = NCManageDatabase.sharedInstance.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesActivity)
  197. if activity != nil {
  198. statusActivity.text = "✓ " + NSLocalizedString("_available_", comment: "")
  199. } else {
  200. statusActivity.text = NSLocalizedString("_not_available_", comment: "")
  201. }
  202. let notification = NCManageDatabase.sharedInstance.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesNotification)
  203. if notification != nil {
  204. statusNotification.text = "✓ " + NSLocalizedString("_available_", comment: "")
  205. } else {
  206. statusNotification.text = NSLocalizedString("_not_available_", comment: "")
  207. }
  208. let deleteFiles = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFilesUndelete, exists: false)
  209. if deleteFiles {
  210. statusDeletedFiles.text = "✓ " + NSLocalizedString("_available_", comment: "")
  211. } else {
  212. statusDeletedFiles.text = NSLocalizedString("_not_available_", comment: "")
  213. }
  214. var textEditor = false
  215. var onlyofficeEditors = false
  216. if let editors = NCManageDatabase.sharedInstance.getDirectEditingEditors(account: account) {
  217. for editor in editors {
  218. if editor.editor == k_editor_text {
  219. textEditor = true
  220. } else if editor.editor == k_editor_onlyoffice {
  221. onlyofficeEditors = true
  222. }
  223. }
  224. }
  225. if textEditor {
  226. statusText.text = "✓ " + NSLocalizedString("_available_", comment: "")
  227. } else {
  228. statusText.text = NSLocalizedString("_not_available_", comment: "")
  229. }
  230. let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes)
  231. if richdocumentsMimetypes != nil {
  232. statusCollabora.text = "✓ " + NSLocalizedString("_available_", comment: "")
  233. } else {
  234. statusCollabora.text = NSLocalizedString("_not_available_", comment: "")
  235. }
  236. if onlyofficeEditors {
  237. statusOnlyOffice.text = "✓ " + NSLocalizedString("_available_", comment: "")
  238. } else {
  239. statusOnlyOffice.text = NSLocalizedString("_not_available_", comment: "")
  240. }
  241. let userStatus = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesUserStatusEnabled, exists: false)
  242. if userStatus {
  243. statusUserStatus.text = "✓ " + NSLocalizedString("_available_", comment: "")
  244. } else {
  245. statusUserStatus.text = NSLocalizedString("_not_available_", comment: "")
  246. }
  247. print("end.")
  248. }
  249. }