Skip to content

Commit

Permalink
Also set profile when changing route if needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
saivert committed May 1, 2024
1 parent 57dd4a0 commit 5b8ffe1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/backend/pwdeviceobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ impl PwDeviceObject {
let description_key = keys.find_value_from_short_name("description").expect("decription key");
let available_key = keys.find_value_from_short_name("available").expect("available key");
let direction_key = keys.find_value_from_short_name("direction").expect("direction key");
let profiles_key = keys.find_value_from_short_name("profiles").expect("profiles key");

if let Ok(Some(iter)) = res {
let removed = widget.imp().routemodel.n_items();
Expand All @@ -282,8 +283,11 @@ impl PwDeviceObject {
let description = pod.find_spa_property(&description_key).expect("Format!").string().expect("String");
let available = pod.find_spa_property(&available_key).expect("Availability!").id().expect("Id");
let direction = pod.find_spa_property(&direction_key).expect("Direction!").id().expect("Id");
let profiles = pod.find_spa_property(&profiles_key).expect("Profiles!");
assert!(profiles.is_array());
let profiles_vec: Vec<u32> = profiles.array_iterator::<i32>().map(|x| x as u32).collect();

routes.push(PwRouteObject::new(index as u32, &description, available, direction));
routes.push(PwRouteObject::new(index as u32, &description, available, direction, &profiles_vec));
}
widget.imp().routemodel.splice(0, removed as u32, &routes);

Expand Down
12 changes: 10 additions & 2 deletions src/backend/pwnodeobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use glib::{self, clone, subclass::{prelude::*, Signal}, ObjectExt, ParamSpec, Pr
use once_cell::sync::{Lazy, OnceCell};
use gtk::{gio, prelude::ListModelExt};
use crate::backend::PwChannelObject;
use super::{PwDeviceObject, PwvucontrolManager};
use super::{PwDeviceObject, PwRouteObject, PwvucontrolManager};
use crate::macros::*;

mod mixerapi;
Expand Down Expand Up @@ -491,9 +491,17 @@ impl PwNodeObject {
None
}

pub(crate) fn set_route(&self, index: u32) {
pub(crate) fn set_route(&self, routeobj: &PwRouteObject) {
let index = routeobj.index();
if let Ok(Some(card_profile_device)) = self.wpnode().device_index() {
if let Some(device) = self.get_device() {
let profiles = routeobj.get_profiles();
if !profiles.is_empty() {
if device.profile_index() != profiles[0] {
device.set_profile(profiles[0] as i32);
}
}

device.set_route(index, card_profile_device as i32);
}
}
Expand Down
21 changes: 18 additions & 3 deletions src/backend/pwrouteobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ mod imp {
availability: Cell<ParamAvailability>,
#[property(get, set, builder(RouteDirection::Unknown))]
direction: Cell<RouteDirection>,

pub(super) profiles: RefCell<Vec<u32>>,
}

#[glib::object_subclass]
Expand All @@ -44,12 +46,25 @@ glib::wrapper! {
}

impl PwRouteObject {
pub(crate) fn new(index: u32, description: &str, availability: u32, direction: u32) -> Self {
glib::Object::builder()
pub(crate) fn new(index: u32, description: &str, availability: u32, direction: u32, profiles: &[u32]) -> Self {
let new: PwRouteObject = glib::Object::builder()
.property("index", index)
.property("description", format!("{description} ({index})"))
.property("availability", ParamAvailability::from(availability))
.property("direction", RouteDirection::from(direction))
.build()
.build();

new.set_profiles(profiles);

new
}

pub(crate) fn get_profiles(&self) -> Vec<u32> {
self.imp().profiles.borrow().clone()
}

pub(crate) fn set_profiles(&self, list: &[u32]) {
self.imp().profiles.replace(list.to_vec());
}

}
3 changes: 1 addition & 2 deletions src/ui/route_dropdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ mod imp {
self.route_dropdown.set_factory(Some(&factory));
self.route_dropdown.set_list_factory(Some(&list_factory));

self.route_dropdown.set_enable_search(true);

let widget = self.obj();
let selected_handler = closure_local!(
Expand All @@ -188,7 +187,7 @@ mod imp {
pwvucontrol_critical!("Had set profile to {}", dropdown.selected());

if let Some(routeobject) = dropdown.selected_item().and_downcast::<PwRouteObject>() {
nodeobject.set_route(routeobject.index());
nodeobject.set_route(&routeobject);
}

}
Expand Down

0 comments on commit 5b8ffe1

Please sign in to comment.