NCSettingsAdvancedView.swift 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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.brandElement))
  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())
  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.brandElement))
  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.brandElement))
  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.brandElement))
  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.brandElement))
  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.brandElement))
  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. Section(content: {
  184. NavigationLink(destination: LazyView {
  185. NCCapabilitiesView(model: NCCapabilitiesModel())
  186. }) {
  187. HStack {
  188. Image(systemName: "list.bullet")
  189. .resizable()
  190. .scaledToFit()
  191. .font(Font.system(.body).weight(.light))
  192. .frame(width: 25, height: 25)
  193. .foregroundColor(Color(NCBrandColor.shared.iconImageColor))
  194. Text(NSLocalizedString("_capabilities_", comment: ""))
  195. }
  196. .font(.system(size: 16))
  197. }
  198. }, header: {
  199. Text(NSLocalizedString("_capabilities_", comment: ""))
  200. }, footer: {
  201. Text(NSLocalizedString("_capabilities_footer_", comment: ""))
  202. })
  203. }
  204. /// Delete in Cache & Clear Cache
  205. Section(content: {
  206. Picker(NSLocalizedString("_delete_old_files_", comment: ""), selection: $model.selectedInterval) {
  207. ForEach(CacheDeletionInterval.allCases) { interval in
  208. Text(interval.displayText).tag(interval)
  209. }
  210. }
  211. .font(.system(size: 16))
  212. .pickerStyle(.automatic)
  213. .onChange(of: model.selectedInterval) { _ in
  214. model.updateSelectedInterval()
  215. }
  216. Button(action: {
  217. showCacheAlert.toggle()
  218. }, label: {
  219. HStack {
  220. Image(systemName: "xmark")
  221. .resizable()
  222. .scaledToFit()
  223. .font(Font.system(.body).weight(.light))
  224. .frame(width: 15, height: 15)
  225. .foregroundColor(Color(NCBrandColor.shared.iconImageColor))
  226. Text(NSLocalizedString("_clear_cache_", comment: ""))
  227. }
  228. .font(.system(size: 16))
  229. })
  230. .tint(Color(UIColor.label))
  231. .alert(NSLocalizedString("_want_delete_cache_", comment: ""), isPresented: $showCacheAlert) {
  232. Button(NSLocalizedString("_yes_", comment: ""), role: .destructive) {
  233. model.clearCache()
  234. }
  235. Button(NSLocalizedString("_cancel_", comment: ""), role: .cancel) { }
  236. }
  237. }, header: {
  238. Text(NSLocalizedString("_delete_files_desc_", comment: ""))
  239. }, footer: {
  240. Text(model.footerTitle)
  241. .font(.system(size: 12))
  242. .multilineTextAlignment(.leading)
  243. })
  244. /// Reset Application
  245. Section(content: {
  246. Button(action: {
  247. showExitAlert.toggle()
  248. }, label: {
  249. HStack {
  250. Image(systemName: "xmark")
  251. .resizable()
  252. .scaledToFit()
  253. .font(Font.system(.body).weight(.light))
  254. .frame(width: 15, height: 15)
  255. .foregroundColor(Color(UIColor.systemRed))
  256. Text(NSLocalizedString("_exit_", comment: ""))
  257. .foregroundColor(Color(UIColor.systemRed))
  258. }
  259. .font(.system(size: 16))
  260. })
  261. .tint(Color(UIColor.label))
  262. .alert(NSLocalizedString("_want_exit_", comment: ""), isPresented: $showExitAlert) {
  263. Button(NSLocalizedString("_ok_", comment: ""), role: .destructive) {
  264. model.resetNextCloud(exit: showExitAlert)
  265. }
  266. Button(NSLocalizedString("_cancel_", comment: ""), role: .cancel) { }
  267. }
  268. }, footer: {
  269. (
  270. Text(NSLocalizedString("_exit_footer_", comment: ""))
  271. +
  272. Text("\n\n")
  273. )
  274. .font(.system(size: 12))
  275. .multilineTextAlignment(.leading)
  276. })
  277. }
  278. .navigationBarTitle(NSLocalizedString("_advanced_", comment: ""))
  279. .defaultViewModifier(model)
  280. }
  281. }
  282. #Preview {
  283. NCSettingsAdvancedView(model: NCSettingsAdvancedModel(controller: nil), showExitAlert: false, showCacheAlert: false)
  284. }