Skip to content

Commit c3b6025

Browse files
author
Deren Vural
committed
empty GObject subclass template
Signed-off-by: Deren Vural <[email protected]>
1 parent 82f3dee commit c3b6025

File tree

2 files changed

+258
-0
lines changed

2 files changed

+258
-0
lines changed

src/provider/imp.rs

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// SPDX-FileCopyrightText: 2022 Deren Vural
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
/*
5+
* Name:
6+
* imp.rs
7+
*
8+
* Description:
9+
* Implementation of our custom GObject class (Provider)
10+
*
11+
* Made:
12+
* 06/10/2022
13+
*
14+
* Made by:
15+
* Deren Vural
16+
*
17+
* Notes:
18+
*
19+
*/
20+
21+
// Imports
22+
use gtk::glib::once_cell::sync::Lazy;
23+
use gtk::glib::{self, ParamSpec, Value};
24+
use gtk::prelude::*;
25+
use gtk::subclass::prelude::*;
26+
use std::cell::Cell;
27+
28+
// Object holding the State
29+
#[derive(Default)]
30+
pub struct Provider;
31+
32+
// The central trait for subclassing a GObject
33+
#[glib::object_subclass]
34+
impl ObjectSubclass for Provider {
35+
//Crate+Obj to avoid collisions
36+
const NAME: &'static str = "NvidiaExtensionRustProcessor";
37+
// the actual GObject that will be created
38+
type Type = super::Provider;
39+
// Parent GObject we inherit from
40+
type ParentType = gtk::Widget;
41+
}
42+
43+
/*
44+
* Trait Name:
45+
* ObjectImpl
46+
*
47+
* Description:
48+
* Trait shared by all GObjects
49+
*
50+
* Made:
51+
* 06/10/2022
52+
*
53+
* Made by:
54+
* Deren Vural
55+
*
56+
* Notes:
57+
*
58+
*/
59+
impl ObjectImpl for Provider {
60+
/*
61+
* Name:
62+
* properties
63+
*
64+
* Description:
65+
* Create list of custom properties for our GObject
66+
*
67+
* Made:
68+
* 06/10/2022
69+
*
70+
* Made by:
71+
* Deren Vural
72+
*
73+
* Notes:
74+
* beware that you need to use kebab-case (https://en.wikipedia.org/wiki/Letter_case#Kebab_case)
75+
*
76+
* ParamSpec Examples:
77+
* glib::ParamSpecString::builder("icon").build(),
78+
* glib::ParamSpecUInt::builder("gpu_count").build(),
79+
* glib::ParamSpecString::builder("call_extension").build(),
80+
* TODO: these are from property class
81+
* glib::ParamSpecBoxed::builder("processor").build(),
82+
* glib::ParamSpecObject::builder("formatter").build(),
83+
*/
84+
fn properties() -> &'static [ParamSpec] {
85+
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| vec![]);
86+
87+
//println!("PROPERTIES: {:?}", PROPERTIES);//TEST
88+
//println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST
89+
90+
PROPERTIES.as_ref()
91+
}
92+
93+
/*
94+
* Name:
95+
* set_property
96+
*
97+
* Description:
98+
* Mutator for custom GObject properties
99+
*
100+
* Made:
101+
* 06/10/2022
102+
*
103+
* Made by:
104+
* Deren Vural
105+
*
106+
* Notes:
107+
*
108+
*/
109+
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
110+
//println!("setting: {:?}", pspec.name());//TEST
111+
112+
match pspec.name() {
113+
_ => unimplemented!(), //TODO
114+
}
115+
}
116+
117+
/*
118+
* Name:
119+
* property
120+
*
121+
* Description:
122+
* Accessor for custom GObject properties
123+
*
124+
* Made:
125+
* 06/10/2022
126+
*
127+
* Made by:
128+
* Deren Vural
129+
*
130+
* Notes:
131+
*
132+
*/
133+
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
134+
//println!("getting: {:?}", pspec.name());//TEST
135+
136+
match pspec.name() {
137+
_ => unimplemented!(), //TODO
138+
}
139+
}
140+
}
141+
142+
/*
143+
* Trait Name:
144+
* WidgetImpl
145+
*
146+
* Description:
147+
* Trait shared by all widgets
148+
*
149+
* Made:
150+
* 06/10/2022
151+
*
152+
* Made by:
153+
* Deren Vural
154+
*
155+
* Notes:
156+
* leaving blank atm, boilerplate
157+
*/
158+
impl WidgetImpl for Provider {}

src/provider/mod.rs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// SPDX-FileCopyrightText: 2022 Deren Vural
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
/*
5+
* Name:
6+
* mod.rs
7+
*
8+
* Description:
9+
* Public-facing interface/wrapper for our custom GObject (Provider)
10+
*
11+
* Made:
12+
* 06/10/2022
13+
*
14+
* Made by:
15+
* Deren Vural
16+
*
17+
* Notes:
18+
*
19+
*/
20+
21+
// Custom GObjects
22+
mod imp;
23+
24+
// Imports
25+
use super::subprocess;
26+
use glib::Object;
27+
use gtk::{gio, glib, prelude::ObjectExt};
28+
use std::ffi::OsStr;
29+
30+
// GObject wrapper for Provider
31+
glib::wrapper! {
32+
pub struct Provider(ObjectSubclass<imp::Provider>)
33+
@extends gtk::Widget,
34+
@implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget;
35+
}
36+
37+
/*
38+
* Trait Name:
39+
* Provider
40+
*
41+
* Description:
42+
* Trait shared by all Providers
43+
*
44+
* Made:
45+
* 06/10/2022
46+
*
47+
* Made by:
48+
* Deren Vural
49+
*
50+
* Notes:
51+
*
52+
*/
53+
impl Provider {
54+
/*
55+
* Name:
56+
* new
57+
*
58+
* Description:
59+
* Create a new Provider object
60+
*
61+
* Made:
62+
* 06/10/2022
63+
*
64+
* Made by:
65+
* Deren Vural
66+
*
67+
* Notes:
68+
*
69+
*/
70+
pub fn new() -> Self {
71+
let obj: Provider = Object::new(&[]).expect("Failed to create `Provider`");
72+
73+
// TODO: set properties
74+
//obj.set_property("call", base_call.to_string().clone());
75+
76+
obj
77+
}
78+
}
79+
80+
/*
81+
* Trait Name:
82+
* Default
83+
*
84+
* Description:
85+
* Default object
86+
*
87+
* Made:
88+
* 06/10/2022
89+
*
90+
* Made by:
91+
* Deren Vural
92+
*
93+
* Notes:
94+
*
95+
*/
96+
impl Default for Provider {
97+
fn default() -> Self {
98+
Self::new()
99+
}
100+
}

0 commit comments

Comments
 (0)