Render the Settings page and the Library via view models #227
|
@ -126,7 +126,6 @@ impl Core {
|
||||||
println!("config: {:?}", config);
|
println!("config: {:?}", config);
|
||||||
|
|
||||||
let library = if let Some(ref path) = config.get::<LibraryPath>() {
|
let library = if let Some(ref path) = config.get::<LibraryPath>() {
|
||||||
println!("loading initial library");
|
|
||||||
Some(Database::open_path(path.to_path_buf()).unwrap())
|
Some(Database::open_path(path.to_path_buf()).unwrap())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -43,10 +43,12 @@ impl Database {
|
||||||
match parse_sgf(&buffer) {
|
match parse_sgf(&buffer) {
|
||||||
Ok(sgfs) => {
|
Ok(sgfs) => {
|
||||||
for sgf in sgfs {
|
for sgf in sgfs {
|
||||||
|
if let Ok(sgf) = sgf {
|
||||||
games.push(sgf);
|
games.push(sgf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => println!("Error parsing {:?}: {:?}", entry.path(), err),
|
}
|
||||||
|
Err(err) => println!("Error parsing {:?}", entry.path()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with Kif
|
||||||
|
|
||||||
use crate::{Core, Config};
|
use crate::{Core, Config};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sgf::GameInfo;
|
use sgf::Game;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub enum LibraryRequest {
|
pub enum LibraryRequest {
|
||||||
|
@ -25,16 +25,14 @@ pub enum LibraryRequest {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub enum LibraryResponse {
|
pub enum LibraryResponse {
|
||||||
Games(Vec<GameInfo>)
|
Games(Vec<Game>)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_list_games(model: &Core) -> LibraryResponse {
|
async fn handle_list_games(model: &Core) -> LibraryResponse {
|
||||||
println!("handle_list_games");
|
|
||||||
let library = model.library();
|
let library = model.library();
|
||||||
println!("library: {:?}", *library);
|
|
||||||
match *library {
|
match *library {
|
||||||
Some(ref 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)
|
LibraryResponse::Games(info)
|
||||||
}
|
}
|
||||||
None => LibraryResponse::Games(vec![]),
|
None => LibraryResponse::Games(vec![]),
|
||||||
|
|
|
@ -2,12 +2,12 @@ use adw::{prelude::*, subclass::prelude::*};
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::glib;
|
use gtk::glib;
|
||||||
// use kifu_core::ui::GamePreviewElement;
|
// use kifu_core::ui::GamePreviewElement;
|
||||||
use sgf::GameInfo;
|
use sgf::Game;
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct GameObjectPrivate {
|
pub struct GameObjectPrivate {
|
||||||
game: Rc<RefCell<Option<GameInfo>>>,
|
game: Rc<RefCell<Option<Game>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
@ -23,13 +23,13 @@ glib::wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameObject {
|
impl GameObject {
|
||||||
pub fn new(game: GameInfo) -> Self {
|
pub fn new(game: Game) -> Self {
|
||||||
let s: Self = Object::builder().build();
|
let s: Self = Object::builder().build();
|
||||||
*s.imp().game.borrow_mut() = Some(game);
|
*s.imp().game.borrow_mut() = Some(game);
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn game(&self) -> Option<GameInfo> {
|
pub fn game(&self) -> Option<Game> {
|
||||||
self.imp().game.borrow().clone()
|
self.imp().game.borrow().clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ impl Default for LibraryPrivate {
|
||||||
|
|
||||||
fn make_factory<F>(bind: F) -> gtk::SignalListItemFactory
|
fn make_factory<F>(bind: F) -> gtk::SignalListItemFactory
|
||||||
where
|
where
|
||||||
F: Fn(GameInfo) -> String + 'static,
|
F: Fn(Game) -> String + 'static,
|
||||||
{
|
{
|
||||||
let factory = gtk::SignalListItemFactory::new();
|
let factory = gtk::SignalListItemFactory::new();
|
||||||
factory.connect_setup(|_, list_item| {
|
factory.connect_setup(|_, list_item| {
|
||||||
|
@ -114,7 +114,7 @@ impl Default for LibraryPrivate {
|
||||||
>k::ColumnViewColumn::builder()
|
>k::ColumnViewColumn::builder()
|
||||||
.title("date")
|
.title("date")
|
||||||
.factory(&make_factory(|g| {
|
.factory(&make_factory(|g| {
|
||||||
g.date
|
g.dates
|
||||||
.iter()
|
.iter()
|
||||||
.map(|date| {
|
.map(|date| {
|
||||||
format!("{}", date)
|
format!("{}", date)
|
||||||
|
@ -146,7 +146,7 @@ impl Default for LibraryPrivate {
|
||||||
>k::ColumnViewColumn::builder()
|
>k::ColumnViewColumn::builder()
|
||||||
.title("black")
|
.title("black")
|
||||||
.factory(&make_factory(|g| {
|
.factory(&make_factory(|g| {
|
||||||
g.black_player.unwrap_or("Black".to_owned())
|
g.black_player.name.unwrap_or("Black".to_owned())
|
||||||
}))
|
}))
|
||||||
.expand(true)
|
.expand(true)
|
||||||
.build(),
|
.build(),
|
||||||
|
@ -155,7 +155,7 @@ impl Default for LibraryPrivate {
|
||||||
>k::ColumnViewColumn::builder()
|
>k::ColumnViewColumn::builder()
|
||||||
.title("white")
|
.title("white")
|
||||||
.factory(&make_factory(|g| {
|
.factory(&make_factory(|g| {
|
||||||
g.white_player.unwrap_or("White".to_owned())
|
g.white_player.name.unwrap_or("White".to_owned())
|
||||||
}))
|
}))
|
||||||
.expand(true)
|
.expand(true)
|
||||||
.build(),
|
.build(),
|
||||||
|
@ -196,7 +196,7 @@ impl Default for Library {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Library {
|
impl Library {
|
||||||
pub fn set_games(&self, games: Vec<GameInfo>) {
|
pub fn set_games(&self, games: Vec<Game>) {
|
||||||
let games = games
|
let games = games
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(GameObject::new)
|
.map(GameObject::new)
|
||||||
|
|
Loading…
Reference in New Issue