|
| 1 | +import { TabWidget, LineEdit, Button, ListView, ComboBox } from "std-widgets.slint"; |
| 2 | + |
| 3 | +struct Device { |
| 4 | + name: string, |
| 5 | + ip: string, |
| 6 | + port: string, |
| 7 | + status: string, |
| 8 | + paired: bool, |
| 9 | +} |
| 10 | + |
| 11 | +component PairedDeviceFile { |
| 12 | + in property <string> device_name; |
| 13 | + in property <int> index; |
| 14 | + callback send_file(string); |
| 15 | + |
| 16 | + HorizontalLayout { |
| 17 | + Text { text: device_name; color: #333; } |
| 18 | + file_path := LineEdit { placeholder-text: "File path"; } |
| 19 | + Button { |
| 20 | + text: "Send File"; |
| 21 | + clicked => { send_file(file_path.text); } |
| 22 | + } |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +component PairedDeviceClipboard { |
| 27 | + in property <string> device_name; |
| 28 | + in property <int> index; |
| 29 | + callback send_clipboard(string); |
| 30 | + |
| 31 | + HorizontalLayout { |
| 32 | + Text { text: device_name; color: #333; } |
| 33 | + content := LineEdit { placeholder-text: "Clipboard content"; } |
| 34 | + Button { |
| 35 | + text: "Send Clipboard"; |
| 36 | + clicked => { send_clipboard(content.text); } |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +export component AppWindow inherits Window { |
| 42 | + in-out property <[Device]> devices: []; |
| 43 | + in-out property <[string]> device_names: []; |
| 44 | + in-out property <[string]> messages: []; |
| 45 | + in-out property <string> my_device_name: "My Device"; |
| 46 | + in-out property <string> my_ip: "0.0.0.0"; |
| 47 | + in-out property <string> status_message: ""; |
| 48 | + |
| 49 | + callback discover_devices(); |
| 50 | + callback pair_device(int); |
| 51 | + callback disconnect_device(int); |
| 52 | + callback send_file(int, string); |
| 53 | + callback send_clipboard(int, string); |
| 54 | + callback send_message(int, string); |
| 55 | + |
| 56 | + title: "Hackeros Connect"; |
| 57 | + width: 800px; |
| 58 | + height: 600px; |
| 59 | + background: #f0f0f0; |
| 60 | + |
| 61 | + VerticalLayout { |
| 62 | + spacing: 10px; |
| 63 | + padding: 10px; |
| 64 | + |
| 65 | + Text { text: "My Device: " + root.my_device_name + " (" + root.my_ip + ")"; font-size: 16px; color: #333; } |
| 66 | + |
| 67 | + TabWidget { |
| 68 | + Tab { |
| 69 | + title: "Devices"; |
| 70 | + VerticalLayout { |
| 71 | + Button { |
| 72 | + text: "Discover Devices"; |
| 73 | + clicked => { root.discover_devices(); } |
| 74 | + } |
| 75 | + |
| 76 | + ListView { |
| 77 | + for model-data [model-row] in root.devices : Rectangle { |
| 78 | + background: model-data.paired ? #d4ffd4 : #ffffff; |
| 79 | + border-color: #ddd; |
| 80 | + border-width: 1px; |
| 81 | + HorizontalLayout { |
| 82 | + padding: 10px; |
| 83 | + Text { text: "📱 "; } |
| 84 | + Text { text: model-data.name + " (" + model-data.ip + ":" + model-data.port + ") - " + model-data.status; color: #333; } |
| 85 | + if !model-data.paired: Button { |
| 86 | + text: "Pair"; |
| 87 | + clicked => { root.pair_device(model-row); } |
| 88 | + } |
| 89 | + if model-data.paired: Button { |
| 90 | + text: "Disconnect"; |
| 91 | + clicked => { root.disconnect_device(model-row); } |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + Tab { |
| 100 | + title: "File Transfer"; |
| 101 | + VerticalLayout { |
| 102 | + Text { text: "Select Device and File to Send"; color: #333; } |
| 103 | + |
| 104 | + ListView { |
| 105 | + for model-data [model-row] in root.devices : Rectangle { |
| 106 | + if model-data.paired: PairedDeviceFile { |
| 107 | + device_name: model-data.name; |
| 108 | + index: model-row; |
| 109 | + send_file(path) => { root.send_file(self.index, path); } |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + Tab { |
| 117 | + title: "Clipboard Share"; |
| 118 | + VerticalLayout { |
| 119 | + Text { text: "Select Device and Content to Send"; color: #333; } |
| 120 | + |
| 121 | + ListView { |
| 122 | + for model-data [model-row] in root.devices : Rectangle { |
| 123 | + if model-data.paired: PairedDeviceClipboard { |
| 124 | + device_name: model-data.name; |
| 125 | + index: model-row; |
| 126 | + send_clipboard(content) => { root.send_clipboard(self.index, content); } |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + Tab { |
| 134 | + title: "Chat"; |
| 135 | + VerticalLayout { |
| 136 | + Text { text: "Select Device and Send Message"; color: #333; } |
| 137 | + |
| 138 | + device_combo := ComboBox { |
| 139 | + model: root.device_names; |
| 140 | + } |
| 141 | + |
| 142 | + HorizontalLayout { |
| 143 | + chat_input := LineEdit { placeholder-text: "Type message"; width: parent.width - 100px; } |
| 144 | + Button { |
| 145 | + text: "Send"; |
| 146 | + clicked => { root.send_message(device_combo.current-index, chat_input.text); chat_input.text = ""; } |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + ListView { |
| 151 | + for model-data in root.messages : Rectangle { |
| 152 | + background: #ffffff; |
| 153 | + border-color: #ddd; |
| 154 | + border-width: 1px; |
| 155 | + VerticalLayout { |
| 156 | + padding: 5px; |
| 157 | + Text { text: model-data; color: #333; } |
| 158 | + } |
| 159 | + } |
| 160 | + } |
| 161 | + } |
| 162 | + } |
| 163 | + |
| 164 | + Tab { |
| 165 | + title: "Settings"; |
| 166 | + VerticalLayout { |
| 167 | + Text { text: "Settings: Ports, etc. (Coming soon)"; color: #333; } |
| 168 | + } |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + Text { text: root.status_message; color: #007bff; } |
| 173 | + } |
| 174 | +} |
1 | 175 |
|
0 commit comments