chore: Use actionrow

This commit is contained in:
Fabio Lenherr / DashieTM 2023-12-06 17:54:08 +01:00
parent c5c5f6761e
commit c4af8696a8
6 changed files with 81 additions and 88 deletions

View file

@ -17,7 +17,6 @@ use gtk::{gio, StringObject, Widget};
use re_set_lib::bluetooth::bluetooth_structures::{BluetoothAdapter, BluetoothDevice};
use re_set_lib::signals::{BluetoothDeviceAdded, BluetoothDeviceChanged, BluetoothDeviceRemoved};
use crate::components::base::list_entry::ListEntry;
use crate::components::base::utils::Listeners;
use crate::components::bluetooth::bluetooth_box_impl;
use crate::components::bluetooth::bluetooth_entry::BluetoothEntry;
@ -178,14 +177,13 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
let path = device.path.clone();
let connected = device.connected;
let bluetooth_entry = Arc::new(BluetoothEntry::new(&device));
let entry = Arc::new(ListEntry::new(&*bluetooth_entry));
imp.available_devices
.borrow_mut()
.insert(path, (bluetooth_entry.clone(), entry.clone(), device));
.insert(path, (bluetooth_entry.clone(), device));
if connected {
imp.reset_bluetooth_connected_devices.add(&*entry);
imp.reset_bluetooth_connected_devices.add(&*bluetooth_entry);
} else {
imp.reset_bluetooth_available_devices.add(&*entry);
imp.reset_bluetooth_available_devices.add(&*bluetooth_entry);
}
}
});
@ -239,15 +237,13 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
let path = ir.bluetooth_device.path.clone();
let connected = ir.bluetooth_device.connected;
let bluetooth_entry = Arc::new(BluetoothEntry::new(&ir.bluetooth_device));
let entry = Arc::new(ListEntry::new(&*bluetooth_entry));
imp.available_devices.borrow_mut().insert(
path,
(bluetooth_entry.clone(), entry.clone(), ir.bluetooth_device),
);
imp.available_devices
.borrow_mut()
.insert(path, (bluetooth_entry.clone(), ir.bluetooth_device));
if connected {
imp.reset_bluetooth_connected_devices.add(&*entry);
imp.reset_bluetooth_connected_devices.add(&*bluetooth_entry);
} else {
imp.reset_bluetooth_available_devices.add(&*entry);
imp.reset_bluetooth_available_devices.add(&*bluetooth_entry);
}
});
});
@ -266,7 +262,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
let imp = bluetooth_box.imp();
let map = imp.available_devices.borrow_mut();
if let Some(list_entry) = map.get(&ir.bluetooth_device) {
imp.reset_bluetooth_connected_devices.remove(&*list_entry.1);
imp.reset_bluetooth_connected_devices.remove(&*list_entry.0);
}
});
});
@ -285,16 +281,16 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
let imp = bluetooth_box.imp();
let map = imp.available_devices.borrow_mut();
if let Some(list_entry) = map.get(&ir.bluetooth_device.path) {
if list_entry.2.connected != ir.bluetooth_device.connected {
if list_entry.1.connected != ir.bluetooth_device.connected {
if ir.bluetooth_device.connected {
imp.reset_bluetooth_connected_devices.add(&*list_entry.1);
imp.reset_bluetooth_available_devices.remove(&*list_entry.1);
imp.reset_bluetooth_connected_devices.add(&*list_entry.0);
imp.reset_bluetooth_available_devices.remove(&*list_entry.0);
} else {
imp.reset_bluetooth_available_devices.add(&*list_entry.1);
imp.reset_bluetooth_connected_devices.remove(&*list_entry.1);
imp.reset_bluetooth_available_devices.add(&*list_entry.0);
imp.reset_bluetooth_connected_devices.remove(&*list_entry.0);
}
}
if list_entry.2.paired != ir.bluetooth_device.paired {
if list_entry.1.paired != ir.bluetooth_device.paired {
if ir.bluetooth_device.paired {
list_entry
.0
@ -333,7 +329,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
let imp = loop_box.imp();
let mut entries = imp.available_devices.borrow_mut();
for entry in entries.iter() {
imp.reset_bluetooth_available_devices.remove(&*entry.1 .1);
imp.reset_bluetooth_available_devices.remove(&*entry.1 .0);
}
entries.clear();
imp.reset_bluetooth_refresh_button.set_sensitive(true);

View file

@ -13,7 +13,7 @@ use crate::components::bluetooth::bluetooth_box;
use crate::components::bluetooth::bluetooth_entry::BluetoothEntry;
type BluetoothMap =
RefCell<HashMap<Path<'static>, (Arc<BluetoothEntry>, Arc<ListEntry>, BluetoothDevice)>>;
RefCell<HashMap<Path<'static>, (Arc<BluetoothEntry>, BluetoothDevice)>>;
#[derive(Default, CompositeTemplate)]
#[template(resource = "/org/Xetibo/ReSet/resetBluetooth.ui")]

View file

@ -2,9 +2,10 @@ use std::sync::Arc;
use std::time::Duration;
use crate::components::bluetooth::bluetooth_entry_impl;
use adw::glib;
use adw::glib::Object;
use adw::prelude::ActionRowExt;
use adw::subclass::prelude::ObjectSubclassIsExt;
use adw::{glib, ActionRow};
use dbus::blocking::Connection;
use dbus::{Error, Path};
use gtk::prelude::{ButtonExt, WidgetExt};
@ -13,7 +14,7 @@ use re_set_lib::bluetooth::bluetooth_structures::BluetoothDevice;
glib::wrapper! {
pub struct BluetoothEntry(ObjectSubclass<bluetooth_entry_impl::BluetoothEntry>)
@extends gtk::Box, gtk::Widget,
@extends ActionRow, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget;
}
@ -23,15 +24,13 @@ unsafe impl Sync for BluetoothEntry {}
impl BluetoothEntry {
pub fn new(device: &BluetoothDevice) -> Self {
let entry: BluetoothEntry = Object::builder().build();
entry.set_sensitive(true);
let entry_imp = entry.imp();
entry_imp
.reset_bluetooth_label
.get()
.set_text(&device.alias);
entry_imp
.reset_bluetooth_address
.get()
.set_text(&device.address);
entry.set_subtitle(&device.address);
if device.icon.is_empty() {
entry_imp
.reset_bluetooth_device_type

View file

@ -1,4 +1,7 @@
use crate::components::bluetooth::bluetooth_entry;
use adw::subclass::action_row::ActionRowImpl;
use adw::subclass::preferences_row::PreferencesRowImpl;
use adw::ActionRow;
use gtk::subclass::prelude::*;
use gtk::{glib, Button, CompositeTemplate, Image, Label};
use std::cell::RefCell;
@ -11,8 +14,6 @@ pub struct BluetoothEntry {
#[template_child]
pub reset_bluetooth_label: TemplateChild<Label>,
#[template_child]
pub reset_bluetooth_address: TemplateChild<Label>,
#[template_child]
pub reset_bluetooth_button: TemplateChild<Button>,
pub device_name: RefCell<String>,
}
@ -22,7 +23,7 @@ impl ObjectSubclass for BluetoothEntry {
const ABSTRACT: bool = false;
const NAME: &'static str = "resetBluetoothEntry";
type Type = bluetooth_entry::BluetoothEntry;
type ParentType = gtk::Box;
type ParentType = ActionRow;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
@ -39,7 +40,11 @@ impl ObjectImpl for BluetoothEntry {
}
}
impl BoxImpl for BluetoothEntry {}
impl ActionRowImpl for BluetoothEntry {}
impl PreferencesRowImpl for BluetoothEntry {}
impl ListBoxRowImpl for BluetoothEntry {}
impl WidgetImpl for BluetoothEntry {}