mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-12 08:28:32 +02:00
reorganize wifi (wip)
This commit is contained in:
parent
f4a6f29343
commit
c4c95df8d3
|
@ -1,89 +1,5 @@
|
|||
#![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 wifiEntry;
|
||||
|
||||
glib::wrapper! {
|
||||
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
|
||||
}
|
||||
}
|
||||
mod wifiBoxImpl;
|
||||
mod wifiEntryImpl;
|
||||
mod wifiEntry;
|
|
@ -1,55 +1,49 @@
|
|||
use std::cell::RefCell;
|
||||
use gtk::{CompositeTemplate, glib, ListBox, ListBoxRow, Switch};
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
use adw::glib;
|
||||
use dbus::blocking::Connection;
|
||||
use crate::components::wifi::wifiEntry::WifiEntry;
|
||||
use crate::components::wifi::wifiEntryImpl::WifiStrength;
|
||||
|
||||
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::wrapper! {
|
||||
pub struct WifiBox(ObjectSubclass<wifiBox::WifiBox>)
|
||||
@extends gtk::Box, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
|
||||
}
|
||||
|
||||
#[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();
|
||||
impl WifiBox {
|
||||
pub fn new() -> Self {
|
||||
Object::builder().build()
|
||||
}
|
||||
|
||||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
||||
obj.init_template();
|
||||
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 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 gtk::{Button, CompositeTemplate, glib, Image, Label};
|
||||
use gtk::subclass::prelude::*;
|
||||
use adw::glib;
|
||||
use crate::components::wifi::wifiEntryImpl::WifiStrength;
|
||||
|
||||
#[derive(Default, Copy, Clone)]
|
||||
pub enum WifiStrength {
|
||||
Excellent,
|
||||
Ok,
|
||||
Weak,
|
||||
#[default]
|
||||
None,
|
||||
glib::wrapper! {
|
||||
pub struct WifiEntry(ObjectSubclass<wifiEntryImpl::WifiEntry>)
|
||||
@extends gtk::ListBoxRow, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget;
|
||||
}
|
||||
|
||||
#[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();
|
||||
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
|
||||
}
|
||||
|
||||
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