Skip to content

Commit

Permalink
Updated src/settingswindow/imp.rs:
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
derenv committed May 20, 2024
1 parent eec6a8a commit dbea3a1
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 27 deletions.
77 changes: 57 additions & 20 deletions src/settingswindow/imp.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: 2022 Deren Vural
// SPDX-FileCopyrightText: 2024 Deren Vural
// SPDX-License-Identifier: GPL-3.0-or-later

use adwaita::{gio, glib, prelude::*, subclass::prelude::*, ComboRow};
use gio::Settings;
/**
* Name:
* imp.rs
Expand All @@ -20,10 +18,30 @@ use gio::Settings;
*
*/
// Imports
use glib::{once_cell::sync::Lazy, ParamSpec, Value};
use glib::{once_cell::sync::OnceCell, signal::Inhibit, subclass::InitializingObject};
use gtk::{subclass::prelude::*, CheckButton, CompositeTemplate, SpinButton, TemplateChild};
use std::{cell::RefCell, cell::RefMut, rc::Rc};
// std
use std::sync::OnceLock;
use std::cell::{
//Cell,
OnceCell, RefCell, RefMut
};
use std::rc::Rc;
// gtk-rs
use gtk::{
subclass::prelude::*,
CheckButton, CompositeTemplate, SpinButton, TemplateChild
};
use adwaita::{
gio, glib,
prelude::*, subclass::prelude::*,
ComboRow
};
use gio::Settings;
use glib::{
signal::Propagation,
ParamSpec, subclass::InitializingObject,
variant::Variant,
value::Value
};

// Modules
//use crate::utils::data_path;
Expand Down Expand Up @@ -107,7 +125,11 @@ impl SettingsWindow {
* Notes:
*
*/
pub fn update_setting<T: ToVariant>(&self, name: &str, value: T) {
pub fn update_setting<T: Into<Variant> + Clone>(
&self,
name: &str,
value: T
) {
// Fetch settings
match self.settings.get() {
Some(settings) => match settings.set(name, &value) {
Expand Down Expand Up @@ -135,7 +157,10 @@ impl SettingsWindow {
*
*/
#[template_callback]
fn refreshrate_set(&self, button: &SpinButton) {
fn refreshrate_set(
&self,
button: &SpinButton
) {
// Get new refresh rate input
let new_value: i32 = button.value_as_int();

Expand All @@ -160,7 +185,10 @@ impl SettingsWindow {
*
*/
#[template_callback]
fn temp_unit_set(&self, button: &CheckButton) {
fn temp_unit_set(
&self,
button: &CheckButton
) {
// Get list of buttons
let check_buttons: [&CheckButton; 2] = [&self.temp_unit_c, &self.temp_unit_f];

Expand Down Expand Up @@ -224,11 +252,12 @@ impl ObjectImpl for SettingsWindow {
* Notes:
*
*/
fn constructed(&self, obj: &Self::Type) {
fn constructed(&self) {
// Call "constructed" on parent
self.parent_constructed(obj);
self.parent_constructed();

// Setup
let obj: glib::BorrowedObject<super::SettingsWindow> = self.obj();
obj.setup_settings();
obj.restore_data();
obj.setup_widgets();
Expand Down Expand Up @@ -261,16 +290,15 @@ impl ObjectImpl for SettingsWindow {
* glib::ParamSpecObject::builder("formatter").build(),
*/
fn properties() -> &'static [ParamSpec] {
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
static PROPERTIES: OnceLock<Vec<ParamSpec>> = OnceLock::new();
PROPERTIES.get_or_init(|| {
vec![
//
]
});
})

//println!("PROPERTIES: {:?}", PROPERTIES);//TEST
//println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST

PROPERTIES.as_ref()
}

/**
Expand All @@ -289,7 +317,12 @@ impl ObjectImpl for SettingsWindow {
* Notes:
*
*/
fn set_property(&self, _obj: &Self::Type, _id: usize, _value: &Value, pspec: &ParamSpec) {
fn set_property(
&self,
_id: usize,
_value: &Value,
pspec: &ParamSpec
) {
//println!("setting: {:?}", pspec.name());//TEST

match pspec.name() {
Expand All @@ -314,7 +347,11 @@ impl ObjectImpl for SettingsWindow {
* Notes:
*
*/
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
fn property(
&self,
_id: usize,
pspec: &ParamSpec
) -> Value {
//println!("getting: {:?}", pspec.name());//TEST

match pspec.name() {
Expand Down Expand Up @@ -359,7 +396,7 @@ impl WidgetImpl for SettingsWindow {}
*
*/
impl WindowImpl for SettingsWindow {
fn close_request(&self, window: &Self::Type) -> Inhibit {
fn close_request(&self) -> Propagation {
/*
// Store task data in vector
let backup_data: Vec<TaskData> = window
Expand Down Expand Up @@ -390,7 +427,7 @@ impl WindowImpl for SettingsWindow {
.emit_by_name::<i32>("update-all-views", &[]);

// Pass close request on to the parent
self.parent_close_request(window)
self.parent_close_request()
}
}

Expand Down
24 changes: 17 additions & 7 deletions src/settingswindow/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 Deren Vural
// SPDX-FileCopyrightText: 2024 Deren Vural
// SPDX-License-Identifier: GPL-3.0-or-later

/**
Expand All @@ -21,11 +21,20 @@
mod imp;

// Imports
use adwaita::{gio, glib, prelude::*, subclass::prelude::*};
use gio::Settings;
use glib::{clone, Object};
use gtk::{Adjustment, CheckButton, StringList};
// std
use std::cell::RefMut;
// gtk-rs
use adwaita::{
gio, glib,
prelude::*, subclass::prelude::*
};
use gio::Settings;
use glib::{
clone, Object
};
use gtk::{
Adjustment, CheckButton, StringList
};

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

// Set custom properties
//
Expand Down

0 comments on commit dbea3a1

Please sign in to comment.