From 2a7137e6dccb74ae0dbe9f2f246967571654a9c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Tue, 11 Jan 2022 13:43:25 +0100 Subject: [PATCH] graphview: code cleanup Remove dead code Rewrite error message Use simplified anyhow result for xml methods --- src/graphmanager/graphview.rs | 6 +++--- src/graphmanager/node.rs | 5 ++--- src/graphmanager/port.rs | 21 ++------------------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/graphmanager/graphview.rs b/src/graphmanager/graphview.rs index e0af894..43a252f 100644 --- a/src/graphmanager/graphview.rs +++ b/src/graphmanager/graphview.rs @@ -40,7 +40,7 @@ use gtk::{ use log::{error, warn}; use std::cell::RefMut; -use std::{cmp::Ordering, collections::HashMap, error}; +use std::{cmp::Ordering, collections::HashMap}; static GRAPHVIEW_STYLE: &str = include_str!("graphview.css"); @@ -771,7 +771,7 @@ impl GraphView { self.queue_draw(); } - pub fn render_xml(&self, filename: &str) -> anyhow::Result<(), Box> { + pub fn render_xml(&self, filename: &str) -> anyhow::Result<()> { let mut file = File::create(filename).unwrap(); let mut writer = EmitterConfig::new() .perform_indent(true) @@ -825,7 +825,7 @@ impl GraphView { Ok(()) } - pub fn load_xml(&self, filename: &str) -> anyhow::Result<(), Box> { + pub fn load_xml(&self, filename: &str) -> anyhow::Result<()> { let file = File::open(filename).unwrap(); let file = BufReader::new(file); diff --git a/src/graphmanager/node.rs b/src/graphmanager/node.rs index 3d4cc7d..b58aaf5 100644 --- a/src/graphmanager/node.rs +++ b/src/graphmanager/node.rs @@ -170,7 +170,7 @@ impl Node { pub fn new(id: u32, name: &str, node_type: NodeType) -> Self { let res: Self = glib::Object::new(&[]).expect("Failed to create Node"); let private = imp::Node::from_instance(&res); - private.id.set(id).expect("Node id already set"); + private.id.set(id).expect("Node id is already set"); res.set_name(name); res.add_css_class("node"); private @@ -183,7 +183,6 @@ impl Node { fn set_name(&self, name: &str) { let self_ = imp::Node::from_instance(self); self_.name.set_text(name); - println!("{}", name); } fn set_description(&self, description: &str) { @@ -276,7 +275,7 @@ impl Node { pub fn add_property(&self, name: String, value: String) { let private = imp::Node::from_instance(self); - println!("{} {} updated", name, value); + println!("property name={} updated with value={}", name, value); private.properties.borrow_mut().insert(name, value); self.update_description(); } diff --git a/src/graphmanager/port.rs b/src/graphmanager/port.rs index e268990..f4f88ec 100644 --- a/src/graphmanager/port.rs +++ b/src/graphmanager/port.rs @@ -18,7 +18,7 @@ // // SPDX-License-Identifier: GPL-3.0-only use gtk::{ - glib::{self, subclass::Signal}, + glib::{self}, prelude::*, subclass::prelude::*, }; @@ -36,8 +36,6 @@ pub enum PortDirection { impl fmt::Display for PortDirection { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self) - // or, alternatively: - // fmt::Debug::fmt(self, f) } } @@ -54,7 +52,7 @@ impl PortDirection { mod imp { use super::*; - use once_cell::{sync::Lazy, unsync::OnceCell}; + use once_cell::unsync::OnceCell; /// Graphical representation of a pipewire port. #[derive(Default, Clone)] @@ -85,21 +83,6 @@ mod imp { label.unparent() } } - - fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { - vec![Signal::builder( - "port-toggled", - // Provide id of output port and input port to signal handler. - &[::static_type().into(), ::static_type().into()], - // signal handler sends back nothing. - <()>::static_type().into(), - ) - .build()] - }); - - SIGNALS.as_ref() - } } impl WidgetImpl for Port {} }