{vereina}/{vereinb} (= {home}/{away}, {heim}/{gast}), {homeshort}/{awayshort}, {competition}, {round},
{season} … aus dem Spieltag des Bildes oder aus dem IPTC-Ereignis („Liga: A - B“). Gilt für das
Immich-Album und das FTP-Umbenennungsmuster, z. B. „{vereina} - {vereinb} | {date}“.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
414 lines
22 KiB
Swift
414 lines
22 KiB
Swift
import SwiftUI
|
||
import LichtkastenCore
|
||
|
||
/// Own settings navigation (Apple's settings tab bar always uses the system accent color).
|
||
struct SettingsView: View {
|
||
enum Page: String, CaseIterable, Identifiable {
|
||
case general = "Allgemein", ftp = "FTP", check = "Agentur-Check", immich = "Immich", lightroom = "Lightroom", codes = "Codes"
|
||
var id: String { rawValue }
|
||
var icon: String {
|
||
switch self {
|
||
case .general: return "gearshape"
|
||
case .ftp: return "server.rack"
|
||
case .check: return "checkmark.shield"
|
||
case .immich: return "photo.stack"
|
||
case .lightroom: return "camera.aperture"
|
||
case .codes: return "character.textbox"
|
||
}
|
||
}
|
||
}
|
||
|
||
@AppStorage("settingsPage") private var page: Page = .general
|
||
|
||
var body: some View {
|
||
HStack(spacing: 0) {
|
||
VStack(alignment: .leading, spacing: 4) {
|
||
LKSectionLabel(title: "Einstellungen").padding(.horizontal, 10).padding(.bottom, 8)
|
||
ForEach(Page.allCases) { p in
|
||
let on = p == page
|
||
Button { page = p } label: {
|
||
HStack(spacing: 10) {
|
||
Image(systemName: p.icon).frame(width: 18)
|
||
Text(p.rawValue).font(.system(size: 13, weight: on ? .bold : .medium))
|
||
Spacer()
|
||
}
|
||
.foregroundStyle(on ? LK.amber : LK.text)
|
||
.padding(.horizontal, 10)
|
||
.frame(height: 32)
|
||
.background(RoundedRectangle(cornerRadius: 8).fill(on ? LK.selected : Color.clear))
|
||
.contentShape(Rectangle())
|
||
}
|
||
.buttonStyle(.plain)
|
||
}
|
||
Spacer()
|
||
}
|
||
.padding(14)
|
||
.frame(width: 190)
|
||
.background(LK.panel)
|
||
Rectangle().fill(LK.border).frame(width: 1)
|
||
Group {
|
||
switch page {
|
||
case .general: GeneralSettings()
|
||
case .ftp: FTPSettings()
|
||
case .check: PreflightSettings()
|
||
case .immich: ImmichSettingsView()
|
||
case .lightroom: LightroomSettingsView()
|
||
case .codes: CodesSettings()
|
||
}
|
||
}
|
||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||
}
|
||
.background(LK.ground)
|
||
.navigationTitle(page.rawValue)
|
||
}
|
||
}
|
||
|
||
struct GeneralSettings: View {
|
||
@EnvironmentObject var state: AppState
|
||
|
||
var body: some View {
|
||
Form {
|
||
Section("Tastatur") {
|
||
Picker("Belegung", selection: $state.settings.keyScheme) {
|
||
ForEach(KeyScheme.allCases, id: \.self) { Text($0.title).tag($0) }
|
||
}
|
||
Toggle("Nach Bewertung/Tag automatisch zum nächsten Bild", isOn: $state.settings.autoAdvance)
|
||
Text("1–8 = Farbklasse · 0 = keine · ⌥1–5 = Sterne · T = Tag · I = IPTC-Info · ⌘I = IPTC für Auswahl · ⌘U = Hochladen · ⌘E = Lightroom · ⌘⌥S = INPUT ⇄ SENT")
|
||
.font(.caption).foregroundStyle(.secondary)
|
||
}.lkRow()
|
||
Section("Zoom") {
|
||
Picker("Maximaler Zoom in der Vorschau", selection: $state.settings.maxZoom) {
|
||
Text("100 %").tag(1.0); Text("200 %").tag(2.0); Text("400 %").tag(4.0); Text("800 %").tag(8.0); Text("1600 %").tag(16.0)
|
||
}
|
||
Slider(value: $state.settings.maxThumbnailSize, in: 300...1200, step: 50) {
|
||
Text("Größte Vorschaubilder: \(Int(state.settings.maxThumbnailSize)) px")
|
||
}
|
||
Text("Vorschau: Z = Einpassen/100 %, + / − oder Trackpad zum Zoomen.").font(.caption).foregroundStyle(.secondary)
|
||
}.lkRow()
|
||
Section("Ansicht") {
|
||
Toggle("Matchday-Ansicht (Teamleiste, Spieler:innen-Liste, Teamfarben)", isOn: $state.settings.jersey.matchday)
|
||
if state.settings.jersey.matchday && state.settings.jersey.teams.count < 2 {
|
||
Text("Braucht zwei Teams in Bild → Trikot-Erkennung einrichten.").font(.caption).foregroundStyle(.secondary)
|
||
}
|
||
Toggle("IPTC-Panel neben der Vorschau", isOn: $state.settings.loupePanel)
|
||
}.lkRow()
|
||
Section("Ingest") {
|
||
Toggle("Ingest-Fenster öffnen, wenn eine Speicherkarte erkannt wird", isOn: $state.settings.autoIngestOnCardMount)
|
||
Toggle("Karte nach dem Ingest automatisch auswerfen", isOn: $state.settings.ingest.unmountAfter)
|
||
}.lkRow()
|
||
Section("exiftool") {
|
||
HStack {
|
||
TextField("Pfad (leer = automatisch)", text: $state.settings.exiftoolPath)
|
||
Button("Neu verbinden") { state.resetExifTool() }
|
||
}
|
||
if let url = ExifTool.locate(custom: state.settings.exiftoolPath) {
|
||
Label("Gefunden: \(url.path)", systemImage: "checkmark.circle.fill").foregroundStyle(.green)
|
||
} else {
|
||
Label("Nicht gefunden – Terminal: brew install exiftool", systemImage: "xmark.octagon.fill").foregroundStyle(.red)
|
||
}
|
||
}.lkRow()
|
||
Section("Variablen") {
|
||
TextField("Datumsformat für {date}", text: $state.settings.dateFormat)
|
||
Text("z. B. dd.MM.yyyy → 03.11.2026 · d. MMMM yyyy → 3. November 2026")
|
||
.font(.caption).foregroundStyle(.secondary)
|
||
}.lkRow()
|
||
}
|
||
.lkForm()
|
||
}
|
||
}
|
||
|
||
struct FTPSettings: View {
|
||
@EnvironmentObject var state: AppState
|
||
@State private var selected: UUID?
|
||
@State private var password = ""
|
||
@State private var testResult = ""
|
||
@State private var testing = false
|
||
|
||
private var index: Int? { state.settings.ftpDestinations.firstIndex { $0.id == selected } }
|
||
|
||
var body: some View {
|
||
HSplitView {
|
||
VStack(spacing: 0) {
|
||
List(selection: $selected) {
|
||
ForEach(state.settings.ftpDestinations) { d in Text(d.name).tag(d.id) }
|
||
}.scrollContentBackground(.hidden).background(LK.deep)
|
||
HStack {
|
||
Button { let d = FTPDestination(); state.settings.ftpDestinations.append(d); selected = d.id } label: { Image(systemName: "plus") }
|
||
Button {
|
||
// first leave the form (its bindings use the index), then remove by id – otherwise
|
||
// SwiftUI may still read the old index → "Index out of range"
|
||
guard let id = selected, let d = state.settings.ftpDestinations.first(where: { $0.id == id }) else { return }
|
||
selected = nil
|
||
DispatchQueue.main.async {
|
||
Keychain.set("", account: d.keychainAccount)
|
||
state.settings.ftpDestinations.removeAll { $0.id == id }
|
||
}
|
||
} label: { Image(systemName: "minus") }.disabled(index == nil)
|
||
Spacer()
|
||
}
|
||
.buttonStyle(.borderless).padding(6)
|
||
}
|
||
.frame(minWidth: 170, maxWidth: 220)
|
||
|
||
if let i = index {
|
||
Form {
|
||
Section("Server") {
|
||
TextField("Name", text: $state.settings.ftpDestinations[i].name)
|
||
Picker("Protokoll", selection: Binding(
|
||
get: { state.settings.ftpDestinations[i].proto },
|
||
set: { p in
|
||
state.settings.ftpDestinations[i].proto = p
|
||
state.settings.ftpDestinations[i].port = p.defaultPort
|
||
})) {
|
||
ForEach(FTPProtocol.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
||
}
|
||
TextField("Server", text: $state.settings.ftpDestinations[i].host)
|
||
TextField("Port", value: $state.settings.ftpDestinations[i].port, format: .number.grouping(.never))
|
||
TextField("Benutzer", text: $state.settings.ftpDestinations[i].username)
|
||
SecureField("Passwort (Schlüsselbund)", text: $password)
|
||
.onSubmit { Keychain.set(password, account: state.settings.ftpDestinations[i].keychainAccount) }
|
||
.onChange(of: password) { _, p in Keychain.set(p, account: state.settings.ftpDestinations[i].keychainAccount) }
|
||
if state.settings.ftpDestinations[i].proto == .sftp {
|
||
TextField("SSH-Schlüssel (optional)", text: $state.settings.ftpDestinations[i].sshKeyPath)
|
||
}
|
||
TextField("Zielordner", text: $state.settings.ftpDestinations[i].remoteDirectory)
|
||
Picker("Dateien", selection: $state.settings.ftpDestinations[i].variant) {
|
||
ForEach(UploadVariant.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
||
}
|
||
TextField("Umbenennen (leer = Originalname)", text: $state.settings.ftpDestinations[i].renamePattern)
|
||
Toggle("Passiver Modus", isOn: $state.settings.ftpDestinations[i].passive)
|
||
Toggle("Mit .part hochladen und danach umbenennen", isOn: $state.settings.ftpDestinations[i].uploadWithTempName)
|
||
Toggle("Vorhandene Datei auf dem Server ersetzen (wie PM)", isOn: $state.settings.ftpDestinations[i].replaceExisting)
|
||
.help("An: korrigierte Bilder können unter gleichem Namen erneut gesendet werden. Aus: Upload stoppt, wenn der Name schon existiert.")
|
||
Toggle("TLS-Zertifikat nicht prüfen (nur wenn nötig)", isOn: $state.settings.ftpDestinations[i].allowInsecureTLS)
|
||
HStack {
|
||
Button("Verbindung testen") { test(state.settings.ftpDestinations[i]) }.disabled(testing)
|
||
if testing { ProgressView().controlSize(.small) }
|
||
Text(testResult).font(.caption).lineLimit(3)
|
||
}
|
||
}.lkRow()
|
||
}
|
||
.lkForm()
|
||
.onAppear { password = Keychain.get(state.settings.ftpDestinations[i].keychainAccount) ?? "" }
|
||
.onChange(of: selected) { _, _ in
|
||
testResult = ""
|
||
if let i = index { password = Keychain.get(state.settings.ftpDestinations[i].keychainAccount) ?? "" }
|
||
}
|
||
} else {
|
||
Text("Server hinzufügen oder auswählen").foregroundStyle(.secondary).frame(maxWidth: .infinity, maxHeight: .infinity)
|
||
}
|
||
}
|
||
}
|
||
|
||
private func test(_ d: FTPDestination) {
|
||
testing = true
|
||
testResult = ""
|
||
Task {
|
||
do {
|
||
try await FTPUploader().testConnection(d, password: Keychain.get(d.keychainAccount))
|
||
testResult = "✅ Verbindung OK"
|
||
} catch { testResult = "❌ " + error.localizedDescription }
|
||
testing = false
|
||
}
|
||
}
|
||
}
|
||
|
||
struct ImmichSettingsView: View {
|
||
@EnvironmentObject var state: AppState
|
||
@State private var apiKey = ""
|
||
@State private var result = ""
|
||
|
||
var body: some View {
|
||
Form {
|
||
Section("Immich") {
|
||
Toggle("Immich-Upload aktivieren", isOn: $state.settings.immich.enabled)
|
||
TextField("Server-URL", text: $state.settings.immich.serverURL, prompt: Text("https://immich.example.de"))
|
||
SecureField("API-Schlüssel (Schlüsselbund)", text: $apiKey)
|
||
.onChange(of: apiKey) { _, k in Keychain.set(k, account: ImmichSettings.keychainAccount); state.uploads.resetImmich() }
|
||
TextField("Album", text: $state.settings.immich.albumName, prompt: Text("{event}"))
|
||
TextField("Album, wenn kein Ereignis im IPTC", text: $state.settings.immich.albumFallback, prompt: Text("{isodate} {city}"))
|
||
Text("Variablen aus IPTC/EXIF pro Bild, z. B. {event}, {headline}, {city}, {sublocation}, {isodate}, {date}, {year4}, {creator}. Vereine: {vereina} - {vereinb} (= {home}/{away}, kurz {homeshort}/{awayshort}), dazu {competition}, {round}, {season} – aus dem Spieltag oder dem Ereignis. Beispiel: {vereina} - {vereinb} | {date}. Fehlende Alben werden angelegt, leer = kein Album.")
|
||
.font(.caption).foregroundStyle(.secondary)
|
||
if let first = state.selectedItems.first {
|
||
LabeledContent("Beispiel (\(first.filename))", value: state.immichAlbum(for: first).isEmpty ? "– kein Album –" : state.immichAlbum(for: first))
|
||
.font(.caption)
|
||
}
|
||
Picker("Dateien", selection: $state.settings.immich.variant) {
|
||
ForEach(UploadVariant.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
||
}
|
||
HStack {
|
||
Button("Verbindung testen") { test() }
|
||
Text(result).font(.caption)
|
||
}
|
||
Text("API-Schlüssel in Immich: Konto-Einstellungen → API-Schlüssel. Benötigte Rechte: asset.upload, album.read, album.create, albumAsset.create.")
|
||
.font(.caption).foregroundStyle(.secondary)
|
||
}.lkRow()
|
||
}
|
||
.lkForm()
|
||
.onAppear { apiKey = Keychain.get(ImmichSettings.keychainAccount) ?? "" }
|
||
.onChange(of: state.settings.immich) { _, _ in state.uploads.resetImmich() }
|
||
}
|
||
|
||
private func test() {
|
||
result = "…"
|
||
Task {
|
||
do {
|
||
let c = try ImmichClient(settings: state.settings.immich, apiKey: apiKey)
|
||
result = "✅ Angemeldet als \(try await c.testConnection())"
|
||
} catch { result = "❌ " + error.localizedDescription }
|
||
}
|
||
}
|
||
}
|
||
|
||
struct LightroomSettingsView: View {
|
||
@EnvironmentObject var state: AppState
|
||
@State private var pluginMessage = ""
|
||
|
||
var body: some View {
|
||
Form {
|
||
Section("Lichtkasten-Bridge-Plugin") {
|
||
HStack {
|
||
if LightroomBridge.pluginIsAlive {
|
||
Label("Plugin aktiv (Lightroom läuft)", systemImage: "checkmark.circle.fill").foregroundStyle(.green)
|
||
} else if LightroomBridge.pluginInstalled {
|
||
Label("Installiert – Lightroom starten", systemImage: "pause.circle").foregroundStyle(.orange)
|
||
} else {
|
||
Label("Nicht installiert", systemImage: "xmark.circle").foregroundStyle(.red)
|
||
}
|
||
Spacer()
|
||
Button(LightroomBridge.pluginInstalled ? "Neu installieren" : "Plugin installieren") { install() }
|
||
}
|
||
if !pluginMessage.isEmpty { Text(pluginMessage).font(.caption) }
|
||
Text("Ohne Plugin öffnet ⌘⇧L den normalen Importdialog von Lightroom.")
|
||
.font(.caption).foregroundStyle(.secondary)
|
||
}.lkRow()
|
||
Section("Import") {
|
||
TextField("Entwicklungsvorgabe (exakter Name, optional „Ordner/Name“)", text: $state.settings.lightroom.developPreset)
|
||
TextField("Sammlung (leer = keine)", text: $state.settings.lightroom.collection)
|
||
}.lkRow()
|
||
Section("Bearbeiten (⌘E)") {
|
||
Toggle("Entwicklungsvorgabe auch bei ⌘E anwenden", isOn: $state.settings.lightroom.presetOnEdit)
|
||
Text("⌘E importiert die Auswahl in den offenen Katalog und öffnet das Entwickeln-Modul.")
|
||
.font(.caption).foregroundStyle(.secondary)
|
||
}.lkRow()
|
||
Section("JPEG-Export (⌘⌥L) → SENT") {
|
||
Picker("Exportziel", selection: $state.settings.lightroom.exportTarget) {
|
||
ForEach(ExportTarget.allCases, id: \.self) { Text($0.title).tag($0) }
|
||
}
|
||
TextField("Name des SENT-Ordners", text: $state.settings.lightroom.sentFolderName)
|
||
if state.settings.lightroom.exportTarget == .fixed {
|
||
HStack {
|
||
TextField("Fester Exportordner", text: $state.settings.lightroom.exportFolder)
|
||
Button("Wählen …") {
|
||
let p = NSOpenPanel(); p.canChooseDirectories = true; p.canChooseFiles = false; p.canCreateDirectories = true
|
||
if p.runModal() == .OK, let u = p.url { state.settings.lightroom.exportFolder = u.path }
|
||
}
|
||
}
|
||
}
|
||
Toggle("Nach dem Export den SENT-Ordner öffnen (zum Beschriften)", isOn: $state.settings.lightroom.openSentAfterExport)
|
||
Stepper("JPEG-Qualität: \(state.settings.lightroom.jpegQuality)", value: $state.settings.lightroom.jpegQuality, in: 50...100, step: 5)
|
||
TextField("Lange Kante in px (0 = volle Größe)", value: $state.settings.lightroom.longEdge, format: .number.grouping(.never))
|
||
Picker("Ausgabeschärfung", selection: $state.settings.lightroom.sharpening) {
|
||
Text("Keine").tag("none"); Text("Bildschirm").tag("screen"); Text("Matt").tag("matte"); Text("Glanz").tag("glossy")
|
||
}
|
||
Picker("Farbraum", selection: $state.settings.lightroom.colorSpace) {
|
||
Text("sRGB").tag("sRGB"); Text("Adobe RGB").tag("AdobeRGB")
|
||
}
|
||
Toggle("Original-IPTC nach Export erneut schreiben (PM-identischer Aufbau)", isOn: $state.settings.lightroom.rewriteIPTCAfterExport)
|
||
}.lkRow()
|
||
Section("Nach dem Export automatisch hochladen") {
|
||
ForEach(state.settings.ftpDestinations) { d in
|
||
Toggle("FTP: \(d.name)", isOn: uploadBinding(d.id.uuidString))
|
||
}
|
||
Toggle("Immich", isOn: uploadBinding("immich")).disabled(!state.settings.immich.enabled)
|
||
}.lkRow()
|
||
}
|
||
.lkForm()
|
||
}
|
||
|
||
private func uploadBinding(_ id: String) -> Binding<Bool> {
|
||
Binding(get: { state.settings.lightroom.autoUploadTargets.contains(id) },
|
||
set: { on in
|
||
state.settings.lightroom.autoUploadTargets.removeAll { $0 == id }
|
||
if on { state.settings.lightroom.autoUploadTargets.append(id) }
|
||
})
|
||
}
|
||
|
||
private func install() {
|
||
guard let bundle = Bundle.main.url(forResource: "LichtkastenBridge", withExtension: "lrplugin") else {
|
||
pluginMessage = "Plugin nicht im App-Bundle gefunden. Bitte LightroomPlugin/LichtkastenBridge.lrplugin über Lightroom → Zusatzmodul-Manager hinzufügen."
|
||
return
|
||
}
|
||
do {
|
||
try LightroomBridge.installPlugin(from: bundle)
|
||
pluginMessage = "Installiert. Lightroom Classic bitte neu starten."
|
||
} catch { pluginMessage = error.localizedDescription }
|
||
}
|
||
}
|
||
|
||
struct CodesSettings: View {
|
||
@EnvironmentObject var state: AppState
|
||
|
||
var body: some View {
|
||
Form {
|
||
Section("Code-Ersetzung") {
|
||
Text("\(state.codeLibrary.sets.filter(\.enabled).count) von \(state.codeLibrary.sets.count) Teams aktiv · \(state.codes.table.count) Codes")
|
||
Button("Code-Ersetzungen öffnen … (⌘⇧K)") { state.openWindow("codes") }
|
||
}.lkRow()
|
||
}
|
||
.lkForm()
|
||
}
|
||
}
|
||
|
||
/// Agentur-Check rules (applied before uploads to FTP servers with the check switched on).
|
||
struct PreflightSettings: View {
|
||
@EnvironmentObject var state: AppState
|
||
|
||
/// fields offered as "Pflichtfeld"
|
||
private static let candidates = ["caption", "headline", "creator", "copyright", "credit", "source", "event",
|
||
"city", "sublocation", "state", "country", "countryCode", "dateCreated",
|
||
"keywords", "objectName", "captionWriter",
|
||
// "Locations Taken and Shown" (many agencies require it)
|
||
"lcSublocation", "lcCity", "lcState", "lcCountry", "lcCountryCode", "lcWorldRegion"]
|
||
|
||
private var opts: Binding<PreflightOptions> { $state.settings.preflight }
|
||
|
||
var body: some View {
|
||
Form {
|
||
Section("Pflichtfelder (Fehler, wenn leer)") {
|
||
LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())], alignment: .leading, spacing: 8) {
|
||
ForEach(Self.candidates, id: \.self) { id in
|
||
if let f = IPTCField.byID[id] {
|
||
Toggle(f.section == .locationCreated ? "\(f.label) (Aufnahmeort)" : f.label, isOn: Binding(
|
||
get: { state.settings.preflight.requiredFields.contains(id) },
|
||
set: { on in
|
||
state.settings.preflight.requiredFields.removeAll { $0 == id }
|
||
if on { state.settings.preflight.requiredFields.append(id) }
|
||
}))
|
||
.toggleStyle(.checkbox)
|
||
}
|
||
}
|
||
}
|
||
}.lkRow()
|
||
Section("Weitere Prüfungen (Hinweise)") {
|
||
Toggle("Erste Zeile der Beschreibung leer (Person vergessen?)", isOn: opts.warnEmptyFirstLine)
|
||
Toggle("Datum in Überschrift/Beschreibung passt nicht zum Aufnahmedatum (alte Vorlage?)", isOn: opts.checkDates)
|
||
Toggle("Felder länger als das IPTC-Limit (Agentur kürzt)", isOn: opts.checkLengths)
|
||
Toggle("Offene Spieler-Vorschläge (Trikotnummern)", isOn: opts.checkOpenSuggestions)
|
||
Text("Immer geprüft: nicht ersetzte Variablen wie {city} und Codes wie .w10. – das sind Fehler.")
|
||
.font(.caption).foregroundStyle(.secondary)
|
||
}.lkRow()
|
||
Section("Bildgröße") {
|
||
TextField("Mindestens lange Kante in px (0 = aus)", value: opts.minLongEdge, format: .number.grouping(.never))
|
||
}.lkRow()
|
||
Section("Pro Server") {
|
||
ForEach(state.settings.ftpDestinations.indices, id: \.self) { i in
|
||
Toggle("Agentur-Check für „\(state.settings.ftpDestinations[i].name)“", isOn: $state.settings.ftpDestinations[i].preflight)
|
||
}
|
||
Text("Immich wird nicht geprüft (persönliches Archiv).").font(.caption).foregroundStyle(.secondary)
|
||
}.lkRow()
|
||
}
|
||
.lkForm()
|
||
}
|
||
}
|