mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-17 10:18:32 +02:00
chore: refactor wifi and bluetooth event handlers
This commit is contained in:
parent
0105956815
commit
0fe99fa3a6
|
@ -9,7 +9,7 @@ use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||||
use dbus::blocking::Connection;
|
use dbus::blocking::Connection;
|
||||||
use dbus::message::SignalArgs;
|
use dbus::message::SignalArgs;
|
||||||
use dbus::{Error, Path};
|
use dbus::{Error, Path};
|
||||||
use glib::{clone, Cast, PropertySet};
|
use glib::{clone, Cast, ControlFlow, PropertySet};
|
||||||
use gtk::glib::Variant;
|
use gtk::glib::Variant;
|
||||||
use gtk::prelude::{ActionableExt, ButtonExt, ListBoxRowExt, WidgetExt};
|
use gtk::prelude::{ActionableExt, ButtonExt, ListBoxRowExt, WidgetExt};
|
||||||
use gtk::{gio, StringObject};
|
use gtk::{gio, StringObject};
|
||||||
|
@ -99,7 +99,11 @@ fn setup_callbacks(
|
||||||
|
|
||||||
imp.reset_bluetooth_switch
|
imp.reset_bluetooth_switch
|
||||||
.connect_state_set(move |_, state| {
|
.connect_state_set(move |_, state| {
|
||||||
bluetooth_enabled_switch_handler(state, bluetooth_box_ref.clone(), listeners_ref.clone())
|
bluetooth_enabled_switch_handler(
|
||||||
|
state,
|
||||||
|
bluetooth_box_ref.clone(),
|
||||||
|
listeners_ref.clone(),
|
||||||
|
)
|
||||||
});
|
});
|
||||||
bluetooth_box
|
bluetooth_box
|
||||||
}
|
}
|
||||||
|
@ -213,24 +217,10 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
|
||||||
imp.reset_switch_initial.set(false);
|
imp.reset_switch_initial.set(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
imp.reset_bluetooth_adapter.connect_selected_notify(
|
imp.reset_bluetooth_adapter
|
||||||
clone!(@weak imp => move |dropdown| {
|
.connect_selected_notify(move |dropdown| {
|
||||||
let selected = dropdown.selected_item();
|
select_bluetooth_adapter_handler(dropdown, new_adapter_ref.clone());
|
||||||
if selected.is_none() {
|
});
|
||||||
return;
|
|
||||||
}
|
|
||||||
let selected = selected.unwrap();
|
|
||||||
let selected = selected.downcast_ref::<StringObject>().unwrap();
|
|
||||||
let selected = selected.string().to_string();
|
|
||||||
|
|
||||||
let device = imp.reset_bluetooth_adapters.read().unwrap();
|
|
||||||
let device = device.get(&selected);
|
|
||||||
if device.is_none() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
set_bluetooth_adapter(device.unwrap().0.path.clone(), new_adapter_ref.clone());
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
for device in devices {
|
for device in devices {
|
||||||
let path = device.path.clone();
|
let path = device.path.clone();
|
||||||
|
@ -250,6 +240,28 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn select_bluetooth_adapter_handler(
|
||||||
|
dropdown: &adw::ComboRow,
|
||||||
|
bluetooth_box: Arc<BluetoothBox>,
|
||||||
|
) -> ControlFlow {
|
||||||
|
let imp = bluetooth_box.imp();
|
||||||
|
let selected = dropdown.selected_item();
|
||||||
|
if selected.is_none() {
|
||||||
|
return ControlFlow::Break;
|
||||||
|
}
|
||||||
|
let selected = selected.unwrap();
|
||||||
|
let selected = selected.downcast_ref::<StringObject>().unwrap();
|
||||||
|
let selected = selected.string().to_string();
|
||||||
|
let device = imp.reset_bluetooth_adapters.read().unwrap();
|
||||||
|
let device = device.get(&selected);
|
||||||
|
if device.is_none() {
|
||||||
|
return ControlFlow::Break;
|
||||||
|
}
|
||||||
|
set_bluetooth_adapter(device.unwrap().0.path.clone(), bluetooth_box.clone());
|
||||||
|
|
||||||
|
ControlFlow::Continue
|
||||||
|
}
|
||||||
|
|
||||||
pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<BluetoothBox>) {
|
pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<BluetoothBox>) {
|
||||||
gio::spawn_blocking(move || {
|
gio::spawn_blocking(move || {
|
||||||
if listeners.bluetooth_listener.load(Ordering::SeqCst) {
|
if listeners.bluetooth_listener.load(Ordering::SeqCst) {
|
||||||
|
@ -285,25 +297,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
|
||||||
.static_clone();
|
.static_clone();
|
||||||
|
|
||||||
let res = conn.add_match(device_added, move |ir: BluetoothDeviceAdded, _, _| {
|
let res = conn.add_match(device_added, move |ir: BluetoothDeviceAdded, _, _| {
|
||||||
let bluetooth_box = device_added_box.clone();
|
device_added_handler(device_added_box.clone(), ir)
|
||||||
glib::spawn_future(async move {
|
|
||||||
glib::idle_add_once(move || {
|
|
||||||
let imp = bluetooth_box.imp();
|
|
||||||
let path = ir.bluetooth_device.path.clone();
|
|
||||||
let connected = ir.bluetooth_device.connected;
|
|
||||||
let bluetooth_entry =
|
|
||||||
BluetoothEntry::new(ir.bluetooth_device, bluetooth_box.clone());
|
|
||||||
imp.available_devices
|
|
||||||
.borrow_mut()
|
|
||||||
.insert(path, bluetooth_entry.clone());
|
|
||||||
if connected {
|
|
||||||
imp.reset_bluetooth_connected_devices.add(&*bluetooth_entry);
|
|
||||||
} else {
|
|
||||||
imp.reset_bluetooth_available_devices.add(&*bluetooth_entry);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
true
|
|
||||||
});
|
});
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
println!("fail on bluetooth device add event");
|
println!("fail on bluetooth device add event");
|
||||||
|
@ -311,21 +305,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = conn.add_match(device_removed, move |ir: BluetoothDeviceRemoved, _, _| {
|
let res = conn.add_match(device_removed, move |ir: BluetoothDeviceRemoved, _, _| {
|
||||||
let bluetooth_box = device_removed_box.clone();
|
device_removed_handler(device_removed_box.clone(), ir)
|
||||||
glib::spawn_future(async move {
|
|
||||||
glib::idle_add_once(move || {
|
|
||||||
let imp = bluetooth_box.imp();
|
|
||||||
let mut map = imp.available_devices.borrow_mut();
|
|
||||||
if let Some(list_entry) = map.remove(&ir.bluetooth_device) {
|
|
||||||
if list_entry.imp().bluetooth_device.borrow().connected {
|
|
||||||
imp.reset_bluetooth_connected_devices.remove(&*list_entry);
|
|
||||||
} else {
|
|
||||||
imp.reset_bluetooth_available_devices.remove(&*list_entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
true
|
|
||||||
});
|
});
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
println!("fail on bluetooth device remove event");
|
println!("fail on bluetooth device remove event");
|
||||||
|
@ -333,43 +313,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = conn.add_match(device_changed, move |ir: BluetoothDeviceChanged, _, _| {
|
let res = conn.add_match(device_changed, move |ir: BluetoothDeviceChanged, _, _| {
|
||||||
let bluetooth_box = device_changed_box.clone();
|
device_changed_handler(device_changed_box.clone(), ir)
|
||||||
glib::spawn_future(async move {
|
|
||||||
glib::idle_add_once(move || {
|
|
||||||
let imp = bluetooth_box.imp();
|
|
||||||
let mut map = imp.available_devices.borrow_mut();
|
|
||||||
if let Some(list_entry) = map.get_mut(&ir.bluetooth_device.path) {
|
|
||||||
let mut existing_bluetooth_device =
|
|
||||||
list_entry.imp().bluetooth_device.borrow_mut();
|
|
||||||
if existing_bluetooth_device.connected != ir.bluetooth_device.connected {
|
|
||||||
if ir.bluetooth_device.connected {
|
|
||||||
imp.reset_bluetooth_available_devices.remove(&**list_entry);
|
|
||||||
imp.reset_bluetooth_connected_devices.add(&**list_entry);
|
|
||||||
} else {
|
|
||||||
imp.reset_bluetooth_connected_devices.remove(&**list_entry);
|
|
||||||
imp.reset_bluetooth_available_devices.add(&**list_entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if existing_bluetooth_device.bonded != ir.bluetooth_device.bonded {
|
|
||||||
if ir.bluetooth_device.bonded {
|
|
||||||
list_entry
|
|
||||||
.imp()
|
|
||||||
.remove_device_button
|
|
||||||
.borrow()
|
|
||||||
.set_sensitive(true);
|
|
||||||
} else {
|
|
||||||
list_entry
|
|
||||||
.imp()
|
|
||||||
.remove_device_button
|
|
||||||
.borrow()
|
|
||||||
.set_sensitive(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*existing_bluetooth_device = ir.bluetooth_device;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
true
|
|
||||||
});
|
});
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
println!("fail on bluetooth device remove event");
|
println!("fail on bluetooth device remove event");
|
||||||
|
@ -380,69 +324,171 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
|
||||||
let mut time = SystemTime::now();
|
let mut time = SystemTime::now();
|
||||||
let mut listener_active = true;
|
let mut listener_active = true;
|
||||||
|
|
||||||
loop {
|
bluetooth_listener_loop(
|
||||||
let _ = conn.process(Duration::from_millis(1000));
|
&conn,
|
||||||
if !listeners.bluetooth_listener.load(Ordering::SeqCst) {
|
listeners,
|
||||||
let res: Result<(), Error> =
|
proxy,
|
||||||
proxy.method_call(BLUETOOTH, "StopBluetoothListener", ());
|
bluetooth_box,
|
||||||
if res.is_err() {
|
loop_box,
|
||||||
show_error::<BluetoothBox>(
|
listener_active,
|
||||||
bluetooth_box.clone(),
|
time,
|
||||||
"Failed to stop bluetooth listener",
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
loop_box
|
|
||||||
.imp()
|
|
||||||
.reset_bluetooth_available_devices
|
|
||||||
.set_description(None);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if listener_active && time.elapsed().unwrap() > Duration::from_millis(10000) {
|
|
||||||
listener_active = false;
|
|
||||||
let instance_ref = loop_box.clone();
|
|
||||||
glib::spawn_future(async move {
|
|
||||||
glib::idle_add_once(move || {
|
|
||||||
instance_ref
|
|
||||||
.imp()
|
|
||||||
.reset_bluetooth_refresh_button
|
|
||||||
.set_sensitive(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
let res: Result<(), Error> = proxy.method_call(BLUETOOTH, "StopBluetoothScan", ());
|
|
||||||
if res.is_err() {
|
|
||||||
show_error::<BluetoothBox>(
|
|
||||||
bluetooth_box.clone(),
|
|
||||||
"Failed to stop bluetooth listener",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
loop_box
|
|
||||||
.imp()
|
|
||||||
.reset_bluetooth_available_devices
|
|
||||||
.set_description(None);
|
|
||||||
}
|
|
||||||
if !listener_active && listeners.bluetooth_scan_requested.load(Ordering::SeqCst) {
|
|
||||||
listeners
|
|
||||||
.bluetooth_scan_requested
|
|
||||||
.store(false, Ordering::SeqCst);
|
|
||||||
listener_active = true;
|
|
||||||
let res: Result<(), Error> =
|
|
||||||
proxy.method_call(BLUETOOTH, "StartBluetoothListener", ());
|
|
||||||
if res.is_err() {
|
|
||||||
show_error::<BluetoothBox>(
|
|
||||||
bluetooth_box.clone(),
|
|
||||||
"Failed to start bluetooth listener",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
loop_box
|
|
||||||
.imp()
|
|
||||||
.reset_bluetooth_available_devices
|
|
||||||
.set_description(Some("Scanning..."));
|
|
||||||
time = SystemTime::now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bluetooth_listener_loop(
|
||||||
|
conn: &Connection,
|
||||||
|
listeners: Arc<Listeners>,
|
||||||
|
proxy: dbus::blocking::Proxy<'_, &Connection>,
|
||||||
|
bluetooth_box: Arc<BluetoothBox>,
|
||||||
|
loop_box: Arc<BluetoothBox>,
|
||||||
|
mut listener_active: bool,
|
||||||
|
mut time: SystemTime,
|
||||||
|
) {
|
||||||
|
loop {
|
||||||
|
let _ = conn.process(Duration::from_millis(1000));
|
||||||
|
if !listeners.bluetooth_listener.load(Ordering::SeqCst) {
|
||||||
|
let res: Result<(), Error> = proxy.method_call(BLUETOOTH, "StopBluetoothListener", ());
|
||||||
|
if res.is_err() {
|
||||||
|
show_error::<BluetoothBox>(
|
||||||
|
bluetooth_box.clone(),
|
||||||
|
"Failed to stop bluetooth listener",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
loop_box
|
||||||
|
.imp()
|
||||||
|
.reset_bluetooth_available_devices
|
||||||
|
.set_description(None);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if listener_active && time.elapsed().unwrap() > Duration::from_millis(10000) {
|
||||||
|
listener_active = false;
|
||||||
|
let instance_ref = loop_box.clone();
|
||||||
|
glib::spawn_future(async move {
|
||||||
|
glib::idle_add_once(move || {
|
||||||
|
instance_ref
|
||||||
|
.imp()
|
||||||
|
.reset_bluetooth_refresh_button
|
||||||
|
.set_sensitive(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
let res: Result<(), Error> = proxy.method_call(BLUETOOTH, "StopBluetoothScan", ());
|
||||||
|
if res.is_err() {
|
||||||
|
show_error::<BluetoothBox>(
|
||||||
|
bluetooth_box.clone(),
|
||||||
|
"Failed to stop bluetooth listener",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
loop_box
|
||||||
|
.imp()
|
||||||
|
.reset_bluetooth_available_devices
|
||||||
|
.set_description(None);
|
||||||
|
}
|
||||||
|
if !listener_active && listeners.bluetooth_scan_requested.load(Ordering::SeqCst) {
|
||||||
|
listeners
|
||||||
|
.bluetooth_scan_requested
|
||||||
|
.store(false, Ordering::SeqCst);
|
||||||
|
listener_active = true;
|
||||||
|
let res: Result<(), Error> = proxy.method_call(BLUETOOTH, "StartBluetoothListener", ());
|
||||||
|
if res.is_err() {
|
||||||
|
show_error::<BluetoothBox>(
|
||||||
|
bluetooth_box.clone(),
|
||||||
|
"Failed to start bluetooth listener",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
loop_box
|
||||||
|
.imp()
|
||||||
|
.reset_bluetooth_available_devices
|
||||||
|
.set_description(Some("Scanning..."));
|
||||||
|
time = SystemTime::now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn device_changed_handler(
|
||||||
|
device_changed_box: Arc<BluetoothBox>,
|
||||||
|
ir: BluetoothDeviceChanged,
|
||||||
|
) -> bool {
|
||||||
|
let bluetooth_box = device_changed_box.clone();
|
||||||
|
glib::spawn_future(async move {
|
||||||
|
glib::idle_add_once(move || {
|
||||||
|
let imp = bluetooth_box.imp();
|
||||||
|
let mut map = imp.available_devices.borrow_mut();
|
||||||
|
if let Some(list_entry) = map.get_mut(&ir.bluetooth_device.path) {
|
||||||
|
let mut existing_bluetooth_device = list_entry.imp().bluetooth_device.borrow_mut();
|
||||||
|
if existing_bluetooth_device.connected != ir.bluetooth_device.connected {
|
||||||
|
if ir.bluetooth_device.connected {
|
||||||
|
imp.reset_bluetooth_available_devices.remove(&**list_entry);
|
||||||
|
imp.reset_bluetooth_connected_devices.add(&**list_entry);
|
||||||
|
} else {
|
||||||
|
imp.reset_bluetooth_connected_devices.remove(&**list_entry);
|
||||||
|
imp.reset_bluetooth_available_devices.add(&**list_entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if existing_bluetooth_device.bonded != ir.bluetooth_device.bonded {
|
||||||
|
if ir.bluetooth_device.bonded {
|
||||||
|
list_entry
|
||||||
|
.imp()
|
||||||
|
.remove_device_button
|
||||||
|
.borrow()
|
||||||
|
.set_sensitive(true);
|
||||||
|
} else {
|
||||||
|
list_entry
|
||||||
|
.imp()
|
||||||
|
.remove_device_button
|
||||||
|
.borrow()
|
||||||
|
.set_sensitive(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*existing_bluetooth_device = ir.bluetooth_device;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn device_removed_handler(
|
||||||
|
device_removed_box: Arc<BluetoothBox>,
|
||||||
|
ir: BluetoothDeviceRemoved,
|
||||||
|
) -> bool {
|
||||||
|
let bluetooth_box = device_removed_box.clone();
|
||||||
|
glib::spawn_future(async move {
|
||||||
|
glib::idle_add_once(move || {
|
||||||
|
let imp = bluetooth_box.imp();
|
||||||
|
let mut map = imp.available_devices.borrow_mut();
|
||||||
|
if let Some(list_entry) = map.remove(&ir.bluetooth_device) {
|
||||||
|
if list_entry.imp().bluetooth_device.borrow().connected {
|
||||||
|
imp.reset_bluetooth_connected_devices.remove(&*list_entry);
|
||||||
|
} else {
|
||||||
|
imp.reset_bluetooth_available_devices.remove(&*list_entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn device_added_handler(device_added_box: Arc<BluetoothBox>, ir: BluetoothDeviceAdded) -> bool {
|
||||||
|
let bluetooth_box = device_added_box.clone();
|
||||||
|
glib::spawn_future(async move {
|
||||||
|
glib::idle_add_once(move || {
|
||||||
|
let imp = bluetooth_box.imp();
|
||||||
|
let path = ir.bluetooth_device.path.clone();
|
||||||
|
let connected = ir.bluetooth_device.connected;
|
||||||
|
let bluetooth_entry = BluetoothEntry::new(ir.bluetooth_device, bluetooth_box.clone());
|
||||||
|
imp.available_devices
|
||||||
|
.borrow_mut()
|
||||||
|
.insert(path, bluetooth_entry.clone());
|
||||||
|
if connected {
|
||||||
|
imp.reset_bluetooth_connected_devices.add(&*bluetooth_entry);
|
||||||
|
} else {
|
||||||
|
imp.reset_bluetooth_available_devices.add(&*bluetooth_entry);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn get_connected_devices(bluetooth_box: Arc<BluetoothBox>) -> Vec<BluetoothDevice> {
|
fn get_connected_devices(bluetooth_box: Arc<BluetoothBox>) -> Vec<BluetoothDevice> {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
|
|
|
@ -64,7 +64,10 @@ impl BluetoothEntry {
|
||||||
.borrow()
|
.borrow()
|
||||||
.connect_clicked(move |_| {
|
.connect_clicked(move |_| {
|
||||||
let imp = entry_ref_remove.imp();
|
let imp = entry_ref_remove.imp();
|
||||||
remove_device_pairing(imp.bluetooth_device.borrow().path.clone(), bluetooth_box.clone());
|
remove_device_pairing(
|
||||||
|
imp.bluetooth_device.borrow().path.clone(),
|
||||||
|
bluetooth_box.clone(),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
let gesture = GestureClick::new();
|
let gesture = GestureClick::new();
|
||||||
// paired is not what we think
|
// paired is not what we think
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
pub mod output_stream_entry;
|
pub mod output_stream_entry;
|
||||||
pub mod output_stream_entry_impl;
|
pub mod output_stream_entry_impl;
|
||||||
pub mod source_box;
|
pub mod source_box;
|
||||||
|
mod source_box_event_handlers;
|
||||||
pub mod source_box_impl;
|
pub mod source_box_impl;
|
||||||
pub mod source_entry;
|
pub mod source_entry;
|
||||||
pub mod source_entry_impl;
|
pub mod source_entry_impl;
|
||||||
mod source_box_event_handlers;
|
|
||||||
|
|
|
@ -163,12 +163,7 @@ impl InputStreamEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_inputstream_volume(
|
fn set_inputstream_volume(value: f64, index: u32, channels: u16, output_box: Arc<SinkBox>) -> bool {
|
||||||
value: f64,
|
|
||||||
index: u32,
|
|
||||||
channels: u16,
|
|
||||||
output_box: Arc<SinkBox>,
|
|
||||||
) -> bool {
|
|
||||||
gio::spawn_blocking(move || {
|
gio::spawn_blocking(move || {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use adw::{ActionRow, ComboRow};
|
|
||||||
use adw::gdk::pango::EllipsizeMode;
|
use adw::gdk::pango::EllipsizeMode;
|
||||||
use adw::prelude::ListModelExtManual;
|
use adw::prelude::ListModelExtManual;
|
||||||
|
use adw::{ActionRow, ComboRow};
|
||||||
use glib::{Cast, Object};
|
use glib::{Cast, Object};
|
||||||
use gtk::{Align, SignalListItemFactory, StringObject};
|
|
||||||
use gtk::prelude::{GObjectPropertyExpressionExt, ListBoxRowExt, ListItemExt, WidgetExt};
|
use gtk::prelude::{GObjectPropertyExpressionExt, ListBoxRowExt, ListItemExt, WidgetExt};
|
||||||
|
use gtk::{Align, SignalListItemFactory, StringObject};
|
||||||
|
|
||||||
pub const DBUS_PATH: &str = "/org/Xetibo/ReSet/Daemon";
|
pub const DBUS_PATH: &str = "/org/Xetibo/ReSet/Daemon";
|
||||||
pub const WIRELESS: &str = "org.Xetibo.ReSet.Wireless";
|
pub const WIRELESS: &str = "org.Xetibo.ReSet.Wireless";
|
||||||
|
@ -17,14 +17,22 @@ pub fn create_dropdown_label_factory() -> SignalListItemFactory {
|
||||||
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
|
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
|
||||||
let label = gtk::Label::new(None);
|
let label = gtk::Label::new(None);
|
||||||
label.set_halign(Align::Start);
|
label.set_halign(Align::Start);
|
||||||
item.property_expression("item").chain_property::<StringObject>("string").bind(&label, "label", gtk::Widget::NONE);
|
item.property_expression("item")
|
||||||
|
.chain_property::<StringObject>("string")
|
||||||
|
.bind(&label, "label", gtk::Widget::NONE);
|
||||||
item.set_child(Some(&label));
|
item.set_child(Some(&label));
|
||||||
});
|
});
|
||||||
factory
|
factory
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_combo_row_ellipsis(element: ComboRow) {
|
pub fn set_combo_row_ellipsis(element: ComboRow) {
|
||||||
for (i, child) in element.child().unwrap().observe_children().iter::<Object>().enumerate() {
|
for (i, child) in element
|
||||||
|
.child()
|
||||||
|
.unwrap()
|
||||||
|
.observe_children()
|
||||||
|
.iter::<Object>()
|
||||||
|
.enumerate()
|
||||||
|
{
|
||||||
if i == 2 {
|
if i == 2 {
|
||||||
if let Ok(object) = child {
|
if let Ok(object) = child {
|
||||||
if let Some(item) = object.downcast_ref::<gtk::Box>() {
|
if let Some(item) = object.downcast_ref::<gtk::Box>() {
|
||||||
|
|
|
@ -66,12 +66,7 @@ impl SavedWifiEntry {
|
||||||
fn delete_connection(path: Path<'static>) {
|
fn delete_connection(path: Path<'static>) {
|
||||||
gio::spawn_blocking(move || {
|
gio::spawn_blocking(move || {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
let _: Result<(), Error> = proxy.method_call(WIRELESS, "DeleteConnection", (path,));
|
||||||
DBUS_PATH,
|
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let _: Result<(), Error> =
|
|
||||||
proxy.method_call(WIRELESS, "DeleteConnection", (path,));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,8 @@ type ResultType =
|
||||||
|
|
||||||
pub fn get_connection_settings(path: Path<'static>) -> ResetConnection {
|
pub fn get_connection_settings(path: Path<'static>) -> ResetConnection {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
let res: ResultType = proxy.method_call(WIRELESS, "GetConnectionSettings", (path,));
|
||||||
DBUS_PATH,
|
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let res: ResultType =
|
|
||||||
proxy.method_call(WIRELESS, "GetConnectionSettings", (path,));
|
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
ResetConnection::default();
|
ResetConnection::default();
|
||||||
}
|
}
|
||||||
|
|
|
@ -389,15 +389,8 @@ fn setup_callbacks(wifi_options: &Arc<WifiOptions>, path: Path<'static>) {
|
||||||
fn set_connection_settings(path: Path<'static>, prop: HashMap<String, PropMap>) {
|
fn set_connection_settings(path: Path<'static>, prop: HashMap<String, PropMap>) {
|
||||||
gio::spawn_blocking(move || {
|
gio::spawn_blocking(move || {
|
||||||
let conn = dbus::blocking::Connection::new_session().unwrap();
|
let conn = dbus::blocking::Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
let _: Result<(bool,), Error> =
|
||||||
DBUS_PATH,
|
proxy.method_call(WIRELESS, "SetConnectionSettings", (path, prop));
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let _: Result<(bool,), Error> = proxy.method_call(
|
|
||||||
WIRELESS,
|
|
||||||
"SetConnectionSettings",
|
|
||||||
(path, prop),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue