mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-07-03 08:47:45 +02:00
Dynamically add bluetooth devices
Add scrolling for wifi Improve audio ui a little
This commit is contained in:
parent
13084ed86d
commit
e34e8ce80f
11 changed files with 263 additions and 141 deletions
|
@ -1,6 +1,10 @@
|
|||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
|
||||
use crate::components::bluetooth::bluetoothBoxImpl;
|
||||
use crate::components::bluetooth::bluetoothEntry::BluetoothEntry;
|
||||
use crate::components::bluetooth::bluetoothEntryImpl::DeviceTypes;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct BluetoothBox(ObjectSubclass<bluetoothBoxImpl::BluetoothBox>)
|
||||
|
@ -13,4 +17,28 @@ impl BluetoothBox {
|
|||
pub fn new() -> Self {
|
||||
Object::builder().build()
|
||||
}
|
||||
|
||||
pub fn scanForDevices(&self) {
|
||||
let selfImp = self.imp();
|
||||
let mut wifiEntries = selfImp.availableDevices.borrow_mut();
|
||||
wifiEntries.push(BluetoothEntry::new(DeviceTypes::Mouse, "ina mouse"));
|
||||
wifiEntries.push(BluetoothEntry::new(DeviceTypes::Keyboard, "inaboard"));
|
||||
wifiEntries.push(BluetoothEntry::new(DeviceTypes::Controller, "ina controller"));
|
||||
wifiEntries.push(BluetoothEntry::new(DeviceTypes::Controller, "ina best waifu"));
|
||||
|
||||
for wifiEntry in wifiEntries.iter() {
|
||||
selfImp.resetBluetoothAvailableDevices.append(wifiEntry);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn addConnectedDevices(&self) {
|
||||
let selfImp = self.imp();
|
||||
let mut wifiEntries = selfImp.connectedDevices.borrow_mut();
|
||||
wifiEntries.push(BluetoothEntry::new(DeviceTypes::Mouse, "why are we still here?"));
|
||||
wifiEntries.push(BluetoothEntry::new(DeviceTypes::Keyboard, "just to suffer?"));
|
||||
|
||||
for wifiEntry in wifiEntries.iter() {
|
||||
selfImp.resetBluetoothConnectedDevices.append(wifiEntry);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use std::cell::RefCell;
|
||||
use gtk::{CompositeTemplate, glib, ListBox, Switch};
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
|
@ -15,6 +16,8 @@ pub struct BluetoothBox {
|
|||
pub resetBluetoothAvailableDevices: TemplateChild<ListBox>,
|
||||
#[template_child]
|
||||
pub resetBluetoothConnectedDevices: TemplateChild<ListBox>,
|
||||
pub availableDevices: RefCell<Vec<BluetoothEntry>>,
|
||||
pub connectedDevices: RefCell<Vec<BluetoothEntry>>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
|
@ -36,6 +39,9 @@ impl ObjectSubclass for BluetoothBox {
|
|||
impl ObjectImpl for BluetoothBox {
|
||||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
let obj = self.obj();
|
||||
obj.scanForDevices();
|
||||
obj.addConnectedDevices();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
use crate::components::bluetooth::bluetoothEntryImpl;
|
||||
use crate::components::bluetooth::bluetoothEntryImpl::DeviceTypes;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct BluetoothEntry(ObjectSubclass<bluetoothEntryImpl::BluetoothEntry>)
|
||||
|
@ -9,7 +11,21 @@ glib::wrapper! {
|
|||
}
|
||||
|
||||
impl BluetoothEntry {
|
||||
pub fn new() -> Self {
|
||||
Object::builder().build()
|
||||
pub fn new(deviceType: DeviceTypes, name: &str) -> Self {
|
||||
let entry: BluetoothEntry = Object::builder().build();
|
||||
let entryImp = entry.imp();
|
||||
entryImp.resetBluetoothLabel.get().set_text(name);
|
||||
entryImp.resetBluetoothDeviceType.get().set_from_icon_name(match deviceType {
|
||||
DeviceTypes::Mouse => Some("input-mouse-symbolic"),
|
||||
DeviceTypes::Keyboard => Some("input-keyboard-symbolic"),
|
||||
DeviceTypes::Headset => Some("audio-headset-symbolic"),
|
||||
DeviceTypes::Controller => Some("input-gaming-symbolic"),
|
||||
DeviceTypes::None => Some("text-x-generic-symbolic") // no generic bluetooth device icon found
|
||||
});
|
||||
{
|
||||
let mut wifiName = entryImp.deviceName.borrow_mut();
|
||||
*wifiName = String::from(name);
|
||||
}
|
||||
entry
|
||||
}
|
||||
}
|
|
@ -1,7 +1,17 @@
|
|||
use std::cell::RefCell;
|
||||
use gtk::{Button, CompositeTemplate, glib, Image, Label};
|
||||
use gtk::subclass::prelude::*;
|
||||
use crate::components::bluetooth::bluetoothEntry;
|
||||
|
||||
#[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")]
|
||||
|
@ -12,6 +22,7 @@ pub struct BluetoothEntry {
|
|||
pub resetBluetoothLabel: TemplateChild<Label>,
|
||||
#[template_child]
|
||||
pub resetBluetoothButton: TemplateChild<Button>,
|
||||
pub deviceName: RefCell<String>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue