Skip to content

Commit 002fcca

Browse files
author
Deren Vural
committed
Working views
Updated MainWindow UI: - Added some comments Updated SettingsWindow UI: - Added some comments Updated GpuPage UI: - Updated to disable some properties - Updated to use to AdwViewSwitcher (AdwViewSwitcherTitle, AdwViewStack, AdwViewSwitcherBar) - Added a placeholder GtkGrid at 0,0 - Added some example AdwViewStackPage items (in comments) Updated gschema XML: - Updated descriptions for "app-settings-open" and "nvidia-settings-open" - Added "modification-open" key Updated lib.rs: - Added modificationwindow dependancy - Removed unused imports Updated MainWindow class: - Removed "update_prov()" function - Updated some comments to be in docs - Added "update_setting()" call to "close_request()" function, to update "modification-open" setting Updated SettingsWindow class: - Updated "close_request()" function to use "update_setting()" function instead of doing it manually Updated GpuPage class: - Updated imports and modules - Added ModificationWindowContainer struct (like SettingsWindowContainer) - Added "modification_window" struct member - Switched to using the ViewSwitcherBar ("view_switcher"), as can easily swap the stack used - Added "get_setting()" function - Added "update_setting()" function - Added "replace_stack()" function - Updated "load_views()" function, calls "create_updater()" function - Updated "check_properties_for_view()" function - Refactored "create_properties()" function to remove callback function - Added "create_updater()" function to create callback function - Refactored "setup_widgets()" function Updated Processor class: - Disabled some debug print statements Updated Property class: - Disabled some debug print statements Updated Provider class: - Disabled some debug print statements Signed-off-by: Deren Vural <[email protected]>
1 parent aa9b737 commit 002fcca

File tree

15 files changed

+1148
-251
lines changed

15 files changed

+1148
-251
lines changed

src/com.gtk_d.NvidiaMonitorRust.gschema.xml

Lines changed: 9 additions & 2 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>

src/gpu_page/imp.rs

Lines changed: 71 additions & 24 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::{
2525
once_cell::sync::Lazy, once_cell::sync::OnceCell, subclass::InitializingObject, ParamSpec,
26-
ToValue, Value,
26+
ToValue, Value, FromVariant
2727
};
2828
use gtk::{subclass::prelude::*, CompositeTemplate, TemplateChild};
29-
use std::cell::Cell;
29+
use std::{cell::Cell, cell::RefCell, rc::Rc};
3030

3131
// Modules
32-
use crate::provider::Provider;
32+
use crate::{provider::Provider, modificationwindow::ModificationWindow};
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)]
@@ -41,8 +48,10 @@ pub struct GpuPage {
4148
provider: Cell<Option<Provider>>,
4249
refreshid: Cell<u32>,
4350

51+
pub modification_window: Rc<RefCell<ModificationWindowContainer>>,
52+
4453
#[template_child]
45-
pub view_stack: TemplateChild<adwaita::ViewStack>,
54+
pub view_switcher: TemplateChild<ViewSwitcherBar>,
4655
}
4756

4857
/// The central trait for subclassing a GObject
@@ -89,37 +98,75 @@ impl GpuPage {
8998
}
9099

91100
impl GpuPage {
92-
/*
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+
/**
93153
* Name:
94-
* add_stack_item
154+
* replace_stack
95155
*
96156
* Description:
97-
* Add item passed as a parameter to the view_stack object, using name, title & icon passed as parameters
157+
* Replace current view_stack using passed value
98158
*
99159
* Made:
100-
* 03/12/2022
160+
* 04/12/2022
101161
*
102162
* Made by:
103163
* Deren Vural
104164
*
105165
* Notes:
106166
*
107167
*/
108-
pub fn add_stack_item<T: IsA<gtk::Widget>>(
109-
&self,
110-
item: &T,
111-
name: Option<&str>,
112-
title: &str,
113-
icon: &str,
114-
) {
115-
// Add the passed item to the stack
116-
self.view_stack.add_titled(item, name, title);
117-
118-
// Set the icon of the new item
119-
//NOTE: see https://world.pages.gitlab.gnome.org/Rust/libadwaita-rs/stable/latest/docs/libadwaita/struct.ViewStack.html
120-
// function "add_titled_with_icon" not in stable yet
121-
let new_item = self.view_stack.page(item);
122-
new_item.set_icon_name(Some(icon));
168+
pub fn replace_stack(&self, stack: Option<&ViewStack>) {
169+
self.view_switcher.set_stack(stack);
123170
}
124171
}
125172

0 commit comments

Comments
 (0)