NCCapabilitiesModel.swift 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // NCCapabilitiesModel.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 02/06/24.
  6. // Copyright © 2024 Marino Faggiana. All rights reserved.
  7. //
  8. import Foundation
  9. import UIKit
  10. import SwiftUI
  11. class NCCapabilitiesModel: ObservableObject, ViewOnAppearHandling {
  12. struct Capability: Identifiable, Hashable {
  13. let id = UUID()
  14. let text: String
  15. let image: UIImage
  16. let resize: Bool
  17. let available: Bool
  18. }
  19. @Published var capabililies: [Capability] = []
  20. @Published var homeServer = ""
  21. /// Root View Controller
  22. @Published var controller: NCMainTabBarController?
  23. /// Get session
  24. var session: NCSession.Session {
  25. NCSession.shared.getSession(controller: controller)
  26. }
  27. let utilityFileSystem = NCUtilityFileSystem()
  28. let utility = NCUtility()
  29. init(controller: NCMainTabBarController?) {
  30. self.controller = controller
  31. onViewAppear()
  32. }
  33. /// Triggered when the view appears.
  34. func onViewAppear() {
  35. var textEditor = false
  36. var onlyofficeEditors = false
  37. let capability = NCCapabilities.shared.getCapabilities(account: session.account)
  38. capabililies.removeAll()
  39. var image = utility.loadImage(named: "person.fill.badge.plus")
  40. capabililies.append(Capability(text: "File sharing", image: image, resize: false, available: capability.capabilityFileSharingApiEnabled))
  41. image = utility.loadImage(named: "network")
  42. capabililies.append(Capability(text: "External site", image: image, resize: false, available: capability.capabilityExternalSites))
  43. image = utility.loadImage(named: "lock")
  44. capabililies.append(Capability(text: "End-to-End Encryption", image: image, resize: false, available: capability.capabilityE2EEEnabled))
  45. image = utility.loadImage(named: "bolt")
  46. capabililies.append(Capability(text: "Activity", image: image, resize: false, available: !capability.capabilityActivity.isEmpty))
  47. image = utility.loadImage(named: "bell")
  48. capabililies.append(Capability(text: "Notification", image: image, resize: false, available: !capability.capabilityNotification.isEmpty))
  49. image = utility.loadImage(named: "trash")
  50. capabililies.append(Capability(text: "Deleted files", image: image, resize: false, available: capability.capabilityFilesUndelete))
  51. if let editors = NCManageDatabase.shared.getDirectEditingEditors(account: session.account) {
  52. for editor in editors {
  53. if editor.editor == NCGlobal.shared.editorText {
  54. textEditor = true
  55. } else if editor.editor == NCGlobal.shared.editorOnlyoffice {
  56. onlyofficeEditors = true
  57. }
  58. }
  59. }
  60. capabililies.append(Capability(text: "Text", image: utility.loadImage(named: "doc.text"), resize: false, available: textEditor))
  61. capabililies.append(Capability(text: "ONLYOFFICE", image: utility.loadImage(named: "onlyoffice"), resize: true, available: onlyofficeEditors))
  62. capabililies.append(Capability(text: "Collabora", image: utility.loadImage(named: "collabora"), resize: true, available: capability.capabilityRichDocumentsEnabled))
  63. capabililies.append(Capability(text: "User Status", image: utility.loadImage(named: "moon"), resize: false, available: capability.capabilityUserStatusEnabled))
  64. capabililies.append(Capability(text: "Comments", image: utility.loadImage(named: "ellipsis.bubble"), resize: false, available: capability.capabilityFilesComments))
  65. capabililies.append(Capability(text: "Lock file", image: utility.loadImage(named: "lock"), resize: false, available: !capability.capabilityFilesLockVersion.isEmpty))
  66. capabililies.append(Capability(text: "Group folders", image: utility.loadImage(named: "person.2"), resize: false, available: capability.capabilityGroupfoldersEnabled))
  67. if NCBrandOptions.shared.brand != "Nextcloud" {
  68. capabililies.append(Capability(text: "Security Guard Diagnostics", image: utility.loadImage(named: "shield"), resize: false, available: capability.capabilitySecurityGuardDiagnostics))
  69. }
  70. capabililies.append(Capability(text: "Assistant", image: utility.loadImage(named: "sparkles"), resize: false, available: capability.capabilityAssistantEnabled))
  71. homeServer = utilityFileSystem.getHomeServer(session: session) + "/"
  72. }
  73. }