Dynamically add wifientries

Update wifi UI
Increase size of setting
This commit is contained in:
takotori 2023-10-30 09:51:37 +01:00
parent bf1baf5ca3
commit f06a436aed
10 changed files with 197 additions and 71 deletions

View file

@ -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<wifiEntry::WifiEntry>)
@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()::<WifiEntry>().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
}
}

View file

@ -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<ListBox>,
#[template_child]
pub resetWifiSwitchRow: TemplateChild<ListBoxRow>,
#[template_child]
pub resetWifiSwitch: TemplateChild<Switch>,
#[template_child]
pub resetWifiList: TemplateChild<ListBox>,
pub wifiEntries: RefCell<Vec<WifiEntry>>,
}
#[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();
}
}

View file

@ -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<Image>,
#[template_child]
pub resetWifiEncrypted: TemplateChild<Image>,
#[template_child]
pub resetWifiLabel: TemplateChild<Label>,
#[template_child]
pub resetWifiButton: TemplateChild<Button>,
pub wifiName: RefCell<String>,
pub wifiStrength: RefCell<WifiStrength>,
}
#[glib::object_subclass]
@ -22,7 +36,7 @@ impl ObjectSubclass for WifiEntry {
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}

View file

@ -40,12 +40,12 @@ impl Window {
let selfImp = self.imp();
selfImp.resetSearchEntry.connect_search_changed(clone!(@ weak self as window => move |_| {
window.filterList();
}));
window.filterList();
}));
selfImp.resetSideBarToggle.connect_clicked(clone!(@ weak self as window => move |_| {
window.toggleSidebar();
}));
window.toggleSidebar();
}));
selfImp.resetSidebarList.connect_row_activated(
clone!(@ weak selfImp as flowbox => move |_, y| {
@ -67,7 +67,7 @@ impl Window {
fn handleDynamicSidebar(&self) {
let selfImp = self.imp();
selfImp.resetSidebarBreakpoint.set_condition(BreakpointCondition::parse("max-width: 500sp").as_ref().ok());
selfImp.resetSidebarBreakpoint.set_condition(BreakpointCondition::parse("max-width: 600sp").as_ref().ok());
selfImp.resetSidebarBreakpoint.add_setter(
&Object::from(selfImp.resetOverlaySplitView.get()),
"collapsed",
@ -191,9 +191,7 @@ impl Window {
fn setupPopoverButtons(&self) {
let selfImp = self.imp();
selfImp
.resetAboutButton
.connect_clicked(clone!(@ weak self as window => move |_| {
selfImp.resetAboutButton.connect_clicked(clone!(@ weak self as window => move |_| {
let dialog = adw::AboutWindow::builder()
.application_name("ReSet")
.application_icon("ReSet")