Skip to content

Commit 8de4b47

Browse files
committed
Updated src/property/imp.rs:
- Updated reuse copyright year - Added clearer import headers - Refactored to now import std::sync::OncelLock as it has been [merged into std](rust-lang/rust#105587) - Refactored to import Value and ToValue from glib::value as it now has its own module in glib - Refactored "properties()" functions to reflect OnceLock changes - Removed now unused "_obj" parameter to "property()" and "set_property()" functions Updated src/property/mod.rs: - Updated reuse copyright year - Added clearer import headers - Added import of FromValue from glib::value - Updated "new()" function to use "Object::builder::<Property>().build()" instead of untyped "Obect::new()"" - Commented out "update_value()" function as it is unused Signed-off-by: Deren Vural <[email protected]>
1 parent debda60 commit 8de4b47

File tree

2 files changed

+77
-40
lines changed

2 files changed

+77
-40
lines changed

src/property/imp.rs

+26-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +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::glib;
54
/**
65
* Name:
76
* imp.rs
@@ -19,9 +18,16 @@ use adwaita::glib;
1918
*
2019
*/
2120
// Imports
22-
use glib::{once_cell::sync::Lazy, ParamSpec, ToValue, Value};
23-
use gtk::subclass::prelude::*;
21+
// std
22+
use std::sync::OnceLock;
2423
use std::cell::Cell;
24+
// gtk-rs
25+
use gtk::subclass::prelude::*;
26+
use adwaita::glib;
27+
use glib::{
28+
ParamSpec,
29+
value::ToValue, value::Value
30+
};
2531

2632
// Modules
2733
use crate::formatter::Formatter;
@@ -81,18 +87,17 @@ impl ObjectImpl for Property {
8187
* beware that you need to use kebab-case (<https://en.wikipedia.org/wiki/Letter_case#Kebab_case>)
8288
*/
8389
fn properties() -> &'static [ParamSpec] {
84-
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
90+
static PROPERTIES: OnceLock<Vec<ParamSpec>> = OnceLock::new();
91+
PROPERTIES.get_or_init(|| {
8592
vec![
8693
glib::ParamSpecString::builder("id").build(),
87-
glib::ParamSpecObject::builder("processor", glib::Type::OBJECT).build(),
88-
glib::ParamSpecObject::builder("formatter", glib::Type::OBJECT).build(),
94+
glib::ParamSpecObject::builder::<Processor>("processor").build(),
95+
glib::ParamSpecObject::builder::<Formatter>("formatter").build(),
8996
]
90-
});
97+
})
9198

9299
//println!("PROPERTIES: {:?}", PROPERTIES);//TEST
93100
//println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST
94-
95-
PROPERTIES.as_ref()
96101
}
97102

98103
/**
@@ -111,7 +116,12 @@ impl ObjectImpl for Property {
111116
* Notes:
112117
*
113118
*/
114-
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
119+
fn set_property(
120+
&self,
121+
_id: usize,
122+
value: &Value,
123+
pspec: &ParamSpec
124+
) {
115125
//println!("setting: {:?}", pspec.name());//TEST
116126

117127
match pspec.name() {
@@ -153,7 +163,11 @@ impl ObjectImpl for Property {
153163
* Notes:
154164
*
155165
*/
156-
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
166+
fn property(
167+
&self,
168+
_id: usize,
169+
pspec: &ParamSpec
170+
) -> Value {
157171
//println!("getting: {:?}", pspec.name());//TEST
158172

159173
match pspec.name() {

src/property/mod.rs

+51-28
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
/**
@@ -20,10 +20,18 @@
2020
// Custom GObjects
2121
mod imp;
2222

23-
use gdk::glib::value::FromValue;
2423
// Imports
25-
use glib::Object;
26-
use gtk::{glib, prelude::*};
24+
// std
25+
//
26+
// gtk-rs
27+
use gtk::{
28+
prelude::*,
29+
glib
30+
};
31+
use glib::{
32+
value::FromValue,
33+
Object
34+
};
2735

2836
// Modules
2937
use crate::formatter::Formatter;
@@ -72,8 +80,13 @@ impl Property {
7280
*
7381
* given proc and gpuCount
7482
*/
75-
pub fn new(processor: &Processor, formatter: &Formatter, id: &str) -> Self {
76-
let obj: Property = Object::new(&[]).expect("Failed to create `Property`.");
83+
pub fn new(
84+
processor: &Processor,
85+
formatter: &Formatter,
86+
id: &str
87+
) -> Self {
88+
// Create Object
89+
let obj: Property = Object::builder::<Property>().build();
7790

7891
// Set properties
7992
obj.set_property("processor", processor);
@@ -100,7 +113,10 @@ impl Property {
100113
* Notes:
101114
*
102115
*/
103-
pub fn parse(self, uuid: &str) -> Option<String> {
116+
pub fn parse(
117+
self,
118+
uuid: &str
119+
) -> Option<String> {
104120
// println!("UUID: `{}`", uuid); //TEST
105121
// Grab formatter & processor
106122
let formatter: Formatter = self.property("formatter");
@@ -159,31 +175,38 @@ impl Property {
159175
* Notes:
160176
*
161177
*/
162-
pub fn get_value<T: for<'a> FromValue<'a> + 'static>(&self, name: &str) -> T {
178+
pub fn get_value<T: for<'a> FromValue<'a> + 'static>(
179+
&self,
180+
name: &str
181+
) -> T {
163182
// Return the value of the property
164183
self.property::<T>(name)
165184
}
166185

167-
/**
168-
* Name:
169-
* update_value
170-
*
171-
* Description:
172-
* Update a property with a new value
173-
*
174-
* Made:
175-
* 29/10/2022
176-
*
177-
* Made by:
178-
* Deren Vural
179-
*
180-
* Notes:
181-
*
182-
*/
183-
pub fn update_value<T: ToValue>(&self, property_name: &str, value: T) {
184-
// Update the property with new value
185-
self.set_property(property_name, value);
186-
}
186+
// /**
187+
// * Name:
188+
// * update_value
189+
// *
190+
// * Description:
191+
// * Update a property with a new value
192+
// *
193+
// * Made:
194+
// * 29/10/2022
195+
// *
196+
// * Made by:
197+
// * Deren Vural
198+
// *
199+
// * Notes:
200+
// *
201+
// */
202+
// pub fn update_value<T: Into<Variant>>(
203+
// &self,
204+
// property_name: &str,
205+
// value: T
206+
// ) {
207+
// // Update the property with new value
208+
// self.set_property(property_name, value);
209+
// }
187210
}
188211

189212
/**

0 commit comments

Comments
 (0)