From cd70e8faff3fdd709f8683c6f036964bc763d720 Mon Sep 17 00:00:00 2001 From: Sebastian Wiesner Date: Sat, 28 Sep 2024 19:14:30 +0200 Subject: [PATCH] Add suffix to device rows Show device host in suffix, and set the mac address as subtitle. Add dummy buttons to edit or remove a device. --- resources/ui/device-row.blp | 42 ++++++++++++++++++++++++++++++- resources/ui/device-row.ui | 49 +++++++++++++++++++++++++++++++++++-- src/widgets/device_row.rs | 11 ++++++++- 3 files changed, 98 insertions(+), 4 deletions(-) diff --git a/resources/ui/device-row.blp b/resources/ui/device-row.blp index e971c45..28fc856 100644 --- a/resources/ui/device-row.blp +++ b/resources/ui/device-row.blp @@ -7,6 +7,46 @@ using Adw 1; template $DeviceRow: Adw.ActionRow { title: bind (template.device as <$Device>).label; - subtitle: bind (template.device as <$Device>).host; + subtitle: bind $device_mac_address(template.device) as ; activatable: true; + + [suffix] + Gtk.Box { + orientation: horizontal; + spacing: 3; + + Label { + label: bind (template.device as <$Device>).host; + + styles [ + "dim-label" + ] + } + + Gtk.Box { + orientation: horizontal; + + Gtk.Button { + icon-name: "document-edit-symbolic"; + // TODO: implement + sensitive: false; + tooltip-text: _("Editing of devices is not yet implemented"); + + styles [ + "flat" + ] + } + + Gtk.Button { + icon-name: "user-trash-symbolic"; + // TODO: implement + sensitive: false; + tooltip-text: _("Deleting of devices is not yet implemented"); + + styles [ + "flat" + ] + } + } + } } diff --git a/resources/ui/device-row.ui b/resources/ui/device-row.ui index 922da88..fb54d5b 100644 --- a/resources/ui/device-row.ui +++ b/resources/ui/device-row.ui @@ -15,12 +15,57 @@ corresponding .blp file and regenerate this file with blueprint-compiler. - + DeviceRow - + true + + + 0 + 3 + + + + + + DeviceRow + + + + + + + + + 0 + + + document-edit-symbolic + false + Editing of devices is not yet implemented + + + + + + user-trash-symbolic + false + Deleting of devices is not yet implemented + + + + + + + \ No newline at end of file diff --git a/src/widgets/device_row.rs b/src/widgets/device_row.rs index f8e1ffa..ab2afa5 100644 --- a/src/widgets/device_row.rs +++ b/src/widgets/device_row.rs @@ -33,7 +33,7 @@ mod imp { use adw::subclass::prelude::*; use glib::subclass::InitializingObject; use glib::Properties; - use gtk::CompositeTemplate; + use gtk::{template_callbacks, CompositeTemplate}; use crate::model::Device; @@ -45,6 +45,14 @@ mod imp { device: RefCell, } + #[template_callbacks] + impl DeviceRow { + #[template_callback] + pub fn device_mac_address(_row: &super::DeviceRow, device: &Device) -> String { + device.mac_addr6().to_string() + } + } + #[glib::object_subclass] impl ObjectSubclass for DeviceRow { const NAME: &'static str = "DeviceRow"; @@ -55,6 +63,7 @@ mod imp { fn class_init(klass: &mut Self::Class) { klass.bind_template(); + klass.bind_template_callbacks(); } fn instance_init(obj: &InitializingObject) {