Skip to content

Commit debda60

Browse files
committed
Updated src/processor/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 from glib::value as it now has its own module in glib - Refactored "properties()" function to reflect OnceLock changes - Removed now unused "_obj" parameter to "property()" and "set_property()" functions Updated src/processor/mod.rs: - Updated reuse copyright year - Added clearer import headers - Updated "new()" function to use "Object::builder::<Processor>().build()" instead of untyped "Obect::new()"" Signed-off-by: Deren Vural <[email protected]>
1 parent 6a9ec5e commit debda60

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

src/processor/imp.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +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;
5-
use glib::{once_cell::sync::Lazy, ParamSpec, Value};
6-
use gtk::{prelude::*, subclass::prelude::*};
74
/**
85
* Name:
96
* imp.rs
@@ -23,7 +20,18 @@ use gtk::{prelude::*, subclass::prelude::*};
2320
* <https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/g_object_properties/4/custom_button/mod.rs>
2421
*/
2522
// Imports
23+
// std
24+
use std::sync::OnceLock;
2625
use std::cell::Cell;
26+
// gtk-rs
27+
use gtk::{
28+
prelude::*, subclass::prelude::*
29+
};
30+
use adwaita::glib;
31+
use glib::{
32+
ParamSpec,
33+
value::Value
34+
};
2735

2836
/// Object holding the State and any Template Children
2937
#[derive(Default)]
@@ -87,19 +95,18 @@ impl ObjectImpl for Processor {
8795
* glib::ParamSpecObject::builder("formatter").build(),
8896
*/
8997
fn properties() -> &'static [ParamSpec] {
90-
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
98+
static PROPERTIES: OnceLock<Vec<ParamSpec>> = OnceLock::new();
99+
PROPERTIES.get_or_init(|| {
91100
vec![
92101
glib::ParamSpecString::builder("base-call").build(),
93102
glib::ParamSpecString::builder("start-call").build(),
94103
glib::ParamSpecString::builder("middle-call").build(),
95-
glib::ParamSpecString::builder("end-call").build(),
104+
glib::ParamSpecString::builder("end-call").build()
96105
]
97-
});
106+
})
98107

99108
//println!("PROPERTIES: {:?}", PROPERTIES);//TEST
100109
//println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST
101-
102-
PROPERTIES.as_ref()
103110
}
104111

105112
/**
@@ -118,7 +125,12 @@ impl ObjectImpl for Processor {
118125
* Notes:
119126
*
120127
*/
121-
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
128+
fn set_property(
129+
&self,
130+
_id: usize,
131+
value: &Value,
132+
pspec: &ParamSpec
133+
) {
122134
//println!("setting: {:?}", pspec.name());//TEST
123135

124136
match pspec.name() {
@@ -166,7 +178,11 @@ impl ObjectImpl for Processor {
166178
* Notes:
167179
*
168180
*/
169-
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
181+
fn property(
182+
&self,
183+
_id: usize,
184+
pspec: &ParamSpec
185+
) -> Value {
170186
//println!("getting: {:?}", pspec.name());//TEST
171187

172188
match pspec.name() {

src/processor/mod.rs

Lines changed: 10 additions & 4 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
/**
@@ -22,9 +22,14 @@
2222
mod imp;
2323

2424
// Imports
25-
use glib::Object;
26-
use gtk::{gio, glib, prelude::ObjectExt};
25+
// std
2726
use std::ffi::OsStr;
27+
// gtk-rs
28+
use gtk::{
29+
gio, glib,
30+
prelude::ObjectExt
31+
};
32+
use glib::Object;
2833

2934
// Crates
3035
use crate::subprocess::subprocess::exec_communicate_sync;
@@ -75,7 +80,8 @@ impl Processor {
7580
middle_call: Option<&str>,
7681
end_call: &str,
7782
) -> Self {
78-
let obj: Processor = Object::new(&[]).expect("Failed to create `Processor`");
83+
// Create Object
84+
let obj: Processor = Object::builder::<Processor>().build();
7985

8086
// Set properties
8187
obj.set_property("base-call", String::from(base_call));

0 commit comments

Comments
 (0)