NCCapabilitiesViewController.swift 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. class NCCapabilitiesViewController: UIViewController {
  25. @IBOutlet weak var textView: UITextView!
  26. @IBOutlet weak var imageFileSharing: UIImageView!
  27. @IBOutlet weak var imageStatusFileSharing: UIImageView!
  28. @IBOutlet weak var imageDirectEditing: UIImageView!
  29. @IBOutlet weak var imageStatusDirectEditing: UIImageView!
  30. @IBOutlet weak var imageExternalSite: UIImageView!
  31. @IBOutlet weak var imageStatusExternalSite: UIImageView!
  32. @IBOutlet weak var imageEndToEndEncryption: UIImageView!
  33. @IBOutlet weak var imageStatusEndToEndEncryption: UIImageView!
  34. @IBOutlet weak var imagePaginatedFileListing: UIImageView!
  35. @IBOutlet weak var imageStatusPaginatedFileListing: UIImageView!
  36. private var account: String = ""
  37. private var imageEnable: UIImage?
  38. private var imageDisable: UIImage?
  39. override func viewDidLoad() {
  40. super.viewDidLoad()
  41. self.title = NSLocalizedString("_capabilities_", comment: "")
  42. let closeButton : UIBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_done_", comment: ""), style: UIBarButtonItem.Style.plain, target: self, action: #selector(close))
  43. self.navigationItem.leftBarButtonItem = closeButton
  44. imageEnable = CCGraphics.changeThemingColorImage(UIImage.init(named: "circle"), width: 50, height: 50, color: .green)
  45. imageDisable = CCGraphics.changeThemingColorImage(UIImage.init(named: "circle"), width: 50, height: 50, color: .red)
  46. imageFileSharing.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 100, height: 100, color: .gray)
  47. imageDirectEditing.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "document"), width: 100, height: 100, color: .gray)
  48. imageExternalSite.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "country"), width: 100, height: 100, color: .gray)
  49. imageEndToEndEncryption.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "lock"), width: 100, height: 100, color: .gray)
  50. imagePaginatedFileListing.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "application"), width: 100, height: 100, color: .gray)
  51. guard let account = NCManageDatabase.sharedInstance.getAccountActive() else { return }
  52. self.account = account.account
  53. if let jsonText = NCManageDatabase.sharedInstance.getCapabilities(account: account.account) {
  54. textView.text = jsonText
  55. readCapabilities()
  56. } else {
  57. NCContentPresenter.shared.messageNotification("_error_", description: "_no_capabilities_found_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: Int(k_CCErrorInternalError), forced: true)
  58. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  59. self.dismiss(animated: true, completion: nil)
  60. }
  61. }
  62. }
  63. @objc func close() {
  64. self.dismiss(animated: true, completion: nil)
  65. }
  66. func readCapabilities() {
  67. if NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false) {
  68. imageStatusFileSharing.image = imageEnable
  69. } else {
  70. imageStatusFileSharing.image = imageDisable
  71. }
  72. if NCManageDatabase.sharedInstance.getDirectEditingCreators(account: account) != nil {
  73. imageStatusDirectEditing.image = imageEnable
  74. } else {
  75. imageStatusDirectEditing.image = imageDisable
  76. }
  77. if NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesExternalSitesExists, exists: false) {
  78. imageStatusExternalSite.image = imageEnable
  79. } else {
  80. imageStatusExternalSite.image = imageDisable
  81. }
  82. let isE2EEEnabled = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesE2EEEnabled, exists: false)
  83. let versionE2EE = NCManageDatabase.sharedInstance.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesE2EEApiVersion)
  84. if isE2EEEnabled && versionE2EE == k_E2EE_API {
  85. imageStatusEndToEndEncryption.image = imageEnable
  86. } else {
  87. imageStatusEndToEndEncryption.image = imageDisable
  88. }
  89. let paginationEndpoint = NCManageDatabase.sharedInstance.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesPaginationEndpoint)
  90. if paginationEndpoint != nil {
  91. imageStatusPaginatedFileListing.image = imageEnable
  92. } else {
  93. imageStatusPaginatedFileListing.image = imageDisable
  94. }
  95. }
  96. }