NCCapabilitiesViewController.swift 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 imageComments: UIImageView!
  42. @IBOutlet weak var statusComments: UILabel!
  43. @IBOutlet weak var imageText: UIImageView!
  44. @IBOutlet weak var statusText: UILabel!
  45. @IBOutlet weak var imageCollabora: UIImageView!
  46. @IBOutlet weak var statusCollabora: UILabel!
  47. @IBOutlet weak var imageOnlyOffice: UIImageView!
  48. @IBOutlet weak var statusOnlyOffice: UILabel!
  49. @IBOutlet weak var homeImage: UIImageView!
  50. @IBOutlet weak var homeServer: UILabel!
  51. @IBOutlet weak var davImage: UIImageView!
  52. @IBOutlet weak var davFiles: UILabel!
  53. private let appDelegate = UIApplication.shared.delegate as! AppDelegate
  54. private var documentController: UIDocumentInteractionController?
  55. private var account: String = ""
  56. private var capabilitiesText = ""
  57. //private var timer: Timer?
  58. override func viewDidLoad() {
  59. super.viewDidLoad()
  60. self.title = NSLocalizedString("_capabilities_", comment: "")
  61. let shareImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "shareFill"), width: 50, height: 50, color: .gray)
  62. self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: shareImage, style: UIBarButtonItem.Style.plain, target: self, action: #selector(share))
  63. self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_done_", comment: ""), style: UIBarButtonItem.Style.plain, target: self, action: #selector(close))
  64. textView.layer.cornerRadius = 15
  65. textView.backgroundColor = NCBrandColor.shared.graySoft
  66. statusFileSharing.layer.cornerRadius = 12.5
  67. statusFileSharing.layer.borderWidth = 0.5
  68. statusFileSharing.layer.borderColor = NCBrandColor.shared.textView.cgColor
  69. statusFileSharing.layer.backgroundColor = NCBrandColor.shared.graySoft.withAlphaComponent(0.3).cgColor
  70. statusExternalSite.layer.cornerRadius = 12.5
  71. statusExternalSite.layer.borderWidth = 0.5
  72. statusExternalSite.layer.borderColor = NCBrandColor.shared.textView.cgColor
  73. statusExternalSite.layer.backgroundColor = NCBrandColor.shared.graySoft.withAlphaComponent(0.3).cgColor
  74. statusEndToEndEncryption.layer.cornerRadius = 12.5
  75. statusEndToEndEncryption.layer.borderWidth = 0.5
  76. statusEndToEndEncryption.layer.borderColor = NCBrandColor.shared.textView.cgColor
  77. statusEndToEndEncryption.layer.backgroundColor = NCBrandColor.shared.graySoft.withAlphaComponent(0.3).cgColor
  78. statusActivity.layer.cornerRadius = 12.5
  79. statusActivity.layer.borderWidth = 0.5
  80. statusActivity.layer.borderColor = NCBrandColor.shared.textView.cgColor
  81. statusActivity.layer.backgroundColor = NCBrandColor.shared.graySoft.withAlphaComponent(0.3).cgColor
  82. statusNotification.layer.cornerRadius = 12.5
  83. statusNotification.layer.borderWidth = 0.5
  84. statusNotification.layer.borderColor = NCBrandColor.shared.textView.cgColor
  85. statusNotification.layer.backgroundColor = NCBrandColor.shared.graySoft.withAlphaComponent(0.3).cgColor
  86. statusDeletedFiles.layer.cornerRadius = 12.5
  87. statusDeletedFiles.layer.borderWidth = 0.5
  88. statusDeletedFiles.layer.borderColor = NCBrandColor.shared.textView.cgColor
  89. statusDeletedFiles.layer.backgroundColor = NCBrandColor.shared.graySoft.withAlphaComponent(0.3).cgColor
  90. statusText.layer.cornerRadius = 12.5
  91. statusText.layer.borderWidth = 0.5
  92. statusText.layer.borderColor = NCBrandColor.shared.textView.cgColor
  93. statusText.layer.backgroundColor = NCBrandColor.shared.graySoft.withAlphaComponent(0.3).cgColor
  94. statusCollabora.layer.cornerRadius = 12.5
  95. statusCollabora.layer.borderWidth = 0.5
  96. statusCollabora.layer.borderColor = NCBrandColor.shared.textView.cgColor
  97. statusCollabora.layer.backgroundColor = NCBrandColor.shared.graySoft.withAlphaComponent(0.3).cgColor
  98. statusOnlyOffice.layer.cornerRadius = 12.5
  99. statusOnlyOffice.layer.borderWidth = 0.5
  100. statusOnlyOffice.layer.borderColor = NCBrandColor.shared.textView.cgColor
  101. statusOnlyOffice.layer.backgroundColor = NCBrandColor.shared.graySoft.withAlphaComponent(0.3).cgColor
  102. statusUserStatus.layer.cornerRadius = 12.5
  103. statusUserStatus.layer.borderWidth = 0.5
  104. statusUserStatus.layer.borderColor = NCBrandColor.shared.textView.cgColor
  105. statusUserStatus.layer.backgroundColor = NCBrandColor.shared.graySoft.withAlphaComponent(0.3).cgColor
  106. statusComments.layer.cornerRadius = 12.5
  107. statusComments.layer.borderWidth = 0.5
  108. statusComments.layer.borderColor = NCBrandColor.shared.textView.cgColor
  109. statusComments.layer.backgroundColor = NCBrandColor.shared.graySoft.withAlphaComponent(0.3).cgColor
  110. imageFileSharing.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 100, height: 100, color: .gray)
  111. imageExternalSite.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "externalsites"), width: 100, height: 100, color: .gray)
  112. imageEndToEndEncryption.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "lock"), width: 100, height: 100, color: .gray)
  113. imageActivity.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "activity"), width: 100, height: 100, color: .gray)
  114. imageNotification.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "notification"), width: 100, height: 100, color: .gray)
  115. imageDeletedFiles.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "delete"), width: 100, height: 100, color: .gray)
  116. imageText.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "text"), width: 100, height: 100, color: .gray)
  117. imageCollabora.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "collabora"), width: 100, height: 100, color: .gray)
  118. imageOnlyOffice.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "onlyoffice"), width: 100, height: 100, color: .gray)
  119. imageUserStatus.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "userStatusAway"), width: 100, height: 100, color: .gray)
  120. imageComments.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "comments"), width: 100, height: 100, color: .gray)
  121. guard let account = NCManageDatabase.shared.getAccountActive() else { return }
  122. self.account = account.account
  123. if let text = NCManageDatabase.shared.getCapabilities(account: account.account) {
  124. capabilitiesText = text
  125. updateCapabilities()
  126. } else {
  127. NCContentPresenter.shared.messageNotification("_error_", description: "_no_capabilities_found_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: Int(k_CCErrorInternalError), forced: true)
  128. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  129. self.dismiss(animated: true, completion: nil)
  130. }
  131. }
  132. homeImage.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "home"), width: 100, height: 100, color: .gray)
  133. homeServer.text = NCUtility.shared.getHomeServer(urlBase: appDelegate.urlBase, account: appDelegate.account) + "/"
  134. davImage.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "dav"), width: 100, height: 100, color: .gray)
  135. davFiles.text = appDelegate.urlBase + "/" + NCUtility.shared.getDAV() + "/files/" + appDelegate.user + "/"
  136. }
  137. @objc func updateCapabilities() {
  138. NCCommunication.shared.getCapabilities() { (account, data, errorCode, errorDescription) in
  139. if errorCode == 0 && data != nil {
  140. NCManageDatabase.shared.addCapabilitiesJSon(data!, account: account)
  141. // EDITORS
  142. let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
  143. if serverVersionMajor >= k_nextcloud_version_18_0 {
  144. NCCommunication.shared.NCTextObtainEditorDetails() { (account, editors, creators, errorCode, errorMessage) in
  145. if errorCode == 0 && account == self.appDelegate.account {
  146. NCManageDatabase.shared.addDirectEditing(account: account, editors: editors, creators: creators)
  147. self.readCapabilities()
  148. }
  149. if self.view.window != nil {
  150. //self.timer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(self.updateCapabilities), userInfo: nil, repeats: false)
  151. }
  152. }
  153. } else {
  154. if self.view.window != nil {
  155. //self.timer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(self.updateCapabilities), userInfo: nil, repeats: false)
  156. }
  157. }
  158. if let text = NCManageDatabase.shared.getCapabilities(account: account) {
  159. self.capabilitiesText = text
  160. }
  161. self.readCapabilities()
  162. }
  163. }
  164. readCapabilities()
  165. }
  166. @objc func share() {
  167. //timer?.invalidate()
  168. self.dismiss(animated: true) {
  169. let fileURL = NSURL.fileURL(withPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent("capabilities.txt")
  170. do {
  171. try self.capabilitiesText.write(to: fileURL, atomically: true, encoding: .utf8)
  172. if let view = self.appDelegate.window?.rootViewController?.view {
  173. self.documentController = UIDocumentInteractionController(url: fileURL)
  174. self.documentController?.delegate = self
  175. self.documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
  176. }
  177. } catch { }
  178. }
  179. }
  180. @objc func close() {
  181. //timer?.invalidate()
  182. self.dismiss(animated: true, completion: nil)
  183. }
  184. func readCapabilities() {
  185. textView.text = capabilitiesText
  186. if NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false) {
  187. statusFileSharing.text = "✓ " + NSLocalizedString("_available_", comment: "")
  188. } else {
  189. statusFileSharing.text = NSLocalizedString("_not_available_", comment: "")
  190. }
  191. if NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesExternalSitesExists, exists: true) {
  192. statusExternalSite.text = "✓ " + NSLocalizedString("_available_", comment: "")
  193. } else {
  194. statusExternalSite.text = NSLocalizedString("_not_available_", comment: "")
  195. }
  196. let isE2EEEnabled = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesE2EEEnabled, exists: false)
  197. //let versionE2EE = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesE2EEApiVersion)
  198. if isE2EEEnabled {
  199. statusEndToEndEncryption.text = "✓ " + NSLocalizedString("_available_", comment: "")
  200. } else {
  201. statusEndToEndEncryption.text = NSLocalizedString("_not_available_", comment: "")
  202. }
  203. let activity = NCManageDatabase.shared.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesActivity)
  204. if activity != nil {
  205. statusActivity.text = "✓ " + NSLocalizedString("_available_", comment: "")
  206. } else {
  207. statusActivity.text = NSLocalizedString("_not_available_", comment: "")
  208. }
  209. let notification = NCManageDatabase.shared.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesNotification)
  210. if notification != nil {
  211. statusNotification.text = "✓ " + NSLocalizedString("_available_", comment: "")
  212. } else {
  213. statusNotification.text = NSLocalizedString("_not_available_", comment: "")
  214. }
  215. let deleteFiles = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFilesUndelete, exists: false)
  216. if deleteFiles {
  217. statusDeletedFiles.text = "✓ " + NSLocalizedString("_available_", comment: "")
  218. } else {
  219. statusDeletedFiles.text = NSLocalizedString("_not_available_", comment: "")
  220. }
  221. var textEditor = false
  222. var onlyofficeEditors = false
  223. if let editors = NCManageDatabase.shared.getDirectEditingEditors(account: account) {
  224. for editor in editors {
  225. if editor.editor == k_editor_text {
  226. textEditor = true
  227. } else if editor.editor == k_editor_onlyoffice {
  228. onlyofficeEditors = true
  229. }
  230. }
  231. }
  232. if textEditor {
  233. statusText.text = "✓ " + NSLocalizedString("_available_", comment: "")
  234. } else {
  235. statusText.text = NSLocalizedString("_not_available_", comment: "")
  236. }
  237. let richdocumentsMimetypes = NCManageDatabase.shared.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes)
  238. if richdocumentsMimetypes != nil {
  239. statusCollabora.text = "✓ " + NSLocalizedString("_available_", comment: "")
  240. } else {
  241. statusCollabora.text = NSLocalizedString("_not_available_", comment: "")
  242. }
  243. if onlyofficeEditors {
  244. statusOnlyOffice.text = "✓ " + NSLocalizedString("_available_", comment: "")
  245. } else {
  246. statusOnlyOffice.text = NSLocalizedString("_not_available_", comment: "")
  247. }
  248. let userStatus = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesUserStatusEnabled, exists: false)
  249. if userStatus {
  250. statusUserStatus.text = "✓ " + NSLocalizedString("_available_", comment: "")
  251. } else {
  252. statusUserStatus.text = NSLocalizedString("_not_available_", comment: "")
  253. }
  254. let comments = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFilesComments, exists: false)
  255. if comments {
  256. statusComments.text = "✓ " + NSLocalizedString("_available_", comment: "")
  257. } else {
  258. statusComments.text = NSLocalizedString("_not_available_", comment: "")
  259. }
  260. print("end.")
  261. }
  262. }