mirror of
				https://github.com/Xetibo/ReSet.git
				synced 2025-11-04 09:45:19 +01:00 
			
		
		
		
	wip: Refactor Dbus functions
This commit is contained in:
		
							parent
							
								
									39fd353c7e
								
							
						
					
					
						commit
						7593f2edc1
					
				
					 12 changed files with 115 additions and 50 deletions
				
			
		| 
						 | 
					@ -17,23 +17,23 @@ use crate::components::{
 | 
				
			||||||
    utils::{AUDIO, BASE, DBUS_PATH},
 | 
					    utils::{AUDIO, BASE, DBUS_PATH},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::generic_entry::{Audio, AudioBox, AudioBoxImpl, AudioImpl};
 | 
					use super::generic_entry::{Audio, AudioBox, AudioBoxImpl, AudioImpl, DBusFunction};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn set_volume<T: ReSetErrorImpl + 'static>(
 | 
					pub fn set_volume<T: ReSetErrorImpl + 'static>(
 | 
				
			||||||
    value: f64,
 | 
					    value: f64,
 | 
				
			||||||
    index: u32,
 | 
					    index: u32,
 | 
				
			||||||
    channels: u16,
 | 
					    channels: u16,
 | 
				
			||||||
    reset_box: Arc<T>,
 | 
					    reset_box: Arc<T>,
 | 
				
			||||||
    function: (&'static str, &'static str),
 | 
					    function: &'static DBusFunction,
 | 
				
			||||||
) -> bool {
 | 
					) -> bool {
 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
        let conn = Connection::new_session().unwrap();
 | 
					        let conn = Connection::new_session().unwrap();
 | 
				
			||||||
        let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
					        let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
        let res: Result<(), Error> =
 | 
					        let res: Result<(), Error> =
 | 
				
			||||||
            proxy.method_call(AUDIO, function.0, (index, channels, value as u32));
 | 
					            proxy.method_call(AUDIO, function.function, (index, channels, value as u32));
 | 
				
			||||||
        if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
            // TODO: also log this with LOG/ERROR
 | 
					            // TODO: also log this with LOG/ERROR
 | 
				
			||||||
            show_error::<T>(reset_box.clone(), function.1);
 | 
					            show_error::<T>(reset_box.clone(), function.error);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    true
 | 
					    true
 | 
				
			||||||
| 
						 | 
					@ -43,15 +43,15 @@ pub fn toggle_audio_object_mute<T: ReSetErrorImpl + 'static>(
 | 
				
			||||||
    index: u32,
 | 
					    index: u32,
 | 
				
			||||||
    muted: bool,
 | 
					    muted: bool,
 | 
				
			||||||
    input_box: Arc<T>,
 | 
					    input_box: Arc<T>,
 | 
				
			||||||
    function: (&'static str, &'static str),
 | 
					    function: &'static DBusFunction,
 | 
				
			||||||
) -> bool {
 | 
					) -> bool {
 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
        let conn = Connection::new_session().unwrap();
 | 
					        let conn = Connection::new_session().unwrap();
 | 
				
			||||||
        let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
					        let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
        let res: Result<(), Error> = proxy.method_call(AUDIO, function.0, (index, muted));
 | 
					        let res: Result<(), Error> = proxy.method_call(AUDIO, function.function, (index, muted));
 | 
				
			||||||
        if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
            // TODO: also log this with LOG/ERROR
 | 
					            // TODO: also log this with LOG/ERROR
 | 
				
			||||||
            show_error::<T>(input_box.clone(), function.1);
 | 
					            show_error::<T>(input_box.clone(), function.error);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    true
 | 
					    true
 | 
				
			||||||
| 
						 | 
					@ -60,7 +60,7 @@ pub fn toggle_audio_object_mute<T: ReSetErrorImpl + 'static>(
 | 
				
			||||||
pub fn set_default_audio_object<T, R>(
 | 
					pub fn set_default_audio_object<T, R>(
 | 
				
			||||||
    name: Arc<String>,
 | 
					    name: Arc<String>,
 | 
				
			||||||
    input_box: Arc<T>,
 | 
					    input_box: Arc<T>,
 | 
				
			||||||
    function: (&'static str, &'static str),
 | 
					    function: &'static DBusFunction,
 | 
				
			||||||
) -> Option<R>
 | 
					) -> Option<R>
 | 
				
			||||||
where
 | 
					where
 | 
				
			||||||
    T: ReSetErrorImpl + 'static,
 | 
					    T: ReSetErrorImpl + 'static,
 | 
				
			||||||
| 
						 | 
					@ -68,9 +68,9 @@ where
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    let conn = Connection::new_session().unwrap();
 | 
					    let conn = Connection::new_session().unwrap();
 | 
				
			||||||
    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
					    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
    let res: Result<(R,), Error> = proxy.method_call(AUDIO, function.0, (name.as_str(),));
 | 
					    let res: Result<(R,), Error> = proxy.method_call(AUDIO, function.function, (name.as_str(),));
 | 
				
			||||||
    if res.is_err() {
 | 
					    if res.is_err() {
 | 
				
			||||||
        show_error::<T>(input_box.clone(), function.1);
 | 
					        show_error::<T>(input_box.clone(), function.error);
 | 
				
			||||||
        return None;
 | 
					        return None;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    Some(res.unwrap().0)
 | 
					    Some(res.unwrap().0)
 | 
				
			||||||
| 
						 | 
					@ -116,12 +116,11 @@ pub fn refresh_default_audio_object<
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            imp.volume_percentage().set_text(&percentage);
 | 
					            imp.volume_percentage().set_text(&percentage);
 | 
				
			||||||
            imp.volume_slider().set_value(volume as f64);
 | 
					            imp.volume_slider().set_value(volume as f64);
 | 
				
			||||||
 | 
					            let icons = imp.icons();
 | 
				
			||||||
            if new_audio_object.muted() {
 | 
					            if new_audio_object.muted() {
 | 
				
			||||||
                imp.audio_object_mute()
 | 
					                imp.audio_object_mute().set_icon_name(icons.muted);
 | 
				
			||||||
                    .set_icon_name("audio-volume-muted-symbolic");
 | 
					 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                imp.audio_object_mute()
 | 
					                imp.audio_object_mute().set_icon_name(icons.active);
 | 
				
			||||||
                    .set_icon_name("audio-volume-high-symbolic");
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            imp.default_audio_object().replace(new_audio_object);
 | 
					            imp.default_audio_object().replace(new_audio_object);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -58,8 +58,10 @@ pub trait AudioBoxImpl<OBJ, ENTRY, STREAMENTRY> {
 | 
				
			||||||
    fn model_index(&self) -> Arc<RwLock<u32>>;
 | 
					    fn model_index(&self) -> Arc<RwLock<u32>>;
 | 
				
			||||||
    fn source_map(&self) -> &AudioMap;
 | 
					    fn source_map(&self) -> &AudioMap;
 | 
				
			||||||
    fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>>;
 | 
					    fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>>;
 | 
				
			||||||
 | 
					    fn icons(&self) -> &AudioIcons;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[allow(dead_code)]
 | 
				
			||||||
pub trait AudioImpl<T: AudioObject> {
 | 
					pub trait AudioImpl<T: AudioObject> {
 | 
				
			||||||
    fn name(&self) -> &TemplateChild<ActionRow>;
 | 
					    fn name(&self) -> &TemplateChild<ActionRow>;
 | 
				
			||||||
    fn selected_audio_object(&self) -> &TemplateChild<CheckButton>;
 | 
					    fn selected_audio_object(&self) -> &TemplateChild<CheckButton>;
 | 
				
			||||||
| 
						 | 
					@ -68,9 +70,10 @@ pub trait AudioImpl<T: AudioObject> {
 | 
				
			||||||
    fn volume_percentage(&self) -> &TemplateChild<Label>;
 | 
					    fn volume_percentage(&self) -> &TemplateChild<Label>;
 | 
				
			||||||
    fn audio_object(&self) -> Arc<RefCell<T>>;
 | 
					    fn audio_object(&self) -> Arc<RefCell<T>>;
 | 
				
			||||||
    fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>>;
 | 
					    fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>>;
 | 
				
			||||||
    fn set_volume_fn(&self) -> (&'static str, &'static str);
 | 
					    fn set_volume_fn(&self) -> &'static DBusFunction;
 | 
				
			||||||
    fn set_audio_object_fn(&self) -> (&'static str, &'static str);
 | 
					    fn set_audio_object_fn(&self) -> &'static DBusFunction;
 | 
				
			||||||
    fn set_mute_fn(&self) -> (&'static str, &'static str);
 | 
					    fn set_mute_fn(&self) -> &'static DBusFunction;
 | 
				
			||||||
 | 
					    fn icons(&self) -> &AudioIcons;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// pub trait AudioObject {
 | 
					// pub trait AudioObject {
 | 
				
			||||||
| 
						 | 
					@ -83,6 +86,17 @@ pub trait AudioImpl<T: AudioObject> {
 | 
				
			||||||
//     fn toggle_muted(&mut self);
 | 
					//     fn toggle_muted(&mut self);
 | 
				
			||||||
//     fn active() -> i32;
 | 
					//     fn active() -> i32;
 | 
				
			||||||
// }
 | 
					// }
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub struct AudioIcons {
 | 
				
			||||||
 | 
					    pub muted: &'static str,
 | 
				
			||||||
 | 
					    pub active: &'static str,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub struct DBusFunction {
 | 
				
			||||||
 | 
					    pub function: &'static str,
 | 
				
			||||||
 | 
					    pub error: &'static str,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn new_entry<
 | 
					pub fn new_entry<
 | 
				
			||||||
    AObject: AudioObject + Arg + for<'z> Get<'z> + Send + Sync + 'static,
 | 
					    AObject: AudioObject + Arg + for<'z> Get<'z> + Send + Sync + 'static,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,5 +4,6 @@ pub mod source_box;
 | 
				
			||||||
mod source_box_handlers;
 | 
					mod source_box_handlers;
 | 
				
			||||||
pub mod source_box_impl;
 | 
					pub mod source_box_impl;
 | 
				
			||||||
mod source_box_utils;
 | 
					mod source_box_utils;
 | 
				
			||||||
 | 
					mod source_const;
 | 
				
			||||||
pub mod source_entry;
 | 
					pub mod source_entry;
 | 
				
			||||||
pub mod source_entry_impl;
 | 
					pub mod source_entry_impl;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,13 +16,14 @@ use re_set_lib::signals::{
 | 
				
			||||||
    SourceRemoved,
 | 
					    SourceRemoved,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::components::base::list_entry::ListEntry;
 | 
					use crate::components::{audio::generic_audio_functions::set_volume, base::list_entry::ListEntry};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::{
 | 
					use super::{
 | 
				
			||||||
    output_stream_entry::OutputStreamEntry,
 | 
					    output_stream_entry::OutputStreamEntry,
 | 
				
			||||||
    source_box::SourceBox,
 | 
					    source_box::SourceBox,
 | 
				
			||||||
    source_box_utils::{get_default_source_name, refresh_default_source},
 | 
					    source_box_utils::{get_default_source_name, refresh_default_source},
 | 
				
			||||||
    source_entry::{set_default_source, set_source_volume, toggle_source_mute, SourceEntry},
 | 
					    source_const::SETVOLUME,
 | 
				
			||||||
 | 
					    source_entry::{set_default_source, toggle_source_mute, SourceEntry},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn source_added_handler(source_box: Arc<SourceBox>, ir: SourceAdded) -> bool {
 | 
					pub fn source_added_handler(source_box: Arc<SourceBox>, ir: SourceAdded) -> bool {
 | 
				
			||||||
| 
						 | 
					@ -290,7 +291,7 @@ pub fn volume_slider_handler(source_box: Arc<SourceBox>, value: f64) -> Propagat
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        *time = Some(SystemTime::now());
 | 
					        *time = Some(SystemTime::now());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    set_source_volume(value, index, channels, source_box.clone());
 | 
					    set_volume::<SourceBox>(value, index, channels, source_box.clone(), &SETVOLUME);
 | 
				
			||||||
    Propagation::Proceed
 | 
					    Propagation::Proceed
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@ use std::collections::HashMap;
 | 
				
			||||||
use std::sync::{Arc, RwLock};
 | 
					use std::sync::{Arc, RwLock};
 | 
				
			||||||
use std::time::SystemTime;
 | 
					use std::time::SystemTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::components::audio::generic_entry::AudioBoxImpl;
 | 
					use crate::components::audio::generic_entry::{AudioBoxImpl, AudioIcons};
 | 
				
			||||||
use crate::components::audio::input::source_box;
 | 
					use crate::components::audio::input::source_box;
 | 
				
			||||||
use crate::components::base::error::ReSetError;
 | 
					use crate::components::base::error::ReSetError;
 | 
				
			||||||
use crate::components::base::list_entry::ListEntry;
 | 
					use crate::components::base::list_entry::ListEntry;
 | 
				
			||||||
| 
						 | 
					@ -14,6 +14,7 @@ use gtk::{prelude::*, Button, Label, Scale};
 | 
				
			||||||
use gtk::{CheckButton, CompositeTemplate, StringList};
 | 
					use gtk::{CheckButton, CompositeTemplate, StringList};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::output_stream_entry::OutputStreamEntry;
 | 
					use super::output_stream_entry::OutputStreamEntry;
 | 
				
			||||||
 | 
					use super::source_const::ICONS;
 | 
				
			||||||
use super::source_entry::SourceEntry;
 | 
					use super::source_entry::SourceEntry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type SourceEntryMap = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<SourceEntry>, String)>>>;
 | 
					type SourceEntryMap = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<SourceEntry>, String)>>>;
 | 
				
			||||||
| 
						 | 
					@ -178,4 +179,8 @@ impl AudioBoxImpl<Source, SourceEntry, super::source_entry_impl::SourceEntry> fo
 | 
				
			||||||
    fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>> {
 | 
					    fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>> {
 | 
				
			||||||
        &self.volume_time_stamp
 | 
					        &self.volume_time_stamp
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn icons(&self) -> &AudioIcons {
 | 
				
			||||||
 | 
					        &ICONS
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										21
									
								
								src/components/audio/input/source_const.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/components/audio/input/source_const.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,21 @@
 | 
				
			||||||
 | 
					use crate::components::audio::generic_entry::{AudioIcons, DBusFunction};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub const ICONS: AudioIcons = AudioIcons {
 | 
				
			||||||
 | 
					    muted: "audio-input-microphone-symbolic",
 | 
				
			||||||
 | 
					    active: "microphone-disabled-symbolic",
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub const SETVOLUME: DBusFunction = DBusFunction {
 | 
				
			||||||
 | 
					    function: "SetSourceVolume",
 | 
				
			||||||
 | 
					    error: "Failed to set source volume",
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub const SETMUTE: DBusFunction = DBusFunction {
 | 
				
			||||||
 | 
					    function: "SetSourceMute",
 | 
				
			||||||
 | 
					    error: "Failed to mute source",
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub const SETDEFAULT: DBusFunction = DBusFunction {
 | 
				
			||||||
 | 
					    function: "SetDefaultSource",
 | 
				
			||||||
 | 
					    error: "Failed to set default source",
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -46,20 +46,6 @@ impl SourceEntry {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn set_source_volume(value: f64, index: u32, channels: u16, input_box: Arc<SourceBox>) -> bool {
 | 
					 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					 | 
				
			||||||
        let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
        let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
					 | 
				
			||||||
        let res: Result<(), Error> =
 | 
					 | 
				
			||||||
            proxy.method_call(AUDIO, "SetSourceVolume", (index, channels, value as u32));
 | 
					 | 
				
			||||||
        if res.is_err() {
 | 
					 | 
				
			||||||
            // TODO: also log this with LOG/ERROR
 | 
					 | 
				
			||||||
            show_error::<SourceBox>(input_box.clone(), "Failed to set source volume");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    true
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn toggle_source_mute(index: u32, muted: bool, input_box: Arc<SourceBox>) -> bool {
 | 
					pub fn toggle_source_mute(index: u32, muted: bool, input_box: Arc<SourceBox>) -> bool {
 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
        let conn = Connection::new_session().unwrap();
 | 
					        let conn = Connection::new_session().unwrap();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,8 +8,9 @@ use std::time::SystemTime;
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{Button, CheckButton, CompositeTemplate, Label, Scale};
 | 
					use gtk::{Button, CheckButton, CompositeTemplate, Label, Scale};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::components::audio::generic_entry::AudioImpl;
 | 
					use crate::components::audio::generic_entry::{AudioIcons, AudioImpl, DBusFunction};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::source_const::{ICONS, SETDEFAULT, SETMUTE, SETVOLUME};
 | 
				
			||||||
use super::source_entry;
 | 
					use super::source_entry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default, CompositeTemplate)]
 | 
					#[derive(Default, CompositeTemplate)]
 | 
				
			||||||
| 
						 | 
					@ -80,15 +81,19 @@ impl AudioImpl<Source> for SourceEntry {
 | 
				
			||||||
        &self.volume_time_stamp
 | 
					        &self.volume_time_stamp
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn set_volume_fn(&self) -> (&'static str, &'static str) {
 | 
					    fn set_volume_fn(&self) -> &'static DBusFunction {
 | 
				
			||||||
        ("SetSourceVolume", "Failed to set set source volume")
 | 
					        &SETVOLUME
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn set_audio_object_fn(&self) -> (&'static str, &'static str) {
 | 
					    fn set_audio_object_fn(&self) -> &'static DBusFunction {
 | 
				
			||||||
        ("SetDefaultSource", "Faield to set default source")
 | 
					        &SETDEFAULT
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn set_mute_fn(&self) -> (&'static str, &'static str) {
 | 
					    fn set_mute_fn(&self) -> &'static DBusFunction {
 | 
				
			||||||
        ("SetSourceMute", "Failed to mute source")
 | 
					        &SETMUTE
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn icons(&self) -> &AudioIcons {
 | 
				
			||||||
 | 
					        &ICONS
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,5 +4,6 @@ pub mod sink_box;
 | 
				
			||||||
mod sink_box_handlers;
 | 
					mod sink_box_handlers;
 | 
				
			||||||
pub mod sink_box_impl;
 | 
					pub mod sink_box_impl;
 | 
				
			||||||
mod sink_box_utils;
 | 
					mod sink_box_utils;
 | 
				
			||||||
 | 
					mod sink_const;
 | 
				
			||||||
pub mod sink_entry;
 | 
					pub mod sink_entry;
 | 
				
			||||||
pub mod sink_entry_impl;
 | 
					pub mod sink_entry_impl;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@ use std::collections::HashMap;
 | 
				
			||||||
use std::sync::{Arc, RwLock};
 | 
					use std::sync::{Arc, RwLock};
 | 
				
			||||||
use std::time::SystemTime;
 | 
					use std::time::SystemTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::components::audio::generic_entry::AudioBoxImpl;
 | 
					use crate::components::audio::generic_entry::{AudioBoxImpl, AudioIcons};
 | 
				
			||||||
use crate::components::audio::output::input_stream_entry::InputStreamEntry;
 | 
					use crate::components::audio::output::input_stream_entry::InputStreamEntry;
 | 
				
			||||||
use crate::components::base::error::ReSetError;
 | 
					use crate::components::base::error::ReSetError;
 | 
				
			||||||
use crate::components::base::list_entry::ListEntry;
 | 
					use crate::components::base::list_entry::ListEntry;
 | 
				
			||||||
| 
						 | 
					@ -14,6 +14,7 @@ use gtk::{prelude::*, Scale};
 | 
				
			||||||
use gtk::{Box, Button, CheckButton, CompositeTemplate, Label, StringList};
 | 
					use gtk::{Box, Button, CheckButton, CompositeTemplate, Label, StringList};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::sink_box;
 | 
					use super::sink_box;
 | 
				
			||||||
 | 
					use super::sink_const::ICONS;
 | 
				
			||||||
use super::sink_entry::SinkEntry;
 | 
					use super::sink_entry::SinkEntry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type SinkEntryMap = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<SinkEntry>, String)>>>;
 | 
					type SinkEntryMap = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<SinkEntry>, String)>>>;
 | 
				
			||||||
| 
						 | 
					@ -179,4 +180,8 @@ impl AudioBoxImpl<Sink, SinkEntry, super::sink_entry_impl::SinkEntry> for SinkBo
 | 
				
			||||||
    fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>> {
 | 
					    fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>> {
 | 
				
			||||||
        &self.volume_time_stamp
 | 
					        &self.volume_time_stamp
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn icons(&self) -> &AudioIcons {
 | 
				
			||||||
 | 
					        &ICONS
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										21
									
								
								src/components/audio/output/sink_const.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/components/audio/output/sink_const.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,21 @@
 | 
				
			||||||
 | 
					use crate::components::audio::generic_entry::{AudioIcons, DBusFunction};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub const ICONS: AudioIcons = AudioIcons {
 | 
				
			||||||
 | 
					    muted: "audio-volume-high-symbolic",
 | 
				
			||||||
 | 
					    active: "audio-volume-muted-symbolic",
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub const SETVOLUME: DBusFunction = DBusFunction {
 | 
				
			||||||
 | 
					    function: "SetSinkVolume",
 | 
				
			||||||
 | 
					    error: "Failed to set sink volume",
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub const SETMUTE: DBusFunction = DBusFunction {
 | 
				
			||||||
 | 
					    function: "SetSinkMute",
 | 
				
			||||||
 | 
					    error: "Failed to mute sink",
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub const SETDEFAULT: DBusFunction = DBusFunction {
 | 
				
			||||||
 | 
					    function: "SetDefaultSink",
 | 
				
			||||||
 | 
					    error: "Failed to set default sink",
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -5,11 +5,13 @@ use std::cell::RefCell;
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
use std::time::SystemTime;
 | 
					use std::time::SystemTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::components::audio::generic_entry::AudioImpl;
 | 
					use crate::components::audio::generic_entry::{AudioIcons, AudioImpl, DBusFunction};
 | 
				
			||||||
use crate::components::audio::output::sink_entry;
 | 
					use crate::components::audio::output::sink_entry;
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{Button, CheckButton, CompositeTemplate, Label, Scale};
 | 
					use gtk::{Button, CheckButton, CompositeTemplate, Label, Scale};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::sink_const::{ICONS, SETDEFAULT, SETMUTE, SETVOLUME};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default, CompositeTemplate)]
 | 
					#[derive(Default, CompositeTemplate)]
 | 
				
			||||||
#[template(resource = "/org/Xetibo/ReSet/resetSinkEntry.ui")]
 | 
					#[template(resource = "/org/Xetibo/ReSet/resetSinkEntry.ui")]
 | 
				
			||||||
pub struct SinkEntry {
 | 
					pub struct SinkEntry {
 | 
				
			||||||
| 
						 | 
					@ -78,15 +80,19 @@ impl AudioImpl<Sink> for SinkEntry {
 | 
				
			||||||
        &self.volume_time_stamp
 | 
					        &self.volume_time_stamp
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn set_volume_fn(&self) -> (&'static str, &'static str) {
 | 
					    fn set_volume_fn(&self) -> &'static DBusFunction {
 | 
				
			||||||
        ("SetSinkVolume", "Failed to set set sink volume")
 | 
					        &SETVOLUME
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn set_audio_object_fn(&self) -> (&'static str, &'static str) {
 | 
					    fn set_audio_object_fn(&self) -> &'static DBusFunction {
 | 
				
			||||||
        ("SetDefaultSink", "Faield to set default sink")
 | 
					        &SETDEFAULT
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn set_mute_fn(&self) -> (&'static str, &'static str) {
 | 
					    fn set_mute_fn(&self) -> &'static DBusFunction {
 | 
				
			||||||
        ("SetSinkMute", "Failed to mute sink")
 | 
					        &SETMUTE
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn icons(&self) -> &AudioIcons {
 | 
				
			||||||
 | 
					        &ICONS
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue