76 lines
2.1 KiB
Rust
76 lines
2.1 KiB
Rust
use crate::login_window::LoginWindow;
|
|
|
|
use gtk4 as gtk;
|
|
use gtk::{glib, gdk, gio, prelude::*, subclass::prelude::*};
|
|
|
|
mod imp {
|
|
use super::*;
|
|
use std::cell::RefCell;
|
|
|
|
#[derive(Debug, glib::Properties)]
|
|
#[properties(wrapper_type = super::Application)]
|
|
pub struct Application {
|
|
#[property(name = "api-key", type = Option<String>,
|
|
get = Self::api_key, set = Self::set_api_key, nullable)]
|
|
pub settings: RefCell<gio::Settings>,
|
|
}
|
|
|
|
impl Application {
|
|
fn api_key(&self) -> Option<String> {
|
|
self.settings.borrow().value("api-key").get()
|
|
}
|
|
|
|
fn set_api_key(&self, value: Option<String>) {
|
|
_ = self.settings.borrow().set("api-key", value).unwrap();
|
|
}
|
|
}
|
|
|
|
impl Default for Application {
|
|
fn default() -> Self {
|
|
Self {
|
|
settings: RefCell::new(gio::Settings::new(crate::APP_ID)),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[glib::object_subclass]
|
|
impl ObjectSubclass for Application {
|
|
const NAME: &'static str = "Application";
|
|
type Type = super::Application;
|
|
type ParentType = gtk::Application;
|
|
}
|
|
|
|
impl ApplicationImpl for Application {
|
|
fn activate(&self) {
|
|
let css = gtk::CssProvider::new();
|
|
gtk::style_context_add_provider_for_display(
|
|
&gdk::Display::default().unwrap(),
|
|
&css, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION
|
|
);
|
|
css.load_from_string(include_str!("../data/global.css"));
|
|
if self.api_key().is_none() {
|
|
let login_window = LoginWindow::new(&self.obj());
|
|
login_window.present();
|
|
} else {
|
|
todo!();
|
|
}
|
|
}
|
|
}
|
|
|
|
#[glib::derived_properties]
|
|
impl ObjectImpl for Application {}
|
|
impl GtkApplicationImpl for Application {}
|
|
}
|
|
|
|
glib::wrapper! {
|
|
pub struct Application(ObjectSubclass<imp::Application>)
|
|
@extends gtk::Application, gio::Application,
|
|
@implements gio::ActionMap, gio::ActionGroup;
|
|
}
|
|
|
|
impl Application {
|
|
pub fn new(app_id: &str) -> Self {
|
|
glib::Object::builder().property("application-id", app_id).build()
|
|
}
|
|
}
|