mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-09-16 22:59:16 +02:00
chore: Code cleanup
This commit is contained in:
parent
f8c27fd498
commit
921d5e7fe6
27 changed files with 304 additions and 234 deletions
|
@ -5,8 +5,8 @@ use adw::glib::Object;
|
|||
use adw::prelude::{ComboRowExt, PreferencesRowExt};
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::Error;
|
||||
use glib::{Cast, clone};
|
||||
use glib::subclass::types::ObjectSubclassIsExt;
|
||||
use glib::{clone, Cast};
|
||||
use gtk::{gio, StringList, StringObject};
|
||||
use ReSet_Lib::audio::audio::Card;
|
||||
|
||||
|
@ -29,10 +29,9 @@ impl CardEntry {
|
|||
let imp = entry.imp();
|
||||
let mut map = imp.resetCardMap.borrow_mut();
|
||||
entry.set_title(&card.name);
|
||||
let mut i: u32 = 0;
|
||||
let mut index: u32 = 0;
|
||||
let list = StringList::new(&[]);
|
||||
for profile in card.profiles.iter() {
|
||||
for (i, profile) in (0_u32..).zip(card.profiles.iter()) {
|
||||
if profile.name == card.active_profile {
|
||||
index = i;
|
||||
}
|
||||
|
@ -41,23 +40,22 @@ impl CardEntry {
|
|||
profile.description.clone(),
|
||||
(card.index, profile.name.clone()),
|
||||
);
|
||||
i += 1;
|
||||
}
|
||||
entry.set_model(Some(&list));
|
||||
entry.set_selected(index);
|
||||
entry.set_use_subtitle(true);
|
||||
entry.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());
|
||||
}));
|
||||
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.set_factory(Some(&createDropdownLabelFactory()));
|
||||
}
|
||||
entry
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use adw::ComboRow;
|
||||
use adw::subclass::action_row::ActionRowImpl;
|
||||
use adw::subclass::preferences_row::PreferencesRowImpl;
|
||||
use adw::subclass::prelude::ComboRowImpl;
|
||||
use adw::ComboRow;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, CompositeTemplate};
|
||||
|
|
|
@ -13,7 +13,12 @@ glib::wrapper! {
|
|||
impl Popup {
|
||||
pub fn new() -> Self {
|
||||
let popup: Popup = Object::builder().build();
|
||||
// popup.set_child(child);
|
||||
popup
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Popup {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,4 +17,3 @@ impl SettingBox {
|
|||
entry
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -394,11 +394,11 @@ pub fn start_audio_listener(
|
|||
|
||||
let mut conn = start_dbus_audio_listener(conn);
|
||||
|
||||
if sink_box.is_some() {
|
||||
conn = start_output_box_listener(conn, sink_box.unwrap());
|
||||
if let Some(sink_box) = sink_box {
|
||||
conn = start_output_box_listener(conn, sink_box);
|
||||
}
|
||||
if source_box.is_some() {
|
||||
conn = start_input_box_listener(conn, source_box.unwrap());
|
||||
if let Some(source_box) = source_box {
|
||||
conn = start_input_box_listener(conn, source_box);
|
||||
}
|
||||
|
||||
listeners.pulse_listener.store(true, Ordering::SeqCst);
|
||||
|
@ -435,4 +435,3 @@ fn stop_dbus_audio_listener(conn: Connection) {
|
|||
);
|
||||
let _: Result<(), Error> = proxy.method_call("org.Xetibo.ReSetAudio", "StopAudioListener", ());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue