mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-18 18:48:33 +02:00
reorganize wifi (wip)
This commit is contained in:
parent
f4a6f29343
commit
c4c95df8d3
|
@ -1,89 +1,5 @@
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use std::thread;
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
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::WidgetExt;
|
|
||||||
|
|
||||||
use crate::components::wifi::wifiEntry::WifiStrength;
|
|
||||||
|
|
||||||
mod wifiBox;
|
mod wifiBox;
|
||||||
mod wifiEntry;
|
mod wifiBoxImpl;
|
||||||
|
mod wifiEntryImpl;
|
||||||
glib::wrapper! {
|
mod wifiEntry;
|
||||||
pub struct WifiBox(ObjectSubclass<wifiBox::WifiBox>)
|
|
||||||
@extends gtk::Box, gtk::Widget,
|
|
||||||
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
|
|
||||||
}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub struct WifiEntry(ObjectSubclass<wifiEntry::WifiEntry>)
|
|
||||||
@extends gtk::ListBoxRow, gtk::Widget,
|
|
||||||
@implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WifiBox {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
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();
|
|
||||||
let proxy = conn.with_proxy(
|
|
||||||
"org.freedesktop.Notifications",
|
|
||||||
"/org/freedesktop/Notifications",
|
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let _: Result<(), Error> = proxy.method_call("org.freedesktop.Notifications", "DoNotDisturb", ());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WifiEntry {
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,55 +1,49 @@
|
||||||
use std::cell::RefCell;
|
use adw::glib;
|
||||||
use gtk::{CompositeTemplate, glib, ListBox, ListBoxRow, Switch};
|
use dbus::blocking::Connection;
|
||||||
use gtk::prelude::*;
|
use crate::components::wifi::wifiEntry::WifiEntry;
|
||||||
use gtk::subclass::prelude::*;
|
use crate::components::wifi::wifiEntryImpl::WifiStrength;
|
||||||
|
|
||||||
use crate::components::wifi::WifiEntry;
|
glib::wrapper! {
|
||||||
|
pub struct WifiBox(ObjectSubclass<wifiBox::WifiBox>)
|
||||||
#[allow(non_snake_case)]
|
@extends gtk::Box, gtk::Widget,
|
||||||
#[derive(Default, CompositeTemplate)]
|
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
|
||||||
#[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]
|
impl WifiBox {
|
||||||
impl ObjectSubclass for WifiBox {
|
pub fn new() -> Self {
|
||||||
const NAME: &'static str = "resetWifi";
|
Object::builder().build()
|
||||||
type Type = super::WifiBox;
|
|
||||||
type ParentType = gtk::Box;
|
|
||||||
|
|
||||||
fn class_init(klass: &mut Self::Class) {
|
|
||||||
WifiEntry::ensure_type();
|
|
||||||
klass.bind_template();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
pub fn setupCallbacks(&self) {
|
||||||
obj.init_template();
|
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();
|
||||||
|
let proxy = conn.with_proxy(
|
||||||
|
"org.freedesktop.Notifications",
|
||||||
|
"/org/freedesktop/Notifications",
|
||||||
|
Duration::from_millis(1000),
|
||||||
|
);
|
||||||
|
let _: Result<(), Error> = proxy.method_call("org.freedesktop.Notifications", "DoNotDisturb", ());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectImpl for WifiBox {
|
|
||||||
fn constructed(&self) {
|
|
||||||
self.parent_constructed();
|
|
||||||
|
|
||||||
let obj = self.obj();
|
|
||||||
obj.setupCallbacks();
|
|
||||||
obj.scanForWifi();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BoxImpl for WifiBox {}
|
|
||||||
|
|
||||||
impl WidgetImpl for WifiBox {}
|
|
||||||
|
|
||||||
impl WindowImpl for WifiBox {}
|
|
||||||
|
|
||||||
impl ApplicationWindowImpl for WifiBox {}
|
|
||||||
|
|
55
src/components/wifi/wifiBoxImpl.rs
Normal file
55
src/components/wifi/wifiBoxImpl.rs
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use gtk::{CompositeTemplate, glib, ListBox, ListBoxRow, Switch};
|
||||||
|
use gtk::prelude::*;
|
||||||
|
use gtk::subclass::prelude::*;
|
||||||
|
|
||||||
|
use crate::components::wifi::WifiEntry;
|
||||||
|
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
#[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]
|
||||||
|
impl ObjectSubclass for WifiBox {
|
||||||
|
const NAME: &'static str = "resetWifi";
|
||||||
|
type Type = super::WifiBox;
|
||||||
|
type ParentType = gtk::Box;
|
||||||
|
|
||||||
|
fn class_init(klass: &mut Self::Class) {
|
||||||
|
WifiEntry::ensure_type();
|
||||||
|
klass.bind_template();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
||||||
|
obj.init_template();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectImpl for WifiBox {
|
||||||
|
fn constructed(&self) {
|
||||||
|
self.parent_constructed();
|
||||||
|
|
||||||
|
let obj = self.obj();
|
||||||
|
obj.setupCallbacks();
|
||||||
|
obj.scanForWifi();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BoxImpl for WifiBox {}
|
||||||
|
|
||||||
|
impl WidgetImpl for WifiBox {}
|
||||||
|
|
||||||
|
impl WindowImpl for WifiBox {}
|
||||||
|
|
||||||
|
impl ApplicationWindowImpl for WifiBox {}
|
|
@ -1,57 +1,29 @@
|
||||||
use std::cell::RefCell;
|
use adw::glib;
|
||||||
use gtk::{Button, CompositeTemplate, glib, Image, Label};
|
use crate::components::wifi::wifiEntryImpl::WifiStrength;
|
||||||
use gtk::subclass::prelude::*;
|
|
||||||
|
|
||||||
#[derive(Default, Copy, Clone)]
|
glib::wrapper! {
|
||||||
pub enum WifiStrength {
|
pub struct WifiEntry(ObjectSubclass<wifiEntryImpl::WifiEntry>)
|
||||||
Excellent,
|
@extends gtk::ListBoxRow, gtk::Widget,
|
||||||
Ok,
|
@implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget;
|
||||||
Weak,
|
|
||||||
#[default]
|
|
||||||
None,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
impl WifiEntry {
|
||||||
#[derive(Default, CompositeTemplate)]
|
pub fn new(strength: WifiStrength, name: &str, isEncrypted: bool) -> Self {
|
||||||
#[template(resource = "/org/Xetibo/ReSet/resetWifiEntry.ui")]
|
let entry: WifiEntry = Object::builder().build();
|
||||||
pub struct WifiEntry {
|
let entryImp = entry.imp();
|
||||||
#[template_child]
|
entryImp.wifiStrength.set(strength);
|
||||||
pub resetWifiStrength: TemplateChild<Image>,
|
entryImp.resetWifiLabel.get().set_text(name);
|
||||||
#[template_child]
|
entryImp.resetWifiEncrypted.set_visible(isEncrypted);
|
||||||
pub resetWifiEncrypted: TemplateChild<Image>,
|
entryImp.resetWifiStrength.get().set_from_icon_name(match strength {
|
||||||
#[template_child]
|
WifiStrength::Excellent => Some("network-wireless-signal-excellent-symbolic"),
|
||||||
pub resetWifiLabel: TemplateChild<Label>,
|
WifiStrength::Ok => Some("network-wireless-signal-ok-symbolic"),
|
||||||
#[template_child]
|
WifiStrength::Weak => Some("network-wireless-signal-weak-symbolic"),
|
||||||
pub resetWifiButton: TemplateChild<Button>,
|
WifiStrength::None => Some("network-wireless-signal-none-symbolic"),
|
||||||
pub wifiName: RefCell<String>,
|
});
|
||||||
pub wifiStrength: RefCell<WifiStrength>,
|
{
|
||||||
}
|
let mut wifiName = entryImp.wifiName.borrow_mut();
|
||||||
|
*wifiName = String::from(name);
|
||||||
#[glib::object_subclass]
|
}
|
||||||
impl ObjectSubclass for WifiEntry {
|
entry
|
||||||
const NAME: &'static str = "resetWifiEntry";
|
|
||||||
type Type = super::WifiEntry;
|
|
||||||
type ParentType = gtk::ListBoxRow;
|
|
||||||
|
|
||||||
fn class_init(klass: &mut Self::Class) {
|
|
||||||
klass.bind_template();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
|
||||||
obj.init_template();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ObjectImpl for WifiEntry {
|
|
||||||
fn constructed(&self) {
|
|
||||||
self.parent_constructed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ListBoxRowImpl for WifiEntry {}
|
|
||||||
|
|
||||||
impl WidgetImpl for WifiEntry {}
|
|
||||||
|
|
||||||
impl WindowImpl for WifiEntry {}
|
|
||||||
|
|
||||||
impl ApplicationWindowImpl for WifiEntry {}
|
|
57
src/components/wifi/wifiEntryImpl.rs
Normal file
57
src/components/wifi/wifiEntryImpl.rs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
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")]
|
||||||
|
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]
|
||||||
|
impl ObjectSubclass for WifiEntry {
|
||||||
|
const NAME: &'static str = "resetWifiEntry";
|
||||||
|
type Type = super::WifiEntry;
|
||||||
|
type ParentType = gtk::ListBoxRow;
|
||||||
|
|
||||||
|
fn class_init(klass: &mut Self::Class) {
|
||||||
|
klass.bind_template();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
||||||
|
obj.init_template();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectImpl for WifiEntry {
|
||||||
|
fn constructed(&self) {
|
||||||
|
self.parent_constructed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ListBoxRowImpl for WifiEntry {}
|
||||||
|
|
||||||
|
impl WidgetImpl for WifiEntry {}
|
||||||
|
|
||||||
|
impl WindowImpl for WifiEntry {}
|
||||||
|
|
||||||
|
impl ApplicationWindowImpl for WifiEntry {}
|
Loading…
Reference in a new issue