mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-16 17:58:33 +02:00
wip: format and fix warnings
This commit is contained in:
parent
472584649b
commit
39fd353c7e
|
@ -2,13 +2,13 @@ use std::{sync::Arc, time::Duration};
|
|||
|
||||
use adw::traits::ComboRowExt;
|
||||
use dbus::{
|
||||
arg::{Arg, Get, ReadAll},
|
||||
arg::{Arg, Get},
|
||||
blocking::Connection,
|
||||
Error,
|
||||
};
|
||||
use gtk::{
|
||||
gio,
|
||||
prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt},
|
||||
prelude::{ButtonExt, CheckButtonExt, RangeExt},
|
||||
};
|
||||
use re_set_lib::audio::audio_structures::AudioObject;
|
||||
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
use std::sync::RwLock;
|
||||
use std::time::Duration;
|
||||
use std::{cell::RefCell, sync::Arc, time::SystemTime};
|
||||
|
||||
use adw::prelude::{ButtonExt, CheckButtonExt, PreferencesRowExt, RangeExt};
|
||||
use adw::{ActionRow, ComboRow, PreferencesGroup};
|
||||
use dbus::arg::{Arg, Get, ReadAll};
|
||||
use glib::clone::{Downgrade, Upgrade};
|
||||
use glib::{clone, Propagation};
|
||||
use dbus::arg::{Arg, Get};
|
||||
use glib::Propagation;
|
||||
use glib::{
|
||||
object::{IsA, IsClass, ObjectSubclassIs, ParentClassIs},
|
||||
subclass::types::{InstanceStruct, InstanceStructExt, ObjectSubclass, ObjectSubclassType},
|
||||
object::{IsA, IsClass},
|
||||
Object,
|
||||
};
|
||||
use gtk::{gio, Button, CheckButton, Label, Scale, StringList, TemplateChild};
|
||||
use re_set_lib::audio::audio_structures::{AudioObject, Source, Volume};
|
||||
use re_set_lib::audio::audio_structures::AudioObject;
|
||||
|
||||
use crate::components::base::error::ReSetError;
|
||||
use crate::components::base::error_impl::ReSetErrorImpl;
|
||||
|
@ -35,9 +32,11 @@ pub trait AudioBox<AudioBoxImpl> {
|
|||
}
|
||||
|
||||
pub type AudioEntryMap<T> = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<T>, String)>>>;
|
||||
#[allow(dead_code)]
|
||||
pub type AudioStreamEntryMap<T> = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<T>)>>>;
|
||||
pub type AudioMap = Arc<RwLock<HashMap<String, (u32, String)>>>;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub trait AudioBoxImpl<OBJ, ENTRY, STREAMENTRY> {
|
||||
fn audio_object_row(&self) -> &TemplateChild<ActionRow>;
|
||||
fn cards_row(&self) -> &TemplateChild<ActionRow>;
|
||||
|
|
|
@ -1,22 +1,17 @@
|
|||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::components::audio::generic_entry::{new_entry, Audio, AudioImpl};
|
||||
use crate::components::audio::generic_entry::{new_entry, Audio};
|
||||
use crate::components::base::error_impl::show_error;
|
||||
use crate::components::utils::set_action_row_ellipsis;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{ButtonExt, CheckButtonExt, PreferencesRowExt, RangeExt};
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::Error;
|
||||
use glib::subclass::types::ObjectSubclassIsExt;
|
||||
use glib::{clone, Propagation};
|
||||
use gtk::{gio, CheckButton};
|
||||
use re_set_lib::audio::audio_structures::Source;
|
||||
|
||||
use crate::components::utils::{AUDIO, BASE, DBUS_PATH};
|
||||
|
||||
use super::source_box::SourceBox;
|
||||
use super::source_box_utils::refresh_default_source;
|
||||
use super::source_entry_impl;
|
||||
|
||||
glib::wrapper! {
|
||||
|
@ -49,84 +44,6 @@ impl SourceEntry {
|
|||
super::source_box_impl::SourceBox,
|
||||
>(is_default, check_group, source, input_box)
|
||||
}
|
||||
// pub fn new(
|
||||
// is_default: bool,
|
||||
// check_group: Arc<CheckButton>,
|
||||
// source: Source,
|
||||
// input_box: Arc<SourceBox>,
|
||||
// ) -> Self {
|
||||
// let obj: Self = Object::builder().build();
|
||||
// // TODO use event callback for progress bar -> this is the "im speaking" indicator
|
||||
// {
|
||||
// let imp = obj.imp();
|
||||
// imp.reset_source_name
|
||||
// .set_title(source.alias.clone().as_str());
|
||||
// let name = Arc::new(source.name.clone());
|
||||
// let volume = source.volume.first().unwrap_or(&0_u32);
|
||||
// let fraction = (*volume as f64 / 655.36).round();
|
||||
// let percentage = (fraction).to_string() + "%";
|
||||
// let input_box_slider = input_box.clone();
|
||||
// let input_box_ref = input_box.clone();
|
||||
// imp.reset_volume_percentage.set_text(&percentage);
|
||||
// imp.reset_volume_slider.set_value(*volume as f64);
|
||||
// imp.source.replace(source);
|
||||
// imp.reset_volume_slider.connect_change_value(
|
||||
// clone!(@weak imp => @default-return Propagation::Stop, move |_, _, value| {
|
||||
// let fraction = (value / 655.36).round();
|
||||
// let percentage = (fraction).to_string() + "%";
|
||||
// imp.reset_volume_percentage.set_text(&percentage);
|
||||
// let source = imp.source.borrow();
|
||||
// let index = source.index;
|
||||
// let channels = source.channels;
|
||||
// {
|
||||
// let mut time = imp.volume_time_stamp.borrow_mut();
|
||||
// if time.is_some()
|
||||
// && time.unwrap().elapsed().unwrap() < Duration::from_millis(50)
|
||||
// {
|
||||
// return Propagation::Proceed;
|
||||
// }
|
||||
// *time = Some(SystemTime::now());
|
||||
// }
|
||||
// set_source_volume(value, index, channels, input_box_slider.clone());
|
||||
// Propagation::Proceed
|
||||
// }),
|
||||
// );
|
||||
// imp.reset_selected_source.set_group(Some(&*check_group));
|
||||
// if is_default {
|
||||
// imp.reset_selected_source.set_active(true);
|
||||
// } else {
|
||||
// imp.reset_selected_source.set_active(false);
|
||||
// }
|
||||
// imp.reset_selected_source.connect_toggled(move |button| {
|
||||
// let input_box = input_box.clone();
|
||||
// if button.is_active() {
|
||||
// let name = name.clone();
|
||||
// gio::spawn_blocking(move || {
|
||||
// let result = set_default_source(name, input_box.clone());
|
||||
// if result.is_none() {
|
||||
// return;
|
||||
// }
|
||||
// refresh_default_source(result.unwrap(), input_box, true);
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// imp.reset_source_mute
|
||||
// .connect_clicked(clone!(@weak imp => move |_| {
|
||||
// let mut source = imp.source.borrow_mut();
|
||||
// source.muted = !source.muted;
|
||||
// if source.muted {
|
||||
// imp.reset_source_mute
|
||||
// .set_icon_name("microphone-disabled-symbolic");
|
||||
// } else {
|
||||
// imp.reset_source_mute
|
||||
// .set_icon_name("audio-input-microphone-symbolic");
|
||||
// }
|
||||
// toggle_source_mute(source.index, source.muted, input_box_ref.clone());
|
||||
// }));
|
||||
// set_action_row_ellipsis(imp.reset_source_name.get());
|
||||
// }
|
||||
// obj
|
||||
// }
|
||||
}
|
||||
|
||||
pub fn set_source_volume(value: f64, index: u32, channels: u16, input_box: Arc<SourceBox>) -> bool {
|
||||
|
|
|
@ -17,6 +17,7 @@ use glib::Variant;
|
|||
use gtk::gio;
|
||||
use gtk::prelude::ActionableExt;
|
||||
|
||||
use crate::components::audio::generic_entry::AudioBox;
|
||||
use crate::components::base::error_impl::ReSetErrorImpl;
|
||||
use crate::components::utils::BASE;
|
||||
use crate::components::utils::DBUS_PATH;
|
||||
|
@ -52,6 +53,12 @@ impl ReSetErrorImpl for SinkBox {
|
|||
}
|
||||
}
|
||||
|
||||
impl AudioBox<super::sink_box_impl::SinkBox> for SinkBox {
|
||||
fn box_imp(&self) -> &super::sink_box_impl::SinkBox {
|
||||
self.imp()
|
||||
}
|
||||
}
|
||||
|
||||
impl SinkBox {
|
||||
pub fn new() -> Self {
|
||||
let obj: Self = Object::builder().build();
|
||||
|
|
|
@ -99,12 +99,12 @@ pub fn sink_added_handler(sink_box: Arc<SinkBox>, ir: SinkAdded) -> bool {
|
|||
if sink_box_imp.reset_default_sink.borrow().name == ir.sink.name {
|
||||
is_default = true;
|
||||
}
|
||||
let sink_entry = Arc::new(SinkEntry::new(
|
||||
let sink_entry = SinkEntry::new(
|
||||
is_default,
|
||||
sink_box_imp.reset_default_check_button.clone(),
|
||||
ir.sink,
|
||||
sink_box.clone(),
|
||||
));
|
||||
);
|
||||
let sink_clone = sink_entry.clone();
|
||||
let entry = Arc::new(ListEntry::new(&*sink_entry));
|
||||
entry.set_activatable(false);
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::collections::HashMap;
|
|||
use std::sync::{Arc, RwLock};
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::components::audio::generic_entry::AudioBoxImpl;
|
||||
use crate::components::audio::output::input_stream_entry::InputStreamEntry;
|
||||
use crate::components::base::error::ReSetError;
|
||||
use crate::components::base::list_entry::ListEntry;
|
||||
|
@ -93,3 +94,89 @@ impl WidgetImpl for SinkBox {}
|
|||
impl WindowImpl for SinkBox {}
|
||||
|
||||
impl ApplicationWindowImpl for SinkBox {}
|
||||
|
||||
impl AudioBoxImpl<Sink, SinkEntry, super::sink_entry_impl::SinkEntry> for SinkBox {
|
||||
fn audio_object_row(&self) -> &TemplateChild<ActionRow> {
|
||||
&self.reset_sinks_row
|
||||
}
|
||||
|
||||
fn cards_row(&self) -> &TemplateChild<ActionRow> {
|
||||
&self.reset_cards_row
|
||||
}
|
||||
|
||||
fn audio_object_dropdown(&self) -> &TemplateChild<ComboRow> {
|
||||
&self.reset_sink_dropdown
|
||||
}
|
||||
|
||||
fn audio_object_mute(&self) -> &TemplateChild<Button> {
|
||||
&self.reset_sink_mute
|
||||
}
|
||||
|
||||
fn volume_slider(&self) -> &TemplateChild<Scale> {
|
||||
&self.reset_volume_slider
|
||||
}
|
||||
|
||||
fn volume_percentage(&self) -> &TemplateChild<Label> {
|
||||
&self.reset_volume_percentage
|
||||
}
|
||||
|
||||
fn audio_objects(&self) -> &TemplateChild<gtk::Box> {
|
||||
&self.reset_sinks
|
||||
}
|
||||
|
||||
fn audio_object_stream_button(&self) -> &TemplateChild<ActionRow> {
|
||||
&self.reset_input_stream_button
|
||||
}
|
||||
|
||||
fn audio_object_streams(&self) -> &TemplateChild<gtk::Box> {
|
||||
&self.reset_input_streams
|
||||
}
|
||||
|
||||
fn cards_button(&self) -> &TemplateChild<ActionRow> {
|
||||
&self.reset_input_cards_back_button
|
||||
}
|
||||
|
||||
fn cards(&self) -> &TemplateChild<PreferencesGroup> {
|
||||
&self.reset_cards
|
||||
}
|
||||
|
||||
fn error(&self) -> &TemplateChild<ReSetError> {
|
||||
&self.error
|
||||
}
|
||||
|
||||
fn default_check_button(&self) -> Arc<CheckButton> {
|
||||
self.reset_default_check_button.clone()
|
||||
}
|
||||
|
||||
fn default_audio_object(&self) -> Arc<RefCell<Sink>> {
|
||||
self.reset_default_sink.clone()
|
||||
}
|
||||
|
||||
fn audio_object_list(
|
||||
&self,
|
||||
) -> &crate::components::audio::generic_entry::AudioEntryMap<SinkEntry> {
|
||||
&self.reset_sink_list
|
||||
}
|
||||
|
||||
// fn audio_object_stream_list(
|
||||
// &self,
|
||||
// ) -> &crate::components::audio::generic_entry::AudioStreamEntryMap<SourceEntry> {
|
||||
// &
|
||||
// }
|
||||
|
||||
fn model_list(&self) -> Arc<RwLock<StringList>> {
|
||||
self.reset_model_list.clone()
|
||||
}
|
||||
|
||||
fn model_index(&self) -> Arc<RwLock<u32>> {
|
||||
self.reset_model_index.clone()
|
||||
}
|
||||
|
||||
fn source_map(&self) -> &crate::components::audio::generic_entry::AudioMap {
|
||||
&self.reset_sink_map
|
||||
}
|
||||
|
||||
fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>> {
|
||||
&self.volume_time_stamp
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,12 +56,12 @@ pub fn populate_sink_information(sink_box: Arc<SinkBox>, sinks: Vec<Sink>) {
|
|||
if sink_box_imp.reset_default_sink.borrow().name == sink.name {
|
||||
is_default = true;
|
||||
}
|
||||
let sink_entry = Arc::new(SinkEntry::new(
|
||||
let sink_entry = SinkEntry::new(
|
||||
is_default,
|
||||
sink_box_imp.reset_default_check_button.clone(),
|
||||
sink,
|
||||
sink_box.clone(),
|
||||
));
|
||||
);
|
||||
let sink_clone = sink_entry.clone();
|
||||
let entry = Arc::new(ListEntry::new(&*sink_entry));
|
||||
entry.set_activatable(false);
|
||||
|
|
|
@ -1,21 +1,17 @@
|
|||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::components::audio::generic_entry::{new_entry, Audio};
|
||||
use crate::components::base::error_impl::show_error;
|
||||
use crate::components::utils::set_action_row_ellipsis;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{ButtonExt, CheckButtonExt, PreferencesRowExt, RangeExt};
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::Error;
|
||||
use glib::subclass::types::ObjectSubclassIsExt;
|
||||
use glib::{clone, Propagation};
|
||||
use gtk::{gio, CheckButton};
|
||||
use re_set_lib::audio::audio_structures::Sink;
|
||||
|
||||
use crate::components::utils::{AUDIO, BASE, DBUS_PATH};
|
||||
|
||||
use super::sink_box::SinkBox;
|
||||
use super::sink_box_utils::refresh_default_sink;
|
||||
use super::sink_entry_impl;
|
||||
|
||||
glib::wrapper! {
|
||||
|
@ -27,82 +23,26 @@ glib::wrapper! {
|
|||
unsafe impl Send for SinkEntry {}
|
||||
unsafe impl Sync for SinkEntry {}
|
||||
|
||||
impl Audio<Sink, super::sink_entry_impl::SinkEntry> for SinkEntry {
|
||||
fn entry_imp(&self) -> &super::sink_entry_impl::SinkEntry {
|
||||
self.imp()
|
||||
}
|
||||
}
|
||||
|
||||
impl SinkEntry {
|
||||
pub fn new(
|
||||
is_default: bool,
|
||||
check_group: Arc<CheckButton>,
|
||||
stream: Sink,
|
||||
sink: Sink,
|
||||
output_box: Arc<SinkBox>,
|
||||
) -> Self {
|
||||
let obj: Self = Object::builder().build();
|
||||
// TODO use event callback for progress bar -> this is the "im speaking" indicator
|
||||
{
|
||||
let imp = obj.imp();
|
||||
imp.reset_sink_name.set_title(stream.alias.clone().as_str());
|
||||
let name = Arc::new(stream.name.clone());
|
||||
let volume = stream.volume.first().unwrap_or(&0_u32);
|
||||
let fraction = (*volume as f64 / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
let output_box_slider = output_box.clone();
|
||||
let output_box_ref = output_box.clone();
|
||||
imp.reset_volume_percentage.set_text(&percentage);
|
||||
imp.reset_volume_slider.set_value(*volume as f64);
|
||||
imp.stream.replace(stream);
|
||||
imp.reset_volume_slider.connect_change_value(
|
||||
clone!(@weak imp => @default-return Propagation::Stop, move |_, _, value| {
|
||||
let fraction = (value / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
imp.reset_volume_percentage.set_text(&percentage);
|
||||
let sink = imp.stream.borrow();
|
||||
let index = sink.index;
|
||||
let channels = sink.channels;
|
||||
{
|
||||
let mut time = imp.volume_time_stamp.borrow_mut();
|
||||
if time.is_some() && time.unwrap().elapsed().unwrap() < Duration::from_millis(50) {
|
||||
return Propagation::Proceed;
|
||||
}
|
||||
*time = Some(SystemTime::now());
|
||||
}
|
||||
set_sink_volume(value, index, channels, output_box_slider.clone());
|
||||
Propagation::Proceed
|
||||
}),
|
||||
);
|
||||
imp.reset_selected_sink.set_group(Some(&*check_group));
|
||||
if is_default {
|
||||
imp.reset_selected_sink.set_active(true);
|
||||
} else {
|
||||
imp.reset_selected_sink.set_active(false);
|
||||
}
|
||||
imp.reset_selected_sink.connect_toggled(move |button| {
|
||||
let output_box_ref = output_box.clone();
|
||||
if button.is_active() {
|
||||
let name = name.clone();
|
||||
gio::spawn_blocking(move || {
|
||||
let result = set_default_sink(name, output_box_ref.clone());
|
||||
if result.is_none() {
|
||||
return;
|
||||
}
|
||||
refresh_default_sink(result.unwrap(), output_box_ref, true);
|
||||
});
|
||||
}
|
||||
});
|
||||
imp.reset_sink_mute
|
||||
.connect_clicked(clone!(@weak imp => move |_| {
|
||||
let stream = imp.stream.clone();
|
||||
let mut stream = stream.borrow_mut();
|
||||
stream.muted = !stream.muted;
|
||||
if stream.muted {
|
||||
imp.reset_sink_mute
|
||||
.set_icon_name("audio-volume-muted-symbolic");
|
||||
} else {
|
||||
imp.reset_sink_mute
|
||||
.set_icon_name("audio-volume-high-symbolic");
|
||||
}
|
||||
toggle_sink_mute(stream.index, stream.muted, output_box_ref.clone());
|
||||
}));
|
||||
set_action_row_ellipsis(imp.reset_sink_name.get());
|
||||
}
|
||||
obj
|
||||
) -> Arc<Self> {
|
||||
new_entry::<
|
||||
Sink,
|
||||
SinkBox,
|
||||
SinkEntry,
|
||||
super::sink_entry_impl::SinkEntry,
|
||||
super::sink_box_impl::SinkBox,
|
||||
>(is_default, check_group, sink, output_box)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::cell::RefCell;
|
|||
use std::sync::Arc;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::components::audio::generic_entry::AudioImpl;
|
||||
use crate::components::audio::output::sink_entry;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{Button, CheckButton, CompositeTemplate, Label, Scale};
|
||||
|
@ -22,7 +23,7 @@ pub struct SinkEntry {
|
|||
pub reset_volume_slider: TemplateChild<Scale>,
|
||||
#[template_child]
|
||||
pub reset_volume_percentage: TemplateChild<Label>,
|
||||
pub stream: Arc<RefCell<Sink>>,
|
||||
pub sink: Arc<RefCell<Sink>>,
|
||||
pub volume_time_stamp: RefCell<Option<SystemTime>>,
|
||||
}
|
||||
|
||||
|
@ -47,3 +48,45 @@ impl PreferencesGroupImpl for SinkEntry {}
|
|||
impl ObjectImpl for SinkEntry {}
|
||||
|
||||
impl WidgetImpl for SinkEntry {}
|
||||
|
||||
impl AudioImpl<Sink> for SinkEntry {
|
||||
fn name(&self) -> &TemplateChild<ActionRow> {
|
||||
&self.reset_sink_name
|
||||
}
|
||||
|
||||
fn selected_audio_object(&self) -> &TemplateChild<CheckButton> {
|
||||
&self.reset_selected_sink
|
||||
}
|
||||
|
||||
fn mute(&self) -> &TemplateChild<Button> {
|
||||
&self.reset_sink_mute
|
||||
}
|
||||
|
||||
fn volume_slider(&self) -> &TemplateChild<Scale> {
|
||||
&self.reset_volume_slider
|
||||
}
|
||||
|
||||
fn volume_percentage(&self) -> &TemplateChild<Label> {
|
||||
&self.reset_volume_percentage
|
||||
}
|
||||
|
||||
fn audio_object(&self) -> Arc<RefCell<Sink>> {
|
||||
self.sink.clone()
|
||||
}
|
||||
|
||||
fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>> {
|
||||
&self.volume_time_stamp
|
||||
}
|
||||
|
||||
fn set_volume_fn(&self) -> (&'static str, &'static str) {
|
||||
("SetSinkVolume", "Failed to set set sink volume")
|
||||
}
|
||||
|
||||
fn set_audio_object_fn(&self) -> (&'static str, &'static str) {
|
||||
("SetDefaultSink", "Faield to set default sink")
|
||||
}
|
||||
|
||||
fn set_mute_fn(&self) -> (&'static str, &'static str) {
|
||||
("SetSinkMute", "Failed to mute sink")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue