2023-08-09 17:54:56 +00:00
|
|
|
use crate::{
|
2023-08-10 16:35:48 +00:00
|
|
|
components::{Date, Events, TransitCard, TransitClock},
|
2023-08-09 17:54:56 +00:00
|
|
|
types::State,
|
|
|
|
};
|
2023-08-10 03:33:51 +00:00
|
|
|
use adw::prelude::AdwApplicationWindowExt;
|
2023-08-10 15:07:35 +00:00
|
|
|
use gio::resources_lookup_data;
|
|
|
|
use gtk::{prelude::*, STYLE_PROVIDER_PRIORITY_USER};
|
2023-08-09 17:54:56 +00:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct ApplicationWindow {
|
2023-08-10 03:33:51 +00:00
|
|
|
pub window: adw::ApplicationWindow,
|
2023-08-09 17:54:56 +00:00
|
|
|
pub date_label: Date,
|
2023-08-10 16:35:48 +00:00
|
|
|
pub events: Events,
|
2023-08-10 14:13:57 +00:00
|
|
|
pub transit_card: TransitCard,
|
2023-08-09 17:54:56 +00:00
|
|
|
pub transit_clock: TransitClock,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ApplicationWindow {
|
2023-08-10 03:33:51 +00:00
|
|
|
pub fn new(app: &adw::Application) -> Self {
|
|
|
|
let window = adw::ApplicationWindow::new(app);
|
2023-08-09 17:54:56 +00:00
|
|
|
|
2023-08-10 15:07:35 +00:00
|
|
|
let stylesheet = String::from_utf8(
|
|
|
|
resources_lookup_data(
|
|
|
|
"/com/luminescent-dreams/dashboard/style.css",
|
|
|
|
gio::ResourceLookupFlags::NONE,
|
|
|
|
)
|
|
|
|
.expect("stylesheet should just be available")
|
|
|
|
.to_vec(),
|
|
|
|
)
|
|
|
|
.expect("to parse stylesheet");
|
|
|
|
|
|
|
|
let provider = gtk::CssProvider::new();
|
|
|
|
provider.load_from_data(&stylesheet);
|
|
|
|
let context = window.style_context();
|
|
|
|
context.add_provider(&provider, STYLE_PROVIDER_PRIORITY_USER);
|
|
|
|
|
2023-08-09 17:54:56 +00:00
|
|
|
let layout = gtk::Box::builder()
|
|
|
|
.orientation(gtk::Orientation::Vertical)
|
|
|
|
.hexpand(true)
|
|
|
|
.vexpand(true)
|
|
|
|
.build();
|
|
|
|
|
2023-10-04 21:28:55 +00:00
|
|
|
let date_label = Date::default();
|
2023-08-09 17:54:56 +00:00
|
|
|
layout.append(&date_label);
|
2023-08-09 18:02:20 +00:00
|
|
|
|
2023-10-04 21:28:55 +00:00
|
|
|
let events = Events::default();
|
2023-08-10 16:35:48 +00:00
|
|
|
layout.append(&events);
|
2023-08-09 18:02:20 +00:00
|
|
|
|
2023-10-04 21:28:55 +00:00
|
|
|
let transit_card = TransitCard::default();
|
2023-08-10 14:13:57 +00:00
|
|
|
layout.append(&transit_card);
|
|
|
|
|
2023-10-04 21:28:55 +00:00
|
|
|
let transit_clock = TransitClock::default();
|
2023-08-09 17:54:56 +00:00
|
|
|
layout.append(&transit_clock);
|
|
|
|
|
2023-08-10 03:33:51 +00:00
|
|
|
window.set_content(Some(&layout));
|
2023-08-09 17:54:56 +00:00
|
|
|
|
|
|
|
Self {
|
|
|
|
window,
|
|
|
|
date_label,
|
2023-08-10 16:35:48 +00:00
|
|
|
events,
|
2023-08-10 14:13:57 +00:00
|
|
|
transit_card,
|
2023-08-09 17:54:56 +00:00
|
|
|
transit_clock,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn update_state(&self, state: State) {
|
|
|
|
self.date_label.update_date(state.date);
|
2023-08-10 16:35:48 +00:00
|
|
|
self.events.set_events(state.events, state.next_event);
|
2023-08-09 17:54:56 +00:00
|
|
|
if let Some(transit) = state.transit {
|
2023-08-10 14:13:57 +00:00
|
|
|
self.transit_card.update_transit(&transit);
|
2023-08-09 17:54:56 +00:00
|
|
|
self.transit_clock.update_transit(transit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|