From f06a436aed71ee77a7bb5c6fa8e56e2a344843bd Mon Sep 17 00:00:00 2001 From: takotori Date: Mon, 30 Oct 2023 09:51:37 +0100 Subject: [PATCH] Dynamically add wifientries Update wifi UI Increase size of setting --- src/components/wifi/mod.rs | 51 ++++++++++++++++++-- src/components/wifi/wifiBox.rs | 15 +++++- src/components/wifi/wifiEntry.rs | 16 ++++++- src/components/window/mod.rs | 14 +++--- src/resources/resetAudio.ui | 2 +- src/resources/resetBluetooth.ui | 2 +- src/resources/resetMainWindow.ui | 1 + src/resources/resetUI.cmb | 67 +++++++++++++++++--------- src/resources/resetWiFi.ui | 80 ++++++++++++++++++++------------ src/resources/resetWifiEntry.ui | 20 ++++++-- 10 files changed, 197 insertions(+), 71 deletions(-) diff --git a/src/components/wifi/mod.rs b/src/components/wifi/mod.rs index 665286d..2ec9259 100644 --- a/src/components/wifi/mod.rs +++ b/src/components/wifi/mod.rs @@ -3,10 +3,15 @@ use std::thread; use std::time::Duration; -use adw::glib::Object; +use adw::glib::{Object, PropertySet}; +use adw::glib::clone; +use adw::subclass::prelude::ObjectSubclassIsExt; use dbus::blocking::Connection; use dbus::Error; use gtk::glib; +use gtk::prelude::{ListBoxRowExt, TreeViewExt, WidgetExt}; + +use crate::components::wifi::wifiEntry::WifiStrength; mod wifiBox; mod wifiEntry; @@ -19,7 +24,7 @@ glib::wrapper! { glib::wrapper! { pub struct WifiEntry(ObjectSubclass) - @extends gtk::Widget, + @extends gtk::ListBoxRow, gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget; } @@ -28,6 +33,27 @@ impl WifiBox { Object::builder().build() } + 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 + })); + } + + 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)); + + for wifiEntry in wifiEntries.iter() { + selfImp.resetWifiList.append(wifiEntry); + } + } + pub fn donotdisturb() { thread::spawn(|| { let conn = Connection::new_session().unwrap(); @@ -36,13 +62,28 @@ impl WifiBox { "/org/freedesktop/Notifications", Duration::from_millis(1000), ); - let _ : Result<(), Error> = proxy.method_call("org.freedesktop.Notifications", "DoNotDisturb", ()); + let _: Result<(), Error> = proxy.method_call("org.freedesktop.Notifications", "DoNotDisturb", ()); }); } } impl WifiEntry { - pub fn new() -> Self { - Object::builder().build() + pub fn new(strength: WifiStrength, name: &str, isEncrypted: bool) -> Self { + let entry: WifiEntry = Object::builder().build(); + let entryImp = entry.imp(); + entryImp.wifiStrength.set(strength); + entryImp.resetWifiLabel.get().set_text(name); + entryImp.resetWifiEncrypted.set_visible(isEncrypted); + entryImp.resetWifiStrength.get().set_from_icon_name(match strength { + WifiStrength::Excellent => Some("network-wireless-signal-excellent-symbolic"), + WifiStrength::Ok => Some("network-wireless-signal-ok-symbolic"), + WifiStrength::Weak => Some("network-wireless-signal-weak-symbolic"), + WifiStrength::None => Some("network-wireless-signal-none-symbolic"), + }); + { + let mut wifiName = entryImp.wifiName.borrow_mut(); + *wifiName = String::from(name); + } + entry } } \ No newline at end of file diff --git a/src/components/wifi/wifiBox.rs b/src/components/wifi/wifiBox.rs index 32daa68..401169a 100644 --- a/src/components/wifi/wifiBox.rs +++ b/src/components/wifi/wifiBox.rs @@ -1,6 +1,8 @@ -use gtk::{CompositeTemplate, glib, ListBox}; +use std::cell::RefCell; +use gtk::{CompositeTemplate, glib, ListBox, ListBoxRow, Switch}; use gtk::prelude::*; use gtk::subclass::prelude::*; +use gtk::prelude::*; use crate::components::wifi::WifiEntry; @@ -8,8 +10,15 @@ use crate::components::wifi::WifiEntry; #[derive(Default, CompositeTemplate)] #[template(resource = "/org/Xetibo/ReSet/resetWiFi.ui")] pub struct WifiBox { + #[template_child] + pub resetWifiDetails: TemplateChild, + #[template_child] + pub resetWifiSwitchRow: TemplateChild, + #[template_child] + pub resetWifiSwitch: TemplateChild, #[template_child] pub resetWifiList: TemplateChild, + pub wifiEntries: RefCell>, } #[glib::object_subclass] @@ -31,6 +40,10 @@ impl ObjectSubclass for WifiBox { impl ObjectImpl for WifiBox { fn constructed(&self) { self.parent_constructed(); + + let obj = self.obj(); + obj.setupCallbacks(); + obj.scanForWifi(); } } diff --git a/src/components/wifi/wifiEntry.rs b/src/components/wifi/wifiEntry.rs index cc51f15..d7fb28a 100644 --- a/src/components/wifi/wifiEntry.rs +++ b/src/components/wifi/wifiEntry.rs @@ -1,6 +1,16 @@ +use std::cell::RefCell; use gtk::{Button, CompositeTemplate, glib, Image, Label}; use gtk::subclass::prelude::*; +#[derive(Default, Copy, Clone)] +pub enum WifiStrength { + Excellent, + Ok, + Weak, + #[default] + None, +} + #[allow(non_snake_case)] #[derive(Default, CompositeTemplate)] #[template(resource = "/org/Xetibo/ReSet/resetWifiEntry.ui")] @@ -8,9 +18,13 @@ pub struct WifiEntry { #[template_child] pub resetWifiStrength: TemplateChild, #[template_child] + pub resetWifiEncrypted: TemplateChild, + #[template_child] pub resetWifiLabel: TemplateChild