NCGlobal.swift 21 KB

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