From 49571b0f8253edb4c123f672a43122941938f8fd Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Thu, 21 Mar 2024 23:30:24 -0400 Subject: [PATCH] Show real information in the library view --- kifu/core/src/api.rs | 1 - kifu/core/src/database.rs | 6 ++++-- kifu/core/src/library.rs | 8 +++----- kifu/gtk/src/components/library.rs | 18 +++++++++--------- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/kifu/core/src/api.rs b/kifu/core/src/api.rs index e87d7c7..405d63b 100644 --- a/kifu/core/src/api.rs +++ b/kifu/core/src/api.rs @@ -126,7 +126,6 @@ impl Core { println!("config: {:?}", config); let library = if let Some(ref path) = config.get::() { - println!("loading initial library"); Some(Database::open_path(path.to_path_buf()).unwrap()) } else { None diff --git a/kifu/core/src/database.rs b/kifu/core/src/database.rs index 1fbb9ca..796d0ca 100644 --- a/kifu/core/src/database.rs +++ b/kifu/core/src/database.rs @@ -43,10 +43,12 @@ impl Database { match parse_sgf(&buffer) { Ok(sgfs) => { for sgf in sgfs { - games.push(sgf); + if let Ok(sgf) = sgf { + games.push(sgf); + } } } - Err(err) => println!("Error parsing {:?}: {:?}", entry.path(), err), + Err(err) => println!("Error parsing {:?}", entry.path()), } } } diff --git a/kifu/core/src/library.rs b/kifu/core/src/library.rs index 3bf88f4..ddeb4ec 100644 --- a/kifu/core/src/library.rs +++ b/kifu/core/src/library.rs @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with Kif use crate::{Core, Config}; use serde::{Deserialize, Serialize}; -use sgf::GameInfo; +use sgf::Game; #[derive(Clone, Debug, Serialize, Deserialize)] pub enum LibraryRequest { @@ -25,16 +25,14 @@ pub enum LibraryRequest { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum LibraryResponse { - Games(Vec) + Games(Vec) } async fn handle_list_games(model: &Core) -> LibraryResponse { - println!("handle_list_games"); let library = model.library(); - println!("library: {:?}", *library); match *library { Some(ref library) => { - let info = library.all_games().map(|g| g.info.clone()).collect::>(); + let info = library.all_games().map(|g| g.clone()).collect::>(); LibraryResponse::Games(info) } None => LibraryResponse::Games(vec![]), diff --git a/kifu/gtk/src/components/library.rs b/kifu/gtk/src/components/library.rs index 1ec5aef..0cdec79 100644 --- a/kifu/gtk/src/components/library.rs +++ b/kifu/gtk/src/components/library.rs @@ -2,12 +2,12 @@ use adw::{prelude::*, subclass::prelude::*}; use glib::Object; use gtk::glib; // use kifu_core::ui::GamePreviewElement; -use sgf::GameInfo; +use sgf::Game; use std::{cell::RefCell, rc::Rc}; #[derive(Default)] pub struct GameObjectPrivate { - game: Rc>>, + game: Rc>>, } #[glib::object_subclass] @@ -23,13 +23,13 @@ glib::wrapper! { } impl GameObject { - pub fn new(game: GameInfo) -> Self { + pub fn new(game: Game) -> Self { let s: Self = Object::builder().build(); *s.imp().game.borrow_mut() = Some(game); s } - pub fn game(&self) -> Option { + pub fn game(&self) -> Option { self.imp().game.borrow().clone() } } @@ -85,7 +85,7 @@ impl Default for LibraryPrivate { fn make_factory(bind: F) -> gtk::SignalListItemFactory where - F: Fn(GameInfo) -> String + 'static, + F: Fn(Game) -> String + 'static, { let factory = gtk::SignalListItemFactory::new(); factory.connect_setup(|_, list_item| { @@ -114,7 +114,7 @@ impl Default for LibraryPrivate { >k::ColumnViewColumn::builder() .title("date") .factory(&make_factory(|g| { - g.date + g.dates .iter() .map(|date| { format!("{}", date) @@ -146,7 +146,7 @@ impl Default for LibraryPrivate { >k::ColumnViewColumn::builder() .title("black") .factory(&make_factory(|g| { - g.black_player.unwrap_or("Black".to_owned()) + g.black_player.name.unwrap_or("Black".to_owned()) })) .expand(true) .build(), @@ -155,7 +155,7 @@ impl Default for LibraryPrivate { >k::ColumnViewColumn::builder() .title("white") .factory(&make_factory(|g| { - g.white_player.unwrap_or("White".to_owned()) + g.white_player.name.unwrap_or("White".to_owned()) })) .expand(true) .build(), @@ -196,7 +196,7 @@ impl Default for Library { } impl Library { - pub fn set_games(&self, games: Vec) { + pub fn set_games(&self, games: Vec) { let games = games .into_iter() .map(GameObject::new)