19
19
*/
20
20
21
21
// Imports
22
- use adwaita:: { gio, glib, prelude:: * } ;
22
+ use adwaita:: { gio, glib, prelude:: * , ViewStack , ViewSwitcherBar } ;
23
23
use gio:: Settings ;
24
24
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 ,
27
27
} ;
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 } ;
30
30
31
31
// 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
+ }
33
40
34
41
/// Object holding the State and any Template Children
35
42
#[ derive( CompositeTemplate , Default ) ]
@@ -39,6 +46,12 @@ pub struct GpuPage {
39
46
uuid : Cell < String > ,
40
47
name : Cell < String > ,
41
48
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 > ,
42
55
}
43
56
44
57
/// The central trait for subclassing a GObject
@@ -84,6 +97,79 @@ impl GpuPage {
84
97
// }
85
98
}
86
99
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
+
87
173
/**
88
174
* Trait Name:
89
175
* ObjectImpl
@@ -123,6 +209,7 @@ impl ObjectImpl for GpuPage {
123
209
self . parent_constructed ( obj) ;
124
210
125
211
// Setup
212
+ self . refreshid . set ( 0 ) ;
126
213
//obj.setup_settings();
127
214
//obj.load_properties();//TODO
128
215
//obj.setup_widgets();
@@ -161,6 +248,7 @@ impl ObjectImpl for GpuPage {
161
248
glib:: ParamSpecString :: builder( "uuid" ) . build( ) ,
162
249
glib:: ParamSpecString :: builder( "name" ) . build( ) ,
163
250
glib:: ParamSpecObject :: builder( "provider" , glib:: Type :: OBJECT ) . build( ) ,
251
+ glib:: ParamSpecUInt :: builder( "refreshid" ) . build( ) ,
164
252
]
165
253
} ) ;
166
254
@@ -216,6 +304,12 @@ impl ObjectImpl for GpuPage {
216
304
}
217
305
Err ( _) => panic ! ( "The value needs to be of type `Provider`." ) ,
218
306
} ,
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
+ } ,
219
313
_ => panic ! ( "Property `{}` does not exist.." , pspec. name( ) ) ,
220
314
}
221
315
@@ -270,6 +364,13 @@ impl ObjectImpl for GpuPage {
270
364
271
365
value. to_value ( )
272
366
}
367
+ "refreshid" => {
368
+ let value: u32 = self . refreshid . take ( ) ;
369
+
370
+ self . refreshid . set ( value. clone ( ) ) ;
371
+
372
+ value. to_value ( )
373
+ }
273
374
_ => panic ! ( "Property `{}` does not exist.." , pspec. name( ) ) ,
274
375
}
275
376
}
0 commit comments