Skip to content

Commit f4d127d

Browse files
author
Deren Vural
committed
Better Loading of Views
Updated GpuPage UI: - Added AdwViewStack and title + switcher bar for the new views - There are some commented out defaults here for my sanity Updated gschema XML: - Added "viewconfigs" string list key with some defaults: UUID:viewposition:View Title - Added "pageconfigs" string list key with some defaults: UUID:View Title:Property Position:Property ID - Removed unused keys "settingsconfig", "smiconfig", "settingsandsmiconfig", "optimusconfig" Updated GpuPage class: - Removed unused imports - Added "refreshid" struct member, a u32 value that is either 0 or some SourceId value - Added "view_stack" template_child struct member, holds the views of each GpuPage - Added "add_stack_item()" function in GpuPage trait for appending a view item to the stack - Updated "constructed()" function in ObjectImpl trait to set new "refreshid" struct member to "0" (i.e. no ID stored) - Updated "property()","set_property()" and "properties()" functions for new "refreshid" struct member - Added "load_views()" function that loads all saved views from settings, then calls functions to populate - Added "check_properties_for_view()" function that uses passed view title, returns list of saved properties - Added "create_properties()" function that adds labels (of properties) to a passed grid and a recurring closure to fill them, returns the grid afterwards (stores the ID of the recurring closure in new "refreshid" struct member to allow removal of this closure!) - Refactored "setup_widgets()" into the above functions, added (currently mostly empty) closure for edit_button "clicked" signal: to be updated for ModificationWindow class. At the moment only re-runs "load_views()" function Signed-off-by: Deren Vural <[email protected]>
1 parent fd851be commit f4d127d

File tree

6 files changed

+565
-175
lines changed

6 files changed

+565
-175
lines changed

install_schemas.sh

100644100755
File mode changed.

src/com.gtk_d.NvidiaMonitorRust.gschema.xml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,26 @@ SPDX-License-Identifier: GPL-3.0-or-later
4242
</description>
4343
</key>
4444

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

src/gpu_page/imp.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use glib::{
2525
once_cell::sync::Lazy, once_cell::sync::OnceCell, subclass::InitializingObject, ParamSpec,
2626
ToValue, Value,
2727
};
28-
use gtk::{subclass::prelude::*, CompositeTemplate};
28+
use gtk::{subclass::prelude::*, CompositeTemplate, TemplateChild};
2929
use std::cell::Cell;
3030

3131
// Modules
@@ -39,6 +39,10 @@ pub struct GpuPage {
3939
uuid: Cell<String>,
4040
name: Cell<String>,
4141
provider: Cell<Option<Provider>>,
42+
refreshid: Cell<u32>,
43+
44+
#[template_child]
45+
pub view_stack: TemplateChild<adwaita::ViewStack>,
4246
}
4347

4448
/// The central trait for subclassing a GObject
@@ -84,6 +88,35 @@ impl GpuPage {
8488
// }
8589
}
8690

91+
impl GpuPage {
92+
/*
93+
* Name:
94+
* add_stack_item
95+
*
96+
* Description:
97+
* Add item passed as a parameter to the view_stack object, using name, title & icon passed as parameters
98+
*
99+
* Made:
100+
* 03/12/2022
101+
*
102+
* Made by:
103+
* Deren Vural
104+
*
105+
* Notes:
106+
*
107+
*/
108+
pub fn add_stack_item<T: IsA<gtk::Widget>>(&self, item: &T, name: Option<&str>, title: &str, icon: &str) {
109+
// Add the passed item to the stack
110+
self.view_stack.add_titled(item, name, title);
111+
112+
// Set the icon of the new item
113+
//NOTE: see https://world.pages.gitlab.gnome.org/Rust/libadwaita-rs/stable/latest/docs/libadwaita/struct.ViewStack.html
114+
// function "add_titled_with_icon" not in stable yet
115+
let new_item = self.view_stack.page(item);
116+
new_item.set_icon_name(Some(icon));
117+
}
118+
}
119+
87120
/**
88121
* Trait Name:
89122
* ObjectImpl
@@ -123,6 +156,7 @@ impl ObjectImpl for GpuPage {
123156
self.parent_constructed(obj);
124157

125158
// Setup
159+
self.refreshid.set(0);
126160
//obj.setup_settings();
127161
//obj.load_properties();//TODO
128162
//obj.setup_widgets();
@@ -161,6 +195,7 @@ impl ObjectImpl for GpuPage {
161195
glib::ParamSpecString::builder("uuid").build(),
162196
glib::ParamSpecString::builder("name").build(),
163197
glib::ParamSpecObject::builder("provider", glib::Type::OBJECT).build(),
198+
glib::ParamSpecUInt::builder("refreshid").build(),
164199
]
165200
});
166201

@@ -216,6 +251,12 @@ impl ObjectImpl for GpuPage {
216251
}
217252
Err(_) => panic!("The value needs to be of type `Provider`."),
218253
},
254+
"refreshid" => match value.get() {
255+
Ok(input_refreshid_property) => {
256+
self.refreshid.replace(input_refreshid_property);
257+
}
258+
Err(_) => panic!("The value needs to be of type `u32`."),
259+
},
219260
_ => panic!("Property `{}` does not exist..", pspec.name()),
220261
}
221262

@@ -270,6 +311,13 @@ impl ObjectImpl for GpuPage {
270311

271312
value.to_value()
272313
}
314+
"refreshid" => {
315+
let value: u32 = self.refreshid.take();
316+
317+
self.refreshid.set(value.clone());
318+
319+
value.to_value()
320+
}
273321
_ => panic!("Property `{}` does not exist..", pspec.name()),
274322
}
275323
}

0 commit comments

Comments
 (0)