pub mod mock {
use std::rc::Rc;
use crate::widgets::list_widget::list_widget_item::ListWidgetItem;
#[derive(Clone, Debug)]
pub struct MockFile {
name: String,
size: usize,
_filetype: Option<String>,
}
impl MockFile {
pub fn new(name: String, size: usize) -> Self {
MockFile {
name,
size,
_filetype: None,
}
}
pub fn with_filetype(self, filetype: String) -> Self {
MockFile {
_filetype: Some(filetype),
..self
}
}
}
impl ListWidgetItem for MockFile {
fn len_columns() -> usize {
3
}
fn get_column_name(idx: usize) -> &'static str {
match idx {
0 => "filename",
1 => "size",
2 => "type",
_ => "N/A",
}
}
fn get(&self, idx: usize) -> Option<Rc<String>> {
match idx {
0 => Some(Rc::new(self.name.clone())),
1 => Some(Rc::new(format!("{}", self.size))),
_ => None,
}
}
fn get_min_column_width(idx: usize) -> u16 {
match idx {
0 => 20,
1 => 12,
2 => 5,
_ => 0,
}
}
}
pub fn get_mock_file_list() -> Vec<MockFile> {
let mut res: Vec<MockFile> = vec![];
for i in 0..10 {
res.push(MockFile::new(format!("text_file_{}.txt", i), 1000 + i).with_filetype("txt".to_string()));
res.push(MockFile::new(format!("photo_{}.png", i), 30000 + i).with_filetype("png".to_string()));
}
res
}
}