Skip to content

Commit dbea3a1

Browse files
committed
Updated src/settingswindow/imp.rs:
- Updated reuse copyright year - Added clearer import headers - Refactored to now import std::cell::OnceCell as it has been [merged into std](rust-lang/rust#105587) - Refactored to now import std::sync::OncelLock as it has been [merged into std](rust-lang/rust#105587) - Refactored to import Value from glib::value as it now has its own module in glib - Refactored to import Variant and FromVariant from glib::variant as it now has its own module in glib - Added glib::BorrowedObject import - Refactored to use glib::signal::Propagation instead of glib::signal::Inhibit - Refactored "properties()"function to reflect OnceLock changes - Removed now unused "_obj" parameter to "property()" and "set_property()" functions - Removed deprecated "window" parameter from "close_request()" function - Updated "close_request()" function to return a Propagation type - Updated "parent_close_request()" call in "close_request()" function - Refactored "constructed()" function to get "obj" reference via "self" instead of as a parameter - Updated "parent_constructed()" call in "constructed()" function Updated src/settingswindow/mod.rs: - Updated reuse copyright year - Added clearer import headers - Updated "new()" function to use "Object::builder::<SettingsWindow>().build()" instead of untyped "Obect::new()"" Signed-off-by: Deren Vural <35734401+derenv@users.noreply.github.com>
1 parent eec6a8a commit dbea3a1

File tree

2 files changed

+74
-27
lines changed

2 files changed

+74
-27
lines changed

src/settingswindow/imp.rs

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
// SPDX-FileCopyrightText: 2022 Deren Vural
1+
// SPDX-FileCopyrightText: 2024 Deren Vural
22
// SPDX-License-Identifier: GPL-3.0-or-later
33

4-
use adwaita::{gio, glib, prelude::*, subclass::prelude::*, ComboRow};
5-
use gio::Settings;
64
/**
75
* Name:
86
* imp.rs
@@ -20,10 +18,30 @@ use gio::Settings;
2018
*
2119
*/
2220
// Imports
23-
use glib::{once_cell::sync::Lazy, ParamSpec, Value};
24-
use glib::{once_cell::sync::OnceCell, signal::Inhibit, subclass::InitializingObject};
25-
use gtk::{subclass::prelude::*, CheckButton, CompositeTemplate, SpinButton, TemplateChild};
26-
use std::{cell::RefCell, cell::RefMut, rc::Rc};
21+
// std
22+
use std::sync::OnceLock;
23+
use std::cell::{
24+
//Cell,
25+
OnceCell, RefCell, RefMut
26+
};
27+
use std::rc::Rc;
28+
// gtk-rs
29+
use gtk::{
30+
subclass::prelude::*,
31+
CheckButton, CompositeTemplate, SpinButton, TemplateChild
32+
};
33+
use adwaita::{
34+
gio, glib,
35+
prelude::*, subclass::prelude::*,
36+
ComboRow
37+
};
38+
use gio::Settings;
39+
use glib::{
40+
signal::Propagation,
41+
ParamSpec, subclass::InitializingObject,
42+
variant::Variant,
43+
value::Value
44+
};
2745

2846
// Modules
2947
//use crate::utils::data_path;
@@ -107,7 +125,11 @@ impl SettingsWindow {
107125
* Notes:
108126
*
109127
*/
110-
pub fn update_setting<T: ToVariant>(&self, name: &str, value: T) {
128+
pub fn update_setting<T: Into<Variant> + Clone>(
129+
&self,
130+
name: &str,
131+
value: T
132+
) {
111133
// Fetch settings
112134
match self.settings.get() {
113135
Some(settings) => match settings.set(name, &value) {
@@ -135,7 +157,10 @@ impl SettingsWindow {
135157
*
136158
*/
137159
#[template_callback]
138-
fn refreshrate_set(&self, button: &SpinButton) {
160+
fn refreshrate_set(
161+
&self,
162+
button: &SpinButton
163+
) {
139164
// Get new refresh rate input
140165
let new_value: i32 = button.value_as_int();
141166

@@ -160,7 +185,10 @@ impl SettingsWindow {
160185
*
161186
*/
162187
#[template_callback]
163-
fn temp_unit_set(&self, button: &CheckButton) {
188+
fn temp_unit_set(
189+
&self,
190+
button: &CheckButton
191+
) {
164192
// Get list of buttons
165193
let check_buttons: [&CheckButton; 2] = [&self.temp_unit_c, &self.temp_unit_f];
166194

@@ -224,11 +252,12 @@ impl ObjectImpl for SettingsWindow {
224252
* Notes:
225253
*
226254
*/
227-
fn constructed(&self, obj: &Self::Type) {
255+
fn constructed(&self) {
228256
// Call "constructed" on parent
229-
self.parent_constructed(obj);
257+
self.parent_constructed();
230258

231259
// Setup
260+
let obj: glib::BorrowedObject<super::SettingsWindow> = self.obj();
232261
obj.setup_settings();
233262
obj.restore_data();
234263
obj.setup_widgets();
@@ -261,16 +290,15 @@ impl ObjectImpl for SettingsWindow {
261290
* glib::ParamSpecObject::builder("formatter").build(),
262291
*/
263292
fn properties() -> &'static [ParamSpec] {
264-
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
293+
static PROPERTIES: OnceLock<Vec<ParamSpec>> = OnceLock::new();
294+
PROPERTIES.get_or_init(|| {
265295
vec![
266296
//
267297
]
268-
});
298+
})
269299

270300
//println!("PROPERTIES: {:?}", PROPERTIES);//TEST
271301
//println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST
272-
273-
PROPERTIES.as_ref()
274302
}
275303

276304
/**
@@ -289,7 +317,12 @@ impl ObjectImpl for SettingsWindow {
289317
* Notes:
290318
*
291319
*/
292-
fn set_property(&self, _obj: &Self::Type, _id: usize, _value: &Value, pspec: &ParamSpec) {
320+
fn set_property(
321+
&self,
322+
_id: usize,
323+
_value: &Value,
324+
pspec: &ParamSpec
325+
) {
293326
//println!("setting: {:?}", pspec.name());//TEST
294327

295328
match pspec.name() {
@@ -314,7 +347,11 @@ impl ObjectImpl for SettingsWindow {
314347
* Notes:
315348
*
316349
*/
317-
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
350+
fn property(
351+
&self,
352+
_id: usize,
353+
pspec: &ParamSpec
354+
) -> Value {
318355
//println!("getting: {:?}", pspec.name());//TEST
319356

320357
match pspec.name() {
@@ -359,7 +396,7 @@ impl WidgetImpl for SettingsWindow {}
359396
*
360397
*/
361398
impl WindowImpl for SettingsWindow {
362-
fn close_request(&self, window: &Self::Type) -> Inhibit {
399+
fn close_request(&self) -> Propagation {
363400
/*
364401
// Store task data in vector
365402
let backup_data: Vec<TaskData> = window
@@ -390,7 +427,7 @@ impl WindowImpl for SettingsWindow {
390427
.emit_by_name::<i32>("update-all-views", &[]);
391428

392429
// Pass close request on to the parent
393-
self.parent_close_request(window)
430+
self.parent_close_request()
394431
}
395432
}
396433

src/settingswindow/mod.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 Deren Vural
1+
// SPDX-FileCopyrightText: 2024 Deren Vural
22
// SPDX-License-Identifier: GPL-3.0-or-later
33

44
/**
@@ -21,11 +21,20 @@
2121
mod imp;
2222

2323
// Imports
24-
use adwaita::{gio, glib, prelude::*, subclass::prelude::*};
25-
use gio::Settings;
26-
use glib::{clone, Object};
27-
use gtk::{Adjustment, CheckButton, StringList};
24+
// std
2825
use std::cell::RefMut;
26+
// gtk-rs
27+
use adwaita::{
28+
gio, glib,
29+
prelude::*, subclass::prelude::*
30+
};
31+
use gio::Settings;
32+
use glib::{
33+
clone, Object
34+
};
35+
use gtk::{
36+
Adjustment, CheckButton, StringList
37+
};
2938

3039
// Modules
3140
use crate::{mainwindow::MainWindow, settingswindow::imp::ParentContainer, APP_ID};
@@ -73,8 +82,9 @@ impl SettingsWindow {
7382
*/
7483
pub fn new(app: &adwaita::Application, parent_window: &MainWindow) -> Self {
7584
// Create new window
76-
let obj: SettingsWindow = Object::new(&[("application", app)])
77-
.expect("`SettingsWindow` should be instantiable.");
85+
let obj: SettingsWindow = Object::builder::<SettingsWindow>()
86+
.property("application", app)
87+
.build();
7888

7989
// Set custom properties
8090
//

0 commit comments

Comments
 (0)