mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-07-01 15:57:46 +02:00
simplify bluetooth entry
This commit is contained in:
parent
8518d6e247
commit
0184fba8b4
5 changed files with 30 additions and 147 deletions
|
@ -295,13 +295,15 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
|
|||
list_entry
|
||||
.0
|
||||
.imp()
|
||||
.reset_bluetooth_button
|
||||
.button
|
||||
.borrow()
|
||||
.set_sensitive(true);
|
||||
} else {
|
||||
list_entry
|
||||
.0
|
||||
.imp()
|
||||
.reset_bluetooth_button
|
||||
.button
|
||||
.borrow()
|
||||
.set_sensitive(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,22 @@
|
|||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::components::bluetooth::bluetooth_entry_impl;
|
||||
use adw::glib::Object;
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
use adw::{glib, ActionRow};
|
||||
use adw::prelude::{ActionRowExt, PreferencesRowExt};
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::{Error, Path};
|
||||
use glib::subclass::prelude::ObjectSubclassIsExt;
|
||||
use gtk::prelude::{ButtonExt, ListBoxRowExt, WidgetExt};
|
||||
use gtk::{gio, GestureClick};
|
||||
use gtk::{gio, GestureClick, Image, Button, Align};
|
||||
use re_set_lib::bluetooth::bluetooth_structures::BluetoothDevice;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct BluetoothEntry(ObjectSubclass<bluetooth_entry_impl::BluetoothEntry>)
|
||||
@extends ActionRow, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget, gtk::ListBoxRow;
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget, gtk::ListBoxRow, adw::PreferencesRow;
|
||||
}
|
||||
|
||||
unsafe impl Send for BluetoothEntry {}
|
||||
|
@ -24,31 +26,25 @@ impl BluetoothEntry {
|
|||
pub fn new(device: &BluetoothDevice) -> Self {
|
||||
let entry: BluetoothEntry = Object::builder().build();
|
||||
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_title(&device.alias);
|
||||
entry.set_subtitle(&device.address);
|
||||
entry.set_activatable(true);
|
||||
|
||||
entry_imp.button.replace(Button::builder().icon_name("user-trash-symbolic").valign(Align::Center).build());
|
||||
entry.add_suffix(entry_imp.button.borrow().deref());
|
||||
if device.icon.is_empty() {
|
||||
entry_imp
|
||||
.reset_bluetooth_device_type
|
||||
.set_icon_name(Some("dialog-question-symbolic"));
|
||||
entry.add_prefix(&Image::from_icon_name("dialog-question-symbolic"));
|
||||
} else {
|
||||
entry_imp
|
||||
.reset_bluetooth_device_type
|
||||
.set_icon_name(Some(&device.icon));
|
||||
entry.add_prefix(&Image::from_icon_name(&device.icon));
|
||||
}
|
||||
if device.connected || device.paired {
|
||||
entry_imp.reset_bluetooth_button.set_sensitive(true);
|
||||
entry_imp.button.borrow().set_sensitive(true);
|
||||
} else {
|
||||
entry_imp.reset_bluetooth_button.set_sensitive(false);
|
||||
entry_imp.button.borrow().set_sensitive(false);
|
||||
}
|
||||
let path = Arc::new(device.path.clone());
|
||||
entry_imp.reset_bluetooth_button.connect_clicked(move |_| {
|
||||
entry_imp.button.borrow().connect_clicked(move |_| {
|
||||
remove_device_pairing((*path).clone());
|
||||
});
|
||||
let gesture = GestureClick::new();
|
||||
|
|
|
@ -3,20 +3,13 @@ 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 gtk::{glib, Button, CompositeTemplate};
|
||||
use std::cell::RefCell;
|
||||
|
||||
#[derive(Default, CompositeTemplate)]
|
||||
#[template(resource = "/org/Xetibo/ReSet/resetBluetoothEntry.ui")]
|
||||
pub struct BluetoothEntry {
|
||||
#[template_child]
|
||||
pub reset_bluetooth_device_type: TemplateChild<Image>,
|
||||
#[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 button: RefCell<Button>,
|
||||
pub device_name: RefCell<String>,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue