Skip to content

Commit

Permalink
Remove PwNodeModel, use gio::ListStore instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
saivert committed May 10, 2024
1 parent fa81e76 commit f4a90bc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 96 deletions.
24 changes: 19 additions & 5 deletions src/backend/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::macros::*;
use crate::{
backend::NodeType, backend::PwDeviceObject, backend::PwNodeFilterModel, backend::PwNodeModel, backend::PwNodeObject, ui::PwvucontrolWindow,
backend::NodeType, backend::PwDeviceObject, backend::PwNodeFilterModel, backend::PwNodeObject, ui::PwvucontrolWindow,
ui::PwvucontrolWindowView, PwvucontrolApplication,
};
use gtk::{
Expand Down Expand Up @@ -32,7 +32,7 @@ mod imp {
pub wp_object_manager: OnceCell<wp::registry::ObjectManager>,

#[property(get)]
pub(crate) node_model: PwNodeModel,
pub(crate) node_model: gio::ListStore,

#[property(get)]
pub(crate) stream_output_model: PwNodeFilterModel,
Expand Down Expand Up @@ -67,7 +67,7 @@ mod imp {
Self {
wp_core: Default::default(),
wp_object_manager: Default::default(),
node_model: Default::default(),
node_model: gio::ListStore::new::<PwNodeObject>(),
stream_input_model: PwNodeFilterModel::new(NodeType::StreamInput, None::<gio::ListModel>),
stream_output_model: PwNodeFilterModel::new(NodeType::StreamOutput, None::<gio::ListModel>),
source_model: PwNodeFilterModel::new(NodeType::Source, None::<gio::ListModel>),
Expand Down Expand Up @@ -215,8 +215,7 @@ mod imp {
wp_om.connect_object_removed(clone!(@weak self as imp => move |_, object| {
if let Some(node) = object.dynamic_cast_ref::<wp::pw::Node>() {
pwvucontrol_info!("removed: {:?} id: {}", node.name(), node.bound_id());
let model = &imp.node_model;
model.remove(node.bound_id());
imp.obj().remove_node_by_id(node.bound_id());
} else if let Some(device) = object.dynamic_cast_ref::<wp::pw::Device>() {
imp.obj().remove_device_by_id(device.bound_id());
} else {
Expand Down Expand Up @@ -344,6 +343,21 @@ impl PwvucontrolManager {
None
}

pub fn remove_node_by_id(&self, id: u32) {
let nodemodel = &self.imp().node_model;

for (i, item) in (0..).zip(nodemodel.iter::<PwNodeObject>()) {
if let Ok(item) = item {
if item.wpnode().bound_id() == id {
nodemodel.remove(i);
break;
}
} else {
panic!("Device model mutated during iteration!");
}
}
}

pub fn get_model_for_nodetype(&self, nodetype: NodeType) -> PwNodeFilterModel {
match nodetype {
NodeType::Sink => self.sink_model(),
Expand Down
2 changes: 0 additions & 2 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ mod pwchannelobject;
mod manager;
mod pwdeviceobject;
mod pwprofileobject;
mod pwnodemodel;
mod pwnodeobject;
mod pwrouteobject;
mod routedirection;
Expand All @@ -15,7 +14,6 @@ pub use pwchannelobject::PwChannelObject;
pub use manager::PwvucontrolManager;
pub use pwdeviceobject::PwDeviceObject;
pub use pwprofileobject::PwProfileObject;
pub use pwnodemodel::PwNodeModel;
pub use pwnodeobject::{PwNodeObject, NodeType};
pub use pwrouteobject::PwRouteObject;
pub use routedirection::RouteDirection;
Expand Down
83 changes: 0 additions & 83 deletions src/backend/pwnodemodel.rs

This file was deleted.

6 changes: 0 additions & 6 deletions src/ui/volumebox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,6 @@ glib::wrapper! {
}

impl PwVolumeBox {
pub(crate) fn new(channel_object: &impl glib::IsA<PwNodeObject>) -> Self {
glib::Object::builder()
.property("node-object", channel_object)
//.property("channelmodel", gio::ListStore::new::<PwChannelObject>())
.build()
}

pub(crate) fn set_level(&self, level: f32) {
self.imp().level.set(level);
Expand Down

0 comments on commit f4a90bc

Please sign in to comment.