Welcome to mirror list, hosted at ThFree Co, Russian Federation.

NCGlobal.swift « iOSClient - github.com/nextcloud/ios.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 252db23d9147e0d3a256774ee041ae876c66f59c (plain)
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
//
//  NCGlobal.swift
//  Nextcloud
//
//  Created by Marino Faggiana on 22/02/21.
//  Copyright © 2021 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

class NCGlobal: NSObject {
    @objc static let shared: NCGlobal = {
        let instance = NCGlobal()
        return instance
    }()

    func usernameToColor(_ username: String) -> CGColor {
        // Normalize hash
        let lowerUsername = username.lowercased()
        var hash: String

        let regex = try! NSRegularExpression(pattern: "^([0-9a-f]{4}-?){8}$")
        let matches = regex.matches(
            in: username,
            range: NSRange(username.startIndex..., in: username))

        if !matches.isEmpty {
            // Already a md5 hash?
            // done, use as is.
            hash = lowerUsername
        } else {
            hash = lowerUsername.md5()
        }

        hash = hash.replacingOccurrences(of: "[^0-9a-f]", with: "", options: .regularExpression)

        // userColors has 18 colors by default
        let userColorIx = NCGlobal.hashToInt(hash: hash, maximum: 18)
        return NCBrandColor.shared.userColors[userColorIx]
    }

    // Convert a string to an integer evenly
    // hash is hex string
    static func hashToInt(hash: String, maximum: Int) -> Int {
        let result = hash.compactMap(\.hexDigitValue)
        return result.reduce(0, { $0 + $1 }) % maximum
    }

    // Struct for Progress
    //
    struct progressType {
        var progress: Float
        var totalBytes: Int64
        var totalBytesExpected: Int64
    }

    // Struct for LayoutForView
    //
    struct layoutForViewType {
        var layout: String
        var sort: String
        var ascending: Bool
        var groupBy: String
        var directoryOnTop: Bool
        var titleButtonHeader: String
        var itemForLine: Int
    }

    // Directory on Group
    //
    @objc let directoryProviderStorage              = "File Provider Storage"
    @objc let appApplicationSupport                 = "Library/Application Support"
    @objc let appCertificates                       = "Library/Application Support/Certificates"
    @objc let appDatabaseNextcloud                  = "Library/Application Support/Nextcloud"
    @objc let appScan                               = "Library/Application Support/Scan"
    @objc let appUserData                           = "Library/Application Support/UserData"

    // Service
    //
    @objc let serviceShareKeyChain                  = "Crypto Cloud"
    let metadataKeyedUnarchiver                     = "it.twsweb.nextcloud.metadata"
    let refreshTask                                 = "com.nextcloud.refreshTask"
    let processingTask                              = "com.nextcloud.processingTask"

    // Name
    //
    @objc let appName                               = "files"
    @objc let talkName                              = "talk-message"

    // DAV -
    //
    @objc let dav                                   = "remote.php/dav"
    @objc let davfiles                              = "remote.php/dav/files/"

    // Nextcloud version
    //
    let nextcloudVersion12: Int                     =  12
    let nextcloudVersion15: Int                     =  15
    let nextcloudVersion17: Int                     =  17
    let nextcloudVersion18: Int                     =  18
    let nextcloudVersion20: Int                     =  20
    let nextcloudVersion23: Int                     =  23
    let nextcloudVersion24: Int                     =  24
    let nextcloudVersion25: Int                     =  25

    // Database Realm
    //
    let databaseDefault                             = "nextcloud.realm"
    let databaseSchemaVersion: UInt64               = 255

    // Intro selector
    //
    @objc let introLogin: Int                       = 0
    let introSignup: Int                            = 1

    // Varie size GUI
    //
    @objc let heightCellSettings: CGFloat           = 50

    // Avatar & Preview size
    //
    let avatarSize: Int                             = 128 * Int(UIScreen.main.scale)
    let avatarSizeRounded: Int                      = 128
    let sizePreview: Int                            = 1024
    let sizeIcon: Int                               = 512

    // E2EE
    //
    let e2eeMaxFileSize: UInt64                     = 500000000     // 500 MB
    let e2eePassphraseTest                          = "more over television factory tendency independence international intellectual impress interest sentence pony"
    @objc let e2eeVersion                           = "1.1"
    
    // Video
    //
    let maxHTTPCache: Int64                         = 10000000000   // 10 GB
    let fileNameVideoEncoded: String                = "video_encoded.mp4"

    // NCSharePaging
    //
    enum NCSharePagingIndex: Int, CaseIterable {
        case activity, sharing
    }

    // NCViewerProviderContextMenu
    //
    let maxAutoDownload: UInt64                     = 50000000      // 50MB
    let maxAutoDownloadCellular: UInt64             = 10000000      // 10MB

    // Nextcloud unsupported
    //
    let nextcloud_unsupported_version: Int          = 16

    // Layout
    //
    let layoutList                                  = "typeLayoutList"
    let layoutGrid                                  = "typeLayoutGrid"

    let layoutViewMove                              = "LayoutMove"
    let layoutViewTrash                             = "LayoutTrash"
    let layoutViewOffline                           = "LayoutOffline"
    let layoutViewFavorite                          = "LayoutFavorite"
    let layoutViewFiles                             = "LayoutFiles"
    let layoutViewViewInFolder                      = "LayoutViewInFolder"
    let layoutViewTransfers                         = "LayoutTransfers"
    let layoutViewRecent                            = "LayoutRecent"
    let layoutViewShares                            = "LayoutShares"
    let layoutViewShareExtension                    = "LayoutShareExtension"

    // Button Type in Cell list/grid
    //
    let buttonMoreMore                              = "more"
    let buttonMoreStop                              = "stop"
    let buttonMoreLock                              = "moreLock"

    // Standard height sections header/footer
    //
    let heightButtonsCommand: CGFloat               = 50
    let heightButtonsView: CGFloat                  = 50
    let heightSection: CGFloat                      = 30
    let heightFooter: CGFloat                       = 1
    let heightFooterButton: CGFloat                 = 30
    let endHeightFooter: CGFloat                    = 85

    // Text -  OnlyOffice - Collabora - QuickLook
    //
    let editorText                                  = "text"
    let editorOnlyoffice                            = "onlyoffice"
    let editorCollabora                             = "collabora"
    let editorQuickLook                             = "quicklook"

    let onlyofficeDocx                              = "onlyoffice_docx"
    let onlyofficeXlsx                              = "onlyoffice_xlsx"
    let onlyofficePptx                              = "onlyoffice_pptx"

    // Template
    //
    let templateDocument                            = "document"
    let templateSpreadsheet                         = "spreadsheet"
    let templatePresentation                        = "presentation"

    // Rich Workspace
    //
    let fileNameRichWorkspace                       = "Readme.md"

    // Extension
    //
    @objc let extensionPreview                      = "ico"

    // ContentPresenter
    //
    @objc let dismissAfterSecond: TimeInterval      = 4
    @objc let dismissAfterSecondLong: TimeInterval  = 10

    // Error
    //
    @objc let errorRequestExplicityCancelled: Int   = 15
    @objc let errorNotModified: Int                 = 304
    @objc let errorBadRequest: Int                  = 400
    @objc let errorUnauthorized: Int                = 401
    @objc let errorForbidden: Int                   = 403
    @objc let errorResourceNotFound: Int            = 404
    @objc let errordMethodNotSupported: Int         = 405
    @objc let errorConflict: Int                    = 409
    @objc let errorPreconditionFailed: Int          = 412
    @objc let errorNCUnauthorized: Int              = 997
    @objc let errorConnectionLost: Int              = -1005
    @objc let errorNetworkNotAvailable: Int         = -1009
    @objc let errorBadServerResponse: Int           = -1011
    @objc let errorInternalError: Int               = -99999
    @objc let errorFileNotSaved: Int                = -99998
    @objc let errorDecodeMetadata: Int              = -99997
    @objc let errorE2EENotEnabled: Int              = -99996
    @objc let errorOffline: Int                     = -99994
    @objc let errorCharactersForbidden: Int         = -99993
    @objc let errorCreationFile: Int                = -99992
    @objc let errorReadFile: Int                    = -99991

    // Constants to identify the different permissions of a file
    //
    @objc let permissionShared                      = "S"
    @objc let permissionCanShare                    = "R"
    @objc let permissionMounted                     = "M"
    @objc let permissionFileCanWrite                = "W"
    @objc let permissionCanCreateFile               = "C"
    @objc let permissionCanCreateFolder             = "K"
    @objc let permissionCanDelete                   = "D"
    @objc let permissionCanRename                   = "N"
    @objc let permissionCanMove                     = "V"

    // Share permission
    // permissions - (int) 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all
    //
    @objc let permissionReadShare: Int              = 1
    @objc let permissionUpdateShare: Int            = 2
    @objc let permissionCreateShare: Int            = 4
    @objc let permissionDeleteShare: Int            = 8
    @objc let permissionShareShare: Int             = 16

    @objc let permissionMinFileShare: Int           = 1
    @objc let permissionMaxFileShare: Int           = 19
    @objc let permissionMinFolderShare: Int         = 1
    @objc let permissionMaxFolderShare: Int         = 31
    @objc let permissionDefaultFileRemoteShareNoSupportShareOption: Int     = 3
    @objc let permissionDefaultFolderRemoteShareNoSupportShareOption: Int   = 15

    // Filename Mask and Type
    //
    let keyFileNameMask                             = "fileNameMask"
    let keyFileNameType                             = "fileNameType"
    let keyFileNameAutoUploadMask                   = "fileNameAutoUploadMask"
    let keyFileNameAutoUploadType                   = "fileNameAutoUploadType"
    let keyFileNameOriginal                         = "fileNameOriginal"
    let keyFileNameOriginalAutoUpload               = "fileNameOriginalAutoUpload"

    // Selector
    //
    let selectorDownloadFile                        = "downloadFile"
    let selectorDownloadAllFile                     = "downloadAllFile"
    let selectorReadFile                            = "readFile"
    let selectorListingFavorite                     = "listingFavorite"
    let selectorLoadFileView                        = "loadFileView"
    let selectorLoadFileQuickLook                   = "loadFileQuickLook"
    let selectorLoadOffline                         = "loadOffline"
    let selectorOpenIn                              = "openIn"
    let selectorPrint                               = "print"
    let selectorUploadAutoUpload                    = "uploadAutoUpload"
    let selectorUploadAutoUploadAll                 = "uploadAutoUploadAll"
    let selectorUploadFile                          = "uploadFile"
    let selectorUploadFileNODelete                  = "UploadFileNODelete"
    let selectorUploadFileShareExtension            = "uploadFileShareExtension"
    let selectorSaveAlbum                           = "saveAlbum"
    let selectorSaveAlbumLivePhotoIMG               = "saveAlbumLivePhotoIMG"
    let selectorSaveAlbumLivePhotoMOV               = "saveAlbumLivePhotoMOV"
    let selectorSaveAsScan                          = "saveAsScan"
    let selectorOpenDetail                          = "openDetail"

    // Metadata : Status
    //
    // 1) wait download/upload
    // 2) in download/upload
    // 3) downloading/uploading
    // 4) done or error
    //
    let metadataStatusNormal: Int                   = 0

    let metadataStatusWaitDownload: Int             = -1
    let metadataStatusInDownload: Int               = -2
    let metadataStatusDownloading: Int              = -3
    let metadataStatusDownloadError: Int            = -4

    let metadataStatusWaitUpload: Int               = 1
    let metadataStatusInUpload: Int                 = 2
    let metadataStatusUploading: Int                = 3
    let metadataStatusUploadError: Int              = 4

    // Notification Center
    //
    @objc let notificationCenterApplicationDidEnterBackground   = "applicationDidEnterBackground"
    let notificationCenterApplicationWillEnterForeground        = "applicationWillEnterForeground"
    let notificationCenterApplicationDidBecomeActive            = "applicationDidBecomeActive"
    let notificationCenterApplicationWillResignActive           = "applicationWillResignActive"

    @objc let notificationCenterInitialize                      = "initialize"                      // userInfo?: atStart
    @objc let notificationCenterChangeTheming                   = "changeTheming"
    let notificationCenterRichdocumentGrabFocus                 = "richdocumentGrabFocus"
    let notificationCenterReloadDataNCShare                     = "reloadDataNCShare"
    let notificationCenterCloseRichWorkspaceWebView             = "closeRichWorkspaceWebView"
    let notificationCenterUpdateBadgeNumber                     = "updateBadgeNumber"               // userInfo: counter
    let notificationCenterReloadAvatar                          = "reloadAvatar"

    @objc let notificationCenterReloadDataSource                = "reloadDataSource"                // userInfo: serverUrl?
    let notificationCenterReloadDataSourceNetwork               = "reloadDataSourceNetwork"         // userInfo: serverUrl?
    let notificationCenterReloadDataSourceNetworkForced         = "reloadDataSourceNetworkForced"   // userInfo: serverUrl?

    let notificationCenterChangeStatusFolderE2EE                = "changeStatusFolderE2EE"          // userInfo: serverUrl

    let notificationCenterDownloadStartFile                     = "downloadStartFile"               // userInfo: ocId, serverUrl, account
    let notificationCenterDownloadedFile                        = "downloadedFile"                  // userInfo: ocId, serverUrl, account, selector, error
    let notificationCenterDownloadCancelFile                    = "downloadCancelFile"              // userInfo: ocId, serverUrl, account

    let notificationCenterUploadStartFile                       = "uploadStartFile"                 // userInfo: ocId, serverUrl, account, fileName, sessionSelector
    @objc let notificationCenterUploadedFile                    = "uploadedFile"                    // userInfo: ocId, serverUrl, account, fileName, ocIdTemp, error
    let notificationCenterUploadCancelFile                      = "uploadCancelFile"                // userInfo: ocId, serverUrl, account

    let notificationCenterProgressTask                          = "progressTask"                    // userInfo: account, ocId, serverUrl, status, progress, totalBytes, totalBytesExpected

    let notificationCenterCreateFolder                          = "createFolder"                    // userInfo: ocId, serverUrl, account, e2ee
    let notificationCenterDeleteFile                            = "deleteFile"                      // userInfo: ocId, fileNameView, serverUrl, account, classFile, onlyLocalCache
    let notificationCenterRenameFile                            = "renameFile"                      // userInfo: ocId, account
    let notificationCenterMoveFile                              = "moveFile"                        // userInfo: ocId, account, serverUrlFrom
    let notificationCenterCopyFile                              = "copyFile"                        // userInfo: ocId, serverUrlTo
    let notificationCenterFavoriteFile                          = "favoriteFile"                    // userInfo: ocId, serverUrl

    let notificationCenterMenuSearchTextPDF                     = "menuSearchTextPDF"
    let notificationCenterMenuGotToPageInPDF                    = "menuGotToPageInPDF"
    let notificationCenterMenuDetailClose                       = "menuDetailClose"

    let notificationCenterChangedLocation                       = "changedLocation"
    let notificationStatusAuthorizationChangedLocation          = "statusAuthorizationChangedLocation"

    let notificationCenterDownloadedThumbnail                   = "DownloadedThumbnail"             // userInfo: ocId

    let notificationCenterHidePlayerToolBar                     = "hidePlayerToolBar"               // userInfo: ocId
    let notificationCenterShowPlayerToolBar                     = "showPlayerToolBar"               // userInfo: ocId, enableTimerAutoHide
    let notificationCenterOpenMediaDetail                       = "openMediaDetail"                 // userInfo: ocId

    let notificationCenterReloadMediaPage                       = "reloadMediaPage"
    let notificationCenterPlayMedia                             = "playMedia"
    let notificationCenterPauseMedia                            = "pauseMedia"

    // TIP
    //
    let tipNCViewerPDFThumbnail                                 = "tipncviewerpdfthumbnail"
    let tipNCCollectionViewCommonAccountRequest                 = "tipnccollectionviewcommonaccountrequest"
    let tipNCScanAddImage                                       = "tipncscanaddimage"
    let tipNCViewerMediaDetailView                              = "tipncviewermediadetailview"
    
    // ACTION
    //
    let actionNoAction                                          = "no-action"
    let actionUploadAsset                                       = "upload-asset"
    let actionScanDocument                                      = "add-scan-document"
    let actionTextDocument                                      = "create-text-document"
    let actionVoiceMemo                                         = "create-voice-memo"
    
    // WIDGET ACTION
    //
    let widgetActionNoAction                                    = "nextcloud://open-action?action=no-action"
    let widgetActionUploadAsset                                 = "nextcloud://open-action?action=upload-asset"
    let widgetActionScanDocument                                = "nextcloud://open-action?action=add-scan-document"
    let widgetActionTextDocument                                = "nextcloud://open-action?action=create-text-document"
    let widgetActionVoiceMemo                                   = "nextcloud://open-action?action=create-voice-memo"
    
    // APPCONFIG
    //
    let configuration_brand                                     = "brand"

    let configuration_serverUrl                                 = "serverUrl"
    let configuration_username                                  = "username"
    let configuration_password                                  = "password"
    let configuration_apppassword                               = "apppassword"
    
    let configuration_disable_intro                             = "disable_intro"
    let configuration_disable_multiaccount                      = "disable_multiaccount"
    let configuration_disable_crash_service                     = "disable_crash_service"
    let configuration_disable_log                               = "disable_log"
    let configuration_disable_manage_account                    = "disable_manage_account"
    let configuration_disable_more_external_site                = "disable_more_external_site"
    let configuration_disable_openin_file                       = "disable_openin_file"
}