@@ -22,7 +22,8 @@ use adwaita::{gio, glib, prelude::*, subclass::prelude::*};
22
22
use gio:: Settings ;
23
23
use glib:: {
24
24
once_cell:: sync:: Lazy , once_cell:: sync:: OnceCell , signal:: Inhibit ,
25
- subclass:: InitializingObject , FromVariant , ParamSpec , Value ,
25
+ subclass:: InitializingObject , subclass:: Signal , subclass:: SignalType , FromVariant , ParamSpec ,
26
+ Value ,
26
27
} ;
27
28
use gtk:: {
28
29
subclass:: prelude:: * , Button , CompositeTemplate , PolicyType , ScrolledWindow , Stack ,
@@ -53,12 +54,15 @@ enum TemperatureUnit {
53
54
#[ derive( CompositeTemplate , Default ) ]
54
55
#[ template( resource = "/main-window.ui" ) ]
55
56
pub struct MainWindow {
57
+ // Public
56
58
pub settings : OnceCell < Settings > ,
57
59
pub settings_window : Rc < RefCell < SettingsWindowContainer > > ,
58
60
pub provider : Cell < Option < Provider > > ,
59
61
62
+ // Private
60
63
gpu_pages : RefCell < Vec < GpuPage > > ,
61
64
65
+ // Template Children
62
66
#[ template_child]
63
67
pub gpu_stack : TemplateChild < Stack > ,
64
68
}
@@ -1344,32 +1348,13 @@ impl MainWindow {
1344
1348
}
1345
1349
}
1346
1350
}
1347
- }
1348
1351
1349
- /**
1350
- * Name:
1351
- * MainWindow
1352
- *
1353
- * Description:
1354
- * Trait defining template callbacks shared by all MainWindow objects
1355
- *
1356
- * Made:
1357
- * 13/10/2022
1358
- *
1359
- * Made by:
1360
- * Deren Vural
1361
- *
1362
- * Notes:
1363
- *
1364
- */
1365
- #[ gtk:: template_callbacks]
1366
- impl MainWindow {
1367
1352
/**
1368
1353
* Name:
1369
1354
* refresh_cards
1370
1355
*
1371
1356
* Description:
1372
- * Template callback for GPU list refresh button
1357
+ * Re-create the GpuPages and stack contents when called
1373
1358
*
1374
1359
* Made:
1375
1360
* 28/10/2022
@@ -1380,10 +1365,7 @@ impl MainWindow {
1380
1365
* Notes:
1381
1366
*
1382
1367
*/
1383
- #[ template_callback]
1384
- fn refresh_cards ( & self , _button : & Button ) {
1385
- // println!("GPU Scan Button Pressed!"); //TEST
1386
-
1368
+ pub fn refresh_cards ( & self ) {
1387
1369
// Clear current ActionRow objects from GtkListBox
1388
1370
let mut done: bool = false ;
1389
1371
while !done {
@@ -1544,58 +1526,47 @@ impl MainWindow {
1544
1526
}
1545
1527
}
1546
1528
}
1529
+ }
1530
+ }
1547
1531
1548
- /*
1549
- // Load refresh time (s) from settings
1550
- let refresh_rate: u32 = self.get_setting::<i32>("refreshrate") as u32;
1551
-
1552
- // Create thread safe container for provider
1553
- // Grab copy of current provider
1554
- let provider_container: Option<Provider> = self.provider.take();
1555
- self.provider.set(provider_container.clone());
1556
- let provider_store: Arc<Mutex<Option<Provider>>> = Arc::new(Mutex::new(provider_container));
1557
-
1558
- // Wrapper around `NonNull<RawType>` that just implements `Send`
1559
- struct WrappedPointer(Settings);
1560
- unsafe impl Send for WrappedPointer {}
1561
- // Safe wrapper around `WrappedPointer` that gives access to the pointer
1562
- // only with the mutex locked.
1563
- struct SafeType {
1564
- inner: Mutex<WrappedPointer>,
1565
- }
1566
- let settings_store: SafeType = SafeType
1567
- {
1568
- inner: Mutex::new(WrappedPointer(self.settings.get().expect("").to_owned()))
1569
- };
1570
-
1571
- // Async check for provider changes
1572
- //glib::timeout_add_seconds(refresh_rate, clone!(@strong self as window => move || {
1573
- //glib::timeout_add_seconds(refresh_rate, clone!(@strong settings_store as window => move || {
1574
- glib::timeout_add_seconds_local(refresh_rate, move || {
1575
- // Grab locked data
1576
- // settings object
1577
- let settings_container: MutexGuard<WrappedPointer> = settings_store.inner.lock().unwrap();
1578
- // current provider for scanning gpu data
1579
- let provider_lock: Arc<Mutex<Option<Provider>>> = Arc::clone(&provider_store);
1580
- let mut provider_container: MutexGuard<Option<Provider>> = provider_lock.lock().unwrap();
1581
-
1582
-
1583
- // Check provider type in settings
1584
- let provider_type: i32 = settings_container.0.get("provider");
1585
-
1586
- // If type has been changed, update provider
1587
- match &mut *provider_container {
1588
- Some(prov) => {
1589
- if prov.property::<i32>("provider_type") != provider_type {
1590
- //
1591
- }
1592
- }
1593
- None => todo!(),
1594
- }
1595
-
1596
- Continue(true)
1597
- });
1598
- */
1532
+ /**
1533
+ * Name:
1534
+ * MainWindow
1535
+ *
1536
+ * Description:
1537
+ * Trait defining template callbacks shared by all MainWindow objects
1538
+ *
1539
+ * Made:
1540
+ * 13/10/2022
1541
+ *
1542
+ * Made by:
1543
+ * Deren Vural
1544
+ *
1545
+ * Notes:
1546
+ *
1547
+ */
1548
+ #[ gtk:: template_callbacks]
1549
+ impl MainWindow {
1550
+ /**
1551
+ * Name:
1552
+ * refresh_cards
1553
+ *
1554
+ * Description:
1555
+ * Template callback for GPU list refresh button
1556
+ *
1557
+ * Made:
1558
+ * 28/10/2022
1559
+ *
1560
+ * Made by:
1561
+ * Deren Vural
1562
+ *
1563
+ * Notes:
1564
+ *
1565
+ */
1566
+ #[ template_callback]
1567
+ fn refresh_cards_clicked ( & self , _button : & Button ) {
1568
+ // println!("GPU Scan Button Pressed!"); //TEST
1569
+ self . refresh_cards ( ) ;
1599
1570
}
1600
1571
}
1601
1572
@@ -1740,6 +1711,38 @@ impl ObjectImpl for MainWindow {
1740
1711
_ => panic ! ( "Property `{}` does not exist.." , pspec. name( ) ) ,
1741
1712
}
1742
1713
}
1714
+
1715
+ /**
1716
+ * Name:
1717
+ * signals
1718
+ *
1719
+ * Description:
1720
+ * Defines the list of signals
1721
+ *
1722
+ * Made:
1723
+ * 10/01/2023
1724
+ *
1725
+ * Made by:
1726
+ * Deren Vural
1727
+ *
1728
+ * Notes:
1729
+ * beware that you need to use kebab-case (<https://en.wikipedia.org/wiki/Letter_case#Kebab_case>)
1730
+ *
1731
+ * <https://gtk-rs.org/gtk4-rs/stable/latest/book/g_object_signals.html>
1732
+ *
1733
+ * SignalType::from(i32::static_type())
1734
+ */
1735
+ fn signals ( ) -> & ' static [ Signal ] {
1736
+ static SIGNALS : Lazy < Vec < Signal > > = Lazy :: new ( || {
1737
+ vec ! [ Signal :: builder(
1738
+ "update-all-views" ,
1739
+ & [ ] ,
1740
+ SignalType :: from( i32 :: static_type( ) ) ,
1741
+ )
1742
+ . build( ) ]
1743
+ } ) ;
1744
+ SIGNALS . as_ref ( )
1745
+ }
1743
1746
}
1744
1747
1745
1748
/**
0 commit comments