diff --git a/Cargo.toml b/Cargo.toml index f380968..1102a34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ description = "A wip universal Linux settings application." [dependencies] reset_daemon = "0.3.3" -ReSet-Lib = "0.5.4" +ReSet-Lib = "0.5.5" adw = { version = "0.5.3", package = "libadwaita", features = ["v1_4"] } dbus = "0.9.7" gtk = { version = "0.7.3", package = "gtk4", features = ["v4_12"] } diff --git a/src/components/bluetooth/bluetoothBox.rs b/src/components/bluetooth/bluetoothBox.rs index bcc6342..b96daab 100644 --- a/src/components/bluetooth/bluetoothBox.rs +++ b/src/components/bluetooth/bluetoothBox.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use std::sync::atomic::Ordering; use std::sync::Arc; use std::thread; @@ -12,15 +11,14 @@ use dbus::message::SignalArgs; use dbus::{Error, Path}; use gtk::gio; use gtk::glib::Variant; -use gtk::prelude::{ActionableExt, ListBoxRowExt}; +use gtk::prelude::{ActionableExt, ListBoxRowExt, WidgetExt}; use ReSet_Lib::bluetooth::bluetooth::BluetoothDevice; -use ReSet_Lib::signals::{BluetoothDeviceAdded, BluetoothDeviceRemoved}; +use ReSet_Lib::signals::{BluetoothDeviceAdded, BluetoothDeviceChanged, BluetoothDeviceRemoved}; use crate::components::base::listEntry::ListEntry; use crate::components::base::utils::Listeners; use crate::components::bluetooth::bluetoothBoxImpl; use crate::components::bluetooth::bluetoothEntry::BluetoothEntry; -// use crate::components::bluetooth::bluetoothEntryImpl::DeviceTypes; glib::wrapper! { pub struct BluetoothBox(ObjectSubclass) @@ -52,6 +50,12 @@ impl BluetoothBox { } } +impl Default for BluetoothBox { + fn default() -> Self { + Self::new() + } +} + pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc) { gio::spawn_blocking(move || { let ref_box = bluetooth_box.clone(); @@ -63,11 +67,11 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc) { for device in devices { let path = device.path.clone(); let connected = device.connected; - let bluetooth_entry = Arc::new(BluetoothEntry::new(device)); + let bluetooth_entry = Arc::new(BluetoothEntry::new(&device)); let entry = Arc::new(ListEntry::new(&*bluetooth_entry)); imp.availableDevices .borrow_mut() - .insert(path, (bluetooth_entry.clone(), entry.clone())); + .insert(path, (bluetooth_entry.clone(), entry.clone(), device)); if connected { imp.resetBluetoothConnectedDevices.append(&*entry); } else { @@ -108,8 +112,14 @@ pub fn start_bluetooth_listener(listeners: Arc, bluetooth_box: Arc, bluetooth_box: Arc, bluetooth_box: Arc, (Arc, Arc, BluetoothDevice)>>; + #[allow(non_snake_case)] #[derive(Default, CompositeTemplate)] #[template(resource = "/org/Xetibo/ReSet/resetBluetooth.ui")] @@ -25,8 +29,8 @@ pub struct BluetoothBox { pub resetVisibility: TemplateChild, #[template_child] pub resetBluetoothMainTab: TemplateChild, - pub availableDevices: RefCell, (Arc, Arc)>>, - pub connectedDevices: RefCell, (Arc, Arc)>>, + pub availableDevices: BluetoothMap, + pub connectedDevices: BluetoothMap, } #[glib::object_subclass] diff --git a/src/components/bluetooth/bluetoothEntry.rs b/src/components/bluetooth/bluetoothEntry.rs index 718e2c1..1e72003 100644 --- a/src/components/bluetooth/bluetoothEntry.rs +++ b/src/components/bluetooth/bluetoothEntry.rs @@ -1,15 +1,12 @@ -use std::rc::Rc; use std::sync::Arc; use std::time::Duration; use crate::components::bluetooth::bluetoothEntryImpl; -// use crate::components::bluetooth::bluetoothEntryImpl::DeviceTypes; use adw::glib; use adw::glib::Object; use adw::subclass::prelude::ObjectSubclassIsExt; use dbus::blocking::Connection; use dbus::{Error, Path}; -use glib::clone; use gtk::prelude::{ButtonExt, WidgetExt}; use gtk::{gio, GestureClick}; use ReSet_Lib::bluetooth::bluetooth::BluetoothDevice; @@ -21,21 +18,20 @@ glib::wrapper! { } impl BluetoothEntry { - pub fn new(device: BluetoothDevice) -> Self { + pub fn new(device: &BluetoothDevice) -> Self { let entry: BluetoothEntry = Object::builder().build(); let entryImp = entry.imp(); - entryImp.resetBluetoothLabel.get().set_text(&device.name); - entryImp.resetBluetoothAddress.get().set_text(&device.alias); - // entryImp - // .resetBluetoothDeviceType - // .get() - // .set_from_icon_name(match deviceType { - // DeviceTypes::Mouse => Some("input-mouse-symbolic"), - // DeviceTypes::Keyboard => Some("input-keyboard-symbolic"), - // DeviceTypes::Headset => Some("output-headset-symbolic"), - // DeviceTypes::Controller => Some("input-gaming-symbolic"), - // DeviceTypes::None => Some("text-x-generic-symbolic"), // no generic bluetooth device icon found - // }); + entryImp.resetBluetoothLabel.get().set_text(&device.alias); + entryImp.resetBluetoothAddress.get().set_text(&device.address); + if device.icon == "" { + entryImp + .resetBluetoothDeviceType + .set_icon_name(Some("dialog-question-symbolic")); + } else { + entryImp + .resetBluetoothDeviceType + .set_icon_name(Some(&device.icon)); + } if device.paired { entryImp.resetBluetoothButton.set_sensitive(true); } else { @@ -47,17 +43,17 @@ impl BluetoothEntry { }); let gesture = GestureClick::new(); let connected = device.connected; - entryImp.device.replace(device); - gesture.connect_released(clone!(@weak entryImp => move |_, _, _, _| { - let device = entryImp.device.borrow_mut(); + let paired = device.paired; + let path = device.path.clone(); + gesture.connect_released(move |_, _, _, _| { if connected { - disconnect_from_device(device.path.clone()); - } else if device.paired { - connect_to_device(device.path.clone()); + disconnect_from_device(path.clone()); + } else if paired { + connect_to_device(path.clone()); } else { - pair_with_device(device.path.clone()); + pair_with_device(path.clone()); } - })); + }); entry.add_controller(gesture); entry } diff --git a/src/components/bluetooth/bluetoothEntryImpl.rs b/src/components/bluetooth/bluetoothEntryImpl.rs index 5846ade..98c7bce 100644 --- a/src/components/bluetooth/bluetoothEntryImpl.rs +++ b/src/components/bluetooth/bluetoothEntryImpl.rs @@ -2,17 +2,7 @@ use crate::components::bluetooth::bluetoothEntry; use gtk::subclass::prelude::*; use gtk::{glib, Button, CompositeTemplate, Image, Label}; use std::cell::RefCell; -use ReSet_Lib::bluetooth::bluetooth::BluetoothDevice; -#[derive(Default, Copy, Clone)] -pub enum DeviceTypes { - Mouse, - Keyboard, - Headset, - Controller, - #[default] - None, -} #[allow(non_snake_case)] #[derive(Default, CompositeTemplate)] #[template(resource = "/org/Xetibo/ReSet/resetBluetoothEntry.ui")] @@ -26,7 +16,6 @@ pub struct BluetoothEntry { #[template_child] pub resetBluetoothButton: TemplateChild