mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-09-16 22:59:16 +02:00
feat: Add initial Bluetooth functionality
This commit is contained in:
parent
03fc3790c0
commit
9108ab0d74
14 changed files with 514 additions and 20 deletions
74
src/components/base/cardEntry.rs
Normal file
74
src/components/base/cardEntry.rs
Normal file
|
@ -0,0 +1,74 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::Error;
|
||||
use glib::subclass::types::ObjectSubclassIsExt;
|
||||
use glib::{clone, Cast};
|
||||
use gtk::{gio, StringObject};
|
||||
use ReSet_Lib::audio::audio::Card;
|
||||
|
||||
use super::cardEntryImpl;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct CardEntry(ObjectSubclass<cardEntryImpl::CardEntry>)
|
||||
@extends gtk::Box, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
|
||||
}
|
||||
|
||||
impl CardEntry {
|
||||
pub fn new(card: Card) -> Self {
|
||||
let entry: Self = Object::builder().build();
|
||||
{
|
||||
let imp = entry.imp();
|
||||
let mut map = imp.resetCardMap.borrow_mut();
|
||||
imp.resetCardName.set_text(&card.name);
|
||||
let mut i: u32 = 0;
|
||||
let mut index: u32 = 0;
|
||||
for profile in card.profiles.iter() {
|
||||
if profile.name == card.active_profile {
|
||||
index = i;
|
||||
}
|
||||
imp.resetCardList.append(&profile.description);
|
||||
map.insert(
|
||||
profile.description.clone(),
|
||||
(card.index, profile.name.clone()),
|
||||
);
|
||||
i += 1;
|
||||
}
|
||||
imp.resetCardDropdown.set_selected(index);
|
||||
imp.resetCardDropdown
|
||||
.connect_selected_notify(clone!(@weak imp => move |dropdown| {
|
||||
let selected = dropdown.selected_item();
|
||||
if selected.is_none() {
|
||||
return;
|
||||
}
|
||||
let selected = selected.unwrap();
|
||||
let selected = selected.downcast_ref::<StringObject>().unwrap();
|
||||
let selected = selected.string().to_string();
|
||||
let map = imp.resetCardMap.borrow();
|
||||
let (device_index, profile_name) = map.get(&selected).unwrap();
|
||||
set_card_profile_of_device(*device_index, profile_name.clone());
|
||||
}));
|
||||
}
|
||||
entry
|
||||
}
|
||||
}
|
||||
|
||||
fn set_card_profile_of_device(device_index: u32, profile_name: String) -> bool {
|
||||
gio::spawn_blocking(move || {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.xetibo.ReSet",
|
||||
"/org/xetibo/ReSet",
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let _: Result<(), Error> = proxy.method_call(
|
||||
"org.xetibo.ReSet",
|
||||
"SetCardProfileOfDevice",
|
||||
(device_index, profile_name),
|
||||
);
|
||||
});
|
||||
true
|
||||
}
|
52
src/components/base/cardEntryImpl.rs
Normal file
52
src/components/base/cardEntryImpl.rs
Normal file
|
@ -0,0 +1,52 @@
|
|||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::components::base::listEntry::ListEntry;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, CompositeTemplate, TemplateChild, Label, DropDown, StringList};
|
||||
|
||||
use super::cardEntry;
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Default, CompositeTemplate)]
|
||||
#[template(resource = "/org/Xetibo/ReSet/resetCardEntry.ui")]
|
||||
pub struct CardEntry {
|
||||
#[template_child]
|
||||
pub resetCardName: TemplateChild<Label>,
|
||||
#[template_child]
|
||||
pub resetCardDropdown: TemplateChild<DropDown>,
|
||||
#[template_child]
|
||||
pub resetCardList: TemplateChild<StringList>,
|
||||
// first string is the alias name, the first return string is the index of the adapter and the
|
||||
// second the name of the profile
|
||||
pub resetCardMap: RefCell<HashMap<String, (u32, String)>>
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for CardEntry {
|
||||
const NAME: &'static str = "resetCardEntry";
|
||||
type Type = cardEntry::CardEntry;
|
||||
type ParentType = gtk::Box;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.bind_template();
|
||||
}
|
||||
|
||||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
||||
obj.init_template();
|
||||
}
|
||||
}
|
||||
|
||||
impl BoxImpl for CardEntry {}
|
||||
|
||||
impl ObjectImpl for CardEntry {
|
||||
fn constructed(&self) {}
|
||||
}
|
||||
|
||||
impl ListBoxRowImpl for CardEntry {}
|
||||
|
||||
impl WidgetImpl for CardEntry {}
|
||||
|
||||
impl WindowImpl for CardEntry {}
|
||||
|
||||
impl ApplicationWindowImpl for CardEntry {}
|
|
@ -1,6 +1,8 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use crate::components::base::listEntry;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, CompositeTemplate};
|
||||
use gtk::{glib, CompositeTemplate, DropDown, Label, StringList};
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Default, CompositeTemplate)]
|
||||
|
|
|
@ -5,3 +5,5 @@ pub mod listEntryImpl;
|
|||
pub mod popup;
|
||||
pub mod popupImpl;
|
||||
pub mod utils;
|
||||
pub mod cardEntry;
|
||||
pub mod cardEntryImpl;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue