diff --git a/src/backend/manager.rs b/src/backend/manager.rs index f9ce843..caacff2 100644 --- a/src/backend/manager.rs +++ b/src/backend/manager.rs @@ -343,6 +343,17 @@ impl PwvucontrolManager { } None } + + pub fn get_model_for_nodetype(&self, nodetype: NodeType) -> PwNodeFilterModel { + match nodetype { + NodeType::Sink => self.sink_model(), + NodeType::Source => self.source_model(), + NodeType::StreamInput => self.stream_input_model(), + NodeType::StreamOutput => self.stream_output_model(), + _ => unreachable!() + } + } + } impl Default for PwvucontrolManager { diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 84f0111..a74f1a9 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -3,9 +3,9 @@ mod levelprovider; mod volumebox; mod window; mod withdefaultlistmodel; -mod output_dropdown; +mod stream_dropdown; mod sinkbox; -mod outputbox; +mod streambox; mod profile_dropdown; mod devicebox; mod profilerow; @@ -16,10 +16,10 @@ pub use window::PwvucontrolWindowView; pub use profile_dropdown::PwProfileDropDown; pub use withdefaultlistmodel::WithDefaultListModel; pub use volumebox::{PwVolumeBox, PwVolumeBoxImpl}; -pub use output_dropdown::PwOutputDropDown; +pub use stream_dropdown::PwOutputDropDown; pub use sinkbox::PwSinkBox; pub use channelbox::PwChannelBox; pub use levelprovider::LevelbarProvider; -pub use outputbox::PwOutputBox; +pub use streambox::PwOutputBox; pub use profilerow::PwProfileRow; pub use route_dropdown::PwRouteDropDown; diff --git a/src/ui/output_dropdown.rs b/src/ui/stream_dropdown.rs similarity index 87% rename from src/ui/output_dropdown.rs rename to src/ui/stream_dropdown.rs index e976cda..4c27a3d 100644 --- a/src/ui/output_dropdown.rs +++ b/src/ui/stream_dropdown.rs @@ -11,13 +11,15 @@ use std::cell::{Cell, RefCell}; use wireplumber as wp; mod imp { + use crate::{backend::NodeType, pwvucontrol_warning}; + use super::*; #[derive(Debug, Default, gtk::CompositeTemplate, glib::Properties)] #[properties(wrapper_type = super::PwOutputDropDown)] #[template(resource = "/com/saivert/pwvucontrol/gtk/output-dropdown.ui")] - pub struct PwOutputDropDown { - #[property(get, set, nullable)] + pub struct PwStreamDropDown { + #[property(get, set = Self::set_nodeobj, nullable)] pub(super) nodeobj: RefCell>, #[template_child] @@ -28,7 +30,7 @@ mod imp { } #[glib::object_subclass] - impl ObjectSubclass for PwOutputDropDown { + impl ObjectSubclass for PwStreamDropDown { const NAME: &'static str = "PwOutputDropDown"; type Type = super::PwOutputDropDown; type ParentType = gtk::Widget; @@ -45,12 +47,29 @@ mod imp { } #[gtk::template_callbacks] - impl PwOutputDropDown { + impl PwStreamDropDown { + fn set_nodeobj(&self, nodeobj: Option<&PwNodeObject>) { + let manager = PwvucontrolManager::default(); + + let Some(nodeobj) = nodeobj else { + pwvucontrol_warning!("PwOutputDropDown::set_nodeobj: Tried to set nodeobj to None"); + return; + }; + + let model = match nodeobj.nodetype() { + NodeType::StreamOutput => manager.sink_model(), + NodeType::StreamInput => manager.source_model(), + _ => return, + }; + + self.dropdown_model.replace(WithDefaultListModel::new(Some(&model))); + self.outputdevice_dropdown.set_model(Some(&*self.dropdown_model.borrow())); + } } #[glib::derived_properties] - impl ObjectImpl for PwOutputDropDown { + impl ObjectImpl for PwStreamDropDown { // Needed for direct subclasses of GtkWidget; // Here you need to unparent all direct children // of your template. @@ -61,7 +80,6 @@ mod imp { fn constructed(&self) { self.parent_constructed(); - let manager = PwvucontrolManager::default(); fn setup_handler(item: &glib::Object) { @@ -99,8 +117,6 @@ mod imp { self.outputdevice_dropdown.set_factory(Some(&factory)); self.outputdevice_dropdown.set_list_factory(default_dropdown_factory.as_ref()); - let sinkmodel = &manager.sink_model(); - self.outputdevice_dropdown.set_enable_search(true); @@ -116,8 +132,6 @@ mod imp { }), ))); - self.dropdown_model.replace(WithDefaultListModel::new(Some(sinkmodel))); - self.outputdevice_dropdown.set_model(Some(&*self.dropdown_model.borrow())); let widget = self.obj(); let selected_handler = closure_local!( @@ -146,11 +160,11 @@ mod imp { } } - impl WidgetImpl for PwOutputDropDown {} + impl WidgetImpl for PwStreamDropDown {} } glib::wrapper! { - pub struct PwOutputDropDown(ObjectSubclass) @extends gtk::Widget; + pub struct PwOutputDropDown(ObjectSubclass) @extends gtk::Widget; } impl PwOutputDropDown { diff --git a/src/ui/outputbox.rs b/src/ui/streambox.rs similarity index 91% rename from src/ui/outputbox.rs rename to src/ui/streambox.rs index 8bbb080..c556cf0 100644 --- a/src/ui/outputbox.rs +++ b/src/ui/streambox.rs @@ -16,13 +16,13 @@ mod imp { #[derive(Default, gtk::CompositeTemplate)] #[template(resource = "/com/saivert/pwvucontrol/gtk/outputbox.ui")] - pub struct PwOutputBox { + pub struct PwStreamBox { #[template_child] pub output_dropdown: TemplateChild, } #[glib::object_subclass] - impl ObjectSubclass for PwOutputBox { + impl ObjectSubclass for PwStreamBox { const NAME: &'static str = "PwOutputBox"; type Type = super::PwOutputBox; type ParentType = PwVolumeBox; @@ -36,7 +36,7 @@ mod imp { } } - impl ObjectImpl for PwOutputBox { + impl ObjectImpl for PwStreamBox { fn constructed(&self) { let manager = PwvucontrolManager::default(); @@ -49,7 +49,7 @@ mod imp { self.parent_constructed(); - if let Some(metadata) = manager.imp().metadata.borrow().as_ref() { + if let Some(metadata) = manager.metadata() { let boundid = item.boundid(); let widget = self.obj(); let changed_closure = closure_local!(@watch widget => @@ -71,15 +71,15 @@ mod imp { })); } } - impl WidgetImpl for PwOutputBox {} - impl ListBoxRowImpl for PwOutputBox {} - impl PwVolumeBoxImpl for PwOutputBox {} + impl WidgetImpl for PwStreamBox {} + impl ListBoxRowImpl for PwStreamBox {} + impl PwVolumeBoxImpl for PwStreamBox {} - impl PwOutputBox {} + impl PwStreamBox {} } glib::wrapper! { - pub struct PwOutputBox(ObjectSubclass) + pub struct PwOutputBox(ObjectSubclass) @extends gtk::Widget, gtk::ListBoxRow, PwVolumeBox, @implements gtk::Actionable; } @@ -92,7 +92,9 @@ impl PwOutputBox { pub(crate) fn update_output_device_dropdown(&self) { let manager = PwvucontrolManager::default(); - let sinkmodel = manager.sink_model(); + let item = self.node_object().expect("nodeobj"); + + let sinkmodel = manager.get_model_for_nodetype(item.nodetype()); let imp = self.imp(); @@ -107,7 +109,6 @@ impl PwOutputBox { }; output_dropdown.set_default_text(&string); - let item = self.node_object().expect("nodeobj"); if let Some(deftarget) = item.default_target() { // let model: gio::ListModel = imp diff --git a/src/ui/window.rs b/src/ui/window.rs index 0704baf..f58605b 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -108,7 +108,7 @@ mod imp { self.recordlist.bind_model( Some(&manager.stream_input_model()), clone!(@weak self as window => @default-panic, move |item| { - PwVolumeBox::new( + PwOutputBox::new( item.downcast_ref::() .expect("RowData is of wrong type"), )