put in a placeholder for a historical view and the logic to choose it

This commit is contained in:
Savanni D'Gerinel 2023-12-07 23:00:17 -05:00
parent e008a97f83
commit 7ee3e1432e
4 changed files with 71 additions and 10 deletions

1
Cargo.lock generated
View File

@ -976,6 +976,7 @@ checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6"
name = "fitnesstrax" name = "fitnesstrax"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"emseries",
"ft-core", "ft-core",
"gio", "gio",
"glib", "glib",

View File

@ -7,6 +7,7 @@ edition = "2021"
[dependencies] [dependencies]
adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] } adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] }
emseries = { path = "../../emseries" }
ft-core = { path = "../core" } ft-core = { path = "../core" }
gio = { version = "0.18" } gio = { version = "0.18" }
glib = { version = "0.18" } glib = { version = "0.18" }

View File

@ -1,15 +1,31 @@
use adw::prelude::*; use adw::prelude::*;
use emseries::Series;
use ft_core::TraxRecord;
use gio::resources_lookup_data; use gio::resources_lookup_data;
use glib::Object; use glib::Object;
use gtk::{prelude::*, subclass::prelude::*, STYLE_PROVIDER_PRIORITY_USER}; 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_DEV: &str = "com.luminescent-dreams.fitnesstrax.dev";
const APP_ID_PROD: &str = "com.luminescent-dreams.fitnesstrax"; const APP_ID_PROD: &str = "com.luminescent-dreams.fitnesstrax";
const RESOURCE_BASE_PATH: &str = "/com/luminescent-dreams/fitnesstrax/"; const RESOURCE_BASE_PATH: &str = "/com/luminescent-dreams/fitnesstrax/";
struct AppState {} #[derive(Clone)]
struct App {
database: Arc<RwLock<Option<Series<TraxRecord>>>>,
}
impl App {
pub fn new() -> Self {
Self {
database: Arc::new(RwLock::new(None)),
}
}
}
pub struct NoDatabaseViewPrivate {} 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<HistoricalViewPrivate>) @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... // window setup...
// main window with all of its layout // main window with all of its layout
// modals that overlay atop the main window and capture focus // modals that overlay atop the main window and capture focus
@ -62,15 +111,17 @@ impl NoDatabaseView {
enum MainView { enum MainView {
NoDatabase(NoDatabaseView), NoDatabase(NoDatabaseView),
HistoricalView(HistoricalView),
} }
struct AppWindow { struct AppWindow {
app: App,
window: adw::ApplicationWindow, window: adw::ApplicationWindow,
current_view: MainView, current_view: MainView,
} }
impl AppWindow { impl AppWindow {
fn new(app: &adw::Application) -> AppWindow { fn new(adw_app: &adw::Application, app: App) -> AppWindow {
let stylesheet = String::from_utf8( let stylesheet = String::from_utf8(
resources_lookup_data( resources_lookup_data(
&format!("{}style.css", RESOURCE_BASE_PATH), &format!("{}style.css", RESOURCE_BASE_PATH),
@ -85,7 +136,7 @@ impl AppWindow {
provider.load_from_data(&stylesheet); provider.load_from_data(&stylesheet);
let window = adw::ApplicationWindow::builder() let window = adw::ApplicationWindow::builder()
.application(app) .application(adw_app)
.width_request(800) .width_request(800)
.height_request(600) .height_request(600)
.build(); .build();
@ -95,13 +146,18 @@ impl AppWindow {
window.present(); window.present();
let current_view = { let current_view = if app.database.read().unwrap().is_none() {
let view = NoDatabaseView::new(); let view = NoDatabaseView::new();
window.set_content(Some(&view)); window.set_content(Some(&view));
MainView::NoDatabase(view) MainView::NoDatabase(view)
} else {
let view = HistoricalView::new();
window.set_content(Some(&view));
MainView::HistoricalView(view)
}; };
Self { Self {
app,
window, window,
current_view, current_view,
} }
@ -126,11 +182,13 @@ fn main() {
println!("database path: {}", settings.string("series-path")); println!("database path: {}", settings.string("series-path"));
let app = adw::Application::builder() let adw_app = adw::Application::builder()
.application_id(app_id) .application_id(app_id)
.resource_base_path(RESOURCE_BASE_PATH) .resource_base_path(RESOURCE_BASE_PATH)
.build(); .build();
let app = App::new();
/* /*
let runtime = tokio::runtime::Builder::new_multi_thread() let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all() .enable_all()
@ -138,15 +196,15 @@ fn main() {
.unwrap(); .unwrap();
*/ */
let app = adw::Application::builder() let adw_app = adw::Application::builder()
.application_id(app_id) .application_id(app_id)
.resource_base_path(RESOURCE_BASE_PATH) .resource_base_path(RESOURCE_BASE_PATH)
.build(); .build();
app.connect_activate(move |app| { adw_app.connect_activate(move |adw_app| {
AppWindow::new(app); AppWindow::new(adw_app, app.clone());
}); });
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
ApplicationExtManual::run_with_args(&app, &args); ApplicationExtManual::run_with_args(&adw_app, &args);
} }

View File

@ -4,3 +4,4 @@ use emseries::DateTimeTz;
mod legacy; mod legacy;
mod types; mod types;
pub use types::TraxRecord;