Skip to content

Commit

Permalink
Add suffix to device rows
Browse files Browse the repository at this point in the history
Show device host in suffix, and set the mac address as subtitle.
Add dummy buttons to edit or remove a device.
  • Loading branch information
swsnr committed Sep 28, 2024
1 parent 3974435 commit cd70e8f
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 4 deletions.
42 changes: 41 additions & 1 deletion resources/ui/device-row.blp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string>;
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"
]
}
}
}
}
49 changes: 47 additions & 2 deletions resources/ui/device-row.ui
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,57 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
</lookup>
</binding>
<binding name="subtitle">
<lookup name="host" type="Device">
<closure function="device_mac_address" type="gchararray">
<lookup name="device" type="DeviceRow">
<constant>DeviceRow</constant>
</lookup>
</lookup>
</closure>
</binding>
<property name="activatable">true</property>
<child type="suffix">
<object class="GtkBox">
<property name="orientation">0</property>
<property name="spacing">3</property>
<child>
<object class="GtkLabel">
<binding name="label">
<lookup name="host" type="Device">
<lookup name="device" type="DeviceRow">
<constant>DeviceRow</constant>
</lookup>
</lookup>
</binding>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkBox">
<property name="orientation">0</property>
<child>
<object class="GtkButton">
<property name="icon-name">document-edit-symbolic</property>
<property name="sensitive">false</property>
<property name="tooltip-text" translatable="yes">Editing of devices is not yet implemented</property>
<style>
<class name="flat"/>
</style>
</object>
</child>
<child>
<object class="GtkButton">
<property name="icon-name">user-trash-symbolic</property>
<property name="sensitive">false</property>
<property name="tooltip-text" translatable="yes">Deleting of devices is not yet implemented</property>
<style>
<class name="flat"/>
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
</interface>
11 changes: 10 additions & 1 deletion src/widgets/device_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -45,6 +45,14 @@ mod imp {
device: RefCell<Device>,
}

#[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";
Expand All @@ -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<Self>) {
Expand Down

0 comments on commit cd70e8f

Please sign in to comment.