145 lines
4.2 KiB
Text
145 lines
4.2 KiB
Text
import { Theme } from "../theme.slint";
|
|
import { Icons } from "../components/icon.slint";
|
|
import { Dialog } from "../components/dialog.slint";
|
|
import { ButtonKind } from "../components/button.slint";
|
|
import { TextField } from "../components/text-field.slint";
|
|
import { Chip } from "../components/chip.slint";
|
|
|
|
// A saved SFTP connection as the dialog edits it. The password is never part of it.
|
|
export struct ConnectionData {
|
|
name: string,
|
|
host: string,
|
|
port: string,
|
|
user: string,
|
|
folder: string,
|
|
// 0 automatic (agent, default keys, password), 1 key file, 2 password.
|
|
auth: int,
|
|
key-file: string,
|
|
// An existing connection: the dialog offers Remove.
|
|
editing: bool,
|
|
error: string,
|
|
}
|
|
|
|
// Adds or edits a connection. `saved` returns the reason it can't be saved, or an empty
|
|
// string; the dialog stays open on a reason and shows it under the host.
|
|
export component ConnectionDialog inherits Dialog {
|
|
in-out property <ConnectionData> data;
|
|
callback saved(ConnectionData) -> string;
|
|
callback removed();
|
|
|
|
glyph: Icons.cloud;
|
|
title: root.data.editing ? "Edit connection" : "New connection";
|
|
dialog-width: 520px;
|
|
content-focus: true;
|
|
actions: root.data.editing
|
|
? [{ text: "Cancel", kind: ButtonKind.text }, { text: "Remove", kind: ButtonKind.text }, { text: "Save", kind: ButtonKind.filled }]
|
|
: [{ text: "Cancel", kind: ButtonKind.text }, { text: "Save", kind: ButtonKind.filled }];
|
|
default-action: root.actions.length - 1;
|
|
cancel-action: 0;
|
|
focus-content => {
|
|
name-field.focus-input();
|
|
}
|
|
action(i) => {
|
|
if i == 0 {
|
|
self.close();
|
|
} else if root.data.editing && i == 1 {
|
|
self.close();
|
|
root.removed();
|
|
} else {
|
|
let reason = root.saved(root.data);
|
|
if reason == "" {
|
|
self.close();
|
|
} else {
|
|
root.data.error = reason;
|
|
}
|
|
}
|
|
}
|
|
|
|
name-field := TextField {
|
|
label: "Name";
|
|
placeholder: "Home server";
|
|
text <=> root.data.name;
|
|
}
|
|
|
|
HorizontalLayout {
|
|
spacing: Theme.space-3;
|
|
|
|
TextField {
|
|
horizontal-stretch: 1;
|
|
label: "Host";
|
|
placeholder: "name or address";
|
|
error: root.data.error;
|
|
text <=> root.data.host;
|
|
edited => {
|
|
root.data.error = "";
|
|
}
|
|
}
|
|
|
|
TextField {
|
|
width: 96px;
|
|
label: "Port";
|
|
placeholder: "22";
|
|
text <=> root.data.port;
|
|
}
|
|
}
|
|
|
|
HorizontalLayout {
|
|
spacing: Theme.space-3;
|
|
|
|
TextField {
|
|
horizontal-stretch: 1;
|
|
label: "User";
|
|
placeholder: "your name on the server";
|
|
text <=> root.data.user;
|
|
}
|
|
|
|
TextField {
|
|
horizontal-stretch: 1;
|
|
label: "Start folder";
|
|
placeholder: "home folder";
|
|
text <=> root.data.folder;
|
|
}
|
|
}
|
|
|
|
HorizontalLayout {
|
|
spacing: Theme.space-2;
|
|
alignment: start;
|
|
|
|
Text {
|
|
text: "Sign in with";
|
|
color: Theme.on-surface-variant;
|
|
font-size: Theme.body-small.size;
|
|
font-weight: Theme.body-small.weight;
|
|
vertical-alignment: center;
|
|
}
|
|
|
|
for name[i] in ["Automatic", "Key file", "Password"]: Chip {
|
|
property <bool> sel: i == root.data.auth;
|
|
|
|
text: name;
|
|
checked: self.sel;
|
|
changed sel => {
|
|
self.checked = self.sel;
|
|
}
|
|
clicked => {
|
|
root.data.auth = i;
|
|
self.checked = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if root.data.auth == 1: TextField {
|
|
label: "Key file";
|
|
placeholder: "~/.ssh/id_ed25519";
|
|
supporting: "The passphrase is asked when needed and never saved.";
|
|
text <=> root.data.key-file;
|
|
}
|
|
|
|
if root.data.auth != 1: Text {
|
|
text: root.data.auth == 0 ? "Uses your key agent and default keys, then asks for a password." : "Asks for the password each time it connects. It is never saved.";
|
|
color: Theme.on-surface-variant;
|
|
font-size: Theme.body-small.size;
|
|
font-weight: Theme.body-small.weight;
|
|
wrap: word-wrap;
|
|
}
|
|
}
|