NCGlobal.swift 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. //
  2. // NCGlobal.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 22/02/21.
  6. // Copyright © 2021 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 NCGlobal: NSObject {
  25. @objc static let shared: NCGlobal = {
  26. let instance = NCGlobal()
  27. return instance
  28. }()
  29. func usernameToColor(_ username: String) -> CGColor {
  30. // Normalize hash
  31. let lowerUsername = username.lowercased()
  32. var hash: String
  33. let regex = try! NSRegularExpression(pattern: "^([0-9a-f]{4}-?){8}$")
  34. let matches = regex.matches(
  35. in: username,
  36. range: NSRange(username.startIndex..., in: username))
  37. if !matches.isEmpty {
  38. // Already a md5 hash?
  39. // done, use as is.
  40. hash = lowerUsername
  41. } else {
  42. hash = lowerUsername.md5()
  43. }
  44. hash = hash.replacingOccurrences(of: "[^0-9a-f]", with: "", options: .regularExpression)
  45. // userColors has 18 colors by default
  46. let userColorIx = NCGlobal.hashToInt(hash: hash, maximum: 18)
  47. return NCBrandColor.shared.userColors[userColorIx]
  48. }
  49. // Convert a string to an integer evenly
  50. // hash is hex string
  51. static func hashToInt(hash: String, maximum: Int) -> Int {
  52. let result = hash.compactMap(\.hexDigitValue)
  53. return result.reduce(0, { $0 + $1 }) % maximum
  54. }
  55. // Struct for Progress
  56. //
  57. struct progressType {
  58. var progress: Float
  59. var totalBytes: Int64
  60. var totalBytesExpected: Int64
  61. }
  62. // Directory on Group
  63. //
  64. @objc let directoryProviderStorage = "File Provider Storage"
  65. @objc let appApplicationSupport = "Library/Application Support"
  66. @objc let appCertificates = "Library/Application Support/Certificates"
  67. @objc let appDatabaseNextcloud = "Library/Application Support/Nextcloud"
  68. @objc let appScan = "Library/Application Support/Scan"
  69. @objc let appUserData = "Library/Application Support/UserData"
  70. // Service
  71. //
  72. @objc let serviceShareKeyChain = "Crypto Cloud"
  73. let metadataKeyedUnarchiver = "it.twsweb.nextcloud.metadata"
  74. let refreshTask = "com.nextcloud.refreshTask"
  75. let processingTask = "com.nextcloud.processingTask"
  76. // Name
  77. //
  78. @objc let appName = "files"
  79. @objc let talkName = "talk-message"
  80. @objc let appScheme = "nextcloud"
  81. // Nextcloud version
  82. //
  83. let nextcloudVersion12: Int = 12
  84. let nextcloudVersion15: Int = 15
  85. let nextcloudVersion17: Int = 17
  86. let nextcloudVersion18: Int = 18
  87. let nextcloudVersion20: Int = 20
  88. let nextcloudVersion23: Int = 23
  89. let nextcloudVersion24: Int = 24
  90. let nextcloudVersion25: Int = 25
  91. let nextcloudVersion26: Int = 26
  92. // Nextcloud unsupported
  93. //
  94. let nextcloud_unsupported_version: Int = 16
  95. // Database Realm
  96. //
  97. let databaseDefault = "nextcloud.realm"
  98. let databaseSchemaVersion: UInt64 = 266
  99. // Intro selector
  100. //
  101. @objc let introLogin: Int = 0
  102. let introSignup: Int = 1
  103. // Varie size GUI
  104. //
  105. @objc let heightCellSettings: CGFloat = 50
  106. // Avatar & Preview size
  107. //
  108. let avatarSize: Int = 128 * Int(UIScreen.main.scale)
  109. let avatarSizeRounded: Int = 128
  110. let sizePreview: Int = 1024
  111. let sizeIcon: Int = 512
  112. // E2EE
  113. //
  114. let e2eeMaxFileSize: UInt64 = 500000000 // 500 MB
  115. let e2eePassphraseTest = "more over television factory tendency independence international intellectual impress interest sentence pony"
  116. @objc let e2eeVersion = "1.1"
  117. // Video
  118. //
  119. let maxHTTPCache: Int64 = 10000000000 // 10 GB
  120. let fileNameVideoEncoded: String = "video_encoded.mp4"
  121. // NCSharePaging
  122. //
  123. enum NCSharePagingIndex: Int, CaseIterable {
  124. case activity, sharing
  125. }
  126. // NCViewerProviderContextMenu
  127. //
  128. let maxAutoDownload: UInt64 = 50000000 // 50MB
  129. let maxAutoDownloadCellular: UInt64 = 10000000 // 10MB
  130. // Layout
  131. //
  132. let layoutList = "typeLayoutList"
  133. let layoutGrid = "typeLayoutGrid"
  134. let layoutViewMove = "LayoutMove"
  135. let layoutViewTrash = "LayoutTrash"
  136. let layoutViewOffline = "LayoutOffline"
  137. let layoutViewFavorite = "LayoutFavorite"
  138. let layoutViewFiles = "LayoutFiles"
  139. let layoutViewViewInFolder = "LayoutViewInFolder"
  140. let layoutViewTransfers = "LayoutTransfers"
  141. let layoutViewRecent = "LayoutRecent"
  142. let layoutViewShares = "LayoutShares"
  143. let layoutViewShareExtension = "LayoutShareExtension"
  144. // Button Type in Cell list/grid
  145. //
  146. let buttonMoreMore = "more"
  147. let buttonMoreStop = "stop"
  148. let buttonMoreLock = "moreLock"
  149. // Standard height sections header/footer
  150. //
  151. let heightButtonsCommand: CGFloat = 50
  152. let heightButtonsView: CGFloat = 50
  153. let heightSection: CGFloat = 30
  154. let heightFooter: CGFloat = 1
  155. let heightFooterButton: CGFloat = 30
  156. let endHeightFooter: CGFloat = 85
  157. // Text - OnlyOffice - Collabora - QuickLook
  158. //
  159. let editorText = "text"
  160. let editorOnlyoffice = "onlyoffice"
  161. let editorCollabora = "collabora"
  162. let editorQuickLook = "quicklook"
  163. let onlyofficeDocx = "onlyoffice_docx"
  164. let onlyofficeXlsx = "onlyoffice_xlsx"
  165. let onlyofficePptx = "onlyoffice_pptx"
  166. // Template
  167. //
  168. let templateDocument = "document"
  169. let templateSpreadsheet = "spreadsheet"
  170. let templatePresentation = "presentation"
  171. // Rich Workspace
  172. //
  173. let fileNameRichWorkspace = "Readme.md"
  174. // Extension
  175. //
  176. @objc let extensionPreview = "ico"
  177. // ContentPresenter
  178. //
  179. @objc let dismissAfterSecond: TimeInterval = 4
  180. @objc let dismissAfterSecondLong: TimeInterval = 10
  181. // Error
  182. //
  183. @objc let errorRequestExplicityCancelled: Int = 15
  184. @objc let errorNotModified: Int = 304
  185. @objc let errorBadRequest: Int = 400
  186. @objc let errorUnauthorized: Int = 401
  187. @objc let errorForbidden: Int = 403
  188. @objc let errorResourceNotFound: Int = 404
  189. @objc let errordMethodNotSupported: Int = 405
  190. @objc let errorConflict: Int = 409
  191. @objc let errorPreconditionFailed: Int = 412
  192. @objc let errorNCUnauthorized: Int = 997
  193. @objc let errorConnectionLost: Int = -1005
  194. @objc let errorNetworkNotAvailable: Int = -1009
  195. @objc let errorBadServerResponse: Int = -1011
  196. @objc let errorInternalError: Int = -99999
  197. @objc let errorFileNotSaved: Int = -99998
  198. @objc let errorDecodeMetadata: Int = -99997
  199. @objc let errorE2EENotEnabled: Int = -99996
  200. @objc let errorOffline: Int = -99994
  201. @objc let errorCharactersForbidden: Int = -99993
  202. @objc let errorCreationFile: Int = -99992
  203. @objc let errorReadFile: Int = -99991
  204. @objc let errorUnauthorizedFilesPasscode: Int = -99990
  205. @objc let errorDisableFilesApp: Int = -99989
  206. // Constants to identify the different permissions of a file
  207. //
  208. @objc let permissionShared = "S"
  209. @objc let permissionCanShare = "R"
  210. @objc let permissionMounted = "M"
  211. @objc let permissionFileCanWrite = "W"
  212. @objc let permissionCanCreateFile = "C"
  213. @objc let permissionCanCreateFolder = "K"
  214. @objc let permissionCanDelete = "D"
  215. @objc let permissionCanRename = "N"
  216. @objc let permissionCanMove = "V"
  217. // Share permission
  218. // permissions - (int) 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all
  219. //
  220. @objc let permissionReadShare: Int = 1
  221. @objc let permissionUpdateShare: Int = 2
  222. @objc let permissionCreateShare: Int = 4
  223. @objc let permissionDeleteShare: Int = 8
  224. @objc let permissionShareShare: Int = 16
  225. @objc let permissionMinFileShare: Int = 1
  226. @objc let permissionMaxFileShare: Int = 19
  227. @objc let permissionMinFolderShare: Int = 1
  228. @objc let permissionMaxFolderShare: Int = 31
  229. @objc let permissionDefaultFileRemoteShareNoSupportShareOption: Int = 3
  230. @objc let permissionDefaultFolderRemoteShareNoSupportShareOption: Int = 15
  231. // Filename Mask and Type
  232. //
  233. let keyFileNameMask = "fileNameMask"
  234. let keyFileNameType = "fileNameType"
  235. let keyFileNameAutoUploadMask = "fileNameAutoUploadMask"
  236. let keyFileNameAutoUploadType = "fileNameAutoUploadType"
  237. let keyFileNameOriginal = "fileNameOriginal"
  238. let keyFileNameOriginalAutoUpload = "fileNameOriginalAutoUpload"
  239. // Selector
  240. //
  241. let selectorDownloadFile = "downloadFile"
  242. let selectorDownloadAllFile = "downloadAllFile"
  243. let selectorReadFile = "readFile"
  244. let selectorListingFavorite = "listingFavorite"
  245. let selectorLoadFileView = "loadFileView"
  246. let selectorLoadFileQuickLook = "loadFileQuickLook"
  247. let selectorLoadOffline = "loadOffline"
  248. let selectorOpenIn = "openIn"
  249. let selectorPrint = "print"
  250. let selectorUploadAutoUpload = "uploadAutoUpload"
  251. let selectorUploadAutoUploadAll = "uploadAutoUploadAll"
  252. let selectorUploadFile = "uploadFile"
  253. let selectorUploadFileNODelete = "UploadFileNODelete"
  254. let selectorUploadFileShareExtension = "uploadFileShareExtension"
  255. let selectorSaveAlbum = "saveAlbum"
  256. let selectorSaveAlbumLivePhotoIMG = "saveAlbumLivePhotoIMG"
  257. let selectorSaveAlbumLivePhotoMOV = "saveAlbumLivePhotoMOV"
  258. let selectorSaveAsScan = "saveAsScan"
  259. let selectorOpenDetail = "openDetail"
  260. // Metadata : Status
  261. //
  262. // 1) wait download/upload
  263. // 2) in download/upload
  264. // 3) downloading/uploading
  265. // 4) done or error
  266. //
  267. let metadataStatusNormal: Int = 0
  268. let metadataStatusWaitDownload: Int = -1
  269. let metadataStatusInDownload: Int = -2
  270. let metadataStatusDownloading: Int = -3
  271. let metadataStatusDownloadError: Int = -4
  272. let metadataStatusWaitUpload: Int = 1
  273. let metadataStatusInUpload: Int = 2
  274. let metadataStatusUploading: Int = 3
  275. let metadataStatusUploadError: Int = 4
  276. // Hidden files included in the read
  277. //
  278. let includeHiddenFiles: [String] = [".LivePhoto"]
  279. // Notification Center
  280. //
  281. @objc let notificationCenterApplicationDidEnterBackground = "applicationDidEnterBackground"
  282. let notificationCenterApplicationWillEnterForeground = "applicationWillEnterForeground"
  283. let notificationCenterApplicationDidBecomeActive = "applicationDidBecomeActive"
  284. let notificationCenterApplicationWillResignActive = "applicationWillResignActive"
  285. @objc let notificationCenterInitialize = "initialize" // userInfo?: atStart
  286. @objc let notificationCenterChangeTheming = "changeTheming"
  287. let notificationCenterRichdocumentGrabFocus = "richdocumentGrabFocus"
  288. let notificationCenterReloadDataNCShare = "reloadDataNCShare"
  289. let notificationCenterCloseRichWorkspaceWebView = "closeRichWorkspaceWebView"
  290. let notificationCenterUpdateBadgeNumber = "updateBadgeNumber" // userInfo: counter
  291. let notificationCenterReloadAvatar = "reloadAvatar"
  292. @objc let notificationCenterReloadDataSource = "reloadDataSource" // userInfo: serverUrl?
  293. let notificationCenterReloadDataSourceNetwork = "reloadDataSourceNetwork" // userInfo: serverUrl?
  294. let notificationCenterReloadDataSourceNetworkForced = "reloadDataSourceNetworkForced" // userInfo: serverUrl?
  295. let notificationCenterChangeStatusFolderE2EE = "changeStatusFolderE2EE" // userInfo: serverUrl
  296. let notificationCenterDownloadStartFile = "downloadStartFile" // userInfo: ocId, serverUrl, account
  297. let notificationCenterDownloadedFile = "downloadedFile" // userInfo: ocId, serverUrl, account, selector, error
  298. let notificationCenterDownloadCancelFile = "downloadCancelFile" // userInfo: ocId, serverUrl, account
  299. let notificationCenterUploadStartFile = "uploadStartFile" // userInfo: ocId, serverUrl, account, fileName, sessionSelector
  300. @objc let notificationCenterUploadedFile = "uploadedFile" // userInfo: ocId, serverUrl, account, fileName, ocIdTemp, error
  301. let notificationCenterUploadCancelFile = "uploadCancelFile" // userInfo: ocId, serverUrl, account
  302. let notificationCenterProgressTask = "progressTask" // userInfo: account, ocId, serverUrl, status, progress, totalBytes, totalBytesExpected
  303. let notificationCenterCreateFolder = "createFolder" // userInfo: ocId, serverUrl, account, e2ee, withPush
  304. let notificationCenterDeleteFile = "deleteFile" // userInfo: ocId, fileNameView, serverUrl, account, classFile, onlyLocalCache
  305. let notificationCenterRenameFile = "renameFile" // userInfo: ocId, account
  306. let notificationCenterMoveFile = "moveFile" // userInfo: ocId, account, serverUrlFrom
  307. let notificationCenterCopyFile = "copyFile" // userInfo: ocId, serverUrlTo
  308. let notificationCenterFavoriteFile = "favoriteFile" // userInfo: ocId, serverUrl
  309. let notificationCenterMenuSearchTextPDF = "menuSearchTextPDF"
  310. let notificationCenterMenuGotToPageInPDF = "menuGotToPageInPDF"
  311. let notificationCenterMenuDetailClose = "menuDetailClose"
  312. let notificationCenterDownloadedThumbnail = "DownloadedThumbnail" // userInfo: ocId
  313. let notificationCenterHidePlayerToolBar = "hidePlayerToolBar" // userInfo: ocId
  314. let notificationCenterShowPlayerToolBar = "showPlayerToolBar" // userInfo: ocId, enableTimerAutoHide
  315. let notificationCenterOpenMediaDetail = "openMediaDetail" // userInfo: ocId
  316. let notificationCenterReloadMediaPage = "reloadMediaPage"
  317. let notificationCenterPlayMedia = "playMedia"
  318. let notificationCenterPauseMedia = "pauseMedia"
  319. let notificationCenterDismissScanDocument = "dismissScanDocument"
  320. let notificationCenterDismissUploadAssets = "dismissUploadAssets"
  321. // TIP
  322. //
  323. let tipNCViewerPDFThumbnail = "tipncviewerpdfthumbnail"
  324. let tipNCCollectionViewCommonAccountRequest = "tipnccollectionviewcommonaccountrequest"
  325. let tipNCScanAddImage = "tipncscanaddimage"
  326. let tipNCViewerMediaDetailView = "tipncviewermediadetailview"
  327. // ACTION
  328. //
  329. let actionNoAction = "no-action"
  330. let actionUploadAsset = "upload-asset"
  331. let actionScanDocument = "add-scan-document"
  332. let actionTextDocument = "create-text-document"
  333. let actionVoiceMemo = "create-voice-memo"
  334. // WIDGET ACTION
  335. //
  336. let widgetActionNoAction = "nextcloud://open-action?action=no-action"
  337. let widgetActionUploadAsset = "nextcloud://open-action?action=upload-asset"
  338. let widgetActionScanDocument = "nextcloud://open-action?action=add-scan-document"
  339. let widgetActionTextDocument = "nextcloud://open-action?action=create-text-document"
  340. let widgetActionVoiceMemo = "nextcloud://open-action?action=create-voice-memo"
  341. // APPCONFIG
  342. //
  343. let configuration_brand = "brand"
  344. let configuration_serverUrl = "serverUrl"
  345. let configuration_username = "username"
  346. let configuration_password = "password"
  347. let configuration_apppassword = "apppassword"
  348. let configuration_disable_intro = "disable_intro"
  349. let configuration_disable_multiaccount = "disable_multiaccount"
  350. let configuration_disable_crash_service = "disable_crash_service"
  351. let configuration_disable_log = "disable_log"
  352. let configuration_disable_manage_account = "disable_manage_account"
  353. let configuration_disable_more_external_site = "disable_more_external_site"
  354. let configuration_disable_openin_file = "disable_openin_file"
  355. }