NCGlobal.swift 21 KB

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