NCCapabilitiesViewController.swift 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 imageStatusFileSharing: UIImageView!
  29. @IBOutlet weak var imageExternalSite: UIImageView!
  30. @IBOutlet weak var imageStatusExternalSite: UIImageView!
  31. @IBOutlet weak var imageEndToEndEncryption: UIImageView!
  32. @IBOutlet weak var imageStatusEndToEndEncryption: UIImageView!
  33. @IBOutlet weak var imagePaginatedFileListing: UIImageView!
  34. @IBOutlet weak var imageStatusPaginatedFileListing: UIImageView!
  35. @IBOutlet weak var imageActivity: UIImageView!
  36. @IBOutlet weak var imageStatusActivity: UIImageView!
  37. @IBOutlet weak var imageNotification: UIImageView!
  38. @IBOutlet weak var imageStatusNotification: UIImageView!
  39. @IBOutlet weak var imageText: UIImageView!
  40. @IBOutlet weak var imageStatusText: UIImageView!
  41. @IBOutlet weak var imageCollabora: UIImageView!
  42. @IBOutlet weak var imageStatusCollabora: UIImageView!
  43. @IBOutlet weak var imageOnlyOffice: UIImageView!
  44. @IBOutlet weak var imageStatusOnlyOffice: UIImageView!
  45. private var documentController: UIDocumentInteractionController?
  46. private var account: String = ""
  47. private var capabilitiesText = ""
  48. private var imageEnable: UIImage?
  49. private var imageDisable: UIImage?
  50. override func viewDidLoad() {
  51. super.viewDidLoad()
  52. self.title = NSLocalizedString("_capabilities_", comment: "")
  53. let shareImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "shareFill"), width: 50, height: 50, color: .gray)
  54. self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: shareImage, style: UIBarButtonItem.Style.plain, target: self, action: #selector(share))
  55. self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_done_", comment: ""), style: UIBarButtonItem.Style.plain, target: self, action: #selector(close))
  56. imageEnable = CCGraphics.changeThemingColorImage(UIImage.init(named: "circle"), width: 50, height: 50, color: .green)
  57. imageDisable = CCGraphics.changeThemingColorImage(UIImage.init(named: "circle"), width: 50, height: 50, color: .red)
  58. imageFileSharing.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 100, height: 100, color: .gray)
  59. imageExternalSite.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "externalsites"), width: 100, height: 100, color: .gray)
  60. imageEndToEndEncryption.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "lock"), width: 100, height: 100, color: .gray)
  61. imagePaginatedFileListing.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "application"), width: 100, height: 100, color: .gray)
  62. imageActivity.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "activity"), width: 100, height: 100, color: .gray)
  63. imageNotification.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "notification"), width: 100, height: 100, color: .gray)
  64. imageText.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "text"), width: 100, height: 100, color: .gray)
  65. imageCollabora.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "collabora"), width: 100, height: 100, color: .gray)
  66. imageOnlyOffice.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "onlyoffice"), width: 100, height: 100, color: .gray)
  67. guard let account = NCManageDatabase.sharedInstance.getAccountActive() else { return }
  68. self.account = account.account
  69. if let text = NCManageDatabase.sharedInstance.getCapabilities(account: account.account) {
  70. capabilitiesText = text
  71. readCapabilities()
  72. } else {
  73. NCContentPresenter.shared.messageNotification("_error_", description: "_no_capabilities_found_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: Int(k_CCErrorInternalError), forced: true)
  74. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  75. self.dismiss(animated: true, completion: nil)
  76. }
  77. }
  78. }
  79. override func viewWillAppear(_ animated: Bool) {
  80. super.viewWillAppear(animated)
  81. NCCommunication.shared.getCapabilities() { (account, data, errorCode, errorDescription) in
  82. if errorCode == 0 && data != nil {
  83. NCManageDatabase.sharedInstance.addCapabilitiesJSon(data!, account: account)
  84. if let text = NCManageDatabase.sharedInstance.getCapabilities(account: account) {
  85. self.capabilitiesText = text
  86. }
  87. self.readCapabilities()
  88. }
  89. }
  90. }
  91. @objc func share() {
  92. let tempDirectoryURL = NSURL.fileURL(withPath: NSTemporaryDirectory(), isDirectory: true)
  93. let fileURL = tempDirectoryURL.appendingPathComponent("capabilities.txt")
  94. if NCUtilityFileSystem.shared.writeFile(fileURL: fileURL, text: capabilitiesText) {
  95. documentController = UIDocumentInteractionController.init(url: fileURL)
  96. if documentController != nil {
  97. documentController!.delegate = self
  98. documentController!.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)
  99. }
  100. }
  101. }
  102. @objc func close() {
  103. self.dismiss(animated: true, completion: nil)
  104. }
  105. func readCapabilities() {
  106. textView.text = capabilitiesText
  107. if NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false) {
  108. imageStatusFileSharing.image = imageEnable
  109. } else {
  110. imageStatusFileSharing.image = imageDisable
  111. }
  112. if NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesExternalSitesExists, exists: false) {
  113. imageStatusExternalSite.image = imageEnable
  114. } else {
  115. imageStatusExternalSite.image = imageDisable
  116. }
  117. let isE2EEEnabled = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesE2EEEnabled, exists: false)
  118. let versionE2EE = NCManageDatabase.sharedInstance.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesE2EEApiVersion)
  119. if isE2EEEnabled && versionE2EE == k_E2EE_API {
  120. imageStatusEndToEndEncryption.image = imageEnable
  121. } else {
  122. imageStatusEndToEndEncryption.image = imageDisable
  123. }
  124. let paginationEndpoint = NCManageDatabase.sharedInstance.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesPaginationEndpoint)
  125. if paginationEndpoint != nil {
  126. imageStatusPaginatedFileListing.image = imageEnable
  127. } else {
  128. imageStatusPaginatedFileListing.image = imageDisable
  129. }
  130. let activity = NCManageDatabase.sharedInstance.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesActivity)
  131. if activity != nil {
  132. imageStatusActivity.image = imageEnable
  133. } else {
  134. imageStatusActivity.image = imageDisable
  135. }
  136. let notification = NCManageDatabase.sharedInstance.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesNotification)
  137. if notification != nil {
  138. imageStatusNotification.image = imageEnable
  139. } else {
  140. imageStatusNotification.image = imageDisable
  141. }
  142. var textEditor = false
  143. var onlyofficeEditors = false
  144. if let editors = NCManageDatabase.sharedInstance.getDirectEditingEditors(account: account) {
  145. for editor in editors {
  146. if editor.editor == k_editor_text {
  147. textEditor = true
  148. } else if editor.editor == k_editor_onlyoffice {
  149. onlyofficeEditors = true
  150. }
  151. }
  152. }
  153. if textEditor {
  154. imageStatusText.image = imageEnable
  155. } else {
  156. imageStatusText.image = imageDisable
  157. }
  158. let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes)
  159. if richdocumentsMimetypes != nil {
  160. imageStatusCollabora.image = imageEnable
  161. } else {
  162. imageStatusCollabora.image = imageDisable
  163. }
  164. if onlyofficeEditors {
  165. imageStatusOnlyOffice.image = imageEnable
  166. } else {
  167. imageStatusOnlyOffice.image = imageDisable
  168. }
  169. print("end.")
  170. }
  171. }