Show real information in the library view

This commit is contained in:
Savanni D'Gerinel 2024-03-21 23:30:24 -04:00
parent 89a289a1ae
commit 49571b0f82
4 changed files with 16 additions and 17 deletions

View File

@ -126,7 +126,6 @@ impl Core {
println!("config: {:?}", config);
let library = if let Some(ref path) = config.get::<LibraryPath>() {
println!("loading initial library");
Some(Database::open_path(path.to_path_buf()).unwrap())
} else {
None

View File

@ -43,10 +43,12 @@ impl Database {
match parse_sgf(&buffer) {
Ok(sgfs) => {
for sgf in sgfs {
if let Ok(sgf) = sgf {
games.push(sgf);
}
}
Err(err) => println!("Error parsing {:?}: {:?}", entry.path(), err),
}
Err(err) => println!("Error parsing {:?}", entry.path()),
}
}
}

View File

@ -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<GameInfo>)
Games(Vec<Game>)
}
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::<Vec<GameInfo>>();
let info = library.all_games().map(|g| g.clone()).collect::<Vec<Game>>();
LibraryResponse::Games(info)
}
None => LibraryResponse::Games(vec![]),

View File

@ -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<RefCell<Option<GameInfo>>>,
game: Rc<RefCell<Option<Game>>>,
}
#[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<GameInfo> {
pub fn game(&self) -> Option<Game> {
self.imp().game.borrow().clone()
}
}
@ -85,7 +85,7 @@ impl Default for LibraryPrivate {
fn make_factory<F>(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 {
&gtk::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 {
&gtk::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 {
&gtk::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<GameInfo>) {
pub fn set_games(&self, games: Vec<Game>) {
let games = games
.into_iter()
.map(GameObject::new)