diff --git a/Cargo.lock b/Cargo.lock index 3c04fd4..4b85df9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -976,6 +976,7 @@ checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" name = "fitnesstrax" version = "0.1.0" dependencies = [ + "emseries", "ft-core", "gio", "glib", diff --git a/fitnesstrax/app/Cargo.toml b/fitnesstrax/app/Cargo.toml index 005fc16..470ecea 100644 --- a/fitnesstrax/app/Cargo.toml +++ b/fitnesstrax/app/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] } +emseries = { path = "../../emseries" } ft-core = { path = "../core" } gio = { version = "0.18" } glib = { version = "0.18" } diff --git a/fitnesstrax/app/src/main.rs b/fitnesstrax/app/src/main.rs index 1a431a6..67e02a9 100644 --- a/fitnesstrax/app/src/main.rs +++ b/fitnesstrax/app/src/main.rs @@ -1,15 +1,31 @@ use adw::prelude::*; +use emseries::Series; +use ft_core::TraxRecord; use gio::resources_lookup_data; use glib::Object; use gtk::{prelude::*, subclass::prelude::*, STYLE_PROVIDER_PRIORITY_USER}; -use std::env; +use std::{ + env, + sync::{Arc, RwLock}, +}; const APP_ID_DEV: &str = "com.luminescent-dreams.fitnesstrax.dev"; const APP_ID_PROD: &str = "com.luminescent-dreams.fitnesstrax"; const RESOURCE_BASE_PATH: &str = "/com/luminescent-dreams/fitnesstrax/"; -struct AppState {} +#[derive(Clone)] +struct App { + database: Arc>>>, +} + +impl App { + pub fn new() -> Self { + Self { + database: Arc::new(RwLock::new(None)), + } + } +} pub struct NoDatabaseViewPrivate {} @@ -44,6 +60,39 @@ impl NoDatabaseView { } } +pub struct HistoricalViewPrivate {} + +#[glib::object_subclass] +impl ObjectSubclass for HistoricalViewPrivate { + const NAME: &'static str = "HistoricalView"; + type Type = HistoricalView; + type ParentType = gtk::Box; + + fn new() -> Self { + Self {} + } +} + +impl ObjectImpl for HistoricalViewPrivate {} +impl WidgetImpl for HistoricalViewPrivate {} +impl BoxImpl for HistoricalViewPrivate {} + +glib::wrapper! { + pub struct HistoricalView(ObjectSubclass) @extends gtk::Box, gtk::Widget; +} + +impl HistoricalView { + pub fn new() -> Self { + let s: Self = Object::builder().build(); + + let label = gtk::Label::builder() + .label("Database has been configured and now it is time to show data") + .build(); + s.append(&label); + s + } +} + // window setup... // main window with all of its layout // modals that overlay atop the main window and capture focus @@ -62,15 +111,17 @@ impl NoDatabaseView { enum MainView { NoDatabase(NoDatabaseView), + HistoricalView(HistoricalView), } struct AppWindow { + app: App, window: adw::ApplicationWindow, current_view: MainView, } impl AppWindow { - fn new(app: &adw::Application) -> AppWindow { + fn new(adw_app: &adw::Application, app: App) -> AppWindow { let stylesheet = String::from_utf8( resources_lookup_data( &format!("{}style.css", RESOURCE_BASE_PATH), @@ -85,7 +136,7 @@ impl AppWindow { provider.load_from_data(&stylesheet); let window = adw::ApplicationWindow::builder() - .application(app) + .application(adw_app) .width_request(800) .height_request(600) .build(); @@ -95,13 +146,18 @@ impl AppWindow { window.present(); - let current_view = { + let current_view = if app.database.read().unwrap().is_none() { let view = NoDatabaseView::new(); window.set_content(Some(&view)); MainView::NoDatabase(view) + } else { + let view = HistoricalView::new(); + window.set_content(Some(&view)); + MainView::HistoricalView(view) }; Self { + app, window, current_view, } @@ -126,11 +182,13 @@ fn main() { println!("database path: {}", settings.string("series-path")); - let app = adw::Application::builder() + let adw_app = adw::Application::builder() .application_id(app_id) .resource_base_path(RESOURCE_BASE_PATH) .build(); + let app = App::new(); + /* let runtime = tokio::runtime::Builder::new_multi_thread() .enable_all() @@ -138,15 +196,15 @@ fn main() { .unwrap(); */ - let app = adw::Application::builder() + let adw_app = adw::Application::builder() .application_id(app_id) .resource_base_path(RESOURCE_BASE_PATH) .build(); - app.connect_activate(move |app| { - AppWindow::new(app); + adw_app.connect_activate(move |adw_app| { + AppWindow::new(adw_app, app.clone()); }); let args: Vec = env::args().collect(); - ApplicationExtManual::run_with_args(&app, &args); + ApplicationExtManual::run_with_args(&adw_app, &args); } diff --git a/fitnesstrax/core/src/lib.rs b/fitnesstrax/core/src/lib.rs index b591639..9d7103a 100644 --- a/fitnesstrax/core/src/lib.rs +++ b/fitnesstrax/core/src/lib.rs @@ -4,3 +4,4 @@ use emseries::DateTimeTz; mod legacy; mod types; +pub use types::TraxRecord;