1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
//
// NCCapabilitiesViewController.swift
// Nextcloud
//
// Created by Marino Faggiana on 28/07/2020.
// Copyright © 2020 Marino Faggiana. All rights reserved.
//
// Author Marino Faggiana <marino.faggiana@nextcloud.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
import UIKit
import NextcloudKit
class NCCapabilitiesViewController: UIViewController, UIDocumentInteractionControllerDelegate {
@IBOutlet weak var textView: UITextView!
@IBOutlet weak var imageFileSharing: UIImageView!
@IBOutlet weak var statusFileSharing: UILabel!
@IBOutlet weak var imageExternalSite: UIImageView!
@IBOutlet weak var statusExternalSite: UILabel!
@IBOutlet weak var imageEndToEndEncryption: UIImageView!
@IBOutlet weak var statusEndToEndEncryption: UILabel!
@IBOutlet weak var imageActivity: UIImageView!
@IBOutlet weak var statusActivity: UILabel!
@IBOutlet weak var imageNotification: UIImageView!
@IBOutlet weak var statusNotification: UILabel!
@IBOutlet weak var imageDeletedFiles: UIImageView!
@IBOutlet weak var statusDeletedFiles: UILabel!
@IBOutlet weak var imageUserStatus: UIImageView!
@IBOutlet weak var statusUserStatus: UILabel!
@IBOutlet weak var imageComments: UIImageView!
@IBOutlet weak var statusComments: UILabel!
@IBOutlet weak var imageText: UIImageView!
@IBOutlet weak var statusText: UILabel!
@IBOutlet weak var imageCollabora: UIImageView!
@IBOutlet weak var statusCollabora: UILabel!
@IBOutlet weak var imageOnlyOffice: UIImageView!
@IBOutlet weak var statusOnlyOffice: UILabel!
@IBOutlet weak var homeImage: UIImageView!
@IBOutlet weak var homeServer: UILabel!
@IBOutlet weak var imageLockFile: UIImageView!
@IBOutlet weak var statusLockFile: UILabel!
private let appDelegate = UIApplication.shared.delegate as! AppDelegate
private var documentController: UIDocumentInteractionController?
private var account: String = ""
private var capabilitiesText = ""
// private var timer: Timer?
// MARK: - View Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
self.title = NSLocalizedString("_capabilities_", comment: "")
let shareImage = UIImage(named: "shareFill")!.image(color: .gray, size: 25)
self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: shareImage, style: UIBarButtonItem.Style.plain, target: self, action: #selector(share))
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_done_", comment: ""), style: UIBarButtonItem.Style.plain, target: self, action: #selector(close))
textView.layer.cornerRadius = 15
textView.layer.masksToBounds = true
textView.backgroundColor = .secondarySystemBackground
statusFileSharing.layer.cornerRadius = 12.5
statusFileSharing.layer.borderWidth = 0.5
statusFileSharing.layer.borderColor = UIColor.systemGray.cgColor
statusFileSharing.layer.masksToBounds = true
statusFileSharing.backgroundColor = .secondarySystemBackground
statusExternalSite.layer.cornerRadius = 12.5
statusExternalSite.layer.borderWidth = 0.5
statusExternalSite.layer.borderColor = UIColor.systemGray.cgColor
statusExternalSite.layer.masksToBounds = true
statusExternalSite.backgroundColor = .secondarySystemBackground
statusEndToEndEncryption.layer.cornerRadius = 12.5
statusEndToEndEncryption.layer.borderWidth = 0.5
statusEndToEndEncryption.layer.borderColor = UIColor.systemGray.cgColor
statusEndToEndEncryption.layer.masksToBounds = true
statusEndToEndEncryption.backgroundColor = .secondarySystemBackground
statusActivity.layer.cornerRadius = 12.5
statusActivity.layer.borderWidth = 0.5
statusActivity.layer.borderColor = UIColor.systemGray.cgColor
statusActivity.layer.masksToBounds = true
statusActivity.backgroundColor = .secondarySystemBackground
statusNotification.layer.cornerRadius = 12.5
statusNotification.layer.borderWidth = 0.5
statusNotification.layer.borderColor = UIColor.systemGray.cgColor
statusNotification.layer.masksToBounds = true
statusNotification.backgroundColor = .secondarySystemBackground
statusDeletedFiles.layer.cornerRadius = 12.5
statusDeletedFiles.layer.borderWidth = 0.5
statusDeletedFiles.layer.borderColor = UIColor.systemGray.cgColor
statusDeletedFiles.layer.masksToBounds = true
statusDeletedFiles.backgroundColor = .secondarySystemBackground
statusText.layer.cornerRadius = 12.5
statusText.layer.borderWidth = 0.5
statusText.layer.borderColor = UIColor.systemGray.cgColor
statusText.layer.masksToBounds = true
statusText.backgroundColor = .secondarySystemBackground
statusCollabora.layer.cornerRadius = 12.5
statusCollabora.layer.borderWidth = 0.5
statusCollabora.layer.borderColor = UIColor.systemGray.cgColor
statusCollabora.layer.masksToBounds = true
statusCollabora.backgroundColor = .secondarySystemBackground
statusOnlyOffice.layer.cornerRadius = 12.5
statusOnlyOffice.layer.borderWidth = 0.5
statusOnlyOffice.layer.borderColor = UIColor.systemGray.cgColor
statusOnlyOffice.layer.masksToBounds = true
statusOnlyOffice.backgroundColor = .secondarySystemBackground
statusUserStatus.layer.cornerRadius = 12.5
statusUserStatus.layer.borderWidth = 0.5
statusUserStatus.layer.borderColor = UIColor.systemGray.cgColor
statusUserStatus.layer.masksToBounds = true
statusUserStatus.backgroundColor = .secondarySystemBackground
statusComments.layer.cornerRadius = 12.5
statusComments.layer.borderWidth = 0.5
statusComments.layer.borderColor = UIColor.systemGray.cgColor
statusComments.layer.masksToBounds = true
statusComments.backgroundColor = .secondarySystemBackground
statusLockFile.layer.cornerRadius = 12.5
statusLockFile.layer.borderWidth = 0.5
statusLockFile.layer.borderColor = UIColor.systemGray.cgColor
statusLockFile.layer.masksToBounds = true
statusLockFile.backgroundColor = .secondarySystemBackground
imageFileSharing.image = UIImage(named: "share")!.image(color: NCBrandColor.shared.gray, size: 50)
imageExternalSite.image = NCUtility.shared.loadImage(named: "network", color: NCBrandColor.shared.gray)
imageEndToEndEncryption.image = NCUtility.shared.loadImage(named: "lock", color: NCBrandColor.shared.gray)
imageActivity.image = UIImage(named: "bolt")!.image(color: NCBrandColor.shared.gray, size: 50)
imageNotification.image = NCUtility.shared.loadImage(named: "bell", color: NCBrandColor.shared.gray)
imageDeletedFiles.image = NCUtility.shared.loadImage(named: "trash", color: NCBrandColor.shared.gray)
imageText.image = UIImage(named: "text")!.image(color: NCBrandColor.shared.gray, size: 50)
imageCollabora.image = UIImage(named: "collabora")!.image(color: NCBrandColor.shared.gray, size: 50)
imageOnlyOffice.image = UIImage(named: "onlyoffice")!.image(color: NCBrandColor.shared.gray, size: 50)
imageUserStatus.image = UIImage(named: "userStatusAway")!.image(color: NCBrandColor.shared.gray, size: 50)
imageComments.image = UIImage(named: "comments")!.image(color: NCBrandColor.shared.gray, size: 50)
imageLockFile.image = UIImage(named: "lock")!.image(color: NCBrandColor.shared.gray, size: 50)
guard let activeAccount = NCManageDatabase.shared.getActiveAccount() else { return }
self.account = activeAccount.account
if let text = NCManageDatabase.shared.getCapabilities(account: activeAccount.account) {
capabilitiesText = text
updateCapabilities()
} else {
let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_capabilities_found_")
NCContentPresenter.shared.showError(error: error, priority: .max)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.dismiss(animated: true, completion: nil)
}
}
homeImage.image = UIImage(named: "home")!.image(color: NCBrandColor.shared.gray, size: 50)
homeServer.text = NCUtilityFileSystem.shared.getHomeServer(account: appDelegate.account) + "/"
}
@objc func updateCapabilities() {
NextcloudKit.shared.getCapabilities { account, data, error in
if error == .success && data != nil {
NCManageDatabase.shared.addCapabilitiesJSon(data!, account: account)
// EDITORS
let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
if serverVersionMajor >= NCGlobal.shared.nextcloudVersion18 {
NextcloudKit.shared.NCTextObtainEditorDetails { account, editors, creators, data, error in
if error == .success && account == self.appDelegate.account {
NCManageDatabase.shared.addDirectEditing(account: account, editors: editors, creators: creators)
self.readCapabilities()
}
if self.view.window != nil {
// self.timer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(self.updateCapabilities), userInfo: nil, repeats: false)
}
}
} else {
if self.view.window != nil {
// self.timer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(self.updateCapabilities), userInfo: nil, repeats: false)
}
}
if let text = NCManageDatabase.shared.getCapabilities(account: account) {
self.capabilitiesText = text
}
self.readCapabilities()
}
}
readCapabilities()
}
@objc func share() {
// timer?.invalidate()
self.dismiss(animated: true) {
let fileURL = NSURL.fileURL(withPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent("capabilities.txt")
do {
try self.capabilitiesText.write(to: fileURL, atomically: true, encoding: .utf8)
if let view = self.appDelegate.window?.rootViewController?.view {
self.documentController = UIDocumentInteractionController(url: fileURL)
self.documentController?.delegate = self
self.documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
}
} catch { }
}
}
@objc func close() {
// timer?.invalidate()
self.dismiss(animated: true, completion: nil)
}
func readCapabilities() {
textView.text = capabilitiesText
if NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false) {
statusFileSharing.text = "✓ " + NSLocalizedString("_available_", comment: "")
} else {
statusFileSharing.text = NSLocalizedString("_not_available_", comment: "")
}
if NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesExternalSitesExists, exists: true) {
statusExternalSite.text = "✓ " + NSLocalizedString("_available_", comment: "")
} else {
statusExternalSite.text = NSLocalizedString("_not_available_", comment: "")
}
let isE2EEEnabled = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesE2EEEnabled, exists: false)
// let versionE2EE = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesE2EEApiVersion)
if isE2EEEnabled {
statusEndToEndEncryption.text = "✓ " + NSLocalizedString("_available_", comment: "")
} else {
statusEndToEndEncryption.text = NSLocalizedString("_not_available_", comment: "")
}
let activity = NCManageDatabase.shared.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesActivity)
if activity != nil {
statusActivity.text = "✓ " + NSLocalizedString("_available_", comment: "")
} else {
statusActivity.text = NSLocalizedString("_not_available_", comment: "")
}
let notification = NCManageDatabase.shared.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesNotification)
if notification != nil {
statusNotification.text = "✓ " + NSLocalizedString("_available_", comment: "")
} else {
statusNotification.text = NSLocalizedString("_not_available_", comment: "")
}
let deleteFiles = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFilesUndelete, exists: false)
if deleteFiles {
statusDeletedFiles.text = "✓ " + NSLocalizedString("_available_", comment: "")
} else {
statusDeletedFiles.text = NSLocalizedString("_not_available_", comment: "")
}
var textEditor = false
var onlyofficeEditors = false
if let editors = NCManageDatabase.shared.getDirectEditingEditors(account: account) {
for editor in editors {
if editor.editor == NCGlobal.shared.editorText {
textEditor = true
} else if editor.editor == NCGlobal.shared.editorOnlyoffice {
onlyofficeEditors = true
}
}
}
if textEditor {
statusText.text = "✓ " + NSLocalizedString("_available_", comment: "")
} else {
statusText.text = NSLocalizedString("_not_available_", comment: "")
}
let richdocumentsMimetypes = NCManageDatabase.shared.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes)
if richdocumentsMimetypes != nil {
statusCollabora.text = "✓ " + NSLocalizedString("_available_", comment: "")
} else {
statusCollabora.text = NSLocalizedString("_not_available_", comment: "")
}
if onlyofficeEditors {
statusOnlyOffice.text = "✓ " + NSLocalizedString("_available_", comment: "")
} else {
statusOnlyOffice.text = NSLocalizedString("_not_available_", comment: "")
}
let userStatus = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesUserStatusEnabled, exists: false)
if userStatus {
statusUserStatus.text = "✓ " + NSLocalizedString("_available_", comment: "")
} else {
statusUserStatus.text = NSLocalizedString("_not_available_", comment: "")
}
let comments = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFilesComments, exists: false)
if comments {
statusComments.text = "✓ " + NSLocalizedString("_available_", comment: "")
} else {
statusComments.text = NSLocalizedString("_not_available_", comment: "")
}
let hasLockCapability = NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesFilesLockVersion) >= 1
if hasLockCapability {
statusLockFile.text = "✓ " + NSLocalizedString("_available_", comment: "")
} else {
statusLockFile.text = NSLocalizedString("_not_available_", comment: "")
}
print("end.")
}
}
|