chore: snake_case all but UI templates

This commit is contained in:
Fabio Lenherr / DashieTM 2023-12-05 15:30:04 +01:00
parent 9f0ca6e8bf
commit 391182607d
55 changed files with 1471 additions and 1427 deletions

View file

@ -17,13 +17,13 @@ use gtk::{gio, StringObject, Widget};
use ReSet_Lib::bluetooth::bluetooth::{BluetoothAdapter, BluetoothDevice};
use ReSet_Lib::signals::{BluetoothDeviceAdded, BluetoothDeviceChanged, BluetoothDeviceRemoved};
use crate::components::base::listEntry::ListEntry;
use crate::components::base::list_entry::ListEntry;
use crate::components::base::utils::Listeners;
use crate::components::bluetooth::bluetoothBoxImpl;
use crate::components::bluetooth::bluetoothEntry::BluetoothEntry;
use crate::components::bluetooth::bluetooth_box_impl;
use crate::components::bluetooth::bluetooth_entry::BluetoothEntry;
glib::wrapper! {
pub struct BluetoothBox(ObjectSubclass<bluetoothBoxImpl::BluetoothBox>)
pub struct BluetoothBox(ObjectSubclass<bluetooth_box_impl::BluetoothBox>)
@extends gtk::Box, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
}
@ -34,13 +34,11 @@ unsafe impl Sync for BluetoothBox {}
impl BluetoothBox {
pub fn new(listeners: Arc<Listeners>) -> Arc<Self> {
let obj: Arc<Self> = Arc::new(Object::builder().build());
setupCallbacks(listeners, obj)
setup_callbacks(listeners, obj)
}
pub fn setupCallbacks(&self) {}
}
fn setupCallbacks(
fn setup_callbacks(
listeners: Arc<Listeners>,
bluetooth_box: Arc<BluetoothBox>,
) -> Arc<BluetoothBox> {
@ -58,21 +56,28 @@ fn setupCallbacks(
imp.resetBluetoothSwitch.connect_state_set(move |_, state| {
if !state {
let imp = bluetooth_box_ref.imp();
for x in imp.resetBluetoothConnectedDevices.observe_children().iter::<Object>() {
if let Ok(entry) = x { // todo test this
if let Some(item) = entry.downcast_ref::<Widget>() {
imp.resetBluetoothAvailableDevices.remove(item);
}
for x in imp
.resetBluetoothConnectedDevices
.observe_children()
.iter::<Object>()
.flatten()
{
// todo test this
if let Some(item) = x.downcast_ref::<Widget>() {
imp.resetBluetoothAvailableDevices.remove(item);
}
};
}
listeners.bluetooth_listener.store(false, Ordering::SeqCst);
set_adapter_enabled(
imp.resetCurrentBluetoothAdapter.borrow().path.clone(),
imp.reset_current_bluetooth_adapter.borrow().path.clone(),
false,
);
} else {
let imp = bluetooth_box_ref.imp();
set_adapter_enabled(imp.resetCurrentBluetoothAdapter.borrow().path.clone(), true);
set_adapter_enabled(
imp.reset_current_bluetooth_adapter.borrow().path.clone(),
true,
);
start_bluetooth_listener(listeners.clone(), bluetooth_box_ref.clone());
}
glib::Propagation::Proceed
@ -87,10 +92,10 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
let adapters = get_bluetooth_adapters();
{
let imp = bluetooth_box.imp();
let list = imp.resetModelList.write().unwrap();
let mut model_index = imp.resetModelIndex.write().unwrap();
let mut map = imp.resetBluetoothAdapters.write().unwrap();
imp.resetCurrentBluetoothAdapter
let list = imp.reset_model_list.write().unwrap();
let mut model_index = imp.reset_model_index.write().unwrap();
let mut map = imp.reset_bluetooth_adapters.write().unwrap();
imp.reset_current_bluetooth_adapter
.replace(adapters.last().unwrap().clone());
for (index, adapter) in adapters.into_iter().enumerate() {
list.append(&adapter.alias);
@ -102,10 +107,10 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
glib::idle_add_once(move || {
let imp = ref_box.imp();
let list = imp.resetModelList.read().unwrap();
let list = imp.reset_model_list.read().unwrap();
imp.resetBluetoothAdapter.set_model(Some(&*list));
let map = imp.resetBluetoothAdapters.read().unwrap();
let device = imp.resetCurrentBluetoothAdapter.borrow();
let map = imp.reset_bluetooth_adapters.read().unwrap();
let device = imp.reset_current_bluetooth_adapter.borrow();
if let Some(index) = map.get(&device.alias) {
imp.resetBluetoothAdapter.set_selected(index.1);
}
@ -119,7 +124,7 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
let selected = selected.downcast_ref::<StringObject>().unwrap();
let selected = selected.string().to_string();
let device = imp.resetBluetoothAdapters.read().unwrap();
let device = imp.reset_bluetooth_adapters.read().unwrap();
let device = device.get(&selected);
if device.is_none() {
return;
@ -133,7 +138,7 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
let connected = device.connected;
let bluetooth_entry = Arc::new(BluetoothEntry::new(&device));
let entry = Arc::new(ListEntry::new(&*bluetooth_entry));
imp.availableDevices
imp.available_devices
.borrow_mut()
.insert(path, (bluetooth_entry.clone(), entry.clone(), device));
if connected {
@ -197,7 +202,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
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.availableDevices.borrow_mut().insert(
imp.available_devices.borrow_mut().insert(
path,
(bluetooth_entry.clone(), entry.clone(), ir.bluetooth_device),
);
@ -221,7 +226,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
glib::spawn_future(async move {
glib::idle_add_once(move || {
let imp = bluetooth_box.imp();
let map = imp.availableDevices.borrow_mut();
let map = imp.available_devices.borrow_mut();
if let Some(list_entry) = map.get(&ir.bluetooth_device) {
imp.resetBluetoothConnectedDevices.remove(&*list_entry.1);
}
@ -240,7 +245,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
glib::spawn_future(async move {
glib::idle_add_once(move || {
let imp = bluetooth_box.imp();
let map = imp.availableDevices.borrow_mut();
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 ir.bluetooth_device.connected {
@ -279,13 +284,16 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
glib::spawn_future(async move {
glib::idle_add_once(move || {
let imp = loop_box.imp();
for x in imp.resetBluetoothAvailableDevices.observe_children().iter::<Object>() {
if let Ok(entry) = x { // todo test this
if let Some(item) = entry.downcast_ref::<Widget>() {
imp.resetBluetoothAvailableDevices.remove(item);
}
for x in imp
.resetBluetoothAvailableDevices
.observe_children()
.iter::<Object>()
.flatten()
{
if let Some(item) = x.downcast_ref::<Widget>() {
imp.resetBluetoothAvailableDevices.remove(item);
}
};
}
});
});
println!("stopping bluetooth listener");

View file

@ -1,16 +1,16 @@
use adw::{ActionRow, ComboRow};
use dbus::Path;
use gtk::subclass::prelude::*;
use gtk::{glib, CompositeTemplate, ListBox, Switch, Button};
use gtk::{glib, Button, CompositeTemplate, Switch};
use gtk::{prelude::*, StringList};
use std::cell::RefCell;
use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use ReSet_Lib::bluetooth::bluetooth::{BluetoothAdapter, BluetoothDevice};
use crate::components::base::listEntry::ListEntry;
use crate::components::bluetooth::bluetoothBox;
use crate::components::bluetooth::bluetoothEntry::BluetoothEntry;
use crate::components::base::list_entry::ListEntry;
use crate::components::bluetooth::bluetooth_box;
use crate::components::bluetooth::bluetooth_entry::BluetoothEntry;
type BluetoothMap =
RefCell<HashMap<Path<'static>, (Arc<BluetoothEntry>, Arc<ListEntry>, BluetoothDevice)>>;
@ -33,19 +33,19 @@ pub struct BluetoothBox {
pub resetVisibility: TemplateChild<ActionRow>,
#[template_child]
pub resetBluetoothMainTab: TemplateChild<ListEntry>,
pub availableDevices: BluetoothMap,
pub connectedDevices: BluetoothMap,
pub resetBluetoothAdapters: Arc<RwLock<HashMap<String, (BluetoothAdapter, u32)>>>,
pub resetCurrentBluetoothAdapter: Arc<RefCell<BluetoothAdapter>>,
pub resetModelList: Arc<RwLock<StringList>>,
pub resetModelIndex: Arc<RwLock<u32>>,
pub available_devices: BluetoothMap,
pub connected_devices: BluetoothMap,
pub reset_bluetooth_adapters: Arc<RwLock<HashMap<String, (BluetoothAdapter, u32)>>>,
pub reset_current_bluetooth_adapter: Arc<RefCell<BluetoothAdapter>>,
pub reset_model_list: Arc<RwLock<StringList>>,
pub reset_model_index: Arc<RwLock<u32>>,
}
#[glib::object_subclass]
impl ObjectSubclass for BluetoothBox {
const ABSTRACT: bool = false;
const NAME: &'static str = "resetBluetooth";
type Type = bluetoothBox::BluetoothBox;
type Type = bluetooth_box::BluetoothBox;
type ParentType = gtk::Box;
fn class_init(klass: &mut Self::Class) {
@ -62,8 +62,6 @@ impl ObjectSubclass for BluetoothBox {
impl ObjectImpl for BluetoothBox {
fn constructed(&self) {
self.parent_constructed();
let obj = self.obj();
obj.setupCallbacks();
}
}

View file

@ -1,7 +1,7 @@
use std::sync::Arc;
use std::time::Duration;
use crate::components::bluetooth::bluetoothEntryImpl;
use crate::components::bluetooth::bluetooth_entry_impl;
use adw::glib;
use adw::glib::Object;
use adw::subclass::prelude::ObjectSubclassIsExt;
@ -12,7 +12,7 @@ use gtk::{gio, GestureClick};
use ReSet_Lib::bluetooth::bluetooth::BluetoothDevice;
glib::wrapper! {
pub struct BluetoothEntry(ObjectSubclass<bluetoothEntryImpl::BluetoothEntry>)
pub struct BluetoothEntry(ObjectSubclass<bluetooth_entry_impl::BluetoothEntry>)
@extends gtk::Box, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget;
}
@ -23,28 +23,28 @@ unsafe impl Sync for BluetoothEntry {}
impl BluetoothEntry {
pub fn new(device: &BluetoothDevice) -> Self {
let entry: BluetoothEntry = Object::builder().build();
let entryImp = entry.imp();
entryImp.resetBluetoothLabel.get().set_text(&device.alias);
entryImp
let entry_imp = entry.imp();
entry_imp.resetBluetoothLabel.get().set_text(&device.alias);
entry_imp
.resetBluetoothAddress
.get()
.set_text(&device.address);
if device.icon.is_empty() {
entryImp
entry_imp
.resetBluetoothDeviceType
.set_icon_name(Some("dialog-question-symbolic"));
} else {
entryImp
entry_imp
.resetBluetoothDeviceType
.set_icon_name(Some(&device.icon));
}
if device.paired {
entryImp.resetBluetoothButton.set_sensitive(true);
entry_imp.resetBluetoothButton.set_sensitive(true);
} else {
entryImp.resetBluetoothButton.set_sensitive(false);
entry_imp.resetBluetoothButton.set_sensitive(false);
}
let path = Arc::new(device.path.clone());
entryImp.resetBluetoothButton.connect_clicked(move |_| {
entry_imp.resetBluetoothButton.connect_clicked(move |_| {
remove_device_pairing((*path).clone());
});
let gesture = GestureClick::new();

View file

@ -1,4 +1,4 @@
use crate::components::bluetooth::bluetoothEntry;
use crate::components::bluetooth::bluetooth_entry;
use gtk::subclass::prelude::*;
use gtk::{glib, Button, CompositeTemplate, Image, Label};
use std::cell::RefCell;
@ -15,14 +15,14 @@ pub struct BluetoothEntry {
pub resetBluetoothAddress: TemplateChild<Label>,
#[template_child]
pub resetBluetoothButton: TemplateChild<Button>,
pub deviceName: RefCell<String>,
pub device_name: RefCell<String>,
}
#[glib::object_subclass]
impl ObjectSubclass for BluetoothEntry {
const ABSTRACT: bool = false;
const NAME: &'static str = "resetBluetoothEntry";
type Type = bluetoothEntry::BluetoothEntry;
type Type = bluetooth_entry::BluetoothEntry;
type ParentType = gtk::Box;
fn class_init(klass: &mut Self::Class) {

View file

@ -1,5 +1,4 @@
#![allow(non_snake_case)]
pub mod bluetoothBox;
pub mod bluetoothBoxImpl;
pub mod bluetoothEntry;
pub mod bluetoothEntryImpl;
pub mod bluetooth_box;
pub mod bluetooth_box_impl;
pub mod bluetooth_entry;
pub mod bluetooth_entry_impl;