mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-05 23:41:27 +03:00
add hostname entry row with clipboard button
This commit is contained in:
37
Cargo.lock
generated
37
Cargo.lock
generated
@@ -1142,6 +1142,17 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hostname"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f9c7c7c8ac16c798734b8a24560c1362120597c40d5e1459f09498f8f6c8f2ba"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"windows 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "humantime"
|
name = "humantime"
|
||||||
version = "2.1.0"
|
version = "2.1.0"
|
||||||
@@ -1241,6 +1252,7 @@ dependencies = [
|
|||||||
"futures-core",
|
"futures-core",
|
||||||
"glib-build-tools",
|
"glib-build-tools",
|
||||||
"gtk4",
|
"gtk4",
|
||||||
|
"hostname 0.4.0",
|
||||||
"keycode",
|
"keycode",
|
||||||
"libadwaita",
|
"libadwaita",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -1259,7 +1271,7 @@ dependencies = [
|
|||||||
"wayland-protocols",
|
"wayland-protocols",
|
||||||
"wayland-protocols-misc",
|
"wayland-protocols-misc",
|
||||||
"wayland-protocols-wlr",
|
"wayland-protocols-wlr",
|
||||||
"windows",
|
"windows 0.54.0",
|
||||||
"x11",
|
"x11",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1733,7 +1745,7 @@ version = "0.7.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00"
|
checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hostname",
|
"hostname 0.3.1",
|
||||||
"quick-error",
|
"quick-error",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2331,13 +2343,32 @@ version = "0.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows"
|
||||||
|
version = "0.52.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
|
||||||
|
dependencies = [
|
||||||
|
"windows-core 0.52.0",
|
||||||
|
"windows-targets 0.52.4",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows"
|
name = "windows"
|
||||||
version = "0.54.0"
|
version = "0.54.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49"
|
checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-core",
|
"windows-core 0.54.0",
|
||||||
|
"windows-targets 0.52.4",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-core"
|
||||||
|
version = "0.52.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||||
|
dependencies = [
|
||||||
"windows-targets 0.52.4",
|
"windows-targets 0.52.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ async-channel = { version = "2.1.1", optional = true }
|
|||||||
keycode = "0.4.0"
|
keycode = "0.4.0"
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.19.0"
|
||||||
num_enum = "0.7.2"
|
num_enum = "0.7.2"
|
||||||
|
hostname = "0.4.0"
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
libc = "0.2.148"
|
libc = "0.2.148"
|
||||||
|
|||||||
@@ -11,6 +11,16 @@
|
|||||||
<property name="tooltip-text" translatable="yes">enable</property>
|
<property name="tooltip-text" translatable="yes">enable</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child type="suffix">
|
||||||
|
<object class="GtkButton" id="dns_button">
|
||||||
|
<signal name="activate" handler="handle_request_dns" swapped="true"/>
|
||||||
|
<!--<property name="icon-name">network-wired-disconnected-symbolic</property>-->
|
||||||
|
<property name="icon-name">network-wired-symbolic</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
<property name="halign">end</property>
|
||||||
|
<property name="tooltip-text" translatable="yes">resolve dns</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
<!-- host -->
|
<!-- host -->
|
||||||
<child>
|
<child>
|
||||||
<object class="AdwActionRow">
|
<object class="AdwActionRow">
|
||||||
|
|||||||
@@ -5,6 +5,6 @@
|
|||||||
<file compressed="true" preprocess="xml-stripblanks">client_row.ui</file>
|
<file compressed="true" preprocess="xml-stripblanks">client_row.ui</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
<gresource prefix="/de/feschber/LanMouse/icons">
|
<gresource prefix="/de/feschber/LanMouse/icons">
|
||||||
<file compressed="true" preprocess="xml-stripblanks">de.feschber.LanMouse.svg</file>
|
<file compressed="true" preprocess="xml-stripblanks">de.feschber.LanMouse.svg</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
</gresources>
|
</gresources>
|
||||||
|
|||||||
@@ -99,6 +99,25 @@
|
|||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="AdwActionRow">
|
||||||
|
<property name="title">hostname</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="hostname_label">
|
||||||
|
<property name="label"><span font_style="italic" font_weight="light" foreground="darkgrey">could not determine hostname</span></property>
|
||||||
|
<property name="use-markup">true</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="copy-hostname-button">
|
||||||
|
<property name="icon-name">edit-copy-symbolic</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
<signal name="clicked" handler="handle_copy_hostname" swapped="true"/>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ use crate::frontend::gtk::window::Window;
|
|||||||
|
|
||||||
use adw::Application;
|
use adw::Application;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gdk::Display, glib::clone, prelude::*, subclass::prelude::ObjectSubclassIsExt,
|
gdk::Display, glib::clone, prelude::*, subclass::prelude::ObjectSubclassIsExt, IconTheme,
|
||||||
IconTheme,
|
|
||||||
};
|
};
|
||||||
use gtk::{gio, glib, prelude::ApplicationExt};
|
use gtk::{gio, glib, prelude::ApplicationExt};
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ pub struct ClientRow {
|
|||||||
#[template_child]
|
#[template_child]
|
||||||
pub enable_switch: TemplateChild<gtk::Switch>,
|
pub enable_switch: TemplateChild<gtk::Switch>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
|
pub dns_button: TemplateChild<gtk::Button>,
|
||||||
|
#[template_child]
|
||||||
pub hostname: TemplateChild<gtk::Entry>,
|
pub hostname: TemplateChild<gtk::Entry>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub port: TemplateChild<gtk::Entry>,
|
pub port: TemplateChild<gtk::Entry>,
|
||||||
@@ -76,6 +78,11 @@ impl ClientRow {
|
|||||||
true // dont run default handler
|
true // dont run default handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[template_callback]
|
||||||
|
fn handle_request_dns(&self) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
#[template_callback]
|
#[template_callback]
|
||||||
fn handle_client_delete(&self, _button: &Button) {
|
fn handle_client_delete(&self, _button: &Button) {
|
||||||
log::debug!("delete button pressed -> requesting delete");
|
log::debug!("delete button pressed -> requesting delete");
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ use std::os::unix::net::UnixStream;
|
|||||||
use adw::subclass::prelude::*;
|
use adw::subclass::prelude::*;
|
||||||
use adw::{prelude::*, ActionRow, ToastOverlay};
|
use adw::{prelude::*, ActionRow, ToastOverlay};
|
||||||
use glib::subclass::InitializingObject;
|
use glib::subclass::InitializingObject;
|
||||||
use gtk::{gio, glib, Button, CompositeTemplate, Entry, ListBox};
|
use gtk::glib::clone;
|
||||||
|
use gtk::{gdk, gio, glib, Button, CompositeTemplate, Entry, Label, ListBox};
|
||||||
|
|
||||||
use crate::config::DEFAULT_PORT;
|
use crate::config::DEFAULT_PORT;
|
||||||
|
|
||||||
@@ -26,6 +27,8 @@ pub struct Window {
|
|||||||
#[template_child]
|
#[template_child]
|
||||||
pub port_entry: TemplateChild<Entry>,
|
pub port_entry: TemplateChild<Entry>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
|
pub hostname_label: TemplateChild<Label>,
|
||||||
|
#[template_child]
|
||||||
pub toast_overlay: TemplateChild<ToastOverlay>,
|
pub toast_overlay: TemplateChild<ToastOverlay>,
|
||||||
pub clients: RefCell<Option<gio::ListStore>>,
|
pub clients: RefCell<Option<gio::ListStore>>,
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
@@ -61,6 +64,23 @@ impl Window {
|
|||||||
self.obj().request_client_create();
|
self.obj().request_client_create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[template_callback]
|
||||||
|
fn handle_copy_hostname(&self, button: &Button) {
|
||||||
|
if let Ok(hostname) = hostname::get() {
|
||||||
|
let prev_icon = button.icon_name().unwrap();
|
||||||
|
let display = gdk::Display::default().unwrap();
|
||||||
|
let clipboard = display.clipboard();
|
||||||
|
clipboard.set_text(hostname.to_str().expect("hostname: invalid utf8"));
|
||||||
|
button.set_icon_name("emblem-ok-symbolic");
|
||||||
|
button.set_css_classes(&["success"]);
|
||||||
|
glib::spawn_future_local(clone!(@weak button => async move {
|
||||||
|
glib::timeout_future_seconds(1).await;
|
||||||
|
button.set_icon_name(&prev_icon);
|
||||||
|
button.set_css_classes(&[]);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[template_callback]
|
#[template_callback]
|
||||||
fn handle_port_changed(&self, _entry: &Entry) {
|
fn handle_port_changed(&self, _entry: &Entry) {
|
||||||
self.port_edit_apply.set_visible(true);
|
self.port_edit_apply.set_visible(true);
|
||||||
@@ -95,6 +115,10 @@ impl Window {
|
|||||||
|
|
||||||
impl ObjectImpl for Window {
|
impl ObjectImpl for Window {
|
||||||
fn constructed(&self) {
|
fn constructed(&self) {
|
||||||
|
if let Ok(hostname) = hostname::get() {
|
||||||
|
self.hostname_label
|
||||||
|
.set_text(hostname.to_str().expect("hostname: invalid utf8"));
|
||||||
|
}
|
||||||
self.parent_constructed();
|
self.parent_constructed();
|
||||||
self.set_port(DEFAULT_PORT);
|
self.set_port(DEFAULT_PORT);
|
||||||
let obj = self.obj();
|
let obj = self.obj();
|
||||||
|
|||||||
Reference in New Issue
Block a user