Skip to content

Commit b49a8f6

Browse files
authored
Merge pull request #44 from derenv/better_loading
Better loading
2 parents fd851be + 591f540 commit b49a8f6

File tree

16 files changed

+1523
-217
lines changed

16 files changed

+1523
-217
lines changed

install_schemas.sh

100644100755
File mode changed.

src/com.gtk_d.NvidiaMonitorRust.gschema.xml

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,25 @@ SPDX-License-Identifier: GPL-3.0-or-later
77
<schema id="com.gtk_d.NvidiaMonitorRust" path="/com/gtk_d/NvidiaMonitorRust/">
88
<key name="nvidia-settings-open" type="b">
99
<default>false</default>
10-
<summary>Nvidia settings state</summary>
10+
<summary>Nvidia settings window state</summary>
1111
<description>
1212
Nvidia settings open/closed
1313
</description>
1414
</key>
1515
<key name="app-settings-open" type="b">
1616
<default>false</default>
17-
<summary>App settings state</summary>
17+
<summary>App settings window state</summary>
1818
<description>
1919
App settings window open/closed
2020
</description>
2121
</key>
22+
<key name="modification-open" type="b">
23+
<default>false</default>
24+
<summary>App view-modification window state</summary>
25+
<description>
26+
App view-modification window open/closed
27+
</description>
28+
</key>
2229

2330
<key name="refreshrate" type="i">
2431
<default>5</default>
@@ -42,18 +49,26 @@ SPDX-License-Identifier: GPL-3.0-or-later
4249
</description>
4350
</key>
4451

45-
<!-- Not entirely sure what these are for..-->
46-
<key name="settingsconfig" type="as">
47-
<default>[]</default>
48-
</key>
49-
<key name="smiconfig" type="as">
50-
<default>[]</default>
52+
<key name="viewconfigs" type="as">
53+
<default>[
54+
"GPU-fb231809-72f7-79fd-eb6c-178b24827aa9:0:GPU",
55+
"GPU-fb231809-72f7-79fd-eb6c-178b24827aa9:1:VRAM",
56+
"GPU-fb231809-72f7-79fd-eb6c-178b24827aa9:2:Fans"
57+
]</default>
5158
</key>
52-
<key name="settingsandsmiconfig" type="as">
53-
<default>[]</default>
54-
</key>
55-
<key name="optimusconfig" type="as">
56-
<default>[]</default>
59+
60+
<key name="pageconfigs" type="as">
61+
<default>[
62+
"GPU-fb231809-72f7-79fd-eb6c-178b24827aa9:GPU:0:util",
63+
"GPU-fb231809-72f7-79fd-eb6c-178b24827aa9:GPU:1:temp",
64+
"GPU-fb231809-72f7-79fd-eb6c-178b24827aa9:GPU:2:power_usage",
65+
66+
"GPU-fb231809-72f7-79fd-eb6c-178b24827aa9:VRAM:2:memory_usage",
67+
"GPU-fb231809-72f7-79fd-eb6c-178b24827aa9:VRAM:3:memory_total",
68+
"GPU-fb231809-72f7-79fd-eb6c-178b24827aa9:VRAM:4:mem_ctrl_util",
69+
70+
"GPU-fb231809-72f7-79fd-eb6c-178b24827aa9:Fans:5:fan_speed"
71+
]</default>
5772
</key>
5873
</schema>
5974
</schemalist>

src/gpu_page/imp.rs

Lines changed: 107 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,24 @@
1919
*/
2020

2121
// Imports
22-
use adwaita::{gio, glib, prelude::*};
22+
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, ParamSpec,
26-
ToValue, Value,
25+
once_cell::sync::Lazy, once_cell::sync::OnceCell, subclass::InitializingObject, FromVariant,
26+
ParamSpec, ToValue, Value,
2727
};
28-
use gtk::{subclass::prelude::*, CompositeTemplate};
29-
use std::cell::Cell;
28+
use gtk::{subclass::prelude::*, CompositeTemplate, TemplateChild};
29+
use std::{cell::Cell, cell::RefCell, rc::Rc};
3030

3131
// Modules
32-
use crate::provider::Provider;
32+
use crate::{modificationwindow::ModificationWindow, provider::Provider};
33+
34+
/// Structure for storing a SettingsWindow object and any related information
35+
#[derive(Default)]
36+
pub struct ModificationWindowContainer {
37+
pub window: Option<ModificationWindow>,
38+
pub open: bool,
39+
}
3340

3441
/// Object holding the State and any Template Children
3542
#[derive(CompositeTemplate, Default)]
@@ -39,6 +46,12 @@ pub struct GpuPage {
3946
uuid: Cell<String>,
4047
name: Cell<String>,
4148
provider: Cell<Option<Provider>>,
49+
refreshid: Cell<u32>,
50+
51+
pub modification_window: Rc<RefCell<ModificationWindowContainer>>,
52+
53+
#[template_child]
54+
pub view_switcher: TemplateChild<ViewSwitcherBar>,
4255
}
4356

4457
/// The central trait for subclassing a GObject
@@ -84,6 +97,79 @@ impl GpuPage {
8497
// }
8598
}
8699

100+
impl GpuPage {
101+
/**
102+
* Name:
103+
* get_setting
104+
*
105+
* Description:
106+
* Generic function for getting setting value
107+
*
108+
* Made:
109+
* 04/12/2022
110+
*
111+
* Made by:
112+
* Deren Vural
113+
*
114+
* Notes:
115+
*
116+
*/
117+
pub fn get_setting<T: FromVariant>(&self, name: &str) -> T {
118+
// Return the value of the property
119+
match self.settings.get() {
120+
Some(settings) => settings.get::<T>(name),
121+
None => panic!("`settings` should be set in `setup_settings`."),
122+
}
123+
}
124+
125+
/**
126+
* Name:
127+
* update_setting
128+
*
129+
* Description:
130+
* Generic function for updating setting values
131+
*
132+
* Made:
133+
* 04/12/2022
134+
*
135+
* Made by:
136+
* Deren Vural
137+
*
138+
* Notes:
139+
*
140+
*/
141+
pub fn update_setting<T: ToVariant>(&self, name: &str, value: T) {
142+
// Fetch settings
143+
match self.settings.get() {
144+
Some(settings) => match settings.set(name, &value) {
145+
Ok(_) => println!("..Setting `{}` updated!", name),
146+
Err(err) => panic!("..Cannot update `{}` setting: `{}`", name, err),
147+
},
148+
None => panic!("..Cannot retrieve settings"),
149+
}
150+
}
151+
152+
/**
153+
* Name:
154+
* replace_stack
155+
*
156+
* Description:
157+
* Replace current view_stack using passed value
158+
*
159+
* Made:
160+
* 04/12/2022
161+
*
162+
* Made by:
163+
* Deren Vural
164+
*
165+
* Notes:
166+
*
167+
*/
168+
pub fn replace_stack(&self, stack: Option<&ViewStack>) {
169+
self.view_switcher.set_stack(stack);
170+
}
171+
}
172+
87173
/**
88174
* Trait Name:
89175
* ObjectImpl
@@ -123,6 +209,7 @@ impl ObjectImpl for GpuPage {
123209
self.parent_constructed(obj);
124210

125211
// Setup
212+
self.refreshid.set(0);
126213
//obj.setup_settings();
127214
//obj.load_properties();//TODO
128215
//obj.setup_widgets();
@@ -161,6 +248,7 @@ impl ObjectImpl for GpuPage {
161248
glib::ParamSpecString::builder("uuid").build(),
162249
glib::ParamSpecString::builder("name").build(),
163250
glib::ParamSpecObject::builder("provider", glib::Type::OBJECT).build(),
251+
glib::ParamSpecUInt::builder("refreshid").build(),
164252
]
165253
});
166254

@@ -216,6 +304,12 @@ impl ObjectImpl for GpuPage {
216304
}
217305
Err(_) => panic!("The value needs to be of type `Provider`."),
218306
},
307+
"refreshid" => match value.get() {
308+
Ok(input_refreshid_property) => {
309+
self.refreshid.replace(input_refreshid_property);
310+
}
311+
Err(_) => panic!("The value needs to be of type `u32`."),
312+
},
219313
_ => panic!("Property `{}` does not exist..", pspec.name()),
220314
}
221315

@@ -270,6 +364,13 @@ impl ObjectImpl for GpuPage {
270364

271365
value.to_value()
272366
}
367+
"refreshid" => {
368+
let value: u32 = self.refreshid.take();
369+
370+
self.refreshid.set(value.clone());
371+
372+
value.to_value()
373+
}
273374
_ => panic!("Property `{}` does not exist..", pspec.name()),
274375
}
275376
}

0 commit comments

Comments
 (0)