19
19
*/
20
20
21
21
// Imports
22
- use adwaita:: { gio, glib, prelude:: * , subclass:: prelude:: * } ;
22
+ use adwaita:: { gio, glib, prelude:: * , subclass:: prelude:: * , ComboRow } ;
23
23
use gio:: Settings ;
24
24
use glib:: { once_cell:: sync:: OnceCell , signal:: Inhibit , subclass:: InitializingObject } ;
25
- use gtk:: { subclass:: prelude:: * , CompositeTemplate } ; //, Entry, ListBox, TemplateChild}; //Value, once_cell::sync::Lazy, ParamSpec,
25
+ use gtk:: { subclass:: prelude:: * , CompositeTemplate , TemplateChild , SpinButton , CheckButton } ;
26
26
27
27
// Modules
28
28
//use crate::utils::data_path;
@@ -32,6 +32,14 @@ use gtk::{subclass::prelude::*, CompositeTemplate}; //, Entry, ListBox, Template
32
32
#[ template( resource = "/settings-window.ui" ) ]
33
33
pub struct SettingsWindow {
34
34
pub settings : OnceCell < Settings > ,
35
+ #[ template_child]
36
+ pub refreshrate_input : TemplateChild < SpinButton > ,
37
+ #[ template_child]
38
+ pub temp_unit_c : TemplateChild < CheckButton > ,
39
+ #[ template_child]
40
+ pub temp_unit_f : TemplateChild < CheckButton > ,
41
+ #[ template_child]
42
+ pub provider_input : TemplateChild < ComboRow > ,
35
43
}
36
44
37
45
// The central trait for subclassing a GObject
@@ -40,17 +48,81 @@ impl ObjectSubclass for SettingsWindow {
40
48
// `NAME` needs to match `class` attribute of template
41
49
const NAME : & ' static str = "NvidiaExtensionSettingsWindow" ;
42
50
type Type = super :: SettingsWindow ;
51
+ //type ParentType = adwaita::PreferencesWindow;
43
52
type ParentType = gtk:: ApplicationWindow ;
44
53
45
54
fn class_init ( klass : & mut Self :: Class ) {
46
55
klass. bind_template ( ) ;
56
+ klass. bind_template_callbacks ( ) ;
47
57
}
48
58
49
59
fn instance_init ( obj : & InitializingObject < Self > ) {
50
60
obj. init_template ( ) ;
51
61
}
52
62
}
53
63
64
+ /*
65
+ * Name:
66
+ * SettingsWindow
67
+ *
68
+ * Description:
69
+ * Trait shared by all SettingsWindow objects
70
+ *
71
+ * Made:
72
+ * 13/10/2022
73
+ *
74
+ * Made by:
75
+ * Deren Vural
76
+ *
77
+ * Notes:
78
+ *
79
+ */
80
+ #[ gtk:: template_callbacks]
81
+ impl SettingsWindow {
82
+ #[ template_callback]
83
+ fn refreshrate_set ( & self , button : & SpinButton ) {
84
+ // Get new refresh rate input
85
+ let new_value: i32 = button. value_as_int ( ) ;
86
+
87
+ // Set refresh rate property
88
+ let settings = self . settings . get ( ) . expect ( "..Cannot retrieve settings" ) ;
89
+ settings. set_int ( "refreshrate" , new_value) . expect ( "..Cannot set `tempformat` setting" ) ;
90
+ }
91
+
92
+ #[ template_callback]
93
+ fn temp_unit_set ( & self , button : & CheckButton ) {
94
+ // Get list of buttons
95
+ let check_buttons: [ & CheckButton ; 2 ] = [ & self . temp_unit_c , & self . temp_unit_f ] ;
96
+
97
+ // For each button in the group
98
+ for current_button in check_buttons {
99
+ // Check if current button active
100
+ if current_button. is_active ( ) {
101
+ // Get new unit
102
+ let unit: String = button. label ( ) . expect ( "..Could not fetch contents of temperature unit button label" ) . to_string ( ) ;
103
+
104
+ // Set appropriate setting
105
+ match unit. as_str ( ) {
106
+ "Celcius (C)" => {
107
+ // Set temperature unit as C
108
+ let settings = self . settings . get ( ) . expect ( "..Cannot retrieve settings" ) ;
109
+ settings. set_int ( "tempformat" , 0 ) . expect ( "..Cannot set `tempformat` setting" ) ;
110
+ } ,
111
+ "Fahrenheit (F)" => {
112
+ // Set temperature unit as F
113
+ let settings = self . settings . get ( ) . expect ( "..Cannot retrieve settings" ) ;
114
+ settings. set_int ( "tempformat" , 1 ) . expect ( "..Cannot set `tempformat` setting" ) ;
115
+ } ,
116
+ _ => {
117
+ // Display error message
118
+ panic ! ( "..Unexpected temperature unit" ) ;
119
+ } ,
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+
54
126
/*
55
127
* Trait Name:
56
128
* ObjectImpl
@@ -74,8 +146,8 @@ impl ObjectImpl for SettingsWindow {
74
146
75
147
// Setup
76
148
obj. setup_settings ( ) ;
77
- //obj.setup_tasks();
78
149
obj. restore_data ( ) ;
150
+ obj. setup_widgets ( ) ;
79
151
obj. setup_callbacks ( ) ;
80
152
obj. setup_actions ( ) ;
81
153
}
@@ -163,6 +235,7 @@ impl WindowImpl for SettingsWindow {
163
235
*/
164
236
impl AdwWindowImpl for SettingsWindow { }
165
237
238
+
166
239
/*
167
240
* Trait Name:
168
241
* ApplicationWindowImpl
@@ -171,7 +244,7 @@ impl AdwWindowImpl for SettingsWindow {}
171
244
* Trait shared by all ApplicationWindow's
172
245
*
173
246
* Made:
174
- * 10 /10/2022
247
+ * 09 /10/2022
175
248
*
176
249
* Made by:
177
250
* Deren Vural
@@ -189,7 +262,7 @@ impl ApplicationWindowImpl for SettingsWindow {}
189
262
* Trait shared by all AdwApplicationWindow's
190
263
*
191
264
* Made:
192
- * 10 /10/2022
265
+ * 09 /10/2022
193
266
*
194
267
* Made by:
195
268
* Deren Vural
0 commit comments