From 94801968fa1e974e447c99b32d13e92746c962ce Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Sat, 21 Oct 2023 05:12:52 -0700 Subject: [PATCH] Fix css --- simplelogin-gui/Cargo.toml | 2 +- simplelogin-gui/{res.old => data}/global.css | 0 .../data/im.zander.SimpleLogin.gschema.xml | 4 +- simplelogin-gui/data/login_window.blp | 3 -- simplelogin-gui/src/application.rs | 37 ++++++++++++++++--- simplelogin-gui/src/main.rs | 7 ++-- 6 files changed, 38 insertions(+), 15 deletions(-) rename simplelogin-gui/{res.old => data}/global.css (100%) diff --git a/simplelogin-gui/Cargo.toml b/simplelogin-gui/Cargo.toml index 396c343..2246fd9 100644 --- a/simplelogin-gui/Cargo.toml +++ b/simplelogin-gui/Cargo.toml @@ -6,6 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -gtk4 = { version = "0.7.3", features = ["blueprint"] } +gtk4 = { version = "0.7.3", features = ["blueprint", "v4_12"] } simplelogin = { version = "0.1.0", path = "../simplelogin" } tokio = { version = "1.33.0", features = ["full"] } diff --git a/simplelogin-gui/res.old/global.css b/simplelogin-gui/data/global.css similarity index 100% rename from simplelogin-gui/res.old/global.css rename to simplelogin-gui/data/global.css diff --git a/simplelogin-gui/data/im.zander.SimpleLogin.gschema.xml b/simplelogin-gui/data/im.zander.SimpleLogin.gschema.xml index bf42b08..0e59605 100644 --- a/simplelogin-gui/data/im.zander.SimpleLogin.gschema.xml +++ b/simplelogin-gui/data/im.zander.SimpleLogin.gschema.xml @@ -1,8 +1,8 @@ - - "" + + nothing Api key The api key for the current user diff --git a/simplelogin-gui/data/login_window.blp b/simplelogin-gui/data/login_window.blp index fe14482..c2f8327 100644 --- a/simplelogin-gui/data/login_window.blp +++ b/simplelogin-gui/data/login_window.blp @@ -117,9 +117,6 @@ template $LoginWindow : ApplicationWindow { receives-default: true; truncate-multiline: true; - styles [ - ] - layout { column: "1"; row: "1"; diff --git a/simplelogin-gui/src/application.rs b/simplelogin-gui/src/application.rs index 4fe0b7d..769c5d8 100644 --- a/simplelogin-gui/src/application.rs +++ b/simplelogin-gui/src/application.rs @@ -1,20 +1,34 @@ use crate::login_window::LoginWindow; use gtk4 as gtk; -use gtk::{glib, gio, prelude::*, subclass::prelude::*}; +use gtk::{glib, gdk, gio, prelude::*, subclass::prelude::*}; mod imp { use super::*; + use std::cell::RefCell; - #[derive(Debug)] + #[derive(Debug, glib::Properties)] + #[properties(wrapper_type = super::Application)] pub struct Application { - pub settings: gio::Settings, + #[property(name = "api-key", type = Option, + get = Self::api_key, set = Self::set_api_key, nullable)] + pub settings: RefCell, + } + + impl Application { + fn api_key(&self) -> Option { + self.settings.borrow().value("api-key").get() + } + + fn set_api_key(&self, value: Option) { + _ = self.settings.borrow().set("api-key", value).unwrap(); + } } impl Default for Application { fn default() -> Self { Self { - settings: gio::Settings::new(crate::APP_ID) + settings: RefCell::new(gio::Settings::new(crate::APP_ID)), } } } @@ -28,11 +42,22 @@ mod imp { impl ApplicationImpl for Application { fn activate(&self) { - let login_window = LoginWindow::new(&self.obj()); - login_window.present(); + 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 {} } diff --git a/simplelogin-gui/src/main.rs b/simplelogin-gui/src/main.rs index 90adb39..4b5ad30 100644 --- a/simplelogin-gui/src/main.rs +++ b/simplelogin-gui/src/main.rs @@ -4,15 +4,16 @@ mod application; use gtk4 as gtk; use gtk::prelude::*; -use gtk::glib::{self, g_message}; +use gtk::glib::{self, g_info}; const APP_ID: &str = "im.zander.SimpleLogin"; fn main() -> glib::ExitCode { - if cfg!(debug_assertions) { + #[cfg(debug_assertions)] { + std::env::set_var("G_MESSAGES_DEBUG", "SimpleLogin"); // allow us to use a test schema for debug runs let schema_dir = concat!(env!("OUT_DIR"), "/schemas/"); - g_message!("SimpleLogin", "Using schema dir: \"{}\"", schema_dir); + g_info!("SimpleLogin", "Using schema dir: \"{}\"", schema_dir); std::env::set_var("GSETTINGS_SCHEMA_DIR", schema_dir); } let app = application::Application::new(APP_ID);