Skip to content

Commit

Permalink
Updated src/provider/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)
- Added import of Value from glib::value
- Refactored "properties()" function to reflect OnceLock changes
- Removed now unused "_obj" parameter to "property()" and "set_property()" functions

Updated src/provider/mod.rs:
- Updated reuse copyright year
- Added clearer import headers
- Updated "new()" function to use "Object::builder::<Provider>().build()" instead of untyped "Obect::new()""

Signed-off-by: Deren Vural <[email protected]>
  • Loading branch information
derenv committed May 20, 2024
1 parent 8de4b47 commit a28324c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
43 changes: 32 additions & 11 deletions src/provider/imp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-FileCopyrightText: 2022 Deren Vural
// SPDX-FileCopyrightText: 2024 Deren Vural
// SPDX-License-Identifier: GPL-3.0-or-later

use adwaita::glib;
/**
* Name:
* imp.rs
Expand All @@ -19,9 +18,20 @@ use adwaita::glib;
*
*/
// Imports
use glib::{once_cell::sync::Lazy, ParamSpec, Value};
use gtk::{prelude::*, subclass::prelude::*};
use std::{cell::Cell, cell::RefCell};
// std
use std::sync::OnceLock;
use std::cell::{
Cell, RefCell
};
// gtk-rs
use gtk::{
prelude::*, subclass::prelude::*
};
use adwaita::glib;
use glib::{
ParamSpec,
value::Value
};

// Modules
use crate::property::Property;
Expand Down Expand Up @@ -86,13 +96,15 @@ impl ObjectImpl for Provider {
* glib::ParamSpecObject::builder("formatter").build(),
*/
fn properties() -> &'static [ParamSpec] {
static PROPERTIES: Lazy<Vec<ParamSpec>> =
Lazy::new(|| vec![glib::ParamSpecInt::builder("provider-type").build()]);
static PROPERTIES: OnceLock<Vec<ParamSpec>> = OnceLock::new();
PROPERTIES.get_or_init(|| {
vec![
glib::ParamSpecInt::builder("provider-type").build()
]
})

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

PROPERTIES.as_ref()
}

/**
Expand All @@ -111,7 +123,12 @@ impl ObjectImpl for Provider {
* 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 @@ -141,7 +158,11 @@ impl ObjectImpl for Provider {
* 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
21 changes: 15 additions & 6 deletions src/provider/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,19 @@
mod imp;

// Imports
use adwaita::{gio, glib};
use gio::{Cancellable, Settings};
use glib::Object;
use gtk::{prelude::*, subclass::prelude::*};
// std
use std::ffi::OsStr;
// gtk-rs
use gtk::{
prelude::*, subclass::prelude::*
};
use adwaita::{
gio, glib
};
use gio::{
Cancellable, Settings
};
use glib::Object;

// Crates
use crate::{
Expand Down Expand Up @@ -78,7 +86,8 @@ impl Provider {
*
*/
pub fn new(func: fn() -> Vec<Property>, provider_type: i32) -> Self {
let obj: Provider = Object::new(&[]).expect("Failed to create `Provider`");
// Create Object
let obj: Provider = Object::builder::<Provider>().build();

// Set type of provider
obj.set_property("provider-type", provider_type);
Expand Down

0 comments on commit a28324c

Please sign in to comment.