[fractal/fractal-next] settings: Use the application level instance
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] settings: Use the application level instance
- Date: Tue, 11 May 2021 15:51:17 +0000 (UTC)
commit 5c59282811d6e3359c7d496b68d770d40f7b2f40
Author: Veli Tasali <veli tasali gmail com>
Date: Mon May 10 18:03:20 2021 +0300
settings: Use the application level instance
src/application.rs | 17 ++++++++++++++++-
src/window.rs | 6 ++----
2 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/src/application.rs b/src/application.rs
index c686a218..4fb7fdd9 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -1,7 +1,7 @@
use crate::config;
use crate::Window;
use gettextrs::gettext;
-use gio::ApplicationFlags;
+use gio::{ApplicationFlags, Settings};
use glib::clone;
use glib::WeakRef;
use gtk::prelude::*;
@@ -17,6 +17,7 @@ mod imp {
#[derive(Debug)]
pub struct Application {
pub window: OnceCell<WeakRef<Window>>,
+ pub settings: Settings,
}
#[glib::object_subclass]
@@ -28,6 +29,7 @@ mod imp {
fn new() -> Self {
Self {
window: OnceCell::new(),
+ settings: Settings::new(config::APP_ID),
}
}
}
@@ -91,6 +93,10 @@ impl Application {
.unwrap()
}
+ pub fn settings(&self) -> Settings {
+ imp::Application::from_instance(self).settings.clone()
+ }
+
fn setup_gactions(&self) {
// Quit
action!(
@@ -173,3 +179,12 @@ impl Application {
ApplicationExtManual::run(self);
}
}
+
+impl Default for Application {
+ fn default() -> Self {
+ gio::Application::default()
+ .unwrap()
+ .downcast::<Application>()
+ .unwrap()
+ }
+}
diff --git a/src/window.rs b/src/window.rs
index 1cd0159f..88615b82 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -21,7 +21,6 @@ mod imp {
pub main_stack: TemplateChild<gtk::Stack>,
#[template_child]
pub login: TemplateChild<Login>,
- pub settings: gio::Settings,
}
#[glib::object_subclass]
@@ -34,7 +33,6 @@ mod imp {
Self {
main_stack: TemplateChild::default(),
login: TemplateChild::default(),
- settings: gio::Settings::new(APP_ID),
}
}
@@ -115,7 +113,7 @@ impl Window {
}
pub fn save_window_size(&self) -> Result<(), glib::BoolError> {
- let settings = &imp::Window::from_instance(self).settings;
+ let settings = Application::default().settings();
let size = self.default_size();
@@ -128,7 +126,7 @@ impl Window {
}
fn load_window_size(&self) {
- let settings = &imp::Window::from_instance(self).settings;
+ let settings = Application::default().settings();
let width = settings.int("window-width");
let height = settings.int("window-height");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]