Skip to content

Commit

Permalink
Add source dropdown in record tab.
Browse files Browse the repository at this point in the history
  • Loading branch information
saivert committed May 10, 2024
1 parent ac9da6a commit fa81e76
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 28 deletions.
11 changes: 11 additions & 0 deletions src/backend/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
38 changes: 26 additions & 12 deletions src/ui/output_dropdown.rs → src/ui/stream_dropdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<PwNodeObject>>,

#[template_child]
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -61,7 +80,6 @@ mod imp {
fn constructed(&self) {
self.parent_constructed();

let manager = PwvucontrolManager::default();


fn setup_handler(item: &glib::Object) {
Expand Down Expand Up @@ -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);


Expand All @@ -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!(
Expand Down Expand Up @@ -146,11 +160,11 @@ mod imp {
}
}

impl WidgetImpl for PwOutputDropDown {}
impl WidgetImpl for PwStreamDropDown {}
}

glib::wrapper! {
pub struct PwOutputDropDown(ObjectSubclass<imp::PwOutputDropDown>) @extends gtk::Widget;
pub struct PwOutputDropDown(ObjectSubclass<imp::PwStreamDropDown>) @extends gtk::Widget;
}

impl PwOutputDropDown {
Expand Down
23 changes: 12 additions & 11 deletions src/ui/outputbox.rs → src/ui/streambox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PwOutputDropDown>,
}

#[glib::object_subclass]
impl ObjectSubclass for PwOutputBox {
impl ObjectSubclass for PwStreamBox {
const NAME: &'static str = "PwOutputBox";
type Type = super::PwOutputBox;
type ParentType = PwVolumeBox;
Expand All @@ -36,7 +36,7 @@ mod imp {
}
}

impl ObjectImpl for PwOutputBox {
impl ObjectImpl for PwStreamBox {
fn constructed(&self) {
let manager = PwvucontrolManager::default();

Expand All @@ -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 =>
Expand All @@ -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<imp::PwOutputBox>)
pub struct PwOutputBox(ObjectSubclass<imp::PwStreamBox>)
@extends gtk::Widget, gtk::ListBoxRow, PwVolumeBox,
@implements gtk::Actionable;
}
Expand All @@ -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();

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<PwNodeObject>()
.expect("RowData is of wrong type"),
)
Expand Down

0 comments on commit fa81e76

Please sign in to comment.