port changing functionality (#34)

* port changing functionality

* add portchange to cli frontend
This commit is contained in:
Ferdinand Schober
2023-10-17 15:12:17 +02:00
committed by GitHub
parent 60a73b3cb0
commit e88241e816
9 changed files with 263 additions and 121 deletions

View File

@@ -100,9 +100,19 @@ impl Window {
pub fn request_client_create(&self) {
let event = FrontendEvent::AddClient(None, DEFAULT_PORT, Position::default());
self.imp().set_port(DEFAULT_PORT);
self.request(event);
}
pub fn request_port_change(&self) {
let port = self.imp().port_entry.get().text().to_string();
if let Ok(port) = u16::from_str_radix(port.as_str(), 10) {
self.request(FrontendEvent::ChangePort(port));
} else {
self.request(FrontendEvent::ChangePort(DEFAULT_PORT));
}
}
pub fn request_client_update(&self, client: &ClientObject) {
let data = client.get_data();
let position = match data.position.as_str() {
@@ -150,11 +160,9 @@ impl Window {
};
}
fn setup_callbacks(&self) {
self.imp()
.add_client_button
.connect_clicked(clone!(@weak self as window => move |_| {
window.request_client_create();
}));
pub fn show_toast(&self, msg: &str) {
let toast = adw::Toast::new(msg);
let toast_overlay = &self.imp().toast_overlay;
toast_overlay.add_toast(toast);
}
}