Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
199 lines
8.0 KiB
Swift
199 lines
8.0 KiB
Swift
import SwiftUI
|
|
import LichtkastenCore
|
|
|
|
struct ContentView: View {
|
|
@EnvironmentObject var state: AppState
|
|
@EnvironmentObject var uploads: UploadQueue
|
|
@State private var keyboard = KeyboardMonitor()
|
|
|
|
var body: some View {
|
|
NavigationSplitView {
|
|
SidebarView()
|
|
.navigationSplitViewColumnWidth(min: 180, ideal: 220)
|
|
} detail: {
|
|
VStack(spacing: 0) {
|
|
if state.folder == nil {
|
|
EmptyStateView()
|
|
} else if state.previewMode {
|
|
PreviewView()
|
|
} else {
|
|
ContactSheetView()
|
|
}
|
|
StatusBar()
|
|
}
|
|
.inspector(isPresented: $state.showInspector) {
|
|
IPTCInspectorView()
|
|
.inspectorColumnWidth(min: 300, ideal: 360, max: 520)
|
|
}
|
|
}
|
|
.navigationTitle(state.folder?.lastPathComponent ?? "Lichtkasten")
|
|
.toolbar { MainToolbar() }
|
|
.searchable(text: $state.searchText, placement: .toolbar, prompt: "Dateiname, IPTC …")
|
|
.onAppear { keyboard.install(state: state) }
|
|
.sheet(isPresented: $state.showTemplatePicker) { TemplatePickerSheet() }
|
|
.sheet(isPresented: $state.showTemplateManager) { TemplateManagerView().frame(minWidth: 900, minHeight: 620) }
|
|
.sheet(isPresented: $state.showIngest) { IngestView() }
|
|
.sheet(isPresented: $state.showUploads) { UploadsView() }
|
|
.alert(item: $state.alert) { a in
|
|
Alert(title: Text(a.title), message: Text(a.message), dismissButton: .default(Text("OK")))
|
|
}
|
|
}
|
|
}
|
|
|
|
struct EmptyStateView: View {
|
|
@EnvironmentObject var state: AppState
|
|
var body: some View {
|
|
VStack(spacing: 16) {
|
|
Image(systemName: "photo.on.rectangle.angled").font(.system(size: 56)).foregroundStyle(.secondary)
|
|
Text("Ordner öffnen oder Karte ingesten").font(.title2)
|
|
HStack {
|
|
Button("Ordner öffnen … (⌘O)") { state.chooseFolder() }
|
|
Button("Ingest … (⌘G)") { state.showIngest = true }
|
|
}
|
|
.controlSize(.large)
|
|
}
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
}
|
|
}
|
|
|
|
struct MainToolbar: ToolbarContent {
|
|
@EnvironmentObject var state: AppState
|
|
@EnvironmentObject var uploads: UploadQueue
|
|
|
|
var body: some ToolbarContent {
|
|
ToolbarItemGroup(placement: .navigation) {
|
|
Button { state.chooseFolder() } label: { Label("Öffnen", systemImage: "folder") }
|
|
}
|
|
ToolbarItemGroup(placement: .primaryAction) {
|
|
Picker("Filter", selection: $state.filter) {
|
|
Text("Alle").tag(ItemFilter.all)
|
|
Text("Getaggt").tag(ItemFilter.tagged)
|
|
Text("Nicht getaggt").tag(ItemFilter.untagged)
|
|
Divider()
|
|
ForEach(1...5, id: \.self) { n in Text("≥ \(n) ★").tag(ItemFilter.minRating(n)) }
|
|
Divider()
|
|
ForEach(ColorLabel.allCases, id: \.self) { l in Text(l.germanName).tag(ItemFilter.label(l)) }
|
|
}
|
|
.frame(width: 130)
|
|
.help("Filter")
|
|
|
|
Picker("Sortierung", selection: $state.sortOrder) {
|
|
ForEach(SortOrder.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
|
}
|
|
.frame(width: 130)
|
|
|
|
Slider(value: $state.settings.thumbnailSize, in: 110...420)
|
|
.frame(width: 110)
|
|
.help("Vorschaugröße")
|
|
|
|
Button { state.showTemplatePicker = true } label: { Label("Vorlage", systemImage: "text.badge.plus") }
|
|
.help("IPTC-Vorlage anwenden (⌘⇧I)")
|
|
|
|
Menu {
|
|
Button("Nur importieren (⌘⇧L)") { state.sendToLightroom(export: false) }
|
|
Button("Importieren + Vorgabe + JPEG (⌘⌥L)") { state.sendToLightroom(export: true) }
|
|
} label: {
|
|
Label("Lightroom", systemImage: "square.and.arrow.up.on.square")
|
|
} primaryAction: {
|
|
state.sendToLightroom(export: false)
|
|
}
|
|
.help("Auswahl an Lightroom Classic senden")
|
|
|
|
Menu {
|
|
ForEach(state.settings.ftpDestinations) { d in
|
|
Button("FTP: \(d.name)") { state.upload(to: d.id.uuidString) }
|
|
}
|
|
if state.settings.immich.enabled {
|
|
Button("Immich") { state.upload(to: "immich") }
|
|
}
|
|
Divider()
|
|
Button("Warteschlange anzeigen …") { state.showUploads = true }
|
|
} label: {
|
|
Label(uploads.activeCount > 0 ? "Upload (\(uploads.activeCount))" : "Upload", systemImage: "icloud.and.arrow.up")
|
|
}
|
|
|
|
Button { state.showInspector.toggle() } label: { Label("IPTC", systemImage: "sidebar.right") }
|
|
}
|
|
}
|
|
}
|
|
|
|
struct StatusBar: View {
|
|
@EnvironmentObject var state: AppState
|
|
@EnvironmentObject var uploads: UploadQueue
|
|
|
|
var body: some View {
|
|
HStack(spacing: 12) {
|
|
if state.loadingMetadata { ProgressView().controlSize(.small) }
|
|
Text(state.statusText).lineLimit(1)
|
|
Spacer()
|
|
if state.lrPendingCount > 0 {
|
|
Label("LR: \(state.lrPendingCount) Auftrag/Aufträge", systemImage: "hourglass")
|
|
}
|
|
if uploads.activeCount > 0 {
|
|
Label("\(uploads.activeCount) Uploads", systemImage: "arrow.up.circle")
|
|
.onTapGesture { state.showUploads = true }
|
|
}
|
|
if uploads.failedCount > 0 {
|
|
Label("\(uploads.failedCount) fehlgeschlagen", systemImage: "exclamationmark.triangle.fill")
|
|
.foregroundStyle(.red)
|
|
.onTapGesture { state.showUploads = true }
|
|
}
|
|
Text("\(state.selection.count) / \(state.visible.count) ausgewählt")
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
.font(.callout)
|
|
.padding(.horizontal, 10)
|
|
.padding(.vertical, 5)
|
|
.background(.bar)
|
|
}
|
|
}
|
|
|
|
struct SidebarView: View {
|
|
@EnvironmentObject var state: AppState
|
|
|
|
var body: some View {
|
|
List {
|
|
Section("Favoriten") {
|
|
ForEach(state.settings.favoriteFolders, id: \.self) { path in
|
|
folderRow(path)
|
|
.contextMenu { Button("Aus Favoriten entfernen") { state.settings.favoriteFolders.removeAll { $0 == path } } }
|
|
}
|
|
if let f = state.folder, !state.settings.favoriteFolders.contains(f.path) {
|
|
Button { state.settings.favoriteFolders.append(f.path) } label: {
|
|
Label("Aktuellen Ordner merken", systemImage: "star")
|
|
}
|
|
.buttonStyle(.borderless)
|
|
}
|
|
}
|
|
Section("Zuletzt") {
|
|
ForEach(state.settings.recentFolders, id: \.self) { folderRow($0) }
|
|
}
|
|
Section("Wechseldatenträger") {
|
|
ForEach(volumes(), id: \.self) { v in
|
|
Button { state.showIngest = true } label: { Label(v.lastPathComponent, systemImage: "sdcard") }
|
|
.buttonStyle(.borderless)
|
|
}
|
|
}
|
|
}
|
|
.listStyle(.sidebar)
|
|
}
|
|
|
|
private func folderRow(_ path: String) -> some View {
|
|
let url = URL(fileURLWithPath: path)
|
|
return Button { state.open(folder: url) } label: {
|
|
Label(url.lastPathComponent, systemImage: state.folder?.path == path ? "folder.fill" : "folder")
|
|
}
|
|
.buttonStyle(.borderless)
|
|
.help(path)
|
|
}
|
|
|
|
private func volumes() -> [URL] {
|
|
let keys: [URLResourceKey] = [.volumeIsRemovableKey]
|
|
let vols = FileManager.default.mountedVolumeURLs(includingResourceValuesForKeys: keys, options: [.skipHiddenVolumes]) ?? []
|
|
return vols.filter { v in
|
|
(try? v.resourceValues(forKeys: Set(keys)).volumeIsRemovable) == true
|
|
|| FileManager.default.fileExists(atPath: v.appendingPathComponent("DCIM").path)
|
|
}
|
|
}
|
|
}
|