import { Button, LineEdit, ListView, ComboBox, AboutSlint, VerticalBox, HorizontalBox, ScrollView } from "std-widgets.slint"; export struct ServerItem { id: int, name: string, address: string, // "offline", "connecting", "observing" or "connected" status: string, } export struct TreeItem { is-channel: bool, depth: int, id: int, name: string, own: bool, talking: bool, muted: bool, sound-off: bool, away: bool, streaming: bool, locked: bool, collapsed: bool, } export struct ChatTab { title: string, // 0 = server chat, 1 = channel chat kind: int, id: int, unread: int, } export struct ChatLine { author: string, text: string, time: string, relayed: bool, } export struct BookmarkForm { id: int, name: string, address: string, nickname: string, server-password: string, gateway-url: string, query-transport: string, query-addr: string, query-user: string, query-password: string, } export global Bridge { in property <[ServerItem]> servers; in-out property current-server: -1; in property <[TreeItem]> tree; in property <[ChatTab]> tabs; in-out property current-tab: 0; in property <[ChatLine]> messages; in property status-text; in property server-title: "No server selected"; in property voice-connected; in property voice-connecting; in property observing; in property can-observe; in property input-muted; in property output-muted; in property transmitting; in property presence-source; callback select-server(int); callback connect-voice(); callback disconnect-voice(); callback toggle-observe(); callback join-channel(int); callback open-channel-chat(int); callback toggle-collapse(int); callback select-tab(int); callback close-tab(int); callback send-message(string); callback set-input-muted(bool); callback set-output-muted(bool); callback push-to-talk(bool); callback edit-bookmark(int) -> BookmarkForm; callback save-bookmark(BookmarkForm); callback delete-bookmark(int); } component StatusDot inherits Rectangle { in property status; width: 10px; height: 10px; border-radius: 5px; background: status == "connected" ? #3fb950 : status == "observing" ? #58a6ff : status == "connecting" ? #d29922 : #6e7681; } component Field inherits HorizontalLayout { in property label; in-out property value; in property placeholder; in property input-type: InputType.text; spacing: 8px; Text { text: label; width: 130px; vertical-alignment: center; } LineEdit { text <=> value; placeholder-text: placeholder; input-type: input-type; } } component BookmarkEditor inherits Rectangle { in-out property form; callback done(); background: #000000a0; TouchArea { } Rectangle { width: min(parent.width - 32px, 520px); height: min(parent.height - 32px, 520px); background: #1f2328; border-radius: 8px; VerticalBox { Text { text: form.id < 0 ? "Add server" : "Edit server"; font-size: 18px; font-weight: 700; } ScrollView { VerticalLayout { spacing: 6px; Field { label: "Name"; value <=> form.name; placeholder: "My server"; } Field { label: "Address"; value <=> form.address; placeholder: "ts.example.org:9987"; } Field { label: "Nickname"; value <=> form.nickname; } Field { label: "Server password"; value <=> form.server-password; input-type: InputType.password; } Text { text: "Invisible presence and chat without joining (optional)"; font-weight: 600; } Field { label: "Gateway URL"; value <=> form.gateway-url; placeholder: "wss://gw.example.org/v1"; } HorizontalLayout { spacing: 8px; Text { text: "Query transport"; width: 130px; vertical-alignment: center; } ComboBox { model: ["none", "ssh", "raw", "http"]; current-value <=> form.query-transport; } } Field { label: "Query address"; value <=> form.query-addr; placeholder: "ts.example.org:10022"; } Field { label: "Query login"; value <=> form.query-user; } Field { label: "Query password"; value <=> form.query-password; input-type: InputType.password; } } } HorizontalLayout { alignment: end; spacing: 8px; if form.id >= 0: Button { text: "Delete"; clicked => { Bridge.delete-bookmark(form.id); done(); } } Button { text: "Cancel"; clicked => { done(); } } Button { text: "Save"; primary: true; enabled: form.address != "" && form.nickname != ""; clicked => { Bridge.save-bookmark(form); done(); } } } } } } component ServerList inherits Rectangle { callback add(); callback edit(int); background: #161b22; VerticalBox { HorizontalLayout { Text { text: "Servers"; font-weight: 700; vertical-alignment: center; } Button { text: "+"; width: 32px; clicked => { add(); } } } ListView { for server[i] in Bridge.servers: Rectangle { height: 48px; border-radius: 6px; background: Bridge.current-server == server.id ? #30363d : area.has-hover ? #21262d : transparent; area := TouchArea { clicked => { Bridge.select-server(server.id); } double-clicked => { edit(server.id); } } HorizontalLayout { padding: 6px; spacing: 8px; StatusDot { status: server.status; y: (parent.height - self.height) / 2; } VerticalLayout { Text { text: server.name; font-weight: 600; overflow: elide; } Text { text: server.address; font-size: 11px; color: #8b949e; overflow: elide; } } } } } } } component ChannelTree inherits Rectangle { background: #0d1117; ListView { for row in Bridge.tree: Rectangle { height: 26px; background: row-area.has-hover ? #161b22 : transparent; row-area := TouchArea { double-clicked => { if (row.is-channel) { Bridge.join-channel(row.id); } } clicked => { if (row.is-channel) { Bridge.open-channel-chat(row.id); } } } HorizontalLayout { padding-left: 8px + row.depth * 18px; padding-right: 8px; spacing: 6px; if row.is-channel: Text { text: row.collapsed ? "▸" : "▾"; vertical-alignment: center; TouchArea { clicked => { Bridge.toggle-collapse(row.id); } } } if !row.is-channel: Rectangle { width: 10px; height: 10px; y: (parent.height - self.height) / 2; border-radius: 5px; background: row.talking ? #3fb950 : #30363d; } Text { text: (row.is-channel ? "# " : "") + row.name; horizontal-stretch: 1; horizontal-alignment: left; vertical-alignment: center; font-weight: row.is-channel || row.own ? 600 : 400; color: row.away ? #8b949e : row.own ? #58a6ff : #e6edf3; overflow: elide; } if row.locked: Text { text: "password"; font-size: 10px; color: #d29922; vertical-alignment: center; } if row.muted: Text { text: "mic off"; font-size: 10px; color: #f85149; vertical-alignment: center; } if row.sound-off: Text { text: "sound off"; font-size: 10px; color: #f85149; vertical-alignment: center; } if row.streaming: Text { text: "LIVE"; font-size: 10px; color: #a371f7; vertical-alignment: center; } if row.away: Text { text: "away"; font-size: 10px; color: #8b949e; vertical-alignment: center; } } } } } component ChatPanel inherits Rectangle { background: #0d1117; VerticalLayout { HorizontalLayout { height: 34px; spacing: 2px; for tab[i] in Bridge.tabs: Rectangle { width: tab-text.preferred-width + 28px; background: Bridge.current-tab == i ? #30363d : tab-area.has-hover ? #21262d : #161b22; tab-area := TouchArea { clicked => { Bridge.select-tab(i); } } HorizontalLayout { padding-left: 10px; padding-right: 6px; spacing: 4px; tab-text := Text { text: tab.title + (tab.unread > 0 ? " (" + tab.unread + ")" : ""); vertical-alignment: center; font-weight: tab.unread > 0 ? 700 : 400; } if tab.kind == 1: Text { text: "×"; vertical-alignment: center; TouchArea { clicked => { Bridge.close-tab(i); } } } } } Rectangle { } } ListView { for line in Bridge.messages: VerticalLayout { padding: 6px; HorizontalLayout { spacing: 8px; Text { text: line.author; font-weight: 700; color: line.relayed ? #58a6ff : #e6edf3; } Text { text: line.time + (line.relayed ? " via relay" : ""); font-size: 11px; color: #8b949e; vertical-alignment: center; } } Text { text: line.text; wrap: word-wrap; } } } HorizontalLayout { padding: 6px; spacing: 6px; input := LineEdit { placeholder-text: "Message"; accepted(text) => { if (text != "") { Bridge.send-message(text); self.text = ""; } } } Button { text: "Send"; clicked => { if (input.text != "") { Bridge.send-message(input.text); input.text = ""; } } } } } } export component MainWindow inherits Window { title: "TS Client"; preferred-width: 1200px; preferred-height: 760px; min-width: 360px; min-height: 480px; background: #0d1117; default-font-size: 13px; property editing: false; property show-about: false; property form; // Phones and narrow windows show one pane at a time. property narrow: self.width < 800px; property pane: 1; VerticalLayout { // Toolbar Rectangle { height: 48px; background: #161b22; HorizontalLayout { padding: 6px; spacing: 6px; if narrow: Button { text: pane == 0 ? "Tree" : pane == 1 ? "Chat" : "Servers"; clicked => { pane = mod(pane + 1, 3); } } Text { text: Bridge.server-title; font-size: 15px; font-weight: 700; vertical-alignment: center; overflow: elide; } Rectangle { } Button { text: Bridge.voice-connected ? "Disconnect" : Bridge.voice-connecting ? "Connecting…" : "Connect"; enabled: Bridge.current-server >= 0 && !Bridge.voice-connecting; primary: !Bridge.voice-connected; clicked => { if (Bridge.voice-connected) { Bridge.disconnect-voice(); } else { Bridge.connect-voice(); } } } Button { text: Bridge.observing ? "Stop observing" : "Observe (invisible)"; enabled: Bridge.can-observe; clicked => { Bridge.toggle-observe(); } } Button { text: Bridge.input-muted ? "Mic: off" : "Mic: on"; enabled: Bridge.voice-connected; clicked => { Bridge.set-input-muted(!Bridge.input-muted); } } Button { text: Bridge.output-muted ? "Sound: off" : "Sound: on"; enabled: Bridge.voice-connected; clicked => { Bridge.set-output-muted(!Bridge.output-muted); } } ptt := Rectangle { width: 110px; border-radius: 4px; background: Bridge.transmitting ? #238636 : ptt-area.has-hover ? #30363d : #21262d; opacity: Bridge.voice-connected ? 1.0 : 0.4; Text { text: Bridge.transmitting ? "Talking…" : "Hold to talk"; } ptt-area := TouchArea { enabled: Bridge.voice-connected; pointer-event(e) => { if (e.kind == PointerEventKind.down) { Bridge.push-to-talk(true); } else if (e.kind == PointerEventKind.up || e.kind == PointerEventKind.cancel) { Bridge.push-to-talk(false); } } } } Button { text: "About"; clicked => { show-about = true; } } } } HorizontalLayout { if !narrow || pane == 2: ServerList { width: narrow ? parent.width : 230px; add => { form = Bridge.edit-bookmark(-1); editing = true; } edit(id) => { form = Bridge.edit-bookmark(id); editing = true; } } if !narrow || pane == 0: ChannelTree { width: narrow ? parent.width : 360px; } if !narrow || pane == 1: ChatPanel { } } // Status bar Rectangle { height: 26px; background: #161b22; HorizontalLayout { padding-left: 8px; padding-right: 8px; Text { text: Bridge.status-text; color: #8b949e; vertical-alignment: center; overflow: elide; } Rectangle { } Text { text: Bridge.presence-source; color: #58a6ff; vertical-alignment: center; } } } } if editing: BookmarkEditor { form <=> form; done => { editing = false; } } if show-about: Rectangle { background: #000000c0; TouchArea { clicked => { show-about = false; } } VerticalBox { alignment: center; Text { text: "Unofficial TeamSpeak 3/6 compatible client. Not affiliated with TeamSpeak Systems GmbH."; horizontal-alignment: center; wrap: word-wrap; } AboutSlint { } Text { text: "Third-party licenses: see THIRD_PARTY_NOTICES. Click to close."; horizontal-alignment: center; color: #8b949e; } } } }