NCSettingsAdvancedView.swift 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. //
  2. // NCSettingsAdvancedView.swift
  3. // Nextcloud
  4. //
  5. // Created by Aditya Tyagi on 08/03/24.
  6. // Created by Marino Faggiana on 30/05/24.
  7. // Copyright © 2024 Marino Faggiana. All rights reserved.
  8. //
  9. // Author Aditya Tyagi <adityagi02@yahoo.com>
  10. //
  11. // This program is free software: you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published by
  13. // the Free Software Foundation, either version 3 of the License, or
  14. // (at your option) any later version.
  15. //
  16. // This program is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. // GNU General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU General Public License
  22. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. //
  24. import SwiftUI
  25. import NextcloudKit
  26. struct NCSettingsAdvancedView: View {
  27. @ObservedObject var model: NCSettingsAdvancedModel
  28. /// State variable for indicating whether the exit alert is shown.
  29. @State var showExitAlert: Bool = false
  30. /// State variable for indicating whether the cache alert is shown.
  31. @State var showCacheAlert: Bool = false
  32. /// State variable for indicating whether to disable crash reporter.
  33. @State var showCrashReporter: Bool = false
  34. var body: some View {
  35. Form {
  36. /// Show Hidden Files
  37. Section(content: {
  38. Toggle(NSLocalizedString("_show_hidden_files_", comment: ""), isOn: $model.showHiddenFiles)
  39. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  40. .onChange(of: model.showHiddenFiles) { _ in
  41. model.updateShowHiddenFiles()
  42. }
  43. .font(.system(size: 16))
  44. }, footer: { })
  45. /// file name
  46. Section(content: {
  47. NavigationLink(destination: LazyView {
  48. NCFileNameView(model: NCFileNameModel(controller: model.controller))
  49. }) {
  50. Text(NSLocalizedString("_filenamemask_", comment: ""))
  51. .font(.system(size: 16))
  52. }
  53. }, footer: {
  54. Text(NSLocalizedString("_filenamemask_footer_", comment: ""))
  55. })
  56. /// Most Compatible & Enable Live Photo
  57. Section(content: {
  58. Toggle(NSLocalizedString("_format_compatibility_", comment: ""), isOn: $model.mostCompatible)
  59. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  60. .onChange(of: model.mostCompatible) { _ in
  61. model.updateMostCompatible()
  62. }
  63. .font(.system(size: 16))
  64. Toggle(NSLocalizedString("_upload_mov_livephoto_", comment: ""), isOn: $model.livePhoto)
  65. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  66. .onChange(of: model.livePhoto) { _ in
  67. model.updateLivePhoto()
  68. }
  69. .font(.system(size: 16))
  70. }, footer: {
  71. (
  72. Text(NSLocalizedString("_format_compatibility_footer_", comment: ""))
  73. +
  74. Text(NSLocalizedString("_upload_mov_livephoto_footer_", comment: ""))
  75. ).font(.system(size: 12))
  76. .multilineTextAlignment(.leading)
  77. })
  78. /// Remove from Camera Roll
  79. Section(content: {
  80. Toggle(NSLocalizedString("_remove_photo_CameraRoll_", comment: ""), isOn: $model.removeFromCameraRoll)
  81. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  82. .onChange(of: model.removeFromCameraRoll) { _ in
  83. model.updateRemoveFromCameraRoll()
  84. }
  85. .font(.system(size: 16))
  86. }, footer: {
  87. Text(NSLocalizedString("_remove_photo_CameraRoll_desc_", comment: ""))
  88. .font(.system(size: 12))
  89. .multilineTextAlignment(.leading)
  90. })
  91. /// Section : Files App
  92. if !NCBrandOptions.shared.disable_openin_file {
  93. Section(content: {
  94. Toggle(NSLocalizedString("_disable_files_app_", comment: ""), isOn: $model.appIntegration)
  95. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  96. .onChange(of: model.appIntegration) { _ in
  97. model.updateAppIntegration()
  98. }
  99. .font(.system(size: 16))
  100. }, footer: {
  101. Text(NSLocalizedString("_disable_files_app_footer_", comment: ""))
  102. .font(.system(size: 12))
  103. .multilineTextAlignment(.leading)
  104. })
  105. }
  106. /// Section: Privacy
  107. if !NCBrandOptions.shared.disable_crash_service {
  108. Section(content: {
  109. Toggle(NSLocalizedString("_crashservice_title_", comment: ""), isOn: $model.crashReporter)
  110. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  111. .onChange(of: model.crashReporter) { _ in
  112. model.updateCrashReporter()
  113. showCrashReporter.toggle()
  114. }
  115. .font(.system(size: 16))
  116. .alert(NSLocalizedString("_crashservice_title_", comment: ""), isPresented: $showCrashReporter, actions: {
  117. Button(NSLocalizedString("OK", comment: ""), role: .cancel) {
  118. model.exitNextCloud(ext: showCrashReporter)
  119. }
  120. }, message: {
  121. Text(NSLocalizedString("_crashservice_alert_", comment: ""))
  122. })
  123. }, header: {
  124. Text(NSLocalizedString("_privacy_", comment: ""))
  125. }, footer: {
  126. Text(NSLocalizedString("_privacy_footer_", comment: ""))
  127. .font(.system(size: 12))
  128. .multilineTextAlignment(.leading)
  129. })
  130. }
  131. /// Section: Diagnostic LOG
  132. if !NCBrandOptions.shared.disable_log {
  133. Section(content: {
  134. /// View Log File
  135. Button(action: {
  136. model.viewLogFile()
  137. }, label: {
  138. HStack {
  139. Image(systemName: "doc.badge.gearshape")
  140. .resizable()
  141. .scaledToFit()
  142. .font(Font.system(.body).weight(.light))
  143. .frame(width: 25, height: 25)
  144. .foregroundColor(Color(NCBrandColor.shared.iconImageColor))
  145. Text(NSLocalizedString("_view_log_", comment: ""))
  146. }
  147. .font(.system(size: 16))
  148. })
  149. .tint(Color(UIColor.label))
  150. /// Set Log Level()
  151. Picker(NSLocalizedString("_set_log_level_", comment: ""), selection: $model.selectedLogLevel) {
  152. ForEach(LogLevel.allCases) { level in
  153. Text(level.displayText).tag(level)
  154. }
  155. }
  156. .font(.system(size: 16))
  157. .onChange(of: model.selectedLogLevel) { _ in
  158. model.updateSelectedLogLevel()
  159. }
  160. /// Clear Log File
  161. Button(action: {
  162. model.clearLogFile()
  163. }, label: {
  164. HStack {
  165. Image(systemName: "xmark")
  166. .resizable()
  167. .scaledToFit()
  168. .font(Font.system(.body).weight(.light))
  169. .frame(width: 25, height: 15)
  170. .foregroundColor(Color(NCBrandColor.shared.iconImageColor))
  171. Text(NSLocalizedString("_clear_log_", comment: ""))
  172. }
  173. .font(.system(size: 16))
  174. })
  175. .tint(Color(UIColor.label))
  176. .alert(NSLocalizedString("_log_file_clear_alert_", comment: ""), isPresented: $model.logFileCleared) {
  177. Button(NSLocalizedString("OK", comment: ""), role: .cancel) { }
  178. }
  179. }, header: {
  180. Text(NSLocalizedString("_diagnostics_", comment: ""))
  181. }, footer: { })
  182. /// Set Log Level() & Capabilities
  183. if model.isAdminGroup {
  184. Section(content: {
  185. NavigationLink(destination: LazyView {
  186. NCCapabilitiesView(model: NCCapabilitiesModel(controller: model.controller))
  187. }) {
  188. HStack {
  189. Image(systemName: "list.bullet")
  190. .resizable()
  191. .scaledToFit()
  192. .font(Font.system(.body).weight(.light))
  193. .frame(width: 25, height: 25)
  194. .foregroundColor(Color(NCBrandColor.shared.iconImageColor))
  195. Text(NSLocalizedString("_capabilities_", comment: ""))
  196. }
  197. .font(.system(size: 16))
  198. }
  199. }, header: {
  200. Text(NSLocalizedString("_capabilities_", comment: ""))
  201. }, footer: {
  202. Text(NSLocalizedString("_capabilities_footer_", comment: ""))
  203. })
  204. }
  205. }
  206. /// Delete in Cache & Clear Cache
  207. Section(content: {
  208. Picker(NSLocalizedString("_delete_old_files_", comment: ""), selection: $model.selectedInterval) {
  209. ForEach(CacheDeletionInterval.allCases) { interval in
  210. Text(interval.displayText).tag(interval)
  211. }
  212. }
  213. .font(.system(size: 16))
  214. .pickerStyle(.automatic)
  215. .onChange(of: model.selectedInterval) { _ in
  216. model.updateSelectedInterval()
  217. }
  218. Button(action: {
  219. showCacheAlert.toggle()
  220. }, label: {
  221. HStack {
  222. Image(systemName: "xmark")
  223. .resizable()
  224. .scaledToFit()
  225. .font(Font.system(.body).weight(.light))
  226. .frame(width: 15, height: 15)
  227. .foregroundColor(Color(NCBrandColor.shared.iconImageColor))
  228. Text(NSLocalizedString("_clear_cache_", comment: ""))
  229. }
  230. .font(.system(size: 16))
  231. })
  232. .tint(Color(UIColor.label))
  233. .alert(NSLocalizedString("_want_delete_cache_", comment: ""), isPresented: $showCacheAlert) {
  234. Button(NSLocalizedString("_yes_", comment: ""), role: .destructive) {
  235. model.clearCache()
  236. }
  237. Button(NSLocalizedString("_cancel_", comment: ""), role: .cancel) { }
  238. }
  239. }, header: {
  240. Text(NSLocalizedString("_delete_files_desc_", comment: ""))
  241. }, footer: {
  242. Text(model.footerTitle)
  243. .font(.system(size: 12))
  244. .multilineTextAlignment(.leading)
  245. })
  246. /// Reset Application
  247. Section(content: {
  248. Button(action: {
  249. showExitAlert.toggle()
  250. }, label: {
  251. HStack {
  252. Image(systemName: "xmark")
  253. .resizable()
  254. .scaledToFit()
  255. .font(Font.system(.body).weight(.light))
  256. .frame(width: 15, height: 15)
  257. .foregroundColor(Color(UIColor.systemRed))
  258. Text(NSLocalizedString("_exit_", comment: ""))
  259. .foregroundColor(Color(UIColor.systemRed))
  260. }
  261. .font(.system(size: 16))
  262. })
  263. .tint(Color(UIColor.label))
  264. .alert(NSLocalizedString("_want_exit_", comment: ""), isPresented: $showExitAlert) {
  265. Button(NSLocalizedString("_ok_", comment: ""), role: .destructive) {
  266. model.resetNextCloud()
  267. }
  268. Button(NSLocalizedString("_cancel_", comment: ""), role: .cancel) { }
  269. }
  270. }, footer: {
  271. (
  272. Text(NSLocalizedString("_exit_footer_", comment: ""))
  273. +
  274. Text("\n\n")
  275. )
  276. .font(.system(size: 12))
  277. .multilineTextAlignment(.leading)
  278. })
  279. }
  280. .navigationBarTitle(NSLocalizedString("_advanced_", comment: ""))
  281. .defaultViewModifier(model)
  282. }
  283. }
  284. #Preview {
  285. NCSettingsAdvancedView(model: NCSettingsAdvancedModel(controller: nil), showExitAlert: false, showCacheAlert: false)
  286. }