123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- //
- // Copyright © 2020 osy. All rights reserved.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- //
- import SwiftUI
- @available(iOS 14, *)
- struct VMSettingsView: View {
- let vm: UTMVirtualMachine?
- @ObservedObject var config: UTMConfiguration
-
- @EnvironmentObject private var data: UTMData
- @Environment(\.presentationMode) private var presentationMode: Binding<PresentationMode>
-
- var qemuConfig: UTMQemuConfiguration {
- config as! UTMQemuConfiguration
- }
-
- var body: some View {
- NavigationView {
- Form {
- List {
- NavigationLink(
- destination: VMConfigInfoView(config: qemuConfig).navigationTitle("Information"),
- label: {
- Label("Information", systemImage: "info.circle")
- .labelStyle(RoundRectIconLabelStyle())
- })
- NavigationLink(
- destination: VMConfigSystemView(config: qemuConfig).navigationTitle("System"),
- label: {
- Label("System", systemImage: "cpu")
- .labelStyle(RoundRectIconLabelStyle())
- })
- NavigationLink(
- destination: VMConfigQEMUView(config: qemuConfig).navigationTitle("QEMU"),
- label: {
- Label("QEMU", systemImage: "shippingbox")
- .labelStyle(RoundRectIconLabelStyle())
- })
- NavigationLink(
- destination: VMConfigDrivesView(config: qemuConfig).navigationTitle("Drives"),
- label: {
- Label("Drives", systemImage: "internaldrive")
- .labelStyle(RoundRectIconLabelStyle())
- })
- NavigationLink(
- destination: VMConfigDisplayView(config: qemuConfig).navigationTitle("Display"),
- label: {
- Label("Display", systemImage: "rectangle.on.rectangle")
- .labelStyle(RoundRectIconLabelStyle(color: .green))
- })
- NavigationLink(
- destination: VMConfigInputView(config: qemuConfig).navigationTitle("Input"),
- label: {
- Label("Input", systemImage: "keyboard")
- .labelStyle(RoundRectIconLabelStyle(color: .green))
- })
- NavigationLink(
- destination: VMConfigNetworkView(config: qemuConfig).navigationTitle("Network"),
- label: {
- Label("Network", systemImage: "network")
- .labelStyle(RoundRectIconLabelStyle(color: .green))
- })
- NavigationLink(
- destination: VMConfigSoundView(config: qemuConfig).navigationTitle("Sound"),
- label: {
- Label("Sound", systemImage: "speaker.wave.2")
- .labelStyle(RoundRectIconLabelStyle(color: .green))
- })
- NavigationLink(
- destination: VMConfigSharingView(config: qemuConfig).navigationTitle("Sharing"),
- label: {
- Label("Sharing", systemImage: "person.crop.circle.fill")
- .labelStyle(RoundRectIconLabelStyle(color: .yellow))
- })
- }
- }
- .navigationTitle("Settings")
- .navigationViewStyle(StackNavigationViewStyle())
- .navigationBarItems(leading: Button(action: cancel, label: {
- Text("Cancel")
- }), trailing: HStack {
- Button(action: save, label: {
- Text("Save")
- })
- })
- }.disabled(data.busy)
- .overlay(BusyOverlay())
- }
-
- func save() {
- presentationMode.wrappedValue.dismiss()
- data.busyWork {
- if let existing = self.vm {
- try data.save(vm: existing)
- } else {
- try data.create(config: self.config)
- }
- }
- }
-
- func cancel() {
- presentationMode.wrappedValue.dismiss()
- if let existing = self.vm {
- data.busyWork {
- try data.discardChanges(forVM: existing)
- }
- }
- }
- }
- @available(iOS 14, *)
- struct RoundRectIconLabelStyle: LabelStyle {
- var color: Color = .blue
-
- func makeBody(configuration: Configuration) -> some View {
- Label(
- title: { configuration.title },
- icon: {
- ZStack(alignment: .center) {
- RoundedRectangle(cornerRadius: 10.0, style: .circular)
- .frame(width: 32, height: 32)
- .foregroundColor(color)
- configuration.icon.foregroundColor(.white)
- }
- })
- }
- }
- @available(iOS 14, *)
- struct VMSettingsView_Previews: PreviewProvider {
- @State static private var config = UTMQemuConfiguration()
-
- static var previews: some View {
- VMSettingsView(vm: nil, config: config)
- }
- }
|