Skip to content

Commit

Permalink
Updated src/processor/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::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]>
  • Loading branch information
derenv committed May 20, 2024
1 parent 6a9ec5e commit debda60
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
38 changes: 27 additions & 11 deletions src/processor/imp.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// SPDX-FileCopyrightText: 2022 Deren Vural
// SPDX-FileCopyrightText: 2024 Deren Vural
// SPDX-License-Identifier: GPL-3.0-or-later

use adwaita::glib;
use glib::{once_cell::sync::Lazy, ParamSpec, Value};
use gtk::{prelude::*, subclass::prelude::*};
/**
* Name:
* imp.rs
Expand All @@ -23,7 +20,18 @@ use gtk::{prelude::*, subclass::prelude::*};
* <https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/g_object_properties/4/custom_button/mod.rs>
*/
// Imports
// std
use std::sync::OnceLock;
use std::cell::Cell;
// gtk-rs
use gtk::{
prelude::*, subclass::prelude::*
};
use adwaita::glib;
use glib::{
ParamSpec,
value::Value
};

/// Object holding the State and any Template Children
#[derive(Default)]
Expand Down Expand Up @@ -87,19 +95,18 @@ impl ObjectImpl for Processor {
* 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![
glib::ParamSpecString::builder("base-call").build(),
glib::ParamSpecString::builder("start-call").build(),
glib::ParamSpecString::builder("middle-call").build(),
glib::ParamSpecString::builder("end-call").build(),
glib::ParamSpecString::builder("end-call").build()
]
});
})

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

PROPERTIES.as_ref()
}

/**
Expand All @@ -118,7 +125,12 @@ impl ObjectImpl for Processor {
* 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 Down Expand Up @@ -166,7 +178,11 @@ impl ObjectImpl for Processor {
* 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
14 changes: 10 additions & 4 deletions src/processor/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 @@ -22,9 +22,14 @@
mod imp;

// Imports
use glib::Object;
use gtk::{gio, glib, prelude::ObjectExt};
// std
use std::ffi::OsStr;
// gtk-rs
use gtk::{
gio, glib,
prelude::ObjectExt
};
use glib::Object;

// Crates
use crate::subprocess::subprocess::exec_communicate_sync;
Expand Down Expand Up @@ -75,7 +80,8 @@ impl Processor {
middle_call: Option<&str>,
end_call: &str,
) -> Self {
let obj: Processor = Object::new(&[]).expect("Failed to create `Processor`");
// Create Object
let obj: Processor = Object::builder::<Processor>().build();

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

0 comments on commit debda60

Please sign in to comment.