Skip to content

Commit 90c2cee

Browse files
authored
Merge pull request #45 from derenv/modification_window
Modification window
2 parents b49a8f6 + 579604d commit 90c2cee

File tree

16 files changed

+1850
-390
lines changed

16 files changed

+1850
-390
lines changed

src/com.gtk_d.NvidiaMonitorRust.gschema.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
5757
]</default>
5858
</key>
5959

60-
<key name="pageconfigs" type="as">
60+
<key name="viewcomponentconfigs" type="as">
6161
<default>[
6262
"GPU-fb231809-72f7-79fd-eb6c-178b24827aa9:GPU:0:util",
6363
"GPU-fb231809-72f7-79fd-eb6c-178b24827aa9:GPU:1:temp",

src/formatter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl Formatter {
101101
.expect("`settings` should not be set before calling `setup_settings`.");
102102
}
103103

104-
/*
104+
/**
105105
* Name:
106106
* format
107107
*

src/gpu_page/imp.rs

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
use adwaita::{gio, glib, prelude::*, ViewStack, ViewSwitcherBar};
2323
use gio::Settings;
2424
use glib::{
25-
once_cell::sync::Lazy, once_cell::sync::OnceCell, subclass::InitializingObject, FromVariant,
26-
ParamSpec, ToValue, Value,
25+
once_cell::sync::Lazy, once_cell::sync::OnceCell, subclass::InitializingObject,
26+
subclass::Signal, subclass::SignalType, FromVariant, ParamSpec, ToValue, Value,
2727
};
2828
use gtk::{subclass::prelude::*, CompositeTemplate, TemplateChild};
2929
use std::{cell::Cell, cell::RefCell, rc::Rc};
@@ -43,9 +43,9 @@ pub struct ModificationWindowContainer {
4343
#[template(resource = "/gpu-page.ui")]
4444
pub struct GpuPage {
4545
pub settings: OnceCell<Settings>,
46-
uuid: Cell<String>,
47-
name: Cell<String>,
48-
provider: Cell<Option<Provider>>,
46+
uuid: OnceCell<String>,
47+
name: OnceCell<String>,
48+
provider: OnceCell<Option<Provider>>,
4949
refreshid: Cell<u32>,
5050

5151
pub modification_window: Rc<RefCell<ModificationWindowContainer>>,
@@ -90,11 +90,7 @@ impl ObjectSubclass for GpuPage {
9090
*/
9191
#[gtk::template_callbacks]
9292
impl GpuPage {
93-
// #[template_callback]
94-
// fn get_gpu_data(&self, _label: &Label) {
95-
// //
96-
// println!("TEST callback");//TEST
97-
// }
93+
//
9894
}
9995

10096
impl GpuPage {
@@ -287,21 +283,24 @@ impl ObjectImpl for GpuPage {
287283

288284
match pspec.name() {
289285
"uuid" => match value.get() {
290-
Ok(input_uuid) => {
291-
self.uuid.replace(input_uuid);
292-
}
286+
Ok(input_uuid) => self
287+
.uuid
288+
.set(input_uuid)
289+
.expect("`uuid` should not be set after calling constructor.."),
293290
Err(_) => panic!("The value needs to be of type `String`."),
294291
},
295292
"name" => match value.get() {
296-
Ok(input_name) => {
297-
self.name.replace(input_name);
298-
}
293+
Ok(input_name) => self
294+
.name
295+
.set(input_name)
296+
.expect("`name` should not be set after calling constructor.."),
299297
Err(_) => panic!("The value needs to be of type `String`."),
300298
},
301299
"provider" => match value.get() {
302-
Ok(input_provider_property) => {
303-
self.provider.replace(input_provider_property);
304-
}
300+
Ok(input_provider) => self
301+
.provider
302+
.set(input_provider)
303+
.expect("`provider` should not be set after calling constructor.."),
305304
Err(_) => panic!("The value needs to be of type `Provider`."),
306305
},
307306
"refreshid" => match value.get() {
@@ -341,29 +340,18 @@ impl ObjectImpl for GpuPage {
341340
//println!("getting: {:?}", pspec.name());//TEST
342341

343342
match pspec.name() {
344-
"uuid" => {
345-
//TODO: this seems ridiculous..
346-
let value: String = self.uuid.take();
347-
348-
self.uuid.set(value.clone());
349-
350-
value.to_value()
351-
}
352-
"name" => {
353-
//TODO: this seems ridiculous..
354-
let value: String = self.name.take();
355-
356-
self.name.set(value.clone());
357-
358-
value.to_value()
359-
}
360-
"provider" => {
361-
let value: Option<Provider> = self.provider.take();
362-
363-
self.provider.set(value.clone());
364-
365-
value.to_value()
366-
}
343+
"uuid" => match self.uuid.clone().get() {
344+
Some(value) => return value.to_value(),
345+
None => panic!("Cannot get value of `uuid` property.."),
346+
},
347+
"name" => match self.name.clone().get() {
348+
Some(value) => return value.to_value(),
349+
None => panic!("Cannot get value of `name` property.."),
350+
},
351+
"provider" => match self.provider.clone().get() {
352+
Some(value) => return value.to_value(),
353+
None => panic!("Cannot get value of `provider` property.."),
354+
},
367355
"refreshid" => {
368356
let value: u32 = self.refreshid.take();
369357

@@ -374,6 +362,38 @@ impl ObjectImpl for GpuPage {
374362
_ => panic!("Property `{}` does not exist..", pspec.name()),
375363
}
376364
}
365+
366+
/**
367+
* Name:
368+
* signals
369+
*
370+
* Description:
371+
* Defines the list of signals
372+
*
373+
* Made:
374+
* 07/01/2023
375+
*
376+
* Made by:
377+
* Deren Vural
378+
*
379+
* Notes:
380+
* beware that you need to use kebab-case (<https://en.wikipedia.org/wiki/Letter_case#Kebab_case>)
381+
*
382+
* <https://gtk-rs.org/gtk4-rs/stable/latest/book/g_object_signals.html>
383+
*
384+
* SignalType::from(i32::static_type())
385+
*/
386+
fn signals() -> &'static [Signal] {
387+
static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
388+
vec![Signal::builder(
389+
"update-views",
390+
&[SignalType::from(i32::static_type())],
391+
SignalType::from(i32::static_type()),
392+
)
393+
.build()]
394+
});
395+
SIGNALS.as_ref()
396+
}
377397
}
378398

379399
/**

0 commit comments

Comments
 (0)