mirror of
				https://github.com/Xetibo/ReSet.git
				synced 2025-11-04 09:45:19 +01:00 
			
		
		
		
	Merge pull request #91 from Xetibo/ina
feat: refactoring, plugin base, example plugin
This commit is contained in:
		
						commit
						0268f31733
					
				
					 91 changed files with 2948 additions and 2303 deletions
				
			
		
							
								
								
									
										17
									
								
								Cargo.toml
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								Cargo.toml
									
										
									
									
									
								
							| 
						 | 
					@ -7,13 +7,14 @@ repository = "https://github.com/Xetibo/ReSet"
 | 
				
			||||||
license = "GPL-3.0-only"
 | 
					license = "GPL-3.0-only"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[dependencies]
 | 
					[dependencies]
 | 
				
			||||||
reset_daemon = "1.0.1"
 | 
					#reset_daemon = "1.1.0"
 | 
				
			||||||
re_set-lib = "1.0.0"
 | 
					re_set-lib = { git = "https://github.com/Xetibo/ReSet-Lib" }
 | 
				
			||||||
adw = { version = "0.5.3", package = "libadwaita", features = ["v1_4"] }
 | 
					reset_daemon = { git = "https://github.com/Xetibo/ReSet-Daemon", branch = "dashie" }
 | 
				
			||||||
 | 
					adw = { version = "0.6.0", package = "libadwaita", features = ["v1_4"] }
 | 
				
			||||||
dbus = "0.9.7"
 | 
					dbus = "0.9.7"
 | 
				
			||||||
gtk = { version = "0.7.3", package = "gtk4", features = ["v4_12"] }
 | 
					gtk = { version = "0.8.1", package = "gtk4", features = ["v4_12"] }
 | 
				
			||||||
glib = "0.18.3"
 | 
					glib = "0.19.3"
 | 
				
			||||||
tokio = { version = "1.33.0", features = [
 | 
					tokio = { version = "1.36.0", features = [
 | 
				
			||||||
  "rt",
 | 
					  "rt",
 | 
				
			||||||
  "time",
 | 
					  "time",
 | 
				
			||||||
  "net",
 | 
					  "net",
 | 
				
			||||||
| 
						 | 
					@ -21,8 +22,8 @@ tokio = { version = "1.33.0", features = [
 | 
				
			||||||
  "rt-multi-thread",
 | 
					  "rt-multi-thread",
 | 
				
			||||||
  "sync",
 | 
					  "sync",
 | 
				
			||||||
] }
 | 
					] }
 | 
				
			||||||
fork = "0.1.22"
 | 
					fork = "0.1.23"
 | 
				
			||||||
ipnetwork = "0.20.0"
 | 
					ipnetwork = "0.20.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[build-dependencies]
 | 
					[build-dependencies]
 | 
				
			||||||
glib-build-tools = "0.18.0"
 | 
					glib-build-tools = "0.19.0"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										13
									
								
								better_test_plugin/Cargo.toml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								better_test_plugin/Cargo.toml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,13 @@
 | 
				
			||||||
 | 
					[package]
 | 
				
			||||||
 | 
					name = "better_test_plugin"
 | 
				
			||||||
 | 
					version = "0.1.0"
 | 
				
			||||||
 | 
					edition = "2021"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[lib]
 | 
				
			||||||
 | 
					crate-type = ["dylib"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[dependencies]
 | 
				
			||||||
 | 
					re_set-lib = { git = "https://github.com/Xetibo/ReSet-Lib" }
 | 
				
			||||||
 | 
					gtk = { version = "0.8.1", package = "gtk4", features = ["v4_12"] }
 | 
				
			||||||
 | 
					dbus = "0.9.7"
 | 
				
			||||||
 | 
					glib = "0.19.3"
 | 
				
			||||||
							
								
								
									
										84
									
								
								better_test_plugin/src/lib.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								better_test_plugin/src/lib.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,84 @@
 | 
				
			||||||
 | 
					use std::sync::Arc;
 | 
				
			||||||
 | 
					use std::time::Duration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use dbus::blocking::Connection;
 | 
				
			||||||
 | 
					use dbus::Error;
 | 
				
			||||||
 | 
					use gtk::{gio, Orientation};
 | 
				
			||||||
 | 
					use gtk::prelude::{BoxExt, ButtonExt};
 | 
				
			||||||
 | 
					use re_set_lib::utils::plugin::{PluginCapabilities, PluginImplementation, PluginTestFunc, SidebarInfo};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub const BASE: &str = "org.Xetibo.ReSet.Daemon";
 | 
				
			||||||
 | 
					pub const DBUS_PATH: &str = "/org/Xebito/ReSet/Plugins/test";
 | 
				
			||||||
 | 
					pub const INTERFACE: &str = "org.Xetibo.ReSet.TestPlugin";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[no_mangle]
 | 
				
			||||||
 | 
					#[allow(improper_ctypes_definitions)]
 | 
				
			||||||
 | 
					pub extern "C" fn capabilities() -> PluginCapabilities {
 | 
				
			||||||
 | 
					    println!("frontend capabilities called");
 | 
				
			||||||
 | 
					    PluginCapabilities::new(vec!["frontend test"], PluginImplementation::Frontend)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[no_mangle]
 | 
				
			||||||
 | 
					pub extern "C" fn frontend_startup() {
 | 
				
			||||||
 | 
					    println!("frontend startup called");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[no_mangle]
 | 
				
			||||||
 | 
					pub extern "C" fn frontend_shutdown() {
 | 
				
			||||||
 | 
					    println!("frontend shutdown called");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[no_mangle]
 | 
				
			||||||
 | 
					#[allow(improper_ctypes_definitions)]
 | 
				
			||||||
 | 
					pub extern "C" fn frontend_data() -> (SidebarInfo, Vec<gtk::Box>) {
 | 
				
			||||||
 | 
					    println!("frontend data called");
 | 
				
			||||||
 | 
					    let info = SidebarInfo {
 | 
				
			||||||
 | 
					        name: "test",
 | 
				
			||||||
 | 
					        icon_name: "microphone-disabled-symbolic",
 | 
				
			||||||
 | 
					        parent: None,
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    let box1 = gtk::Box::builder().orientation(Orientation::Vertical).build();
 | 
				
			||||||
 | 
					    let box2 = gtk::Box::builder().orientation(Orientation::Horizontal).build();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let label = Arc::new(LabelWrapper {
 | 
				
			||||||
 | 
					        label: gtk::Label::builder().label("Hello, World!").build(),
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let label2 = gtk::Label::builder().label("Bye, World!").build();
 | 
				
			||||||
 | 
					    let button = gtk::Button::builder().label("Click me!").build();
 | 
				
			||||||
 | 
					    box1.append(&label.label);
 | 
				
			||||||
 | 
					    box2.append(&label2);
 | 
				
			||||||
 | 
					    box2.append(&button);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    button.connect_clicked(move |_| {
 | 
				
			||||||
 | 
					        let label = Arc::clone(&label);
 | 
				
			||||||
 | 
					        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<(String, u32), Error> = proxy.method_call(INTERFACE, "Test", ());
 | 
				
			||||||
 | 
					            let (text, age) = res.unwrap();
 | 
				
			||||||
 | 
					            label.label.set_text(&format!("Name: {}, Age: {}", text, age));
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let boxes = vec![
 | 
				
			||||||
 | 
					        box1, box2,
 | 
				
			||||||
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (info, boxes)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[no_mangle]
 | 
				
			||||||
 | 
					#[allow(improper_ctypes_definitions)]
 | 
				
			||||||
 | 
					pub extern "C" fn frontend_tests() -> Vec<PluginTestFunc> {
 | 
				
			||||||
 | 
					    println!("frontend tests called");
 | 
				
			||||||
 | 
					    vec![]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub struct LabelWrapper {
 | 
				
			||||||
 | 
					    label: gtk::Label,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsafe impl Send for LabelWrapper {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsafe impl Sync for LabelWrapper {}
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,8 @@
 | 
				
			||||||
pub mod output_stream_entry;
 | 
					pub mod output_stream_entry;
 | 
				
			||||||
pub mod output_stream_entry_impl;
 | 
					pub mod output_stream_entry_impl;
 | 
				
			||||||
pub mod source_box;
 | 
					pub mod source_box;
 | 
				
			||||||
 | 
					mod source_box_handlers;
 | 
				
			||||||
pub mod source_box_impl;
 | 
					pub mod source_box_impl;
 | 
				
			||||||
 | 
					mod source_box_utils;
 | 
				
			||||||
pub mod source_entry;
 | 
					pub mod source_entry;
 | 
				
			||||||
pub mod source_entry_impl;
 | 
					pub mod source_entry_impl;
 | 
				
			||||||
| 
						 | 
					@ -1,16 +1,17 @@
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
use std::time::{Duration, SystemTime};
 | 
					use std::time::{Duration, SystemTime};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::base::error_impl::show_error;
 | 
				
			||||||
use crate::components::utils::{
 | 
					use crate::components::utils::{
 | 
				
			||||||
    create_dropdown_label_factory, set_combo_row_ellipsis, AUDIO, BASE, DBUS_PATH,
 | 
					    create_dropdown_label_factory, set_combo_row_ellipsis, AUDIO, BASE, DBUS_PATH,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use adw::glib;
 | 
					 | 
				
			||||||
use adw::glib::Object;
 | 
					use adw::glib::Object;
 | 
				
			||||||
use adw::prelude::{ButtonExt, ComboRowExt, PreferencesRowExt, RangeExt};
 | 
					use adw::prelude::{ButtonExt, ComboRowExt, PreferencesRowExt, RangeExt};
 | 
				
			||||||
use dbus::blocking::Connection;
 | 
					use dbus::blocking::Connection;
 | 
				
			||||||
use dbus::Error;
 | 
					use dbus::Error;
 | 
				
			||||||
use glib::subclass::types::ObjectSubclassIsExt;
 | 
					use glib::subclass::types::ObjectSubclassIsExt;
 | 
				
			||||||
use glib::{clone, Cast, Propagation};
 | 
					use glib::{clone, Propagation};
 | 
				
			||||||
 | 
					use glib::prelude::Cast;
 | 
				
			||||||
use gtk::{gio, StringObject};
 | 
					use gtk::{gio, StringObject};
 | 
				
			||||||
use re_set_lib::audio::audio_structures::OutputStream;
 | 
					use re_set_lib::audio::audio_structures::OutputStream;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,6 +31,9 @@ impl OutputStreamEntry {
 | 
				
			||||||
    pub fn new(source_box: Arc<SourceBox>, stream: OutputStream) -> Self {
 | 
					    pub fn new(source_box: Arc<SourceBox>, stream: OutputStream) -> Self {
 | 
				
			||||||
        let obj: Self = Object::builder().build();
 | 
					        let obj: Self = Object::builder().build();
 | 
				
			||||||
        // TODO use event callback for progress bar -> this is the "im speaking" indicator
 | 
					        // TODO use event callback for progress bar -> this is the "im speaking" indicator
 | 
				
			||||||
 | 
					        let output_box_volume_ref = source_box.clone();
 | 
				
			||||||
 | 
					        let output_box_mute_ref = source_box.clone();
 | 
				
			||||||
 | 
					        let output_box_source_ref = source_box.clone();
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            let index = stream.index;
 | 
					            let index = stream.index;
 | 
				
			||||||
            let box_imp = source_box.imp();
 | 
					            let box_imp = source_box.imp();
 | 
				
			||||||
| 
						 | 
					@ -66,7 +70,7 @@ impl OutputStreamEntry {
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        *time = Some(SystemTime::now());
 | 
					                        *time = Some(SystemTime::now());
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    set_outputstream_volume(value, index, channels);
 | 
					                    set_outputstream_volume(value, index, channels, output_box_volume_ref.clone());
 | 
				
			||||||
                    Propagation::Proceed
 | 
					                    Propagation::Proceed
 | 
				
			||||||
                }),
 | 
					                }),
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
| 
						 | 
					@ -118,7 +122,7 @@ impl OutputStreamEntry {
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    let stream = stream.unwrap();
 | 
					                    let stream = stream.unwrap();
 | 
				
			||||||
                    let source = source.unwrap().0;
 | 
					                    let source = source.unwrap().0;
 | 
				
			||||||
                    set_source_of_output_stream(stream.index, source);
 | 
					                    set_source_of_output_stream(stream.index, source, output_box_source_ref.clone());
 | 
				
			||||||
                }),
 | 
					                }),
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
            imp.reset_source_mute
 | 
					            imp.reset_source_mute
 | 
				
			||||||
| 
						 | 
					@ -139,53 +143,56 @@ impl OutputStreamEntry {
 | 
				
			||||||
                        imp.reset_source_mute
 | 
					                        imp.reset_source_mute
 | 
				
			||||||
                           .set_icon_name("audio-input-microphone-symbolic");
 | 
					                           .set_icon_name("audio-input-microphone-symbolic");
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    toggle_output_stream_mute(index, muted);
 | 
					                    toggle_output_stream_mute(index, muted, output_box_mute_ref.clone());
 | 
				
			||||||
                }));
 | 
					                }));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        obj
 | 
					        obj
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn set_outputstream_volume(value: f64, index: u32, channels: u16) -> bool {
 | 
					fn set_outputstream_volume(
 | 
				
			||||||
 | 
					    value: f64,
 | 
				
			||||||
 | 
					    index: u32,
 | 
				
			||||||
 | 
					    channels: u16,
 | 
				
			||||||
 | 
					    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();
 | 
				
			||||||
        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 _: Result<(), Error> = proxy.method_call(
 | 
					        let res: Result<(), Error> = proxy.method_call(
 | 
				
			||||||
            AUDIO,
 | 
					            AUDIO,
 | 
				
			||||||
            "SetOutputStreamVolume",
 | 
					            "SetOutputStreamVolume",
 | 
				
			||||||
            (index, channels, value as u32),
 | 
					            (index, channels, value as u32),
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        // if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
        //     return false;
 | 
					            show_error::<SourceBox>(input_box.clone(), "Failed to set output stream volume");
 | 
				
			||||||
        // }
 | 
					        }
 | 
				
			||||||
        // res.unwrap().0
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    true
 | 
					    true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn toggle_output_stream_mute(index: u32, muted: bool) -> bool {
 | 
					fn toggle_output_stream_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();
 | 
				
			||||||
        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 _: Result<(), Error> = proxy.method_call(AUDIO, "SetOutputStreamMute", (index, muted));
 | 
					        let res: Result<(), Error> =
 | 
				
			||||||
        // if res.is_err() {
 | 
					            proxy.method_call(AUDIO, "SetOutputStreamMute", (index, muted));
 | 
				
			||||||
        //     return false;
 | 
					        if res.is_err() {
 | 
				
			||||||
        // }
 | 
					            show_error::<SourceBox>(input_box.clone(), "Failed to mute output stream");
 | 
				
			||||||
        // res.unwrap().0
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    true
 | 
					    true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn set_source_of_output_stream(stream: u32, source: u32) -> bool {
 | 
					fn set_source_of_output_stream(stream: u32, source: u32, 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();
 | 
				
			||||||
        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 _: Result<(bool,), Error> =
 | 
					        let res: Result<(bool,), Error> =
 | 
				
			||||||
            proxy.method_call(AUDIO, "SetSourceOfOutputStream", (stream, source));
 | 
					            proxy.method_call(AUDIO, "SetSourceOfOutputStream", (stream, source));
 | 
				
			||||||
        // if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
        //     return false;
 | 
					            show_error::<SourceBox>(input_box.clone(), "Failed to set source of output stream");
 | 
				
			||||||
        // }
 | 
					        }
 | 
				
			||||||
        // res.unwrap().0
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    true
 | 
					    true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -5,9 +5,9 @@ use std::cell::RefCell;
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
use std::time::SystemTime;
 | 
					use std::time::SystemTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::components::input::output_stream_entry;
 | 
					use crate::components::audio::input::output_stream_entry;
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, Button, CompositeTemplate, Label, Scale};
 | 
					use gtk::{Button, CompositeTemplate, Label, Scale};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default, CompositeTemplate)]
 | 
					#[derive(Default, CompositeTemplate)]
 | 
				
			||||||
#[template(resource = "/org/Xetibo/ReSet/resetOutputStreamEntry.ui")]
 | 
					#[template(resource = "/org/Xetibo/ReSet/resetOutputStreamEntry.ui")]
 | 
				
			||||||
							
								
								
									
										203
									
								
								src/components/audio/input/source_box.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										203
									
								
								src/components/audio/input/source_box.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,203 @@
 | 
				
			||||||
 | 
					use re_set_lib::signals::{
 | 
				
			||||||
 | 
					    OutputStreamAdded, OutputStreamChanged, OutputStreamRemoved, SourceAdded, SourceChanged,
 | 
				
			||||||
 | 
					    SourceRemoved,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					use std::sync::Arc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use adw::glib::Object;
 | 
				
			||||||
 | 
					use adw::prelude::{ComboRowExt, ListBoxRowExt};
 | 
				
			||||||
 | 
					use dbus::blocking::Connection;
 | 
				
			||||||
 | 
					use dbus::message::SignalArgs;
 | 
				
			||||||
 | 
					use dbus::Path;
 | 
				
			||||||
 | 
					use glib::subclass::prelude::ObjectSubclassIsExt;
 | 
				
			||||||
 | 
					use glib::Variant;
 | 
				
			||||||
 | 
					use gtk::gio;
 | 
				
			||||||
 | 
					use gtk::prelude::ActionableExt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::audio::input::source_box_impl;
 | 
				
			||||||
 | 
					use crate::components::base::error::{self};
 | 
				
			||||||
 | 
					use crate::components::base::error_impl::ReSetErrorImpl;
 | 
				
			||||||
 | 
					use crate::components::utils::{
 | 
				
			||||||
 | 
					    create_dropdown_label_factory, set_combo_row_ellipsis, BASE, DBUS_PATH,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::source_box_handlers::{
 | 
				
			||||||
 | 
					    output_stream_added_handler, output_stream_changed_handler, output_stream_removed_handler,
 | 
				
			||||||
 | 
					    source_added_handler, source_changed_handler, source_removed_handler,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					use super::source_box_utils::{
 | 
				
			||||||
 | 
					    get_default_source, get_sources, populate_cards, populate_outputstreams,
 | 
				
			||||||
 | 
					    populate_source_information,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					glib::wrapper! {
 | 
				
			||||||
 | 
					    pub struct SourceBox(ObjectSubclass<source_box_impl::SourceBox>)
 | 
				
			||||||
 | 
					    @extends gtk::Box, gtk::Widget,
 | 
				
			||||||
 | 
					    @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsafe impl Send for SourceBox {}
 | 
				
			||||||
 | 
					unsafe impl Sync for SourceBox {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl ReSetErrorImpl for SourceBox {
 | 
				
			||||||
 | 
					    fn error(&self) -> >k::subclass::prelude::TemplateChild<error::ReSetError> {
 | 
				
			||||||
 | 
					        &self.imp().error
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl SourceBox {
 | 
				
			||||||
 | 
					    pub fn new() -> Self {
 | 
				
			||||||
 | 
					        let obj: Self = Object::builder().build();
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            let imp = obj.imp();
 | 
				
			||||||
 | 
					            let mut model_index = imp.reset_model_index.write().unwrap();
 | 
				
			||||||
 | 
					            *model_index = 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        obj
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn setup_callbacks(&self) {
 | 
				
			||||||
 | 
					        let self_imp = self.imp();
 | 
				
			||||||
 | 
					        self_imp.reset_source_row.set_activatable(true);
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_source_row
 | 
				
			||||||
 | 
					            .set_action_name(Some("navigation.push"));
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_source_row
 | 
				
			||||||
 | 
					            .set_action_target_value(Some(&Variant::from("sources")));
 | 
				
			||||||
 | 
					        self_imp.reset_cards_row.set_activatable(true);
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_cards_row
 | 
				
			||||||
 | 
					            .set_action_name(Some("navigation.push"));
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_cards_row
 | 
				
			||||||
 | 
					            .set_action_target_value(Some(&Variant::from("profileConfiguration")));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self_imp.reset_output_stream_button.set_activatable(true);
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_output_stream_button
 | 
				
			||||||
 | 
					            .set_action_name(Some("navigation.pop"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self_imp.reset_input_cards_back_button.set_activatable(true);
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_input_cards_back_button
 | 
				
			||||||
 | 
					            .set_action_name(Some("navigation.pop"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_source_dropdown
 | 
				
			||||||
 | 
					            .set_factory(Some(&create_dropdown_label_factory()));
 | 
				
			||||||
 | 
					        set_combo_row_ellipsis(self_imp.reset_source_dropdown.get());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Default for SourceBox {
 | 
				
			||||||
 | 
					    fn default() -> Self {
 | 
				
			||||||
 | 
					        Self::new()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn populate_sources(source_box: Arc<SourceBox>) {
 | 
				
			||||||
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
 | 
					        let sources = get_sources(source_box.clone());
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            let source_box_imp = source_box.imp();
 | 
				
			||||||
 | 
					            let list = source_box_imp.reset_model_list.write().unwrap();
 | 
				
			||||||
 | 
					            let mut map = source_box_imp.reset_source_map.write().unwrap();
 | 
				
			||||||
 | 
					            let mut model_index = source_box_imp.reset_model_index.write().unwrap();
 | 
				
			||||||
 | 
					            source_box_imp
 | 
				
			||||||
 | 
					                .reset_default_source
 | 
				
			||||||
 | 
					                .replace(get_default_source(source_box.clone()));
 | 
				
			||||||
 | 
					            for source in sources.iter() {
 | 
				
			||||||
 | 
					                list.append(&source.alias);
 | 
				
			||||||
 | 
					                map.insert(source.alias.clone(), (source.index, source.name.clone()));
 | 
				
			||||||
 | 
					                *model_index += 1;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        populate_outputstreams(source_box.clone());
 | 
				
			||||||
 | 
					        populate_cards(source_box.clone());
 | 
				
			||||||
 | 
					        populate_source_information(source_box, sources);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn start_source_box_listener(conn: Connection, source_box: Arc<SourceBox>) -> Connection {
 | 
				
			||||||
 | 
					    let source_added =
 | 
				
			||||||
 | 
					        SourceAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
 | 
				
			||||||
 | 
					    let source_removed =
 | 
				
			||||||
 | 
					        SourceRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
 | 
				
			||||||
 | 
					    let source_changed =
 | 
				
			||||||
 | 
					        SourceChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
 | 
				
			||||||
 | 
					    let output_stream_added =
 | 
				
			||||||
 | 
					        OutputStreamAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
 | 
				
			||||||
 | 
					            .static_clone();
 | 
				
			||||||
 | 
					    let output_stream_removed =
 | 
				
			||||||
 | 
					        OutputStreamRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
 | 
				
			||||||
 | 
					            .static_clone();
 | 
				
			||||||
 | 
					    let output_stream_changed =
 | 
				
			||||||
 | 
					        OutputStreamChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
 | 
				
			||||||
 | 
					            .static_clone();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let source_added_box = source_box.clone();
 | 
				
			||||||
 | 
					    let source_removed_box = source_box.clone();
 | 
				
			||||||
 | 
					    let source_changed_box = source_box.clone();
 | 
				
			||||||
 | 
					    let output_stream_added_box = source_box.clone();
 | 
				
			||||||
 | 
					    let output_stream_removed_box = source_box.clone();
 | 
				
			||||||
 | 
					    let output_stream_changed_box = source_box.clone();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let res = conn.add_match(source_added, move |ir: SourceAdded, _, _| {
 | 
				
			||||||
 | 
					        source_added_handler(source_added_box.clone(), ir)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        // TODO: handle this with the log/error macro
 | 
				
			||||||
 | 
					        println!("fail on source add event");
 | 
				
			||||||
 | 
					        return conn;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let res = conn.add_match(source_removed, move |ir: SourceRemoved, _, _| {
 | 
				
			||||||
 | 
					        source_removed_handler(source_removed_box.clone(), ir)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        println!("fail on source remove event");
 | 
				
			||||||
 | 
					        return conn;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let res = conn.add_match(source_changed, move |ir: SourceChanged, _, _| {
 | 
				
			||||||
 | 
					        source_changed_handler(source_changed_box.clone(), ir)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        println!("fail on source change event");
 | 
				
			||||||
 | 
					        return conn;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let res = conn.add_match(output_stream_added, move |ir: OutputStreamAdded, _, _| {
 | 
				
			||||||
 | 
					        output_stream_added_handler(output_stream_added_box.clone(), ir)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        println!("fail on output stream add event");
 | 
				
			||||||
 | 
					        return conn;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let res = conn.add_match(
 | 
				
			||||||
 | 
					        output_stream_changed,
 | 
				
			||||||
 | 
					        move |ir: OutputStreamChanged, _, _| {
 | 
				
			||||||
 | 
					            output_stream_changed_handler(output_stream_changed_box.clone(), ir)
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        println!("fail on output stream change event");
 | 
				
			||||||
 | 
					        return conn;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let res = conn.add_match(
 | 
				
			||||||
 | 
					        output_stream_removed,
 | 
				
			||||||
 | 
					        move |ir: OutputStreamRemoved, _, _| {
 | 
				
			||||||
 | 
					            output_stream_removed_handler(output_stream_removed_box.clone(), ir)
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        println!("fail on output stream remove event");
 | 
				
			||||||
 | 
					        return conn;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    conn
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										309
									
								
								src/components/audio/input/source_box_handlers.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										309
									
								
								src/components/audio/input/source_box_handlers.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,309 @@
 | 
				
			||||||
 | 
					use std::{
 | 
				
			||||||
 | 
					    sync::Arc,
 | 
				
			||||||
 | 
					    time::{Duration, SystemTime},
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use adw::prelude::{ComboRowExt, PreferencesRowExt};
 | 
				
			||||||
 | 
					use glib::{subclass::types::ObjectSubclassIsExt, ControlFlow, Propagation};
 | 
				
			||||||
 | 
					use glib::prelude::Cast;
 | 
				
			||||||
 | 
					use gtk::{
 | 
				
			||||||
 | 
					    gio,
 | 
				
			||||||
 | 
					    prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt},
 | 
				
			||||||
 | 
					    StringObject,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					use re_set_lib::signals::{
 | 
				
			||||||
 | 
					    OutputStreamAdded, OutputStreamChanged, OutputStreamRemoved, SourceAdded, SourceChanged,
 | 
				
			||||||
 | 
					    SourceRemoved,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::base::list_entry::ListEntry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::{
 | 
				
			||||||
 | 
					    output_stream_entry::OutputStreamEntry,
 | 
				
			||||||
 | 
					    source_box::SourceBox,
 | 
				
			||||||
 | 
					    source_box_utils::{get_default_source_name, refresh_default_source},
 | 
				
			||||||
 | 
					    source_entry::{set_default_source, set_source_volume, toggle_source_mute, SourceEntry},
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn source_added_handler(source_box: Arc<SourceBox>, ir: SourceAdded) -> bool {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let source_box = source_box.clone();
 | 
				
			||||||
 | 
					            let source_box_imp = source_box.imp();
 | 
				
			||||||
 | 
					            let source_index = ir.source.index;
 | 
				
			||||||
 | 
					            let alias = ir.source.alias.clone();
 | 
				
			||||||
 | 
					            let name = ir.source.name.clone();
 | 
				
			||||||
 | 
					            let mut is_default = false;
 | 
				
			||||||
 | 
					            if source_box_imp.reset_default_source.borrow().name == ir.source.name {
 | 
				
			||||||
 | 
					                is_default = true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let source_entry = Arc::new(SourceEntry::new(
 | 
				
			||||||
 | 
					                is_default,
 | 
				
			||||||
 | 
					                source_box_imp.reset_default_check_button.clone(),
 | 
				
			||||||
 | 
					                ir.source,
 | 
				
			||||||
 | 
					                source_box.clone(),
 | 
				
			||||||
 | 
					            ));
 | 
				
			||||||
 | 
					            let source_clone = source_entry.clone();
 | 
				
			||||||
 | 
					            let entry = Arc::new(ListEntry::new(&*source_entry));
 | 
				
			||||||
 | 
					            entry.set_activatable(false);
 | 
				
			||||||
 | 
					            let mut list = source_box_imp.reset_source_list.write().unwrap();
 | 
				
			||||||
 | 
					            list.insert(source_index, (entry.clone(), source_clone, alias.clone()));
 | 
				
			||||||
 | 
					            source_box_imp.reset_sources.append(&*entry);
 | 
				
			||||||
 | 
					            let mut map = source_box_imp.reset_source_map.write().unwrap();
 | 
				
			||||||
 | 
					            let mut index = source_box_imp.reset_model_index.write().unwrap();
 | 
				
			||||||
 | 
					            let model_list = source_box_imp.reset_model_list.write().unwrap();
 | 
				
			||||||
 | 
					            if model_list.string(*index - 1) == Some("Monitor of Dummy Output".into()) {
 | 
				
			||||||
 | 
					                model_list.append(&alias);
 | 
				
			||||||
 | 
					                model_list.remove(*index - 1);
 | 
				
			||||||
 | 
					                map.insert(alias, (source_index, name));
 | 
				
			||||||
 | 
					                source_box_imp.reset_source_dropdown.set_selected(0);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                model_list.append(&alias);
 | 
				
			||||||
 | 
					                map.insert(alias.clone(), (source_index, name));
 | 
				
			||||||
 | 
					                if alias == "Monitor of Dummy Output" {
 | 
				
			||||||
 | 
					                    source_box_imp.reset_source_dropdown.set_selected(0);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                *index += 1;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn source_removed_handler(source_box: Arc<SourceBox>, ir: SourceRemoved) -> bool {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let source_box = source_box.clone();
 | 
				
			||||||
 | 
					            let source_box_imp = source_box.imp();
 | 
				
			||||||
 | 
					            let entry: Option<(Arc<ListEntry>, Arc<SourceEntry>, String)>;
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                let mut list = source_box_imp.reset_source_list.write().unwrap();
 | 
				
			||||||
 | 
					                entry = list.remove(&ir.index);
 | 
				
			||||||
 | 
					                if entry.is_none() {
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            source_box_imp
 | 
				
			||||||
 | 
					                .reset_sources
 | 
				
			||||||
 | 
					                .remove(&*entry.clone().unwrap().0);
 | 
				
			||||||
 | 
					            let mut map = source_box_imp.reset_source_map.write().unwrap();
 | 
				
			||||||
 | 
					            let alias = entry.unwrap().2;
 | 
				
			||||||
 | 
					            map.remove(&alias);
 | 
				
			||||||
 | 
					            let mut index = source_box_imp.reset_model_index.write().unwrap();
 | 
				
			||||||
 | 
					            let model_list = source_box_imp.reset_model_list.write().unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if *index == 1 {
 | 
				
			||||||
 | 
					                model_list.append("Monitor of Dummy Output");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            for entry in 0..*index {
 | 
				
			||||||
 | 
					                if model_list.string(entry) == Some(alias.clone().into()) {
 | 
				
			||||||
 | 
					                    model_list.splice(entry, 1, &[]);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if *index > 1 {
 | 
				
			||||||
 | 
					                *index -= 1;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn source_changed_handler(source_box: Arc<SourceBox>, ir: SourceChanged) -> bool {
 | 
				
			||||||
 | 
					    let default_source = get_default_source_name(source_box.clone());
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let source_box = source_box.clone();
 | 
				
			||||||
 | 
					            let source_box_imp = source_box.imp();
 | 
				
			||||||
 | 
					            let is_default = ir.source.name == default_source;
 | 
				
			||||||
 | 
					            let volume = ir.source.volume.first().unwrap_or(&0_u32);
 | 
				
			||||||
 | 
					            let fraction = (*volume as f64 / 655.36).round();
 | 
				
			||||||
 | 
					            let percentage = (fraction).to_string() + "%";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            let list = source_box_imp.reset_source_list.read().unwrap();
 | 
				
			||||||
 | 
					            let entry = list.get(&ir.source.index);
 | 
				
			||||||
 | 
					            if entry.is_none() {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let imp = entry.unwrap().1.imp();
 | 
				
			||||||
 | 
					            if is_default {
 | 
				
			||||||
 | 
					                source_box_imp.reset_volume_percentage.set_text(&percentage);
 | 
				
			||||||
 | 
					                source_box_imp.reset_volume_slider.set_value(*volume as f64);
 | 
				
			||||||
 | 
					                source_box_imp
 | 
				
			||||||
 | 
					                    .reset_default_source
 | 
				
			||||||
 | 
					                    .replace(ir.source.clone());
 | 
				
			||||||
 | 
					                if ir.source.muted {
 | 
				
			||||||
 | 
					                    source_box_imp
 | 
				
			||||||
 | 
					                        .reset_source_mute
 | 
				
			||||||
 | 
					                        .set_icon_name("microphone-disabled-symbolic");
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    source_box_imp
 | 
				
			||||||
 | 
					                        .reset_source_mute
 | 
				
			||||||
 | 
					                        .set_icon_name("audio-input-microphone-symbolic");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                imp.reset_selected_source.set_active(true);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                imp.reset_selected_source.set_active(false);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            imp.reset_source_name
 | 
				
			||||||
 | 
					                .set_title(ir.source.alias.clone().as_str());
 | 
				
			||||||
 | 
					            imp.reset_volume_percentage.set_text(&percentage);
 | 
				
			||||||
 | 
					            imp.reset_volume_slider.set_value(*volume as f64);
 | 
				
			||||||
 | 
					            if ir.source.muted {
 | 
				
			||||||
 | 
					                imp.reset_source_mute
 | 
				
			||||||
 | 
					                    .set_icon_name("microphone-disabled-symbolic");
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                imp.reset_source_mute
 | 
				
			||||||
 | 
					                    .set_icon_name("audio-input-microphone-symbolic");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn output_stream_added_handler(source_box: Arc<SourceBox>, ir: OutputStreamAdded) -> bool {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let source_box = source_box.clone();
 | 
				
			||||||
 | 
					            let source_box_imp = source_box.imp();
 | 
				
			||||||
 | 
					            let mut list = source_box_imp.reset_output_stream_list.write().unwrap();
 | 
				
			||||||
 | 
					            let index = ir.stream.index;
 | 
				
			||||||
 | 
					            let output_stream = Arc::new(OutputStreamEntry::new(source_box.clone(), ir.stream));
 | 
				
			||||||
 | 
					            let entry = Arc::new(ListEntry::new(&*output_stream));
 | 
				
			||||||
 | 
					            entry.set_activatable(false);
 | 
				
			||||||
 | 
					            list.insert(index, (entry.clone(), output_stream.clone()));
 | 
				
			||||||
 | 
					            source_box_imp.reset_output_streams.append(&*entry);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn output_stream_changed_handler(source_box: Arc<SourceBox>, ir: OutputStreamChanged) -> bool {
 | 
				
			||||||
 | 
					    let imp = source_box.imp();
 | 
				
			||||||
 | 
					    let alias: String;
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        let source_list = imp.reset_source_list.read().unwrap();
 | 
				
			||||||
 | 
					        if let Some(alias_opt) = source_list.get(&ir.stream.source_index) {
 | 
				
			||||||
 | 
					            alias = alias_opt.2.clone();
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            alias = String::from("");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let source_box = source_box.clone();
 | 
				
			||||||
 | 
					            let source_box_imp = source_box.imp();
 | 
				
			||||||
 | 
					            let entry: Arc<OutputStreamEntry>;
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                let list = source_box_imp.reset_output_stream_list.read().unwrap();
 | 
				
			||||||
 | 
					                let entry_opt = list.get(&ir.stream.index);
 | 
				
			||||||
 | 
					                if entry_opt.is_none() {
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                entry = entry_opt.unwrap().1.clone();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let imp = entry.imp();
 | 
				
			||||||
 | 
					            if ir.stream.muted {
 | 
				
			||||||
 | 
					                imp.reset_source_mute
 | 
				
			||||||
 | 
					                    .set_icon_name("microphone-disabled-symbolic");
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                imp.reset_source_mute
 | 
				
			||||||
 | 
					                    .set_icon_name("audio-input-microphone-symbolic");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let name = ir.stream.application_name.clone() + ": " + ir.stream.name.as_str();
 | 
				
			||||||
 | 
					            imp.reset_source_selection.set_title(name.as_str());
 | 
				
			||||||
 | 
					            let volume = ir.stream.volume.first().unwrap_or(&0_u32);
 | 
				
			||||||
 | 
					            let fraction = (*volume as f64 / 655.36).round();
 | 
				
			||||||
 | 
					            let percentage = (fraction).to_string() + "%";
 | 
				
			||||||
 | 
					            imp.reset_volume_percentage.set_text(&percentage);
 | 
				
			||||||
 | 
					            imp.reset_volume_slider.set_value(*volume as f64);
 | 
				
			||||||
 | 
					            let index = source_box_imp.reset_model_index.read().unwrap();
 | 
				
			||||||
 | 
					            let model_list = source_box_imp.reset_model_list.read().unwrap();
 | 
				
			||||||
 | 
					            for entry in 0..*index {
 | 
				
			||||||
 | 
					                if model_list.string(entry) == Some(alias.clone().into()) {
 | 
				
			||||||
 | 
					                    imp.reset_source_selection.set_selected(entry);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn output_stream_removed_handler(source_box: Arc<SourceBox>, ir: OutputStreamRemoved) -> bool {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let source_box = source_box.clone();
 | 
				
			||||||
 | 
					            let source_box_imp = source_box.imp();
 | 
				
			||||||
 | 
					            let mut list = source_box_imp.reset_output_stream_list.write().unwrap();
 | 
				
			||||||
 | 
					            let entry = list.remove(&ir.index);
 | 
				
			||||||
 | 
					            if entry.is_none() {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            source_box_imp
 | 
				
			||||||
 | 
					                .reset_output_streams
 | 
				
			||||||
 | 
					                .remove(&*entry.unwrap().0);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn dropdown_handler(source_box: Arc<SourceBox>, dropdown: &adw::ComboRow) -> ControlFlow {
 | 
				
			||||||
 | 
					    let source_box_imp = source_box.imp();
 | 
				
			||||||
 | 
					    let source_box_ref = source_box.clone();
 | 
				
			||||||
 | 
					    let selected = dropdown.selected_item();
 | 
				
			||||||
 | 
					    if selected.is_none() {
 | 
				
			||||||
 | 
					        return ControlFlow::Break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let selected = selected.unwrap();
 | 
				
			||||||
 | 
					    let selected = selected.downcast_ref::<StringObject>().unwrap();
 | 
				
			||||||
 | 
					    let selected = selected.string().to_string();
 | 
				
			||||||
 | 
					    let source = source_box_imp.reset_source_map.read().unwrap();
 | 
				
			||||||
 | 
					    let source = source.get(&selected);
 | 
				
			||||||
 | 
					    if source.is_none() {
 | 
				
			||||||
 | 
					        return ControlFlow::Break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let source = Arc::new(source.unwrap().1.clone());
 | 
				
			||||||
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
 | 
					        let result = set_default_source(source, source_box_ref.clone());
 | 
				
			||||||
 | 
					        if result.is_none() {
 | 
				
			||||||
 | 
					            return ControlFlow::Break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        refresh_default_source(result.unwrap(), source_box_ref.clone(), false);
 | 
				
			||||||
 | 
					        ControlFlow::Continue
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    ControlFlow::Continue
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn volume_slider_handler(source_box: Arc<SourceBox>, value: f64) -> Propagation {
 | 
				
			||||||
 | 
					    let imp = source_box.imp();
 | 
				
			||||||
 | 
					    let fraction = (value / 655.36).round();
 | 
				
			||||||
 | 
					    let percentage = (fraction).to_string() + "%";
 | 
				
			||||||
 | 
					    imp.reset_volume_percentage.set_text(&percentage);
 | 
				
			||||||
 | 
					    let source = imp.reset_default_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, source_box.clone());
 | 
				
			||||||
 | 
					    Propagation::Proceed
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn mute_clicked_handler(source_box_ref_mute: Arc<SourceBox>) {
 | 
				
			||||||
 | 
					    let imp = source_box_ref_mute.imp();
 | 
				
			||||||
 | 
					    let mut source = imp.reset_default_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, source_box_ref_mute.clone());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -5,11 +5,12 @@ 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::input::source_box;
 | 
				
			||||||
 | 
					use crate::components::base::error::ReSetError;
 | 
				
			||||||
use crate::components::base::list_entry::ListEntry;
 | 
					use crate::components::base::list_entry::ListEntry;
 | 
				
			||||||
use crate::components::input::source_box;
 | 
					 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, CheckButton, CompositeTemplate, StringList, TemplateChild};
 | 
					 | 
				
			||||||
use gtk::{prelude::*, Button, Label, Scale};
 | 
					use gtk::{prelude::*, Button, Label, Scale};
 | 
				
			||||||
 | 
					use gtk::{CheckButton, CompositeTemplate, StringList};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::output_stream_entry::OutputStreamEntry;
 | 
					use super::output_stream_entry::OutputStreamEntry;
 | 
				
			||||||
use super::source_entry::SourceEntry;
 | 
					use super::source_entry::SourceEntry;
 | 
				
			||||||
| 
						 | 
					@ -45,6 +46,8 @@ pub struct SourceBox {
 | 
				
			||||||
    pub reset_input_cards_back_button: TemplateChild<ActionRow>,
 | 
					    pub reset_input_cards_back_button: TemplateChild<ActionRow>,
 | 
				
			||||||
    #[template_child]
 | 
					    #[template_child]
 | 
				
			||||||
    pub reset_cards: TemplateChild<PreferencesGroup>,
 | 
					    pub reset_cards: TemplateChild<PreferencesGroup>,
 | 
				
			||||||
 | 
					    #[template_child]
 | 
				
			||||||
 | 
					    pub error: TemplateChild<ReSetError>,
 | 
				
			||||||
    pub reset_default_check_button: Arc<CheckButton>,
 | 
					    pub reset_default_check_button: Arc<CheckButton>,
 | 
				
			||||||
    pub reset_default_source: Arc<RefCell<Source>>,
 | 
					    pub reset_default_source: Arc<RefCell<Source>>,
 | 
				
			||||||
    pub reset_source_list: SourceEntryMap,
 | 
					    pub reset_source_list: SourceEntryMap,
 | 
				
			||||||
							
								
								
									
										229
									
								
								src/components/audio/input/source_box_utils.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										229
									
								
								src/components/audio/input/source_box_utils.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,229 @@
 | 
				
			||||||
 | 
					use std::{sync::Arc, time::Duration};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use adw::prelude::{ComboRowExt, PreferencesGroupExt};
 | 
				
			||||||
 | 
					use dbus::{blocking::Connection, Error};
 | 
				
			||||||
 | 
					use glib::subclass::types::ObjectSubclassIsExt;
 | 
				
			||||||
 | 
					use gtk::{
 | 
				
			||||||
 | 
					    gio,
 | 
				
			||||||
 | 
					    prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt},
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					use re_set_lib::audio::audio_structures::{Card, OutputStream, Source};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::{
 | 
				
			||||||
 | 
					    base::{card_entry::CardEntry, error_impl::show_error, list_entry::ListEntry},
 | 
				
			||||||
 | 
					    utils::{AUDIO, BASE, DBUS_PATH},
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::{
 | 
				
			||||||
 | 
					    output_stream_entry::OutputStreamEntry,
 | 
				
			||||||
 | 
					    source_box::SourceBox,
 | 
				
			||||||
 | 
					    source_box_handlers::{dropdown_handler, mute_clicked_handler, volume_slider_handler},
 | 
				
			||||||
 | 
					    source_entry::SourceEntry,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn populate_source_information(source_box: Arc<SourceBox>, sources: Vec<Source>) {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let source_box_ref_slider = source_box.clone();
 | 
				
			||||||
 | 
					            let source_box_ref_toggle = source_box.clone();
 | 
				
			||||||
 | 
					            let source_box_ref_mute = source_box.clone();
 | 
				
			||||||
 | 
					            let source_box_imp = source_box.imp();
 | 
				
			||||||
 | 
					            let default_sink = source_box_imp.reset_default_source.clone();
 | 
				
			||||||
 | 
					            let source = default_sink.borrow();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if source.muted {
 | 
				
			||||||
 | 
					                source_box_imp
 | 
				
			||||||
 | 
					                    .reset_source_mute
 | 
				
			||||||
 | 
					                    .set_icon_name("microphone-disabled-symbolic");
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                source_box_imp
 | 
				
			||||||
 | 
					                    .reset_source_mute
 | 
				
			||||||
 | 
					                    .set_icon_name("audio-input-microphone-symbolic");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            let volume = source.volume.first().unwrap_or(&0_u32);
 | 
				
			||||||
 | 
					            let fraction = (*volume as f64 / 655.36).round();
 | 
				
			||||||
 | 
					            let percentage = (fraction).to_string() + "%";
 | 
				
			||||||
 | 
					            source_box_imp.reset_volume_percentage.set_text(&percentage);
 | 
				
			||||||
 | 
					            source_box_imp.reset_volume_slider.set_value(*volume as f64);
 | 
				
			||||||
 | 
					            let mut list = source_box_imp.reset_source_list.write().unwrap();
 | 
				
			||||||
 | 
					            for source in sources {
 | 
				
			||||||
 | 
					                let index = source.index;
 | 
				
			||||||
 | 
					                let alias = source.alias.clone();
 | 
				
			||||||
 | 
					                let mut is_default = false;
 | 
				
			||||||
 | 
					                if source_box_imp.reset_default_source.borrow().name == source.name {
 | 
				
			||||||
 | 
					                    is_default = true;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                let source_entry = Arc::new(SourceEntry::new(
 | 
				
			||||||
 | 
					                    is_default,
 | 
				
			||||||
 | 
					                    source_box_imp.reset_default_check_button.clone(),
 | 
				
			||||||
 | 
					                    source,
 | 
				
			||||||
 | 
					                    source_box.clone(),
 | 
				
			||||||
 | 
					                ));
 | 
				
			||||||
 | 
					                let source_clone = source_entry.clone();
 | 
				
			||||||
 | 
					                let entry = Arc::new(ListEntry::new(&*source_entry));
 | 
				
			||||||
 | 
					                entry.set_activatable(false);
 | 
				
			||||||
 | 
					                list.insert(index, (entry.clone(), source_clone, alias));
 | 
				
			||||||
 | 
					                source_box_imp.reset_sources.append(&*entry);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let list = source_box_imp.reset_model_list.read().unwrap();
 | 
				
			||||||
 | 
					            source_box_imp.reset_source_dropdown.set_model(Some(&*list));
 | 
				
			||||||
 | 
					            let name = source_box_imp.reset_default_source.borrow();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            let index = source_box_imp.reset_model_index.read().unwrap();
 | 
				
			||||||
 | 
					            let model_list = source_box_imp.reset_model_list.read().unwrap();
 | 
				
			||||||
 | 
					            for entry in 0..*index {
 | 
				
			||||||
 | 
					                if model_list.string(entry) == Some(name.alias.clone().into()) {
 | 
				
			||||||
 | 
					                    source_box_imp.reset_source_dropdown.set_selected(entry);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            source_box_imp
 | 
				
			||||||
 | 
					                .reset_source_dropdown
 | 
				
			||||||
 | 
					                .connect_selected_notify(move |dropdown| {
 | 
				
			||||||
 | 
					                    dropdown_handler(source_box_ref_toggle.clone(), dropdown);
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            source_box_imp
 | 
				
			||||||
 | 
					                .reset_volume_slider
 | 
				
			||||||
 | 
					                .connect_change_value(move |_, _, value| {
 | 
				
			||||||
 | 
					                    volume_slider_handler(source_box_ref_slider.clone(), value)
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            source_box_imp.reset_source_mute.connect_clicked(move |_| {
 | 
				
			||||||
 | 
					                mute_clicked_handler(source_box_ref_mute.clone());
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn refresh_default_source(new_source: Source, source_box: Arc<SourceBox>, entry: bool) {
 | 
				
			||||||
 | 
					    let volume = *new_source.volume.first().unwrap_or(&0_u32);
 | 
				
			||||||
 | 
					    let fraction = (volume as f64 / 655.36).round();
 | 
				
			||||||
 | 
					    let percentage = (fraction).to_string() + "%";
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let imp = source_box.imp();
 | 
				
			||||||
 | 
					            if !entry {
 | 
				
			||||||
 | 
					                let list = imp.reset_source_list.read().unwrap();
 | 
				
			||||||
 | 
					                let entry = list.get(&new_source.index);
 | 
				
			||||||
 | 
					                if entry.is_none() {
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                let entry_imp = entry.unwrap().1.imp();
 | 
				
			||||||
 | 
					                entry_imp.reset_selected_source.set_active(true);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                let model_list = imp.reset_model_list.read().unwrap();
 | 
				
			||||||
 | 
					                for entry in 0..*imp.reset_model_index.read().unwrap() {
 | 
				
			||||||
 | 
					                    if model_list.string(entry) == Some(new_source.alias.clone().into()) {
 | 
				
			||||||
 | 
					                        imp.reset_source_dropdown.set_selected(entry);
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            imp.reset_volume_percentage.set_text(&percentage);
 | 
				
			||||||
 | 
					            imp.reset_volume_slider.set_value(volume as f64);
 | 
				
			||||||
 | 
					            if new_source.muted {
 | 
				
			||||||
 | 
					                imp.reset_source_mute
 | 
				
			||||||
 | 
					                    .set_icon_name("microphone-disabled-symbolic");
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                imp.reset_source_mute
 | 
				
			||||||
 | 
					                    .set_icon_name("audio-input-microphone-symbolic");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            imp.reset_default_source.replace(new_source);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn populate_outputstreams(source_box: Arc<SourceBox>) {
 | 
				
			||||||
 | 
					    let source_box_ref = source_box.clone();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
 | 
					        let streams = get_output_streams(source_box.clone());
 | 
				
			||||||
 | 
					        glib::spawn_future(async move {
 | 
				
			||||||
 | 
					            glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					                let source_box_imp = source_box_ref.imp();
 | 
				
			||||||
 | 
					                let mut list = source_box_imp.reset_output_stream_list.write().unwrap();
 | 
				
			||||||
 | 
					                for stream in streams {
 | 
				
			||||||
 | 
					                    let index = stream.index;
 | 
				
			||||||
 | 
					                    let input_stream = Arc::new(OutputStreamEntry::new(source_box.clone(), stream));
 | 
				
			||||||
 | 
					                    let input_stream_clone = input_stream.clone();
 | 
				
			||||||
 | 
					                    let entry = Arc::new(ListEntry::new(&*input_stream));
 | 
				
			||||||
 | 
					                    entry.set_activatable(false);
 | 
				
			||||||
 | 
					                    list.insert(index, (entry.clone(), input_stream_clone));
 | 
				
			||||||
 | 
					                    source_box_imp.reset_output_streams.append(&*entry);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn populate_cards(source_box: Arc<SourceBox>) {
 | 
				
			||||||
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
 | 
					        let source_box_ref = source_box.clone();
 | 
				
			||||||
 | 
					        let cards = get_cards(source_box.clone());
 | 
				
			||||||
 | 
					        glib::spawn_future(async move {
 | 
				
			||||||
 | 
					            glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					                let imp = source_box_ref.imp();
 | 
				
			||||||
 | 
					                for card in cards {
 | 
				
			||||||
 | 
					                    imp.reset_cards.add(&CardEntry::new(card));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn get_output_streams(source_box: Arc<SourceBox>) -> Vec<OutputStream> {
 | 
				
			||||||
 | 
					    let conn = Connection::new_session().unwrap();
 | 
				
			||||||
 | 
					    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
 | 
					    let res: Result<(Vec<OutputStream>,), Error> =
 | 
				
			||||||
 | 
					        proxy.method_call(AUDIO, "ListOutputStreams", ());
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<SourceBox>(source_box.clone(), "Failed to get output streams");
 | 
				
			||||||
 | 
					        return Vec::new();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    res.unwrap().0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn get_sources(source_box: Arc<SourceBox>) -> Vec<Source> {
 | 
				
			||||||
 | 
					    let conn = Connection::new_session().unwrap();
 | 
				
			||||||
 | 
					    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
 | 
					    let res: Result<(Vec<Source>,), Error> = proxy.method_call(AUDIO, "ListSources", ());
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<SourceBox>(source_box.clone(), "Failed to get sources");
 | 
				
			||||||
 | 
					        return Vec::new();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    res.unwrap().0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn get_cards(source_box: Arc<SourceBox>) -> Vec<Card> {
 | 
				
			||||||
 | 
					    let conn = Connection::new_session().unwrap();
 | 
				
			||||||
 | 
					    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
 | 
					    let res: Result<(Vec<Card>,), Error> = proxy.method_call(AUDIO, "ListCards", ());
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<SourceBox>(source_box.clone(), "Failed to get profiles");
 | 
				
			||||||
 | 
					        return Vec::new();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    res.unwrap().0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn get_default_source_name(source_box: Arc<SourceBox>) -> String {
 | 
				
			||||||
 | 
					    let conn = Connection::new_session().unwrap();
 | 
				
			||||||
 | 
					    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
 | 
					    let res: Result<(String,), Error> = proxy.method_call(AUDIO, "GetDefaultSourceName", ());
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<SourceBox>(source_box.clone(), "Failed to get default source name");
 | 
				
			||||||
 | 
					        return String::from("");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    res.unwrap().0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn get_default_source(source_box: Arc<SourceBox>) -> Source {
 | 
				
			||||||
 | 
					    let conn = Connection::new_session().unwrap();
 | 
				
			||||||
 | 
					    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
 | 
					    let res: Result<(Source,), Error> = proxy.method_call(AUDIO, "GetDefaultSource", ());
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<SourceBox>(source_box.clone(), "Failed to get default source");
 | 
				
			||||||
 | 
					        return Source::default();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    res.unwrap().0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,8 @@
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
use std::time::{Duration, SystemTime};
 | 
					use std::time::{Duration, SystemTime};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use adw::glib;
 | 
					use crate::components::base::error_impl::show_error;
 | 
				
			||||||
 | 
					use crate::components::utils::set_action_row_ellipsis;
 | 
				
			||||||
use adw::glib::Object;
 | 
					use adw::glib::Object;
 | 
				
			||||||
use adw::prelude::{ButtonExt, CheckButtonExt, PreferencesRowExt, RangeExt};
 | 
					use adw::prelude::{ButtonExt, CheckButtonExt, PreferencesRowExt, RangeExt};
 | 
				
			||||||
use dbus::blocking::Connection;
 | 
					use dbus::blocking::Connection;
 | 
				
			||||||
| 
						 | 
					@ -10,11 +11,11 @@ use glib::subclass::types::ObjectSubclassIsExt;
 | 
				
			||||||
use glib::{clone, Propagation};
 | 
					use glib::{clone, Propagation};
 | 
				
			||||||
use gtk::{gio, CheckButton};
 | 
					use gtk::{gio, CheckButton};
 | 
				
			||||||
use re_set_lib::audio::audio_structures::Source;
 | 
					use re_set_lib::audio::audio_structures::Source;
 | 
				
			||||||
use crate::components::utils::set_action_row_ellipsis;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::components::utils::{BASE, DBUS_PATH, AUDIO};
 | 
					use crate::components::utils::{AUDIO, BASE, DBUS_PATH};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::source_box::{refresh_default_source, SourceBox};
 | 
					use super::source_box::SourceBox;
 | 
				
			||||||
 | 
					use super::source_box_utils::refresh_default_source;
 | 
				
			||||||
use super::source_entry_impl;
 | 
					use super::source_entry_impl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
glib::wrapper! {
 | 
					glib::wrapper! {
 | 
				
			||||||
| 
						 | 
					@ -43,6 +44,8 @@ impl SourceEntry {
 | 
				
			||||||
            let volume = source.volume.first().unwrap_or(&0_u32);
 | 
					            let volume = source.volume.first().unwrap_or(&0_u32);
 | 
				
			||||||
            let fraction = (*volume as f64 / 655.36).round();
 | 
					            let fraction = (*volume as f64 / 655.36).round();
 | 
				
			||||||
            let percentage = (fraction).to_string() + "%";
 | 
					            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_percentage.set_text(&percentage);
 | 
				
			||||||
            imp.reset_volume_slider.set_value(*volume as f64);
 | 
					            imp.reset_volume_slider.set_value(*volume as f64);
 | 
				
			||||||
            imp.source.replace(source);
 | 
					            imp.source.replace(source);
 | 
				
			||||||
| 
						 | 
					@ -63,7 +66,7 @@ impl SourceEntry {
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        *time = Some(SystemTime::now());
 | 
					                        *time = Some(SystemTime::now());
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    set_source_volume(value, index, channels);
 | 
					                    set_source_volume(value, index, channels, input_box_slider.clone());
 | 
				
			||||||
                    Propagation::Proceed
 | 
					                    Propagation::Proceed
 | 
				
			||||||
                }),
 | 
					                }),
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
| 
						 | 
					@ -78,7 +81,7 @@ impl SourceEntry {
 | 
				
			||||||
                if button.is_active() {
 | 
					                if button.is_active() {
 | 
				
			||||||
                    let name = name.clone();
 | 
					                    let name = name.clone();
 | 
				
			||||||
                    gio::spawn_blocking(move || {
 | 
					                    gio::spawn_blocking(move || {
 | 
				
			||||||
                        let result = set_default_source(name);
 | 
					                        let result = set_default_source(name, input_box.clone());
 | 
				
			||||||
                        if result.is_none() {
 | 
					                        if result.is_none() {
 | 
				
			||||||
                            return;
 | 
					                            return;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
| 
						 | 
					@ -97,7 +100,7 @@ impl SourceEntry {
 | 
				
			||||||
                        imp.reset_source_mute
 | 
					                        imp.reset_source_mute
 | 
				
			||||||
                           .set_icon_name("audio-input-microphone-symbolic");
 | 
					                           .set_icon_name("audio-input-microphone-symbolic");
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    toggle_source_mute(source.index, source.muted);
 | 
					                    toggle_source_mute(source.index, source.muted, input_box_ref.clone());
 | 
				
			||||||
                }));
 | 
					                }));
 | 
				
			||||||
            set_action_row_ellipsis(imp.reset_source_name.get());
 | 
					            set_action_row_ellipsis(imp.reset_source_name.get());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -105,58 +108,39 @@ impl SourceEntry {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn set_source_volume(value: f64, index: u32, channels: u16) -> bool {
 | 
					pub fn set_source_volume(value: f64, index: u32, channels: u16, 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();
 | 
				
			||||||
        let proxy = conn.with_proxy(
 | 
					        let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
            BASE,
 | 
					        let res: Result<(), Error> =
 | 
				
			||||||
            DBUS_PATH,
 | 
					            proxy.method_call(AUDIO, "SetSourceVolume", (index, channels, value as u32));
 | 
				
			||||||
            Duration::from_millis(1000),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        let _: Result<(), Error> = proxy.method_call(
 | 
					 | 
				
			||||||
            AUDIO,
 | 
					 | 
				
			||||||
            "SetSourceVolume",
 | 
					 | 
				
			||||||
            (index, channels, value as u32),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        // if res.is_err() {
 | 
					 | 
				
			||||||
        //     return false;
 | 
					 | 
				
			||||||
        // }
 | 
					 | 
				
			||||||
        // res.unwrap().0
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    true
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn toggle_source_mute(index: u32, muted: bool) -> bool {
 | 
					 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					 | 
				
			||||||
        let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
        let proxy = conn.with_proxy(
 | 
					 | 
				
			||||||
            BASE,
 | 
					 | 
				
			||||||
            DBUS_PATH,
 | 
					 | 
				
			||||||
            Duration::from_millis(1000),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        let _: Result<(), Error> =
 | 
					 | 
				
			||||||
            proxy.method_call(AUDIO, "SetSourceMute", (index, muted));
 | 
					 | 
				
			||||||
        // if res.is_err() {
 | 
					 | 
				
			||||||
        //     return false;
 | 
					 | 
				
			||||||
        // }
 | 
					 | 
				
			||||||
        // res.unwrap().0
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    true
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn set_default_source(name: Arc<String>) -> Option<Source> {
 | 
					 | 
				
			||||||
    let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
    let proxy = conn.with_proxy(
 | 
					 | 
				
			||||||
        BASE,
 | 
					 | 
				
			||||||
        DBUS_PATH,
 | 
					 | 
				
			||||||
        Duration::from_millis(1000),
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    let res: Result<(Source,), Error> = proxy.method_call(
 | 
					 | 
				
			||||||
        AUDIO,
 | 
					 | 
				
			||||||
        "SetDefaultSource",
 | 
					 | 
				
			||||||
        (name.as_str(),),
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
        if res.is_err() {
 | 
					        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 {
 | 
				
			||||||
 | 
					    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, "SetSourceMute", (index, muted));
 | 
				
			||||||
 | 
					        if res.is_err() {
 | 
				
			||||||
 | 
					            show_error::<SourceBox>(input_box.clone(), "Failed to mute source");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn set_default_source(name: Arc<String>, input_box: Arc<SourceBox>) -> Option<Source> {
 | 
				
			||||||
 | 
					    let conn = Connection::new_session().unwrap();
 | 
				
			||||||
 | 
					    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
 | 
					    let res: Result<(Source,), Error> =
 | 
				
			||||||
 | 
					        proxy.method_call(AUDIO, "SetDefaultSource", (name.as_str(),));
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<SourceBox>(input_box.clone(), "Failed to set default source");
 | 
				
			||||||
        return None;
 | 
					        return None;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    Some(res.unwrap().0)
 | 
					    Some(res.unwrap().0)
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ use std::sync::Arc;
 | 
				
			||||||
use std::time::SystemTime;
 | 
					use std::time::SystemTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, Button, CheckButton, CompositeTemplate, Label, Scale};
 | 
					use gtk::{Button, CheckButton, CompositeTemplate, Label, Scale};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::source_entry;
 | 
					use super::source_entry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								src/components/audio/mod.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								src/components/audio/mod.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,2 @@
 | 
				
			||||||
 | 
					pub mod input;
 | 
				
			||||||
 | 
					pub mod output;
 | 
				
			||||||
| 
						 | 
					@ -1,16 +1,17 @@
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
use std::time::{Duration, SystemTime};
 | 
					use std::time::{Duration, SystemTime};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::base::error_impl::show_error;
 | 
				
			||||||
use crate::components::utils::{
 | 
					use crate::components::utils::{
 | 
				
			||||||
    create_dropdown_label_factory, set_combo_row_ellipsis, AUDIO, BASE, DBUS_PATH,
 | 
					    create_dropdown_label_factory, set_combo_row_ellipsis, AUDIO, BASE, DBUS_PATH,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use adw::glib;
 | 
					 | 
				
			||||||
use adw::glib::Object;
 | 
					use adw::glib::Object;
 | 
				
			||||||
use adw::prelude::{ButtonExt, ComboRowExt, PreferencesRowExt, RangeExt};
 | 
					use adw::prelude::{ButtonExt, ComboRowExt, PreferencesRowExt, RangeExt};
 | 
				
			||||||
use dbus::blocking::Connection;
 | 
					use dbus::blocking::Connection;
 | 
				
			||||||
use dbus::Error;
 | 
					use dbus::Error;
 | 
				
			||||||
use glib::subclass::types::ObjectSubclassIsExt;
 | 
					use glib::subclass::types::ObjectSubclassIsExt;
 | 
				
			||||||
use glib::{clone, Cast, Propagation};
 | 
					use glib::{clone, Propagation};
 | 
				
			||||||
 | 
					use glib::prelude::Cast;
 | 
				
			||||||
use gtk::{gio, StringObject};
 | 
					use gtk::{gio, StringObject};
 | 
				
			||||||
use re_set_lib::audio::audio_structures::InputStream;
 | 
					use re_set_lib::audio::audio_structures::InputStream;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,6 +31,9 @@ impl InputStreamEntry {
 | 
				
			||||||
    pub fn new(sink_box: Arc<SinkBox>, stream: InputStream) -> Self {
 | 
					    pub fn new(sink_box: Arc<SinkBox>, stream: InputStream) -> Self {
 | 
				
			||||||
        let obj: Self = Object::builder().build();
 | 
					        let obj: Self = Object::builder().build();
 | 
				
			||||||
        // TODO use event callback for progress bar -> this is the "im speaking" indicator
 | 
					        // TODO use event callback for progress bar -> this is the "im speaking" indicator
 | 
				
			||||||
 | 
					        let output_box_mute_ref = sink_box.clone();
 | 
				
			||||||
 | 
					        let output_box_volume_ref = sink_box.clone();
 | 
				
			||||||
 | 
					        let output_box_sink_ref = sink_box.clone();
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            let index = stream.sink_index;
 | 
					            let index = stream.sink_index;
 | 
				
			||||||
            let box_imp = sink_box.imp();
 | 
					            let box_imp = sink_box.imp();
 | 
				
			||||||
| 
						 | 
					@ -75,7 +79,7 @@ impl InputStreamEntry {
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        *time = Some(SystemTime::now());
 | 
					                        *time = Some(SystemTime::now());
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    set_inputstream_volume(value, index, channels);
 | 
					                    set_inputstream_volume(value, index, channels, output_box_volume_ref.clone());
 | 
				
			||||||
                    Propagation::Proceed
 | 
					                    Propagation::Proceed
 | 
				
			||||||
                }),
 | 
					                }),
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
| 
						 | 
					@ -131,7 +135,7 @@ impl InputStreamEntry {
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    let stream = stream.unwrap();
 | 
					                    let stream = stream.unwrap();
 | 
				
			||||||
                let sink = sink.unwrap().0;
 | 
					                let sink = sink.unwrap().0;
 | 
				
			||||||
                    set_sink_of_input_stream(stream.index, sink);
 | 
					                    set_sink_of_input_stream(stream.index, sink, output_box_sink_ref.clone());
 | 
				
			||||||
                }),
 | 
					                }),
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
            imp.reset_sink_mute
 | 
					            imp.reset_sink_mute
 | 
				
			||||||
| 
						 | 
					@ -152,54 +156,50 @@ impl InputStreamEntry {
 | 
				
			||||||
                        imp.reset_sink_mute
 | 
					                        imp.reset_sink_mute
 | 
				
			||||||
                           .set_icon_name("audio-volume-high-symbolic");
 | 
					                           .set_icon_name("audio-volume-high-symbolic");
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    toggle_input_stream_mute(index, muted);
 | 
					                    toggle_input_stream_mute(index, muted, output_box_mute_ref.clone());
 | 
				
			||||||
                }));
 | 
					                }));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        obj
 | 
					        obj
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn set_inputstream_volume(value: f64, index: u32, channels: u16) -> bool {
 | 
					fn set_inputstream_volume(value: f64, index: u32, channels: u16, output_box: Arc<SinkBox>) -> 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 _: Result<(), Error> = proxy.method_call(
 | 
					        let res: Result<(), Error> = proxy.method_call(
 | 
				
			||||||
            AUDIO,
 | 
					            AUDIO,
 | 
				
			||||||
            "SetInputStreamVolume",
 | 
					            "SetInputStreamVolume",
 | 
				
			||||||
            (index, channels, value as u32),
 | 
					            (index, channels, value as u32),
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        // if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
        //     return false;
 | 
					            show_error::<SinkBox>(output_box.clone(), "Failed to set input stream volume");
 | 
				
			||||||
        // }
 | 
					        }
 | 
				
			||||||
        // res.unwrap().0
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    true
 | 
					    true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn toggle_input_stream_mute(index: u32, muted: bool) -> bool {
 | 
					fn toggle_input_stream_mute(index: u32, muted: bool, output_box: Arc<SinkBox>) -> 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 _: Result<(), Error> = proxy.method_call(AUDIO, "SetInputStreamMute", (index, muted));
 | 
					        let res: Result<(), Error> = proxy.method_call(AUDIO, "SetInputStreamMute", (index, muted));
 | 
				
			||||||
        // if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
        //     return false;
 | 
					            show_error::<SinkBox>(output_box.clone(), "Failed to mute input stream");
 | 
				
			||||||
        // }
 | 
					        }
 | 
				
			||||||
        // res.unwrap().0
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    true
 | 
					    true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn set_sink_of_input_stream(stream: u32, sink: u32) -> bool {
 | 
					fn set_sink_of_input_stream(stream: u32, sink: u32, output_box: Arc<SinkBox>) -> 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 _: Result<(), Error> = proxy.method_call(AUDIO, "SetSinkOfInputStream", (stream, sink));
 | 
					        let res: Result<(), Error> =
 | 
				
			||||||
        // if res.is_err() {
 | 
					            proxy.method_call(AUDIO, "SetSinkOfInputStream", (stream, sink));
 | 
				
			||||||
        //     return false;
 | 
					        if res.is_err() {
 | 
				
			||||||
        // }
 | 
					            show_error::<SinkBox>(output_box.clone(), "Failed to set sink of input stream");
 | 
				
			||||||
        // res.unwrap().0
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    true
 | 
					    true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
// TODO propagate error from dbus
 | 
					 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ use std::sync::Arc;
 | 
				
			||||||
use std::time::SystemTime;
 | 
					use std::time::SystemTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, Button, CompositeTemplate, Label, Scale};
 | 
					use gtk::{Button, CompositeTemplate, Label, Scale};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::input_stream_entry;
 | 
					use super::input_stream_entry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,8 @@
 | 
				
			||||||
pub mod input_stream_entry;
 | 
					pub mod input_stream_entry;
 | 
				
			||||||
pub mod input_stream_entry_impl;
 | 
					pub mod input_stream_entry_impl;
 | 
				
			||||||
pub mod sink_box;
 | 
					pub mod sink_box;
 | 
				
			||||||
 | 
					mod sink_box_handlers;
 | 
				
			||||||
pub mod sink_box_impl;
 | 
					pub mod sink_box_impl;
 | 
				
			||||||
 | 
					mod sink_box_utils;
 | 
				
			||||||
pub mod sink_entry;
 | 
					pub mod sink_entry;
 | 
				
			||||||
pub mod sink_entry_impl;
 | 
					pub mod sink_entry_impl;
 | 
				
			||||||
							
								
								
									
										203
									
								
								src/components/audio/output/sink_box.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										203
									
								
								src/components/audio/output/sink_box.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,203 @@
 | 
				
			||||||
 | 
					use re_set_lib::signals::InputStreamAdded;
 | 
				
			||||||
 | 
					use re_set_lib::signals::InputStreamChanged;
 | 
				
			||||||
 | 
					use re_set_lib::signals::InputStreamRemoved;
 | 
				
			||||||
 | 
					use re_set_lib::signals::SinkAdded;
 | 
				
			||||||
 | 
					use re_set_lib::signals::SinkChanged;
 | 
				
			||||||
 | 
					use re_set_lib::signals::SinkRemoved;
 | 
				
			||||||
 | 
					use std::sync::Arc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use adw::glib::Object;
 | 
				
			||||||
 | 
					use adw::prelude::ComboRowExt;
 | 
				
			||||||
 | 
					use adw::prelude::ListBoxRowExt;
 | 
				
			||||||
 | 
					use dbus::blocking::Connection;
 | 
				
			||||||
 | 
					use dbus::message::SignalArgs;
 | 
				
			||||||
 | 
					use dbus::Path;
 | 
				
			||||||
 | 
					use glib::subclass::prelude::ObjectSubclassIsExt;
 | 
				
			||||||
 | 
					use glib::Variant;
 | 
				
			||||||
 | 
					use gtk::gio;
 | 
				
			||||||
 | 
					use gtk::prelude::ActionableExt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::base::error_impl::ReSetErrorImpl;
 | 
				
			||||||
 | 
					use crate::components::utils::BASE;
 | 
				
			||||||
 | 
					use crate::components::utils::DBUS_PATH;
 | 
				
			||||||
 | 
					use crate::components::utils::{create_dropdown_label_factory, set_combo_row_ellipsis};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::sink_box_handlers::input_stream_added_handler;
 | 
				
			||||||
 | 
					use super::sink_box_handlers::input_stream_changed_handler;
 | 
				
			||||||
 | 
					use super::sink_box_handlers::input_stream_removed_handler;
 | 
				
			||||||
 | 
					use super::sink_box_handlers::sink_added_handler;
 | 
				
			||||||
 | 
					use super::sink_box_handlers::sink_changed_handler;
 | 
				
			||||||
 | 
					use super::sink_box_handlers::sink_removed_handler;
 | 
				
			||||||
 | 
					use super::sink_box_impl;
 | 
				
			||||||
 | 
					use super::sink_box_utils::get_default_sink;
 | 
				
			||||||
 | 
					use super::sink_box_utils::get_sinks;
 | 
				
			||||||
 | 
					use super::sink_box_utils::populate_cards;
 | 
				
			||||||
 | 
					use super::sink_box_utils::populate_inputstreams;
 | 
				
			||||||
 | 
					use super::sink_box_utils::populate_sink_information;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					glib::wrapper! {
 | 
				
			||||||
 | 
					    pub struct SinkBox(ObjectSubclass<sink_box_impl::SinkBox>)
 | 
				
			||||||
 | 
					    @extends gtk::Box, gtk::Widget,
 | 
				
			||||||
 | 
					    @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsafe impl Send for SinkBox {}
 | 
				
			||||||
 | 
					unsafe impl Sync for SinkBox {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl ReSetErrorImpl for SinkBox {
 | 
				
			||||||
 | 
					    fn error(
 | 
				
			||||||
 | 
					        &self,
 | 
				
			||||||
 | 
					    ) -> >k::subclass::prelude::TemplateChild<crate::components::base::error::ReSetError> {
 | 
				
			||||||
 | 
					        &self.imp().error
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl SinkBox {
 | 
				
			||||||
 | 
					    pub fn new() -> Self {
 | 
				
			||||||
 | 
					        let obj: Self = Object::builder().build();
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            let imp = obj.imp();
 | 
				
			||||||
 | 
					            let mut model_index = imp.reset_model_index.write().unwrap();
 | 
				
			||||||
 | 
					            *model_index = 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        obj
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn setup_callbacks(&self) {
 | 
				
			||||||
 | 
					        let self_imp = self.imp();
 | 
				
			||||||
 | 
					        self_imp.reset_sinks_row.set_activatable(true);
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_sinks_row
 | 
				
			||||||
 | 
					            .set_action_name(Some("navigation.push"));
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_sinks_row
 | 
				
			||||||
 | 
					            .set_action_target_value(Some(&Variant::from("outputDevices")));
 | 
				
			||||||
 | 
					        self_imp.reset_cards_row.set_activatable(true);
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_cards_row
 | 
				
			||||||
 | 
					            .set_action_name(Some("navigation.push"));
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_cards_row
 | 
				
			||||||
 | 
					            .set_action_target_value(Some(&Variant::from("profileConfiguration")));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self_imp.reset_input_stream_button.set_activatable(true);
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_input_stream_button
 | 
				
			||||||
 | 
					            .set_action_name(Some("navigation.pop"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self_imp.reset_input_cards_back_button.set_activatable(true);
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_input_cards_back_button
 | 
				
			||||||
 | 
					            .set_action_name(Some("navigation.pop"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_sink_dropdown
 | 
				
			||||||
 | 
					            .set_factory(Some(&create_dropdown_label_factory()));
 | 
				
			||||||
 | 
					        set_combo_row_ellipsis(self_imp.reset_sink_dropdown.get());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Default for SinkBox {
 | 
				
			||||||
 | 
					    fn default() -> Self {
 | 
				
			||||||
 | 
					        Self::new()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn populate_sinks(sink_box: Arc<SinkBox>) {
 | 
				
			||||||
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
 | 
					        let sinks = get_sinks(sink_box.clone());
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            let sink_box_imp = sink_box.imp();
 | 
				
			||||||
 | 
					            let list = sink_box_imp.reset_model_list.write().unwrap();
 | 
				
			||||||
 | 
					            let mut map = sink_box_imp.reset_sink_map.write().unwrap();
 | 
				
			||||||
 | 
					            let mut model_index = sink_box_imp.reset_model_index.write().unwrap();
 | 
				
			||||||
 | 
					            sink_box_imp
 | 
				
			||||||
 | 
					                .reset_default_sink
 | 
				
			||||||
 | 
					                .replace(get_default_sink(sink_box.clone()));
 | 
				
			||||||
 | 
					            for sink in sinks.iter() {
 | 
				
			||||||
 | 
					                list.append(&sink.alias);
 | 
				
			||||||
 | 
					                map.insert(sink.alias.clone(), (sink.index, sink.name.clone()));
 | 
				
			||||||
 | 
					                *model_index += 1;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        populate_inputstreams(sink_box.clone());
 | 
				
			||||||
 | 
					        populate_cards(sink_box.clone());
 | 
				
			||||||
 | 
					        populate_sink_information(sink_box, sinks);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn start_sink_box_listener(conn: Connection, sink_box: Arc<SinkBox>) -> Connection {
 | 
				
			||||||
 | 
					    let sink_added =
 | 
				
			||||||
 | 
					        SinkAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
 | 
				
			||||||
 | 
					    let sink_removed =
 | 
				
			||||||
 | 
					        SinkRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
 | 
				
			||||||
 | 
					    let sink_changed =
 | 
				
			||||||
 | 
					        SinkChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
 | 
				
			||||||
 | 
					    let input_stream_added =
 | 
				
			||||||
 | 
					        InputStreamAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
 | 
				
			||||||
 | 
					            .static_clone();
 | 
				
			||||||
 | 
					    let input_stream_removed =
 | 
				
			||||||
 | 
					        InputStreamRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
 | 
				
			||||||
 | 
					            .static_clone();
 | 
				
			||||||
 | 
					    let input_stream_changed =
 | 
				
			||||||
 | 
					        InputStreamChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
 | 
				
			||||||
 | 
					            .static_clone();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let sink_added_box = sink_box.clone();
 | 
				
			||||||
 | 
					    let sink_removed_box = sink_box.clone();
 | 
				
			||||||
 | 
					    let sink_changed_box = sink_box.clone();
 | 
				
			||||||
 | 
					    let input_stream_added_box = sink_box.clone();
 | 
				
			||||||
 | 
					    let input_stream_removed_box = sink_box.clone();
 | 
				
			||||||
 | 
					    let input_stream_changed_box = sink_box.clone();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let res = conn.add_match(sink_added, move |ir: SinkAdded, _, _| {
 | 
				
			||||||
 | 
					        sink_added_handler(sink_added_box.clone(), ir)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        // TODO: handle this with the log/error macro
 | 
				
			||||||
 | 
					        println!("fail on sink add event");
 | 
				
			||||||
 | 
					        return conn;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let res = conn.add_match(sink_removed, move |ir: SinkRemoved, _, _| {
 | 
				
			||||||
 | 
					        sink_removed_handler(sink_removed_box.clone(), ir)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        println!("fail on sink remove event");
 | 
				
			||||||
 | 
					        return conn;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let res = conn.add_match(sink_changed, move |ir: SinkChanged, _, _| {
 | 
				
			||||||
 | 
					        sink_changed_handler(sink_changed_box.clone(), ir)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        println!("fail on sink change event");
 | 
				
			||||||
 | 
					        return conn;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let res = conn.add_match(input_stream_added, move |ir: InputStreamAdded, _, _| {
 | 
				
			||||||
 | 
					        input_stream_added_handler(input_stream_added_box.clone(), ir)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        println!("fail on input stream add event");
 | 
				
			||||||
 | 
					        return conn;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let res = conn.add_match(input_stream_removed, move |ir: InputStreamRemoved, _, _| {
 | 
				
			||||||
 | 
					        input_stream_removed_handler(input_stream_removed_box.clone(), ir)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        println!("fail on input stream remove event");
 | 
				
			||||||
 | 
					        return conn;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let res = conn.add_match(input_stream_changed, move |ir: InputStreamChanged, _, _| {
 | 
				
			||||||
 | 
					        input_stream_changed_handler(input_stream_changed_box.clone(), ir)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        println!("fail on input stream change event");
 | 
				
			||||||
 | 
					        return conn;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    conn
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										308
									
								
								src/components/audio/output/sink_box_handlers.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										308
									
								
								src/components/audio/output/sink_box_handlers.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,308 @@
 | 
				
			||||||
 | 
					use std::{
 | 
				
			||||||
 | 
					    sync::Arc,
 | 
				
			||||||
 | 
					    time::{Duration, SystemTime},
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use adw::{
 | 
				
			||||||
 | 
					    prelude::{ComboRowExt, PreferencesRowExt},
 | 
				
			||||||
 | 
					    ComboRow,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					use glib::{subclass::types::ObjectSubclassIsExt, Propagation};
 | 
				
			||||||
 | 
					use glib::prelude::Cast;
 | 
				
			||||||
 | 
					use gtk::{
 | 
				
			||||||
 | 
					    gio,
 | 
				
			||||||
 | 
					    prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt},
 | 
				
			||||||
 | 
					    StringObject,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					use re_set_lib::signals::{
 | 
				
			||||||
 | 
					    InputStreamAdded, InputStreamChanged, InputStreamRemoved, SinkAdded, SinkChanged, SinkRemoved,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::base::list_entry::ListEntry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::{
 | 
				
			||||||
 | 
					    input_stream_entry::InputStreamEntry,
 | 
				
			||||||
 | 
					    sink_box::SinkBox,
 | 
				
			||||||
 | 
					    sink_box_utils::{get_default_sink_name, refresh_default_sink},
 | 
				
			||||||
 | 
					    sink_entry::{set_default_sink, set_sink_volume, toggle_sink_mute, SinkEntry},
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn drop_down_handler(sink_box: Arc<SinkBox>, dropdown: &ComboRow) {
 | 
				
			||||||
 | 
					    let sink_box_ref = sink_box.clone();
 | 
				
			||||||
 | 
					    let sink_box_imp = sink_box.imp();
 | 
				
			||||||
 | 
					    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 sink = sink_box_imp.reset_sink_map.read().unwrap();
 | 
				
			||||||
 | 
					    let sink = sink.get(&selected);
 | 
				
			||||||
 | 
					    if sink.is_none() {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let new_sink_name = Arc::new(sink.unwrap().1.clone());
 | 
				
			||||||
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
 | 
					        let result = set_default_sink(new_sink_name, sink_box_ref.clone());
 | 
				
			||||||
 | 
					        if result.is_none() {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        let new_sink = result.unwrap();
 | 
				
			||||||
 | 
					        refresh_default_sink(new_sink, sink_box_ref, false);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn volume_slider_handler(sink_box: Arc<SinkBox>, value: f64) -> glib::Propagation {
 | 
				
			||||||
 | 
					    let imp = sink_box.imp();
 | 
				
			||||||
 | 
					    let fraction = (value / 655.36).round();
 | 
				
			||||||
 | 
					    let percentage = (fraction).to_string() + "%";
 | 
				
			||||||
 | 
					    imp.reset_volume_percentage.set_text(&percentage);
 | 
				
			||||||
 | 
					    let sink = imp.reset_default_sink.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, sink_box.clone());
 | 
				
			||||||
 | 
					    Propagation::Proceed
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn mute_handler(sink_box: Arc<SinkBox>) {
 | 
				
			||||||
 | 
					    let imp = sink_box.imp();
 | 
				
			||||||
 | 
					    let mut stream = imp.reset_default_sink.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, sink_box.clone());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn sink_added_handler(sink_box: Arc<SinkBox>, ir: SinkAdded) -> bool {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let sink_box_imp = sink_box.imp();
 | 
				
			||||||
 | 
					            let sink_index = ir.sink.index;
 | 
				
			||||||
 | 
					            let alias = ir.sink.alias.clone();
 | 
				
			||||||
 | 
					            let name = ir.sink.name.clone();
 | 
				
			||||||
 | 
					            let mut is_default = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if sink_box_imp.reset_default_sink.borrow().name == ir.sink.name {
 | 
				
			||||||
 | 
					                is_default = true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let sink_entry = Arc::new(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);
 | 
				
			||||||
 | 
					            let mut list = sink_box_imp.reset_sink_list.write().unwrap();
 | 
				
			||||||
 | 
					            list.insert(sink_index, (entry.clone(), sink_clone, alias.clone()));
 | 
				
			||||||
 | 
					            sink_box_imp.reset_sinks.append(&*entry);
 | 
				
			||||||
 | 
					            let mut map = sink_box_imp.reset_sink_map.write().unwrap();
 | 
				
			||||||
 | 
					            let mut index = sink_box_imp.reset_model_index.write().unwrap();
 | 
				
			||||||
 | 
					            let model_list = sink_box_imp.reset_model_list.write().unwrap();
 | 
				
			||||||
 | 
					            if model_list.string(*index - 1) == Some("Dummy Output".into()) {
 | 
				
			||||||
 | 
					                model_list.append(&alias);
 | 
				
			||||||
 | 
					                model_list.remove(*index - 1);
 | 
				
			||||||
 | 
					                map.insert(alias, (sink_index, name));
 | 
				
			||||||
 | 
					                sink_box_imp.reset_sink_dropdown.set_selected(0);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                model_list.append(&alias);
 | 
				
			||||||
 | 
					                map.insert(alias.clone(), (sink_index, name));
 | 
				
			||||||
 | 
					                if alias == "Dummy Output" {
 | 
				
			||||||
 | 
					                    sink_box_imp.reset_sink_dropdown.set_selected(0);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                *index += 1;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn sink_removed_handler(sink_box: Arc<SinkBox>, ir: SinkRemoved) -> bool {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let sink_box_imp = sink_box.imp();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            let entry: Option<(Arc<ListEntry>, Arc<SinkEntry>, String)>;
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                let mut list = sink_box_imp.reset_sink_list.write().unwrap();
 | 
				
			||||||
 | 
					                entry = list.remove(&ir.index);
 | 
				
			||||||
 | 
					                if entry.is_none() {
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            sink_box_imp.reset_sinks.remove(&*entry.clone().unwrap().0);
 | 
				
			||||||
 | 
					            let alias = entry.unwrap().2;
 | 
				
			||||||
 | 
					            let mut index = sink_box_imp.reset_model_index.write().unwrap();
 | 
				
			||||||
 | 
					            let model_list = sink_box_imp.reset_model_list.write().unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // add dummy entry when no other devices are available
 | 
				
			||||||
 | 
					            if *index == 1 {
 | 
				
			||||||
 | 
					                model_list.append("Dummy Output");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            let mut map = sink_box_imp.reset_sink_map.write().unwrap();
 | 
				
			||||||
 | 
					            map.remove(&alias);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for entry in 0..*index {
 | 
				
			||||||
 | 
					                if model_list.string(entry) == Some(alias.clone().into()) {
 | 
				
			||||||
 | 
					                    model_list.splice(entry, 1, &[]);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // dummy enforces a minimum of 1
 | 
				
			||||||
 | 
					            if *index > 1 {
 | 
				
			||||||
 | 
					                *index -= 1;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn sink_changed_handler(sink_box: Arc<SinkBox>, ir: SinkChanged) -> bool {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let default_sink = get_default_sink_name(sink_box.clone());
 | 
				
			||||||
 | 
					            let sink_box_imp = sink_box.imp();
 | 
				
			||||||
 | 
					            let is_default = ir.sink.name == default_sink;
 | 
				
			||||||
 | 
					            let volume = ir.sink.volume.first().unwrap_or(&0_u32);
 | 
				
			||||||
 | 
					            let fraction = (*volume as f64 / 655.36).round();
 | 
				
			||||||
 | 
					            let percentage = (fraction).to_string() + "%";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            let list = sink_box_imp.reset_sink_list.read().unwrap();
 | 
				
			||||||
 | 
					            let entry = list.get(&ir.sink.index);
 | 
				
			||||||
 | 
					            if entry.is_none() {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let imp = entry.unwrap().1.imp();
 | 
				
			||||||
 | 
					            if is_default {
 | 
				
			||||||
 | 
					                sink_box_imp.reset_volume_percentage.set_text(&percentage);
 | 
				
			||||||
 | 
					                sink_box_imp.reset_volume_slider.set_value(*volume as f64);
 | 
				
			||||||
 | 
					                sink_box_imp.reset_default_sink.replace(ir.sink.clone());
 | 
				
			||||||
 | 
					                if ir.sink.muted {
 | 
				
			||||||
 | 
					                    sink_box_imp
 | 
				
			||||||
 | 
					                        .reset_sink_mute
 | 
				
			||||||
 | 
					                        .set_icon_name("audio-volume-muted-symbolic");
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    sink_box_imp
 | 
				
			||||||
 | 
					                        .reset_sink_mute
 | 
				
			||||||
 | 
					                        .set_icon_name("audio-volume-high-symbolic");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                imp.reset_selected_sink.set_active(true);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                imp.reset_selected_sink.set_active(false);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            imp.reset_sink_name
 | 
				
			||||||
 | 
					                .set_title(ir.sink.alias.clone().as_str());
 | 
				
			||||||
 | 
					            imp.reset_volume_percentage.set_text(&percentage);
 | 
				
			||||||
 | 
					            imp.reset_volume_slider.set_value(*volume as f64);
 | 
				
			||||||
 | 
					            if ir.sink.muted {
 | 
				
			||||||
 | 
					                imp.reset_sink_mute
 | 
				
			||||||
 | 
					                    .set_icon_name("audio-volume-muted-symbolic");
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                imp.reset_sink_mute
 | 
				
			||||||
 | 
					                    .set_icon_name("audio-volume-high-symbolic");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn input_stream_added_handler(sink_box: Arc<SinkBox>, ir: InputStreamAdded) -> bool {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let sink_box_imp = sink_box.imp();
 | 
				
			||||||
 | 
					            let mut list = sink_box_imp.reset_input_stream_list.write().unwrap();
 | 
				
			||||||
 | 
					            let index = ir.stream.index;
 | 
				
			||||||
 | 
					            let input_stream = Arc::new(InputStreamEntry::new(sink_box.clone(), ir.stream));
 | 
				
			||||||
 | 
					            let entry = Arc::new(ListEntry::new(&*input_stream));
 | 
				
			||||||
 | 
					            entry.set_activatable(false);
 | 
				
			||||||
 | 
					            list.insert(index, (entry.clone(), input_stream.clone()));
 | 
				
			||||||
 | 
					            sink_box_imp.reset_input_streams.append(&*entry);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn input_stream_removed_handler(sink_box: Arc<SinkBox>, ir: InputStreamRemoved) -> bool {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let sink_box_imp = sink_box.imp();
 | 
				
			||||||
 | 
					            let mut list = sink_box_imp.reset_input_stream_list.write().unwrap();
 | 
				
			||||||
 | 
					            let entry = list.remove(&ir.index);
 | 
				
			||||||
 | 
					            if entry.is_none() {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            sink_box_imp.reset_input_streams.remove(&*entry.unwrap().0);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn input_stream_changed_handler(sink_box: Arc<SinkBox>, ir: InputStreamChanged) -> bool {
 | 
				
			||||||
 | 
					    let imp = sink_box.imp();
 | 
				
			||||||
 | 
					    let alias: String;
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        let sink_list = imp.reset_sink_list.read().unwrap();
 | 
				
			||||||
 | 
					        if let Some(alias_opt) = sink_list.get(&ir.stream.sink_index) {
 | 
				
			||||||
 | 
					            alias = alias_opt.2.clone();
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            alias = String::from("");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let sink_box = sink_box.clone();
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let sink_box = sink_box.clone();
 | 
				
			||||||
 | 
					            let sink_box_imp = sink_box.imp();
 | 
				
			||||||
 | 
					            let entry: Arc<InputStreamEntry>;
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                let list = sink_box_imp.reset_input_stream_list.read().unwrap();
 | 
				
			||||||
 | 
					                let entry_opt = list.get(&ir.stream.index);
 | 
				
			||||||
 | 
					                if entry_opt.is_none() {
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                entry = entry_opt.unwrap().1.clone();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let imp = entry.imp();
 | 
				
			||||||
 | 
					            if ir.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");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let name = ir.stream.application_name.clone() + ": " + ir.stream.name.as_str();
 | 
				
			||||||
 | 
					            imp.reset_sink_selection.set_title(name.as_str());
 | 
				
			||||||
 | 
					            let volume = ir.stream.volume.first().unwrap_or(&0_u32);
 | 
				
			||||||
 | 
					            let fraction = (*volume as f64 / 655.36).round();
 | 
				
			||||||
 | 
					            let percentage = (fraction).to_string() + "%";
 | 
				
			||||||
 | 
					            imp.reset_volume_percentage.set_text(&percentage);
 | 
				
			||||||
 | 
					            imp.reset_volume_slider.set_value(*volume as f64);
 | 
				
			||||||
 | 
					            let index = sink_box_imp.reset_model_index.read().unwrap();
 | 
				
			||||||
 | 
					            let model_list = sink_box_imp.reset_model_list.read().unwrap();
 | 
				
			||||||
 | 
					            for entry in 0..*index {
 | 
				
			||||||
 | 
					                if model_list.string(entry) == Some(alias.clone().into()) {
 | 
				
			||||||
 | 
					                    imp.reset_sink_selection.set_selected(entry);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -5,11 +5,12 @@ 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::output::input_stream_entry::InputStreamEntry;
 | 
				
			||||||
 | 
					use crate::components::base::error::ReSetError;
 | 
				
			||||||
use crate::components::base::list_entry::ListEntry;
 | 
					use crate::components::base::list_entry::ListEntry;
 | 
				
			||||||
use crate::components::output::input_stream_entry::InputStreamEntry;
 | 
					 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, Box, Button, CheckButton, CompositeTemplate, Label, StringList, TemplateChild};
 | 
					 | 
				
			||||||
use gtk::{prelude::*, Scale};
 | 
					use gtk::{prelude::*, Scale};
 | 
				
			||||||
 | 
					use gtk::{Box, Button, CheckButton, CompositeTemplate, Label, StringList};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::sink_box;
 | 
					use super::sink_box;
 | 
				
			||||||
use super::sink_entry::SinkEntry;
 | 
					use super::sink_entry::SinkEntry;
 | 
				
			||||||
| 
						 | 
					@ -45,6 +46,8 @@ pub struct SinkBox {
 | 
				
			||||||
    pub reset_input_cards_back_button: TemplateChild<ActionRow>,
 | 
					    pub reset_input_cards_back_button: TemplateChild<ActionRow>,
 | 
				
			||||||
    #[template_child]
 | 
					    #[template_child]
 | 
				
			||||||
    pub reset_cards: TemplateChild<PreferencesGroup>,
 | 
					    pub reset_cards: TemplateChild<PreferencesGroup>,
 | 
				
			||||||
 | 
					    #[template_child]
 | 
				
			||||||
 | 
					    pub error: TemplateChild<ReSetError>,
 | 
				
			||||||
    pub reset_default_check_button: Arc<CheckButton>,
 | 
					    pub reset_default_check_button: Arc<CheckButton>,
 | 
				
			||||||
    pub reset_default_sink: Arc<RefCell<Sink>>,
 | 
					    pub reset_default_sink: Arc<RefCell<Sink>>,
 | 
				
			||||||
    pub reset_sink_list: SinkEntryMap,
 | 
					    pub reset_sink_list: SinkEntryMap,
 | 
				
			||||||
							
								
								
									
										232
									
								
								src/components/audio/output/sink_box_utils.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										232
									
								
								src/components/audio/output/sink_box_utils.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,232 @@
 | 
				
			||||||
 | 
					use std::{sync::Arc, time::Duration};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use adw::prelude::{ComboRowExt, PreferencesGroupExt};
 | 
				
			||||||
 | 
					use dbus::{blocking::Connection, Error};
 | 
				
			||||||
 | 
					use glib::subclass::types::ObjectSubclassIsExt;
 | 
				
			||||||
 | 
					use gtk::{
 | 
				
			||||||
 | 
					    gio,
 | 
				
			||||||
 | 
					    prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt},
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					use re_set_lib::audio::audio_structures::{Card, InputStream, Sink};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::{
 | 
				
			||||||
 | 
					    base::{card_entry::CardEntry, error_impl::show_error, list_entry::ListEntry},
 | 
				
			||||||
 | 
					    utils::{AUDIO, BASE, DBUS_PATH},
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::{
 | 
				
			||||||
 | 
					    input_stream_entry::InputStreamEntry,
 | 
				
			||||||
 | 
					    sink_box::SinkBox,
 | 
				
			||||||
 | 
					    sink_box_handlers::{drop_down_handler, mute_handler, volume_slider_handler},
 | 
				
			||||||
 | 
					    sink_entry::SinkEntry,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn populate_sink_information(sink_box: Arc<SinkBox>, sinks: Vec<Sink>) {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let sink_box_ref_select = sink_box.clone();
 | 
				
			||||||
 | 
					            let sink_box_ref_slider = sink_box.clone();
 | 
				
			||||||
 | 
					            let sink_box_ref_mute = sink_box.clone();
 | 
				
			||||||
 | 
					            let sink_box_ref = sink_box.clone();
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                let sink_box_imp = sink_box_ref.imp();
 | 
				
			||||||
 | 
					                let default_sink = sink_box_imp.reset_default_sink.clone();
 | 
				
			||||||
 | 
					                let sink = default_sink.borrow();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if sink.muted {
 | 
				
			||||||
 | 
					                    sink_box_imp
 | 
				
			||||||
 | 
					                        .reset_sink_mute
 | 
				
			||||||
 | 
					                        .set_icon_name("audio-volume-muted-symbolic");
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    sink_box_imp
 | 
				
			||||||
 | 
					                        .reset_sink_mute
 | 
				
			||||||
 | 
					                        .set_icon_name("audio-volume-high-symbolic");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                let volume = sink.volume.first().unwrap_or(&0);
 | 
				
			||||||
 | 
					                let fraction = (*volume as f64 / 655.36).round();
 | 
				
			||||||
 | 
					                let percentage = (fraction).to_string() + "%";
 | 
				
			||||||
 | 
					                sink_box_imp.reset_volume_percentage.set_text(&percentage);
 | 
				
			||||||
 | 
					                sink_box_imp.reset_volume_slider.set_value(*volume as f64);
 | 
				
			||||||
 | 
					                let mut list = sink_box_imp.reset_sink_list.write().unwrap();
 | 
				
			||||||
 | 
					                for sink in sinks {
 | 
				
			||||||
 | 
					                    let index = sink.index;
 | 
				
			||||||
 | 
					                    let alias = sink.alias.clone();
 | 
				
			||||||
 | 
					                    let mut is_default = false;
 | 
				
			||||||
 | 
					                    if sink_box_imp.reset_default_sink.borrow().name == sink.name {
 | 
				
			||||||
 | 
					                        is_default = true;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    let sink_entry = Arc::new(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);
 | 
				
			||||||
 | 
					                    list.insert(index, (entry.clone(), sink_clone, alias));
 | 
				
			||||||
 | 
					                    sink_box_imp.reset_sinks.append(&*entry);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                let list = sink_box_imp.reset_model_list.read().unwrap();
 | 
				
			||||||
 | 
					                sink_box_imp.reset_sink_dropdown.set_model(Some(&*list));
 | 
				
			||||||
 | 
					                let name = sink_box_imp.reset_default_sink.borrow();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                let index = sink_box_imp.reset_model_index.read().unwrap();
 | 
				
			||||||
 | 
					                let model_list = sink_box_imp.reset_model_list.read().unwrap();
 | 
				
			||||||
 | 
					                for entry in 0..*index {
 | 
				
			||||||
 | 
					                    if model_list.string(entry) == Some(name.alias.clone().into()) {
 | 
				
			||||||
 | 
					                        sink_box_imp.reset_sink_dropdown.set_selected(entry);
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                sink_box_imp
 | 
				
			||||||
 | 
					                    .reset_sink_dropdown
 | 
				
			||||||
 | 
					                    .connect_selected_notify(move |dropdown| {
 | 
				
			||||||
 | 
					                        drop_down_handler(sink_box_ref_select.clone(), dropdown);
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            sink_box_ref
 | 
				
			||||||
 | 
					                .imp()
 | 
				
			||||||
 | 
					                .reset_volume_slider
 | 
				
			||||||
 | 
					                .connect_change_value(move |_, _, value| {
 | 
				
			||||||
 | 
					                    volume_slider_handler(sink_box_ref_slider.clone(), value)
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            sink_box_ref
 | 
				
			||||||
 | 
					                .imp()
 | 
				
			||||||
 | 
					                .reset_sink_mute
 | 
				
			||||||
 | 
					                .connect_clicked(move |_| {
 | 
				
			||||||
 | 
					                    mute_handler(sink_box_ref_mute.clone());
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn refresh_default_sink(new_sink: Sink, sink_box: Arc<SinkBox>, entry: bool) {
 | 
				
			||||||
 | 
					    let volume = *new_sink.volume.first().unwrap_or(&0_u32);
 | 
				
			||||||
 | 
					    let fraction = (volume as f64 / 655.36).round();
 | 
				
			||||||
 | 
					    let percentage = (fraction).to_string() + "%";
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let imp = sink_box.imp();
 | 
				
			||||||
 | 
					            if !entry {
 | 
				
			||||||
 | 
					                let list = imp.reset_sink_list.read().unwrap();
 | 
				
			||||||
 | 
					                let entry = list.get(&new_sink.index);
 | 
				
			||||||
 | 
					                if entry.is_none() {
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                let entry_imp = entry.unwrap().1.imp();
 | 
				
			||||||
 | 
					                entry_imp.reset_selected_sink.set_active(true);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                let index = imp.reset_model_index.read().unwrap();
 | 
				
			||||||
 | 
					                let model_list = imp.reset_model_list.read().unwrap();
 | 
				
			||||||
 | 
					                for entry in 0..*index {
 | 
				
			||||||
 | 
					                    if model_list.string(entry) == Some(new_sink.alias.clone().into()) {
 | 
				
			||||||
 | 
					                        imp.reset_sink_dropdown.set_selected(entry);
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            imp.reset_volume_percentage.set_text(&percentage);
 | 
				
			||||||
 | 
					            imp.reset_volume_slider.set_value(volume as f64);
 | 
				
			||||||
 | 
					            if new_sink.muted {
 | 
				
			||||||
 | 
					                imp.reset_sink_mute
 | 
				
			||||||
 | 
					                    .set_icon_name("audio-volume-muted-symbolic");
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                imp.reset_sink_mute
 | 
				
			||||||
 | 
					                    .set_icon_name("audio-volume-high-symbolic");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            imp.reset_default_sink.replace(new_sink);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn populate_inputstreams(sink_box: Arc<SinkBox>) {
 | 
				
			||||||
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
 | 
					        let streams = get_input_streams(sink_box.clone());
 | 
				
			||||||
 | 
					        glib::spawn_future(async move {
 | 
				
			||||||
 | 
					            glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					                let sink_box_imp = sink_box.imp();
 | 
				
			||||||
 | 
					                let mut list = sink_box_imp.reset_input_stream_list.write().unwrap();
 | 
				
			||||||
 | 
					                for stream in streams {
 | 
				
			||||||
 | 
					                    let index = stream.index;
 | 
				
			||||||
 | 
					                    let input_stream = Arc::new(InputStreamEntry::new(sink_box.clone(), stream));
 | 
				
			||||||
 | 
					                    let entry = Arc::new(ListEntry::new(&*input_stream));
 | 
				
			||||||
 | 
					                    entry.set_activatable(false);
 | 
				
			||||||
 | 
					                    list.insert(index, (entry.clone(), input_stream.clone()));
 | 
				
			||||||
 | 
					                    sink_box_imp.reset_input_streams.append(&*entry);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn populate_cards(sink_box: Arc<SinkBox>) {
 | 
				
			||||||
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
 | 
					        let sink_box_ref = sink_box.clone();
 | 
				
			||||||
 | 
					        let cards = get_cards(sink_box.clone());
 | 
				
			||||||
 | 
					        glib::spawn_future(async move {
 | 
				
			||||||
 | 
					            glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					                let imp = sink_box_ref.imp();
 | 
				
			||||||
 | 
					                for card in cards {
 | 
				
			||||||
 | 
					                    imp.reset_cards.add(&CardEntry::new(card));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn get_input_streams(sink_box: Arc<SinkBox>) -> Vec<InputStream> {
 | 
				
			||||||
 | 
					    let conn = Connection::new_session().unwrap();
 | 
				
			||||||
 | 
					    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
 | 
					    let res: Result<(Vec<InputStream>,), Error> = proxy.method_call(AUDIO, "ListInputStreams", ());
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<SinkBox>(sink_box.clone(), "Failed to list input streams");
 | 
				
			||||||
 | 
					        return Vec::new();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    res.unwrap().0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn get_sinks(sink_box: Arc<SinkBox>) -> Vec<Sink> {
 | 
				
			||||||
 | 
					    let conn = Connection::new_session().unwrap();
 | 
				
			||||||
 | 
					    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
 | 
					    let res: Result<(Vec<Sink>,), Error> = proxy.method_call(AUDIO, "ListSinks", ());
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<SinkBox>(sink_box.clone(), "Failed to list sinks");
 | 
				
			||||||
 | 
					        return Vec::new();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    res.unwrap().0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn get_cards(sink_box: Arc<SinkBox>) -> Vec<Card> {
 | 
				
			||||||
 | 
					    let conn = Connection::new_session().unwrap();
 | 
				
			||||||
 | 
					    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
 | 
					    let res: Result<(Vec<Card>,), Error> = proxy.method_call(AUDIO, "ListCards", ());
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<SinkBox>(sink_box.clone(), "Failed to list profiles");
 | 
				
			||||||
 | 
					        return Vec::new();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    res.unwrap().0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn get_default_sink_name(sink_box: Arc<SinkBox>) -> String {
 | 
				
			||||||
 | 
					    let conn = Connection::new_session().unwrap();
 | 
				
			||||||
 | 
					    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
 | 
					    let res: Result<(String,), Error> = proxy.method_call(AUDIO, "GetDefaultSinkName", ());
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<SinkBox>(sink_box.clone(), "Failed to get default sink name");
 | 
				
			||||||
 | 
					        return String::from("");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    res.unwrap().0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn get_default_sink(sink_box: Arc<SinkBox>) -> Sink {
 | 
				
			||||||
 | 
					    let conn = Connection::new_session().unwrap();
 | 
				
			||||||
 | 
					    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
 | 
					    let res: Result<(Sink,), Error> = proxy.method_call(AUDIO, "GetDefaultSink", ());
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<SinkBox>(sink_box.clone(), "Failed to get default sink");
 | 
				
			||||||
 | 
					        return Sink::default();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    res.unwrap().0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,8 @@
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
use std::time::{Duration, SystemTime};
 | 
					use std::time::{Duration, SystemTime};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use adw::glib;
 | 
					use crate::components::base::error_impl::show_error;
 | 
				
			||||||
 | 
					use crate::components::utils::set_action_row_ellipsis;
 | 
				
			||||||
use adw::glib::Object;
 | 
					use adw::glib::Object;
 | 
				
			||||||
use adw::prelude::{ButtonExt, CheckButtonExt, PreferencesRowExt, RangeExt};
 | 
					use adw::prelude::{ButtonExt, CheckButtonExt, PreferencesRowExt, RangeExt};
 | 
				
			||||||
use dbus::blocking::Connection;
 | 
					use dbus::blocking::Connection;
 | 
				
			||||||
| 
						 | 
					@ -10,11 +11,11 @@ use glib::subclass::types::ObjectSubclassIsExt;
 | 
				
			||||||
use glib::{clone, Propagation};
 | 
					use glib::{clone, Propagation};
 | 
				
			||||||
use gtk::{gio, CheckButton};
 | 
					use gtk::{gio, CheckButton};
 | 
				
			||||||
use re_set_lib::audio::audio_structures::Sink;
 | 
					use re_set_lib::audio::audio_structures::Sink;
 | 
				
			||||||
use crate::components::utils::set_action_row_ellipsis;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::components::utils::{AUDIO, DBUS_PATH, BASE};
 | 
					use crate::components::utils::{AUDIO, BASE, DBUS_PATH};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::sink_box::{refresh_default_sink, SinkBox};
 | 
					use super::sink_box::SinkBox;
 | 
				
			||||||
 | 
					use super::sink_box_utils::refresh_default_sink;
 | 
				
			||||||
use super::sink_entry_impl;
 | 
					use super::sink_entry_impl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
glib::wrapper! {
 | 
					glib::wrapper! {
 | 
				
			||||||
| 
						 | 
					@ -42,6 +43,8 @@ impl SinkEntry {
 | 
				
			||||||
            let volume = stream.volume.first().unwrap_or(&0_u32);
 | 
					            let volume = stream.volume.first().unwrap_or(&0_u32);
 | 
				
			||||||
            let fraction = (*volume as f64 / 655.36).round();
 | 
					            let fraction = (*volume as f64 / 655.36).round();
 | 
				
			||||||
            let percentage = (fraction).to_string() + "%";
 | 
					            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_percentage.set_text(&percentage);
 | 
				
			||||||
            imp.reset_volume_slider.set_value(*volume as f64);
 | 
					            imp.reset_volume_slider.set_value(*volume as f64);
 | 
				
			||||||
            imp.stream.replace(stream);
 | 
					            imp.stream.replace(stream);
 | 
				
			||||||
| 
						 | 
					@ -60,7 +63,7 @@ impl SinkEntry {
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        *time = Some(SystemTime::now());
 | 
					                        *time = Some(SystemTime::now());
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                     set_sink_volume(value, index, channels);
 | 
					                     set_sink_volume(value, index, channels, output_box_slider.clone());
 | 
				
			||||||
                    Propagation::Proceed
 | 
					                    Propagation::Proceed
 | 
				
			||||||
                }),
 | 
					                }),
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
| 
						 | 
					@ -75,7 +78,7 @@ impl SinkEntry {
 | 
				
			||||||
                if button.is_active() {
 | 
					                if button.is_active() {
 | 
				
			||||||
                    let name = name.clone();
 | 
					                    let name = name.clone();
 | 
				
			||||||
                    gio::spawn_blocking(move || {
 | 
					                    gio::spawn_blocking(move || {
 | 
				
			||||||
                        let result = set_default_sink(name);
 | 
					                        let result = set_default_sink(name, output_box_ref.clone());
 | 
				
			||||||
                        if result.is_none() {
 | 
					                        if result.is_none() {
 | 
				
			||||||
                            return;
 | 
					                            return;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
| 
						 | 
					@ -95,7 +98,7 @@ impl SinkEntry {
 | 
				
			||||||
                        imp.reset_sink_mute
 | 
					                        imp.reset_sink_mute
 | 
				
			||||||
                           .set_icon_name("audio-volume-high-symbolic");
 | 
					                           .set_icon_name("audio-volume-high-symbolic");
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    toggle_sink_mute(stream.index, stream.muted);
 | 
					                    toggle_sink_mute(stream.index, stream.muted, output_box_ref.clone());
 | 
				
			||||||
                }));
 | 
					                }));
 | 
				
			||||||
            set_action_row_ellipsis(imp.reset_sink_name.get());
 | 
					            set_action_row_ellipsis(imp.reset_sink_name.get());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -103,55 +106,37 @@ impl SinkEntry {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn set_sink_volume(value: f64, index: u32, channels: u16) -> bool {
 | 
					pub fn set_sink_volume(value: f64, index: u32, channels: u16, output_box: Arc<SinkBox>) -> 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(
 | 
					        let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
            BASE,
 | 
					        let res: Result<(), Error> =
 | 
				
			||||||
            DBUS_PATH,
 | 
					            proxy.method_call(AUDIO, "SetSinkVolume", (index, channels, value as u32));
 | 
				
			||||||
            Duration::from_millis(1000),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        let _: Result<(), Error> = proxy.method_call(
 | 
					 | 
				
			||||||
            AUDIO,
 | 
					 | 
				
			||||||
            "SetSinkVolume",
 | 
					 | 
				
			||||||
            (index, channels, value as u32),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        // if res.is_err() {
 | 
					 | 
				
			||||||
        //     return false;
 | 
					 | 
				
			||||||
        // }
 | 
					 | 
				
			||||||
        // res.unwrap().0
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    true
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn toggle_sink_mute(index: u32, muted: bool) -> bool {
 | 
					 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					 | 
				
			||||||
        let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
        let proxy = conn.with_proxy(
 | 
					 | 
				
			||||||
            BASE,
 | 
					 | 
				
			||||||
            DBUS_PATH,
 | 
					 | 
				
			||||||
            Duration::from_millis(1000),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        let _: Result<(), Error> =
 | 
					 | 
				
			||||||
            proxy.method_call(AUDIO, "SetSinkMute", (index, muted));
 | 
					 | 
				
			||||||
        // if res.is_err() {
 | 
					 | 
				
			||||||
        //     return false;
 | 
					 | 
				
			||||||
        // }
 | 
					 | 
				
			||||||
        // res.unwrap().0
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    true
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn set_default_sink(name: Arc<String>) -> Option<Sink> {
 | 
					 | 
				
			||||||
    let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
    let proxy = conn.with_proxy(
 | 
					 | 
				
			||||||
        BASE,
 | 
					 | 
				
			||||||
        DBUS_PATH,
 | 
					 | 
				
			||||||
        Duration::from_millis(1000),
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    let res: Result<(Sink,), Error> =
 | 
					 | 
				
			||||||
        proxy.method_call(AUDIO, "SetDefaultSink", (name.as_str(),));
 | 
					 | 
				
			||||||
        if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
 | 
					            show_error::<SinkBox>(output_box, "Failed to set sink volume")
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn toggle_sink_mute(index: u32, muted: bool, output_box: Arc<SinkBox>) -> 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, "SetSinkMute", (index, muted));
 | 
				
			||||||
 | 
					        if res.is_err() {
 | 
				
			||||||
 | 
					            show_error::<SinkBox>(output_box, "Failed to mute sink")
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn set_default_sink(name: Arc<String>, output_box: Arc<SinkBox>) -> Option<Sink> {
 | 
				
			||||||
 | 
					    let conn = Connection::new_session().unwrap();
 | 
				
			||||||
 | 
					    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
 | 
					    let res: Result<(Sink,), Error> = proxy.method_call(AUDIO, "SetDefaultSink", (name.as_str(),));
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<SinkBox>(output_box, "Failed to set default sink");
 | 
				
			||||||
        return None;
 | 
					        return None;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    Some(res.unwrap().0)
 | 
					    Some(res.unwrap().0)
 | 
				
			||||||
| 
						 | 
					@ -5,9 +5,9 @@ use std::cell::RefCell;
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
use std::time::SystemTime;
 | 
					use std::time::SystemTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::components::output::sink_entry;
 | 
					use crate::components::audio::output::sink_entry;
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, Button, CheckButton, CompositeTemplate, Label, Scale};
 | 
					use gtk::{Button, CheckButton, CompositeTemplate, Label, Scale};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default, CompositeTemplate)]
 | 
					#[derive(Default, CompositeTemplate)]
 | 
				
			||||||
#[template(resource = "/org/Xetibo/ReSet/resetSinkEntry.ui")]
 | 
					#[template(resource = "/org/Xetibo/ReSet/resetSinkEntry.ui")]
 | 
				
			||||||
| 
						 | 
					@ -1,19 +1,19 @@
 | 
				
			||||||
use std::time::Duration;
 | 
					use std::time::Duration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use adw::glib;
 | 
					 | 
				
			||||||
use adw::glib::Object;
 | 
					use adw::glib::Object;
 | 
				
			||||||
use adw::prelude::{ComboRowExt, PreferencesRowExt};
 | 
					use adw::prelude::{ComboRowExt, PreferencesRowExt};
 | 
				
			||||||
use dbus::blocking::Connection;
 | 
					use dbus::blocking::Connection;
 | 
				
			||||||
use dbus::Error;
 | 
					use dbus::Error;
 | 
				
			||||||
use glib::subclass::types::ObjectSubclassIsExt;
 | 
					use glib::subclass::types::ObjectSubclassIsExt;
 | 
				
			||||||
use glib::{clone, Cast};
 | 
					use glib::{clone};
 | 
				
			||||||
 | 
					use glib::prelude::Cast;
 | 
				
			||||||
use gtk::{gio, StringList, StringObject};
 | 
					use gtk::{gio, StringList, StringObject};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use components::utils::create_dropdown_label_factory;
 | 
					use components::utils::create_dropdown_label_factory;
 | 
				
			||||||
use re_set_lib::audio::audio_structures::Card;
 | 
					use re_set_lib::audio::audio_structures::Card;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::components;
 | 
					use crate::components;
 | 
				
			||||||
use crate::components::utils::{BASE, DBUS_PATH, AUDIO};
 | 
					use crate::components::utils::{AUDIO, BASE, DBUS_PATH};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::card_entry_impl;
 | 
					use super::card_entry_impl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,11 +66,7 @@ impl CardEntry {
 | 
				
			||||||
fn set_card_profile_of_device(device_index: u32, profile_name: String) -> bool {
 | 
					fn set_card_profile_of_device(device_index: u32, profile_name: String) -> 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(
 | 
					        let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
            BASE,
 | 
					 | 
				
			||||||
            DBUS_PATH,
 | 
					 | 
				
			||||||
            Duration::from_millis(1000),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        let _: Result<(), Error> = proxy.method_call(
 | 
					        let _: Result<(), Error> = proxy.method_call(
 | 
				
			||||||
            AUDIO,
 | 
					            AUDIO,
 | 
				
			||||||
            "SetCardProfileOfDevice",
 | 
					            "SetCardProfileOfDevice",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ use std::cell::RefCell;
 | 
				
			||||||
use std::collections::HashMap;
 | 
					use std::collections::HashMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, CompositeTemplate};
 | 
					use gtk::CompositeTemplate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::card_entry;
 | 
					use super::card_entry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										38
									
								
								src/components/base/error.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/components/base/error.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,38 @@
 | 
				
			||||||
 | 
					use adw::glib::Object;
 | 
				
			||||||
 | 
					use glib::{clone, subclass::types::ObjectSubclassIsExt};
 | 
				
			||||||
 | 
					use gtk::{
 | 
				
			||||||
 | 
					    gdk,
 | 
				
			||||||
 | 
					    prelude::{ButtonExt, PopoverExt},
 | 
				
			||||||
 | 
					    Editable, Popover,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::error_impl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					glib::wrapper! {
 | 
				
			||||||
 | 
					    pub struct ReSetError(ObjectSubclass<error_impl::ReSetError>)
 | 
				
			||||||
 | 
					    @extends Popover, gtk::Widget,
 | 
				
			||||||
 | 
					    @implements Editable,gdk::Popup, gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsafe impl Send for ReSetError {}
 | 
				
			||||||
 | 
					unsafe impl Sync for ReSetError {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl ReSetError {
 | 
				
			||||||
 | 
					    pub fn new() -> Self {
 | 
				
			||||||
 | 
					        let error: ReSetError = Object::builder().build();
 | 
				
			||||||
 | 
					        error
 | 
				
			||||||
 | 
					            .imp()
 | 
				
			||||||
 | 
					            .reset_error_button
 | 
				
			||||||
 | 
					            .connect_clicked(clone!(@strong error => move |_| {
 | 
				
			||||||
 | 
					                println!("pingpangpung");
 | 
				
			||||||
 | 
					               error.popdown();
 | 
				
			||||||
 | 
					            }));
 | 
				
			||||||
 | 
					        error
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Default for ReSetError {
 | 
				
			||||||
 | 
					    fn default() -> Self {
 | 
				
			||||||
 | 
					        Self::new()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										74
									
								
								src/components/base/error_impl.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								src/components/base/error_impl.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,74 @@
 | 
				
			||||||
 | 
					use std::sync::Arc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use gtk::prelude::{ButtonExt, PopoverExt};
 | 
				
			||||||
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
 | 
					use gtk::{Button, CompositeTemplate, Label, Popover};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Default, CompositeTemplate)]
 | 
				
			||||||
 | 
					#[template(resource = "/org/Xetibo/ReSet/resetError.ui")]
 | 
				
			||||||
 | 
					pub struct ReSetError {
 | 
				
			||||||
 | 
					    #[template_child]
 | 
				
			||||||
 | 
					    pub reset_error_label: TemplateChild<Label>,
 | 
				
			||||||
 | 
					    #[template_child]
 | 
				
			||||||
 | 
					    pub reset_error_button: TemplateChild<Button>,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsafe impl Send for ReSetError {}
 | 
				
			||||||
 | 
					unsafe impl Sync for ReSetError {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[glib::object_subclass]
 | 
				
			||||||
 | 
					impl ObjectSubclass for ReSetError {
 | 
				
			||||||
 | 
					    const ABSTRACT: bool = false;
 | 
				
			||||||
 | 
					    const NAME: &'static str = "resetError";
 | 
				
			||||||
 | 
					    type Type = error::ReSetError;
 | 
				
			||||||
 | 
					    type ParentType = Popover;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn class_init(klass: &mut Self::Class) {
 | 
				
			||||||
 | 
					        klass.bind_template();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
 | 
				
			||||||
 | 
					        obj.init_template();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl ObjectImpl for ReSetError {
 | 
				
			||||||
 | 
					    fn constructed(&self) {
 | 
				
			||||||
 | 
					        self.parent_constructed();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl WidgetImpl for ReSetError {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl WindowImpl for ReSetError {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl PopoverImpl for ReSetError {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl ApplicationWindowImpl for ReSetError {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl EditableImpl for ReSetError {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn show_error<T: ReSetErrorImpl + Send + Sync + 'static>(
 | 
				
			||||||
 | 
					    parent: Arc<T>,
 | 
				
			||||||
 | 
					    message: &'static str,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
 | 
					    // TODO: Add error to log
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let error = parent.error();
 | 
				
			||||||
 | 
					            let parent_ref = parent.clone();
 | 
				
			||||||
 | 
					            let imp = error.imp();
 | 
				
			||||||
 | 
					            imp.reset_error_label.set_text(message);
 | 
				
			||||||
 | 
					            imp.reset_error_button.connect_clicked(move |_| {
 | 
				
			||||||
 | 
					                parent_ref.error().popdown();
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            error.popup();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub trait ReSetErrorImpl: Send + Sync {
 | 
				
			||||||
 | 
					    fn error(&self) -> &TemplateChild<error::ReSetError>;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
use crate::components::base::list_entry_impl;
 | 
					use crate::components::base::list_entry_impl;
 | 
				
			||||||
use adw::glib;
 | 
					use adw::glib::{Object};
 | 
				
			||||||
use adw::glib::{IsA, Object};
 | 
					use glib::prelude::IsA;
 | 
				
			||||||
use gtk::prelude::ListBoxRowExt;
 | 
					use gtk::prelude::ListBoxRowExt;
 | 
				
			||||||
use gtk::Widget;
 | 
					use gtk::Widget;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
use crate::components::base::list_entry;
 | 
					use crate::components::base::list_entry;
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, CompositeTemplate};
 | 
					use gtk::CompositeTemplate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default, CompositeTemplate)]
 | 
					#[derive(Default, CompositeTemplate)]
 | 
				
			||||||
#[template(resource = "/org/Xetibo/ReSet/resetListBoxRow.ui")]
 | 
					#[template(resource = "/org/Xetibo/ReSet/resetListBoxRow.ui")]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,7 @@
 | 
				
			||||||
pub mod card_entry;
 | 
					pub mod card_entry;
 | 
				
			||||||
pub mod card_entry_impl;
 | 
					pub mod card_entry_impl;
 | 
				
			||||||
 | 
					pub mod error;
 | 
				
			||||||
 | 
					pub mod error_impl;
 | 
				
			||||||
pub mod list_entry;
 | 
					pub mod list_entry;
 | 
				
			||||||
pub mod list_entry_impl;
 | 
					pub mod list_entry_impl;
 | 
				
			||||||
pub mod popup;
 | 
					pub mod popup;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,3 @@
 | 
				
			||||||
use adw::glib;
 | 
					 | 
				
			||||||
use adw::glib::Object;
 | 
					use adw::glib::Object;
 | 
				
			||||||
use gtk::{gdk, Editable, Popover};
 | 
					use gtk::{gdk, Editable, Popover};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ use std::cell::RefCell;
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, Button, CompositeTemplate, Label, PasswordEntry, PasswordEntryBuffer, Popover};
 | 
					use gtk::{Button, CompositeTemplate, Label, PasswordEntry, PasswordEntryBuffer, Popover};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::popup;
 | 
					use super::popup;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,12 +1,12 @@
 | 
				
			||||||
use crate::components::base::setting_box_impl;
 | 
					use crate::components::base::setting_box_impl;
 | 
				
			||||||
use adw::glib;
 | 
					use adw::glib::{Object};
 | 
				
			||||||
use adw::glib::{IsA, Object};
 | 
					use glib::prelude::IsA;
 | 
				
			||||||
use gtk::prelude::BoxExt;
 | 
					use gtk::prelude::BoxExt;
 | 
				
			||||||
use gtk::Widget;
 | 
					use gtk::Widget;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
glib::wrapper! {
 | 
					glib::wrapper! {
 | 
				
			||||||
    pub struct SettingBox(ObjectSubclass<setting_box_impl::SettingBox>)
 | 
					    pub struct SettingBox(ObjectSubclass<setting_box_impl::SettingBox>)
 | 
				
			||||||
    @extends gtk::Box, gtk::Widget,
 | 
					    @extends gtk::Box, Widget,
 | 
				
			||||||
    @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
 | 
					    @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
use crate::components::base::setting_box;
 | 
					use crate::components::base::setting_box;
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, CompositeTemplate};
 | 
					use gtk::CompositeTemplate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default, CompositeTemplate)]
 | 
					#[derive(Default, CompositeTemplate)]
 | 
				
			||||||
#[template(resource = "/org/Xetibo/ReSet/resetSettingBox.ui")]
 | 
					#[template(resource = "/org/Xetibo/ReSet/resetSettingBox.ui")]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,8 +11,8 @@ use dbus::{blocking::Connection, Error};
 | 
				
			||||||
use gtk::gio;
 | 
					use gtk::gio;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::components::{
 | 
					use crate::components::{
 | 
				
			||||||
    input::source_box::{start_input_box_listener, SourceBox},
 | 
					    audio::input::source_box::{start_source_box_listener, SourceBox},
 | 
				
			||||||
    output::sink_box::{start_output_box_listener, SinkBox},
 | 
					    audio::output::sink_box::{start_sink_box_listener, SinkBox},
 | 
				
			||||||
    utils::{BASE, DBUS_PATH, WIRELESS},
 | 
					    utils::{BASE, DBUS_PATH, WIRELESS},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,7 @@ pub enum Position {
 | 
				
			||||||
    Audio,
 | 
					    Audio,
 | 
				
			||||||
    AudioOutput,
 | 
					    AudioOutput,
 | 
				
			||||||
    AudioInput,
 | 
					    AudioInput,
 | 
				
			||||||
 | 
					    Custom(String),
 | 
				
			||||||
    #[default]
 | 
					    #[default]
 | 
				
			||||||
    Home,
 | 
					    Home,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -71,10 +72,10 @@ pub fn start_audio_listener(
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if let Some(sink_box) = sink_box {
 | 
					        if let Some(sink_box) = sink_box {
 | 
				
			||||||
            conn = start_output_box_listener(conn, sink_box);
 | 
					            conn = start_sink_box_listener(conn, sink_box);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if let Some(source_box) = source_box {
 | 
					        if let Some(source_box) = source_box {
 | 
				
			||||||
            conn = start_input_box_listener(conn, source_box);
 | 
					            conn = start_source_box_listener(conn, source_box);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        listeners.pulse_listener.store(true, Ordering::SeqCst);
 | 
					        listeners.pulse_listener.store(true, Ordering::SeqCst);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,25 +2,31 @@ use std::sync::atomic::Ordering;
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
use std::time::{Duration, SystemTime};
 | 
					use std::time::{Duration, SystemTime};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use adw::glib;
 | 
					 | 
				
			||||||
use adw::glib::Object;
 | 
					use adw::glib::Object;
 | 
				
			||||||
use adw::prelude::{ComboRowExt, PreferencesGroupExt};
 | 
					use adw::prelude::{ComboRowExt, PreferencesGroupExt};
 | 
				
			||||||
use adw::subclass::prelude::ObjectSubclassIsExt;
 | 
					use adw::subclass::prelude::ObjectSubclassIsExt;
 | 
				
			||||||
use dbus::blocking::Connection;
 | 
					use dbus::blocking::Connection;
 | 
				
			||||||
use dbus::message::SignalArgs;
 | 
					use dbus::message::SignalArgs;
 | 
				
			||||||
use dbus::{Error, Path};
 | 
					use dbus::{Error, Path};
 | 
				
			||||||
use glib::{clone, Cast, PropertySet};
 | 
					use glib::{clone, ControlFlow};
 | 
				
			||||||
 | 
					use glib::prelude::Cast;
 | 
				
			||||||
 | 
					use glib::property::PropertySet;
 | 
				
			||||||
use gtk::glib::Variant;
 | 
					use gtk::glib::Variant;
 | 
				
			||||||
use gtk::prelude::{ActionableExt, ButtonExt, ListBoxRowExt, WidgetExt};
 | 
					use gtk::prelude::{ActionableExt, ButtonExt, ListBoxRowExt, WidgetExt};
 | 
				
			||||||
use gtk::{gio, StringObject};
 | 
					use gtk::{gio, StringObject};
 | 
				
			||||||
use re_set_lib::bluetooth::bluetooth_structures::{BluetoothAdapter, BluetoothDevice};
 | 
					use re_set_lib::bluetooth::bluetooth_structures::{BluetoothAdapter, BluetoothDevice};
 | 
				
			||||||
use re_set_lib::signals::{BluetoothDeviceAdded, BluetoothDeviceChanged, BluetoothDeviceRemoved};
 | 
					use re_set_lib::signals::{BluetoothDeviceAdded, BluetoothDeviceChanged, BluetoothDeviceRemoved};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::base::error_impl::{show_error, ReSetErrorImpl};
 | 
				
			||||||
use crate::components::base::utils::Listeners;
 | 
					use crate::components::base::utils::Listeners;
 | 
				
			||||||
use crate::components::bluetooth::bluetooth_box_impl;
 | 
					use crate::components::bluetooth::bluetooth_box_impl;
 | 
				
			||||||
use crate::components::bluetooth::bluetooth_entry::BluetoothEntry;
 | 
					use crate::components::bluetooth::bluetooth_entry::BluetoothEntry;
 | 
				
			||||||
use crate::components::utils::{BASE, BLUETOOTH, DBUS_PATH};
 | 
					use crate::components::utils::{BASE, BLUETOOTH, DBUS_PATH};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::bluetooth_event_handlers::{
 | 
				
			||||||
 | 
					    device_added_handler, device_changed_handler, device_removed_handler,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
glib::wrapper! {
 | 
					glib::wrapper! {
 | 
				
			||||||
    pub struct BluetoothBox(ObjectSubclass<bluetooth_box_impl::BluetoothBox>)
 | 
					    pub struct BluetoothBox(ObjectSubclass<bluetooth_box_impl::BluetoothBox>)
 | 
				
			||||||
    @extends gtk::Box, gtk::Widget,
 | 
					    @extends gtk::Box, gtk::Widget,
 | 
				
			||||||
| 
						 | 
					@ -30,6 +36,14 @@ glib::wrapper! {
 | 
				
			||||||
unsafe impl Send for BluetoothBox {}
 | 
					unsafe impl Send for BluetoothBox {}
 | 
				
			||||||
unsafe impl Sync for BluetoothBox {}
 | 
					unsafe impl Sync for BluetoothBox {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl ReSetErrorImpl for BluetoothBox {
 | 
				
			||||||
 | 
					    fn error(
 | 
				
			||||||
 | 
					        &self,
 | 
				
			||||||
 | 
					    ) -> >k::subclass::prelude::TemplateChild<crate::components::base::error::ReSetError> {
 | 
				
			||||||
 | 
					        &self.imp().error
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl BluetoothBox {
 | 
					impl BluetoothBox {
 | 
				
			||||||
    pub fn new(listeners: Arc<Listeners>) -> Arc<Self> {
 | 
					    pub fn new(listeners: Arc<Listeners>) -> Arc<Self> {
 | 
				
			||||||
        let obj: Arc<Self> = Arc::new(Object::builder().build());
 | 
					        let obj: Arc<Self> = Arc::new(Object::builder().build());
 | 
				
			||||||
| 
						 | 
					@ -68,23 +82,47 @@ fn setup_callbacks(
 | 
				
			||||||
                .store(true, Ordering::SeqCst);
 | 
					                .store(true, Ordering::SeqCst);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let bluetooth_box_discover = bluetooth_box.clone();
 | 
				
			||||||
    imp.reset_bluetooth_discoverable_switch
 | 
					    imp.reset_bluetooth_discoverable_switch
 | 
				
			||||||
        .connect_active_notify(clone!(@weak imp => move |state| {
 | 
					        .connect_active_notify(clone!(@weak imp => move |state| {
 | 
				
			||||||
            set_bluetooth_adapter_visibility(imp.reset_current_bluetooth_adapter.borrow().path.clone(), state.is_active());
 | 
					            set_bluetooth_adapter_visibility(
 | 
				
			||||||
 | 
					                imp.reset_current_bluetooth_adapter.borrow().path.clone(),
 | 
				
			||||||
 | 
					                state.is_active(),
 | 
				
			||||||
 | 
					                bluetooth_box_discover.clone()
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
        }));
 | 
					        }));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let bluetooth_box_pairable = bluetooth_box.clone();
 | 
				
			||||||
    imp.reset_bluetooth_pairable_switch
 | 
					    imp.reset_bluetooth_pairable_switch
 | 
				
			||||||
        .connect_active_notify(clone!(@weak imp => move |state| {
 | 
					        .connect_active_notify(clone!(@weak imp => move |state| {
 | 
				
			||||||
            set_bluetooth_adapter_pairability(imp.reset_current_bluetooth_adapter.borrow().path.clone(), state.is_active());
 | 
					            set_bluetooth_adapter_pairability(
 | 
				
			||||||
 | 
					                imp.reset_current_bluetooth_adapter.borrow().path.clone(),
 | 
				
			||||||
 | 
					                state.is_active(),
 | 
				
			||||||
 | 
					                bluetooth_box_pairable.clone()
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
        }));
 | 
					        }));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    imp.reset_bluetooth_switch.connect_state_set(
 | 
					    imp.reset_bluetooth_switch
 | 
				
			||||||
        clone!(@weak imp => @default-return glib::Propagation::Proceed, move |_, state| {
 | 
					        .connect_state_set(move |_, state| {
 | 
				
			||||||
 | 
					            bluetooth_enabled_switch_handler(
 | 
				
			||||||
 | 
					                state,
 | 
				
			||||||
 | 
					                bluetooth_box_ref.clone(),
 | 
				
			||||||
 | 
					                listeners_ref.clone(),
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    bluetooth_box
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn bluetooth_enabled_switch_handler(
 | 
				
			||||||
 | 
					    state: bool,
 | 
				
			||||||
 | 
					    bluetooth_box_ref: Arc<BluetoothBox>,
 | 
				
			||||||
 | 
					    listeners_ref: Arc<Listeners>,
 | 
				
			||||||
 | 
					) -> glib::Propagation {
 | 
				
			||||||
 | 
					    let imp = bluetooth_box_ref.imp();
 | 
				
			||||||
    if imp.reset_switch_initial.load(Ordering::SeqCst) {
 | 
					    if imp.reset_switch_initial.load(Ordering::SeqCst) {
 | 
				
			||||||
        return glib::Propagation::Proceed;
 | 
					        return glib::Propagation::Proceed;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if !state {
 | 
					    if !state {
 | 
				
			||||||
                let imp = bluetooth_box_ref.imp();
 | 
					 | 
				
			||||||
        let mut available_devices = imp.available_devices.borrow_mut();
 | 
					        let mut available_devices = imp.available_devices.borrow_mut();
 | 
				
			||||||
        let mut current_adapter = imp.reset_current_bluetooth_adapter.borrow_mut();
 | 
					        let mut current_adapter = imp.reset_current_bluetooth_adapter.borrow_mut();
 | 
				
			||||||
        for entry in available_devices.iter() {
 | 
					        for entry in available_devices.iter() {
 | 
				
			||||||
| 
						 | 
					@ -110,6 +148,7 @@ fn setup_callbacks(
 | 
				
			||||||
        let res = set_adapter_enabled(
 | 
					        let res = set_adapter_enabled(
 | 
				
			||||||
            current_adapter.path.clone(),
 | 
					            current_adapter.path.clone(),
 | 
				
			||||||
            false,
 | 
					            false,
 | 
				
			||||||
 | 
					            bluetooth_box_ref.clone(),
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        if res {
 | 
					        if res {
 | 
				
			||||||
            current_adapter.powered = false;
 | 
					            current_adapter.powered = false;
 | 
				
			||||||
| 
						 | 
					@ -123,30 +162,25 @@ fn setup_callbacks(
 | 
				
			||||||
            imp.reset_bluetooth_pairable_switch.set_sensitive(true);
 | 
					            imp.reset_bluetooth_pairable_switch.set_sensitive(true);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        gio::spawn_blocking(move || {
 | 
					        gio::spawn_blocking(move || {
 | 
				
			||||||
                    let mut current_adapter = restart_ref.imp().reset_current_bluetooth_adapter.borrow_mut();
 | 
					            let mut current_adapter = restart_ref
 | 
				
			||||||
                    if set_adapter_enabled(
 | 
					                .imp()
 | 
				
			||||||
                        current_adapter
 | 
					                .reset_current_bluetooth_adapter
 | 
				
			||||||
                            .path
 | 
					                .borrow_mut();
 | 
				
			||||||
                            .clone(),
 | 
					            if set_adapter_enabled(current_adapter.path.clone(), true, restart_ref.clone()) {
 | 
				
			||||||
                        true,
 | 
					 | 
				
			||||||
                    ) {
 | 
					 | 
				
			||||||
                current_adapter.powered = true;
 | 
					                current_adapter.powered = true;
 | 
				
			||||||
                start_bluetooth_listener(restart_listener_ref.clone(), restart_ref.clone());
 | 
					                start_bluetooth_listener(restart_listener_ref.clone(), restart_ref.clone());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    glib::Propagation::Proceed
 | 
					    glib::Propagation::Proceed
 | 
				
			||||||
        }),
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    bluetooth_box
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
 | 
					pub fn populate_connected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
 | 
				
			||||||
    // TODO handle saved devices -> they also exist
 | 
					    // TODO handle saved devices -> they also exist
 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
        let ref_box = bluetooth_box.clone();
 | 
					        let ref_box = bluetooth_box.clone();
 | 
				
			||||||
        let devices = get_connected_devices();
 | 
					        let devices = get_connected_devices(ref_box.clone());
 | 
				
			||||||
        let adapters = get_bluetooth_adapters();
 | 
					        let adapters = get_bluetooth_adapters(ref_box.clone());
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            let imp = bluetooth_box.imp();
 | 
					            let imp = bluetooth_box.imp();
 | 
				
			||||||
            let list = imp.reset_model_list.write().unwrap();
 | 
					            let list = imp.reset_model_list.write().unwrap();
 | 
				
			||||||
| 
						 | 
					@ -165,6 +199,7 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					        glib::spawn_future(async move {
 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					            glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					                let new_adapter_ref = ref_box.clone();
 | 
				
			||||||
                let imp = ref_box.imp();
 | 
					                let imp = ref_box.imp();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                let list = imp.reset_model_list.read().unwrap();
 | 
					                let list = imp.reset_model_list.read().unwrap();
 | 
				
			||||||
| 
						 | 
					@ -187,29 +222,15 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
 | 
				
			||||||
                    imp.reset_switch_initial.set(false);
 | 
					                    imp.reset_switch_initial.set(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                imp.reset_bluetooth_adapter.connect_selected_notify(
 | 
					                imp.reset_bluetooth_adapter
 | 
				
			||||||
                    clone!(@weak imp => move |dropdown| {
 | 
					                    .connect_selected_notify(move |dropdown| {
 | 
				
			||||||
                        let selected = dropdown.selected_item();
 | 
					                        select_bluetooth_adapter_handler(dropdown, new_adapter_ref.clone());
 | 
				
			||||||
                        if selected.is_none() {
 | 
					                    });
 | 
				
			||||||
                            return;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        let selected = selected.unwrap();
 | 
					 | 
				
			||||||
                        let selected = selected.downcast_ref::<StringObject>().unwrap();
 | 
					 | 
				
			||||||
                        let selected = selected.string().to_string();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        let device = imp.reset_bluetooth_adapters.read().unwrap();
 | 
					 | 
				
			||||||
                        let device = device.get(&selected);
 | 
					 | 
				
			||||||
                        if device.is_none() {
 | 
					 | 
				
			||||||
                            return;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        set_bluetooth_adapter(device.unwrap().0.path.clone());
 | 
					 | 
				
			||||||
                    }),
 | 
					 | 
				
			||||||
                );
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                for device in devices {
 | 
					                for device in devices {
 | 
				
			||||||
                    let path = device.path.clone();
 | 
					                    let path = device.path.clone();
 | 
				
			||||||
                    let connected = device.connected;
 | 
					                    let connected = device.connected;
 | 
				
			||||||
                    let bluetooth_entry = BluetoothEntry::new(device);
 | 
					                    let bluetooth_entry = BluetoothEntry::new(device, ref_box.clone());
 | 
				
			||||||
                    imp.available_devices
 | 
					                    imp.available_devices
 | 
				
			||||||
                        .borrow_mut()
 | 
					                        .borrow_mut()
 | 
				
			||||||
                        .insert(path, bluetooth_entry.clone());
 | 
					                        .insert(path, bluetooth_entry.clone());
 | 
				
			||||||
| 
						 | 
					@ -224,6 +245,28 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn select_bluetooth_adapter_handler(
 | 
				
			||||||
 | 
					    dropdown: &adw::ComboRow,
 | 
				
			||||||
 | 
					    bluetooth_box: Arc<BluetoothBox>,
 | 
				
			||||||
 | 
					) -> ControlFlow {
 | 
				
			||||||
 | 
					    let imp = bluetooth_box.imp();
 | 
				
			||||||
 | 
					    let selected = dropdown.selected_item();
 | 
				
			||||||
 | 
					    if selected.is_none() {
 | 
				
			||||||
 | 
					        return ControlFlow::Break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let selected = selected.unwrap();
 | 
				
			||||||
 | 
					    let selected = selected.downcast_ref::<StringObject>().unwrap();
 | 
				
			||||||
 | 
					    let selected = selected.string().to_string();
 | 
				
			||||||
 | 
					    let device = imp.reset_bluetooth_adapters.read().unwrap();
 | 
				
			||||||
 | 
					    let device = device.get(&selected);
 | 
				
			||||||
 | 
					    if device.is_none() {
 | 
				
			||||||
 | 
					        return ControlFlow::Break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    set_bluetooth_adapter(device.unwrap().0.path.clone(), bluetooth_box.clone());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ControlFlow::Continue
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<BluetoothBox>) {
 | 
					pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<BluetoothBox>) {
 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
        if listeners.bluetooth_listener.load(Ordering::SeqCst) {
 | 
					        if listeners.bluetooth_listener.load(Ordering::SeqCst) {
 | 
				
			||||||
| 
						 | 
					@ -242,7 +285,10 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        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 _: Result<(), Error> = proxy.method_call(BLUETOOTH, "StartBluetoothListener", ());
 | 
					        let res: Result<(), Error> = proxy.method_call(BLUETOOTH, "StartBluetoothListener", ());
 | 
				
			||||||
 | 
					        if res.is_err() {
 | 
				
			||||||
 | 
					            show_error::<BluetoothBox>(bluetooth_box.clone(), "Failed to start bluetooth listener");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        imp.reset_bluetooth_available_devices
 | 
					        imp.reset_bluetooth_available_devices
 | 
				
			||||||
            .set_description(Some("Scanning..."));
 | 
					            .set_description(Some("Scanning..."));
 | 
				
			||||||
        let device_added =
 | 
					        let device_added =
 | 
				
			||||||
| 
						 | 
					@ -256,24 +302,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
 | 
				
			||||||
                .static_clone();
 | 
					                .static_clone();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let res = conn.add_match(device_added, move |ir: BluetoothDeviceAdded, _, _| {
 | 
					        let res = conn.add_match(device_added, move |ir: BluetoothDeviceAdded, _, _| {
 | 
				
			||||||
            let bluetooth_box = device_added_box.clone();
 | 
					            device_added_handler(device_added_box.clone(), ir)
 | 
				
			||||||
            glib::spawn_future(async move {
 | 
					 | 
				
			||||||
                glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                    let imp = bluetooth_box.imp();
 | 
					 | 
				
			||||||
                    let path = ir.bluetooth_device.path.clone();
 | 
					 | 
				
			||||||
                    let connected = ir.bluetooth_device.connected;
 | 
					 | 
				
			||||||
                    let bluetooth_entry = BluetoothEntry::new(ir.bluetooth_device);
 | 
					 | 
				
			||||||
                    imp.available_devices
 | 
					 | 
				
			||||||
                        .borrow_mut()
 | 
					 | 
				
			||||||
                        .insert(path, bluetooth_entry.clone());
 | 
					 | 
				
			||||||
                    if connected {
 | 
					 | 
				
			||||||
                        imp.reset_bluetooth_connected_devices.add(&*bluetooth_entry);
 | 
					 | 
				
			||||||
                    } else {
 | 
					 | 
				
			||||||
                        imp.reset_bluetooth_available_devices.add(&*bluetooth_entry);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            true
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
            println!("fail on bluetooth device add event");
 | 
					            println!("fail on bluetooth device add event");
 | 
				
			||||||
| 
						 | 
					@ -281,21 +310,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let res = conn.add_match(device_removed, move |ir: BluetoothDeviceRemoved, _, _| {
 | 
					        let res = conn.add_match(device_removed, move |ir: BluetoothDeviceRemoved, _, _| {
 | 
				
			||||||
            let bluetooth_box = device_removed_box.clone();
 | 
					            device_removed_handler(device_removed_box.clone(), ir)
 | 
				
			||||||
            glib::spawn_future(async move {
 | 
					 | 
				
			||||||
                glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                    let imp = bluetooth_box.imp();
 | 
					 | 
				
			||||||
                    let mut map = imp.available_devices.borrow_mut();
 | 
					 | 
				
			||||||
                    if let Some(list_entry) = map.remove(&ir.bluetooth_device) {
 | 
					 | 
				
			||||||
                        if list_entry.imp().bluetooth_device.borrow().connected {
 | 
					 | 
				
			||||||
                            imp.reset_bluetooth_connected_devices.remove(&*list_entry);
 | 
					 | 
				
			||||||
                        } else {
 | 
					 | 
				
			||||||
                            imp.reset_bluetooth_available_devices.remove(&*list_entry);
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            true
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
            println!("fail on bluetooth device remove event");
 | 
					            println!("fail on bluetooth device remove event");
 | 
				
			||||||
| 
						 | 
					@ -303,43 +318,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let res = conn.add_match(device_changed, move |ir: BluetoothDeviceChanged, _, _| {
 | 
					        let res = conn.add_match(device_changed, move |ir: BluetoothDeviceChanged, _, _| {
 | 
				
			||||||
            let bluetooth_box = device_changed_box.clone();
 | 
					            device_changed_handler(device_changed_box.clone(), ir)
 | 
				
			||||||
            glib::spawn_future(async move {
 | 
					 | 
				
			||||||
                glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                    let imp = bluetooth_box.imp();
 | 
					 | 
				
			||||||
                    let mut map = imp.available_devices.borrow_mut();
 | 
					 | 
				
			||||||
                    if let Some(list_entry) = map.get_mut(&ir.bluetooth_device.path) {
 | 
					 | 
				
			||||||
                        let mut existing_bluetooth_device =
 | 
					 | 
				
			||||||
                            list_entry.imp().bluetooth_device.borrow_mut();
 | 
					 | 
				
			||||||
                        if existing_bluetooth_device.connected != ir.bluetooth_device.connected {
 | 
					 | 
				
			||||||
                            if ir.bluetooth_device.connected {
 | 
					 | 
				
			||||||
                                imp.reset_bluetooth_available_devices.remove(&**list_entry);
 | 
					 | 
				
			||||||
                                imp.reset_bluetooth_connected_devices.add(&**list_entry);
 | 
					 | 
				
			||||||
                            } else {
 | 
					 | 
				
			||||||
                                imp.reset_bluetooth_connected_devices.remove(&**list_entry);
 | 
					 | 
				
			||||||
                                imp.reset_bluetooth_available_devices.add(&**list_entry);
 | 
					 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        if existing_bluetooth_device.bonded != ir.bluetooth_device.bonded {
 | 
					 | 
				
			||||||
                            if ir.bluetooth_device.bonded {
 | 
					 | 
				
			||||||
                                list_entry
 | 
					 | 
				
			||||||
                                    .imp()
 | 
					 | 
				
			||||||
                                    .remove_device_button
 | 
					 | 
				
			||||||
                                    .borrow()
 | 
					 | 
				
			||||||
                                    .set_sensitive(true);
 | 
					 | 
				
			||||||
                            } else {
 | 
					 | 
				
			||||||
                                list_entry
 | 
					 | 
				
			||||||
                                    .imp()
 | 
					 | 
				
			||||||
                                    .remove_device_button
 | 
					 | 
				
			||||||
                                    .borrow()
 | 
					 | 
				
			||||||
                                    .set_sensitive(false);
 | 
					 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        *existing_bluetooth_device = ir.bluetooth_device;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            true
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
            println!("fail on bluetooth device remove event");
 | 
					            println!("fail on bluetooth device remove event");
 | 
				
			||||||
| 
						 | 
					@ -347,14 +326,40 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        listeners.bluetooth_listener.store(true, Ordering::SeqCst);
 | 
					        listeners.bluetooth_listener.store(true, Ordering::SeqCst);
 | 
				
			||||||
        let mut time = SystemTime::now();
 | 
					        let time = SystemTime::now();
 | 
				
			||||||
        let mut listener_active = true;
 | 
					        let listener_active = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        bluetooth_listener_loop(
 | 
				
			||||||
 | 
					            &conn,
 | 
				
			||||||
 | 
					            listeners,
 | 
				
			||||||
 | 
					            proxy,
 | 
				
			||||||
 | 
					            bluetooth_box,
 | 
				
			||||||
 | 
					            loop_box,
 | 
				
			||||||
 | 
					            listener_active,
 | 
				
			||||||
 | 
					            time,
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn bluetooth_listener_loop(
 | 
				
			||||||
 | 
					    conn: &Connection,
 | 
				
			||||||
 | 
					    listeners: Arc<Listeners>,
 | 
				
			||||||
 | 
					    proxy: dbus::blocking::Proxy<'_, &Connection>,
 | 
				
			||||||
 | 
					    bluetooth_box: Arc<BluetoothBox>,
 | 
				
			||||||
 | 
					    loop_box: Arc<BluetoothBox>,
 | 
				
			||||||
 | 
					    mut listener_active: bool,
 | 
				
			||||||
 | 
					    mut time: SystemTime,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    loop {
 | 
					    loop {
 | 
				
			||||||
        let _ = conn.process(Duration::from_millis(1000));
 | 
					        let _ = conn.process(Duration::from_millis(1000));
 | 
				
			||||||
        if !listeners.bluetooth_listener.load(Ordering::SeqCst) {
 | 
					        if !listeners.bluetooth_listener.load(Ordering::SeqCst) {
 | 
				
			||||||
                let _: Result<(), Error> =
 | 
					            let res: Result<(), Error> = proxy.method_call(BLUETOOTH, "StopBluetoothListener", ());
 | 
				
			||||||
                    proxy.method_call(BLUETOOTH, "StopBluetoothListener", ());
 | 
					            if res.is_err() {
 | 
				
			||||||
 | 
					                show_error::<BluetoothBox>(
 | 
				
			||||||
 | 
					                    bluetooth_box.clone(),
 | 
				
			||||||
 | 
					                    "Failed to stop bluetooth listener",
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            loop_box
 | 
					            loop_box
 | 
				
			||||||
                .imp()
 | 
					                .imp()
 | 
				
			||||||
                .reset_bluetooth_available_devices
 | 
					                .reset_bluetooth_available_devices
 | 
				
			||||||
| 
						 | 
					@ -372,7 +377,13 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
 | 
				
			||||||
                        .set_sensitive(true);
 | 
					                        .set_sensitive(true);
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
                let _: Result<(), Error> = proxy.method_call(BLUETOOTH, "StopBluetoothScan", ());
 | 
					            let res: Result<(), Error> = proxy.method_call(BLUETOOTH, "StopBluetoothScan", ());
 | 
				
			||||||
 | 
					            if res.is_err() {
 | 
				
			||||||
 | 
					                show_error::<BluetoothBox>(
 | 
				
			||||||
 | 
					                    bluetooth_box.clone(),
 | 
				
			||||||
 | 
					                    "Failed to stop bluetooth listener",
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            loop_box
 | 
					            loop_box
 | 
				
			||||||
                .imp()
 | 
					                .imp()
 | 
				
			||||||
                .reset_bluetooth_available_devices
 | 
					                .reset_bluetooth_available_devices
 | 
				
			||||||
| 
						 | 
					@ -383,8 +394,13 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
 | 
				
			||||||
                .bluetooth_scan_requested
 | 
					                .bluetooth_scan_requested
 | 
				
			||||||
                .store(false, Ordering::SeqCst);
 | 
					                .store(false, Ordering::SeqCst);
 | 
				
			||||||
            listener_active = true;
 | 
					            listener_active = true;
 | 
				
			||||||
                let _: Result<(), Error> =
 | 
					            let res: Result<(), Error> = proxy.method_call(BLUETOOTH, "StartBluetoothListener", ());
 | 
				
			||||||
                    proxy.method_call(BLUETOOTH, "StartBluetoothListener", ());
 | 
					            if res.is_err() {
 | 
				
			||||||
 | 
					                show_error::<BluetoothBox>(
 | 
				
			||||||
 | 
					                    bluetooth_box.clone(),
 | 
				
			||||||
 | 
					                    "Failed to start bluetooth listener",
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            loop_box
 | 
					            loop_box
 | 
				
			||||||
                .imp()
 | 
					                .imp()
 | 
				
			||||||
                .reset_bluetooth_available_devices
 | 
					                .reset_bluetooth_available_devices
 | 
				
			||||||
| 
						 | 
					@ -392,61 +408,93 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
 | 
				
			||||||
            time = SystemTime::now();
 | 
					            time = SystemTime::now();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn get_connected_devices() -> Vec<BluetoothDevice> {
 | 
					fn get_connected_devices(bluetooth_box: Arc<BluetoothBox>) -> Vec<BluetoothDevice> {
 | 
				
			||||||
    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<(Vec<BluetoothDevice>,), Error> =
 | 
					    let res: Result<(Vec<BluetoothDevice>,), Error> =
 | 
				
			||||||
        proxy.method_call(BLUETOOTH, "GetConnectedBluetoothDevices", ());
 | 
					        proxy.method_call(BLUETOOTH, "GetConnectedBluetoothDevices", ());
 | 
				
			||||||
    if res.is_err() {
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<BluetoothBox>(
 | 
				
			||||||
 | 
					            bluetooth_box.clone(),
 | 
				
			||||||
 | 
					            "Failed to get connected bluetooth devices",
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
        return Vec::new();
 | 
					        return Vec::new();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    res.unwrap().0
 | 
					    res.unwrap().0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn get_bluetooth_adapters() -> Vec<BluetoothAdapter> {
 | 
					fn get_bluetooth_adapters(bluetooth_box: Arc<BluetoothBox>) -> Vec<BluetoothAdapter> {
 | 
				
			||||||
    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<(Vec<BluetoothAdapter>,), Error> =
 | 
					    let res: Result<(Vec<BluetoothAdapter>,), Error> =
 | 
				
			||||||
        proxy.method_call(BLUETOOTH, "GetBluetoothAdapters", ());
 | 
					        proxy.method_call(BLUETOOTH, "GetBluetoothAdapters", ());
 | 
				
			||||||
    if res.is_err() {
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<BluetoothBox>(bluetooth_box.clone(), "Failed to get bluetooth adapters");
 | 
				
			||||||
        return Vec::new();
 | 
					        return Vec::new();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    res.unwrap().0
 | 
					    res.unwrap().0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn set_bluetooth_adapter(path: Path<'static>) {
 | 
					fn set_bluetooth_adapter(path: Path<'static>, bluetooth_box: Arc<BluetoothBox>) {
 | 
				
			||||||
    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 _: Result<(Path<'static>,), Error> =
 | 
					    let res: Result<(Path<'static>,), Error> =
 | 
				
			||||||
        proxy.method_call(BLUETOOTH, "SetBluetoothAdapter", (path,));
 | 
					        proxy.method_call(BLUETOOTH, "SetBluetoothAdapter", (path,));
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<BluetoothBox>(bluetooth_box.clone(), "Failed to set bluetooth adapter");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn set_bluetooth_adapter_visibility(path: Path<'static>, visible: bool) {
 | 
					fn set_bluetooth_adapter_visibility(
 | 
				
			||||||
 | 
					    path: Path<'static>,
 | 
				
			||||||
 | 
					    visible: bool,
 | 
				
			||||||
 | 
					    bluetooth_box: Arc<BluetoothBox>,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    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 _: Result<(bool,), Error> = proxy.method_call(
 | 
					    let res: Result<(bool,), Error> = proxy.method_call(
 | 
				
			||||||
        BLUETOOTH,
 | 
					        BLUETOOTH,
 | 
				
			||||||
        "SetBluetoothAdapterDiscoverability",
 | 
					        "SetBluetoothAdapterDiscoverability",
 | 
				
			||||||
        (path, visible),
 | 
					        (path, visible),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<BluetoothBox>(
 | 
				
			||||||
 | 
					            bluetooth_box.clone(),
 | 
				
			||||||
 | 
					            "Failed to set bluetooth adapter visibility",
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn set_bluetooth_adapter_pairability(path: Path<'static>, visible: bool) {
 | 
					fn set_bluetooth_adapter_pairability(
 | 
				
			||||||
 | 
					    path: Path<'static>,
 | 
				
			||||||
 | 
					    visible: bool,
 | 
				
			||||||
 | 
					    bluetooth_box: Arc<BluetoothBox>,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    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 _: Result<(bool,), Error> =
 | 
					    let res: Result<(bool,), Error> =
 | 
				
			||||||
        proxy.method_call(BLUETOOTH, "SetBluetoothAdapterPairability", (path, visible));
 | 
					        proxy.method_call(BLUETOOTH, "SetBluetoothAdapterPairability", (path, visible));
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<BluetoothBox>(
 | 
				
			||||||
 | 
					            bluetooth_box.clone(),
 | 
				
			||||||
 | 
					            "Failed to set bluetooth adapter pairability",
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn set_adapter_enabled(path: Path<'static>, enabled: bool) -> bool {
 | 
					fn set_adapter_enabled(
 | 
				
			||||||
 | 
					    path: Path<'static>,
 | 
				
			||||||
 | 
					    enabled: bool,
 | 
				
			||||||
 | 
					    bluetooth_box: Arc<BluetoothBox>,
 | 
				
			||||||
 | 
					) -> bool {
 | 
				
			||||||
    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 result: Result<(bool,), Error> =
 | 
					    let result: Result<(bool,), Error> =
 | 
				
			||||||
        proxy.method_call(BLUETOOTH, "SetBluetoothAdapterEnabled", (path, enabled));
 | 
					        proxy.method_call(BLUETOOTH, "SetBluetoothAdapterEnabled", (path, enabled));
 | 
				
			||||||
    if result.is_err() {
 | 
					    if result.is_err() {
 | 
				
			||||||
 | 
					        show_error::<BluetoothBox>(bluetooth_box.clone(), "Failed to enable bluetooth adapter");
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    result.unwrap().0
 | 
					    result.unwrap().0
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,14 +1,15 @@
 | 
				
			||||||
use adw::{ActionRow, ComboRow, PreferencesGroup, SwitchRow};
 | 
					use adw::{ActionRow, ComboRow, PreferencesGroup, SwitchRow};
 | 
				
			||||||
use dbus::Path;
 | 
					use dbus::Path;
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, Button, CompositeTemplate, Switch};
 | 
					 | 
				
			||||||
use gtk::{prelude::*, StringList};
 | 
					use gtk::{prelude::*, StringList};
 | 
				
			||||||
 | 
					use gtk::{Button, CompositeTemplate, Switch};
 | 
				
			||||||
use re_set_lib::bluetooth::bluetooth_structures::BluetoothAdapter;
 | 
					use re_set_lib::bluetooth::bluetooth_structures::BluetoothAdapter;
 | 
				
			||||||
use std::cell::RefCell;
 | 
					use std::cell::RefCell;
 | 
				
			||||||
use std::collections::HashMap;
 | 
					use std::collections::HashMap;
 | 
				
			||||||
use std::sync::atomic::AtomicBool;
 | 
					use std::sync::atomic::AtomicBool;
 | 
				
			||||||
use std::sync::{Arc, RwLock};
 | 
					use std::sync::{Arc, RwLock};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::base::error::ReSetError;
 | 
				
			||||||
use crate::components::base::list_entry::ListEntry;
 | 
					use crate::components::base::list_entry::ListEntry;
 | 
				
			||||||
use crate::components::bluetooth::bluetooth_box;
 | 
					use crate::components::bluetooth::bluetooth_box;
 | 
				
			||||||
use crate::components::bluetooth::bluetooth_entry::BluetoothEntry;
 | 
					use crate::components::bluetooth::bluetooth_entry::BluetoothEntry;
 | 
				
			||||||
| 
						 | 
					@ -36,6 +37,8 @@ pub struct BluetoothBox {
 | 
				
			||||||
    pub reset_bluetooth_discoverable_switch: TemplateChild<SwitchRow>,
 | 
					    pub reset_bluetooth_discoverable_switch: TemplateChild<SwitchRow>,
 | 
				
			||||||
    #[template_child]
 | 
					    #[template_child]
 | 
				
			||||||
    pub reset_bluetooth_pairable_switch: TemplateChild<SwitchRow>,
 | 
					    pub reset_bluetooth_pairable_switch: TemplateChild<SwitchRow>,
 | 
				
			||||||
 | 
					    #[template_child]
 | 
				
			||||||
 | 
					    pub error: TemplateChild<ReSetError>,
 | 
				
			||||||
    pub available_devices: BluetoothMap,
 | 
					    pub available_devices: BluetoothMap,
 | 
				
			||||||
    pub connected_devices: BluetoothMap,
 | 
					    pub connected_devices: BluetoothMap,
 | 
				
			||||||
    pub reset_bluetooth_adapters: Arc<RwLock<HashMap<String, (BluetoothAdapter, u32)>>>,
 | 
					    pub reset_bluetooth_adapters: Arc<RwLock<HashMap<String, (BluetoothAdapter, u32)>>>,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,11 +2,12 @@ use std::ops::Deref;
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
use std::time::Duration;
 | 
					use std::time::Duration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::base::error_impl::show_error;
 | 
				
			||||||
use crate::components::bluetooth::bluetooth_entry_impl;
 | 
					use crate::components::bluetooth::bluetooth_entry_impl;
 | 
				
			||||||
use crate::components::utils::{BASE, DBUS_PATH, BLUETOOTH};
 | 
					use crate::components::utils::{BASE, BLUETOOTH, DBUS_PATH};
 | 
				
			||||||
use adw::glib::Object;
 | 
					use adw::glib::Object;
 | 
				
			||||||
use adw::prelude::{ActionRowExt, PreferencesRowExt};
 | 
					use adw::prelude::{ActionRowExt, PreferencesRowExt};
 | 
				
			||||||
use adw::{glib, ActionRow};
 | 
					use adw::ActionRow;
 | 
				
			||||||
use dbus::blocking::Connection;
 | 
					use dbus::blocking::Connection;
 | 
				
			||||||
use dbus::{Error, Path};
 | 
					use dbus::{Error, Path};
 | 
				
			||||||
use glib::subclass::prelude::ObjectSubclassIsExt;
 | 
					use glib::subclass::prelude::ObjectSubclassIsExt;
 | 
				
			||||||
| 
						 | 
					@ -14,6 +15,8 @@ use gtk::prelude::{ButtonExt, ListBoxRowExt, WidgetExt};
 | 
				
			||||||
use gtk::{gio, Align, Button, GestureClick, Image, Label};
 | 
					use gtk::{gio, Align, Button, GestureClick, Image, Label};
 | 
				
			||||||
use re_set_lib::bluetooth::bluetooth_structures::BluetoothDevice;
 | 
					use re_set_lib::bluetooth::bluetooth_structures::BluetoothDevice;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::bluetooth_box::BluetoothBox;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
glib::wrapper! {
 | 
					glib::wrapper! {
 | 
				
			||||||
    pub struct BluetoothEntry(ObjectSubclass<bluetooth_entry_impl::BluetoothEntry>)
 | 
					    pub struct BluetoothEntry(ObjectSubclass<bluetooth_entry_impl::BluetoothEntry>)
 | 
				
			||||||
        @extends ActionRow, gtk::Widget,
 | 
					        @extends ActionRow, gtk::Widget,
 | 
				
			||||||
| 
						 | 
					@ -24,7 +27,7 @@ unsafe impl Send for BluetoothEntry {}
 | 
				
			||||||
unsafe impl Sync for BluetoothEntry {}
 | 
					unsafe impl Sync for BluetoothEntry {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl BluetoothEntry {
 | 
					impl BluetoothEntry {
 | 
				
			||||||
    pub fn new(device: BluetoothDevice) -> Arc<Self> {
 | 
					    pub fn new(device: BluetoothDevice, bluetooth_box: Arc<BluetoothBox>) -> Arc<Self> {
 | 
				
			||||||
        let entry: Arc<BluetoothEntry> = Arc::new(Object::builder().build());
 | 
					        let entry: Arc<BluetoothEntry> = Arc::new(Object::builder().build());
 | 
				
			||||||
        let entry_imp = entry.imp();
 | 
					        let entry_imp = entry.imp();
 | 
				
			||||||
        let entry_ref = entry.clone();
 | 
					        let entry_ref = entry.clone();
 | 
				
			||||||
| 
						 | 
					@ -60,7 +63,10 @@ impl BluetoothEntry {
 | 
				
			||||||
            .borrow()
 | 
					            .borrow()
 | 
				
			||||||
            .connect_clicked(move |_| {
 | 
					            .connect_clicked(move |_| {
 | 
				
			||||||
                let imp = entry_ref_remove.imp();
 | 
					                let imp = entry_ref_remove.imp();
 | 
				
			||||||
                remove_device_pairing(imp.bluetooth_device.borrow().path.clone());
 | 
					                remove_device_pairing(
 | 
				
			||||||
 | 
					                    imp.bluetooth_device.borrow().path.clone(),
 | 
				
			||||||
 | 
					                    bluetooth_box.clone(),
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        let gesture = GestureClick::new();
 | 
					        let gesture = GestureClick::new();
 | 
				
			||||||
        // paired is not what we think
 | 
					        // paired is not what we think
 | 
				
			||||||
| 
						 | 
					@ -87,16 +93,9 @@ impl BluetoothEntry {
 | 
				
			||||||
fn connect_to_device(entry: Arc<BluetoothEntry>, path: Path<'static>) {
 | 
					fn connect_to_device(entry: Arc<BluetoothEntry>, path: Path<'static>) {
 | 
				
			||||||
    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(
 | 
					        let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
            BASE,
 | 
					        let res: Result<(bool,), Error> =
 | 
				
			||||||
            DBUS_PATH,
 | 
					            proxy.method_call(BLUETOOTH, "ConnectToBluetoothDevice", (path,));
 | 
				
			||||||
            Duration::from_millis(1000),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        let res: Result<(bool,), Error> = proxy.method_call(
 | 
					 | 
				
			||||||
            BLUETOOTH,
 | 
					 | 
				
			||||||
            "ConnectToBluetoothDevice",
 | 
					 | 
				
			||||||
            (path,),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					        glib::spawn_future(async move {
 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					            glib::idle_add_once(move || {
 | 
				
			||||||
                if res.is_err() {
 | 
					                if res.is_err() {
 | 
				
			||||||
| 
						 | 
					@ -134,16 +133,9 @@ fn connect_to_device(entry: Arc<BluetoothEntry>, path: Path<'static>) {
 | 
				
			||||||
fn disconnect_from_device(entry: Arc<BluetoothEntry>, path: Path<'static>) {
 | 
					fn disconnect_from_device(entry: Arc<BluetoothEntry>, path: Path<'static>) {
 | 
				
			||||||
    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(
 | 
					        let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
            BASE,
 | 
					        let res: Result<(bool,), Error> =
 | 
				
			||||||
            DBUS_PATH,
 | 
					            proxy.method_call(BLUETOOTH, "DisconnectFromBluetoothDevice", (path,));
 | 
				
			||||||
            Duration::from_millis(1000),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        let res: Result<(bool,), Error> = proxy.method_call(
 | 
					 | 
				
			||||||
            BLUETOOTH,
 | 
					 | 
				
			||||||
            "DisconnectFromBluetoothDevice",
 | 
					 | 
				
			||||||
            (path,),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					        glib::spawn_future(async move {
 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					            glib::idle_add_once(move || {
 | 
				
			||||||
                let imp = entry.imp();
 | 
					                let imp = entry.imp();
 | 
				
			||||||
| 
						 | 
					@ -161,15 +153,14 @@ fn disconnect_from_device(entry: Arc<BluetoothEntry>, path: Path<'static>) {
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn remove_device_pairing(path: Path<'static>) {
 | 
					fn remove_device_pairing(path: Path<'static>, wifi_box: Arc<BluetoothBox>) {
 | 
				
			||||||
    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(
 | 
					        let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
            BASE,
 | 
					        let res: Result<(bool,), Error> =
 | 
				
			||||||
            DBUS_PATH,
 | 
					 | 
				
			||||||
            Duration::from_millis(1000),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        let _: Result<(bool,), Error> =
 | 
					 | 
				
			||||||
            proxy.method_call(BLUETOOTH, "RemoveDevicePairing", (path,));
 | 
					            proxy.method_call(BLUETOOTH, "RemoveDevicePairing", (path,));
 | 
				
			||||||
 | 
					        if res.is_err() {
 | 
				
			||||||
 | 
					            show_error::<BluetoothBox>(wifi_box.clone(), "Failed to remove device pairing");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,7 @@ use adw::subclass::action_row::ActionRowImpl;
 | 
				
			||||||
use adw::subclass::preferences_row::PreferencesRowImpl;
 | 
					use adw::subclass::preferences_row::PreferencesRowImpl;
 | 
				
			||||||
use adw::ActionRow;
 | 
					use adw::ActionRow;
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, Button, CompositeTemplate, Label};
 | 
					use gtk::{Button, CompositeTemplate, Label};
 | 
				
			||||||
use re_set_lib::bluetooth::bluetooth_structures::BluetoothDevice;
 | 
					use re_set_lib::bluetooth::bluetooth_structures::BluetoothDevice;
 | 
				
			||||||
use std::cell::RefCell;
 | 
					use std::cell::RefCell;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										92
									
								
								src/components/bluetooth/bluetooth_event_handlers.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								src/components/bluetooth/bluetooth_event_handlers.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,92 @@
 | 
				
			||||||
 | 
					use std::sync::Arc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use adw::prelude::PreferencesGroupExt;
 | 
				
			||||||
 | 
					use glib::subclass::types::ObjectSubclassIsExt;
 | 
				
			||||||
 | 
					use gtk::prelude::WidgetExt;
 | 
				
			||||||
 | 
					use re_set_lib::signals::{BluetoothDeviceAdded, BluetoothDeviceChanged, BluetoothDeviceRemoved};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::{bluetooth_box::BluetoothBox, bluetooth_entry::BluetoothEntry};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn device_changed_handler(
 | 
				
			||||||
 | 
					    device_changed_box: Arc<BluetoothBox>,
 | 
				
			||||||
 | 
					    ir: BluetoothDeviceChanged,
 | 
				
			||||||
 | 
					) -> bool {
 | 
				
			||||||
 | 
					    let bluetooth_box = device_changed_box.clone();
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let imp = bluetooth_box.imp();
 | 
				
			||||||
 | 
					            let mut map = imp.available_devices.borrow_mut();
 | 
				
			||||||
 | 
					            if let Some(list_entry) = map.get_mut(&ir.bluetooth_device.path) {
 | 
				
			||||||
 | 
					                let mut existing_bluetooth_device = list_entry.imp().bluetooth_device.borrow_mut();
 | 
				
			||||||
 | 
					                if existing_bluetooth_device.connected != ir.bluetooth_device.connected {
 | 
				
			||||||
 | 
					                    if ir.bluetooth_device.connected {
 | 
				
			||||||
 | 
					                        imp.reset_bluetooth_available_devices.remove(&**list_entry);
 | 
				
			||||||
 | 
					                        imp.reset_bluetooth_connected_devices.add(&**list_entry);
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        imp.reset_bluetooth_connected_devices.remove(&**list_entry);
 | 
				
			||||||
 | 
					                        imp.reset_bluetooth_available_devices.add(&**list_entry);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                if existing_bluetooth_device.bonded != ir.bluetooth_device.bonded {
 | 
				
			||||||
 | 
					                    if ir.bluetooth_device.bonded {
 | 
				
			||||||
 | 
					                        list_entry
 | 
				
			||||||
 | 
					                            .imp()
 | 
				
			||||||
 | 
					                            .remove_device_button
 | 
				
			||||||
 | 
					                            .borrow()
 | 
				
			||||||
 | 
					                            .set_sensitive(true);
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        list_entry
 | 
				
			||||||
 | 
					                            .imp()
 | 
				
			||||||
 | 
					                            .remove_device_button
 | 
				
			||||||
 | 
					                            .borrow()
 | 
				
			||||||
 | 
					                            .set_sensitive(false);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                *existing_bluetooth_device = ir.bluetooth_device;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn device_removed_handler(
 | 
				
			||||||
 | 
					    device_removed_box: Arc<BluetoothBox>,
 | 
				
			||||||
 | 
					    ir: BluetoothDeviceRemoved,
 | 
				
			||||||
 | 
					) -> bool {
 | 
				
			||||||
 | 
					    let bluetooth_box = device_removed_box.clone();
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let imp = bluetooth_box.imp();
 | 
				
			||||||
 | 
					            let mut map = imp.available_devices.borrow_mut();
 | 
				
			||||||
 | 
					            if let Some(list_entry) = map.remove(&ir.bluetooth_device) {
 | 
				
			||||||
 | 
					                if list_entry.imp().bluetooth_device.borrow().connected {
 | 
				
			||||||
 | 
					                    imp.reset_bluetooth_connected_devices.remove(&*list_entry);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    imp.reset_bluetooth_available_devices.remove(&*list_entry);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn device_added_handler(device_added_box: Arc<BluetoothBox>, ir: BluetoothDeviceAdded) -> bool {
 | 
				
			||||||
 | 
					    let bluetooth_box = device_added_box.clone();
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let imp = bluetooth_box.imp();
 | 
				
			||||||
 | 
					            let path = ir.bluetooth_device.path.clone();
 | 
				
			||||||
 | 
					            let connected = ir.bluetooth_device.connected;
 | 
				
			||||||
 | 
					            let bluetooth_entry = BluetoothEntry::new(ir.bluetooth_device, bluetooth_box.clone());
 | 
				
			||||||
 | 
					            imp.available_devices
 | 
				
			||||||
 | 
					                .borrow_mut()
 | 
				
			||||||
 | 
					                .insert(path, bluetooth_entry.clone());
 | 
				
			||||||
 | 
					            if connected {
 | 
				
			||||||
 | 
					                imp.reset_bluetooth_connected_devices.add(&*bluetooth_entry);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                imp.reset_bluetooth_available_devices.add(&*bluetooth_entry);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -2,3 +2,4 @@ pub mod bluetooth_box;
 | 
				
			||||||
pub mod bluetooth_box_impl;
 | 
					pub mod bluetooth_box_impl;
 | 
				
			||||||
pub mod bluetooth_entry;
 | 
					pub mod bluetooth_entry;
 | 
				
			||||||
pub mod bluetooth_entry_impl;
 | 
					pub mod bluetooth_entry_impl;
 | 
				
			||||||
 | 
					mod bluetooth_event_handlers;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,655 +0,0 @@
 | 
				
			||||||
use adw::prelude::PreferencesRowExt;
 | 
					 | 
				
			||||||
use re_set_lib::audio::audio_structures::{Card, OutputStream, Source};
 | 
					 | 
				
			||||||
use re_set_lib::signals::{
 | 
					 | 
				
			||||||
    OutputStreamAdded, OutputStreamChanged, OutputStreamRemoved, SourceAdded, SourceChanged,
 | 
					 | 
				
			||||||
    SourceRemoved,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
use std::sync::Arc;
 | 
					 | 
				
			||||||
use std::time::{Duration, SystemTime};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
use adw::glib;
 | 
					 | 
				
			||||||
use adw::glib::Object;
 | 
					 | 
				
			||||||
use adw::prelude::{
 | 
					 | 
				
			||||||
    BoxExt, ButtonExt, CheckButtonExt, ComboRowExt, ListBoxRowExt, PreferencesGroupExt, RangeExt,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
use dbus::blocking::Connection;
 | 
					 | 
				
			||||||
use dbus::message::SignalArgs;
 | 
					 | 
				
			||||||
use dbus::{Error, Path};
 | 
					 | 
				
			||||||
use glib::subclass::prelude::ObjectSubclassIsExt;
 | 
					 | 
				
			||||||
use glib::{clone, Cast, Propagation, Variant};
 | 
					 | 
				
			||||||
use gtk::prelude::ActionableExt;
 | 
					 | 
				
			||||||
use gtk::{gio, StringObject};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
use crate::components::base::card_entry::CardEntry;
 | 
					 | 
				
			||||||
use crate::components::base::list_entry::ListEntry;
 | 
					 | 
				
			||||||
use crate::components::input::source_box_impl;
 | 
					 | 
				
			||||||
use crate::components::input::source_entry::set_source_volume;
 | 
					 | 
				
			||||||
use crate::components::utils::{
 | 
					 | 
				
			||||||
    create_dropdown_label_factory, set_combo_row_ellipsis, AUDIO, BASE, DBUS_PATH,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
use super::output_stream_entry::OutputStreamEntry;
 | 
					 | 
				
			||||||
use super::source_entry::{set_default_source, toggle_source_mute, SourceEntry};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
glib::wrapper! {
 | 
					 | 
				
			||||||
    pub struct SourceBox(ObjectSubclass<source_box_impl::SourceBox>)
 | 
					 | 
				
			||||||
    @extends gtk::Box, gtk::Widget,
 | 
					 | 
				
			||||||
    @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
unsafe impl Send for SourceBox {}
 | 
					 | 
				
			||||||
unsafe impl Sync for SourceBox {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
impl SourceBox {
 | 
					 | 
				
			||||||
    pub fn new() -> Self {
 | 
					 | 
				
			||||||
        let obj: Self = Object::builder().build();
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            let imp = obj.imp();
 | 
					 | 
				
			||||||
            let mut model_index = imp.reset_model_index.write().unwrap();
 | 
					 | 
				
			||||||
            *model_index = 0;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        obj
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pub fn setup_callbacks(&self) {
 | 
					 | 
				
			||||||
        let self_imp = self.imp();
 | 
					 | 
				
			||||||
        self_imp.reset_source_row.set_activatable(true);
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_source_row
 | 
					 | 
				
			||||||
            .set_action_name(Some("navigation.push"));
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_source_row
 | 
					 | 
				
			||||||
            .set_action_target_value(Some(&Variant::from("sources")));
 | 
					 | 
				
			||||||
        self_imp.reset_cards_row.set_activatable(true);
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_cards_row
 | 
					 | 
				
			||||||
            .set_action_name(Some("navigation.push"));
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_cards_row
 | 
					 | 
				
			||||||
            .set_action_target_value(Some(&Variant::from("profileConfiguration")));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self_imp.reset_output_stream_button.set_activatable(true);
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_output_stream_button
 | 
					 | 
				
			||||||
            .set_action_name(Some("navigation.pop"));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self_imp.reset_input_cards_back_button.set_activatable(true);
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_input_cards_back_button
 | 
					 | 
				
			||||||
            .set_action_name(Some("navigation.pop"));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_source_dropdown
 | 
					 | 
				
			||||||
            .set_factory(Some(&create_dropdown_label_factory()));
 | 
					 | 
				
			||||||
        set_combo_row_ellipsis(self_imp.reset_source_dropdown.get());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
impl Default for SourceBox {
 | 
					 | 
				
			||||||
    fn default() -> Self {
 | 
					 | 
				
			||||||
        Self::new()
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn populate_sources(input_box: Arc<SourceBox>) {
 | 
					 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					 | 
				
			||||||
        let sources = get_sources();
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            let input_box_imp = input_box.imp();
 | 
					 | 
				
			||||||
            let list = input_box_imp.reset_model_list.write().unwrap();
 | 
					 | 
				
			||||||
            let mut map = input_box_imp.reset_source_map.write().unwrap();
 | 
					 | 
				
			||||||
            let mut model_index = input_box_imp.reset_model_index.write().unwrap();
 | 
					 | 
				
			||||||
            input_box_imp
 | 
					 | 
				
			||||||
                .reset_default_source
 | 
					 | 
				
			||||||
                .replace(get_default_source());
 | 
					 | 
				
			||||||
            for source in sources.iter() {
 | 
					 | 
				
			||||||
                list.append(&source.alias);
 | 
					 | 
				
			||||||
                map.insert(source.alias.clone(), (source.index, source.name.clone()));
 | 
					 | 
				
			||||||
                *model_index += 1;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        populate_outputstreams(input_box.clone());
 | 
					 | 
				
			||||||
        populate_cards(input_box.clone());
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let input_box_ref_slider = input_box.clone();
 | 
					 | 
				
			||||||
                let input_box_ref_toggle = input_box.clone();
 | 
					 | 
				
			||||||
                let input_box_ref_mute = input_box.clone();
 | 
					 | 
				
			||||||
                let input_box_ref = input_box.clone();
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    let input_box_imp = input_box_ref.imp();
 | 
					 | 
				
			||||||
                    let default_sink = input_box_imp.reset_default_source.clone();
 | 
					 | 
				
			||||||
                    let source = default_sink.borrow();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if source.muted {
 | 
					 | 
				
			||||||
                        input_box_imp
 | 
					 | 
				
			||||||
                            .reset_source_mute
 | 
					 | 
				
			||||||
                            .set_icon_name("microphone-disabled-symbolic");
 | 
					 | 
				
			||||||
                    } else {
 | 
					 | 
				
			||||||
                        input_box_imp
 | 
					 | 
				
			||||||
                            .reset_source_mute
 | 
					 | 
				
			||||||
                            .set_icon_name("audio-input-microphone-symbolic");
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    let volume = source.volume.first().unwrap_or(&0_u32);
 | 
					 | 
				
			||||||
                    let fraction = (*volume as f64 / 655.36).round();
 | 
					 | 
				
			||||||
                    let percentage = (fraction).to_string() + "%";
 | 
					 | 
				
			||||||
                    input_box_imp.reset_volume_percentage.set_text(&percentage);
 | 
					 | 
				
			||||||
                    input_box_imp.reset_volume_slider.set_value(*volume as f64);
 | 
					 | 
				
			||||||
                    let mut list = input_box_imp.reset_source_list.write().unwrap();
 | 
					 | 
				
			||||||
                    for source in sources {
 | 
					 | 
				
			||||||
                        let index = source.index;
 | 
					 | 
				
			||||||
                        let alias = source.alias.clone();
 | 
					 | 
				
			||||||
                        let mut is_default = false;
 | 
					 | 
				
			||||||
                        if input_box_imp.reset_default_source.borrow().name == source.name {
 | 
					 | 
				
			||||||
                            is_default = true;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        let source_entry = Arc::new(SourceEntry::new(
 | 
					 | 
				
			||||||
                            is_default,
 | 
					 | 
				
			||||||
                            input_box_imp.reset_default_check_button.clone(),
 | 
					 | 
				
			||||||
                            source,
 | 
					 | 
				
			||||||
                            input_box.clone(),
 | 
					 | 
				
			||||||
                        ));
 | 
					 | 
				
			||||||
                        let source_clone = source_entry.clone();
 | 
					 | 
				
			||||||
                        let entry = Arc::new(ListEntry::new(&*source_entry));
 | 
					 | 
				
			||||||
                        entry.set_activatable(false);
 | 
					 | 
				
			||||||
                        list.insert(index, (entry.clone(), source_clone, alias));
 | 
					 | 
				
			||||||
                        input_box_imp.reset_sources.append(&*entry);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    let list = input_box_imp.reset_model_list.read().unwrap();
 | 
					 | 
				
			||||||
                    input_box_imp.reset_source_dropdown.set_model(Some(&*list));
 | 
					 | 
				
			||||||
                    let name = input_box_imp.reset_default_source.borrow();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    let index = input_box_imp.reset_model_index.read().unwrap();
 | 
					 | 
				
			||||||
                    let model_list = input_box_imp.reset_model_list.read().unwrap();
 | 
					 | 
				
			||||||
                    for entry in 0..*index {
 | 
					 | 
				
			||||||
                        if model_list.string(entry) == Some(name.alias.clone().into()) {
 | 
					 | 
				
			||||||
                            input_box_imp.reset_source_dropdown.set_selected(entry);
 | 
					 | 
				
			||||||
                            break;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    input_box_imp.reset_source_dropdown.connect_selected_notify(
 | 
					 | 
				
			||||||
                        clone!(@weak input_box_imp => move |dropdown| {
 | 
					 | 
				
			||||||
                            let input_box = input_box_ref_toggle.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 source = input_box_imp.reset_source_map.read().unwrap();
 | 
					 | 
				
			||||||
                            let source = source.get(&selected);
 | 
					 | 
				
			||||||
                            if source.is_none() {
 | 
					 | 
				
			||||||
                                return;
 | 
					 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                            let source = Arc::new(source.unwrap().1.clone());
 | 
					 | 
				
			||||||
                            gio::spawn_blocking(move || {
 | 
					 | 
				
			||||||
                                let result = set_default_source(source);
 | 
					 | 
				
			||||||
                                if result.is_none(){
 | 
					 | 
				
			||||||
                                    return;
 | 
					 | 
				
			||||||
                                }
 | 
					 | 
				
			||||||
                                refresh_default_source(result.unwrap(), input_box.clone(), false);
 | 
					 | 
				
			||||||
                            });
 | 
					 | 
				
			||||||
                        }),
 | 
					 | 
				
			||||||
                    );
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                input_box_ref
 | 
					 | 
				
			||||||
                    .imp()
 | 
					 | 
				
			||||||
                    .reset_volume_slider
 | 
					 | 
				
			||||||
                    .connect_change_value(move |_, _, value| {
 | 
					 | 
				
			||||||
                        let imp = input_box_ref_slider.imp();
 | 
					 | 
				
			||||||
                        let fraction = (value / 655.36).round();
 | 
					 | 
				
			||||||
                        let percentage = (fraction).to_string() + "%";
 | 
					 | 
				
			||||||
                        imp.reset_volume_percentage.set_text(&percentage);
 | 
					 | 
				
			||||||
                        let source = imp.reset_default_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);
 | 
					 | 
				
			||||||
                        Propagation::Proceed
 | 
					 | 
				
			||||||
                    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                input_box_ref
 | 
					 | 
				
			||||||
                    .imp()
 | 
					 | 
				
			||||||
                    .reset_source_mute
 | 
					 | 
				
			||||||
                    .connect_clicked(move |_| {
 | 
					 | 
				
			||||||
                        let imp = input_box_ref_mute.imp();
 | 
					 | 
				
			||||||
                        let mut source = imp.reset_default_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);
 | 
					 | 
				
			||||||
                    });
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn refresh_default_source(new_source: Source, input_box: Arc<SourceBox>, entry: bool) {
 | 
					 | 
				
			||||||
    let volume = *new_source.volume.first().unwrap_or(&0_u32);
 | 
					 | 
				
			||||||
    let fraction = (volume as f64 / 655.36).round();
 | 
					 | 
				
			||||||
    let percentage = (fraction).to_string() + "%";
 | 
					 | 
				
			||||||
    glib::spawn_future(async move {
 | 
					 | 
				
			||||||
        glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
            let imp = input_box.imp();
 | 
					 | 
				
			||||||
            if !entry {
 | 
					 | 
				
			||||||
                let list = imp.reset_source_list.read().unwrap();
 | 
					 | 
				
			||||||
                let entry = list.get(&new_source.index);
 | 
					 | 
				
			||||||
                if entry.is_none() {
 | 
					 | 
				
			||||||
                    return;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                let entry_imp = entry.unwrap().1.imp();
 | 
					 | 
				
			||||||
                entry_imp.reset_selected_source.set_active(true);
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                let model_list = imp.reset_model_list.read().unwrap();
 | 
					 | 
				
			||||||
                for entry in 0..*imp.reset_model_index.read().unwrap() {
 | 
					 | 
				
			||||||
                    if model_list.string(entry) == Some(new_source.alias.clone().into()) {
 | 
					 | 
				
			||||||
                        imp.reset_source_dropdown.set_selected(entry);
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            imp.reset_volume_percentage.set_text(&percentage);
 | 
					 | 
				
			||||||
            imp.reset_volume_slider.set_value(volume as f64);
 | 
					 | 
				
			||||||
            if new_source.muted {
 | 
					 | 
				
			||||||
                imp.reset_source_mute
 | 
					 | 
				
			||||||
                    .set_icon_name("microphone-disabled-symbolic");
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                imp.reset_source_mute
 | 
					 | 
				
			||||||
                    .set_icon_name("audio-input-microphone-symbolic");
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            imp.reset_default_source.replace(new_source);
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn populate_outputstreams(input_box: Arc<SourceBox>) {
 | 
					 | 
				
			||||||
    let input_box_ref = input_box.clone();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					 | 
				
			||||||
        let streams = get_output_streams();
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let input_box_imp = input_box_ref.imp();
 | 
					 | 
				
			||||||
                let mut list = input_box_imp.reset_output_stream_list.write().unwrap();
 | 
					 | 
				
			||||||
                for stream in streams {
 | 
					 | 
				
			||||||
                    let index = stream.index;
 | 
					 | 
				
			||||||
                    let input_stream = Arc::new(OutputStreamEntry::new(input_box.clone(), stream));
 | 
					 | 
				
			||||||
                    let input_stream_clone = input_stream.clone();
 | 
					 | 
				
			||||||
                    let entry = Arc::new(ListEntry::new(&*input_stream));
 | 
					 | 
				
			||||||
                    entry.set_activatable(false);
 | 
					 | 
				
			||||||
                    list.insert(index, (entry.clone(), input_stream_clone));
 | 
					 | 
				
			||||||
                    input_box_imp.reset_output_streams.append(&*entry);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn populate_cards(input_box: Arc<SourceBox>) {
 | 
					 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					 | 
				
			||||||
        let input_box_ref = input_box.clone();
 | 
					 | 
				
			||||||
        let cards = get_cards();
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let imp = input_box_ref.imp();
 | 
					 | 
				
			||||||
                for card in cards {
 | 
					 | 
				
			||||||
                    imp.reset_cards.add(&CardEntry::new(card));
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn get_output_streams() -> Vec<OutputStream> {
 | 
					 | 
				
			||||||
    let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
					 | 
				
			||||||
    let res: Result<(Vec<OutputStream>,), Error> =
 | 
					 | 
				
			||||||
        proxy.method_call(AUDIO, "ListOutputStreams", ());
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        return Vec::new();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    res.unwrap().0
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn get_sources() -> Vec<Source> {
 | 
					 | 
				
			||||||
    let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
					 | 
				
			||||||
    let res: Result<(Vec<Source>,), Error> = proxy.method_call(AUDIO, "ListSources", ());
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        return Vec::new();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    res.unwrap().0
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn get_cards() -> Vec<Card> {
 | 
					 | 
				
			||||||
    let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
					 | 
				
			||||||
    let res: Result<(Vec<Card>,), Error> = proxy.method_call(AUDIO, "ListCards", ());
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        return Vec::new();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    res.unwrap().0
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn get_default_source_name() -> String {
 | 
					 | 
				
			||||||
    let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
					 | 
				
			||||||
    let res: Result<(String,), Error> = proxy.method_call(AUDIO, "GetDefaultSourceName", ());
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        return String::from("");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    res.unwrap().0
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn get_default_source() -> Source {
 | 
					 | 
				
			||||||
    let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
					 | 
				
			||||||
    let res: Result<(Source,), Error> = proxy.method_call(AUDIO, "GetDefaultSource", ());
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        return Source::default();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    res.unwrap().0
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn start_input_box_listener(conn: Connection, source_box: Arc<SourceBox>) -> Connection {
 | 
					 | 
				
			||||||
    let source_added =
 | 
					 | 
				
			||||||
        SourceAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
 | 
					 | 
				
			||||||
    let source_removed =
 | 
					 | 
				
			||||||
        SourceRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
 | 
					 | 
				
			||||||
    let source_changed =
 | 
					 | 
				
			||||||
        SourceChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
 | 
					 | 
				
			||||||
    let output_stream_added =
 | 
					 | 
				
			||||||
        OutputStreamAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
 | 
					 | 
				
			||||||
            .static_clone();
 | 
					 | 
				
			||||||
    let output_stream_removed =
 | 
					 | 
				
			||||||
        OutputStreamRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
 | 
					 | 
				
			||||||
            .static_clone();
 | 
					 | 
				
			||||||
    let output_stream_changed =
 | 
					 | 
				
			||||||
        OutputStreamChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
 | 
					 | 
				
			||||||
            .static_clone();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let source_added_box = source_box.clone();
 | 
					 | 
				
			||||||
    let source_removed_box = source_box.clone();
 | 
					 | 
				
			||||||
    let source_changed_box = source_box.clone();
 | 
					 | 
				
			||||||
    let output_stream_added_box = source_box.clone();
 | 
					 | 
				
			||||||
    let output_stream_removed_box = source_box.clone();
 | 
					 | 
				
			||||||
    let output_stream_changed_box = source_box.clone();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let res = conn.add_match(source_added, move |ir: SourceAdded, _, _| {
 | 
					 | 
				
			||||||
        let source_box = source_added_box.clone();
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let input_box = source_box.clone();
 | 
					 | 
				
			||||||
                let input_box_imp = input_box.imp();
 | 
					 | 
				
			||||||
                let source_index = ir.source.index;
 | 
					 | 
				
			||||||
                let alias = ir.source.alias.clone();
 | 
					 | 
				
			||||||
                let name = ir.source.name.clone();
 | 
					 | 
				
			||||||
                let mut is_default = false;
 | 
					 | 
				
			||||||
                if input_box_imp.reset_default_source.borrow().name == ir.source.name {
 | 
					 | 
				
			||||||
                    is_default = true;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                let source_entry = Arc::new(SourceEntry::new(
 | 
					 | 
				
			||||||
                    is_default,
 | 
					 | 
				
			||||||
                    input_box_imp.reset_default_check_button.clone(),
 | 
					 | 
				
			||||||
                    ir.source,
 | 
					 | 
				
			||||||
                    input_box.clone(),
 | 
					 | 
				
			||||||
                ));
 | 
					 | 
				
			||||||
                let source_clone = source_entry.clone();
 | 
					 | 
				
			||||||
                let entry = Arc::new(ListEntry::new(&*source_entry));
 | 
					 | 
				
			||||||
                entry.set_activatable(false);
 | 
					 | 
				
			||||||
                let mut list = input_box_imp.reset_source_list.write().unwrap();
 | 
					 | 
				
			||||||
                list.insert(source_index, (entry.clone(), source_clone, alias.clone()));
 | 
					 | 
				
			||||||
                input_box_imp.reset_sources.append(&*entry);
 | 
					 | 
				
			||||||
                let mut map = input_box_imp.reset_source_map.write().unwrap();
 | 
					 | 
				
			||||||
                let mut index = input_box_imp.reset_model_index.write().unwrap();
 | 
					 | 
				
			||||||
                let model_list = input_box_imp.reset_model_list.write().unwrap();
 | 
					 | 
				
			||||||
                if model_list.string(*index - 1) == Some("Monitor of Dummy Output".into()) {
 | 
					 | 
				
			||||||
                    model_list.append(&alias);
 | 
					 | 
				
			||||||
                    model_list.remove(*index - 1);
 | 
					 | 
				
			||||||
                    map.insert(alias, (source_index, name));
 | 
					 | 
				
			||||||
                    input_box_imp.reset_source_dropdown.set_selected(0);
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    model_list.append(&alias);
 | 
					 | 
				
			||||||
                    map.insert(alias.clone(), (source_index, name));
 | 
					 | 
				
			||||||
                    if alias == "Monitor of Dummy Output" {
 | 
					 | 
				
			||||||
                        input_box_imp.reset_source_dropdown.set_selected(0);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    *index += 1;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        true
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        println!("fail on source add event");
 | 
					 | 
				
			||||||
        return conn;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let res = conn.add_match(source_removed, move |ir: SourceRemoved, _, _| {
 | 
					 | 
				
			||||||
        let source_box = source_removed_box.clone();
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let input_box = source_box.clone();
 | 
					 | 
				
			||||||
                let input_box_imp = input_box.imp();
 | 
					 | 
				
			||||||
                let entry: Option<(Arc<ListEntry>, Arc<SourceEntry>, String)>;
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    let mut list = input_box_imp.reset_source_list.write().unwrap();
 | 
					 | 
				
			||||||
                    entry = list.remove(&ir.index);
 | 
					 | 
				
			||||||
                    if entry.is_none() {
 | 
					 | 
				
			||||||
                        return;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                input_box_imp
 | 
					 | 
				
			||||||
                    .reset_sources
 | 
					 | 
				
			||||||
                    .remove(&*entry.clone().unwrap().0);
 | 
					 | 
				
			||||||
                let mut map = input_box_imp.reset_source_map.write().unwrap();
 | 
					 | 
				
			||||||
                let alias = entry.unwrap().2;
 | 
					 | 
				
			||||||
                map.remove(&alias);
 | 
					 | 
				
			||||||
                let mut index = input_box_imp.reset_model_index.write().unwrap();
 | 
					 | 
				
			||||||
                let model_list = input_box_imp.reset_model_list.write().unwrap();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if *index == 1 {
 | 
					 | 
				
			||||||
                    model_list.append("Monitor of Dummy Output");
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                for entry in 0..*index {
 | 
					 | 
				
			||||||
                    if model_list.string(entry) == Some(alias.clone().into()) {
 | 
					 | 
				
			||||||
                        model_list.splice(entry, 1, &[]);
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                if *index > 1 {
 | 
					 | 
				
			||||||
                    *index -= 1;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        true
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        println!("fail on source remove event");
 | 
					 | 
				
			||||||
        return conn;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let res = conn.add_match(source_changed, move |ir: SourceChanged, _, _| {
 | 
					 | 
				
			||||||
        let source_box = source_changed_box.clone();
 | 
					 | 
				
			||||||
        let default_source = get_default_source_name();
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let input_box = source_box.clone();
 | 
					 | 
				
			||||||
                let input_box_imp = input_box.imp();
 | 
					 | 
				
			||||||
                let is_default = ir.source.name == default_source;
 | 
					 | 
				
			||||||
                let volume = ir.source.volume.first().unwrap_or(&0_u32);
 | 
					 | 
				
			||||||
                let fraction = (*volume as f64 / 655.36).round();
 | 
					 | 
				
			||||||
                let percentage = (fraction).to_string() + "%";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                let list = input_box_imp.reset_source_list.read().unwrap();
 | 
					 | 
				
			||||||
                let entry = list.get(&ir.source.index);
 | 
					 | 
				
			||||||
                if entry.is_none() {
 | 
					 | 
				
			||||||
                    return;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                let imp = entry.unwrap().1.imp();
 | 
					 | 
				
			||||||
                if is_default {
 | 
					 | 
				
			||||||
                    input_box_imp.reset_volume_percentage.set_text(&percentage);
 | 
					 | 
				
			||||||
                    input_box_imp.reset_volume_slider.set_value(*volume as f64);
 | 
					 | 
				
			||||||
                    input_box_imp
 | 
					 | 
				
			||||||
                        .reset_default_source
 | 
					 | 
				
			||||||
                        .replace(ir.source.clone());
 | 
					 | 
				
			||||||
                    if ir.source.muted {
 | 
					 | 
				
			||||||
                        input_box_imp
 | 
					 | 
				
			||||||
                            .reset_source_mute
 | 
					 | 
				
			||||||
                            .set_icon_name("microphone-disabled-symbolic");
 | 
					 | 
				
			||||||
                    } else {
 | 
					 | 
				
			||||||
                        input_box_imp
 | 
					 | 
				
			||||||
                            .reset_source_mute
 | 
					 | 
				
			||||||
                            .set_icon_name("audio-input-microphone-symbolic");
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    imp.reset_selected_source.set_active(true);
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    imp.reset_selected_source.set_active(false);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                imp.reset_source_name
 | 
					 | 
				
			||||||
                    .set_title(ir.source.alias.clone().as_str());
 | 
					 | 
				
			||||||
                imp.reset_volume_percentage.set_text(&percentage);
 | 
					 | 
				
			||||||
                imp.reset_volume_slider.set_value(*volume as f64);
 | 
					 | 
				
			||||||
                if ir.source.muted {
 | 
					 | 
				
			||||||
                    imp.reset_source_mute
 | 
					 | 
				
			||||||
                        .set_icon_name("microphone-disabled-symbolic");
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    imp.reset_source_mute
 | 
					 | 
				
			||||||
                        .set_icon_name("audio-input-microphone-symbolic");
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        true
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        println!("fail on source change event");
 | 
					 | 
				
			||||||
        return conn;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let res = conn.add_match(output_stream_added, move |ir: OutputStreamAdded, _, _| {
 | 
					 | 
				
			||||||
        let source_box = output_stream_added_box.clone();
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let input_box = source_box.clone();
 | 
					 | 
				
			||||||
                let input_box_imp = input_box.imp();
 | 
					 | 
				
			||||||
                let mut list = input_box_imp.reset_output_stream_list.write().unwrap();
 | 
					 | 
				
			||||||
                let index = ir.stream.index;
 | 
					 | 
				
			||||||
                let output_stream = Arc::new(OutputStreamEntry::new(input_box.clone(), ir.stream));
 | 
					 | 
				
			||||||
                let entry = Arc::new(ListEntry::new(&*output_stream));
 | 
					 | 
				
			||||||
                entry.set_activatable(false);
 | 
					 | 
				
			||||||
                list.insert(index, (entry.clone(), output_stream.clone()));
 | 
					 | 
				
			||||||
                input_box_imp.reset_output_streams.append(&*entry);
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        true
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        println!("fail on output stream add event");
 | 
					 | 
				
			||||||
        return conn;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let res = conn.add_match(
 | 
					 | 
				
			||||||
        output_stream_changed,
 | 
					 | 
				
			||||||
        move |ir: OutputStreamChanged, _, _| {
 | 
					 | 
				
			||||||
            let imp = output_stream_changed_box.imp();
 | 
					 | 
				
			||||||
            let alias: String;
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                let source_list = imp.reset_source_list.read().unwrap();
 | 
					 | 
				
			||||||
                if let Some(alias_opt) = source_list.get(&ir.stream.source_index) {
 | 
					 | 
				
			||||||
                    alias = alias_opt.2.clone();
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    alias = String::from("");
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            let source_box = output_stream_changed_box.clone();
 | 
					 | 
				
			||||||
            glib::spawn_future(async move {
 | 
					 | 
				
			||||||
                glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                    let input_box = source_box.clone();
 | 
					 | 
				
			||||||
                    let input_box_imp = input_box.imp();
 | 
					 | 
				
			||||||
                    let entry: Arc<OutputStreamEntry>;
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        let list = input_box_imp.reset_output_stream_list.read().unwrap();
 | 
					 | 
				
			||||||
                        let entry_opt = list.get(&ir.stream.index);
 | 
					 | 
				
			||||||
                        if entry_opt.is_none() {
 | 
					 | 
				
			||||||
                            return;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        entry = entry_opt.unwrap().1.clone();
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    let imp = entry.imp();
 | 
					 | 
				
			||||||
                    if ir.stream.muted {
 | 
					 | 
				
			||||||
                        imp.reset_source_mute
 | 
					 | 
				
			||||||
                            .set_icon_name("microphone-disabled-symbolic");
 | 
					 | 
				
			||||||
                    } else {
 | 
					 | 
				
			||||||
                        imp.reset_source_mute
 | 
					 | 
				
			||||||
                            .set_icon_name("audio-input-microphone-symbolic");
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    let name = ir.stream.application_name.clone() + ": " + ir.stream.name.as_str();
 | 
					 | 
				
			||||||
                    imp.reset_source_selection.set_title(name.as_str());
 | 
					 | 
				
			||||||
                    let volume = ir.stream.volume.first().unwrap_or(&0_u32);
 | 
					 | 
				
			||||||
                    let fraction = (*volume as f64 / 655.36).round();
 | 
					 | 
				
			||||||
                    let percentage = (fraction).to_string() + "%";
 | 
					 | 
				
			||||||
                    imp.reset_volume_percentage.set_text(&percentage);
 | 
					 | 
				
			||||||
                    imp.reset_volume_slider.set_value(*volume as f64);
 | 
					 | 
				
			||||||
                    let index = input_box_imp.reset_model_index.read().unwrap();
 | 
					 | 
				
			||||||
                    let model_list = input_box_imp.reset_model_list.read().unwrap();
 | 
					 | 
				
			||||||
                    for entry in 0..*index {
 | 
					 | 
				
			||||||
                        if model_list.string(entry) == Some(alias.clone().into()) {
 | 
					 | 
				
			||||||
                            imp.reset_source_selection.set_selected(entry);
 | 
					 | 
				
			||||||
                            break;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            true
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        println!("fail on output stream change event");
 | 
					 | 
				
			||||||
        return conn;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let res = conn.add_match(
 | 
					 | 
				
			||||||
        output_stream_removed,
 | 
					 | 
				
			||||||
        move |ir: OutputStreamRemoved, _, _| {
 | 
					 | 
				
			||||||
            let source_box = output_stream_removed_box.clone();
 | 
					 | 
				
			||||||
            glib::spawn_future(async move {
 | 
					 | 
				
			||||||
                glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                    let input_box = source_box.clone();
 | 
					 | 
				
			||||||
                    let input_box_imp = input_box.imp();
 | 
					 | 
				
			||||||
                    let mut list = input_box_imp.reset_output_stream_list.write().unwrap();
 | 
					 | 
				
			||||||
                    let entry = list.remove(&ir.index);
 | 
					 | 
				
			||||||
                    if entry.is_none() {
 | 
					 | 
				
			||||||
                        return;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    input_box_imp
 | 
					 | 
				
			||||||
                        .reset_output_streams
 | 
					 | 
				
			||||||
                        .remove(&*entry.unwrap().0);
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            true
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        println!("fail on output stream remove event");
 | 
					 | 
				
			||||||
        return conn;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    conn
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
 | 
					pub mod audio;
 | 
				
			||||||
pub mod base;
 | 
					pub mod base;
 | 
				
			||||||
pub mod bluetooth;
 | 
					pub mod bluetooth;
 | 
				
			||||||
mod input;
 | 
					 | 
				
			||||||
pub mod output;
 | 
					 | 
				
			||||||
pub mod utils;
 | 
					pub mod utils;
 | 
				
			||||||
pub mod wifi;
 | 
					pub mod wifi;
 | 
				
			||||||
pub mod window;
 | 
					pub mod window;
 | 
				
			||||||
 | 
					mod plugin;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,655 +0,0 @@
 | 
				
			||||||
use adw::prelude::PreferencesGroupExt;
 | 
					 | 
				
			||||||
use adw::prelude::PreferencesRowExt;
 | 
					 | 
				
			||||||
use re_set_lib::audio::audio_structures::Card;
 | 
					 | 
				
			||||||
use re_set_lib::audio::audio_structures::InputStream;
 | 
					 | 
				
			||||||
use re_set_lib::audio::audio_structures::Sink;
 | 
					 | 
				
			||||||
use re_set_lib::signals::InputStreamAdded;
 | 
					 | 
				
			||||||
use re_set_lib::signals::InputStreamChanged;
 | 
					 | 
				
			||||||
use re_set_lib::signals::InputStreamRemoved;
 | 
					 | 
				
			||||||
use re_set_lib::signals::SinkAdded;
 | 
					 | 
				
			||||||
use re_set_lib::signals::SinkChanged;
 | 
					 | 
				
			||||||
use re_set_lib::signals::SinkRemoved;
 | 
					 | 
				
			||||||
use std::sync::Arc;
 | 
					 | 
				
			||||||
use std::time::{Duration, SystemTime};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
use adw::glib::Object;
 | 
					 | 
				
			||||||
use adw::prelude::{BoxExt, ButtonExt, CheckButtonExt, ComboRowExt, RangeExt};
 | 
					 | 
				
			||||||
use adw::{glib, prelude::ListBoxRowExt};
 | 
					 | 
				
			||||||
use dbus::blocking::Connection;
 | 
					 | 
				
			||||||
use dbus::message::SignalArgs;
 | 
					 | 
				
			||||||
use dbus::{Error, Path};
 | 
					 | 
				
			||||||
use glib::subclass::prelude::ObjectSubclassIsExt;
 | 
					 | 
				
			||||||
use glib::{clone, Cast, Propagation, Variant};
 | 
					 | 
				
			||||||
use gtk::prelude::ActionableExt;
 | 
					 | 
				
			||||||
use gtk::{gio, StringObject};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
use crate::components::base::card_entry::CardEntry;
 | 
					 | 
				
			||||||
use crate::components::base::list_entry::ListEntry;
 | 
					 | 
				
			||||||
use crate::components::output::sink_entry::set_sink_volume;
 | 
					 | 
				
			||||||
use crate::components::utils::AUDIO;
 | 
					 | 
				
			||||||
use crate::components::utils::BASE;
 | 
					 | 
				
			||||||
use crate::components::utils::DBUS_PATH;
 | 
					 | 
				
			||||||
use crate::components::utils::{create_dropdown_label_factory, set_combo_row_ellipsis};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
use super::input_stream_entry::InputStreamEntry;
 | 
					 | 
				
			||||||
use super::sink_box_impl;
 | 
					 | 
				
			||||||
use super::sink_entry::{set_default_sink, toggle_sink_mute, SinkEntry};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
glib::wrapper! {
 | 
					 | 
				
			||||||
    pub struct SinkBox(ObjectSubclass<sink_box_impl::SinkBox>)
 | 
					 | 
				
			||||||
    @extends gtk::Box, gtk::Widget,
 | 
					 | 
				
			||||||
    @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
unsafe impl Send for SinkBox {}
 | 
					 | 
				
			||||||
unsafe impl Sync for SinkBox {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
impl SinkBox {
 | 
					 | 
				
			||||||
    pub fn new() -> Self {
 | 
					 | 
				
			||||||
        let obj: Self = Object::builder().build();
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            let imp = obj.imp();
 | 
					 | 
				
			||||||
            let mut model_index = imp.reset_model_index.write().unwrap();
 | 
					 | 
				
			||||||
            *model_index = 0;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        obj
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pub fn setup_callbacks(&self) {
 | 
					 | 
				
			||||||
        let self_imp = self.imp();
 | 
					 | 
				
			||||||
        self_imp.reset_sinks_row.set_activatable(true);
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_sinks_row
 | 
					 | 
				
			||||||
            .set_action_name(Some("navigation.push"));
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_sinks_row
 | 
					 | 
				
			||||||
            .set_action_target_value(Some(&Variant::from("outputDevices")));
 | 
					 | 
				
			||||||
        self_imp.reset_cards_row.set_activatable(true);
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_cards_row
 | 
					 | 
				
			||||||
            .set_action_name(Some("navigation.push"));
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_cards_row
 | 
					 | 
				
			||||||
            .set_action_target_value(Some(&Variant::from("profileConfiguration")));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self_imp.reset_input_stream_button.set_activatable(true);
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_input_stream_button
 | 
					 | 
				
			||||||
            .set_action_name(Some("navigation.pop"));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self_imp.reset_input_cards_back_button.set_activatable(true);
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_input_cards_back_button
 | 
					 | 
				
			||||||
            .set_action_name(Some("navigation.pop"));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_sink_dropdown
 | 
					 | 
				
			||||||
            .set_factory(Some(&create_dropdown_label_factory()));
 | 
					 | 
				
			||||||
        set_combo_row_ellipsis(self_imp.reset_sink_dropdown.get());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
impl Default for SinkBox {
 | 
					 | 
				
			||||||
    fn default() -> Self {
 | 
					 | 
				
			||||||
        Self::new()
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn populate_sinks(output_box: Arc<SinkBox>) {
 | 
					 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					 | 
				
			||||||
        let sinks = get_sinks();
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            let output_box_imp = output_box.imp();
 | 
					 | 
				
			||||||
            let list = output_box_imp.reset_model_list.write().unwrap();
 | 
					 | 
				
			||||||
            let mut map = output_box_imp.reset_sink_map.write().unwrap();
 | 
					 | 
				
			||||||
            let mut model_index = output_box_imp.reset_model_index.write().unwrap();
 | 
					 | 
				
			||||||
            output_box_imp
 | 
					 | 
				
			||||||
                .reset_default_sink
 | 
					 | 
				
			||||||
                .replace(get_default_sink());
 | 
					 | 
				
			||||||
            for sink in sinks.iter() {
 | 
					 | 
				
			||||||
                list.append(&sink.alias);
 | 
					 | 
				
			||||||
                map.insert(sink.alias.clone(), (sink.index, sink.name.clone()));
 | 
					 | 
				
			||||||
                *model_index += 1;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        populate_inputstreams(output_box.clone());
 | 
					 | 
				
			||||||
        populate_cards(output_box.clone());
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let output_box_ref_select = output_box.clone();
 | 
					 | 
				
			||||||
                let output_box_ref_slider = output_box.clone();
 | 
					 | 
				
			||||||
                let output_box_ref_mute = output_box.clone();
 | 
					 | 
				
			||||||
                let output_box_ref = output_box.clone();
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    let output_box_imp = output_box_ref.imp();
 | 
					 | 
				
			||||||
                    let default_sink = output_box_imp.reset_default_sink.clone();
 | 
					 | 
				
			||||||
                    let sink = default_sink.borrow();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if sink.muted {
 | 
					 | 
				
			||||||
                        output_box_imp
 | 
					 | 
				
			||||||
                            .reset_sink_mute
 | 
					 | 
				
			||||||
                            .set_icon_name("audio-volume-muted-symbolic");
 | 
					 | 
				
			||||||
                    } else {
 | 
					 | 
				
			||||||
                        output_box_imp
 | 
					 | 
				
			||||||
                            .reset_sink_mute
 | 
					 | 
				
			||||||
                            .set_icon_name("audio-volume-high-symbolic");
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    let volume = sink.volume.first().unwrap_or(&0);
 | 
					 | 
				
			||||||
                    let fraction = (*volume as f64 / 655.36).round();
 | 
					 | 
				
			||||||
                    let percentage = (fraction).to_string() + "%";
 | 
					 | 
				
			||||||
                    output_box_imp.reset_volume_percentage.set_text(&percentage);
 | 
					 | 
				
			||||||
                    output_box_imp.reset_volume_slider.set_value(*volume as f64);
 | 
					 | 
				
			||||||
                    let mut list = output_box_imp.reset_sink_list.write().unwrap();
 | 
					 | 
				
			||||||
                    for sink in sinks {
 | 
					 | 
				
			||||||
                        let index = sink.index;
 | 
					 | 
				
			||||||
                        let alias = sink.alias.clone();
 | 
					 | 
				
			||||||
                        let mut is_default = false;
 | 
					 | 
				
			||||||
                        if output_box_imp.reset_default_sink.borrow().name == sink.name {
 | 
					 | 
				
			||||||
                            is_default = true;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        let sink_entry = Arc::new(SinkEntry::new(
 | 
					 | 
				
			||||||
                            is_default,
 | 
					 | 
				
			||||||
                            output_box_imp.reset_default_check_button.clone(),
 | 
					 | 
				
			||||||
                            sink,
 | 
					 | 
				
			||||||
                            output_box.clone(),
 | 
					 | 
				
			||||||
                        ));
 | 
					 | 
				
			||||||
                        let sink_clone = sink_entry.clone();
 | 
					 | 
				
			||||||
                        let entry = Arc::new(ListEntry::new(&*sink_entry));
 | 
					 | 
				
			||||||
                        entry.set_activatable(false);
 | 
					 | 
				
			||||||
                        list.insert(index, (entry.clone(), sink_clone, alias));
 | 
					 | 
				
			||||||
                        output_box_imp.reset_sinks.append(&*entry);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    let list = output_box_imp.reset_model_list.read().unwrap();
 | 
					 | 
				
			||||||
                    output_box_imp.reset_sink_dropdown.set_model(Some(&*list));
 | 
					 | 
				
			||||||
                    let name = output_box_imp.reset_default_sink.borrow();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    let index = output_box_imp.reset_model_index.read().unwrap();
 | 
					 | 
				
			||||||
                    let model_list = output_box_imp.reset_model_list.read().unwrap();
 | 
					 | 
				
			||||||
                    for entry in 0..*index {
 | 
					 | 
				
			||||||
                        if model_list.string(entry) == Some(name.alias.clone().into()) {
 | 
					 | 
				
			||||||
                            output_box_imp.reset_sink_dropdown.set_selected(entry);
 | 
					 | 
				
			||||||
                            break;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    output_box_imp.reset_sink_dropdown.connect_selected_notify(
 | 
					 | 
				
			||||||
                        clone!(@weak output_box_imp => move |dropdown| {
 | 
					 | 
				
			||||||
                            let output_box_ref = output_box_ref_select.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 sink = output_box_imp.reset_sink_map.read().unwrap();
 | 
					 | 
				
			||||||
                            let sink = sink.get(&selected);
 | 
					 | 
				
			||||||
                            if sink.is_none() {
 | 
					 | 
				
			||||||
                                return;
 | 
					 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                            let new_sink_name = Arc::new(sink.unwrap().1.clone());
 | 
					 | 
				
			||||||
                            gio::spawn_blocking(move || {
 | 
					 | 
				
			||||||
                                let result = set_default_sink(new_sink_name);
 | 
					 | 
				
			||||||
                                if result.is_none() {
 | 
					 | 
				
			||||||
                                    return;
 | 
					 | 
				
			||||||
                                }
 | 
					 | 
				
			||||||
                                let new_sink = result.unwrap();
 | 
					 | 
				
			||||||
                                refresh_default_sink(new_sink, output_box_ref, false);
 | 
					 | 
				
			||||||
                            });
 | 
					 | 
				
			||||||
                        }),
 | 
					 | 
				
			||||||
                    );
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                output_box_ref
 | 
					 | 
				
			||||||
                    .imp()
 | 
					 | 
				
			||||||
                    .reset_volume_slider
 | 
					 | 
				
			||||||
                    .connect_change_value(move |_, _, value| {
 | 
					 | 
				
			||||||
                        let imp = output_box_ref_slider.imp();
 | 
					 | 
				
			||||||
                        let fraction = (value / 655.36).round();
 | 
					 | 
				
			||||||
                        let percentage = (fraction).to_string() + "%";
 | 
					 | 
				
			||||||
                        imp.reset_volume_percentage.set_text(&percentage);
 | 
					 | 
				
			||||||
                        let sink = imp.reset_default_sink.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);
 | 
					 | 
				
			||||||
                        Propagation::Proceed
 | 
					 | 
				
			||||||
                    });
 | 
					 | 
				
			||||||
                output_box_ref
 | 
					 | 
				
			||||||
                    .imp()
 | 
					 | 
				
			||||||
                    .reset_sink_mute
 | 
					 | 
				
			||||||
                    .connect_clicked(move |_| {
 | 
					 | 
				
			||||||
                        let imp = output_box_ref_mute.imp();
 | 
					 | 
				
			||||||
                        let mut stream = imp.reset_default_sink.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);
 | 
					 | 
				
			||||||
                    });
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn refresh_default_sink(new_sink: Sink, output_box: Arc<SinkBox>, entry: bool) {
 | 
					 | 
				
			||||||
    let volume = *new_sink.volume.first().unwrap_or(&0_u32);
 | 
					 | 
				
			||||||
    let fraction = (volume as f64 / 655.36).round();
 | 
					 | 
				
			||||||
    let percentage = (fraction).to_string() + "%";
 | 
					 | 
				
			||||||
    glib::spawn_future(async move {
 | 
					 | 
				
			||||||
        glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
            let imp = output_box.imp();
 | 
					 | 
				
			||||||
            if !entry {
 | 
					 | 
				
			||||||
                let list = imp.reset_sink_list.read().unwrap();
 | 
					 | 
				
			||||||
                let entry = list.get(&new_sink.index);
 | 
					 | 
				
			||||||
                if entry.is_none() {
 | 
					 | 
				
			||||||
                    return;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                let entry_imp = entry.unwrap().1.imp();
 | 
					 | 
				
			||||||
                entry_imp.reset_selected_sink.set_active(true);
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                let index = imp.reset_model_index.read().unwrap();
 | 
					 | 
				
			||||||
                let model_list = imp.reset_model_list.read().unwrap();
 | 
					 | 
				
			||||||
                for entry in 0..*index {
 | 
					 | 
				
			||||||
                    if model_list.string(entry) == Some(new_sink.alias.clone().into()) {
 | 
					 | 
				
			||||||
                        imp.reset_sink_dropdown.set_selected(entry);
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            imp.reset_volume_percentage.set_text(&percentage);
 | 
					 | 
				
			||||||
            imp.reset_volume_slider.set_value(volume as f64);
 | 
					 | 
				
			||||||
            if new_sink.muted {
 | 
					 | 
				
			||||||
                imp.reset_sink_mute
 | 
					 | 
				
			||||||
                    .set_icon_name("audio-volume-muted-symbolic");
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                imp.reset_sink_mute
 | 
					 | 
				
			||||||
                    .set_icon_name("audio-volume-high-symbolic");
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            imp.reset_default_sink.replace(new_sink);
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn populate_inputstreams(output_box: Arc<SinkBox>) {
 | 
					 | 
				
			||||||
    let output_box_ref = output_box.clone();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					 | 
				
			||||||
        let streams = get_input_streams();
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let output_box_imp = output_box_ref.imp();
 | 
					 | 
				
			||||||
                let mut list = output_box_imp.reset_input_stream_list.write().unwrap();
 | 
					 | 
				
			||||||
                for stream in streams {
 | 
					 | 
				
			||||||
                    let index = stream.index;
 | 
					 | 
				
			||||||
                    let input_stream = Arc::new(InputStreamEntry::new(output_box.clone(), stream));
 | 
					 | 
				
			||||||
                    let entry = Arc::new(ListEntry::new(&*input_stream));
 | 
					 | 
				
			||||||
                    entry.set_activatable(false);
 | 
					 | 
				
			||||||
                    list.insert(index, (entry.clone(), input_stream.clone()));
 | 
					 | 
				
			||||||
                    output_box_imp.reset_input_streams.append(&*entry);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn populate_cards(output_box: Arc<SinkBox>) {
 | 
					 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					 | 
				
			||||||
        let output_box_ref = output_box.clone();
 | 
					 | 
				
			||||||
        let cards = get_cards();
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let imp = output_box_ref.imp();
 | 
					 | 
				
			||||||
                for card in cards {
 | 
					 | 
				
			||||||
                    imp.reset_cards.add(&CardEntry::new(card));
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn get_input_streams() -> Vec<InputStream> {
 | 
					 | 
				
			||||||
    let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
					 | 
				
			||||||
    let res: Result<(Vec<InputStream>,), Error> = proxy.method_call(AUDIO, "ListInputStreams", ());
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        return Vec::new();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    res.unwrap().0
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn get_sinks() -> Vec<Sink> {
 | 
					 | 
				
			||||||
    let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
					 | 
				
			||||||
    let res: Result<(Vec<Sink>,), Error> = proxy.method_call(AUDIO, "ListSinks", ());
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        return Vec::new();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    res.unwrap().0
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn get_cards() -> Vec<Card> {
 | 
					 | 
				
			||||||
    let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
					 | 
				
			||||||
    let res: Result<(Vec<Card>,), Error> = proxy.method_call(AUDIO, "ListCards", ());
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        return Vec::new();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    res.unwrap().0
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn get_default_sink_name() -> String {
 | 
					 | 
				
			||||||
    let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
					 | 
				
			||||||
    let res: Result<(String,), Error> = proxy.method_call(AUDIO, "GetDefaultSinkName", ());
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        return String::from("");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    res.unwrap().0
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn get_default_sink() -> Sink {
 | 
					 | 
				
			||||||
    let conn = Connection::new_session().unwrap();
 | 
					 | 
				
			||||||
    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
					 | 
				
			||||||
    let res: Result<(Sink,), Error> = proxy.method_call(AUDIO, "GetDefaultSink", ());
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        return Sink::default();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    res.unwrap().0
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn start_output_box_listener(conn: Connection, sink_box: Arc<SinkBox>) -> Connection {
 | 
					 | 
				
			||||||
    let sink_added =
 | 
					 | 
				
			||||||
        SinkAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
 | 
					 | 
				
			||||||
    let sink_removed =
 | 
					 | 
				
			||||||
        SinkRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
 | 
					 | 
				
			||||||
    let sink_changed =
 | 
					 | 
				
			||||||
        SinkChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
 | 
					 | 
				
			||||||
    let input_stream_added =
 | 
					 | 
				
			||||||
        InputStreamAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
 | 
					 | 
				
			||||||
            .static_clone();
 | 
					 | 
				
			||||||
    let input_stream_removed =
 | 
					 | 
				
			||||||
        InputStreamRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
 | 
					 | 
				
			||||||
            .static_clone();
 | 
					 | 
				
			||||||
    let input_stream_changed =
 | 
					 | 
				
			||||||
        InputStreamChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
 | 
					 | 
				
			||||||
            .static_clone();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let sink_added_box = sink_box.clone();
 | 
					 | 
				
			||||||
    let sink_removed_box = sink_box.clone();
 | 
					 | 
				
			||||||
    let sink_changed_box = sink_box.clone();
 | 
					 | 
				
			||||||
    let input_stream_added_box = sink_box.clone();
 | 
					 | 
				
			||||||
    let input_stream_removed_box = sink_box.clone();
 | 
					 | 
				
			||||||
    let input_stream_changed_box = sink_box.clone();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let res = conn.add_match(sink_added, move |ir: SinkAdded, _, _| {
 | 
					 | 
				
			||||||
        let sink_box = sink_added_box.clone();
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let output_box = sink_box.clone();
 | 
					 | 
				
			||||||
                let output_box_imp = output_box.imp();
 | 
					 | 
				
			||||||
                let sink_index = ir.sink.index;
 | 
					 | 
				
			||||||
                let alias = ir.sink.alias.clone();
 | 
					 | 
				
			||||||
                let name = ir.sink.name.clone();
 | 
					 | 
				
			||||||
                let mut is_default = false;
 | 
					 | 
				
			||||||
                if output_box_imp.reset_default_sink.borrow().name == ir.sink.name {
 | 
					 | 
				
			||||||
                    is_default = true;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                let sink_entry = Arc::new(SinkEntry::new(
 | 
					 | 
				
			||||||
                    is_default,
 | 
					 | 
				
			||||||
                    output_box_imp.reset_default_check_button.clone(),
 | 
					 | 
				
			||||||
                    ir.sink,
 | 
					 | 
				
			||||||
                    output_box.clone(),
 | 
					 | 
				
			||||||
                ));
 | 
					 | 
				
			||||||
                let sink_clone = sink_entry.clone();
 | 
					 | 
				
			||||||
                let entry = Arc::new(ListEntry::new(&*sink_entry));
 | 
					 | 
				
			||||||
                entry.set_activatable(false);
 | 
					 | 
				
			||||||
                let mut list = output_box_imp.reset_sink_list.write().unwrap();
 | 
					 | 
				
			||||||
                list.insert(sink_index, (entry.clone(), sink_clone, alias.clone()));
 | 
					 | 
				
			||||||
                output_box_imp.reset_sinks.append(&*entry);
 | 
					 | 
				
			||||||
                let mut map = output_box_imp.reset_sink_map.write().unwrap();
 | 
					 | 
				
			||||||
                let mut index = output_box_imp.reset_model_index.write().unwrap();
 | 
					 | 
				
			||||||
                let model_list = output_box_imp.reset_model_list.write().unwrap();
 | 
					 | 
				
			||||||
                if model_list.string(*index - 1) == Some("Dummy Output".into()) {
 | 
					 | 
				
			||||||
                    model_list.append(&alias);
 | 
					 | 
				
			||||||
                    model_list.remove(*index - 1);
 | 
					 | 
				
			||||||
                    map.insert(alias, (sink_index, name));
 | 
					 | 
				
			||||||
                    output_box_imp.reset_sink_dropdown.set_selected(0);
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    model_list.append(&alias);
 | 
					 | 
				
			||||||
                    map.insert(alias.clone(), (sink_index, name));
 | 
					 | 
				
			||||||
                    if alias == "Dummy Output" {
 | 
					 | 
				
			||||||
                        output_box_imp.reset_sink_dropdown.set_selected(0);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    *index += 1;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        true
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        println!("fail on sink add event");
 | 
					 | 
				
			||||||
        return conn;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let res = conn.add_match(sink_removed, move |ir: SinkRemoved, _, _| {
 | 
					 | 
				
			||||||
        let sink_box = sink_removed_box.clone();
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let output_box = sink_box.clone();
 | 
					 | 
				
			||||||
                let output_box_imp = output_box.imp();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                let entry: Option<(Arc<ListEntry>, Arc<SinkEntry>, String)>;
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    let mut list = output_box_imp.reset_sink_list.write().unwrap();
 | 
					 | 
				
			||||||
                    entry = list.remove(&ir.index);
 | 
					 | 
				
			||||||
                    if entry.is_none() {
 | 
					 | 
				
			||||||
                        return;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                output_box_imp
 | 
					 | 
				
			||||||
                    .reset_sinks
 | 
					 | 
				
			||||||
                    .remove(&*entry.clone().unwrap().0);
 | 
					 | 
				
			||||||
                let alias = entry.unwrap().2;
 | 
					 | 
				
			||||||
                let mut index = output_box_imp.reset_model_index.write().unwrap();
 | 
					 | 
				
			||||||
                let model_list = output_box_imp.reset_model_list.write().unwrap();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                // add dummy entry when no other devices are available
 | 
					 | 
				
			||||||
                if *index == 1 {
 | 
					 | 
				
			||||||
                    model_list.append("Dummy Output");
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                let mut map = output_box_imp.reset_sink_map.write().unwrap();
 | 
					 | 
				
			||||||
                map.remove(&alias);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                for entry in 0..*index {
 | 
					 | 
				
			||||||
                    if model_list.string(entry) == Some(alias.clone().into()) {
 | 
					 | 
				
			||||||
                        model_list.splice(entry, 1, &[]);
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                // dummy enforces a minimum of 1
 | 
					 | 
				
			||||||
                if *index > 1 {
 | 
					 | 
				
			||||||
                    *index -= 1;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        true
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        println!("fail on sink remove event");
 | 
					 | 
				
			||||||
        return conn;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let res = conn.add_match(sink_changed, move |ir: SinkChanged, _, _| {
 | 
					 | 
				
			||||||
        let sink_box = sink_changed_box.clone();
 | 
					 | 
				
			||||||
        let default_sink = get_default_sink_name();
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let output_box = sink_box.clone();
 | 
					 | 
				
			||||||
                let output_box_imp = output_box.imp();
 | 
					 | 
				
			||||||
                let is_default = ir.sink.name == default_sink;
 | 
					 | 
				
			||||||
                let volume = ir.sink.volume.first().unwrap_or(&0_u32);
 | 
					 | 
				
			||||||
                let fraction = (*volume as f64 / 655.36).round();
 | 
					 | 
				
			||||||
                let percentage = (fraction).to_string() + "%";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                let list = output_box_imp.reset_sink_list.read().unwrap();
 | 
					 | 
				
			||||||
                let entry = list.get(&ir.sink.index);
 | 
					 | 
				
			||||||
                if entry.is_none() {
 | 
					 | 
				
			||||||
                    return;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                let imp = entry.unwrap().1.imp();
 | 
					 | 
				
			||||||
                if is_default {
 | 
					 | 
				
			||||||
                    output_box_imp.reset_volume_percentage.set_text(&percentage);
 | 
					 | 
				
			||||||
                    output_box_imp.reset_volume_slider.set_value(*volume as f64);
 | 
					 | 
				
			||||||
                    output_box_imp.reset_default_sink.replace(ir.sink.clone());
 | 
					 | 
				
			||||||
                    if ir.sink.muted {
 | 
					 | 
				
			||||||
                        output_box_imp
 | 
					 | 
				
			||||||
                            .reset_sink_mute
 | 
					 | 
				
			||||||
                            .set_icon_name("audio-volume-muted-symbolic");
 | 
					 | 
				
			||||||
                    } else {
 | 
					 | 
				
			||||||
                        output_box_imp
 | 
					 | 
				
			||||||
                            .reset_sink_mute
 | 
					 | 
				
			||||||
                            .set_icon_name("audio-volume-high-symbolic");
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    imp.reset_selected_sink.set_active(true);
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    imp.reset_selected_sink.set_active(false);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                imp.reset_sink_name
 | 
					 | 
				
			||||||
                    .set_title(ir.sink.alias.clone().as_str());
 | 
					 | 
				
			||||||
                imp.reset_volume_percentage.set_text(&percentage);
 | 
					 | 
				
			||||||
                imp.reset_volume_slider.set_value(*volume as f64);
 | 
					 | 
				
			||||||
                if ir.sink.muted {
 | 
					 | 
				
			||||||
                    imp.reset_sink_mute
 | 
					 | 
				
			||||||
                        .set_icon_name("audio-volume-muted-symbolic");
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    imp.reset_sink_mute
 | 
					 | 
				
			||||||
                        .set_icon_name("audio-volume-high-symbolic");
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        true
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        println!("fail on sink change event");
 | 
					 | 
				
			||||||
        return conn;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let res = conn.add_match(input_stream_added, move |ir: InputStreamAdded, _, _| {
 | 
					 | 
				
			||||||
        let sink_box = input_stream_added_box.clone();
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let output_box = sink_box.clone();
 | 
					 | 
				
			||||||
                let output_box_imp = output_box.imp();
 | 
					 | 
				
			||||||
                let mut list = output_box_imp.reset_input_stream_list.write().unwrap();
 | 
					 | 
				
			||||||
                let index = ir.stream.index;
 | 
					 | 
				
			||||||
                let input_stream = Arc::new(InputStreamEntry::new(output_box.clone(), ir.stream));
 | 
					 | 
				
			||||||
                let entry = Arc::new(ListEntry::new(&*input_stream));
 | 
					 | 
				
			||||||
                entry.set_activatable(false);
 | 
					 | 
				
			||||||
                list.insert(index, (entry.clone(), input_stream.clone()));
 | 
					 | 
				
			||||||
                output_box_imp.reset_input_streams.append(&*entry);
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        true
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        println!("fail on input stream add event");
 | 
					 | 
				
			||||||
        return conn;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let res = conn.add_match(input_stream_changed, move |ir: InputStreamChanged, _, _| {
 | 
					 | 
				
			||||||
        let imp = input_stream_changed_box.imp();
 | 
					 | 
				
			||||||
        let alias: String;
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            let sink_list = imp.reset_sink_list.read().unwrap();
 | 
					 | 
				
			||||||
            if let Some(alias_opt) = sink_list.get(&ir.stream.sink_index) {
 | 
					 | 
				
			||||||
                alias = alias_opt.2.clone();
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                alias = String::from("");
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        let sink_box = input_stream_changed_box.clone();
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let output_box = sink_box.clone();
 | 
					 | 
				
			||||||
                let output_box_imp = output_box.imp();
 | 
					 | 
				
			||||||
                let entry: Arc<InputStreamEntry>;
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    let list = output_box_imp.reset_input_stream_list.read().unwrap();
 | 
					 | 
				
			||||||
                    let entry_opt = list.get(&ir.stream.index);
 | 
					 | 
				
			||||||
                    if entry_opt.is_none() {
 | 
					 | 
				
			||||||
                        return;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    entry = entry_opt.unwrap().1.clone();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                let imp = entry.imp();
 | 
					 | 
				
			||||||
                if ir.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");
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                let name = ir.stream.application_name.clone() + ": " + ir.stream.name.as_str();
 | 
					 | 
				
			||||||
                imp.reset_sink_selection.set_title(name.as_str());
 | 
					 | 
				
			||||||
                let volume = ir.stream.volume.first().unwrap_or(&0_u32);
 | 
					 | 
				
			||||||
                let fraction = (*volume as f64 / 655.36).round();
 | 
					 | 
				
			||||||
                let percentage = (fraction).to_string() + "%";
 | 
					 | 
				
			||||||
                imp.reset_volume_percentage.set_text(&percentage);
 | 
					 | 
				
			||||||
                imp.reset_volume_slider.set_value(*volume as f64);
 | 
					 | 
				
			||||||
                let index = output_box_imp.reset_model_index.read().unwrap();
 | 
					 | 
				
			||||||
                let model_list = output_box_imp.reset_model_list.read().unwrap();
 | 
					 | 
				
			||||||
                for entry in 0..*index {
 | 
					 | 
				
			||||||
                    if model_list.string(entry) == Some(alias.clone().into()) {
 | 
					 | 
				
			||||||
                        imp.reset_sink_selection.set_selected(entry);
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        true
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        println!("fail on input stream change event");
 | 
					 | 
				
			||||||
        return conn;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let res = conn.add_match(input_stream_removed, move |ir: InputStreamRemoved, _, _| {
 | 
					 | 
				
			||||||
        let sink_box = input_stream_removed_box.clone();
 | 
					 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                let output_box = sink_box.clone();
 | 
					 | 
				
			||||||
                let output_box_imp = output_box.imp();
 | 
					 | 
				
			||||||
                let mut list = output_box_imp.reset_input_stream_list.write().unwrap();
 | 
					 | 
				
			||||||
                let entry = list.remove(&ir.index);
 | 
					 | 
				
			||||||
                if entry.is_none() {
 | 
					 | 
				
			||||||
                    return;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                output_box_imp
 | 
					 | 
				
			||||||
                    .reset_input_streams
 | 
					 | 
				
			||||||
                    .remove(&*entry.unwrap().0);
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        true
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					 | 
				
			||||||
        println!("fail on input stream remove event");
 | 
					 | 
				
			||||||
        return conn;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    conn
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										30
									
								
								src/components/plugin/function.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								src/components/plugin/function.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,30 @@
 | 
				
			||||||
 | 
					use std::cell::RefCell;
 | 
				
			||||||
 | 
					use std::rc::Rc;
 | 
				
			||||||
 | 
					use std::sync::Arc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use gtk::FlowBox;
 | 
				
			||||||
 | 
					use re_set_lib::utils::plugin::SidebarInfo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::base::utils::{Listeners, Position};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern "C" {
 | 
				
			||||||
 | 
					    pub fn startup() -> SidebarInfo;
 | 
				
			||||||
 | 
					    pub fn shutdown();
 | 
				
			||||||
 | 
					    pub fn run_test();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub struct ReSetSidebarInfo {
 | 
				
			||||||
 | 
					    pub name: &'static str,
 | 
				
			||||||
 | 
					    pub icon_name: &'static str,
 | 
				
			||||||
 | 
					    pub parent: Option<&'static str>,
 | 
				
			||||||
 | 
					    pub click_event: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[repr(C)]
 | 
				
			||||||
 | 
					pub struct PluginSidebarInfo {
 | 
				
			||||||
 | 
					    pub name: &'static str,
 | 
				
			||||||
 | 
					    pub icon_name: &'static str,
 | 
				
			||||||
 | 
					    pub parent: Option<&'static str>,
 | 
				
			||||||
 | 
					    pub click_event: Rc<dyn Fn(FlowBox, Rc<RefCell<Position>>, Vec<gtk::Box>)>,
 | 
				
			||||||
 | 
					    pub plugin_boxes: Vec<gtk::Box>,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										1
									
								
								src/components/plugin/mod.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								src/components/plugin/mod.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					pub mod function;
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,10 @@
 | 
				
			||||||
use adw::{ActionRow, ComboRow};
 | 
					 | 
				
			||||||
use adw::gdk::pango::EllipsizeMode;
 | 
					use adw::gdk::pango::EllipsizeMode;
 | 
				
			||||||
use adw::prelude::ListModelExtManual;
 | 
					use adw::prelude::ListModelExtManual;
 | 
				
			||||||
use glib::{Cast, Object};
 | 
					use adw::{ActionRow, ComboRow};
 | 
				
			||||||
use gtk::{Align, SignalListItemFactory, StringObject};
 | 
					use glib::{Object};
 | 
				
			||||||
 | 
					use glib::prelude::Cast;
 | 
				
			||||||
use gtk::prelude::{GObjectPropertyExpressionExt, ListBoxRowExt, ListItemExt, WidgetExt};
 | 
					use gtk::prelude::{GObjectPropertyExpressionExt, ListBoxRowExt, ListItemExt, WidgetExt};
 | 
				
			||||||
 | 
					use gtk::{Align, SignalListItemFactory, StringObject};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub const DBUS_PATH: &str = "/org/Xetibo/ReSet/Daemon";
 | 
					pub const DBUS_PATH: &str = "/org/Xetibo/ReSet/Daemon";
 | 
				
			||||||
pub const WIRELESS: &str = "org.Xetibo.ReSet.Wireless";
 | 
					pub const WIRELESS: &str = "org.Xetibo.ReSet.Wireless";
 | 
				
			||||||
| 
						 | 
					@ -17,14 +18,22 @@ pub fn create_dropdown_label_factory() -> SignalListItemFactory {
 | 
				
			||||||
        let item = item.downcast_ref::<gtk::ListItem>().unwrap();
 | 
					        let item = item.downcast_ref::<gtk::ListItem>().unwrap();
 | 
				
			||||||
        let label = gtk::Label::new(None);
 | 
					        let label = gtk::Label::new(None);
 | 
				
			||||||
        label.set_halign(Align::Start);
 | 
					        label.set_halign(Align::Start);
 | 
				
			||||||
        item.property_expression("item").chain_property::<StringObject>("string").bind(&label, "label", gtk::Widget::NONE);
 | 
					        item.property_expression("item")
 | 
				
			||||||
 | 
					            .chain_property::<StringObject>("string")
 | 
				
			||||||
 | 
					            .bind(&label, "label", gtk::Widget::NONE);
 | 
				
			||||||
        item.set_child(Some(&label));
 | 
					        item.set_child(Some(&label));
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    factory
 | 
					    factory
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn set_combo_row_ellipsis(element: ComboRow) {
 | 
					pub fn set_combo_row_ellipsis(element: ComboRow) {
 | 
				
			||||||
    for (i, child) in element.child().unwrap().observe_children().iter::<Object>().enumerate() {
 | 
					    for (i, child) in element
 | 
				
			||||||
 | 
					        .child()
 | 
				
			||||||
 | 
					        .unwrap()
 | 
				
			||||||
 | 
					        .observe_children()
 | 
				
			||||||
 | 
					        .iter::<Object>()
 | 
				
			||||||
 | 
					        .enumerate()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        if i == 2 {
 | 
					        if i == 2 {
 | 
				
			||||||
            if let Ok(object) = child {
 | 
					            if let Ok(object) = child {
 | 
				
			||||||
                if let Some(item) = object.downcast_ref::<gtk::Box>() {
 | 
					                if let Some(item) = object.downcast_ref::<gtk::Box>() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,7 @@ pub mod wifi_box;
 | 
				
			||||||
pub mod wifi_box_impl;
 | 
					pub mod wifi_box_impl;
 | 
				
			||||||
pub mod wifi_entry;
 | 
					pub mod wifi_entry;
 | 
				
			||||||
pub mod wifi_entry_impl;
 | 
					pub mod wifi_entry_impl;
 | 
				
			||||||
 | 
					mod wifi_event_handlers;
 | 
				
			||||||
pub mod wifi_options;
 | 
					pub mod wifi_options;
 | 
				
			||||||
pub mod wifi_options_impl;
 | 
					pub mod wifi_options_impl;
 | 
				
			||||||
pub mod wifi_route_entry;
 | 
					pub mod wifi_route_entry;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,13 +6,13 @@ use crate::components::wifi::saved_wifi_entry_impl;
 | 
				
			||||||
use crate::components::wifi::utils::get_connection_settings;
 | 
					use crate::components::wifi::utils::get_connection_settings;
 | 
				
			||||||
use crate::components::wifi::wifi_box_impl::WifiBox;
 | 
					use crate::components::wifi::wifi_box_impl::WifiBox;
 | 
				
			||||||
use crate::components::wifi::wifi_options::WifiOptions;
 | 
					use crate::components::wifi::wifi_options::WifiOptions;
 | 
				
			||||||
use adw::glib;
 | 
					 | 
				
			||||||
use adw::glib::Object;
 | 
					use adw::glib::Object;
 | 
				
			||||||
use adw::prelude::{ActionRowExt, ButtonExt, PreferencesGroupExt, PreferencesRowExt};
 | 
					use adw::prelude::{ActionRowExt, ButtonExt, PreferencesGroupExt, PreferencesRowExt};
 | 
				
			||||||
use dbus::blocking::Connection;
 | 
					use dbus::blocking::Connection;
 | 
				
			||||||
use dbus::{Error, Path};
 | 
					use dbus::{Error, Path};
 | 
				
			||||||
use glib::subclass::types::ObjectSubclassIsExt;
 | 
					use glib::subclass::types::ObjectSubclassIsExt;
 | 
				
			||||||
use glib::{clone, PropertySet};
 | 
					use glib::{clone};
 | 
				
			||||||
 | 
					use glib::property::PropertySet;
 | 
				
			||||||
use gtk::prelude::{BoxExt, ListBoxRowExt};
 | 
					use gtk::prelude::{BoxExt, ListBoxRowExt};
 | 
				
			||||||
use gtk::{gio, Align, Button, Orientation};
 | 
					use gtk::{gio, Align, Button, Orientation};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,12 +66,7 @@ impl SavedWifiEntry {
 | 
				
			||||||
fn delete_connection(path: Path<'static>) {
 | 
					fn delete_connection(path: Path<'static>) {
 | 
				
			||||||
    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(
 | 
					        let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
            BASE,
 | 
					        let _: Result<(), Error> = proxy.method_call(WIRELESS, "DeleteConnection", (path,));
 | 
				
			||||||
            DBUS_PATH,
 | 
					 | 
				
			||||||
            Duration::from_millis(1000),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        let _: Result<(), Error> =
 | 
					 | 
				
			||||||
            proxy.method_call(WIRELESS, "DeleteConnection", (path,));
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ use std::cell::RefCell;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use dbus::Path;
 | 
					use dbus::Path;
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, CompositeTemplate};
 | 
					use gtk::CompositeTemplate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::saved_wifi_entry;
 | 
					use super::saved_wifi_entry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,13 +22,8 @@ type ResultType =
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn get_connection_settings(path: Path<'static>) -> ResetConnection {
 | 
					pub fn get_connection_settings(path: Path<'static>) -> ResetConnection {
 | 
				
			||||||
    let conn = Connection::new_session().unwrap();
 | 
					    let conn = Connection::new_session().unwrap();
 | 
				
			||||||
    let proxy = conn.with_proxy(
 | 
					    let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
        BASE,
 | 
					    let res: ResultType = proxy.method_call(WIRELESS, "GetConnectionSettings", (path,));
 | 
				
			||||||
        DBUS_PATH,
 | 
					 | 
				
			||||||
        Duration::from_millis(1000),
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    let res: ResultType =
 | 
					 | 
				
			||||||
        proxy.method_call(WIRELESS, "GetConnectionSettings", (path,));
 | 
					 | 
				
			||||||
    if res.is_err() {
 | 
					    if res.is_err() {
 | 
				
			||||||
        ResetConnection::default();
 | 
					        ResetConnection::default();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,6 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
 | 
				
			||||||
use std::rc::Rc;
 | 
					use std::rc::Rc;
 | 
				
			||||||
use std::str::FromStr;
 | 
					use std::str::FromStr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use adw::glib;
 | 
					 | 
				
			||||||
use adw::glib::Object;
 | 
					use adw::glib::Object;
 | 
				
			||||||
use adw::prelude::PreferencesRowExt;
 | 
					use adw::prelude::PreferencesRowExt;
 | 
				
			||||||
use glib::clone;
 | 
					use glib::clone;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ use crate::components::wifi::utils::IpProtocol;
 | 
				
			||||||
use crate::components::wifi::wifi_address_entry;
 | 
					use crate::components::wifi::wifi_address_entry;
 | 
				
			||||||
use adw::{EntryRow, ExpanderRow};
 | 
					use adw::{EntryRow, ExpanderRow};
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, Button, CompositeTemplate};
 | 
					use gtk::{Button, CompositeTemplate};
 | 
				
			||||||
use std::cell::{Cell, RefCell};
 | 
					use std::cell::{Cell, RefCell};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default, CompositeTemplate)]
 | 
					#[derive(Default, CompositeTemplate)]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,21 +4,23 @@ use std::sync::Arc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use std::time::Duration;
 | 
					use std::time::Duration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::base::error_impl::{show_error, ReSetErrorImpl};
 | 
				
			||||||
use crate::components::base::utils::Listeners;
 | 
					use crate::components::base::utils::Listeners;
 | 
				
			||||||
use crate::components::utils::{set_combo_row_ellipsis, BASE, DBUS_PATH, WIRELESS};
 | 
					use crate::components::utils::{set_combo_row_ellipsis, BASE, DBUS_PATH, WIRELESS};
 | 
				
			||||||
use adw::glib;
 | 
					 | 
				
			||||||
use adw::glib::Object;
 | 
					use adw::glib::Object;
 | 
				
			||||||
use adw::prelude::{ComboRowExt, ListBoxRowExt, PreferencesGroupExt, PreferencesRowExt};
 | 
					use adw::prelude::{ComboRowExt, ListBoxRowExt, PreferencesGroupExt};
 | 
				
			||||||
use adw::subclass::prelude::ObjectSubclassIsExt;
 | 
					use adw::subclass::prelude::ObjectSubclassIsExt;
 | 
				
			||||||
use dbus::blocking::Connection;
 | 
					use dbus::blocking::Connection;
 | 
				
			||||||
use dbus::message::SignalArgs;
 | 
					use dbus::message::SignalArgs;
 | 
				
			||||||
use dbus::Error;
 | 
					use dbus::Error;
 | 
				
			||||||
use dbus::Path;
 | 
					use dbus::Path;
 | 
				
			||||||
use glib::{clone, Cast, PropertySet};
 | 
					use glib::{clone, ControlFlow};
 | 
				
			||||||
 | 
					use glib::prelude::Cast;
 | 
				
			||||||
 | 
					use glib::property::PropertySet;
 | 
				
			||||||
use gtk::glib::Variant;
 | 
					use gtk::glib::Variant;
 | 
				
			||||||
use gtk::prelude::{ActionableExt, WidgetExt};
 | 
					use gtk::prelude::ActionableExt;
 | 
				
			||||||
use gtk::{gio, StringList, StringObject};
 | 
					use gtk::{gio, StringList, StringObject};
 | 
				
			||||||
use re_set_lib::network::network_structures::{AccessPoint, WifiDevice, WifiStrength};
 | 
					use re_set_lib::network::network_structures::{AccessPoint, WifiDevice};
 | 
				
			||||||
use re_set_lib::signals::{AccessPointAdded, WifiDeviceChanged, WifiDeviceReset};
 | 
					use re_set_lib::signals::{AccessPointAdded, WifiDeviceChanged, WifiDeviceReset};
 | 
				
			||||||
use re_set_lib::signals::{AccessPointChanged, AccessPointRemoved};
 | 
					use re_set_lib::signals::{AccessPointChanged, AccessPointRemoved};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,6 +28,10 @@ use crate::components::wifi::wifi_box_impl;
 | 
				
			||||||
use crate::components::wifi::wifi_entry::WifiEntry;
 | 
					use crate::components::wifi::wifi_entry::WifiEntry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::saved_wifi_entry::SavedWifiEntry;
 | 
					use super::saved_wifi_entry::SavedWifiEntry;
 | 
				
			||||||
 | 
					use super::wifi_event_handlers::{
 | 
				
			||||||
 | 
					    access_point_added_handler, access_point_changed_handler, access_point_removed_handler,
 | 
				
			||||||
 | 
					    wifi_device_changed_handler, wifi_device_reset_handler,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
glib::wrapper! {
 | 
					glib::wrapper! {
 | 
				
			||||||
    pub struct WifiBox(ObjectSubclass<wifi_box_impl::WifiBox>)
 | 
					    pub struct WifiBox(ObjectSubclass<wifi_box_impl::WifiBox>)
 | 
				
			||||||
| 
						 | 
					@ -38,6 +44,14 @@ type ResultMap = Result<(Vec<(Path<'static>, Vec<u8>)>,), Error>;
 | 
				
			||||||
unsafe impl Send for WifiBox {}
 | 
					unsafe impl Send for WifiBox {}
 | 
				
			||||||
unsafe impl Sync for WifiBox {}
 | 
					unsafe impl Sync for WifiBox {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl ReSetErrorImpl for WifiBox {
 | 
				
			||||||
 | 
					    fn error(
 | 
				
			||||||
 | 
					        &self,
 | 
				
			||||||
 | 
					    ) -> >k::subclass::prelude::TemplateChild<crate::components::base::error::ReSetError> {
 | 
				
			||||||
 | 
					        &self.imp().error
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl WifiBox {
 | 
					impl WifiBox {
 | 
				
			||||||
    pub fn new(listeners: Arc<Listeners>) -> Arc<Self> {
 | 
					    pub fn new(listeners: Arc<Listeners>) -> Arc<Self> {
 | 
				
			||||||
        let obj: Arc<WifiBox> = Arc::new(Object::builder().build());
 | 
					        let obj: Arc<WifiBox> = Arc::new(Object::builder().build());
 | 
				
			||||||
| 
						 | 
					@ -50,6 +64,7 @@ impl WifiBox {
 | 
				
			||||||
fn setup_callbacks(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) -> Arc<WifiBox> {
 | 
					fn setup_callbacks(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) -> Arc<WifiBox> {
 | 
				
			||||||
    let imp = wifi_box.imp();
 | 
					    let imp = wifi_box.imp();
 | 
				
			||||||
    let wifibox_ref = wifi_box.clone();
 | 
					    let wifibox_ref = wifi_box.clone();
 | 
				
			||||||
 | 
					    let wifibox_ref_switch = wifi_box.clone();
 | 
				
			||||||
    imp.reset_switch_initial.set(true);
 | 
					    imp.reset_switch_initial.set(true);
 | 
				
			||||||
    imp.reset_saved_networks.set_activatable(true);
 | 
					    imp.reset_saved_networks.set_activatable(true);
 | 
				
			||||||
    imp.reset_saved_networks
 | 
					    imp.reset_saved_networks
 | 
				
			||||||
| 
						 | 
					@ -66,7 +81,7 @@ fn setup_callbacks(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) -> Arc<Wif
 | 
				
			||||||
            if imp.reset_switch_initial.load(Ordering::SeqCst) {
 | 
					            if imp.reset_switch_initial.load(Ordering::SeqCst) {
 | 
				
			||||||
                return glib::Propagation::Proceed;
 | 
					                return glib::Propagation::Proceed;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            set_wifi_enabled(value);
 | 
					            set_wifi_enabled(value, wifibox_ref_switch.clone());
 | 
				
			||||||
            if !value {
 | 
					            if !value {
 | 
				
			||||||
                imp.reset_wifi_devices.write().unwrap().clear();
 | 
					                imp.reset_wifi_devices.write().unwrap().clear();
 | 
				
			||||||
                *imp.reset_model_list.write().unwrap() = StringList::new(&[]);
 | 
					                *imp.reset_model_list.write().unwrap() = StringList::new(&[]);
 | 
				
			||||||
| 
						 | 
					@ -92,17 +107,16 @@ fn setup_callbacks(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) -> Arc<Wif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn scan_for_wifi(wifi_box: Arc<WifiBox>) {
 | 
					pub fn scan_for_wifi(wifi_box: Arc<WifiBox>) {
 | 
				
			||||||
    let wifibox_ref = wifi_box.clone();
 | 
					    let wifibox_ref = wifi_box.clone();
 | 
				
			||||||
    let _wifibox_ref_listener = wifi_box.clone();
 | 
					 | 
				
			||||||
    let wifi_entries = wifi_box.imp().wifi_entries.clone();
 | 
					    let wifi_entries = wifi_box.imp().wifi_entries.clone();
 | 
				
			||||||
    let wifi_entries_path = wifi_box.imp().wifi_entries_path.clone();
 | 
					    let wifi_entries_path = wifi_box.imp().wifi_entries_path.clone();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
        let wifi_status = get_wifi_status();
 | 
					        let wifi_status = get_wifi_status(wifibox_ref.clone());
 | 
				
			||||||
        let devices = get_wifi_devices();
 | 
					        let devices = get_wifi_devices(wifibox_ref.clone());
 | 
				
			||||||
        if devices.is_empty() {
 | 
					        if devices.is_empty() {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        let access_points = get_access_points();
 | 
					        let access_points = get_access_points(wifibox_ref.clone());
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            let imp = wifibox_ref.imp();
 | 
					            let imp = wifibox_ref.imp();
 | 
				
			||||||
            let list = imp.reset_model_list.write().unwrap();
 | 
					            let list = imp.reset_model_list.write().unwrap();
 | 
				
			||||||
| 
						 | 
					@ -118,7 +132,7 @@ pub fn scan_for_wifi(wifi_box: Arc<WifiBox>) {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        let wifi_entries = wifi_entries.clone();
 | 
					        let wifi_entries = wifi_entries.clone();
 | 
				
			||||||
        let wifi_entries_path = wifi_entries_path.clone();
 | 
					        let wifi_entries_path = wifi_entries_path.clone();
 | 
				
			||||||
        dbus_start_network_events();
 | 
					        dbus_start_network_events(wifibox_ref.clone());
 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					        glib::spawn_future(async move {
 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					            glib::idle_add_once(move || {
 | 
				
			||||||
                let mut wifi_entries = wifi_entries.write().unwrap();
 | 
					                let mut wifi_entries = wifi_entries.write().unwrap();
 | 
				
			||||||
| 
						 | 
					@ -139,24 +153,11 @@ pub fn scan_for_wifi(wifi_box: Arc<WifiBox>) {
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                imp.reset_wifi_device.connect_selected_notify(
 | 
					                let device_changed_ref = wifibox_ref.clone();
 | 
				
			||||||
                    clone!(@weak imp => move |dropdown| {
 | 
					                imp.reset_wifi_device
 | 
				
			||||||
                        let selected = dropdown.selected_item();
 | 
					                    .connect_selected_notify(move |dropdown| {
 | 
				
			||||||
                        if selected.is_none() {
 | 
					                        select_wifi_device_handler(dropdown, device_changed_ref.clone());
 | 
				
			||||||
                            return;
 | 
					                    });
 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        let selected = selected.unwrap();
 | 
					 | 
				
			||||||
                        let selected = selected.downcast_ref::<StringObject>().unwrap();
 | 
					 | 
				
			||||||
                        let selected = selected.string().to_string();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        let device = imp.reset_wifi_devices.read().unwrap();
 | 
					 | 
				
			||||||
                        let device = device.get(&selected);
 | 
					 | 
				
			||||||
                        if device.is_none() {
 | 
					 | 
				
			||||||
                            return;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        set_wifi_device(device.unwrap().0.path.clone());
 | 
					 | 
				
			||||||
                    }),
 | 
					 | 
				
			||||||
                );
 | 
					 | 
				
			||||||
                for access_point in access_points {
 | 
					                for access_point in access_points {
 | 
				
			||||||
                    if access_point.ssid.is_empty() {
 | 
					                    if access_point.ssid.is_empty() {
 | 
				
			||||||
                        continue;
 | 
					                        continue;
 | 
				
			||||||
| 
						 | 
					@ -175,10 +176,29 @@ pub fn scan_for_wifi(wifi_box: Arc<WifiBox>) {
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn select_wifi_device_handler(dropdown: &adw::ComboRow, wifi_box: Arc<WifiBox>) -> ControlFlow {
 | 
				
			||||||
 | 
					    let selected = dropdown.selected_item();
 | 
				
			||||||
 | 
					    if selected.is_none() {
 | 
				
			||||||
 | 
					        return ControlFlow::Break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let selected = selected.unwrap();
 | 
				
			||||||
 | 
					    let selected = selected.downcast_ref::<StringObject>().unwrap();
 | 
				
			||||||
 | 
					    let selected = selected.string().to_string();
 | 
				
			||||||
 | 
					    let imp = wifi_box.imp();
 | 
				
			||||||
 | 
					    let device = imp.reset_wifi_devices.read().unwrap();
 | 
				
			||||||
 | 
					    let device = device.get(&selected);
 | 
				
			||||||
 | 
					    if device.is_none() {
 | 
				
			||||||
 | 
					        return ControlFlow::Break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    set_wifi_device(device.unwrap().0.path.clone(), wifi_box.clone());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ControlFlow::Continue
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn show_stored_connections(wifi_box: Arc<WifiBox>) {
 | 
					pub fn show_stored_connections(wifi_box: Arc<WifiBox>) {
 | 
				
			||||||
    let wifibox_ref = wifi_box.clone();
 | 
					    let wifibox_ref = wifi_box.clone();
 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
        let connections = get_stored_connections();
 | 
					        let connections = get_stored_connections(wifi_box.clone());
 | 
				
			||||||
        glib::spawn_future(async move {
 | 
					        glib::spawn_future(async move {
 | 
				
			||||||
            glib::idle_add_once(move || {
 | 
					            glib::idle_add_once(move || {
 | 
				
			||||||
                let self_imp = wifibox_ref.imp();
 | 
					                let self_imp = wifibox_ref.imp();
 | 
				
			||||||
| 
						 | 
					@ -194,67 +214,80 @@ pub fn show_stored_connections(wifi_box: Arc<WifiBox>) {
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn dbus_start_network_events() {
 | 
					pub fn dbus_start_network_events(wifi_box: Arc<WifiBox>) {
 | 
				
			||||||
    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 _: Result<(), Error> = proxy.method_call(WIRELESS, "StartNetworkListener", ());
 | 
					    let res: Result<(), Error> = proxy.method_call(WIRELESS, "StartNetworkListener", ());
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<WifiBox>(wifi_box.clone(), "Failed to start Network listener");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn get_access_points() -> Vec<AccessPoint> {
 | 
					pub fn get_access_points(wifi_box: Arc<WifiBox>) -> Vec<AccessPoint> {
 | 
				
			||||||
    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<(Vec<AccessPoint>,), Error> =
 | 
					    let res: Result<(Vec<AccessPoint>,), Error> =
 | 
				
			||||||
        proxy.method_call(WIRELESS, "ListAccessPoints", ());
 | 
					        proxy.method_call(WIRELESS, "ListAccessPoints", ());
 | 
				
			||||||
    if res.is_err() {
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<WifiBox>(wifi_box.clone(), "Failed to list access points");
 | 
				
			||||||
        return Vec::new();
 | 
					        return Vec::new();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    let (access_points,) = res.unwrap();
 | 
					    let (access_points,) = res.unwrap();
 | 
				
			||||||
    access_points
 | 
					    access_points
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn set_wifi_device(path: Path<'static>) {
 | 
					pub fn set_wifi_device(path: Path<'static>, wifi_box: Arc<WifiBox>) {
 | 
				
			||||||
    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 _: Result<(bool,), Error> = proxy.method_call(WIRELESS, "SetWifiDevice", (path,));
 | 
					    let res: Result<(bool,), Error> = proxy.method_call(WIRELESS, "SetWifiDevice", (path,));
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<WifiBox>(wifi_box.clone(), "Failed to set WiFi devices");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn get_wifi_devices() -> Vec<WifiDevice> {
 | 
					pub fn get_wifi_devices(wifi_box: Arc<WifiBox>) -> Vec<WifiDevice> {
 | 
				
			||||||
    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<(Vec<WifiDevice>,), Error> =
 | 
					    let res: Result<(Vec<WifiDevice>,), Error> =
 | 
				
			||||||
        proxy.method_call(WIRELESS, "GetAllWifiDevices", ());
 | 
					        proxy.method_call(WIRELESS, "GetAllWifiDevices", ());
 | 
				
			||||||
    if res.is_err() {
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<WifiBox>(wifi_box.clone(), "Failed to get WiFi devices");
 | 
				
			||||||
        return Vec::new();
 | 
					        return Vec::new();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    let (devices,) = res.unwrap();
 | 
					    let (devices,) = res.unwrap();
 | 
				
			||||||
    devices
 | 
					    devices
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn get_wifi_status() -> bool {
 | 
					pub fn get_wifi_status(wifi_box: Arc<WifiBox>) -> bool {
 | 
				
			||||||
    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<(bool,), Error> = proxy.method_call(WIRELESS, "GetWifiStatus", ());
 | 
					    let res: Result<(bool,), Error> = proxy.method_call(WIRELESS, "GetWifiStatus", ());
 | 
				
			||||||
    if res.is_err() {
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<WifiBox>(wifi_box.clone(), "Failed to get WiFi status");
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    res.unwrap().0
 | 
					    res.unwrap().0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn get_stored_connections() -> Vec<(Path<'static>, Vec<u8>)> {
 | 
					pub fn get_stored_connections(wifi_box: Arc<WifiBox>) -> Vec<(Path<'static>, Vec<u8>)> {
 | 
				
			||||||
    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: ResultMap = proxy.method_call(WIRELESS, "ListStoredConnections", ());
 | 
					    let res: ResultMap = proxy.method_call(WIRELESS, "ListStoredConnections", ());
 | 
				
			||||||
    if res.is_err() {
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<WifiBox>(wifi_box.clone(), "Failed to list stored connections");
 | 
				
			||||||
        return Vec::new();
 | 
					        return Vec::new();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    let (connections,) = res.unwrap();
 | 
					    let (connections,) = res.unwrap();
 | 
				
			||||||
    connections
 | 
					    connections
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn set_wifi_enabled(enabled: bool) {
 | 
					pub fn set_wifi_enabled(enabled: bool, wifi_box: Arc<WifiBox>) {
 | 
				
			||||||
    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 _: Result<(bool,), Error> = proxy.method_call(WIRELESS, "SetWifiEnabled", (enabled,));
 | 
					    let res: Result<(bool,), Error> = proxy.method_call(WIRELESS, "SetWifiEnabled", (enabled,));
 | 
				
			||||||
 | 
					    if res.is_err() {
 | 
				
			||||||
 | 
					        show_error::<WifiBox>(wifi_box.clone(), "Failed to enable WiFi");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
 | 
					pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
 | 
				
			||||||
| 
						 | 
					@ -288,176 +321,35 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
 | 
				
			||||||
            WifiDeviceReset::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
 | 
					            WifiDeviceReset::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
 | 
				
			||||||
                .static_clone();
 | 
					                .static_clone();
 | 
				
			||||||
        let res = conn.add_match(access_point_added, move |ir: AccessPointAdded, _, _| {
 | 
					        let res = conn.add_match(access_point_added, move |ir: AccessPointAdded, _, _| {
 | 
				
			||||||
            let wifi_box = added_ref.clone();
 | 
					            access_point_added_handler(added_ref.clone(), ir)
 | 
				
			||||||
            glib::spawn_future(async move {
 | 
					 | 
				
			||||||
                glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                    let imp = wifi_box.imp();
 | 
					 | 
				
			||||||
                    let mut wifi_entries = imp.wifi_entries.write().unwrap();
 | 
					 | 
				
			||||||
                    let mut wifi_entries_path = imp.wifi_entries_path.write().unwrap();
 | 
					 | 
				
			||||||
                    let ssid = ir.access_point.ssid.clone();
 | 
					 | 
				
			||||||
                    let path = ir.access_point.dbus_path.clone();
 | 
					 | 
				
			||||||
                    if wifi_entries.get(&ssid).is_some() || ssid.is_empty() {
 | 
					 | 
				
			||||||
                        return;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    let connected = imp.reset_current_wifi_device.borrow().active_access_point
 | 
					 | 
				
			||||||
                        == ir.access_point.ssid;
 | 
					 | 
				
			||||||
                    let entry = WifiEntry::new(connected, ir.access_point, imp);
 | 
					 | 
				
			||||||
                    wifi_entries.insert(ssid, entry.clone());
 | 
					 | 
				
			||||||
                    wifi_entries_path.insert(path, entry.clone());
 | 
					 | 
				
			||||||
                    imp.reset_wifi_list.add(&*entry);
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            true
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
            println!("fail on access point add event");
 | 
					            println!("fail on access point add event");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        let res = conn.add_match(access_point_removed, move |ir: AccessPointRemoved, _, _| {
 | 
					        let res = conn.add_match(access_point_removed, move |ir: AccessPointRemoved, _, _| {
 | 
				
			||||||
            let wifi_box = removed_ref.clone();
 | 
					            access_point_removed_handler(removed_ref.clone(), ir)
 | 
				
			||||||
            glib::spawn_future(async move {
 | 
					 | 
				
			||||||
                glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                    let imp = wifi_box.imp();
 | 
					 | 
				
			||||||
                    let mut wifi_entries = imp.wifi_entries.write().unwrap();
 | 
					 | 
				
			||||||
                    let mut wifi_entries_path = imp.wifi_entries_path.write().unwrap();
 | 
					 | 
				
			||||||
                    let entry = wifi_entries_path.remove(&ir.access_point);
 | 
					 | 
				
			||||||
                    if entry.is_none() {
 | 
					 | 
				
			||||||
                        return;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    let entry = entry.unwrap();
 | 
					 | 
				
			||||||
                    let ssid = entry.imp().access_point.borrow().ssid.clone();
 | 
					 | 
				
			||||||
                    wifi_entries.remove(&ssid);
 | 
					 | 
				
			||||||
                    imp.reset_wifi_list.remove(&*entry);
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            true
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
            println!("fail on access point remove event");
 | 
					            println!("fail on access point remove event");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        let res = conn.add_match(access_point_changed, move |ir: AccessPointChanged, _, _| {
 | 
					        let res = conn.add_match(access_point_changed, move |ir: AccessPointChanged, _, _| {
 | 
				
			||||||
            let wifi_box = changed_ref.clone();
 | 
					            access_point_changed_handler(changed_ref.clone(), ir)
 | 
				
			||||||
            glib::spawn_future(async move {
 | 
					 | 
				
			||||||
                glib::idle_add_local_once(move || {
 | 
					 | 
				
			||||||
                    let imp = wifi_box.imp();
 | 
					 | 
				
			||||||
                    let wifi_entries = imp.wifi_entries.read().unwrap();
 | 
					 | 
				
			||||||
                    let entry = wifi_entries.get(&ir.access_point.ssid);
 | 
					 | 
				
			||||||
                    if entry.is_none() {
 | 
					 | 
				
			||||||
                        return;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    let entry = entry.unwrap();
 | 
					 | 
				
			||||||
                    let entry_imp = entry.imp();
 | 
					 | 
				
			||||||
                    let strength = WifiStrength::from_u8(ir.access_point.strength);
 | 
					 | 
				
			||||||
                    let ssid = ir.access_point.ssid.clone();
 | 
					 | 
				
			||||||
                    let name_opt = String::from_utf8(ssid).unwrap_or_else(|_| String::from(""));
 | 
					 | 
				
			||||||
                    let name = name_opt.as_str();
 | 
					 | 
				
			||||||
                    entry_imp.wifi_strength.set(strength);
 | 
					 | 
				
			||||||
                    entry.set_title(name);
 | 
					 | 
				
			||||||
                    // TODO handle encryption thing
 | 
					 | 
				
			||||||
                    entry_imp
 | 
					 | 
				
			||||||
                        .reset_wifi_strength
 | 
					 | 
				
			||||||
                        .borrow()
 | 
					 | 
				
			||||||
                        .set_from_icon_name(match strength {
 | 
					 | 
				
			||||||
                            WifiStrength::Excellent => {
 | 
					 | 
				
			||||||
                                Some("network-wireless-signal-excellent-symbolic")
 | 
					 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                            WifiStrength::Ok => Some("network-wireless-signal-ok-symbolic"),
 | 
					 | 
				
			||||||
                            WifiStrength::Weak => Some("network-wireless-signal-weak-symbolic"),
 | 
					 | 
				
			||||||
                            WifiStrength::None => Some("network-wireless-signal-none-symbolic"),
 | 
					 | 
				
			||||||
                        });
 | 
					 | 
				
			||||||
                    if !ir.access_point.stored {
 | 
					 | 
				
			||||||
                        entry_imp
 | 
					 | 
				
			||||||
                            .reset_wifi_edit_button
 | 
					 | 
				
			||||||
                            .borrow()
 | 
					 | 
				
			||||||
                            .set_sensitive(false);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    if ir.access_point.ssid
 | 
					 | 
				
			||||||
                        == imp.reset_current_wifi_device.borrow().active_access_point
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        entry_imp
 | 
					 | 
				
			||||||
                            .reset_wifi_connected
 | 
					 | 
				
			||||||
                            .borrow()
 | 
					 | 
				
			||||||
                            .set_text("Connected");
 | 
					 | 
				
			||||||
                    } else {
 | 
					 | 
				
			||||||
                        entry_imp.reset_wifi_connected.borrow().set_text("");
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        let mut wifi_name = entry_imp.wifi_name.borrow_mut();
 | 
					 | 
				
			||||||
                        *wifi_name = String::from(name);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            true
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
            println!("fail on access point change event");
 | 
					            println!("fail on access point change event");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        let res = conn.add_match(device_changed, move |ir: WifiDeviceChanged, _, _| {
 | 
					        let res = conn.add_match(device_changed, move |ir: WifiDeviceChanged, _, _| {
 | 
				
			||||||
            let wifi_box = wifi_changed_ref.clone();
 | 
					            wifi_device_changed_handler(wifi_changed_ref.clone(), ir)
 | 
				
			||||||
            glib::spawn_future(async move {
 | 
					 | 
				
			||||||
                glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                    let imp = wifi_box.imp();
 | 
					 | 
				
			||||||
                    let mut current_device = imp.reset_current_wifi_device.borrow_mut();
 | 
					 | 
				
			||||||
                    if current_device.path == ir.wifi_device.path {
 | 
					 | 
				
			||||||
                        current_device.active_access_point = ir.wifi_device.active_access_point;
 | 
					 | 
				
			||||||
                    } else {
 | 
					 | 
				
			||||||
                        *current_device = ir.wifi_device;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    let mut wifi_entries = imp.wifi_entries.write().unwrap();
 | 
					 | 
				
			||||||
                    for entry in wifi_entries.iter_mut() {
 | 
					 | 
				
			||||||
                        let imp = entry.1.imp();
 | 
					 | 
				
			||||||
                        let mut connected = imp.connected.borrow_mut();
 | 
					 | 
				
			||||||
                        *connected =
 | 
					 | 
				
			||||||
                            imp.access_point.borrow().ssid == current_device.active_access_point;
 | 
					 | 
				
			||||||
                        if *connected {
 | 
					 | 
				
			||||||
                            imp.reset_wifi_connected.borrow().set_text("Connected");
 | 
					 | 
				
			||||||
                        } else {
 | 
					 | 
				
			||||||
                            imp.reset_wifi_connected.borrow().set_text("");
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            true
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
            println!("fail on wifi device change event");
 | 
					            println!("fail on wifi device change event");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        let res = conn.add_match(devices_reset, move |ir: WifiDeviceReset, _, _| {
 | 
					        let res = conn.add_match(devices_reset, move |ir: WifiDeviceReset, _, _| {
 | 
				
			||||||
            if ir.devices.is_empty() {
 | 
					            wifi_device_reset_handler(wifi_reset_ref.clone(), ir)
 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                let imp = wifi_reset_ref.imp();
 | 
					 | 
				
			||||||
                let list = imp.reset_model_list.write().unwrap();
 | 
					 | 
				
			||||||
                let mut model_index = imp.reset_model_index.write().unwrap();
 | 
					 | 
				
			||||||
                let mut map = imp.reset_wifi_devices.write().unwrap();
 | 
					 | 
				
			||||||
                imp.reset_current_wifi_device
 | 
					 | 
				
			||||||
                    .replace(ir.devices.last().unwrap().clone());
 | 
					 | 
				
			||||||
                for (index, device) in ir.devices.into_iter().enumerate() {
 | 
					 | 
				
			||||||
                    list.append(&device.name);
 | 
					 | 
				
			||||||
                    map.insert(device.name.clone(), (device, index as u32));
 | 
					 | 
				
			||||||
                    *model_index += 1;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            let wifi_box = wifi_reset_ref.clone();
 | 
					 | 
				
			||||||
            glib::spawn_future(async move {
 | 
					 | 
				
			||||||
                glib::idle_add_once(move || {
 | 
					 | 
				
			||||||
                    let imp = wifi_box.imp();
 | 
					 | 
				
			||||||
                    let list = imp.reset_model_list.read().unwrap();
 | 
					 | 
				
			||||||
                    imp.reset_wifi_device.set_model(Some(&*list));
 | 
					 | 
				
			||||||
                    let map = imp.reset_wifi_devices.read().unwrap();
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        let device = imp.reset_current_wifi_device.borrow();
 | 
					 | 
				
			||||||
                        if let Some(index) = map.get(&device.name) {
 | 
					 | 
				
			||||||
                            imp.reset_wifi_device.set_selected(index.1);
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            true
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        if res.is_err() {
 | 
					        if res.is_err() {
 | 
				
			||||||
            println!("fail on wifi device change event");
 | 
					            println!("fail on wifi device change event");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,10 @@
 | 
				
			||||||
 | 
					use crate::components::base::error::ReSetError;
 | 
				
			||||||
use crate::components::wifi::wifi_box;
 | 
					use crate::components::wifi::wifi_box;
 | 
				
			||||||
use adw::{ActionRow, ComboRow, NavigationView, PreferencesGroup};
 | 
					use adw::{ActionRow, ComboRow, NavigationView, PreferencesGroup};
 | 
				
			||||||
use dbus::Path;
 | 
					use dbus::Path;
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, CompositeTemplate, Switch};
 | 
					 | 
				
			||||||
use gtk::{prelude::*, StringList};
 | 
					use gtk::{prelude::*, StringList};
 | 
				
			||||||
 | 
					use gtk::{CompositeTemplate, Switch};
 | 
				
			||||||
use re_set_lib::network::network_structures::WifiDevice;
 | 
					use re_set_lib::network::network_structures::WifiDevice;
 | 
				
			||||||
use std::cell::RefCell;
 | 
					use std::cell::RefCell;
 | 
				
			||||||
use std::collections::HashMap;
 | 
					use std::collections::HashMap;
 | 
				
			||||||
| 
						 | 
					@ -32,6 +33,8 @@ pub struct WifiBox {
 | 
				
			||||||
    pub reset_stored_wifi_list: TemplateChild<PreferencesGroup>,
 | 
					    pub reset_stored_wifi_list: TemplateChild<PreferencesGroup>,
 | 
				
			||||||
    #[template_child]
 | 
					    #[template_child]
 | 
				
			||||||
    pub reset_available_networks: TemplateChild<ActionRow>,
 | 
					    pub reset_available_networks: TemplateChild<ActionRow>,
 | 
				
			||||||
 | 
					    #[template_child]
 | 
				
			||||||
 | 
					    pub error: TemplateChild<ReSetError>,
 | 
				
			||||||
    pub wifi_entries: Arc<RwLock<HashMap<Vec<u8>, Arc<WifiEntry>>>>,
 | 
					    pub wifi_entries: Arc<RwLock<HashMap<Vec<u8>, Arc<WifiEntry>>>>,
 | 
				
			||||||
    pub wifi_entries_path: Arc<RwLock<HashMap<Path<'static>, Arc<WifiEntry>>>>,
 | 
					    pub wifi_entries_path: Arc<RwLock<HashMap<Path<'static>, Arc<WifiEntry>>>>,
 | 
				
			||||||
    pub reset_wifi_devices: Arc<RwLock<HashMap<String, (WifiDevice, u32)>>>,
 | 
					    pub reset_wifi_devices: Arc<RwLock<HashMap<String, (WifiDevice, u32)>>>,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,13 +4,13 @@ use std::time::Duration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::components::utils::{BASE, DBUS_PATH, WIRELESS};
 | 
					use crate::components::utils::{BASE, DBUS_PATH, WIRELESS};
 | 
				
			||||||
use crate::components::wifi::utils::get_connection_settings;
 | 
					use crate::components::wifi::utils::get_connection_settings;
 | 
				
			||||||
use adw::glib;
 | 
					use adw::glib::{Object};
 | 
				
			||||||
use adw::glib::{Object, PropertySet};
 | 
					 | 
				
			||||||
use adw::prelude::{ActionRowExt, ButtonExt, EditableExt, PopoverExt, PreferencesRowExt};
 | 
					use adw::prelude::{ActionRowExt, ButtonExt, EditableExt, PopoverExt, PreferencesRowExt};
 | 
				
			||||||
use adw::subclass::prelude::ObjectSubclassIsExt;
 | 
					use adw::subclass::prelude::ObjectSubclassIsExt;
 | 
				
			||||||
use dbus::blocking::Connection;
 | 
					use dbus::blocking::Connection;
 | 
				
			||||||
use dbus::Error;
 | 
					use dbus::Error;
 | 
				
			||||||
use glib::clone;
 | 
					use glib::clone;
 | 
				
			||||||
 | 
					use glib::property::PropertySet;
 | 
				
			||||||
use gtk::prelude::{BoxExt, ListBoxRowExt, WidgetExt};
 | 
					use gtk::prelude::{BoxExt, ListBoxRowExt, WidgetExt};
 | 
				
			||||||
use gtk::{gio, Align, Button, Image, Orientation};
 | 
					use gtk::{gio, Align, Button, Image, Orientation};
 | 
				
			||||||
use re_set_lib::network::network_structures::{AccessPoint, WifiStrength};
 | 
					use re_set_lib::network::network_structures::{AccessPoint, WifiStrength};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@ use adw::subclass::preferences_row::PreferencesRowImpl;
 | 
				
			||||||
use adw::subclass::prelude::ActionRowImpl;
 | 
					use adw::subclass::prelude::ActionRowImpl;
 | 
				
			||||||
use adw::ActionRow;
 | 
					use adw::ActionRow;
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, Button, CompositeTemplate, Image, Label};
 | 
					use gtk::{Button, CompositeTemplate, Image, Label};
 | 
				
			||||||
use re_set_lib::network::network_structures::{AccessPoint, WifiStrength};
 | 
					use re_set_lib::network::network_structures::{AccessPoint, WifiStrength};
 | 
				
			||||||
use std::cell::RefCell;
 | 
					use std::cell::RefCell;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										166
									
								
								src/components/wifi/wifi_event_handlers.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										166
									
								
								src/components/wifi/wifi_event_handlers.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,166 @@
 | 
				
			||||||
 | 
					use std::sync::Arc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use adw::prelude::{ComboRowExt, PreferencesGroupExt, PreferencesRowExt};
 | 
				
			||||||
 | 
					use glib::{subclass::types::ObjectSubclassIsExt};
 | 
				
			||||||
 | 
					use glib::property::PropertySet;
 | 
				
			||||||
 | 
					use gtk::prelude::WidgetExt;
 | 
				
			||||||
 | 
					use re_set_lib::{
 | 
				
			||||||
 | 
					    network::network_structures::WifiStrength,
 | 
				
			||||||
 | 
					    signals::{
 | 
				
			||||||
 | 
					        AccessPointAdded, AccessPointChanged, AccessPointRemoved, WifiDeviceChanged,
 | 
				
			||||||
 | 
					        WifiDeviceReset,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::{wifi_box::WifiBox, wifi_entry::WifiEntry};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn access_point_added_handler(wifi_box: Arc<WifiBox>, ir: AccessPointAdded) -> bool {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let imp = wifi_box.imp();
 | 
				
			||||||
 | 
					            let mut wifi_entries = imp.wifi_entries.write().unwrap();
 | 
				
			||||||
 | 
					            let mut wifi_entries_path = imp.wifi_entries_path.write().unwrap();
 | 
				
			||||||
 | 
					            let ssid = ir.access_point.ssid.clone();
 | 
				
			||||||
 | 
					            let path = ir.access_point.dbus_path.clone();
 | 
				
			||||||
 | 
					            if wifi_entries.get(&ssid).is_some() || ssid.is_empty() {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let connected =
 | 
				
			||||||
 | 
					                imp.reset_current_wifi_device.borrow().active_access_point == ir.access_point.ssid;
 | 
				
			||||||
 | 
					            let entry = WifiEntry::new(connected, ir.access_point, imp);
 | 
				
			||||||
 | 
					            wifi_entries.insert(ssid, entry.clone());
 | 
				
			||||||
 | 
					            wifi_entries_path.insert(path, entry.clone());
 | 
				
			||||||
 | 
					            imp.reset_wifi_list.add(&*entry);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn access_point_removed_handler(wifi_box: Arc<WifiBox>, ir: AccessPointRemoved) -> bool {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let imp = wifi_box.imp();
 | 
				
			||||||
 | 
					            let mut wifi_entries = imp.wifi_entries.write().unwrap();
 | 
				
			||||||
 | 
					            let mut wifi_entries_path = imp.wifi_entries_path.write().unwrap();
 | 
				
			||||||
 | 
					            let entry = wifi_entries_path.remove(&ir.access_point);
 | 
				
			||||||
 | 
					            if entry.is_none() {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let entry = entry.unwrap();
 | 
				
			||||||
 | 
					            let ssid = entry.imp().access_point.borrow().ssid.clone();
 | 
				
			||||||
 | 
					            wifi_entries.remove(&ssid);
 | 
				
			||||||
 | 
					            imp.reset_wifi_list.remove(&*entry);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn access_point_changed_handler(wifi_box: Arc<WifiBox>, ir: AccessPointChanged) -> bool {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_local_once(move || {
 | 
				
			||||||
 | 
					            let imp = wifi_box.imp();
 | 
				
			||||||
 | 
					            let wifi_entries = imp.wifi_entries.read().unwrap();
 | 
				
			||||||
 | 
					            let entry = wifi_entries.get(&ir.access_point.ssid);
 | 
				
			||||||
 | 
					            if entry.is_none() {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let entry = entry.unwrap();
 | 
				
			||||||
 | 
					            let entry_imp = entry.imp();
 | 
				
			||||||
 | 
					            let strength = WifiStrength::from_u8(ir.access_point.strength);
 | 
				
			||||||
 | 
					            let ssid = ir.access_point.ssid.clone();
 | 
				
			||||||
 | 
					            let name_opt = String::from_utf8(ssid).unwrap_or_else(|_| String::from(""));
 | 
				
			||||||
 | 
					            let name = name_opt.as_str();
 | 
				
			||||||
 | 
					            entry_imp.wifi_strength.set(strength);
 | 
				
			||||||
 | 
					            entry.set_title(name);
 | 
				
			||||||
 | 
					            // TODO handle encryption thing
 | 
				
			||||||
 | 
					            entry_imp
 | 
				
			||||||
 | 
					                .reset_wifi_strength
 | 
				
			||||||
 | 
					                .borrow()
 | 
				
			||||||
 | 
					                .set_from_icon_name(match strength {
 | 
				
			||||||
 | 
					                    WifiStrength::Excellent => Some("network-wireless-signal-excellent-symbolic"),
 | 
				
			||||||
 | 
					                    WifiStrength::Ok => Some("network-wireless-signal-ok-symbolic"),
 | 
				
			||||||
 | 
					                    WifiStrength::Weak => Some("network-wireless-signal-weak-symbolic"),
 | 
				
			||||||
 | 
					                    WifiStrength::None => Some("network-wireless-signal-none-symbolic"),
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            if !ir.access_point.stored {
 | 
				
			||||||
 | 
					                entry_imp
 | 
				
			||||||
 | 
					                    .reset_wifi_edit_button
 | 
				
			||||||
 | 
					                    .borrow()
 | 
				
			||||||
 | 
					                    .set_sensitive(false);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if ir.access_point.ssid == imp.reset_current_wifi_device.borrow().active_access_point {
 | 
				
			||||||
 | 
					                entry_imp
 | 
				
			||||||
 | 
					                    .reset_wifi_connected
 | 
				
			||||||
 | 
					                    .borrow()
 | 
				
			||||||
 | 
					                    .set_text("Connected");
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                entry_imp.reset_wifi_connected.borrow().set_text("");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                let mut wifi_name = entry_imp.wifi_name.borrow_mut();
 | 
				
			||||||
 | 
					                *wifi_name = String::from(name);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn wifi_device_changed_handler(wifi_box: Arc<WifiBox>, ir: WifiDeviceChanged) -> bool {
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let imp = wifi_box.imp();
 | 
				
			||||||
 | 
					            let mut current_device = imp.reset_current_wifi_device.borrow_mut();
 | 
				
			||||||
 | 
					            if current_device.path == ir.wifi_device.path {
 | 
				
			||||||
 | 
					                current_device.active_access_point = ir.wifi_device.active_access_point;
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                *current_device = ir.wifi_device;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let mut wifi_entries = imp.wifi_entries.write().unwrap();
 | 
				
			||||||
 | 
					            for entry in wifi_entries.iter_mut() {
 | 
				
			||||||
 | 
					                let imp = entry.1.imp();
 | 
				
			||||||
 | 
					                let mut connected = imp.connected.borrow_mut();
 | 
				
			||||||
 | 
					                *connected = imp.access_point.borrow().ssid == current_device.active_access_point;
 | 
				
			||||||
 | 
					                if *connected {
 | 
				
			||||||
 | 
					                    imp.reset_wifi_connected.borrow().set_text("Connected");
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    imp.reset_wifi_connected.borrow().set_text("");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn wifi_device_reset_handler(wifi_box: Arc<WifiBox>, ir: WifiDeviceReset) -> bool {
 | 
				
			||||||
 | 
					    if ir.devices.is_empty() {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        let imp = wifi_box.imp();
 | 
				
			||||||
 | 
					        let list = imp.reset_model_list.write().unwrap();
 | 
				
			||||||
 | 
					        let mut model_index = imp.reset_model_index.write().unwrap();
 | 
				
			||||||
 | 
					        let mut map = imp.reset_wifi_devices.write().unwrap();
 | 
				
			||||||
 | 
					        imp.reset_current_wifi_device
 | 
				
			||||||
 | 
					            .replace(ir.devices.last().unwrap().clone());
 | 
				
			||||||
 | 
					        for (index, device) in ir.devices.into_iter().enumerate() {
 | 
				
			||||||
 | 
					            list.append(&device.name);
 | 
				
			||||||
 | 
					            map.insert(device.name.clone(), (device, index as u32));
 | 
				
			||||||
 | 
					            *model_index += 1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    glib::spawn_future(async move {
 | 
				
			||||||
 | 
					        glib::idle_add_once(move || {
 | 
				
			||||||
 | 
					            let imp = wifi_box.imp();
 | 
				
			||||||
 | 
					            let list = imp.reset_model_list.read().unwrap();
 | 
				
			||||||
 | 
					            imp.reset_wifi_device.set_model(Some(&*list));
 | 
				
			||||||
 | 
					            let map = imp.reset_wifi_devices.read().unwrap();
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                let device = imp.reset_current_wifi_device.borrow();
 | 
				
			||||||
 | 
					                if let Some(index) = map.get(&device.name) {
 | 
				
			||||||
 | 
					                    imp.reset_wifi_device.set_selected(index.1);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -4,13 +4,14 @@ use std::str::FromStr;
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
use std::time::Duration;
 | 
					use std::time::Duration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use adw::gio;
 | 
				
			||||||
use adw::glib::Object;
 | 
					use adw::glib::Object;
 | 
				
			||||||
use adw::prelude::{ActionRowExt, ComboRowExt, PreferencesGroupExt};
 | 
					use adw::prelude::{ActionRowExt, ComboRowExt, PreferencesGroupExt};
 | 
				
			||||||
use adw::subclass::prelude::ObjectSubclassIsExt;
 | 
					use adw::subclass::prelude::ObjectSubclassIsExt;
 | 
				
			||||||
use adw::{gio, glib};
 | 
					 | 
				
			||||||
use dbus::arg::PropMap;
 | 
					use dbus::arg::PropMap;
 | 
				
			||||||
use dbus::{Error, Path};
 | 
					use dbus::{Error, Path};
 | 
				
			||||||
use glib::{clone, PropertySet};
 | 
					use glib::{clone};
 | 
				
			||||||
 | 
					use glib::property::PropertySet;
 | 
				
			||||||
use gtk::prelude::{ActionableExt, ButtonExt, EditableExt, ListBoxRowExt, WidgetExt};
 | 
					use gtk::prelude::{ActionableExt, ButtonExt, EditableExt, ListBoxRowExt, WidgetExt};
 | 
				
			||||||
use re_set_lib::network::connection::{
 | 
					use re_set_lib::network::connection::{
 | 
				
			||||||
    Connection, DNSMethod4, DNSMethod6, Enum, KeyManagement, TypeSettings,
 | 
					    Connection, DNSMethod4, DNSMethod6, Enum, KeyManagement, TypeSettings,
 | 
				
			||||||
| 
						 | 
					@ -389,15 +390,8 @@ fn setup_callbacks(wifi_options: &Arc<WifiOptions>, path: Path<'static>) {
 | 
				
			||||||
fn set_connection_settings(path: Path<'static>, prop: HashMap<String, PropMap>) {
 | 
					fn set_connection_settings(path: Path<'static>, prop: HashMap<String, PropMap>) {
 | 
				
			||||||
    gio::spawn_blocking(move || {
 | 
					    gio::spawn_blocking(move || {
 | 
				
			||||||
        let conn = dbus::blocking::Connection::new_session().unwrap();
 | 
					        let conn = dbus::blocking::Connection::new_session().unwrap();
 | 
				
			||||||
        let proxy = conn.with_proxy(
 | 
					        let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
 | 
				
			||||||
            BASE,
 | 
					        let _: Result<(bool,), Error> =
 | 
				
			||||||
            DBUS_PATH,
 | 
					            proxy.method_call(WIRELESS, "SetConnectionSettings", (path, prop));
 | 
				
			||||||
            Duration::from_millis(1000),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        let _: Result<(bool,), Error> = proxy.method_call(
 | 
					 | 
				
			||||||
            WIRELESS,
 | 
					 | 
				
			||||||
            "SetConnectionSettings",
 | 
					 | 
				
			||||||
            (path, prop),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@ use adw::{
 | 
				
			||||||
    ActionRow, ComboRow, EntryRow, NavigationPage, PasswordEntryRow, PreferencesGroup, SwitchRow,
 | 
					    ActionRow, ComboRow, EntryRow, NavigationPage, PasswordEntryRow, PreferencesGroup, SwitchRow,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, Button, CompositeTemplate, Label};
 | 
					use gtk::{Button, CompositeTemplate, Label};
 | 
				
			||||||
use re_set_lib::network::connection::Connection;
 | 
					use re_set_lib::network::connection::Connection;
 | 
				
			||||||
use std::cell::RefCell;
 | 
					use std::cell::RefCell;
 | 
				
			||||||
use std::rc::Rc;
 | 
					use std::rc::Rc;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,4 @@
 | 
				
			||||||
use crate::components::wifi::utils::IpProtocol;
 | 
					use crate::components::wifi::utils::IpProtocol;
 | 
				
			||||||
use adw::glib;
 | 
					 | 
				
			||||||
use adw::glib::Object;
 | 
					use adw::glib::Object;
 | 
				
			||||||
use adw::prelude::{ExpanderRowExt, PreferencesRowExt};
 | 
					use adw::prelude::{ExpanderRowExt, PreferencesRowExt};
 | 
				
			||||||
use glib::clone;
 | 
					use glib::clone;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ use crate::components::wifi::utils::IpProtocol;
 | 
				
			||||||
use crate::components::wifi::wifi_route_entry;
 | 
					use crate::components::wifi::wifi_route_entry;
 | 
				
			||||||
use adw::{EntryRow, ExpanderRow};
 | 
					use adw::{EntryRow, ExpanderRow};
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, Button, CompositeTemplate};
 | 
					use gtk::{Button, CompositeTemplate};
 | 
				
			||||||
use std::cell::{Cell, RefCell};
 | 
					use std::cell::{Cell, RefCell};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default, CompositeTemplate)]
 | 
					#[derive(Default, CompositeTemplate)]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,13 +5,13 @@ use std::rc::Rc;
 | 
				
			||||||
use std::sync::atomic::Ordering;
 | 
					use std::sync::atomic::Ordering;
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::audio::input::source_box::{populate_sources, SourceBox};
 | 
				
			||||||
 | 
					use crate::components::audio::output::sink_box::{populate_sinks, SinkBox};
 | 
				
			||||||
use crate::components::base::setting_box::SettingBox;
 | 
					use crate::components::base::setting_box::SettingBox;
 | 
				
			||||||
use crate::components::base::utils::{start_audio_listener, Listeners, Position};
 | 
					use crate::components::base::utils::{start_audio_listener, Listeners, Position};
 | 
				
			||||||
use crate::components::bluetooth::bluetooth_box::{
 | 
					use crate::components::bluetooth::bluetooth_box::{
 | 
				
			||||||
    populate_conntected_bluetooth_devices, start_bluetooth_listener, BluetoothBox,
 | 
					    populate_connected_bluetooth_devices, start_bluetooth_listener, BluetoothBox,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use crate::components::input::source_box::{populate_sources, SourceBox};
 | 
					 | 
				
			||||||
use crate::components::output::sink_box::{populate_sinks, SinkBox};
 | 
					 | 
				
			||||||
use crate::components::wifi::wifi_box::{
 | 
					use crate::components::wifi::wifi_box::{
 | 
				
			||||||
    scan_for_wifi, show_stored_connections, start_event_listener, WifiBox,
 | 
					    scan_for_wifi, show_stored_connections, start_event_listener, WifiBox,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -29,7 +29,7 @@ pub const HANDLE_CONNECTIVITY_CLICK: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Posi
 | 
				
			||||||
        scan_for_wifi(wifi_box.clone());
 | 
					        scan_for_wifi(wifi_box.clone());
 | 
				
			||||||
        let wifi_frame = wrap_in_flow_box_child(SettingBox::new(&*wifi_box));
 | 
					        let wifi_frame = wrap_in_flow_box_child(SettingBox::new(&*wifi_box));
 | 
				
			||||||
        let bluetooth_box = BluetoothBox::new(listeners.clone());
 | 
					        let bluetooth_box = BluetoothBox::new(listeners.clone());
 | 
				
			||||||
        populate_conntected_bluetooth_devices(bluetooth_box.clone());
 | 
					        populate_connected_bluetooth_devices(bluetooth_box.clone());
 | 
				
			||||||
        start_bluetooth_listener(listeners, bluetooth_box.clone());
 | 
					        start_bluetooth_listener(listeners, bluetooth_box.clone());
 | 
				
			||||||
        let bluetooth_frame = wrap_in_flow_box_child(SettingBox::new(&*bluetooth_box));
 | 
					        let bluetooth_frame = wrap_in_flow_box_child(SettingBox::new(&*bluetooth_box));
 | 
				
			||||||
        reset_main.remove_all();
 | 
					        reset_main.remove_all();
 | 
				
			||||||
| 
						 | 
					@ -60,7 +60,7 @@ pub const HANDLE_BLUETOOTH_CLICK: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Positio
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        let bluetooth_box = BluetoothBox::new(listeners.clone());
 | 
					        let bluetooth_box = BluetoothBox::new(listeners.clone());
 | 
				
			||||||
        start_bluetooth_listener(listeners, bluetooth_box.clone());
 | 
					        start_bluetooth_listener(listeners, bluetooth_box.clone());
 | 
				
			||||||
        populate_conntected_bluetooth_devices(bluetooth_box.clone());
 | 
					        populate_connected_bluetooth_devices(bluetooth_box.clone());
 | 
				
			||||||
        let bluetooth_frame = wrap_in_flow_box_child(SettingBox::new(&*bluetooth_box));
 | 
					        let bluetooth_frame = wrap_in_flow_box_child(SettingBox::new(&*bluetooth_box));
 | 
				
			||||||
        reset_main.remove_all();
 | 
					        reset_main.remove_all();
 | 
				
			||||||
        reset_main.insert(&bluetooth_frame, -1);
 | 
					        reset_main.insert(&bluetooth_frame, -1);
 | 
				
			||||||
| 
						 | 
					@ -162,60 +162,3 @@ fn handle_init(
 | 
				
			||||||
    listeners.stop_bluetooth_listener();
 | 
					    listeners.stop_bluetooth_listener();
 | 
				
			||||||
    false
 | 
					    false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
// for future implementations
 | 
					 | 
				
			||||||
// pub const HANDLE_VPN_CLICK: fn(Arc<Listeners>, FlowBox) =
 | 
					 | 
				
			||||||
//     |listeners: Arc<Listeners>, resetMain: FlowBox| {
 | 
					 | 
				
			||||||
//         listeners.stop_network_listener();
 | 
					 | 
				
			||||||
//         listeners.stop_bluetooth_listener();
 | 
					 | 
				
			||||||
//         listeners.stop_audio_listener();
 | 
					 | 
				
			||||||
//         let label = Label::new(Some("not implemented yet"));
 | 
					 | 
				
			||||||
//         resetMain.remove_all();
 | 
					 | 
				
			||||||
//         resetMain.insert(&label, -1);
 | 
					 | 
				
			||||||
//         resetMain.set_max_children_per_line(1);
 | 
					 | 
				
			||||||
//     };
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// pub const HANDLE_PERIPHERALS_CLICK: fn(Arc<Listeners>, FlowBox) =
 | 
					 | 
				
			||||||
//     |listeners: Arc<Listeners>, resetMain: FlowBox| {
 | 
					 | 
				
			||||||
//         listeners.stop_network_listener();
 | 
					 | 
				
			||||||
//         listeners.stop_audio_listener();
 | 
					 | 
				
			||||||
//         listeners.stop_bluetooth_listener();
 | 
					 | 
				
			||||||
//         let label = Label::new(Some("not implemented yet"));
 | 
					 | 
				
			||||||
//         resetMain.remove_all();
 | 
					 | 
				
			||||||
//         resetMain.insert(&label, -1);
 | 
					 | 
				
			||||||
//         resetMain.set_max_children_per_line(1);
 | 
					 | 
				
			||||||
//     };
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// pub const HANDLE_MONITOR_CLICK: fn(Arc<Listeners>, FlowBox) =
 | 
					 | 
				
			||||||
//     |listeners: Arc<Listeners>, resetMain: FlowBox| {
 | 
					 | 
				
			||||||
//         listeners.stop_network_listener();
 | 
					 | 
				
			||||||
//         listeners.stop_audio_listener();
 | 
					 | 
				
			||||||
//         listeners.stop_bluetooth_listener();
 | 
					 | 
				
			||||||
//         let label = Label::new(Some("not implemented yet"));
 | 
					 | 
				
			||||||
//         resetMain.remove_all();
 | 
					 | 
				
			||||||
//         resetMain.insert(&label, -1);
 | 
					 | 
				
			||||||
//         resetMain.set_max_children_per_line(1);
 | 
					 | 
				
			||||||
//     };
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// pub const HANDLE_MOUSE_CLICK: fn(Arc<Listeners>, FlowBox) =
 | 
					 | 
				
			||||||
//     |listeners: Arc<Listeners>, resetMain: FlowBox| {
 | 
					 | 
				
			||||||
//         listeners.stop_network_listener();
 | 
					 | 
				
			||||||
//         listeners.stop_audio_listener();
 | 
					 | 
				
			||||||
//         listeners.stop_bluetooth_listener();
 | 
					 | 
				
			||||||
//         let label = Label::new(Some("not implemented yet"));
 | 
					 | 
				
			||||||
//         resetMain.remove_all();
 | 
					 | 
				
			||||||
//         resetMain.insert(&label, -1);
 | 
					 | 
				
			||||||
//         resetMain.set_max_children_per_line(1);
 | 
					 | 
				
			||||||
//     };
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// pub const HANDLE_KEYBOARD_CLICK: fn(Arc<Listeners>, FlowBox) =
 | 
					 | 
				
			||||||
//     |listeners: Arc<Listeners>, resetMain: FlowBox| {
 | 
					 | 
				
			||||||
//         listeners.stop_network_listener();
 | 
					 | 
				
			||||||
//         listeners.stop_audio_listener();
 | 
					 | 
				
			||||||
//         listeners.stop_bluetooth_listener();
 | 
					 | 
				
			||||||
//         let label = Label::new(Some("not implemented yet"));
 | 
					 | 
				
			||||||
//         resetMain.remove_all();
 | 
					 | 
				
			||||||
//         resetMain.insert(&label, -1);
 | 
					 | 
				
			||||||
//         resetMain.set_max_children_per_line(1);
 | 
					 | 
				
			||||||
//     };
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,17 +1,22 @@
 | 
				
			||||||
 | 
					use std::cell::RefCell;
 | 
				
			||||||
use std::rc::Rc;
 | 
					use std::rc::Rc;
 | 
				
			||||||
 | 
					use std::sync::Arc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use adw::BreakpointCondition;
 | 
				
			||||||
use adw::glib::clone;
 | 
					use adw::glib::clone;
 | 
				
			||||||
use adw::subclass::prelude::ObjectSubclassIsExt;
 | 
					use adw::subclass::prelude::ObjectSubclassIsExt;
 | 
				
			||||||
use adw::BreakpointCondition;
 | 
					 | 
				
			||||||
use glib::Object;
 | 
					use glib::Object;
 | 
				
			||||||
 | 
					use gtk::{AccessibleRole, Align, Application, FlowBox, FlowBoxChild, Frame, gio, ListBoxRow, Orientation, StateFlags};
 | 
				
			||||||
 | 
					use gtk::{DirectionType, prelude::*};
 | 
				
			||||||
use gtk::gio::ActionEntry;
 | 
					use gtk::gio::ActionEntry;
 | 
				
			||||||
use gtk::{gio, glib, AccessibleRole, Application, ListBoxRow, Orientation, StateFlags};
 | 
					use re_set_lib::utils::plugin_setup::FRONTEND_PLUGINS;
 | 
				
			||||||
use gtk::{prelude::*, DirectionType};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::base::setting_box::SettingBox;
 | 
				
			||||||
 | 
					use crate::components::base::utils::{Listeners, Position};
 | 
				
			||||||
 | 
					use crate::components::plugin::function::{PluginSidebarInfo, ReSetSidebarInfo};
 | 
				
			||||||
use crate::components::window::handle_sidebar_click::*;
 | 
					use crate::components::window::handle_sidebar_click::*;
 | 
				
			||||||
use crate::components::window::reset_window_impl;
 | 
					use crate::components::window::reset_window_impl;
 | 
				
			||||||
use crate::components::window::sidebar_entry::SidebarEntry;
 | 
					use crate::components::window::sidebar_entry::SidebarEntry;
 | 
				
			||||||
use crate::components::window::sidebar_entry_impl::Categories;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
glib::wrapper! {
 | 
					glib::wrapper! {
 | 
				
			||||||
    pub struct ReSetWindow(ObjectSubclass<reset_window_impl::ReSetWindow>)
 | 
					    pub struct ReSetWindow(ObjectSubclass<reset_window_impl::ReSetWindow>)
 | 
				
			||||||
| 
						 | 
					@ -39,6 +44,176 @@ impl ReSetWindow {
 | 
				
			||||||
        window
 | 
					        window
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn handle_dynamic_sidebar(&self) {
 | 
				
			||||||
 | 
					        let self_imp = self.imp();
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_sidebar_breakpoint
 | 
				
			||||||
 | 
					            .set_condition(BreakpointCondition::parse("max-width: 860sp").as_ref().ok());
 | 
				
			||||||
 | 
					        self_imp.reset_sidebar_breakpoint.add_setter(
 | 
				
			||||||
 | 
					            &Object::from(self_imp.reset_overlay_split_view.get()),
 | 
				
			||||||
 | 
					            "collapsed",
 | 
				
			||||||
 | 
					            &true.to_value(),
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        self_imp.reset_sidebar_breakpoint.add_setter(
 | 
				
			||||||
 | 
					            &Object::from(self_imp.reset_sidebar_toggle.get()),
 | 
				
			||||||
 | 
					            "visible",
 | 
				
			||||||
 | 
					            &true.to_value(),
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn filter_list(&self) {
 | 
				
			||||||
 | 
					        let text = self.imp().reset_search_entry.text().to_string();
 | 
				
			||||||
 | 
					        for (main_entry, sub_entriess) in self.imp().sidebar_entries.borrow().iter() {
 | 
				
			||||||
 | 
					            if text.is_empty() {
 | 
				
			||||||
 | 
					                main_entry.set_visible(true);
 | 
				
			||||||
 | 
					                for sub_entry in sub_entriess {
 | 
				
			||||||
 | 
					                    sub_entry.set_visible(true);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if main_entry
 | 
				
			||||||
 | 
					                .imp()
 | 
				
			||||||
 | 
					                .name
 | 
				
			||||||
 | 
					                .borrow()
 | 
				
			||||||
 | 
					                .to_lowercase()
 | 
				
			||||||
 | 
					                .contains(&text.to_lowercase())
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                main_entry.set_visible(true);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                main_entry.set_visible(false);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            for sub_entry in sub_entriess {
 | 
				
			||||||
 | 
					                if sub_entry
 | 
				
			||||||
 | 
					                    .imp()
 | 
				
			||||||
 | 
					                    .name
 | 
				
			||||||
 | 
					                    .borrow()
 | 
				
			||||||
 | 
					                    .to_lowercase()
 | 
				
			||||||
 | 
					                    .contains(&text.to_lowercase())
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    sub_entry.set_visible(true);
 | 
				
			||||||
 | 
					                    main_entry.set_visible(true);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    sub_entry.set_visible(false);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn toggle_sidebar(&self) {
 | 
				
			||||||
 | 
					        if self.imp().reset_overlay_split_view.shows_sidebar() {
 | 
				
			||||||
 | 
					            self.imp().reset_overlay_split_view.set_show_sidebar(false);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            self.imp().reset_overlay_split_view.set_show_sidebar(true);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn setup_sidebar_entries(&self) {
 | 
				
			||||||
 | 
					        let self_imp = self.imp();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let sidebar_list = vec![
 | 
				
			||||||
 | 
					            ReSetSidebarInfo {
 | 
				
			||||||
 | 
					                name: "Connectivity",
 | 
				
			||||||
 | 
					                icon_name: "network-wired-symbolic",
 | 
				
			||||||
 | 
					                parent: None,
 | 
				
			||||||
 | 
					                click_event: HANDLE_CONNECTIVITY_CLICK,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            ReSetSidebarInfo {
 | 
				
			||||||
 | 
					                name: "WiFi",
 | 
				
			||||||
 | 
					                icon_name: "network-wireless-symbolic",
 | 
				
			||||||
 | 
					                parent: Some("Connectivity"),
 | 
				
			||||||
 | 
					                click_event: HANDLE_WIFI_CLICK,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            ReSetSidebarInfo {
 | 
				
			||||||
 | 
					                name: "Bluetooth",
 | 
				
			||||||
 | 
					                icon_name: "bluetooth-symbolic",
 | 
				
			||||||
 | 
					                parent: Some("Connectivity"),
 | 
				
			||||||
 | 
					                click_event: HANDLE_BLUETOOTH_CLICK,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            ReSetSidebarInfo {
 | 
				
			||||||
 | 
					                name: "Audio",
 | 
				
			||||||
 | 
					                icon_name: "audio-headset-symbolic",
 | 
				
			||||||
 | 
					                parent: None,
 | 
				
			||||||
 | 
					                click_event: HANDLE_AUDIO_CLICK,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            ReSetSidebarInfo {
 | 
				
			||||||
 | 
					                name: "Output",
 | 
				
			||||||
 | 
					                icon_name: "audio-volume-high-symbolic",
 | 
				
			||||||
 | 
					                parent: Some("Audio"),
 | 
				
			||||||
 | 
					                click_event: HANDLE_VOLUME_CLICK,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            ReSetSidebarInfo {
 | 
				
			||||||
 | 
					                name: "Input",
 | 
				
			||||||
 | 
					                icon_name: "audio-input-microphone-symbolic",
 | 
				
			||||||
 | 
					                parent: Some("Audio"),
 | 
				
			||||||
 | 
					                click_event: HANDLE_MICROPHONE_CLICK,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let mut plugin_sidebar_list = vec![];
 | 
				
			||||||
 | 
					        unsafe {
 | 
				
			||||||
 | 
					            for plugin in FRONTEND_PLUGINS.iter() {
 | 
				
			||||||
 | 
					                let (sidebar_info, plugin_boxes) = (plugin.frontend_data)();
 | 
				
			||||||
 | 
					                let listeners = self_imp.listeners.clone();
 | 
				
			||||||
 | 
					                (plugin.frontend_startup)();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                let event = Rc::new(
 | 
				
			||||||
 | 
					                    move |reset_main: FlowBox, position: Rc<RefCell<Position>>, boxes: Vec<gtk::Box>| {
 | 
				
			||||||
 | 
					                        if handle_init(listeners.clone(), position, Position::Custom(String::from(sidebar_info.name))) {
 | 
				
			||||||
 | 
					                            return;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                        reset_main.remove_all();
 | 
				
			||||||
 | 
					                        for plugin_box in &boxes {
 | 
				
			||||||
 | 
					                            let frame = wrap_in_flow_box_child(SettingBox::new(&plugin_box.clone()));
 | 
				
			||||||
 | 
					                            reset_main.insert(&frame, -1);
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                        reset_main.set_max_children_per_line(boxes.len() as u32);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                plugin_sidebar_list.push(PluginSidebarInfo {
 | 
				
			||||||
 | 
					                    name: sidebar_info.name,
 | 
				
			||||||
 | 
					                    icon_name: sidebar_info.icon_name,
 | 
				
			||||||
 | 
					                    parent: sidebar_info.parent,
 | 
				
			||||||
 | 
					                    click_event: event,
 | 
				
			||||||
 | 
					                    plugin_boxes,
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        HANDLE_VOLUME_CLICK(
 | 
				
			||||||
 | 
					            self_imp.listeners.clone(),
 | 
				
			||||||
 | 
					            self_imp.reset_main.clone(),
 | 
				
			||||||
 | 
					            self_imp.position.clone(),
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self_imp
 | 
				
			||||||
 | 
					            .reset_sidebar_list
 | 
				
			||||||
 | 
					            .connect_row_activated(clone!(@ weak self_imp => move |_, _| {
 | 
				
			||||||
 | 
					                self_imp.reset_search_entry.set_text("");
 | 
				
			||||||
 | 
					            }));
 | 
				
			||||||
 | 
					        // TODO: refactor this
 | 
				
			||||||
 | 
					        let mut i = 0;
 | 
				
			||||||
 | 
					        for info in sidebar_list {
 | 
				
			||||||
 | 
					            if info.parent.is_none() && i != 0 {
 | 
				
			||||||
 | 
					                self_imp.reset_sidebar_list.insert(&create_separator(), i);
 | 
				
			||||||
 | 
					                i += 1;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let entry = SidebarEntry::new(&info);
 | 
				
			||||||
 | 
					            self_imp.reset_sidebar_list.insert(&entry, i);
 | 
				
			||||||
 | 
					            i += 1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for info in plugin_sidebar_list {
 | 
				
			||||||
 | 
					            if info.parent.is_none() && i != 0 {
 | 
				
			||||||
 | 
					                self_imp.reset_sidebar_list.insert(&create_separator(), i);
 | 
				
			||||||
 | 
					                i += 1;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            let entry = SidebarEntry::new_plugin(&info);
 | 
				
			||||||
 | 
					            self_imp.reset_sidebar_list.insert(&entry, i);
 | 
				
			||||||
 | 
					            i += 1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn setup_shortcuts(&self) {
 | 
					    pub fn setup_shortcuts(&self) {
 | 
				
			||||||
        let search_action = ActionEntry::builder("search")
 | 
					        let search_action = ActionEntry::builder("search")
 | 
				
			||||||
            .activate(move |window: &Self, _, _| {
 | 
					            .activate(move |window: &Self, _, _| {
 | 
				
			||||||
| 
						 | 
					@ -56,6 +231,18 @@ impl ReSetWindow {
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
            .build();
 | 
					            .build();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let error_popup_action = ActionEntry::builder("show_error")
 | 
				
			||||||
 | 
					            .activate(move |window: &Self, _, _| {
 | 
				
			||||||
 | 
					                window.imp().error_popup.popup();
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					            .build();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let error_popdown_action = ActionEntry::builder("hide_error")
 | 
				
			||||||
 | 
					            .activate(move |window: &Self, _, _| {
 | 
				
			||||||
 | 
					                window.imp().error_popup.popdown();
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					            .build();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let vim_up = ActionEntry::builder("up")
 | 
					        let vim_up = ActionEntry::builder("up")
 | 
				
			||||||
            .activate(move |window: &Self, _, _| {
 | 
					            .activate(move |window: &Self, _, _| {
 | 
				
			||||||
                window.child_focus(DirectionType::Up);
 | 
					                window.child_focus(DirectionType::Up);
 | 
				
			||||||
| 
						 | 
					@ -123,224 +310,12 @@ impl ReSetWindow {
 | 
				
			||||||
            vim_right,
 | 
					            vim_right,
 | 
				
			||||||
            vim_down,
 | 
					            vim_down,
 | 
				
			||||||
            vim_left,
 | 
					            vim_left,
 | 
				
			||||||
            // clear_initial,
 | 
					            error_popup_action,
 | 
				
			||||||
 | 
					            error_popdown_action,
 | 
				
			||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    pub fn handle_dynamic_sidebar(&self) {
 | 
					 | 
				
			||||||
        let self_imp = self.imp();
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_sidebar_breakpoint
 | 
					 | 
				
			||||||
            .set_condition(BreakpointCondition::parse("max-width: 860sp").as_ref().ok());
 | 
					 | 
				
			||||||
        self_imp.reset_sidebar_breakpoint.add_setter(
 | 
					 | 
				
			||||||
            &Object::from(self_imp.reset_overlay_split_view.get()),
 | 
					 | 
				
			||||||
            "collapsed",
 | 
					 | 
				
			||||||
            &true.to_value(),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        self_imp.reset_sidebar_breakpoint.add_setter(
 | 
					 | 
				
			||||||
            &Object::from(self_imp.reset_sidebar_toggle.get()),
 | 
					 | 
				
			||||||
            "visible",
 | 
					 | 
				
			||||||
            &true.to_value(),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn filter_list(&self) {
 | 
					 | 
				
			||||||
        let text = self.imp().reset_search_entry.text().to_string();
 | 
					 | 
				
			||||||
        for (main_entry, sub_entriess) in self.imp().sidebar_entries.borrow().iter() {
 | 
					 | 
				
			||||||
            if text.is_empty() {
 | 
					 | 
				
			||||||
                main_entry.set_visible(true);
 | 
					 | 
				
			||||||
                for sub_entry in sub_entriess {
 | 
					 | 
				
			||||||
                    sub_entry.set_visible(true);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if main_entry
 | 
					 | 
				
			||||||
                .imp()
 | 
					 | 
				
			||||||
                .name
 | 
					 | 
				
			||||||
                .borrow()
 | 
					 | 
				
			||||||
                .to_lowercase()
 | 
					 | 
				
			||||||
                .contains(&text.to_lowercase())
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                main_entry.set_visible(true);
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                main_entry.set_visible(false);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            for sub_entry in sub_entriess {
 | 
					 | 
				
			||||||
                if sub_entry
 | 
					 | 
				
			||||||
                    .imp()
 | 
					 | 
				
			||||||
                    .name
 | 
					 | 
				
			||||||
                    .borrow()
 | 
					 | 
				
			||||||
                    .to_lowercase()
 | 
					 | 
				
			||||||
                    .contains(&text.to_lowercase())
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    sub_entry.set_visible(true);
 | 
					 | 
				
			||||||
                    main_entry.set_visible(true);
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    sub_entry.set_visible(false);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pub fn toggle_sidebar(&self) {
 | 
					 | 
				
			||||||
        if self.imp().reset_overlay_split_view.shows_sidebar() {
 | 
					 | 
				
			||||||
            self.imp().reset_overlay_split_view.set_show_sidebar(false);
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            self.imp().reset_overlay_split_view.set_show_sidebar(true);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pub fn setup_sidebar_entries(&self) {
 | 
					 | 
				
			||||||
        let self_imp = self.imp();
 | 
					 | 
				
			||||||
        let mut sidebar_entries = self_imp.sidebar_entries.borrow_mut();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        let connectivity_list = vec![
 | 
					 | 
				
			||||||
            Rc::new(SidebarEntry::new(
 | 
					 | 
				
			||||||
                "WiFi",
 | 
					 | 
				
			||||||
                "network-wireless-symbolic",
 | 
					 | 
				
			||||||
                Categories::Connectivity,
 | 
					 | 
				
			||||||
                true,
 | 
					 | 
				
			||||||
                HANDLE_WIFI_CLICK,
 | 
					 | 
				
			||||||
            )),
 | 
					 | 
				
			||||||
            Rc::new(SidebarEntry::new(
 | 
					 | 
				
			||||||
                "Bluetooth",
 | 
					 | 
				
			||||||
                "bluetooth-symbolic",
 | 
					 | 
				
			||||||
                Categories::Connectivity,
 | 
					 | 
				
			||||||
                true,
 | 
					 | 
				
			||||||
                HANDLE_BLUETOOTH_CLICK,
 | 
					 | 
				
			||||||
            )),
 | 
					 | 
				
			||||||
            // uncommented when VPN is implemented
 | 
					 | 
				
			||||||
            // SidebarEntry::new(
 | 
					 | 
				
			||||||
            //     "VPN",
 | 
					 | 
				
			||||||
            //     "network-vpn-symbolic",
 | 
					 | 
				
			||||||
            //     Categories::Connectivity,
 | 
					 | 
				
			||||||
            //     true,
 | 
					 | 
				
			||||||
            //     HANDLE_VPN_CLICK,
 | 
					 | 
				
			||||||
            // ),
 | 
					 | 
				
			||||||
        ];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        sidebar_entries.push((
 | 
					 | 
				
			||||||
            Rc::new(SidebarEntry::new(
 | 
					 | 
				
			||||||
                "Connectivity",
 | 
					 | 
				
			||||||
                "network-wired-symbolic",
 | 
					 | 
				
			||||||
                Categories::Connectivity,
 | 
					 | 
				
			||||||
                false,
 | 
					 | 
				
			||||||
                HANDLE_CONNECTIVITY_CLICK,
 | 
					 | 
				
			||||||
            )),
 | 
					 | 
				
			||||||
            connectivity_list,
 | 
					 | 
				
			||||||
        ));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        let output = Rc::new(SidebarEntry::new(
 | 
					 | 
				
			||||||
            "Output",
 | 
					 | 
				
			||||||
            "audio-volume-high-symbolic",
 | 
					 | 
				
			||||||
            Categories::Audio,
 | 
					 | 
				
			||||||
            true,
 | 
					 | 
				
			||||||
            HANDLE_VOLUME_CLICK,
 | 
					 | 
				
			||||||
        ));
 | 
					 | 
				
			||||||
        output.set_receives_default(true);
 | 
					 | 
				
			||||||
        let audio_list = vec![
 | 
					 | 
				
			||||||
            output,
 | 
					 | 
				
			||||||
            Rc::new(SidebarEntry::new(
 | 
					 | 
				
			||||||
                "Input",
 | 
					 | 
				
			||||||
                "audio-input-microphone-symbolic",
 | 
					 | 
				
			||||||
                Categories::Audio,
 | 
					 | 
				
			||||||
                true,
 | 
					 | 
				
			||||||
                HANDLE_MICROPHONE_CLICK,
 | 
					 | 
				
			||||||
            )),
 | 
					 | 
				
			||||||
        ];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        sidebar_entries.push((
 | 
					 | 
				
			||||||
            Rc::new(SidebarEntry::new(
 | 
					 | 
				
			||||||
                "Audio",
 | 
					 | 
				
			||||||
                "audio-headset-symbolic",
 | 
					 | 
				
			||||||
                Categories::Audio,
 | 
					 | 
				
			||||||
                false,
 | 
					 | 
				
			||||||
                HANDLE_AUDIO_CLICK,
 | 
					 | 
				
			||||||
            )),
 | 
					 | 
				
			||||||
            audio_list,
 | 
					 | 
				
			||||||
        ));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // uncommented when implemented
 | 
					 | 
				
			||||||
        // let peripheralsList = vec![
 | 
					 | 
				
			||||||
        //     SidebarEntry::new(
 | 
					 | 
				
			||||||
        //         "Displays",
 | 
					 | 
				
			||||||
        //         "video-display-symbolic",
 | 
					 | 
				
			||||||
        //         Categories::Peripherals,
 | 
					 | 
				
			||||||
        //         true,
 | 
					 | 
				
			||||||
        //         HANDLE_MONITOR_CLICK,
 | 
					 | 
				
			||||||
        //     ),
 | 
					 | 
				
			||||||
        //     SidebarEntry::new(
 | 
					 | 
				
			||||||
        //         "Mouse",
 | 
					 | 
				
			||||||
        //         "input-mouse-symbolic",
 | 
					 | 
				
			||||||
        //         Categories::Peripherals,
 | 
					 | 
				
			||||||
        //         true,
 | 
					 | 
				
			||||||
        //         HANDLE_MOUSE_CLICK,
 | 
					 | 
				
			||||||
        //     ),
 | 
					 | 
				
			||||||
        //     SidebarEntry::new(
 | 
					 | 
				
			||||||
        //         "Keyboard",
 | 
					 | 
				
			||||||
        //         "input-keyboard-symbolic",
 | 
					 | 
				
			||||||
        //         Categories::Peripherals,
 | 
					 | 
				
			||||||
        //         true,
 | 
					 | 
				
			||||||
        //         HANDLE_KEYBOARD_CLICK,
 | 
					 | 
				
			||||||
        //     ),
 | 
					 | 
				
			||||||
        // ];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // let home = SidebarEntry::new(
 | 
					 | 
				
			||||||
        //     "Home",
 | 
					 | 
				
			||||||
        //     "preferences-system-devices-symbolic",
 | 
					 | 
				
			||||||
        //     Categories::Peripherals,
 | 
					 | 
				
			||||||
        //     false,
 | 
					 | 
				
			||||||
        //     HANDLE_VOLUME_CLICK,
 | 
					 | 
				
			||||||
        // );
 | 
					 | 
				
			||||||
        //
 | 
					 | 
				
			||||||
        // sidebar_entries.push((home, Vec::new()));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        (HANDLE_VOLUME_CLICK)(
 | 
					 | 
				
			||||||
            self_imp.listeners.clone(),
 | 
					 | 
				
			||||||
            self_imp.reset_main.clone(),
 | 
					 | 
				
			||||||
            self_imp.position.clone(),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self_imp
 | 
					 | 
				
			||||||
            .reset_sidebar_list
 | 
					 | 
				
			||||||
            .connect_row_activated(clone!(@ weak self_imp => move |_, _| {
 | 
					 | 
				
			||||||
                self_imp.reset_search_entry.set_text("");
 | 
					 | 
				
			||||||
            }));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (main_entry, sub_entries) in sidebar_entries.iter() {
 | 
					 | 
				
			||||||
            self_imp.reset_sidebar_list.append(&**main_entry);
 | 
					 | 
				
			||||||
            for sub_entry in sub_entries {
 | 
					 | 
				
			||||||
                // TODO change this to home when home offers dynamic selection
 | 
					 | 
				
			||||||
                // this is just a placeholder for now, hence hardcoded
 | 
					 | 
				
			||||||
                if &*sub_entry.imp().name.borrow() == "Output" {
 | 
					 | 
				
			||||||
                    self_imp.reset_sidebar_list.append(&**sub_entry);
 | 
					 | 
				
			||||||
                    self_imp.default_entry.replace(Some(sub_entry.clone()));
 | 
					 | 
				
			||||||
                    sub_entry.grab_focus();
 | 
					 | 
				
			||||||
                    sub_entry.set_state_flags(StateFlags::SELECTED, false);
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    self_imp.reset_sidebar_list.append(&**sub_entry);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            let separator = gtk::Separator::builder()
 | 
					 | 
				
			||||||
                .margin_bottom(3)
 | 
					 | 
				
			||||||
                .margin_top(3)
 | 
					 | 
				
			||||||
                .orientation(Orientation::Horizontal)
 | 
					 | 
				
			||||||
                .accessible_role(AccessibleRole::Separator)
 | 
					 | 
				
			||||||
                .can_focus(false)
 | 
					 | 
				
			||||||
                .build();
 | 
					 | 
				
			||||||
            let separator_row = ListBoxRow::builder()
 | 
					 | 
				
			||||||
                .child(&separator)
 | 
					 | 
				
			||||||
                .selectable(false)
 | 
					 | 
				
			||||||
                .activatable(false)
 | 
					 | 
				
			||||||
                .can_target(false)
 | 
					 | 
				
			||||||
                // .focusable(false)
 | 
					 | 
				
			||||||
                .accessible_role(AccessibleRole::Separator)
 | 
					 | 
				
			||||||
                .build();
 | 
					 | 
				
			||||||
            // TODO how to simply skip this ?
 | 
					 | 
				
			||||||
            self_imp.reset_sidebar_list.append(&separator_row);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
fn setup_callback(window: Rc<ReSetWindow>) -> Rc<ReSetWindow> {
 | 
					fn setup_callback(window: Rc<ReSetWindow>) -> Rc<ReSetWindow> {
 | 
				
			||||||
    let self_imp = window.imp();
 | 
					    let self_imp = window.imp();
 | 
				
			||||||
    let activated_ref = window.clone();
 | 
					    let activated_ref = window.clone();
 | 
				
			||||||
| 
						 | 
					@ -373,12 +348,21 @@ fn setup_callback(window: Rc<ReSetWindow>) -> Rc<ReSetWindow> {
 | 
				
			||||||
                    *default_entry = None;
 | 
					                    *default_entry = None;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            let click_event = result.imp().on_click_event.borrow().on_click_event;
 | 
					            let click_event = result.imp().on_click_event.borrow();
 | 
				
			||||||
            (click_event)(
 | 
					            if let Some(event) = click_event.on_click_event {
 | 
				
			||||||
 | 
					                event(
 | 
				
			||||||
                    imp.listeners.clone(),
 | 
					                    imp.listeners.clone(),
 | 
				
			||||||
                    imp.reset_main.get(),
 | 
					                    imp.reset_main.get(),
 | 
				
			||||||
                    imp.position.clone(),
 | 
					                    imp.position.clone(),
 | 
				
			||||||
                );
 | 
					                );
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                let event = click_event.on_plugin_click_event.clone();
 | 
				
			||||||
 | 
					                event(
 | 
				
			||||||
 | 
					                    imp.reset_main.get(),
 | 
				
			||||||
 | 
					                    imp.position.clone(),
 | 
				
			||||||
 | 
					                    result.imp().plugin_boxes.borrow().clone(),
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    self_imp.reset_close.connect_clicked(move |_| {
 | 
					    self_imp.reset_close.connect_clicked(move |_| {
 | 
				
			||||||
| 
						 | 
					@ -386,3 +370,49 @@ fn setup_callback(window: Rc<ReSetWindow>) -> Rc<ReSetWindow> {
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    window
 | 
					    window
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn create_separator() -> ListBoxRow {
 | 
				
			||||||
 | 
					    let separator: gtk::Separator = gtk::Separator::builder()
 | 
				
			||||||
 | 
					        .margin_bottom(3)
 | 
				
			||||||
 | 
					        .margin_top(3)
 | 
				
			||||||
 | 
					        .orientation(Orientation::Horizontal)
 | 
				
			||||||
 | 
					        .accessible_role(AccessibleRole::Separator)
 | 
				
			||||||
 | 
					        .can_focus(false)
 | 
				
			||||||
 | 
					        .build();
 | 
				
			||||||
 | 
					    ListBoxRow::builder()
 | 
				
			||||||
 | 
					        .child(&separator)
 | 
				
			||||||
 | 
					        .selectable(false)
 | 
				
			||||||
 | 
					        .activatable(false)
 | 
				
			||||||
 | 
					        .can_target(false)
 | 
				
			||||||
 | 
					        .accessible_role(AccessibleRole::Separator)
 | 
				
			||||||
 | 
					        .build()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn handle_init(
 | 
				
			||||||
 | 
					    listeners: Arc<Listeners>,
 | 
				
			||||||
 | 
					    position: Rc<RefCell<Position>>,
 | 
				
			||||||
 | 
					    clicked_position: Position,
 | 
				
			||||||
 | 
					) -> bool {
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        let mut pos_borrow = position.borrow_mut();
 | 
				
			||||||
 | 
					        if *pos_borrow == clicked_position {
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        *pos_borrow = clicked_position;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    listeners.stop_network_listener();
 | 
				
			||||||
 | 
					    listeners.stop_audio_listener();
 | 
				
			||||||
 | 
					    listeners.stop_bluetooth_listener();
 | 
				
			||||||
 | 
					    false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn wrap_in_flow_box_child(widget: SettingBox) -> FlowBoxChild {
 | 
				
			||||||
 | 
					    let frame = Frame::new(None);
 | 
				
			||||||
 | 
					    frame.set_child(Some(&widget));
 | 
				
			||||||
 | 
					    frame.add_css_class("resetSettingFrame");
 | 
				
			||||||
 | 
					    FlowBoxChild::builder()
 | 
				
			||||||
 | 
					        .child(&frame)
 | 
				
			||||||
 | 
					        .halign(Align::Fill)
 | 
				
			||||||
 | 
					        .valign(Align::Start)
 | 
				
			||||||
 | 
					        .build()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,14 +2,15 @@ use std::cell::RefCell;
 | 
				
			||||||
use std::rc::Rc;
 | 
					use std::rc::Rc;
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use adw::glib::StaticTypeExt;
 | 
					 | 
				
			||||||
use adw::subclass::prelude::AdwApplicationWindowImpl;
 | 
					use adw::subclass::prelude::AdwApplicationWindowImpl;
 | 
				
			||||||
use adw::{Breakpoint, OverlaySplitView};
 | 
					use adw::{Breakpoint, OverlaySplitView};
 | 
				
			||||||
 | 
					use glib::prelude::StaticTypeExt;
 | 
				
			||||||
use glib::subclass::InitializingObject;
 | 
					use glib::subclass::InitializingObject;
 | 
				
			||||||
use gtk::prelude::WidgetExt;
 | 
					use gtk::prelude::WidgetExt;
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, Button, CompositeTemplate, FlowBox, ListBox, SearchEntry};
 | 
					use gtk::{Button, CompositeTemplate, FlowBox, ListBox, SearchEntry};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::components::base::error::ReSetError;
 | 
				
			||||||
use crate::components::base::utils::{Listeners, Position};
 | 
					use crate::components::base::utils::{Listeners, Position};
 | 
				
			||||||
use crate::components::wifi::wifi_box::WifiBox;
 | 
					use crate::components::wifi::wifi_box::WifiBox;
 | 
				
			||||||
use crate::components::window::reset_window;
 | 
					use crate::components::window::reset_window;
 | 
				
			||||||
| 
						 | 
					@ -38,6 +39,7 @@ pub struct ReSetWindow {
 | 
				
			||||||
    pub default_entry: RefCell<Option<Rc<SidebarEntry>>>,
 | 
					    pub default_entry: RefCell<Option<Rc<SidebarEntry>>>,
 | 
				
			||||||
    pub listeners: Arc<Listeners>,
 | 
					    pub listeners: Arc<Listeners>,
 | 
				
			||||||
    pub position: Rc<RefCell<Position>>,
 | 
					    pub position: Rc<RefCell<Position>>,
 | 
				
			||||||
 | 
					    pub error_popup: ReSetError,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
unsafe impl Send for ReSetWindow {}
 | 
					unsafe impl Send for ReSetWindow {}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,14 +1,13 @@
 | 
				
			||||||
use std::cell::RefCell;
 | 
					 | 
				
			||||||
use std::rc::Rc;
 | 
					use std::rc::Rc;
 | 
				
			||||||
use std::sync::Arc;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::components::base::utils::{Listeners, Position};
 | 
					 | 
				
			||||||
use crate::components::window::sidebar_entry_impl;
 | 
					use crate::components::window::sidebar_entry_impl;
 | 
				
			||||||
use crate::components::window::sidebar_entry_impl::{Categories, SidebarAction};
 | 
					use crate::components::window::sidebar_entry_impl::{SidebarAction};
 | 
				
			||||||
use adw::subclass::prelude::ObjectSubclassIsExt;
 | 
					use adw::subclass::prelude::ObjectSubclassIsExt;
 | 
				
			||||||
use glib::Object;
 | 
					use glib::Object;
 | 
				
			||||||
use gtk::prelude::*;
 | 
					use gtk::prelude::*;
 | 
				
			||||||
use gtk::{glib, FlowBox};
 | 
					use crate::components::plugin::function::{PluginSidebarInfo, ReSetSidebarInfo};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use super::handle_sidebar_click::HANDLE_HOME;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
glib::wrapper! {
 | 
					glib::wrapper! {
 | 
				
			||||||
    pub struct SidebarEntry(ObjectSubclass<sidebar_entry_impl::SidebarEntry>)
 | 
					    pub struct SidebarEntry(ObjectSubclass<sidebar_entry_impl::SidebarEntry>)
 | 
				
			||||||
| 
						 | 
					@ -17,37 +16,63 @@ glib::wrapper! {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl SidebarEntry {
 | 
					impl SidebarEntry {
 | 
				
			||||||
    pub fn new(
 | 
					    // TODO: refactor new and new_plugin
 | 
				
			||||||
        entry_name: &str,
 | 
					    pub fn new(info: &ReSetSidebarInfo) -> Self {
 | 
				
			||||||
        icon_name: &str,
 | 
					 | 
				
			||||||
        category: Categories,
 | 
					 | 
				
			||||||
        is_subcategory: bool,
 | 
					 | 
				
			||||||
        click_event: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>),
 | 
					 | 
				
			||||||
    ) -> Self {
 | 
					 | 
				
			||||||
        let entry: SidebarEntry = Object::builder().build();
 | 
					        let entry: SidebarEntry = Object::builder().build();
 | 
				
			||||||
        let entry_imp = entry.imp();
 | 
					        let entry_imp = entry.imp();
 | 
				
			||||||
        entry_imp.reset_sidebar_label.get().set_text(entry_name);
 | 
					        entry_imp.reset_sidebar_label.get().set_text(info.name);
 | 
				
			||||||
        entry_imp
 | 
					        entry_imp
 | 
				
			||||||
            .reset_sidebar_image
 | 
					            .reset_sidebar_image
 | 
				
			||||||
            .set_from_icon_name(Some(icon_name));
 | 
					            .set_from_icon_name(Some(info.icon_name));
 | 
				
			||||||
        entry_imp.category.set(category);
 | 
					        
 | 
				
			||||||
        entry_imp.is_subcategory.set(is_subcategory);
 | 
					        match &info.parent {
 | 
				
			||||||
 | 
					            None => {}
 | 
				
			||||||
 | 
					            Some(parent) => {
 | 
				
			||||||
 | 
					                let mut name = entry_imp.parent.borrow_mut();
 | 
				
			||||||
 | 
					                *name = parent.to_string();
 | 
				
			||||||
 | 
					                entry.child().unwrap().set_margin_start(30);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            let mut name = entry_imp.name.borrow_mut();
 | 
					            let mut name = entry_imp.name.borrow_mut();
 | 
				
			||||||
            *name = String::from(entry_name);
 | 
					            *name = info.name.to_string();
 | 
				
			||||||
            let mut action = entry_imp.on_click_event.borrow_mut();
 | 
					            let mut action = entry_imp.on_click_event.borrow_mut();
 | 
				
			||||||
            *action = SidebarAction {
 | 
					            *action = SidebarAction {
 | 
				
			||||||
                on_click_event: click_event,
 | 
					                on_click_event: Some(info.click_event),
 | 
				
			||||||
 | 
					                on_plugin_click_event: Rc::new(|_,_,_|{}),
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        Self::set_margin(&entry);
 | 
					 | 
				
			||||||
        entry
 | 
					        entry
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    fn set_margin(entry: &SidebarEntry) {
 | 
					    pub fn new_plugin(info: &PluginSidebarInfo) -> Self {
 | 
				
			||||||
        if entry.imp().is_subcategory.get() {
 | 
					        let entry: SidebarEntry = Object::builder().build();
 | 
				
			||||||
            let option = entry.child().unwrap();
 | 
					        let entry_imp = entry.imp();
 | 
				
			||||||
            option.set_margin_start(30);
 | 
					        entry_imp.reset_sidebar_label.get().set_text(info.name);
 | 
				
			||||||
 | 
					        entry_imp
 | 
				
			||||||
 | 
					            .reset_sidebar_image
 | 
				
			||||||
 | 
					            .set_from_icon_name(Some(info.icon_name));
 | 
				
			||||||
 | 
					        entry_imp.plugin_boxes.borrow_mut().extend(info.plugin_boxes.clone());
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        match &info.parent {
 | 
				
			||||||
 | 
					            None => {}
 | 
				
			||||||
 | 
					            Some(parent) => {
 | 
				
			||||||
 | 
					                let mut name = entry_imp.parent.borrow_mut();
 | 
				
			||||||
 | 
					                *name = parent.to_string();
 | 
				
			||||||
 | 
					                entry.child().unwrap().set_margin_start(30);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            let mut name = entry_imp.name.borrow_mut();
 | 
				
			||||||
 | 
					            *name = info.name.to_string();
 | 
				
			||||||
 | 
					            let mut action = entry_imp.on_click_event.borrow_mut();
 | 
				
			||||||
 | 
					            *action = SidebarAction {
 | 
				
			||||||
 | 
					                on_click_event: None,
 | 
				
			||||||
 | 
					                on_plugin_click_event: info.click_event.clone(),
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        entry
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,8 +3,8 @@ use std::rc::Rc;
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use glib::subclass::InitializingObject;
 | 
					use glib::subclass::InitializingObject;
 | 
				
			||||||
 | 
					use gtk::{CompositeTemplate, FlowBox, Image, Label, ListBoxRow};
 | 
				
			||||||
use gtk::subclass::prelude::*;
 | 
					use gtk::subclass::prelude::*;
 | 
				
			||||||
use gtk::{glib, CompositeTemplate, FlowBox, Image, Label, ListBoxRow};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::components::base::utils::{Listeners, Position};
 | 
					use crate::components::base::utils::{Listeners, Position};
 | 
				
			||||||
use crate::components::window::handle_sidebar_click::HANDLE_HOME;
 | 
					use crate::components::window::handle_sidebar_click::HANDLE_HOME;
 | 
				
			||||||
| 
						 | 
					@ -26,20 +26,22 @@ pub struct SidebarEntry {
 | 
				
			||||||
    pub reset_sidebar_label: TemplateChild<Label>,
 | 
					    pub reset_sidebar_label: TemplateChild<Label>,
 | 
				
			||||||
    #[template_child]
 | 
					    #[template_child]
 | 
				
			||||||
    pub reset_sidebar_image: TemplateChild<Image>,
 | 
					    pub reset_sidebar_image: TemplateChild<Image>,
 | 
				
			||||||
    pub category: Cell<Categories>,
 | 
					    pub parent: RefCell<String>,
 | 
				
			||||||
    pub is_subcategory: Cell<bool>,
 | 
					 | 
				
			||||||
    pub on_click_event: RefCell<SidebarAction>,
 | 
					    pub on_click_event: RefCell<SidebarAction>,
 | 
				
			||||||
 | 
					    pub plugin_boxes: RefCell<Vec<gtk::Box>>,
 | 
				
			||||||
    pub name: RefCell<String>,
 | 
					    pub name: RefCell<String>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub struct SidebarAction {
 | 
					pub struct SidebarAction {
 | 
				
			||||||
    pub on_click_event: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>),
 | 
					    pub on_click_event: Option<fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>)>,
 | 
				
			||||||
 | 
					    pub on_plugin_click_event: Rc<dyn Fn(FlowBox, Rc<RefCell<Position>>, Vec<gtk::Box>)>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Default for SidebarAction {
 | 
					impl Default for SidebarAction {
 | 
				
			||||||
    fn default() -> Self {
 | 
					    fn default() -> Self {
 | 
				
			||||||
        Self {
 | 
					        Self {
 | 
				
			||||||
            on_click_event: HANDLE_HOME,
 | 
					            on_click_event: Some(HANDLE_HOME),
 | 
				
			||||||
 | 
					            on_plugin_click_event: Rc::new(|_,_,_|{}),
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -68,6 +68,6 @@ async fn daemon_check() {
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    let res = handle.join();
 | 
					    let res = handle.join();
 | 
				
			||||||
    if res.unwrap().is_err() {
 | 
					    if res.unwrap().is_err() {
 | 
				
			||||||
        run_daemon().await;
 | 
					        run_daemon(vec![String::from("ina")]).await;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,11 +1,14 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.12"/>
 | 
					  <requires lib="gtk" version="4.12"/>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.4"/>
 | 
					  <requires lib="libadwaita" version="1.4"/>
 | 
				
			||||||
  <template class="resetAudioInput" parent="GtkBox">
 | 
					  <template class="resetAudioInput" parent="GtkBox">
 | 
				
			||||||
    <property name="orientation">vertical</property>
 | 
					    <property name="orientation">vertical</property>
 | 
				
			||||||
    <property name="valign">start</property>
 | 
					    <property name="valign">start</property>
 | 
				
			||||||
 | 
					    <child>
 | 
				
			||||||
 | 
					      <object class="resetError" id="error"/>
 | 
				
			||||||
 | 
					    </child>
 | 
				
			||||||
    <child>
 | 
					    <child>
 | 
				
			||||||
      <object class="GtkLabel">
 | 
					      <object class="GtkLabel">
 | 
				
			||||||
        <property name="css-classes">resetSettingLabel</property>
 | 
					        <property name="css-classes">resetSettingLabel</property>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.12"/>
 | 
					  <requires lib="gtk" version="4.12"/>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.4"/>
 | 
					  <requires lib="libadwaita" version="1.4"/>
 | 
				
			||||||
| 
						 | 
					@ -218,5 +218,8 @@
 | 
				
			||||||
        </child>
 | 
					        </child>
 | 
				
			||||||
      </object>
 | 
					      </object>
 | 
				
			||||||
    </child>
 | 
					    </child>
 | 
				
			||||||
 | 
					    <child>
 | 
				
			||||||
 | 
					      <object class="resetError" id="error"/>
 | 
				
			||||||
 | 
					    </child>
 | 
				
			||||||
  </template>
 | 
					  </template>
 | 
				
			||||||
</interface>
 | 
					</interface>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.12"/>
 | 
					  <requires lib="gtk" version="4.12"/>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.4"/>
 | 
					  <requires lib="libadwaita" version="1.4"/>
 | 
				
			||||||
| 
						 | 
					@ -144,5 +144,8 @@
 | 
				
			||||||
        </child>
 | 
					        </child>
 | 
				
			||||||
      </object>
 | 
					      </object>
 | 
				
			||||||
    </child>
 | 
					    </child>
 | 
				
			||||||
 | 
					    <child>
 | 
				
			||||||
 | 
					      <object class="resetError" id="error"/>
 | 
				
			||||||
 | 
					    </child>
 | 
				
			||||||
  </template>
 | 
					  </template>
 | 
				
			||||||
</interface>
 | 
					</interface>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.12"/>
 | 
					  <requires lib="gtk" version="4.12"/>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.0"/>
 | 
					  <requires lib="libadwaita" version="1.0"/>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.4"/>
 | 
					  <requires lib="libadwaita" version="1.4"/>
 | 
				
			||||||
  <object class="AdwComboRow" id="reset_card_entry">
 | 
					  <object class="AdwComboRow" id="reset_card_entry">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										25
									
								
								src/resources/resetError.ui
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/resources/resetError.ui
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,25 @@
 | 
				
			||||||
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
 | 
					<interface>
 | 
				
			||||||
 | 
					  <requires lib="gtk" version="4.12"/>
 | 
				
			||||||
 | 
					  <template class="resetError" parent="GtkPopover">
 | 
				
			||||||
 | 
					    <child>
 | 
				
			||||||
 | 
					      <object class="GtkBox">
 | 
				
			||||||
 | 
					        <property name="homogeneous">True</property>
 | 
				
			||||||
 | 
					        <property name="orientation">vertical</property>
 | 
				
			||||||
 | 
					        <child>
 | 
				
			||||||
 | 
					          <object class="GtkLabel" id="reset_error_label"/>
 | 
				
			||||||
 | 
					        </child>
 | 
				
			||||||
 | 
					        <child>
 | 
				
			||||||
 | 
					          <object class="GtkButton" id="reset_error_button">
 | 
				
			||||||
 | 
					            <property name="label">ok</property>
 | 
				
			||||||
 | 
					            <property name="margin-bottom">5</property>
 | 
				
			||||||
 | 
					            <property name="margin-end">5</property>
 | 
				
			||||||
 | 
					            <property name="margin-start">5</property>
 | 
				
			||||||
 | 
					            <property name="margin-top">5</property>
 | 
				
			||||||
 | 
					          </object>
 | 
				
			||||||
 | 
					        </child>
 | 
				
			||||||
 | 
					      </object>
 | 
				
			||||||
 | 
					    </child>
 | 
				
			||||||
 | 
					  </template>
 | 
				
			||||||
 | 
					</interface>
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.12"/>
 | 
					  <requires lib="gtk" version="4.12"/>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.4"/>
 | 
					  <requires lib="libadwaita" version="1.4"/>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.0"/>
 | 
					  <requires lib="gtk" version="4.0"/>
 | 
				
			||||||
  <template class="resetListBoxRow" parent="GtkListBoxRow">
 | 
					  <template class="resetListBoxRow" parent="GtkListBoxRow">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gio" version="2.0"/>
 | 
					  <requires lib="gio" version="2.0"/>
 | 
				
			||||||
  <requires lib="gtk" version="4.12"/>
 | 
					  <requires lib="gtk" version="4.12"/>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.12"/>
 | 
					  <requires lib="gtk" version="4.12"/>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.4"/>
 | 
					  <requires lib="libadwaita" version="1.4"/>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.12"/>
 | 
					  <requires lib="gtk" version="4.12"/>
 | 
				
			||||||
  <template class="resetPopup" parent="GtkPopover">
 | 
					  <template class="resetPopup" parent="GtkPopover">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.0"/>
 | 
					  <requires lib="libadwaita" version="1.0"/>
 | 
				
			||||||
  <template class="resetSavedWifiEntry" parent="AdwActionRow">
 | 
					  <template class="resetSavedWifiEntry" parent="AdwActionRow">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.0"/>
 | 
					  <requires lib="gtk" version="4.0"/>
 | 
				
			||||||
  <template class="resetSettingBox" parent="GtkBox">
 | 
					  <template class="resetSettingBox" parent="GtkBox">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.0"/>
 | 
					  <requires lib="gtk" version="4.0"/>
 | 
				
			||||||
  <object class="GtkShortcutsWindow" id="help_overlay">
 | 
					  <object class="GtkShortcutsWindow" id="help_overlay">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.0"/>
 | 
					  <requires lib="gtk" version="4.0"/>
 | 
				
			||||||
  <template class="resetSidebarEntry" parent="GtkListBoxRow">
 | 
					  <template class="resetSidebarEntry" parent="GtkListBoxRow">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.12"/>
 | 
					  <requires lib="gtk" version="4.12"/>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.3"/>
 | 
					  <requires lib="libadwaita" version="1.3"/>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.12"/>
 | 
					  <requires lib="gtk" version="4.12"/>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.3"/>
 | 
					  <requires lib="libadwaita" version="1.3"/>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
 | 
					<?xml version='1.0' encoding='UTF-8' standalone='no'?>
 | 
				
			||||||
<!DOCTYPE cambalache-project SYSTEM "cambalache-project.dtd">
 | 
					<!DOCTYPE cambalache-project SYSTEM "cambalache-project.dtd">
 | 
				
			||||||
<cambalache-project version="0.13.1" target_tk="gtk-4.0">
 | 
					<cambalache-project version="0.17.1" target_tk="gtk-4.0">
 | 
				
			||||||
  <ui>
 | 
					  <ui>
 | 
				
			||||||
	(3,1,None,"resetMainWindow.ui",None,None,None,None,None,None,None),
 | 
						(3,1,None,"resetMainWindow.ui",None,None,None,None,None,None,None),
 | 
				
			||||||
	(4,7,None,"resetWiFi.ui",None,None,None,None,None,None,None),
 | 
						(4,7,None,"resetWiFi.ui",None,None,None,None,None,None,None),
 | 
				
			||||||
| 
						 | 
					@ -22,7 +22,8 @@
 | 
				
			||||||
	(21,1,None,"resetWifiOptions.ui",None,None,None,None,None,None,None),
 | 
						(21,1,None,"resetWifiOptions.ui",None,None,None,None,None,None,None),
 | 
				
			||||||
	(22,1,None,"resetWifiAddressEntry.ui",None,None,None,None,None,None,None),
 | 
						(22,1,None,"resetWifiAddressEntry.ui",None,None,None,None,None,None,None),
 | 
				
			||||||
	(23,1,None,"resetWifiRouteEntry.ui",None,None,None,None,None,None,None),
 | 
						(23,1,None,"resetWifiRouteEntry.ui",None,None,None,None,None,None,None),
 | 
				
			||||||
	(24,None,None,"resetShortcuts.ui",None,None,None,None,None,None,None)
 | 
						(24,None,None,"resetShortcuts.ui",None,None,None,None,None,None,None),
 | 
				
			||||||
 | 
						(25,1,None,"resetError.ui",None,None,None,None,None,None,None)
 | 
				
			||||||
  </ui>
 | 
					  </ui>
 | 
				
			||||||
  <ui_library>
 | 
					  <ui_library>
 | 
				
			||||||
	(21,"gtk","4.12",None),
 | 
						(21,"gtk","4.12",None),
 | 
				
			||||||
| 
						 | 
					@ -76,6 +77,7 @@
 | 
				
			||||||
	(4,206,"AdwActionRow","reset_available_networks",205,None,None,None,-1,None),
 | 
						(4,206,"AdwActionRow","reset_available_networks",205,None,None,None,-1,None),
 | 
				
			||||||
	(4,207,"GtkImage",None,206,None,None,None,None,None),
 | 
						(4,207,"GtkImage",None,206,None,None,None,None,None),
 | 
				
			||||||
	(4,208,"AdwPreferencesGroup","reset_wifi_list",154,None,None,None,1,None),
 | 
						(4,208,"AdwPreferencesGroup","reset_wifi_list",154,None,None,None,1,None),
 | 
				
			||||||
 | 
						(4,209,"resetError","error",7,None,None,None,2,None),
 | 
				
			||||||
	(5,12,"AdwActionRow","resetWifiEntry",None,None,None,None,-1,None),
 | 
						(5,12,"AdwActionRow","resetWifiEntry",None,None,None,None,-1,None),
 | 
				
			||||||
	(5,13,"resetPopup","reset_wifi_popup",12,None,None,None,None,None),
 | 
						(5,13,"resetPopup","reset_wifi_popup",12,None,None,None,None,None),
 | 
				
			||||||
	(6,1,"GtkListBoxRow","resetSidebarEntry",None,None,None,None,None,None),
 | 
						(6,1,"GtkListBoxRow","resetSidebarEntry",None,None,None,None,None,None),
 | 
				
			||||||
| 
						 | 
					@ -126,6 +128,7 @@
 | 
				
			||||||
	(8,148,"GtkScale","reset_volume_slider",146,None,None,None,1,None),
 | 
						(8,148,"GtkScale","reset_volume_slider",146,None,None,None,1,None),
 | 
				
			||||||
	(8,149,"GtkAdjustment",None,148,None,None,None,None,None),
 | 
						(8,149,"GtkAdjustment",None,148,None,None,None,None,None),
 | 
				
			||||||
	(8,150,"GtkLabel","reset_volume_percentage",146,None,None,None,2,None),
 | 
						(8,150,"GtkLabel","reset_volume_percentage",146,None,None,None,2,None),
 | 
				
			||||||
 | 
						(8,151,"resetError","error",1,None,None,None,2,None),
 | 
				
			||||||
	(10,1,"GtkBox","resetBluetooth",None,None,None,None,None,None),
 | 
						(10,1,"GtkBox","resetBluetooth",None,None,None,None,None,None),
 | 
				
			||||||
	(10,119,"AdwNavigationView",None,1,None,None,None,1,None),
 | 
						(10,119,"AdwNavigationView",None,1,None,None,None,1,None),
 | 
				
			||||||
	(10,120,"AdwNavigationPage",None,119,None,None,None,None,None),
 | 
						(10,120,"AdwNavigationPage",None,119,None,None,None,None,None),
 | 
				
			||||||
| 
						 | 
					@ -148,6 +151,7 @@
 | 
				
			||||||
	(10,211,"AdwSwitchRow","reset_bluetooth_discoverable_switch",209,None,None,None,-1,None),
 | 
						(10,211,"AdwSwitchRow","reset_bluetooth_discoverable_switch",209,None,None,None,-1,None),
 | 
				
			||||||
	(10,212,"AdwActionRow","reset_bluetooth_main_tab",208,None,None,None,None,None),
 | 
						(10,212,"AdwActionRow","reset_bluetooth_main_tab",208,None,None,None,None,None),
 | 
				
			||||||
	(10,213,"GtkImage",None,212,None,None,None,None,None),
 | 
						(10,213,"GtkImage",None,212,None,None,None,None,None),
 | 
				
			||||||
 | 
						(10,214,"resetError","error",1,None,None,None,2,None),
 | 
				
			||||||
	(11,1,"AdwActionRow","resetBluetoothEntry",None,None,None,None,None,None),
 | 
						(11,1,"AdwActionRow","resetBluetoothEntry",None,None,None,None,None,None),
 | 
				
			||||||
	(12,11,"GtkBox","resetAudioInput",None,None,None,None,None,None),
 | 
						(12,11,"GtkBox","resetAudioInput",None,None,None,None,None,None),
 | 
				
			||||||
	(12,12,"GtkLabel",None,11,None,None,None,None,None),
 | 
						(12,12,"GtkLabel",None,11,None,None,None,None,None),
 | 
				
			||||||
| 
						 | 
					@ -183,6 +187,7 @@
 | 
				
			||||||
	(12,83,"GtkScale","reset_volume_slider",81,None,None,None,1,None),
 | 
						(12,83,"GtkScale","reset_volume_slider",81,None,None,None,1,None),
 | 
				
			||||||
	(12,84,"GtkAdjustment",None,83,None,None,None,None,None),
 | 
						(12,84,"GtkAdjustment",None,83,None,None,None,None,None),
 | 
				
			||||||
	(12,85,"GtkLabel","reset_volume_percentage",81,None,None,None,2,None),
 | 
						(12,85,"GtkLabel","reset_volume_percentage",81,None,None,None,2,None),
 | 
				
			||||||
 | 
						(12,86,"resetError","error",11,None,None,None,-1,None),
 | 
				
			||||||
	(13,22,"AdwPreferencesGroup","resetOutputStreamEntry",None,None,None,None,None,None),
 | 
						(13,22,"AdwPreferencesGroup","resetOutputStreamEntry",None,None,None,None,None,None),
 | 
				
			||||||
	(13,23,"AdwComboRow","reset_source_selection",22,None,None,None,None,None),
 | 
						(13,23,"AdwComboRow","reset_source_selection",22,None,None,None,None,None),
 | 
				
			||||||
	(13,26,"AdwActionRow",None,22,None,None,None,1,None),
 | 
						(13,26,"AdwActionRow",None,22,None,None,None,1,None),
 | 
				
			||||||
| 
						 | 
					@ -303,7 +308,11 @@
 | 
				
			||||||
	(24,3,"GtkShortcutsGroup",None,2,None,None,None,-1,None),
 | 
						(24,3,"GtkShortcutsGroup",None,2,None,None,None,-1,None),
 | 
				
			||||||
	(24,4,"GtkShortcutsShortcut",None,3,None,None,None,-1,None),
 | 
						(24,4,"GtkShortcutsShortcut",None,3,None,None,None,-1,None),
 | 
				
			||||||
	(24,5,"GtkShortcutsShortcut",None,3,None,None,None,-1,None),
 | 
						(24,5,"GtkShortcutsShortcut",None,3,None,None,None,-1,None),
 | 
				
			||||||
	(24,6,"GtkShortcutsShortcut",None,3,None,None,None,2,None)
 | 
						(24,6,"GtkShortcutsShortcut",None,3,None,None,None,2,None),
 | 
				
			||||||
 | 
						(25,1,"GtkPopover","resetError",None,None,None,None,None,None),
 | 
				
			||||||
 | 
						(25,2,"GtkBox",None,1,None,None,None,None,None),
 | 
				
			||||||
 | 
						(25,3,"GtkLabel","reset_error_label",2,None,None,None,None,None),
 | 
				
			||||||
 | 
						(25,5,"GtkButton","reset_error_button",2,None,None,None,2,None)
 | 
				
			||||||
  </object>
 | 
					  </object>
 | 
				
			||||||
  <object_property>
 | 
					  <object_property>
 | 
				
			||||||
	(3,1,"GtkWidget","height-request","200",None,None,None,None,None,None,None,None,None),
 | 
						(3,1,"GtkWidget","height-request","200",None,None,None,None,None,None,None,None,None),
 | 
				
			||||||
| 
						 | 
					@ -962,7 +971,14 @@
 | 
				
			||||||
	(24,6,"GtkShortcutsShortcut","accelerator","<Ctrl>H",None,None,None,None,None,None,None,None,None),
 | 
						(24,6,"GtkShortcutsShortcut","accelerator","<Ctrl>H",None,None,None,None,None,None,None,None,None),
 | 
				
			||||||
	(24,6,"GtkShortcutsShortcut","action-name","win.about",None,None,None,None,None,None,None,None,None),
 | 
						(24,6,"GtkShortcutsShortcut","action-name","win.about",None,None,None,None,None,None,None,None,None),
 | 
				
			||||||
	(24,6,"GtkShortcutsShortcut","icon-set","True",None,None,None,None,None,None,None,None,None),
 | 
						(24,6,"GtkShortcutsShortcut","icon-set","True",None,None,None,None,None,None,None,None,None),
 | 
				
			||||||
	(24,6,"GtkShortcutsShortcut","title","Show about window",None,None,None,None,None,None,None,None,None)
 | 
						(24,6,"GtkShortcutsShortcut","title","Show about window",None,None,None,None,None,None,None,None,None),
 | 
				
			||||||
 | 
						(25,2,"GtkBox","homogeneous","True",None,None,None,None,None,None,None,None,None),
 | 
				
			||||||
 | 
						(25,2,"GtkOrientable","orientation","vertical",None,None,None,None,None,None,None,None,None),
 | 
				
			||||||
 | 
						(25,5,"GtkButton","label","ok",None,None,None,None,None,None,None,None,None),
 | 
				
			||||||
 | 
						(25,5,"GtkWidget","margin-bottom","5",None,None,None,None,None,None,None,None,None),
 | 
				
			||||||
 | 
						(25,5,"GtkWidget","margin-end","5",None,None,None,None,None,None,None,None,None),
 | 
				
			||||||
 | 
						(25,5,"GtkWidget","margin-start","5",None,None,None,None,None,None,None,None,None),
 | 
				
			||||||
 | 
						(25,5,"GtkWidget","margin-top","5",None,None,None,None,None,None,None,None,None)
 | 
				
			||||||
  </object_property>
 | 
					  </object_property>
 | 
				
			||||||
  <object_data>
 | 
					  <object_data>
 | 
				
			||||||
	(3,42,"GtkWidget",1,1,None,None,None,None,None,None),
 | 
						(3,42,"GtkWidget",1,1,None,None,None,None,None,None),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.6"/>
 | 
					  <requires lib="gtk" version="4.6"/>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.4"/>
 | 
					  <requires lib="libadwaita" version="1.4"/>
 | 
				
			||||||
| 
						 | 
					@ -120,5 +120,8 @@
 | 
				
			||||||
        </child>
 | 
					        </child>
 | 
				
			||||||
      </object>
 | 
					      </object>
 | 
				
			||||||
    </child>
 | 
					    </child>
 | 
				
			||||||
 | 
					    <child>
 | 
				
			||||||
 | 
					      <object class="resetError" id="error"/>
 | 
				
			||||||
 | 
					    </child>
 | 
				
			||||||
  </template>
 | 
					  </template>
 | 
				
			||||||
</interface>
 | 
					</interface>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.12"/>
 | 
					  <requires lib="gtk" version="4.12"/>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.2"/>
 | 
					  <requires lib="libadwaita" version="1.2"/>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.0"/>
 | 
					  <requires lib="libadwaita" version="1.0"/>
 | 
				
			||||||
  <template class="resetWifiEntry" parent="AdwActionRow">
 | 
					  <template class="resetWifiEntry" parent="AdwActionRow">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.12"/>
 | 
					  <requires lib="gtk" version="4.12"/>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.4"/>
 | 
					  <requires lib="libadwaita" version="1.4"/>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<?xml version='1.0' encoding='UTF-8'?>
 | 
					<?xml version='1.0' encoding='UTF-8'?>
 | 
				
			||||||
<!-- Created with Cambalache 0.17.0 -->
 | 
					<!-- Created with Cambalache 0.17.2 -->
 | 
				
			||||||
<interface>
 | 
					<interface>
 | 
				
			||||||
  <requires lib="gtk" version="4.12"/>
 | 
					  <requires lib="gtk" version="4.12"/>
 | 
				
			||||||
  <requires lib="libadwaita" version="1.2"/>
 | 
					  <requires lib="libadwaita" version="1.2"/>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,6 +27,7 @@
 | 
				
			||||||
    <file compressed="true" preprocess="xml-stripblanks">resetSourceEntry.ui</file>
 | 
					    <file compressed="true" preprocess="xml-stripblanks">resetSourceEntry.ui</file>
 | 
				
			||||||
    <!--Misc-->
 | 
					    <!--Misc-->
 | 
				
			||||||
    <file compressed="true" preprocess="xml-stripblanks">resetPopup.ui</file>
 | 
					    <file compressed="true" preprocess="xml-stripblanks">resetPopup.ui</file>
 | 
				
			||||||
 | 
					    <file compressed="true" preprocess="xml-stripblanks">resetError.ui</file>
 | 
				
			||||||
    <file compressed="true" preprocess="xml-stripblanks" alias="gtk/help-overlay.ui">resetShortcuts.ui</file>
 | 
					    <file compressed="true" preprocess="xml-stripblanks" alias="gtk/help-overlay.ui">resetShortcuts.ui</file>
 | 
				
			||||||
    <file compressed="true" preprocess="xml-stripblanks">resetMenu.ui</file>
 | 
					    <file compressed="true" preprocess="xml-stripblanks">resetMenu.ui</file>
 | 
				
			||||||
    <file compressed="true" preprocess="xml-stripblanks">resetCardEntry.ui</file>
 | 
					    <file compressed="true" preprocess="xml-stripblanks">resetCardEntry.ui</file>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue