From af7776d62ae36cb4355df3e058084325909989fb Mon Sep 17 00:00:00 2001 From: takotori Date: Tue, 7 Nov 2023 15:08:22 +0100 Subject: [PATCH] Add templates for box and listboxrow kekw --- src/components/bluetooth/bluetoothBox.rs | 14 +- src/components/bluetooth/bluetoothBoxImpl.rs | 6 +- src/components/bluetooth/bluetoothEntry.rs | 2 +- .../bluetooth/bluetoothEntryImpl.rs | 4 +- src/components/mod.rs | 3 +- src/components/temp/listEntry.rs | 19 ++ src/components/temp/listEntryImpl.rs | 38 ++++ src/components/temp/mod.rs | 4 + src/components/temp/settingBox.rs | 19 ++ src/components/temp/settingBoxImpl.rs | 39 ++++ src/components/wifi/wifiBox.rs | 18 +- src/components/wifi/wifiBoxImpl.rs | 10 +- src/components/wifi/wifiEntry.rs | 2 +- src/components/wifi/wifiEntryImpl.rs | 5 +- src/components/window/handleSidebarClick.rs | 22 ++- src/components/window/window.rs | 2 +- src/resources/resetBluetooth.ui | 7 +- src/resources/resetBluetoothEntry.ui | 49 +++-- src/resources/resetListBoxRow.ui | 9 + src/resources/resetSettingBox.ui | 11 ++ src/resources/resetUI.cmb | 176 +++++++++--------- src/resources/resetWiFi.ui | 12 +- src/resources/resetWifiEntry.ui | 65 +++---- src/resources/resources.gresource.xml | 2 + 24 files changed, 333 insertions(+), 205 deletions(-) create mode 100644 src/components/temp/listEntry.rs create mode 100644 src/components/temp/listEntryImpl.rs create mode 100644 src/components/temp/mod.rs create mode 100644 src/components/temp/settingBox.rs create mode 100644 src/components/temp/settingBoxImpl.rs create mode 100644 src/resources/resetListBoxRow.ui create mode 100644 src/resources/resetSettingBox.ui diff --git a/src/components/bluetooth/bluetoothBox.rs b/src/components/bluetooth/bluetoothBox.rs index fd10509..1ec60a8 100644 --- a/src/components/bluetooth/bluetoothBox.rs +++ b/src/components/bluetooth/bluetoothBox.rs @@ -5,6 +5,7 @@ use adw::subclass::prelude::ObjectSubclassIsExt; use crate::components::bluetooth::bluetoothBoxImpl; use crate::components::bluetooth::bluetoothEntry::BluetoothEntry; use crate::components::bluetooth::bluetoothEntryImpl::DeviceTypes; +use crate::components::temp::listEntry::ListEntry; glib::wrapper! { pub struct BluetoothBox(ObjectSubclass) @@ -12,7 +13,6 @@ glib::wrapper! { @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable; } - impl BluetoothBox { pub fn new() -> Self { Object::builder().build() @@ -21,10 +21,10 @@ impl BluetoothBox { pub fn scanForDevices(&self) { let selfImp = self.imp(); let mut wifiEntries = selfImp.availableDevices.borrow_mut(); - wifiEntries.push(BluetoothEntry::new(DeviceTypes::Mouse, "ina mouse")); - wifiEntries.push(BluetoothEntry::new(DeviceTypes::Keyboard, "inaboard")); - wifiEntries.push(BluetoothEntry::new(DeviceTypes::Controller, "ina controller")); - wifiEntries.push(BluetoothEntry::new(DeviceTypes::Controller, "ina best waifu")); + wifiEntries.push(ListEntry::new(&BluetoothEntry::new(DeviceTypes::Mouse, "ina mouse"))); + wifiEntries.push(ListEntry::new(&BluetoothEntry::new(DeviceTypes::Keyboard, "inaboard"))); + wifiEntries.push(ListEntry::new(&BluetoothEntry::new(DeviceTypes::Controller, "ina controller"))); + wifiEntries.push(ListEntry::new(&BluetoothEntry::new(DeviceTypes::Controller, "ina best waifu"))); for wifiEntry in wifiEntries.iter() { selfImp.resetBluetoothAvailableDevices.append(wifiEntry); @@ -34,8 +34,8 @@ impl BluetoothBox { pub fn addConnectedDevices(&self) { let selfImp = self.imp(); let mut wifiEntries = selfImp.connectedDevices.borrow_mut(); - wifiEntries.push(BluetoothEntry::new(DeviceTypes::Mouse, "why are we still here?")); - wifiEntries.push(BluetoothEntry::new(DeviceTypes::Keyboard, "just to suffer?")); + wifiEntries.push(ListEntry::new(&BluetoothEntry::new(DeviceTypes::Mouse, "why are we still here?"))); + wifiEntries.push(ListEntry::new(&BluetoothEntry::new(DeviceTypes::Keyboard, "just to suffer?"))); for wifiEntry in wifiEntries.iter() { selfImp.resetBluetoothConnectedDevices.append(wifiEntry); diff --git a/src/components/bluetooth/bluetoothBoxImpl.rs b/src/components/bluetooth/bluetoothBoxImpl.rs index ad6d28d..294ea75 100644 --- a/src/components/bluetooth/bluetoothBoxImpl.rs +++ b/src/components/bluetooth/bluetoothBoxImpl.rs @@ -5,6 +5,7 @@ use gtk::subclass::prelude::*; use crate::components::bluetooth::bluetoothBox; use crate::components::bluetooth::bluetoothEntry::BluetoothEntry; +use crate::components::temp::listEntry::ListEntry; #[allow(non_snake_case)] #[derive(Default, CompositeTemplate)] @@ -16,8 +17,8 @@ pub struct BluetoothBox { pub resetBluetoothAvailableDevices: TemplateChild, #[template_child] pub resetBluetoothConnectedDevices: TemplateChild, - pub availableDevices: RefCell>, - pub connectedDevices: RefCell>, + pub availableDevices: RefCell>, + pub connectedDevices: RefCell>, } #[glib::object_subclass] @@ -28,6 +29,7 @@ impl ObjectSubclass for BluetoothBox { fn class_init(klass: &mut Self::Class) { BluetoothEntry::ensure_type(); + ListEntry::ensure_type(); klass.bind_template(); } diff --git a/src/components/bluetooth/bluetoothEntry.rs b/src/components/bluetooth/bluetoothEntry.rs index 578a095..bb02c8c 100644 --- a/src/components/bluetooth/bluetoothEntry.rs +++ b/src/components/bluetooth/bluetoothEntry.rs @@ -6,7 +6,7 @@ use crate::components::bluetooth::bluetoothEntryImpl::DeviceTypes; glib::wrapper! { pub struct BluetoothEntry(ObjectSubclass) - @extends gtk::Widget, + @extends gtk::Box, gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget; } diff --git a/src/components/bluetooth/bluetoothEntryImpl.rs b/src/components/bluetooth/bluetoothEntryImpl.rs index c43c56e..3b87336 100644 --- a/src/components/bluetooth/bluetoothEntryImpl.rs +++ b/src/components/bluetooth/bluetoothEntryImpl.rs @@ -29,7 +29,7 @@ pub struct BluetoothEntry { impl ObjectSubclass for BluetoothEntry { const NAME: &'static str = "resetBluetoothEntry"; type Type = bluetoothEntry::BluetoothEntry; - type ParentType = gtk::ListBoxRow; + type ParentType = gtk::Box; fn class_init(klass: &mut Self::Class) { klass.bind_template(); @@ -46,7 +46,7 @@ impl ObjectImpl for BluetoothEntry { } } -impl ListBoxRowImpl for BluetoothEntry {} +impl BoxImpl for BluetoothEntry {} impl WidgetImpl for BluetoothEntry {} diff --git a/src/components/mod.rs b/src/components/mod.rs index 65dbb8f..fa7867d 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -1,4 +1,5 @@ pub mod window; pub mod wifi; pub mod bluetooth; -pub mod audio; \ No newline at end of file +pub mod audio; +mod temp; \ No newline at end of file diff --git a/src/components/temp/listEntry.rs b/src/components/temp/listEntry.rs new file mode 100644 index 0000000..3c9bbd2 --- /dev/null +++ b/src/components/temp/listEntry.rs @@ -0,0 +1,19 @@ +use crate::components::temp::listEntryImpl; +use adw::glib; +use adw::glib::{IsA, Object}; +use gtk::prelude::ListBoxRowExt; +use gtk::Widget; + +glib::wrapper! { + pub struct ListEntry(ObjectSubclass) + @extends gtk::ListBoxRow, gtk::Widget, + @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Actionable; +} + +impl ListEntry { + pub fn new(child: &impl IsA) -> Self { + let entry: ListEntry = Object::builder().build(); + entry.set_child(Some(child)); + entry + } +} \ No newline at end of file diff --git a/src/components/temp/listEntryImpl.rs b/src/components/temp/listEntryImpl.rs new file mode 100644 index 0000000..c31ca77 --- /dev/null +++ b/src/components/temp/listEntryImpl.rs @@ -0,0 +1,38 @@ +use gtk::{CompositeTemplate, glib}; +use gtk::prelude::*; +use gtk::subclass::prelude::*; +use crate::components::temp::listEntry; + +#[allow(non_snake_case)] +#[derive(Default, CompositeTemplate)] +#[template(resource = "/org/Xetibo/ReSet/resetListBoxRow.ui")] +pub struct ListEntry {} + +#[glib::object_subclass] +impl ObjectSubclass for ListEntry { + const NAME: &'static str = "resetListBoxRow"; + type Type = listEntry::ListEntry; + type ParentType = gtk::ListBoxRow; + + fn class_init(klass: &mut Self::Class) { + klass.bind_template(); + } + + fn instance_init(obj: &glib::subclass::InitializingObject) { + obj.init_template(); + } +} + +impl ObjectImpl for ListEntry { + fn constructed(&self) { + self.parent_constructed(); + } +} + +impl ListBoxRowImpl for ListEntry {} + +impl WidgetImpl for ListEntry {} + +impl WindowImpl for ListEntry {} + +impl ApplicationWindowImpl for ListEntry {} diff --git a/src/components/temp/mod.rs b/src/components/temp/mod.rs new file mode 100644 index 0000000..928ec14 --- /dev/null +++ b/src/components/temp/mod.rs @@ -0,0 +1,4 @@ +pub mod settingBox; +pub mod settingBoxImpl; +pub mod listEntry; +pub mod listEntryImpl; diff --git a/src/components/temp/settingBox.rs b/src/components/temp/settingBox.rs new file mode 100644 index 0000000..4ba51e7 --- /dev/null +++ b/src/components/temp/settingBox.rs @@ -0,0 +1,19 @@ +use crate::components::temp::settingBoxImpl; +use adw::glib; +use adw::glib::{IsA, Object}; +use gtk::prelude::BoxExt; +use gtk::Widget; + +glib::wrapper! { + pub struct SettingBox(ObjectSubclass) + @extends gtk::Box, gtk::Widget, + @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable; +} + +impl SettingBox { + pub fn new(child: &impl IsA) -> Self { + let entry: SettingBox = Object::builder().build(); + entry.append(child); + entry + } +} \ No newline at end of file diff --git a/src/components/temp/settingBoxImpl.rs b/src/components/temp/settingBoxImpl.rs new file mode 100644 index 0000000..115fd31 --- /dev/null +++ b/src/components/temp/settingBoxImpl.rs @@ -0,0 +1,39 @@ +use adw::NavigationView; +use gtk::{CompositeTemplate, glib}; +use gtk::prelude::*; +use gtk::subclass::prelude::*; +use crate::components::temp::settingBox; + +#[allow(non_snake_case)] +#[derive(Default, CompositeTemplate)] +#[template(resource = "/org/Xetibo/ReSet/resetSetting.ui")] +pub struct SettingBox {} + +#[glib::object_subclass] +impl ObjectSubclass for SettingBox { + const NAME: &'static str = "resetSetting"; + type Type = settingBox::SettingBox; + type ParentType = gtk::Box; + + fn class_init(klass: &mut Self::Class) { + klass.bind_template(); + } + + fn instance_init(obj: &glib::subclass::InitializingObject) { + obj.init_template(); + } +} + +impl ObjectImpl for SettingBox { + fn constructed(&self) { + self.parent_constructed(); + } +} + +impl BoxImpl for SettingBox {} + +impl WidgetImpl for SettingBox {} + +impl WindowImpl for SettingBox {} + +impl ApplicationWindowImpl for SettingBox {} diff --git a/src/components/wifi/wifiBox.rs b/src/components/wifi/wifiBox.rs index b467c9f..6243317 100644 --- a/src/components/wifi/wifiBox.rs +++ b/src/components/wifi/wifiBox.rs @@ -2,12 +2,13 @@ use std::thread; use std::time::Duration; use adw::glib; -use adw::glib::clone; use adw::glib::Object; use adw::subclass::prelude::ObjectSubclassIsExt; use dbus::blocking::Connection; use dbus::Error; -use gtk::prelude::ButtonExt; +use gtk::glib::Variant; +use gtk::prelude::ActionableExt; +use crate::components::temp::listEntry::ListEntry; use crate::components::wifi::wifiBoxImpl; use crate::components::wifi::wifiEntry::WifiEntry; @@ -27,18 +28,17 @@ impl WifiBox { pub fn setupCallbacks(&self) { let selfImp = self.imp(); - selfImp.resetWifiDetails.connect_row_activated(clone!(@ weak selfImp as window => move |_, _y| { - // let result = y.downcast_ref()::().unwrap(); no worky smh - })); + selfImp.resetSavedNetworks.set_action_name(Some("navigation.push")); + selfImp.resetSavedNetworks.set_action_target_value(Some(&Variant::from("saved"))); } pub fn scanForWifi(&self) { let selfImp = self.imp(); let mut wifiEntries = selfImp.wifiEntries.borrow_mut(); - wifiEntries.push(WifiEntry::new(WifiStrength::Excellent, "ina internet", true)); - wifiEntries.push(WifiEntry::new(WifiStrength::Excellent, "watch ina", true)); - wifiEntries.push(WifiEntry::new(WifiStrength::Ok, "INANET", true)); - wifiEntries.push(WifiEntry::new(WifiStrength::Weak, "ina best waifu", false)); + wifiEntries.push(ListEntry::new(&WifiEntry::new(WifiStrength::Excellent, "ina internet", true))); + wifiEntries.push(ListEntry::new(&WifiEntry::new(WifiStrength::Excellent, "watch ina", true))); + wifiEntries.push(ListEntry::new(&WifiEntry::new(WifiStrength::Ok, "INANET", true))); + wifiEntries.push(ListEntry::new(&WifiEntry::new(WifiStrength::Weak, "ina best waifu", false))); for wifiEntry in wifiEntries.iter() { selfImp.resetWifiList.append(wifiEntry); diff --git a/src/components/wifi/wifiBoxImpl.rs b/src/components/wifi/wifiBoxImpl.rs index 6065c7c..4fcf76a 100644 --- a/src/components/wifi/wifiBoxImpl.rs +++ b/src/components/wifi/wifiBoxImpl.rs @@ -1,10 +1,11 @@ use std::cell::RefCell; -use gtk::{Button, CompositeTemplate, glib, ListBox, ListBoxRow, Revealer, Switch}; +use gtk::{Button, CompositeTemplate, glib, ListBox, Switch}; use gtk::prelude::*; use gtk::subclass::prelude::*; use crate::components::wifi::wifiBox; use crate::components::wifi::wifiEntry::WifiEntry; +use crate::components::temp::listEntry::ListEntry; #[allow(non_snake_case)] #[derive(Default, CompositeTemplate)] @@ -13,14 +14,16 @@ pub struct WifiBox { #[template_child] pub resetWifiDetails: TemplateChild, #[template_child] - pub resetWifiSwitchRow: TemplateChild, + pub resetWifiSwitchRow: TemplateChild, + #[template_child] + pub resetSavedNetworks: TemplateChild, #[template_child] pub resetWifiSwitch: TemplateChild, #[template_child] pub resetWifiList: TemplateChild, #[template_child] pub resetWifiAdvanced: TemplateChild