Skip to content

Commit 5b8ffe1

Browse files
committed
Also set profile when changing route if needed.
1 parent 57dd4a0 commit 5b8ffe1

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

src/backend/pwdeviceobject.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ impl PwDeviceObject {
265265
let description_key = keys.find_value_from_short_name("description").expect("decription key");
266266
let available_key = keys.find_value_from_short_name("available").expect("available key");
267267
let direction_key = keys.find_value_from_short_name("direction").expect("direction key");
268+
let profiles_key = keys.find_value_from_short_name("profiles").expect("profiles key");
268269

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

286-
routes.push(PwRouteObject::new(index as u32, &description, available, direction));
290+
routes.push(PwRouteObject::new(index as u32, &description, available, direction, &profiles_vec));
287291
}
288292
widget.imp().routemodel.splice(0, removed as u32, &routes);
289293

src/backend/pwnodeobject.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use glib::{self, clone, subclass::{prelude::*, Signal}, ObjectExt, ParamSpec, Pr
1111
use once_cell::sync::{Lazy, OnceCell};
1212
use gtk::{gio, prelude::ListModelExt};
1313
use crate::backend::PwChannelObject;
14-
use super::{PwDeviceObject, PwvucontrolManager};
14+
use super::{PwDeviceObject, PwRouteObject, PwvucontrolManager};
1515
use crate::macros::*;
1616

1717
mod mixerapi;
@@ -491,9 +491,17 @@ impl PwNodeObject {
491491
None
492492
}
493493

494-
pub(crate) fn set_route(&self, index: u32) {
494+
pub(crate) fn set_route(&self, routeobj: &PwRouteObject) {
495+
let index = routeobj.index();
495496
if let Ok(Some(card_profile_device)) = self.wpnode().device_index() {
496497
if let Some(device) = self.get_device() {
498+
let profiles = routeobj.get_profiles();
499+
if !profiles.is_empty() {
500+
if device.profile_index() != profiles[0] {
501+
device.set_profile(profiles[0] as i32);
502+
}
503+
}
504+
497505
device.set_route(index, card_profile_device as i32);
498506
}
499507
}

src/backend/pwrouteobject.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ mod imp {
2525
availability: Cell<ParamAvailability>,
2626
#[property(get, set, builder(RouteDirection::Unknown))]
2727
direction: Cell<RouteDirection>,
28+
29+
pub(super) profiles: RefCell<Vec<u32>>,
2830
}
2931

3032
#[glib::object_subclass]
@@ -44,12 +46,25 @@ glib::wrapper! {
4446
}
4547

4648
impl PwRouteObject {
47-
pub(crate) fn new(index: u32, description: &str, availability: u32, direction: u32) -> Self {
48-
glib::Object::builder()
49+
pub(crate) fn new(index: u32, description: &str, availability: u32, direction: u32, profiles: &[u32]) -> Self {
50+
let new: PwRouteObject = glib::Object::builder()
4951
.property("index", index)
5052
.property("description", format!("{description} ({index})"))
5153
.property("availability", ParamAvailability::from(availability))
5254
.property("direction", RouteDirection::from(direction))
53-
.build()
55+
.build();
56+
57+
new.set_profiles(profiles);
58+
59+
new
60+
}
61+
62+
pub(crate) fn get_profiles(&self) -> Vec<u32> {
63+
self.imp().profiles.borrow().clone()
64+
}
65+
66+
pub(crate) fn set_profiles(&self, list: &[u32]) {
67+
self.imp().profiles.replace(list.to_vec());
5468
}
69+
5570
}

src/ui/route_dropdown.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ mod imp {
174174
self.route_dropdown.set_factory(Some(&factory));
175175
self.route_dropdown.set_list_factory(Some(&list_factory));
176176

177-
self.route_dropdown.set_enable_search(true);
178177

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

190189
if let Some(routeobject) = dropdown.selected_item().and_downcast::<PwRouteObject>() {
191-
nodeobject.set_route(routeobject.index());
190+
nodeobject.set_route(&routeobject);
192191
}
193192

194193
}

0 commit comments

Comments
 (0)