Skip to content

Commit

Permalink
Replace 'summary' method with 'description', with detail level argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinling committed Aug 5, 2024
1 parent 5e4f7e4 commit 4253aa3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
11 changes: 7 additions & 4 deletions src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,10 @@ pub trait ItemSource<Item> {
-> Result<Item, Error>;
fn item_children(&mut self, parent: Option<&Item>)
-> Result<(CompletionStatus, u64), Error>;
fn summary(&mut self, item: &Item) -> Result<String, Error>;
fn description(&mut self,
item: &Item,
detail: bool)
-> Result<String, Error>;
fn connectors(&mut self, item: &Item) -> Result<String, Error>;
fn timestamp(&mut self, item: &Item) -> Result<Timestamp, Error>;
}
Expand Down Expand Up @@ -1145,7 +1148,7 @@ impl ItemSource<TrafficItem> for CaptureReader {
})
}

fn summary(&mut self, item: &TrafficItem)
fn description(&mut self, item: &TrafficItem, _detail: bool)
-> Result<String, Error>
{
use PID::*;
Expand Down Expand Up @@ -1588,7 +1591,7 @@ impl ItemSource<DeviceItem> for CaptureReader {
Ok((completion, children as u64))
}

fn summary(&mut self, item: &DeviceItem)
fn description(&mut self, item: &DeviceItem, _detail: bool)
-> Result<String, Error>
{
use DeviceItem::*;
Expand Down Expand Up @@ -1692,7 +1695,7 @@ mod tests {
fn summarize_item(cap: &mut CaptureReader, item: &TrafficItem, depth: usize)
-> String
{
let mut summary = cap.summary(item).unwrap();
let mut summary = cap.description(item, false).unwrap();
let (_completion, num_children) =
cap.item_children(Some(item)).unwrap();
let child_ids = 0..num_children;
Expand Down
10 changes: 5 additions & 5 deletions src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub trait GenericModel<Item> where Self: Sized {
expanded: bool)
-> Result<(), Error>;
fn update(&self) -> Result<bool, Error>;
fn summary(&self, item: &Item) -> String;
fn description(&self, item: &Item, detail: bool) -> String;
fn timestamp(&self, item: &Item) -> u64;
fn connectors(&self, item: &Item) -> String;
}
Expand Down Expand Up @@ -75,10 +75,10 @@ impl GenericModel<TrafficItem> for TrafficModel {
tree.update(self)
}

fn summary(&self, item: &TrafficItem) -> String {
fn description(&self, item: &TrafficItem, detail: bool) -> String {
let tree_opt = self.imp().tree.borrow();
let tree = tree_opt.as_ref().unwrap();
tree.summary(item)
tree.description(item, detail)
}

fn timestamp(&self, item: &TrafficItem) -> u64 {
Expand Down Expand Up @@ -128,10 +128,10 @@ impl GenericModel<DeviceItem> for DeviceModel {
tree.update(self)
}

fn summary(&self, item: &DeviceItem) -> String {
fn description(&self, item: &DeviceItem, detail: bool) -> String {
let tree_opt = self.imp().tree.borrow();
let tree = tree_opt.as_ref().unwrap();
tree.summary(item)
tree.description(item, detail)
}

fn timestamp(&self, _item: &DeviceItem) -> u64 {
Expand Down
2 changes: 1 addition & 1 deletion src/record_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl Recording {
.borrow()
.item;
self.capture
.summary(&item)
.description(&item, false)
.expect("Failed to generate item summary")
}

Expand Down
6 changes: 3 additions & 3 deletions src/tree_list_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ where Item: 'static + Copy + Debug,

if item_updated {
// The node's description may change.
let summary = cap.summary(&item_node.item)?;
let summary = cap.description(&item_node.item, false)?;
#[cfg(any(test, feature="record-ui-test"))]
if let Ok(position) = u32::try_from(position) {
let mut on_item_update = self.on_item_update.borrow_mut();
Expand Down Expand Up @@ -948,9 +948,9 @@ where Item: 'static + Copy + Debug,
cap.timestamp(item).unwrap_or(0)
}

pub fn summary(&self, item: &Item) -> String {
pub fn description(&self, item: &Item, detail: bool) -> String {
let mut cap = self.capture.borrow_mut();
match cap.summary(item) {
match cap.description(item, detail) {
Ok(string) => string,
Err(e) => format!("Error: {e:?}")
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ fn create_view<Item, Model, RowData>(
match row.node() {
Ok(node_ref) => {
let node = node_ref.borrow();
let summary = bind_model.summary(&node.item);
let summary = bind_model.description(&node.item, false);
let connectors = bind_model.connectors(&node.item);
expander_wrapper.set_text(summary);
expander_wrapper.set_connectors(connectors);
Expand Down Expand Up @@ -748,7 +748,7 @@ pub fn reset_capture() -> Result<CaptureWriter, Error> {
match row.node() {
Ok(node_ref) => {
let node = node_ref.borrow();
traffic_model.summary(&node.item)
traffic_model.description(&node.item, true)
},
Err(msg) => String::from(msg)
}
Expand Down

0 comments on commit 4253aa3

Please sign in to comment.