mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-07-13 05:07:45 +02:00
chore: snake_case all but UI templates
This commit is contained in:
parent
9f0ca6e8bf
commit
391182607d
55 changed files with 1471 additions and 1427 deletions
|
@ -1,14 +1,13 @@
|
|||
#![allow(non_snake_case)]
|
||||
pub mod savedWifiEntry;
|
||||
pub mod savedWifiEntryImpl;
|
||||
pub mod saved_wifi_entry;
|
||||
pub mod saved_wifi_entry_impl;
|
||||
pub mod utils;
|
||||
pub mod wifiAddressEntry;
|
||||
pub mod wifiAddressEntryImpl;
|
||||
pub mod wifiBox;
|
||||
pub mod wifiBoxImpl;
|
||||
pub mod wifiEntry;
|
||||
pub mod wifiEntryImpl;
|
||||
pub mod wifiOptions;
|
||||
pub mod wifiOptionsImpl;
|
||||
pub mod wifiRouteEntry;
|
||||
pub mod wifiRouteEntryImpl;
|
||||
pub mod wifi_address_entry;
|
||||
pub mod wifi_address_entry_impl;
|
||||
pub mod wifi_box;
|
||||
pub mod wifi_box_impl;
|
||||
pub mod wifi_entry;
|
||||
pub mod wifi_entry_impl;
|
||||
pub mod wifi_options;
|
||||
pub mod wifi_options_impl;
|
||||
pub mod wifi_route_entry;
|
||||
pub mod wifi_route_entry_impl;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use crate::components::wifi::savedWifiEntryImpl;
|
||||
use crate::components::wifi::wifiBoxImpl::WifiBox;
|
||||
use crate::components::wifi::saved_wifi_entry_impl;
|
||||
use crate::components::wifi::wifi_box_impl::WifiBox;
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{ButtonExt, WidgetExt};
|
||||
|
@ -13,30 +13,30 @@ use gtk::gio;
|
|||
use gtk::prelude::ListBoxRowExt;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct SavedWifiEntry(ObjectSubclass<savedWifiEntryImpl::SavedWifiEntry>)
|
||||
pub struct SavedWifiEntry(ObjectSubclass<saved_wifi_entry_impl::SavedWifiEntry>)
|
||||
@extends adw::ActionRow, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget, gtk::ListBoxRow;
|
||||
}
|
||||
|
||||
impl SavedWifiEntry {
|
||||
pub fn new(name: &str, path: Path<'static>, wifiBox: &WifiBox) -> Self {
|
||||
pub fn new(name: &str, path: Path<'static>, wifi_box: &WifiBox) -> Self {
|
||||
let entry: SavedWifiEntry = Object::builder().build();
|
||||
entry.set_activatable(false);
|
||||
let entryImp = entry.imp();
|
||||
let entry_imp = entry.imp();
|
||||
|
||||
entryImp.resetEditSavedWifiButton.connect_clicked(
|
||||
clone!(@ weak entryImp, @ weak wifiBox => move |_| {
|
||||
entry_imp.resetEditSavedWifiButton.connect_clicked(
|
||||
clone!(@ weak entry_imp, @ weak wifi_box => move |_| {
|
||||
// TODO accesspoint has to be saved somewhere i guess
|
||||
// let _option = getConnectionSettings(entryImp.accessPoint.borrow().associated_connection.clone());
|
||||
// wifiBox.resetWifiNavigation.push(&*WifiOptions::new(_option));
|
||||
}),
|
||||
);
|
||||
|
||||
entryImp.resetSavedWifiLabel.set_text(name);
|
||||
entryImp.resetConnectionPath.set(path);
|
||||
entryImp.resetDeleteSavedWifiButton.connect_clicked(
|
||||
entry_imp.resetSavedWifiLabel.set_text(name);
|
||||
entry_imp.reset_connection_path.set(path);
|
||||
entry_imp.resetDeleteSavedWifiButton.connect_clicked(
|
||||
clone!(@weak entry as entry => move |_| {
|
||||
delete_connection(entry.imp().resetConnectionPath.take());
|
||||
delete_connection(entry.imp().reset_connection_path.take());
|
||||
// TODO handle error
|
||||
let parent = entry.parent().unwrap();
|
||||
parent.set_visible(false);
|
|
@ -8,7 +8,7 @@ use gtk::subclass::prelude::*;
|
|||
use gtk::{glib, Button, CompositeTemplate, Label};
|
||||
use ReSet_Lib::network::network::AccessPoint;
|
||||
|
||||
use super::savedWifiEntry;
|
||||
use super::saved_wifi_entry;
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Default, CompositeTemplate)]
|
||||
|
@ -20,8 +20,8 @@ pub struct SavedWifiEntry {
|
|||
pub resetEditSavedWifiButton: TemplateChild<Button>,
|
||||
#[template_child]
|
||||
pub resetSavedWifiLabel: TemplateChild<Label>,
|
||||
pub resetConnectionPath: RefCell<Path<'static>>,
|
||||
pub accessPoint: RefCell<AccessPoint>,
|
||||
pub reset_connection_path: RefCell<Path<'static>>,
|
||||
pub access_point: RefCell<AccessPoint>,
|
||||
}
|
||||
|
||||
unsafe impl Send for SavedWifiEntry {}
|
||||
|
@ -31,7 +31,7 @@ unsafe impl Sync for SavedWifiEntry {}
|
|||
impl ObjectSubclass for SavedWifiEntry {
|
||||
const ABSTRACT: bool = false;
|
||||
const NAME: &'static str = "resetSavedWifiEntry";
|
||||
type Type = savedWifiEntry::SavedWifiEntry;
|
||||
type Type = saved_wifi_entry::SavedWifiEntry;
|
||||
type ParentType = ActionRow;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
|
@ -16,7 +16,7 @@ pub enum IpProtocol {
|
|||
type ResultType =
|
||||
Result<(HashMap<String, HashMap<String, dbus::arg::Variant<Box<dyn RefArg>>>>,), Error>;
|
||||
|
||||
pub fn getConnectionSettings(path: Path<'static>) -> ResetConnection {
|
||||
pub fn get_connection_settings(path: Path<'static>) -> ResetConnection {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSetDaemon",
|
||||
|
|
|
@ -1,160 +0,0 @@
|
|||
use std::cell::RefCell;
|
||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
use std::rc::Rc;
|
||||
use std::str::FromStr;
|
||||
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::PreferencesRowExt;
|
||||
use glib::clone;
|
||||
use glib::subclass::prelude::ObjectSubclassIsExt;
|
||||
use gtk::prelude::{ButtonExt, EditableExt, WidgetExt};
|
||||
use ReSet_Lib::network::connection::{Address, Connection};
|
||||
|
||||
use crate::components::wifi::utils::IpProtocol;
|
||||
use crate::components::wifi::wifiAddressEntryImpl;
|
||||
use crate::components::wifi::wifiAddressEntryImpl::WifiAddressEntryImpl;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct WifiAddressEntry(ObjectSubclass<wifiAddressEntryImpl::WifiAddressEntryImpl>)
|
||||
@extends gtk::Box, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
|
||||
}
|
||||
|
||||
impl WifiAddressEntry {
|
||||
pub fn new(
|
||||
address: Option<usize>,
|
||||
conn: Rc<RefCell<Connection>>,
|
||||
protocol: IpProtocol,
|
||||
) -> Self {
|
||||
let entry: WifiAddressEntry = Object::builder().build();
|
||||
let entryImp = entry.imp();
|
||||
|
||||
if let Some(address) = address {
|
||||
let conn = conn.borrow();
|
||||
let address = unsafe { conn.ipv4.address_data.get_unchecked(address) };
|
||||
|
||||
entryImp.resetAddressAddress.set_text(&address.address);
|
||||
entryImp
|
||||
.resetAddressPrefix
|
||||
.set_text(&address.prefix_length.to_string());
|
||||
entryImp
|
||||
.resetAddressRow
|
||||
.set_title(&format!("{}/{}", &*address.address, address.prefix_length));
|
||||
}
|
||||
entryImp.protocol.set(protocol);
|
||||
entry.setupCallbacks(conn);
|
||||
entry
|
||||
}
|
||||
|
||||
pub fn setupCallbacks(&self, connection: Rc<RefCell<Connection>>) {
|
||||
let selfImp = self.imp();
|
||||
|
||||
let conn = connection.clone();
|
||||
selfImp.resetAddressAddress.connect_changed(clone!(@weak selfImp => move |entry| {
|
||||
let addressInput = entry.text();
|
||||
let mut conn = conn.borrow_mut();
|
||||
|
||||
if addressInput.is_empty() {
|
||||
selfImp.resetAddressAddress.remove_css_class("error");
|
||||
selfImp.resetAddressRow.set_title("Add new address");
|
||||
return;
|
||||
}
|
||||
let result = match selfImp.protocol.get() {
|
||||
IpProtocol::IPv4 => Ipv4Addr::from_str(addressInput.as_str()).map(IpAddr::V4),
|
||||
IpProtocol::IPv6 => Ipv6Addr::from_str(addressInput.as_str()).map(IpAddr::V6),
|
||||
};
|
||||
match result {
|
||||
Ok(ipAddr) => {
|
||||
selfImp.resetAddressAddress.remove_css_class("error");
|
||||
let addressData = match selfImp.protocol.get() {
|
||||
IpProtocol::IPv4 => &mut conn.ipv4.address_data,
|
||||
IpProtocol::IPv6 => &mut conn.ipv6.address_data,
|
||||
};
|
||||
addressData.push(Address::theBetterNew(ipAddr.to_string(), selfImp.prefix.get().1 as u32));
|
||||
*selfImp.address.borrow_mut() = (true, ipAddr.to_string());
|
||||
}
|
||||
Err(_) => {
|
||||
selfImp.resetAddressAddress.add_css_class("error");
|
||||
*selfImp.address.borrow_mut() = (false, String::default());
|
||||
}
|
||||
}
|
||||
setRowName(&selfImp);
|
||||
}));
|
||||
|
||||
let conn = connection.clone();
|
||||
selfImp.resetAddressPrefix.connect_changed(clone!(@weak selfImp => move |entry| {
|
||||
let prefixInput = entry.text();
|
||||
let prefix = prefixInput.parse::<u8>();
|
||||
let mut conn = conn.borrow_mut();
|
||||
|
||||
let handleError = || {
|
||||
if selfImp.resetAddressPrefix.text().is_empty() {
|
||||
selfImp.resetAddressPrefix.remove_css_class("error");
|
||||
} else {
|
||||
selfImp.resetAddressPrefix.add_css_class("error");
|
||||
}
|
||||
selfImp.prefix.set((false, 0));
|
||||
setRowName(&selfImp);
|
||||
};
|
||||
|
||||
if prefixInput.is_empty() || prefix.is_err() {
|
||||
handleError();
|
||||
return;
|
||||
}
|
||||
|
||||
let prefix = prefix.unwrap();
|
||||
match selfImp.protocol.get() {
|
||||
IpProtocol::IPv4 if prefix <= 32 => {
|
||||
selfImp.prefix.set((true, prefix as u32));
|
||||
selfImp.resetAddressPrefix.remove_css_class("error");
|
||||
if let Ok(address2) = Ipv4Addr::from_str(selfImp.resetAddressAddress.text().as_str()) {
|
||||
if let Some(addr) = conn.ipv4.address_data.iter_mut()
|
||||
.find(|connAddr| *connAddr.address == address2.to_string()) {
|
||||
addr.prefix_length = prefix as u32;
|
||||
}
|
||||
}
|
||||
}
|
||||
IpProtocol::IPv6 if prefix <= 128 => {
|
||||
selfImp.prefix.set((true, prefix as u32));
|
||||
selfImp.resetAddressPrefix.remove_css_class("error");
|
||||
if let Ok(address2) = Ipv6Addr::from_str(selfImp.resetAddressAddress.text().as_str()) {
|
||||
if let Some(addr) = conn.ipv6.address_data.iter_mut()
|
||||
.find(|connAddr| *connAddr.address == address2.to_string()) {
|
||||
addr.prefix_length = prefix as u32;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => handleError()
|
||||
}
|
||||
setRowName(&selfImp);
|
||||
}));
|
||||
|
||||
let conn = connection.clone();
|
||||
selfImp.resetAddressRemove.connect_clicked(
|
||||
clone!(@weak selfImp, @weak self as what => move |_| {
|
||||
let address = selfImp.resetAddressAddress.text();
|
||||
let mut conn = conn.borrow_mut();
|
||||
conn.ipv4.address_data.retain(|addr| addr.address != address);
|
||||
what.unparent();
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn setRowName(selfImp: &WifiAddressEntryImpl) {
|
||||
if selfImp.resetAddressAddress.text().is_empty() {
|
||||
return;
|
||||
}
|
||||
let address = selfImp.address.borrow();
|
||||
let prefix = selfImp.prefix.get();
|
||||
let title = match (address.0, prefix.0) {
|
||||
(true, true) => {
|
||||
format!("{}/{}", address.1, prefix.1)
|
||||
}
|
||||
(true, false) => "Prefix wrong".to_string(),
|
||||
(false, true) => "Address wrong".to_string(),
|
||||
(false, false) => "Address and Prefix wrong".to_string(),
|
||||
};
|
||||
selfImp.resetAddressRow.set_title(&title);
|
||||
}
|
|
@ -1,342 +0,0 @@
|
|||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use adw::{gio, glib};
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{ActionRowExt, ComboRowExt, PreferencesGroupExt};
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
use dbus::{Error, Path};
|
||||
use dbus::arg::PropMap;
|
||||
use glib::{clone, PropertySet};
|
||||
use gtk::prelude::{ButtonExt, EditableExt, WidgetExt};
|
||||
use ReSet_Lib::network::connection::{Connection, DNSMethod4, DNSMethod6, Enum, TypeSettings};
|
||||
use IpProtocol::{IPv4, IPv6};
|
||||
|
||||
use crate::components::wifi::utils::IpProtocol;
|
||||
use crate::components::wifi::wifiAddressEntry::WifiAddressEntry;
|
||||
use crate::components::wifi::wifiOptionsImpl;
|
||||
use crate::components::wifi::wifiRouteEntry::WifiRouteEntry;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct WifiOptions(ObjectSubclass<wifiOptionsImpl::WifiOptions>)
|
||||
@extends adw::NavigationPage, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
|
||||
}
|
||||
|
||||
unsafe impl Send for WifiOptions {}
|
||||
unsafe impl Sync for WifiOptions {}
|
||||
|
||||
impl WifiOptions {
|
||||
pub fn new(connection: Connection, accessPoint: Path<'static>) -> Arc<Self> {
|
||||
let wifiOption: Arc<WifiOptions> = Arc::new(Object::builder().build());
|
||||
wifiOption.imp().connection.set(connection);
|
||||
wifiOption.initializeUI();
|
||||
setupCallbacks(&wifiOption, accessPoint);
|
||||
wifiOption
|
||||
}
|
||||
|
||||
pub fn initializeUI(&self) {
|
||||
let selfImp = self.imp();
|
||||
let ip4AddressLength;
|
||||
let ip4RouteLength;
|
||||
let ip6AddressLength;
|
||||
let ip6RouteLength;
|
||||
{
|
||||
let conn = selfImp.connection.borrow();
|
||||
ip4AddressLength = conn.ipv4.address_data.len();
|
||||
ip4RouteLength = conn.ipv4.route_data.len();
|
||||
ip6AddressLength = conn.ipv4.address_data.len();
|
||||
ip6RouteLength = conn.ipv4.route_data.len();
|
||||
|
||||
// General
|
||||
selfImp.resetWifiAutoConnect.set_active(conn.settings.autoconnect);
|
||||
selfImp.resetWifiMetered.set_active(conn.settings.metered != -1);
|
||||
match &conn.device {
|
||||
TypeSettings::WIFI(wifi) => {
|
||||
selfImp.resetWifiLinkSpeed.set_visible(false);
|
||||
selfImp.resetWifiIP4Addr.set_visible(false);
|
||||
selfImp.resetWifiIP6Addr.set_visible(false);
|
||||
selfImp.resetWifiDNS.set_visible(false);
|
||||
selfImp.resetWifiGateway.set_visible(false);
|
||||
selfImp.resetWifiLastUsed.set_visible(true);
|
||||
selfImp.resetWifiMac.set_subtitle(&*wifi.cloned_mac_address);
|
||||
selfImp.resetWifiName.set_subtitle(&*String::from_utf8(wifi.ssid.clone())
|
||||
.unwrap_or(String::default()));
|
||||
}
|
||||
TypeSettings::ETHERNET(ethernet) => {
|
||||
selfImp.resetWifiLinkSpeed.set_visible(true);
|
||||
selfImp.resetWifiIP4Addr.set_visible(true);
|
||||
selfImp.resetWifiIP6Addr.set_visible(true);
|
||||
selfImp.resetWifiDNS.set_visible(true);
|
||||
selfImp.resetWifiGateway.set_visible(true);
|
||||
selfImp.resetWifiLastUsed.set_visible(false);
|
||||
selfImp.resetWifiMac.set_subtitle(&*ethernet.cloned_mac_address);
|
||||
selfImp.resetWifiLinkSpeed.set_subtitle(&*ethernet.speed.to_string());
|
||||
}
|
||||
TypeSettings::VPN(_vpn) => {}
|
||||
TypeSettings::None => {}
|
||||
};
|
||||
// IPv4
|
||||
selfImp.resetIP4Method.set_selected(conn.ipv4.dns_method.to_i32() as u32);
|
||||
self.setIP4Visibility(conn.ipv4.dns_method.to_i32() as u32);
|
||||
|
||||
let ipv4Dns: Vec<String> = conn.ipv4.dns.iter().map(|addr| {
|
||||
addr.iter().map(|octet| octet.to_string()).collect::<Vec<String>>().join(".")
|
||||
}).collect();
|
||||
selfImp.resetIP4DNS.set_text(&ipv4Dns.join(", "));
|
||||
selfImp.resetIP4Gateway.set_text(&conn.ipv4.gateway);
|
||||
// IPv6
|
||||
selfImp.resetIP6Method.set_selected(conn.ipv6.dns_method.to_i32() as u32);
|
||||
self.setIP6Visibility(conn.ipv6.dns_method.to_i32() as u32);
|
||||
|
||||
let ipv6Dns: Vec<String> = conn.ipv6.dns.iter().map(|addr| {
|
||||
addr.iter().map(|octet| octet.to_string()).collect::<Vec<String>>().join(":")
|
||||
}).collect();
|
||||
selfImp.resetIP6DNS.set_text(&ipv6Dns.join(", "));
|
||||
selfImp.resetIP6Gateway.set_text(&conn.ipv6.gateway);
|
||||
|
||||
// Security
|
||||
if let TypeSettings::WIFI(wifi) = &conn.device {
|
||||
match wifi.security_settings.key_management.as_str() {
|
||||
"none" => {
|
||||
selfImp.resetWifiSecurityDropdown.set_selected(0);
|
||||
selfImp.resetWifiPassword.set_visible(false);
|
||||
selfImp.resetWifiPassword.set_text("");
|
||||
}
|
||||
"wpa-psk" => {
|
||||
selfImp.resetWifiSecurityDropdown.set_selected(1);
|
||||
selfImp.resetWifiPassword.set_visible(true);
|
||||
selfImp.resetWifiPassword.set_text(&wifi.security_settings.psk);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
// IPv4
|
||||
for i in 0..ip4AddressLength {
|
||||
let address = &WifiAddressEntry::new(Some(i), selfImp.connection.clone(), IPv4);
|
||||
selfImp.resetIP4AddressGroup.add(address);
|
||||
}
|
||||
let address = &WifiAddressEntry::new(None, selfImp.connection.clone(), IPv4);
|
||||
selfImp.resetIP4AddressGroup.add(address);
|
||||
|
||||
for i in 0..ip4RouteLength {
|
||||
let route = &WifiRouteEntry::new(Some(i), selfImp.connection.clone(), IPv4);
|
||||
selfImp.resetIP4RoutesGroup.add(route)
|
||||
}
|
||||
let route = &WifiRouteEntry::new(None, selfImp.connection.clone(), IPv4);
|
||||
selfImp.resetIP4RoutesGroup.add(route);
|
||||
|
||||
// IPv6
|
||||
for i in 0..ip6AddressLength {
|
||||
let address = &WifiAddressEntry::new(Some(i), selfImp.connection.clone(), IPv6);
|
||||
selfImp.resetIP6AddressGroup.add(address);
|
||||
}
|
||||
let address = &WifiAddressEntry::new(None, selfImp.connection.clone(), IPv6);
|
||||
selfImp.resetIP6AddressGroup.add(address);
|
||||
|
||||
for i in 0..ip6RouteLength {
|
||||
let route = &WifiRouteEntry::new(Some(i), selfImp.connection.clone(), IPv6);
|
||||
selfImp.resetIP6RoutesGroup.add(route);
|
||||
}
|
||||
let route = &WifiRouteEntry::new(None, selfImp.connection.clone(), IPv6);
|
||||
selfImp.resetIP6RoutesGroup.add(route);
|
||||
// Security
|
||||
}
|
||||
|
||||
pub fn setIP4Visibility(&self, method: u32) {
|
||||
let selfImp = self.imp();
|
||||
match method {
|
||||
0 => { // auto
|
||||
selfImp.resetIP4AddressGroup.set_visible(false);
|
||||
selfImp.resetIP4RoutesGroup.set_visible(true);
|
||||
selfImp.resetIP4Gateway.set_visible(false);
|
||||
}
|
||||
1 => { // manual
|
||||
selfImp.resetIP4AddressGroup.set_visible(true);
|
||||
selfImp.resetIP4RoutesGroup.set_visible(true);
|
||||
selfImp.resetIP4Gateway.set_visible(true);
|
||||
}
|
||||
_ => {
|
||||
selfImp.resetIP4AddressGroup.set_visible(false);
|
||||
selfImp.resetIP4RoutesGroup.set_visible(false);
|
||||
selfImp.resetIP4Gateway.set_visible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setIP6Visibility(&self, method: u32) {
|
||||
let selfImp = self.imp();
|
||||
match method {
|
||||
0 | 1 => { // auto, dhcp
|
||||
selfImp.resetIP6AddressGroup.set_visible(false);
|
||||
selfImp.resetIP6RoutesGroup.set_visible(true);
|
||||
selfImp.resetIP6Gateway.set_visible(false);
|
||||
}
|
||||
2 => { // manual
|
||||
selfImp.resetIP6AddressGroup.set_visible(true);
|
||||
selfImp.resetIP6RoutesGroup.set_visible(true);
|
||||
selfImp.resetIP6Gateway.set_visible(true);
|
||||
}
|
||||
_ => {
|
||||
selfImp.resetIP6AddressGroup.set_visible(false);
|
||||
selfImp.resetIP6RoutesGroup.set_visible(false);
|
||||
selfImp.resetIP6Gateway.set_visible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn setupCallbacks(wifiOptions: &Arc<WifiOptions>, path: Path<'static>) {
|
||||
let imp = wifiOptions.imp();
|
||||
|
||||
// General
|
||||
imp.resetWifiAutoConnect.connect_active_notify(clone!(@weak imp => move |x| {
|
||||
imp.connection.borrow_mut().settings.autoconnect = x.is_active();
|
||||
}));
|
||||
imp.resetWifiMetered.connect_active_notify(clone!(@weak imp => move |x| {
|
||||
imp.connection.borrow_mut().settings.metered = if x.is_active() { 1 } else { 2 };
|
||||
}));
|
||||
imp.wifiOptionsApplyButton.connect_clicked(clone!(@weak imp => move |_| {
|
||||
let prop = imp.connection.borrow().convert_to_propmap();
|
||||
setConnectionSettings(path.clone(), prop);
|
||||
}));
|
||||
// IPv4
|
||||
let wifiOptionsIP4 = wifiOptions.clone();
|
||||
imp.resetIP4Method.connect_selected_notify(clone!(@weak imp => move |dropdown| {
|
||||
let selected = dropdown.selected();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
conn.ipv4.dns_method = DNSMethod4::from_i32(selected as i32);
|
||||
wifiOptionsIP4.setIP4Visibility(selected);
|
||||
}));
|
||||
|
||||
imp.resetIP4DNS.connect_changed(clone!(@weak imp => move |entry| {
|
||||
let dnsInput = entry.text();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
conn.ipv4.dns.clear();
|
||||
if dnsInput.is_empty() {
|
||||
imp.resetIP4DNS.remove_css_class("error");
|
||||
return;
|
||||
}
|
||||
for dnsEntry in dnsInput.as_str().split(',').map(|s| s.trim()) {
|
||||
if let Ok(addr) = Ipv4Addr::from_str(dnsEntry) {
|
||||
imp.resetIP4DNS.remove_css_class("error");
|
||||
conn.ipv4.dns.push(addr.octets().to_vec());
|
||||
} else {
|
||||
imp.resetIP4DNS.add_css_class("error");
|
||||
}
|
||||
}
|
||||
}));
|
||||
imp.resetIP4AddressAddButton.connect_clicked(clone!(@weak imp => move |_| {
|
||||
let address = &WifiAddressEntry::new(None, imp.connection.clone(), IpProtocol::IPv4);
|
||||
imp.resetIP4AddressGroup.add(address);
|
||||
}));
|
||||
|
||||
imp.resetIP4Gateway.connect_changed(clone!(@weak imp => move |entry| {
|
||||
let gatewayInput = entry.text();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
conn.ipv4.gateway.clear();
|
||||
if gatewayInput.is_empty() {
|
||||
imp.resetIP4Gateway.remove_css_class("error");
|
||||
return;
|
||||
}
|
||||
if let Ok(_) = Ipv4Addr::from_str(gatewayInput.as_str()) {
|
||||
imp.resetIP4Gateway.remove_css_class("error");
|
||||
conn.ipv4.gateway = gatewayInput.to_string();
|
||||
} else {
|
||||
imp.resetIP4Gateway.add_css_class("error");
|
||||
}
|
||||
}));
|
||||
// IPv6
|
||||
let wifiOptionsIP6 = wifiOptions.clone();
|
||||
imp.resetIP6Method.connect_selected_notify(clone!(@weak imp => move |dropdown| {
|
||||
let selected = dropdown.selected();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
conn.ipv6.dns_method = DNSMethod6::from_i32(selected as i32);
|
||||
wifiOptionsIP6.setIP6Visibility(selected);
|
||||
}));
|
||||
|
||||
imp.resetIP6DNS.connect_changed(clone!(@weak imp => move |entry| {
|
||||
let dnsInput = entry.text();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
conn.ipv6.dns.clear();
|
||||
if dnsInput.is_empty() {
|
||||
imp.resetIP6DNS.remove_css_class("error");
|
||||
return;
|
||||
}
|
||||
for dnsEntry in dnsInput.as_str().split(',').map(|s| s.trim()) {
|
||||
if let Ok(addr) = Ipv6Addr::from_str(dnsEntry) {
|
||||
imp.resetIP6DNS.remove_css_class("error");
|
||||
conn.ipv6.dns.push(addr.octets().to_vec());
|
||||
} else {
|
||||
imp.resetIP6DNS.add_css_class("error");
|
||||
}
|
||||
}
|
||||
}));
|
||||
imp.resetIP6AddressAddButton.connect_clicked(clone!(@weak imp => move |_| {
|
||||
let address = &WifiAddressEntry::new(None, imp.connection.clone(), IpProtocol::IPv4);
|
||||
imp.resetIP6AddressGroup.add(address);
|
||||
}));
|
||||
|
||||
imp.resetIP6Gateway.connect_changed(clone!(@weak imp => move |entry| {
|
||||
let gatewayInput = entry.text();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
conn.ipv6.gateway.clear();
|
||||
if gatewayInput.is_empty() {
|
||||
imp.resetIP6Gateway.remove_css_class("error");
|
||||
return;
|
||||
}
|
||||
if let Ok(_) = Ipv6Addr::from_str(gatewayInput.as_str()) {
|
||||
imp.resetIP6Gateway.remove_css_class("error");
|
||||
conn.ipv6.gateway = gatewayInput.to_string();
|
||||
} else {
|
||||
imp.resetIP6Gateway.add_css_class("error");
|
||||
}
|
||||
}));
|
||||
|
||||
// Security
|
||||
imp.resetWifiSecurityDropdown.connect_selected_notify(clone!(@weak imp => move |dropdown| {
|
||||
let selected = dropdown.selected();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
|
||||
match (selected, &mut conn.device) {
|
||||
(0 , TypeSettings::WIFI(wifi)) => { // None
|
||||
imp.resetWifiPassword.set_visible(false);
|
||||
wifi.security_settings.key_management = String::from("none");
|
||||
wifi.security_settings.authentication_algorithm = String::from("open");
|
||||
},
|
||||
(1 , TypeSettings::WIFI(wifi)) => { // WPA/WPA2 Personal
|
||||
imp.resetWifiPassword.set_visible(true);
|
||||
wifi.security_settings.key_management = String::from("wpa-psk");
|
||||
wifi.security_settings.authentication_algorithm = String::from("");
|
||||
},
|
||||
(_, _) => {}
|
||||
}
|
||||
}));
|
||||
|
||||
imp.resetWifiPassword.connect_changed(clone!(@weak imp => move |entry| {
|
||||
let passwordInput = entry.text();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
if let TypeSettings::WIFI(wifi) = &mut conn.device {
|
||||
wifi.security_settings.psk = passwordInput.to_string();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
fn setConnectionSettings(path: Path<'static>, prop: PropMap) {
|
||||
gio::spawn_blocking(move || {
|
||||
let conn = dbus::blocking::Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSetDaemon",
|
||||
"/org/Xetibo/ReSetDaemon",
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let _: Result<(bool,), Error> = proxy.method_call(
|
||||
"org.Xetibo.ReSetWireless",
|
||||
"SetConnectionSettings",
|
||||
(path, prop),
|
||||
);
|
||||
});
|
||||
}
|
|
@ -1,242 +0,0 @@
|
|||
use crate::components::wifi::utils::IpProtocol;
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{ExpanderRowExt, PreferencesRowExt};
|
||||
use glib::clone;
|
||||
use glib::subclass::prelude::ObjectSubclassIsExt;
|
||||
use gtk::prelude::{EditableExt, WidgetExt};
|
||||
use std::cell::RefCell;
|
||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
use std::rc::Rc;
|
||||
use std::str::FromStr;
|
||||
use ReSet_Lib::network::connection::{Address, Connection};
|
||||
|
||||
use crate::components::wifi::wifiRouteEntryImpl;
|
||||
use crate::components::wifi::wifiRouteEntryImpl::WifiRouteEntryImpl;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct WifiRouteEntry(ObjectSubclass<wifiRouteEntryImpl::WifiRouteEntryImpl>)
|
||||
@extends gtk::Box, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
|
||||
}
|
||||
|
||||
impl WifiRouteEntry {
|
||||
pub fn new(
|
||||
address: Option<usize>,
|
||||
conn: Rc<RefCell<Connection>>,
|
||||
protocol: IpProtocol,
|
||||
) -> Self {
|
||||
let entry: WifiRouteEntry = Object::builder().build();
|
||||
let entryImp = entry.imp();
|
||||
|
||||
if let Some(address) = address {
|
||||
let conn = conn.borrow();
|
||||
let address = unsafe { conn.ipv4.route_data.get_unchecked(address) };
|
||||
|
||||
entryImp.resetRouteAddress.set_text(&address.address);
|
||||
entryImp
|
||||
.resetRoutePrefix
|
||||
.set_text(&address.prefix_length.to_string());
|
||||
if let Some(gateway) = &address.gateway {
|
||||
entryImp.resetRouteGateway.set_text(gateway);
|
||||
}
|
||||
if let Some(metric) = address.metric {
|
||||
entryImp.resetRouteMetric.set_text(&metric.to_string());
|
||||
}
|
||||
entryImp
|
||||
.resetRouteRow
|
||||
.set_title(&format!("{}/{}", &*address.address, address.prefix_length));
|
||||
}
|
||||
entryImp.protocol.set(protocol);
|
||||
entry.setupCallbacks(conn);
|
||||
entry
|
||||
}
|
||||
|
||||
fn setupCallbacks(&self, connection: Rc<RefCell<Connection>>) {
|
||||
let selfImp = self.imp();
|
||||
|
||||
let conn = connection.clone();
|
||||
selfImp.resetRouteAddress.connect_changed(clone!(@weak selfImp => move |entry| {
|
||||
let addressInput = entry.text();
|
||||
let mut conn = conn.borrow_mut();
|
||||
|
||||
if addressInput.is_empty() {
|
||||
selfImp.resetRouteAddress.remove_css_class("error");
|
||||
selfImp.resetRouteRow.set_title("Add new address");
|
||||
return;
|
||||
}
|
||||
let result = match selfImp.protocol.get() {
|
||||
IpProtocol::IPv4 => Ipv4Addr::from_str(addressInput.as_str()).map(IpAddr::V4),
|
||||
IpProtocol::IPv6 => Ipv6Addr::from_str(addressInput.as_str()).map(IpAddr::V6),
|
||||
};
|
||||
match result {
|
||||
Ok(ipAddr) => {
|
||||
selfImp.resetRouteAddress.remove_css_class("error");
|
||||
let addressData = match selfImp.protocol.get() {
|
||||
IpProtocol::IPv4 => &mut conn.ipv4.route_data,
|
||||
IpProtocol::IPv6 => &mut conn.ipv6.route_data,
|
||||
};
|
||||
addressData.push(Address::new(ipAddr.to_string(), selfImp.prefix.get().1 as u32, selfImp.gateway.borrow().clone(), selfImp.metric.get()));
|
||||
*selfImp.address.borrow_mut() = (true, ipAddr.to_string());
|
||||
}
|
||||
Err(_) => {
|
||||
selfImp.resetRouteAddress.add_css_class("error");
|
||||
*selfImp.address.borrow_mut() = (false, String::default());
|
||||
}
|
||||
}
|
||||
setRowTitle(&selfImp);
|
||||
}));
|
||||
|
||||
let conn = connection.clone();
|
||||
selfImp.resetRoutePrefix.connect_changed(clone!(@weak selfImp => move |entry| {
|
||||
let prefixInput = entry.text();
|
||||
let prefix = prefixInput.parse::<u8>();
|
||||
let mut conn = conn.borrow_mut();
|
||||
|
||||
let handleError = || {
|
||||
if selfImp.resetRoutePrefix.text().is_empty() {
|
||||
selfImp.resetRoutePrefix.remove_css_class("error");
|
||||
} else {
|
||||
selfImp.resetRoutePrefix.add_css_class("error");
|
||||
}
|
||||
selfImp.prefix.set((false, 0));
|
||||
setRowTitle(&selfImp);
|
||||
};
|
||||
|
||||
if prefixInput.is_empty() || prefix.is_err() {
|
||||
handleError();
|
||||
return;
|
||||
}
|
||||
|
||||
let prefix = prefix.unwrap();
|
||||
match selfImp.protocol.get() {
|
||||
IpProtocol::IPv4 if prefix <= 32 => {
|
||||
selfImp.prefix.set((true, prefix as u32));
|
||||
selfImp.resetRoutePrefix.remove_css_class("error");
|
||||
if let Ok(address2) = Ipv4Addr::from_str(selfImp.resetRouteAddress.text().as_str()) {
|
||||
if let Some(addr) = conn.ipv4.route_data.iter_mut()
|
||||
.find(|connAddr| *connAddr.address == address2.to_string()) {
|
||||
addr.prefix_length = prefix as u32;
|
||||
}
|
||||
}
|
||||
}
|
||||
IpProtocol::IPv6 if prefix <= 128 => {
|
||||
selfImp.prefix.set((true, prefix as u32));
|
||||
selfImp.resetRoutePrefix.remove_css_class("error");
|
||||
if let Ok(address2) = Ipv6Addr::from_str(selfImp.resetRouteAddress.text().as_str()) {
|
||||
if let Some(addr) = conn.ipv6.route_data.iter_mut()
|
||||
.find(|connAddr| *connAddr.address == address2.to_string()) {
|
||||
addr.prefix_length = prefix as u32;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => handleError()
|
||||
}
|
||||
setRowTitle(&selfImp);
|
||||
}));
|
||||
|
||||
let conn = connection.clone();
|
||||
selfImp
|
||||
.resetRouteGateway
|
||||
.connect_changed(clone!(@weak selfImp => move |entry| {
|
||||
let gatewayInput = entry.text();
|
||||
let mut conn = conn.borrow_mut();
|
||||
|
||||
if gatewayInput.is_empty() {
|
||||
selfImp.resetRouteGateway.remove_css_class("error");
|
||||
*selfImp.gateway.borrow_mut() = None;
|
||||
setRowSubtitle(&selfImp);
|
||||
return;
|
||||
}
|
||||
let result = match selfImp.protocol.get() {
|
||||
IpProtocol::IPv4 => Ipv4Addr::from_str(gatewayInput.as_str()).map(IpAddr::V4),
|
||||
IpProtocol::IPv6 => Ipv6Addr::from_str(gatewayInput.as_str()).map(IpAddr::V6),
|
||||
};
|
||||
match result {
|
||||
Ok(ipAddr) => {
|
||||
selfImp.resetRouteGateway.remove_css_class("error");
|
||||
let addressData = match selfImp.protocol.get() {
|
||||
IpProtocol::IPv4 => &mut conn.ipv4.route_data,
|
||||
IpProtocol::IPv6 => &mut conn.ipv6.route_data,
|
||||
};
|
||||
if let Some(address) = addressData.iter_mut()
|
||||
.find(|connAddr| *connAddr.address == selfImp.resetRouteAddress.text()) {
|
||||
address.gateway = Some(ipAddr.to_string());
|
||||
}
|
||||
*selfImp.gateway.borrow_mut() = Some(ipAddr.to_string());
|
||||
}
|
||||
Err(_) => {
|
||||
selfImp.resetRouteGateway.add_css_class("error");
|
||||
*selfImp.gateway.borrow_mut() = None;
|
||||
}
|
||||
}
|
||||
setRowSubtitle(&selfImp);
|
||||
}));
|
||||
|
||||
let conn = connection.clone();
|
||||
selfImp
|
||||
.resetRouteMetric
|
||||
.connect_changed(clone!(@weak selfImp => move |entry| {
|
||||
let metricInput = entry.text();
|
||||
let mut conn = conn.borrow_mut();
|
||||
|
||||
if metricInput.is_empty() {
|
||||
selfImp.resetRouteMetric.remove_css_class("error");
|
||||
selfImp.metric.set(None);
|
||||
setRowSubtitle(&selfImp);
|
||||
return;
|
||||
}
|
||||
let result = metricInput.parse::<u32>();
|
||||
match result {
|
||||
Ok(metric) => {
|
||||
selfImp.resetRouteMetric.remove_css_class("error");
|
||||
let addressData = match selfImp.protocol.get() {
|
||||
IpProtocol::IPv4 => &mut conn.ipv4.route_data,
|
||||
IpProtocol::IPv6 => &mut conn.ipv6.route_data,
|
||||
};
|
||||
if let Some(address) = addressData.iter_mut()
|
||||
.find(|connAddr| *connAddr.address == selfImp.resetRouteAddress.text()) {
|
||||
address.metric = Some(metric);
|
||||
}
|
||||
selfImp.metric.set(Some(metric));
|
||||
}
|
||||
Err(_) => {
|
||||
selfImp.resetRouteMetric.add_css_class("error");
|
||||
selfImp.metric.set(None);
|
||||
}
|
||||
}
|
||||
setRowSubtitle(&selfImp);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
fn setRowTitle(selfImp: &WifiRouteEntryImpl) {
|
||||
if selfImp.resetRouteAddress.text().is_empty() {
|
||||
return;
|
||||
}
|
||||
let address = selfImp.address.borrow();
|
||||
let prefix = selfImp.prefix.get();
|
||||
let title = match (address.0, prefix.0) {
|
||||
(true, true) => {
|
||||
format!("{}/{}", address.1, prefix.1)
|
||||
}
|
||||
(true, false) => "Prefix wrong".to_string(),
|
||||
(false, true) => "Address wrong".to_string(),
|
||||
(false, false) => "Address and Prefix wrong".to_string(),
|
||||
};
|
||||
selfImp.resetRouteRow.set_title(&title);
|
||||
}
|
||||
|
||||
fn setRowSubtitle(selfImp: &WifiRouteEntryImpl) {
|
||||
let gateway = selfImp.gateway.borrow().clone();
|
||||
let metric = selfImp.metric.get();
|
||||
let title = match (gateway, metric) {
|
||||
(Some(gateway), Some(metric)) => {
|
||||
format!("{}, {}", gateway, metric)
|
||||
}
|
||||
(Some(gateway), None) => gateway,
|
||||
(None, Some(metric)) => metric.to_string(),
|
||||
(None, None) => String::default(),
|
||||
};
|
||||
selfImp.resetRouteRow.set_subtitle(&title);
|
||||
}
|
160
src/components/wifi/wifi_address_entry.rs
Normal file
160
src/components/wifi/wifi_address_entry.rs
Normal file
|
@ -0,0 +1,160 @@
|
|||
use std::cell::RefCell;
|
||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
use std::rc::Rc;
|
||||
use std::str::FromStr;
|
||||
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::PreferencesRowExt;
|
||||
use glib::clone;
|
||||
use glib::subclass::prelude::ObjectSubclassIsExt;
|
||||
use gtk::prelude::{ButtonExt, EditableExt, WidgetExt};
|
||||
use ReSet_Lib::network::connection::{Address, Connection};
|
||||
|
||||
use crate::components::wifi::utils::IpProtocol;
|
||||
use crate::components::wifi::wifi_address_entry_impl;
|
||||
use crate::components::wifi::wifi_address_entry_impl::WifiAddressEntryImpl;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct WifiAddressEntry(ObjectSubclass<wifi_address_entry_impl::WifiAddressEntryImpl>)
|
||||
@extends gtk::Box, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
|
||||
}
|
||||
|
||||
impl WifiAddressEntry {
|
||||
pub fn new(
|
||||
address: Option<usize>,
|
||||
conn: Rc<RefCell<Connection>>,
|
||||
protocol: IpProtocol,
|
||||
) -> Self {
|
||||
let entry: WifiAddressEntry = Object::builder().build();
|
||||
let entry_imp = entry.imp();
|
||||
|
||||
if let Some(address) = address {
|
||||
let conn = conn.borrow();
|
||||
let address = unsafe { conn.ipv4.address_data.get_unchecked(address) };
|
||||
|
||||
entry_imp.resetAddressAddress.set_text(&address.address);
|
||||
entry_imp
|
||||
.resetAddressPrefix
|
||||
.set_text(&address.prefix_length.to_string());
|
||||
entry_imp
|
||||
.resetAddressRow
|
||||
.set_title(&format!("{}/{}", &*address.address, address.prefix_length));
|
||||
}
|
||||
entry_imp.protocol.set(protocol);
|
||||
entry.setup_callbacks(conn);
|
||||
entry
|
||||
}
|
||||
|
||||
pub fn setup_callbacks(&self, connection: Rc<RefCell<Connection>>) {
|
||||
let self_imp = self.imp();
|
||||
|
||||
let conn = connection.clone();
|
||||
self_imp.resetAddressAddress.connect_changed(clone!(@weak self_imp => move |entry| {
|
||||
let address_input = entry.text();
|
||||
let mut conn = conn.borrow_mut();
|
||||
|
||||
if address_input.is_empty() {
|
||||
self_imp.resetAddressAddress.remove_css_class("error");
|
||||
self_imp.resetAddressRow.set_title("Add new address");
|
||||
return;
|
||||
}
|
||||
let result = match self_imp.protocol.get() {
|
||||
IpProtocol::IPv4 => Ipv4Addr::from_str(address_input.as_str()).map(IpAddr::V4),
|
||||
IpProtocol::IPv6 => Ipv6Addr::from_str(address_input.as_str()).map(IpAddr::V6),
|
||||
};
|
||||
match result {
|
||||
Ok(ip_addr) => {
|
||||
self_imp.resetAddressAddress.remove_css_class("error");
|
||||
let address_data = match self_imp.protocol.get() {
|
||||
IpProtocol::IPv4 => &mut conn.ipv4.address_data,
|
||||
IpProtocol::IPv6 => &mut conn.ipv6.address_data,
|
||||
};
|
||||
address_data.push(Address::theBetterNew(ip_addr.to_string(), self_imp.prefix.get().1 as u32));
|
||||
*self_imp.address.borrow_mut() = (true, ip_addr.to_string());
|
||||
}
|
||||
Err(_) => {
|
||||
self_imp.resetAddressAddress.add_css_class("error");
|
||||
*self_imp.address.borrow_mut() = (false, String::default());
|
||||
}
|
||||
}
|
||||
set_row_name(&self_imp);
|
||||
}));
|
||||
|
||||
let conn = connection.clone();
|
||||
self_imp.resetAddressPrefix.connect_changed(clone!(@weak self_imp => move |entry| {
|
||||
let prefix_input = entry.text();
|
||||
let prefix = prefix_input.parse::<u8>();
|
||||
let mut conn = conn.borrow_mut();
|
||||
|
||||
let handle_error = || {
|
||||
if self_imp.resetAddressPrefix.text().is_empty() {
|
||||
self_imp.resetAddressPrefix.remove_css_class("error");
|
||||
} else {
|
||||
self_imp.resetAddressPrefix.add_css_class("error");
|
||||
}
|
||||
self_imp.prefix.set((false, 0));
|
||||
set_row_name(&self_imp);
|
||||
};
|
||||
|
||||
if prefix_input.is_empty() || prefix.is_err() {
|
||||
handle_error();
|
||||
return;
|
||||
}
|
||||
|
||||
let prefix = prefix.unwrap();
|
||||
match self_imp.protocol.get() {
|
||||
IpProtocol::IPv4 if prefix <= 32 => {
|
||||
self_imp.prefix.set((true, prefix as u32));
|
||||
self_imp.resetAddressPrefix.remove_css_class("error");
|
||||
if let Ok(address2) = Ipv4Addr::from_str(self_imp.resetAddressAddress.text().as_str()) {
|
||||
if let Some(addr) = conn.ipv4.address_data.iter_mut()
|
||||
.find(|conn_addr| *conn_addr.address == address2.to_string()) {
|
||||
addr.prefix_length = prefix as u32;
|
||||
}
|
||||
}
|
||||
}
|
||||
IpProtocol::IPv6 if prefix <= 128 => {
|
||||
self_imp.prefix.set((true, prefix as u32));
|
||||
self_imp.resetAddressPrefix.remove_css_class("error");
|
||||
if let Ok(address2) = Ipv6Addr::from_str(self_imp.resetAddressAddress.text().as_str()) {
|
||||
if let Some(addr) = conn.ipv6.address_data.iter_mut()
|
||||
.find(|conn_addr| *conn_addr.address == address2.to_string()) {
|
||||
addr.prefix_length = prefix as u32;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => handle_error()
|
||||
}
|
||||
set_row_name(&self_imp);
|
||||
}));
|
||||
|
||||
let conn = connection.clone();
|
||||
self_imp.resetAddressRemove.connect_clicked(
|
||||
clone!(@weak self_imp, @weak self as what => move |_| {
|
||||
let address = self_imp.resetAddressAddress.text();
|
||||
let mut conn = conn.borrow_mut();
|
||||
conn.ipv4.address_data.retain(|addr| addr.address != address);
|
||||
what.unparent();
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_row_name(self_imp: &WifiAddressEntryImpl) {
|
||||
if self_imp.resetAddressAddress.text().is_empty() {
|
||||
return;
|
||||
}
|
||||
let address = self_imp.address.borrow();
|
||||
let prefix = self_imp.prefix.get();
|
||||
let title = match (address.0, prefix.0) {
|
||||
(true, true) => {
|
||||
format!("{}/{}", address.1, prefix.1)
|
||||
}
|
||||
(true, false) => "Prefix wrong".to_string(),
|
||||
(false, true) => "Address wrong".to_string(),
|
||||
(false, false) => "Address and Prefix wrong".to_string(),
|
||||
};
|
||||
self_imp.resetAddressRow.set_title(&title);
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
use crate::components::wifi::utils::IpProtocol;
|
||||
use crate::components::wifi::wifiAddressEntry;
|
||||
use crate::components::wifi::wifi_address_entry;
|
||||
use adw::{EntryRow, ExpanderRow};
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, Button, CompositeTemplate};
|
||||
|
@ -26,7 +26,7 @@ pub struct WifiAddressEntryImpl {
|
|||
impl ObjectSubclass for WifiAddressEntryImpl {
|
||||
const ABSTRACT: bool = false;
|
||||
const NAME: &'static str = "resetWifiAddressEntry";
|
||||
type Type = wifiAddressEntry::WifiAddressEntry;
|
||||
type Type = wifi_address_entry::WifiAddressEntry;
|
||||
type ParentType = gtk::Box;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
|
@ -5,7 +5,7 @@ use std::sync::Arc;
|
|||
use std::time::Duration;
|
||||
|
||||
use crate::components::base::utils::Listeners;
|
||||
use crate::components::utils::setComboRowEllipsis;
|
||||
use crate::components::utils::set_combo_row_ellipsis;
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{ComboRowExt, ListBoxRowExt, PreferencesGroupExt};
|
||||
|
@ -16,19 +16,19 @@ use dbus::Error;
|
|||
use dbus::Path;
|
||||
use glib::{clone, Cast, PropertySet};
|
||||
use gtk::glib::Variant;
|
||||
use gtk::prelude::{ActionableExt, WidgetExt, BoxExt};
|
||||
use gtk::prelude::{ActionableExt, WidgetExt};
|
||||
use gtk::{gio, StringObject};
|
||||
use ReSet_Lib::network::network::{AccessPoint, WifiDevice, WifiStrength};
|
||||
use ReSet_Lib::signals::{AccessPointAdded, WifiDeviceChanged};
|
||||
use ReSet_Lib::signals::{AccessPointChanged, AccessPointRemoved};
|
||||
|
||||
use crate::components::wifi::wifiBoxImpl;
|
||||
use crate::components::wifi::wifiEntry::WifiEntry;
|
||||
use crate::components::wifi::wifi_box_impl;
|
||||
use crate::components::wifi::wifi_entry::WifiEntry;
|
||||
|
||||
use super::savedWifiEntry::SavedWifiEntry;
|
||||
use super::saved_wifi_entry::SavedWifiEntry;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct WifiBox(ObjectSubclass<wifiBoxImpl::WifiBox>)
|
||||
pub struct WifiBox(ObjectSubclass<wifi_box_impl::WifiBox>)
|
||||
@extends gtk::Box, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
|
||||
}
|
||||
|
@ -41,15 +41,15 @@ unsafe impl Sync for WifiBox {}
|
|||
impl WifiBox {
|
||||
pub fn new(listeners: Arc<Listeners>) -> Arc<Self> {
|
||||
let obj: Arc<WifiBox> = Arc::new(Object::builder().build());
|
||||
setupCallbacks(listeners, obj)
|
||||
setup_callbacks(listeners, obj)
|
||||
}
|
||||
|
||||
pub fn setupCallbacks(&self) {}
|
||||
pub fn setup_callbacks(&self) {}
|
||||
}
|
||||
|
||||
fn setupCallbacks(listeners: Arc<Listeners>, wifiBox: Arc<WifiBox>) -> Arc<WifiBox> {
|
||||
let imp = wifiBox.imp();
|
||||
let wifibox_ref = wifiBox.clone();
|
||||
fn setup_callbacks(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) -> Arc<WifiBox> {
|
||||
let imp = wifi_box.imp();
|
||||
let wifibox_ref = wifi_box.clone();
|
||||
imp.resetSavedNetworks.set_activatable(true);
|
||||
imp.resetSavedNetworks
|
||||
.set_action_name(Some("navigation.push"));
|
||||
|
@ -59,44 +59,44 @@ fn setupCallbacks(listeners: Arc<Listeners>, wifiBox: Arc<WifiBox>) -> Arc<WifiB
|
|||
imp.resetAvailableNetworks.set_activatable(true);
|
||||
imp.resetAvailableNetworks
|
||||
.set_action_name(Some("navigation.pop"));
|
||||
setComboRowEllipsis(imp.resetWiFiDevice.get());
|
||||
set_combo_row_ellipsis(imp.resetWiFiDevice.get());
|
||||
imp.resetWifiSwitch.connect_state_set(
|
||||
clone!(@weak imp => @default-return glib::Propagation::Proceed, move |_, value| {
|
||||
set_wifi_enabled(value);
|
||||
if !value {
|
||||
let mut map = imp.wifiEntries.lock().unwrap();
|
||||
let mut map = imp.wifi_entries.lock().unwrap();
|
||||
for entry in map.iter() {
|
||||
imp.resetWifiList.remove(&*(*entry.1));
|
||||
}
|
||||
map.clear();
|
||||
imp.wifiEntriesPath.lock().unwrap().clear();
|
||||
imp.wifi_entries_path.lock().unwrap().clear();
|
||||
listeners.network_listener.store(false, Ordering::SeqCst);
|
||||
} else {
|
||||
start_event_listener(listeners.clone(), wifibox_ref.clone());
|
||||
show_stored_connections(wifibox_ref.clone());
|
||||
scanForWifi(wifibox_ref.clone());
|
||||
scan_for_wifi(wifibox_ref.clone());
|
||||
}
|
||||
glib::Propagation::Proceed
|
||||
}),
|
||||
);
|
||||
wifiBox
|
||||
wifi_box
|
||||
}
|
||||
|
||||
pub fn scanForWifi(wifiBox: Arc<WifiBox>) {
|
||||
let wifibox_ref = wifiBox.clone();
|
||||
let _wifibox_ref_listener = wifiBox.clone();
|
||||
let wifiEntries = wifiBox.imp().wifiEntries.clone();
|
||||
let wifiEntriesPath = wifiBox.imp().wifiEntriesPath.clone();
|
||||
pub fn scan_for_wifi(wifi_box: Arc<WifiBox>) {
|
||||
let wifibox_ref = wifi_box.clone();
|
||||
let _wifibox_ref_listener = wifi_box.clone();
|
||||
let wifi_entries = wifi_box.imp().wifi_entries.clone();
|
||||
let wifi_entries_path = wifi_box.imp().wifi_entries_path.clone();
|
||||
|
||||
gio::spawn_blocking(move || {
|
||||
let accessPoints = get_access_points();
|
||||
let access_points = get_access_points();
|
||||
let devices = get_wifi_devices();
|
||||
{
|
||||
let imp = wifibox_ref.imp();
|
||||
let list = imp.resetModelList.write().unwrap();
|
||||
let mut model_index = imp.resetModelIndex.write().unwrap();
|
||||
let mut map = imp.resetWifiDevices.write().unwrap();
|
||||
imp.resetCurrentWifiDevice
|
||||
let list = imp.reset_model_list.write().unwrap();
|
||||
let mut model_index = imp.reset_model_index.write().unwrap();
|
||||
let mut map = imp.reset_wifi_devices.write().unwrap();
|
||||
imp.reset_current_wifi_device
|
||||
.replace(devices.last().unwrap().clone());
|
||||
for (index, device) in devices.into_iter().enumerate() {
|
||||
list.append(&device.name);
|
||||
|
@ -104,19 +104,19 @@ pub fn scanForWifi(wifiBox: Arc<WifiBox>) {
|
|||
*model_index += 1;
|
||||
}
|
||||
}
|
||||
let wifiEntries = wifiEntries.clone();
|
||||
let wifiEntriesPath = wifiEntriesPath.clone();
|
||||
let wifi_entries = wifi_entries.clone();
|
||||
let wifi_entries_path = wifi_entries_path.clone();
|
||||
dbus_start_network_events();
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let mut wifiEntries = wifiEntries.lock().unwrap();
|
||||
let mut wifiEntriesPath = wifiEntriesPath.lock().unwrap();
|
||||
let mut wifi_entries = wifi_entries.lock().unwrap();
|
||||
let mut wifi_entries_path = wifi_entries_path.lock().unwrap();
|
||||
let imp = wifibox_ref.imp();
|
||||
|
||||
let list = imp.resetModelList.read().unwrap();
|
||||
let list = imp.reset_model_list.read().unwrap();
|
||||
imp.resetWiFiDevice.set_model(Some(&*list));
|
||||
let map = imp.resetWifiDevices.read().unwrap();
|
||||
let device = imp.resetCurrentWifiDevice.borrow();
|
||||
let map = imp.reset_wifi_devices.read().unwrap();
|
||||
let device = imp.reset_current_wifi_device.borrow();
|
||||
if let Some(index) = map.get(&device.name) {
|
||||
imp.resetWiFiDevice.set_selected(index.1);
|
||||
}
|
||||
|
@ -130,20 +130,21 @@ pub fn scanForWifi(wifiBox: Arc<WifiBox>) {
|
|||
let selected = selected.downcast_ref::<StringObject>().unwrap();
|
||||
let selected = selected.string().to_string();
|
||||
|
||||
let device = imp.resetWifiDevices.read().unwrap();
|
||||
let device = imp.reset_wifi_devices.read().unwrap();
|
||||
let device = device.get(&selected);
|
||||
if device.is_none() {
|
||||
return;
|
||||
}
|
||||
set_wifi_device(device.unwrap().0.path.clone());
|
||||
}));
|
||||
for accessPoint in accessPoints {
|
||||
let ssid = accessPoint.ssid.clone();
|
||||
let path = accessPoint.dbus_path.clone();
|
||||
let connected = imp.resetCurrentWifiDevice.borrow().active_access_point == path;
|
||||
let entry = WifiEntry::new(connected, accessPoint, imp);
|
||||
wifiEntries.insert(ssid, entry.clone());
|
||||
wifiEntriesPath.insert(path, entry.clone());
|
||||
for access_point in access_points {
|
||||
let ssid = access_point.ssid.clone();
|
||||
let path = access_point.dbus_path.clone();
|
||||
let connected =
|
||||
imp.reset_current_wifi_device.borrow().active_access_point == path;
|
||||
let entry = WifiEntry::new(connected, access_point, imp);
|
||||
wifi_entries.insert(ssid, entry.clone());
|
||||
wifi_entries_path.insert(path, entry.clone());
|
||||
imp.resetWifiList.add(&*entry);
|
||||
}
|
||||
});
|
||||
|
@ -151,19 +152,19 @@ pub fn scanForWifi(wifiBox: Arc<WifiBox>) {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn show_stored_connections(wifiBox: Arc<WifiBox>) {
|
||||
let wifibox_ref = wifiBox.clone();
|
||||
pub fn show_stored_connections(wifi_box: Arc<WifiBox>) {
|
||||
let wifibox_ref = wifi_box.clone();
|
||||
gio::spawn_blocking(move || {
|
||||
let connections = get_stored_connections();
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let selfImp = wifibox_ref.imp();
|
||||
let self_imp = wifibox_ref.imp();
|
||||
for connection in connections {
|
||||
// TODO include button for settings
|
||||
let name =
|
||||
&String::from_utf8(connection.1).unwrap_or_else(|_| String::from(""));
|
||||
let entry = SavedWifiEntry::new(name, connection.0, selfImp);
|
||||
selfImp.resetStoredWifiList.add(&entry);
|
||||
let entry = SavedWifiEntry::new(name, connection.0, self_imp);
|
||||
self_imp.resetStoredWifiList.add(&entry);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -193,8 +194,8 @@ pub fn get_access_points() -> Vec<AccessPoint> {
|
|||
if res.is_err() {
|
||||
return Vec::new();
|
||||
}
|
||||
let (accessPoints,) = res.unwrap();
|
||||
accessPoints
|
||||
let (access_points,) = res.unwrap();
|
||||
access_points
|
||||
}
|
||||
|
||||
pub fn set_wifi_device(path: Path<'static>) {
|
||||
|
@ -289,18 +290,18 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
|
|||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let imp = wifi_box.imp();
|
||||
let mut wifiEntries = imp.wifiEntries.lock().unwrap();
|
||||
let mut wifiEntriesPath = imp.wifiEntriesPath.lock().unwrap();
|
||||
let mut wifi_entries = imp.wifi_entries.lock().unwrap();
|
||||
let mut wifi_entries_path = imp.wifi_entries_path.lock().unwrap();
|
||||
let ssid = ir.access_point.ssid.clone();
|
||||
let path = ir.access_point.dbus_path.clone();
|
||||
if wifiEntries.get(&ssid).is_some() {
|
||||
if wifi_entries.get(&ssid).is_some() {
|
||||
return;
|
||||
}
|
||||
let connected = imp.resetCurrentWifiDevice.borrow().active_access_point
|
||||
let connected = imp.reset_current_wifi_device.borrow().active_access_point
|
||||
== ir.access_point.dbus_path;
|
||||
let entry = WifiEntry::new(connected, ir.access_point, imp);
|
||||
wifiEntries.insert(ssid, entry.clone());
|
||||
wifiEntriesPath.insert(path, entry.clone());
|
||||
wifi_entries.insert(ssid, entry.clone());
|
||||
wifi_entries_path.insert(path, entry.clone());
|
||||
imp.resetWifiList.add(&*entry);
|
||||
});
|
||||
});
|
||||
|
@ -316,15 +317,15 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
|
|||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let imp = wifi_box.imp();
|
||||
let mut wifiEntries = imp.wifiEntries.lock().unwrap();
|
||||
let mut wifiEntriesPath = imp.wifiEntriesPath.lock().unwrap();
|
||||
let entry = wifiEntriesPath.remove(&ir.access_point);
|
||||
let mut wifi_entries = imp.wifi_entries.lock().unwrap();
|
||||
let mut wifi_entries_path = imp.wifi_entries_path.lock().unwrap();
|
||||
let entry = wifi_entries_path.remove(&ir.access_point);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
}
|
||||
let entry = entry.unwrap();
|
||||
let ssid = entry.imp().accessPoint.borrow().ssid.clone();
|
||||
wifiEntries.remove(&ssid);
|
||||
let ssid = entry.imp().access_point.borrow().ssid.clone();
|
||||
wifi_entries.remove(&ssid);
|
||||
imp.resetWifiList.remove(&*entry);
|
||||
});
|
||||
});
|
||||
|
@ -341,22 +342,22 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
|
|||
glib::spawn_future(async move {
|
||||
glib::idle_add_local_once(move || {
|
||||
let imp = wifi_box.imp();
|
||||
let wifiEntries = imp.wifiEntries.lock().unwrap();
|
||||
let entry = wifiEntries.get(&ir.access_point.ssid);
|
||||
let wifi_entries = imp.wifi_entries.lock().unwrap();
|
||||
let entry = wifi_entries.get(&ir.access_point.ssid);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
}
|
||||
let entry = entry.unwrap();
|
||||
let entryImp = entry.imp();
|
||||
let entry_imp = entry.imp();
|
||||
let strength = WifiStrength::from_u8(ir.access_point.strength);
|
||||
let ssid = ir.access_point.ssid.clone();
|
||||
let name_opt = String::from_utf8(ssid).unwrap_or_else(|_| String::from(""));
|
||||
let name = name_opt.as_str();
|
||||
entryImp.wifiStrength.set(strength);
|
||||
entryImp.resetWifiLabel.get().set_text(name);
|
||||
entryImp.resetWifiEncrypted.set_visible(false);
|
||||
entry_imp.wifi_strength.set(strength);
|
||||
entry_imp.resetWifiLabel.get().set_text(name);
|
||||
entry_imp.resetWifiEncrypted.set_visible(false);
|
||||
// TODO handle encryption thing
|
||||
entryImp
|
||||
entry_imp
|
||||
.resetWifiStrength
|
||||
.get()
|
||||
.set_from_icon_name(match strength {
|
||||
|
@ -368,18 +369,18 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
|
|||
WifiStrength::None => Some("network-wireless-signal-none-symbolic"),
|
||||
});
|
||||
if !ir.access_point.stored {
|
||||
entryImp.resetWifiEditButton.set_sensitive(false);
|
||||
entry_imp.resetWifiEditButton.set_sensitive(false);
|
||||
}
|
||||
if ir.access_point.dbus_path
|
||||
== imp.resetCurrentWifiDevice.borrow().active_access_point
|
||||
== imp.reset_current_wifi_device.borrow().active_access_point
|
||||
{
|
||||
entryImp.resetWifiConnected.set_text("Connected");
|
||||
entry_imp.resetWifiConnected.set_text("Connected");
|
||||
} else {
|
||||
entryImp.resetWifiConnected.set_text("");
|
||||
entry_imp.resetWifiConnected.set_text("");
|
||||
}
|
||||
{
|
||||
let mut wifiName = entryImp.wifiName.borrow_mut();
|
||||
*wifiName = String::from(name);
|
||||
let mut wifi_name = entry_imp.wifi_name.borrow_mut();
|
||||
*wifi_name = String::from(name);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -395,17 +396,17 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
|
|||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let imp = wifi_box.imp();
|
||||
let mut current_device = imp.resetCurrentWifiDevice.borrow_mut();
|
||||
let mut current_device = imp.reset_current_wifi_device.borrow_mut();
|
||||
if current_device.path == ir.wifi_device.path {
|
||||
current_device.active_access_point = ir.wifi_device.active_access_point;
|
||||
} else {
|
||||
*current_device = ir.wifi_device;
|
||||
}
|
||||
let mut wifiEntries = imp.wifiEntries.lock().unwrap();
|
||||
for entry in wifiEntries.iter_mut() {
|
||||
let mut wifi_entries = imp.wifi_entries.lock().unwrap();
|
||||
for entry in wifi_entries.iter_mut() {
|
||||
let imp = entry.1.imp();
|
||||
let mut connected = imp.connected.borrow_mut();
|
||||
*connected = imp.accessPoint.borrow().dbus_path == current_device.path;
|
||||
*connected = imp.access_point.borrow().dbus_path == current_device.path;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,4 +1,4 @@
|
|||
use crate::components::wifi::wifiBox;
|
||||
use crate::components::wifi::wifi_box;
|
||||
use adw::{ActionRow, ComboRow, NavigationView, PreferencesGroup};
|
||||
use dbus::Path;
|
||||
use gtk::subclass::prelude::*;
|
||||
|
@ -9,8 +9,8 @@ use std::collections::HashMap;
|
|||
use std::sync::{Arc, Mutex, RwLock};
|
||||
use ReSet_Lib::network::network::WifiDevice;
|
||||
|
||||
use crate::components::base::listEntry::ListEntry;
|
||||
use crate::components::wifi::wifiEntry::WifiEntry;
|
||||
use crate::components::base::list_entry::ListEntry;
|
||||
use crate::components::wifi::wifi_entry::WifiEntry;
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Default, CompositeTemplate)]
|
||||
|
@ -32,13 +32,13 @@ pub struct WifiBox {
|
|||
pub resetStoredWifiList: TemplateChild<PreferencesGroup>,
|
||||
#[template_child]
|
||||
pub resetAvailableNetworks: TemplateChild<ActionRow>,
|
||||
pub wifiEntries: Arc<Mutex<HashMap<Vec<u8>, Arc<WifiEntry>>>>,
|
||||
pub wifiEntriesPath: Arc<Mutex<HashMap<Path<'static>, Arc<WifiEntry>>>>,
|
||||
pub savedWifiEntries: Arc<Mutex<Vec<ListEntry>>>,
|
||||
pub resetWifiDevices: Arc<RwLock<HashMap<String, (WifiDevice, u32)>>>,
|
||||
pub resetCurrentWifiDevice: Arc<RefCell<WifiDevice>>,
|
||||
pub resetModelList: Arc<RwLock<StringList>>,
|
||||
pub resetModelIndex: Arc<RwLock<u32>>,
|
||||
pub wifi_entries: Arc<Mutex<HashMap<Vec<u8>, Arc<WifiEntry>>>>,
|
||||
pub wifi_entries_path: Arc<Mutex<HashMap<Path<'static>, Arc<WifiEntry>>>>,
|
||||
pub saved_wifi_entries: Arc<Mutex<Vec<ListEntry>>>,
|
||||
pub reset_wifi_devices: Arc<RwLock<HashMap<String, (WifiDevice, u32)>>>,
|
||||
pub reset_current_wifi_device: Arc<RefCell<WifiDevice>>,
|
||||
pub reset_model_list: Arc<RwLock<StringList>>,
|
||||
pub reset_model_index: Arc<RwLock<u32>>,
|
||||
}
|
||||
|
||||
unsafe impl Send for WifiBox {}
|
||||
|
@ -48,7 +48,7 @@ unsafe impl Sync for WifiBox {}
|
|||
impl ObjectSubclass for WifiBox {
|
||||
const ABSTRACT: bool = false;
|
||||
const NAME: &'static str = "resetWifi";
|
||||
type Type = wifiBox::WifiBox;
|
||||
type Type = wifi_box::WifiBox;
|
||||
type ParentType = gtk::Box;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
|
@ -67,7 +67,7 @@ impl ObjectImpl for WifiBox {
|
|||
self.parent_constructed();
|
||||
|
||||
let obj = self.obj();
|
||||
obj.setupCallbacks();
|
||||
obj.setup_callbacks();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::components::wifi::utils::getConnectionSettings;
|
||||
use crate::components::wifi::utils::get_connection_settings;
|
||||
use adw::glib;
|
||||
use adw::glib::{Object, PropertySet};
|
||||
use adw::prelude::{ActionRowExt, ButtonExt, EditableExt, PopoverExt};
|
||||
|
@ -13,12 +13,12 @@ use gtk::gio;
|
|||
use gtk::prelude::{ListBoxRowExt, WidgetExt};
|
||||
use ReSet_Lib::network::network::{AccessPoint, WifiStrength};
|
||||
|
||||
use crate::components::wifi::wifiBoxImpl::WifiBox;
|
||||
use crate::components::wifi::wifiEntryImpl;
|
||||
use crate::components::wifi::wifiOptions::WifiOptions;
|
||||
use crate::components::wifi::wifi_box_impl::WifiBox;
|
||||
use crate::components::wifi::wifi_entry_impl;
|
||||
use crate::components::wifi::wifi_options::WifiOptions;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct WifiEntry(ObjectSubclass<wifiEntryImpl::WifiEntry>)
|
||||
pub struct WifiEntry(ObjectSubclass<wifi_entry_impl::WifiEntry>)
|
||||
@extends adw::ActionRow, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget, gtk::ListBoxRow;
|
||||
}
|
||||
|
@ -27,21 +27,21 @@ unsafe impl Send for WifiEntry {}
|
|||
unsafe impl Sync for WifiEntry {}
|
||||
|
||||
impl WifiEntry {
|
||||
pub fn new(connected: bool, access_point: AccessPoint, wifiBox: &WifiBox) -> Arc<Self> {
|
||||
pub fn new(connected: bool, access_point: AccessPoint, wifi_box: &WifiBox) -> Arc<Self> {
|
||||
let entry: Arc<WifiEntry> = Arc::new(Object::builder().build());
|
||||
let stored_entry = entry.clone();
|
||||
let new_entry = entry.clone();
|
||||
let entryImp = entry.imp();
|
||||
let entry_imp = entry.imp();
|
||||
let strength = WifiStrength::from_u8(access_point.strength);
|
||||
let ssid = access_point.ssid.clone();
|
||||
let name_opt = String::from_utf8(ssid).unwrap_or_else(|_| String::from(""));
|
||||
let name = name_opt.as_str();
|
||||
entryImp.wifiStrength.set(strength);
|
||||
entryImp.resetWifiLabel.get().set_text(name);
|
||||
entryImp.resetWifiEncrypted.set_visible(false);
|
||||
entryImp.connected.set(connected);
|
||||
entry_imp.wifi_strength.set(strength);
|
||||
entry_imp.resetWifiLabel.get().set_text(name);
|
||||
entry_imp.resetWifiEncrypted.set_visible(false);
|
||||
entry_imp.connected.set(connected);
|
||||
// TODO handle encryption thing
|
||||
entryImp
|
||||
entry_imp
|
||||
.resetWifiStrength
|
||||
.get()
|
||||
.set_from_icon_name(match strength {
|
||||
|
@ -51,22 +51,21 @@ impl WifiEntry {
|
|||
WifiStrength::None => Some("network-wireless-signal-none-symbolic"),
|
||||
});
|
||||
if !access_point.stored {
|
||||
entryImp.resetWifiEditButton.set_sensitive(false);
|
||||
entry_imp.resetWifiEditButton.set_sensitive(false);
|
||||
}
|
||||
if connected {
|
||||
entryImp
|
||||
.resetWifiConnected.set_text("Connected");
|
||||
entry_imp.resetWifiConnected.set_text("Connected");
|
||||
}
|
||||
{
|
||||
let mut wifiName = entryImp.wifiName.borrow_mut();
|
||||
*wifiName = String::from(name);
|
||||
let mut wifi_name = entry_imp.wifi_name.borrow_mut();
|
||||
*wifi_name = String::from(name);
|
||||
}
|
||||
entryImp.accessPoint.set(access_point);
|
||||
entry_imp.access_point.set(access_point);
|
||||
|
||||
entry.set_activatable(true);
|
||||
entry.connect_activated(clone!(@weak entryImp => move |_| {
|
||||
let access_point = entryImp.accessPoint.borrow();
|
||||
if *entryImp.connected.borrow() {
|
||||
entry.connect_activated(clone!(@weak entry_imp => move |_| {
|
||||
let access_point = entry_imp.access_point.borrow();
|
||||
if *entry_imp.connected.borrow() {
|
||||
click_disconnect(stored_entry.clone());
|
||||
} else if access_point.stored {
|
||||
click_stored_network(stored_entry.clone());
|
||||
|
@ -74,15 +73,15 @@ impl WifiEntry {
|
|||
click_new_network(new_entry.clone());
|
||||
}
|
||||
}));
|
||||
entry.setupCallbacks(wifiBox);
|
||||
entry.setup_callbacks(wifi_box);
|
||||
entry
|
||||
}
|
||||
|
||||
pub fn setupCallbacks(&self, wifiBox: &WifiBox) {
|
||||
let selfImp = self.imp();
|
||||
selfImp.resetWifiEditButton.connect_clicked(clone!(@ weak selfImp, @ weak wifiBox => move |_| {
|
||||
let _option = getConnectionSettings(selfImp.accessPoint.borrow().associated_connection.clone());
|
||||
wifiBox.resetWifiNavigation.push(&*WifiOptions::new(_option, selfImp.accessPoint.borrow().dbus_path.clone()));
|
||||
pub fn setup_callbacks(&self, wifi_box: &WifiBox) {
|
||||
let self_imp = self.imp();
|
||||
self_imp.resetWifiEditButton.connect_clicked(clone!(@ weak self_imp, @ weak wifi_box => move |_| {
|
||||
let _option = get_connection_settings(self_imp.access_point.borrow().associated_connection.clone());
|
||||
wifi_box.resetWifiNavigation.push(&*WifiOptions::new(_option, self_imp.access_point.borrow().dbus_path.clone()));
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -119,8 +118,8 @@ pub fn click_disconnect(entry: Arc<WifiEntry>) {
|
|||
}
|
||||
|
||||
pub fn click_stored_network(entry: Arc<WifiEntry>) {
|
||||
let entryImp = entry.imp();
|
||||
let access_point = entryImp.accessPoint.borrow().clone();
|
||||
let entry_imp = entry.imp();
|
||||
let access_point = entry_imp.access_point.borrow().clone();
|
||||
let entry_ref = entry.clone();
|
||||
entry.set_activatable(false);
|
||||
gio::spawn_blocking(move || {
|
||||
|
@ -212,18 +211,18 @@ pub fn click_new_network(entry: Arc<WifiEntry>) {
|
|||
// TODO crate spinner animation and block UI
|
||||
};
|
||||
|
||||
let entryImp = entry.imp();
|
||||
let popupImp = entryImp.resetWifiPopup.imp();
|
||||
popupImp
|
||||
let entry_imp = entry.imp();
|
||||
let popup_imp = entry_imp.resetWifiPopup.imp();
|
||||
popup_imp
|
||||
.resetPopupEntry
|
||||
.connect_activate(clone!(@weak entry as origEntry, @weak entryImp => move |entry| {
|
||||
connect_new_network(origEntry, entryImp.accessPoint.clone().take(), entry.text().to_string());
|
||||
.connect_activate(clone!(@weak entry as orig_entry, @weak entry_imp => move |entry| {
|
||||
connect_new_network(orig_entry, entry_imp.access_point.clone().take(), entry.text().to_string());
|
||||
}));
|
||||
popupImp.resetPopupButton.connect_clicked(
|
||||
clone!(@weak entry as origEntry,@weak entryImp, @weak popupImp => move |_| {
|
||||
let entry = entryImp.resetWifiPopup.imp().resetPopupEntry.text().to_string();
|
||||
connect_new_network(origEntry, entryImp.accessPoint.clone().take(), entry);
|
||||
popup_imp.resetPopupButton.connect_clicked(
|
||||
clone!(@weak entry as orig_entry,@weak entry_imp, @weak popup_imp => move |_| {
|
||||
let entry = entry_imp.resetWifiPopup.imp().resetPopupEntry.text().to_string();
|
||||
connect_new_network(orig_entry, entry_imp.access_point.clone().take(), entry);
|
||||
}),
|
||||
);
|
||||
entryImp.resetWifiPopup.popup();
|
||||
entry_imp.resetWifiPopup.popup();
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
use crate::components::base::popup::Popup;
|
||||
use crate::components::wifi::wifiEntry;
|
||||
use crate::components::wifi::wifi_entry;
|
||||
use adw::subclass::preferences_row::PreferencesRowImpl;
|
||||
use adw::subclass::prelude::ActionRowImpl;
|
||||
use adw::ActionRow;
|
||||
|
@ -24,9 +24,9 @@ pub struct WifiEntry {
|
|||
pub resetWifiConnected: TemplateChild<Label>,
|
||||
#[template_child]
|
||||
pub resetWifiPopup: TemplateChild<Popup>,
|
||||
pub wifiName: RefCell<String>,
|
||||
pub wifiStrength: RefCell<WifiStrength>,
|
||||
pub accessPoint: RefCell<AccessPoint>,
|
||||
pub wifi_name: RefCell<String>,
|
||||
pub wifi_strength: RefCell<WifiStrength>,
|
||||
pub access_point: RefCell<AccessPoint>,
|
||||
pub connected: RefCell<bool>,
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ unsafe impl Sync for WifiEntry {}
|
|||
impl ObjectSubclass for WifiEntry {
|
||||
const ABSTRACT: bool = false;
|
||||
const NAME: &'static str = "resetWifiEntry";
|
||||
type Type = wifiEntry::WifiEntry;
|
||||
type Type = wifi_entry::WifiEntry;
|
||||
type ParentType = ActionRow;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
390
src/components/wifi/wifi_options.rs
Normal file
390
src/components/wifi/wifi_options.rs
Normal file
|
@ -0,0 +1,390 @@
|
|||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{ActionRowExt, ComboRowExt, PreferencesGroupExt};
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
use adw::{gio, glib};
|
||||
use dbus::arg::PropMap;
|
||||
use dbus::{Error, Path};
|
||||
use glib::{clone, PropertySet};
|
||||
use gtk::prelude::{ButtonExt, EditableExt, WidgetExt};
|
||||
use IpProtocol::{IPv4, IPv6};
|
||||
use ReSet_Lib::network::connection::{Connection, DNSMethod4, DNSMethod6, Enum, TypeSettings};
|
||||
|
||||
use crate::components::wifi::utils::IpProtocol;
|
||||
use crate::components::wifi::wifi_address_entry::WifiAddressEntry;
|
||||
use crate::components::wifi::wifi_options_impl;
|
||||
use crate::components::wifi::wifi_route_entry::WifiRouteEntry;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct WifiOptions(ObjectSubclass<wifi_options_impl::WifiOptions>)
|
||||
@extends adw::NavigationPage, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
|
||||
}
|
||||
|
||||
unsafe impl Send for WifiOptions {}
|
||||
unsafe impl Sync for WifiOptions {}
|
||||
|
||||
impl WifiOptions {
|
||||
pub fn new(connection: Connection, access_point: Path<'static>) -> Arc<Self> {
|
||||
let wifi_option: Arc<WifiOptions> = Arc::new(Object::builder().build());
|
||||
wifi_option.imp().connection.set(connection);
|
||||
wifi_option.initialize_ui();
|
||||
setup_callbacks(&wifi_option, access_point);
|
||||
wifi_option
|
||||
}
|
||||
|
||||
pub fn initialize_ui(&self) {
|
||||
let self_imp = self.imp();
|
||||
let ip4_address_length;
|
||||
let ip4_route_length;
|
||||
let ip6_address_length;
|
||||
let ip6_route_length;
|
||||
{
|
||||
let conn = self_imp.connection.borrow();
|
||||
ip4_address_length = conn.ipv4.address_data.len();
|
||||
ip4_route_length = conn.ipv4.route_data.len();
|
||||
ip6_address_length = conn.ipv4.address_data.len();
|
||||
ip6_route_length = conn.ipv4.route_data.len();
|
||||
|
||||
// General
|
||||
self_imp
|
||||
.resetWifiAutoConnect
|
||||
.set_active(conn.settings.autoconnect);
|
||||
self_imp
|
||||
.resetWifiMetered
|
||||
.set_active(conn.settings.metered != -1);
|
||||
match &conn.device {
|
||||
TypeSettings::WIFI(wifi) => {
|
||||
self_imp.resetWifiLinkSpeed.set_visible(false);
|
||||
self_imp.resetWifiIP4Addr.set_visible(false);
|
||||
self_imp.resetWifiIP6Addr.set_visible(false);
|
||||
self_imp.resetWifiDNS.set_visible(false);
|
||||
self_imp.resetWifiGateway.set_visible(false);
|
||||
self_imp.resetWifiLastUsed.set_visible(true);
|
||||
self_imp.resetWifiMac.set_subtitle(&wifi.cloned_mac_address);
|
||||
self_imp
|
||||
.resetWifiName
|
||||
.set_subtitle(&String::from_utf8(wifi.ssid.clone()).unwrap_or_default());
|
||||
}
|
||||
TypeSettings::ETHERNET(ethernet) => {
|
||||
self_imp.resetWifiLinkSpeed.set_visible(true);
|
||||
self_imp.resetWifiIP4Addr.set_visible(true);
|
||||
self_imp.resetWifiIP6Addr.set_visible(true);
|
||||
self_imp.resetWifiDNS.set_visible(true);
|
||||
self_imp.resetWifiGateway.set_visible(true);
|
||||
self_imp.resetWifiLastUsed.set_visible(false);
|
||||
self_imp
|
||||
.resetWifiMac
|
||||
.set_subtitle(ðernet.cloned_mac_address);
|
||||
self_imp
|
||||
.resetWifiLinkSpeed
|
||||
.set_subtitle(ðernet.speed.to_string());
|
||||
}
|
||||
TypeSettings::VPN(_vpn) => {}
|
||||
TypeSettings::None => {}
|
||||
};
|
||||
// IPv4
|
||||
self_imp
|
||||
.resetIP4Method
|
||||
.set_selected(conn.ipv4.dns_method.to_i32() as u32);
|
||||
self.set_ip4_visibility(conn.ipv4.dns_method.to_i32() as u32);
|
||||
|
||||
let ipv4_dns: Vec<String> = conn
|
||||
.ipv4
|
||||
.dns
|
||||
.iter()
|
||||
.map(|addr| {
|
||||
addr.iter()
|
||||
.map(|octet| octet.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join(".")
|
||||
})
|
||||
.collect();
|
||||
self_imp.resetIP4DNS.set_text(&ipv4_dns.join(", "));
|
||||
self_imp.resetIP4Gateway.set_text(&conn.ipv4.gateway);
|
||||
// IPv6
|
||||
self_imp
|
||||
.resetIP6Method
|
||||
.set_selected(conn.ipv6.dns_method.to_i32() as u32);
|
||||
self.set_ip6_visibility(conn.ipv6.dns_method.to_i32() as u32);
|
||||
|
||||
let ipv6_dns: Vec<String> = conn
|
||||
.ipv6
|
||||
.dns
|
||||
.iter()
|
||||
.map(|addr| {
|
||||
addr.iter()
|
||||
.map(|octet| octet.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join(":")
|
||||
})
|
||||
.collect();
|
||||
self_imp.resetIP6DNS.set_text(&ipv6_dns.join(", "));
|
||||
self_imp.resetIP6Gateway.set_text(&conn.ipv6.gateway);
|
||||
|
||||
// Security
|
||||
if let TypeSettings::WIFI(wifi) = &conn.device {
|
||||
match wifi.security_settings.key_management.as_str() {
|
||||
"none" => {
|
||||
self_imp.resetWifiSecurityDropdown.set_selected(0);
|
||||
self_imp.resetWifiPassword.set_visible(false);
|
||||
self_imp.resetWifiPassword.set_text("");
|
||||
}
|
||||
"wpa-psk" => {
|
||||
self_imp.resetWifiSecurityDropdown.set_selected(1);
|
||||
self_imp.resetWifiPassword.set_visible(true);
|
||||
self_imp
|
||||
.resetWifiPassword
|
||||
.set_text(&wifi.security_settings.psk);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
// IPv4
|
||||
for i in 0..ip4_address_length {
|
||||
let address = &WifiAddressEntry::new(Some(i), self_imp.connection.clone(), IPv4);
|
||||
self_imp.resetIP4AddressGroup.add(address);
|
||||
}
|
||||
let address = &WifiAddressEntry::new(None, self_imp.connection.clone(), IPv4);
|
||||
self_imp.resetIP4AddressGroup.add(address);
|
||||
|
||||
for i in 0..ip4_route_length {
|
||||
let route = &WifiRouteEntry::new(Some(i), self_imp.connection.clone(), IPv4);
|
||||
self_imp.resetIP4RoutesGroup.add(route)
|
||||
}
|
||||
let route = &WifiRouteEntry::new(None, self_imp.connection.clone(), IPv4);
|
||||
self_imp.resetIP4RoutesGroup.add(route);
|
||||
|
||||
// IPv6
|
||||
for i in 0..ip6_address_length {
|
||||
let address = &WifiAddressEntry::new(Some(i), self_imp.connection.clone(), IPv6);
|
||||
self_imp.resetIP6AddressGroup.add(address);
|
||||
}
|
||||
let address = &WifiAddressEntry::new(None, self_imp.connection.clone(), IPv6);
|
||||
self_imp.resetIP6AddressGroup.add(address);
|
||||
|
||||
for i in 0..ip6_route_length {
|
||||
let route = &WifiRouteEntry::new(Some(i), self_imp.connection.clone(), IPv6);
|
||||
self_imp.resetIP6RoutesGroup.add(route);
|
||||
}
|
||||
let route = &WifiRouteEntry::new(None, self_imp.connection.clone(), IPv6);
|
||||
self_imp.resetIP6RoutesGroup.add(route);
|
||||
// Security
|
||||
}
|
||||
|
||||
pub fn set_ip4_visibility(&self, method: u32) {
|
||||
let self_imp = self.imp();
|
||||
match method {
|
||||
0 => {
|
||||
// auto
|
||||
self_imp.resetIP4AddressGroup.set_visible(false);
|
||||
self_imp.resetIP4RoutesGroup.set_visible(true);
|
||||
self_imp.resetIP4Gateway.set_visible(false);
|
||||
}
|
||||
1 => {
|
||||
// manual
|
||||
self_imp.resetIP4AddressGroup.set_visible(true);
|
||||
self_imp.resetIP4RoutesGroup.set_visible(true);
|
||||
self_imp.resetIP4Gateway.set_visible(true);
|
||||
}
|
||||
_ => {
|
||||
self_imp.resetIP4AddressGroup.set_visible(false);
|
||||
self_imp.resetIP4RoutesGroup.set_visible(false);
|
||||
self_imp.resetIP4Gateway.set_visible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_ip6_visibility(&self, method: u32) {
|
||||
let self_imp = self.imp();
|
||||
match method {
|
||||
0 | 1 => {
|
||||
// auto, dhcp
|
||||
self_imp.resetIP6AddressGroup.set_visible(false);
|
||||
self_imp.resetIP6RoutesGroup.set_visible(true);
|
||||
self_imp.resetIP6Gateway.set_visible(false);
|
||||
}
|
||||
2 => {
|
||||
// manual
|
||||
self_imp.resetIP6AddressGroup.set_visible(true);
|
||||
self_imp.resetIP6RoutesGroup.set_visible(true);
|
||||
self_imp.resetIP6Gateway.set_visible(true);
|
||||
}
|
||||
_ => {
|
||||
self_imp.resetIP6AddressGroup.set_visible(false);
|
||||
self_imp.resetIP6RoutesGroup.set_visible(false);
|
||||
self_imp.resetIP6Gateway.set_visible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn setup_callbacks(wifi_options: &Arc<WifiOptions>, path: Path<'static>) {
|
||||
let imp = wifi_options.imp();
|
||||
|
||||
// General
|
||||
imp.resetWifiAutoConnect
|
||||
.connect_active_notify(clone!(@weak imp => move |x| {
|
||||
imp.connection.borrow_mut().settings.autoconnect = x.is_active();
|
||||
}));
|
||||
imp.resetWifiMetered
|
||||
.connect_active_notify(clone!(@weak imp => move |x| {
|
||||
imp.connection.borrow_mut().settings.metered = if x.is_active() { 1 } else { 2 };
|
||||
}));
|
||||
imp.wifiOptionsApplyButton
|
||||
.connect_clicked(clone!(@weak imp => move |_| {
|
||||
let prop = imp.connection.borrow().convert_to_propmap();
|
||||
set_connection_settings(path.clone(), prop);
|
||||
}));
|
||||
// IPv4
|
||||
let wifi_options_ip4 = wifi_options.clone();
|
||||
imp.resetIP4Method
|
||||
.connect_selected_notify(clone!(@weak imp => move |dropdown| {
|
||||
let selected = dropdown.selected();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
conn.ipv4.dns_method = DNSMethod4::from_i32(selected as i32);
|
||||
wifi_options_ip4.set_ip4_visibility(selected);
|
||||
}));
|
||||
|
||||
imp.resetIP4DNS
|
||||
.connect_changed(clone!(@weak imp => move |entry| {
|
||||
let dns_input = entry.text();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
conn.ipv4.dns.clear();
|
||||
if dns_input.is_empty() {
|
||||
imp.resetIP4DNS.remove_css_class("error");
|
||||
return;
|
||||
}
|
||||
for dns_entry in dns_input.as_str().split(',').map(|s| s.trim()) {
|
||||
if let Ok(addr) = Ipv4Addr::from_str(dns_entry) {
|
||||
imp.resetIP4DNS.remove_css_class("error");
|
||||
conn.ipv4.dns.push(addr.octets().to_vec());
|
||||
} else {
|
||||
imp.resetIP4DNS.add_css_class("error");
|
||||
}
|
||||
}
|
||||
}));
|
||||
imp.resetIP4AddressAddButton
|
||||
.connect_clicked(clone!(@weak imp => move |_| {
|
||||
let address = &WifiAddressEntry::new(None, imp.connection.clone(), IpProtocol::IPv4);
|
||||
imp.resetIP4AddressGroup.add(address);
|
||||
}));
|
||||
|
||||
imp.resetIP4Gateway
|
||||
.connect_changed(clone!(@weak imp => move |entry| {
|
||||
let gateway_input = entry.text();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
conn.ipv4.gateway.clear();
|
||||
if gateway_input.is_empty() {
|
||||
imp.resetIP4Gateway.remove_css_class("error");
|
||||
return;
|
||||
}
|
||||
if Ipv4Addr::from_str(gateway_input.as_str()).is_ok() {
|
||||
imp.resetIP4Gateway.remove_css_class("error");
|
||||
conn.ipv4.gateway = gateway_input.to_string();
|
||||
} else {
|
||||
imp.resetIP4Gateway.add_css_class("error");
|
||||
}
|
||||
}));
|
||||
// IPv6
|
||||
let wifi_options_ip6 = wifi_options.clone();
|
||||
imp.resetIP6Method
|
||||
.connect_selected_notify(clone!(@weak imp => move |dropdown| {
|
||||
let selected = dropdown.selected();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
conn.ipv6.dns_method = DNSMethod6::from_i32(selected as i32);
|
||||
wifi_options_ip6.set_ip6_visibility(selected);
|
||||
}));
|
||||
|
||||
imp.resetIP6DNS
|
||||
.connect_changed(clone!(@weak imp => move |entry| {
|
||||
let dns_input = entry.text();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
conn.ipv6.dns.clear();
|
||||
if dns_input.is_empty() {
|
||||
imp.resetIP6DNS.remove_css_class("error");
|
||||
return;
|
||||
}
|
||||
for dns_entry in dns_input.as_str().split(',').map(|s| s.trim()) {
|
||||
if let Ok(addr) = Ipv6Addr::from_str(dns_entry) {
|
||||
imp.resetIP6DNS.remove_css_class("error");
|
||||
conn.ipv6.dns.push(addr.octets().to_vec());
|
||||
} else {
|
||||
imp.resetIP6DNS.add_css_class("error");
|
||||
}
|
||||
}
|
||||
}));
|
||||
imp.resetIP6AddressAddButton
|
||||
.connect_clicked(clone!(@weak imp => move |_| {
|
||||
let address = &WifiAddressEntry::new(None, imp.connection.clone(), IpProtocol::IPv4);
|
||||
imp.resetIP6AddressGroup.add(address);
|
||||
}));
|
||||
|
||||
imp.resetIP6Gateway
|
||||
.connect_changed(clone!(@weak imp => move |entry| {
|
||||
let gateway_input = entry.text();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
conn.ipv6.gateway.clear();
|
||||
if gateway_input.is_empty() {
|
||||
imp.resetIP6Gateway.remove_css_class("error");
|
||||
return;
|
||||
}
|
||||
if Ipv6Addr::from_str(gateway_input.as_str()).is_ok() {
|
||||
imp.resetIP6Gateway.remove_css_class("error");
|
||||
conn.ipv6.gateway = gateway_input.to_string();
|
||||
} else {
|
||||
imp.resetIP6Gateway.add_css_class("error");
|
||||
}
|
||||
}));
|
||||
|
||||
// Security
|
||||
imp.resetWifiSecurityDropdown
|
||||
.connect_selected_notify(clone!(@weak imp => move |dropdown| {
|
||||
let selected = dropdown.selected();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
|
||||
match (selected, &mut conn.device) {
|
||||
(0 , TypeSettings::WIFI(wifi)) => { // None
|
||||
imp.resetWifiPassword.set_visible(false);
|
||||
wifi.security_settings.key_management = String::from("none");
|
||||
wifi.security_settings.authentication_algorithm = String::from("open");
|
||||
},
|
||||
(1 , TypeSettings::WIFI(wifi)) => { // WPA/WPA2 Personal
|
||||
imp.resetWifiPassword.set_visible(true);
|
||||
wifi.security_settings.key_management = String::from("wpa-psk");
|
||||
wifi.security_settings.authentication_algorithm = String::from("");
|
||||
},
|
||||
(_, _) => {}
|
||||
}
|
||||
}));
|
||||
|
||||
imp.resetWifiPassword
|
||||
.connect_changed(clone!(@weak imp => move |entry| {
|
||||
let password_input = entry.text();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
if let TypeSettings::WIFI(wifi) = &mut conn.device {
|
||||
wifi.security_settings.psk = password_input.to_string();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
fn set_connection_settings(path: Path<'static>, prop: PropMap) {
|
||||
gio::spawn_blocking(move || {
|
||||
let conn = dbus::blocking::Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSetDaemon",
|
||||
"/org/Xetibo/ReSetDaemon",
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let _: Result<(bool,), Error> = proxy.method_call(
|
||||
"org.Xetibo.ReSetWireless",
|
||||
"SetConnectionSettings",
|
||||
(path, prop),
|
||||
);
|
||||
});
|
||||
}
|
|
@ -1,12 +1,13 @@
|
|||
use crate::components::wifi::wifiOptions;
|
||||
use crate::components::wifi::wifi_options;
|
||||
use adw::subclass::prelude::NavigationPageImpl;
|
||||
use adw::{ActionRow, ComboRow, EntryRow, NavigationPage, PasswordEntryRow, PreferencesGroup, SwitchRow};
|
||||
use adw::{
|
||||
ActionRow, ComboRow, EntryRow, NavigationPage, PasswordEntryRow, PreferencesGroup, SwitchRow,
|
||||
};
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, Button, CompositeTemplate};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use ReSet_Lib::network::connection::Connection;
|
||||
use ReSet_Lib::network::network::AccessPoint;
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Default, CompositeTemplate)]
|
||||
|
@ -78,7 +79,7 @@ pub struct WifiOptions {
|
|||
impl ObjectSubclass for WifiOptions {
|
||||
const ABSTRACT: bool = false;
|
||||
const NAME: &'static str = "resetWifiOptions";
|
||||
type Type = wifiOptions::WifiOptions;
|
||||
type Type = wifi_options::WifiOptions;
|
||||
type ParentType = NavigationPage;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
242
src/components/wifi/wifi_route_entry.rs
Normal file
242
src/components/wifi/wifi_route_entry.rs
Normal file
|
@ -0,0 +1,242 @@
|
|||
use crate::components::wifi::utils::IpProtocol;
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{ExpanderRowExt, PreferencesRowExt};
|
||||
use glib::clone;
|
||||
use glib::subclass::prelude::ObjectSubclassIsExt;
|
||||
use gtk::prelude::{EditableExt, WidgetExt};
|
||||
use std::cell::RefCell;
|
||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
use std::rc::Rc;
|
||||
use std::str::FromStr;
|
||||
use ReSet_Lib::network::connection::{Address, Connection};
|
||||
|
||||
use crate::components::wifi::wifi_route_entry_impl;
|
||||
use crate::components::wifi::wifi_route_entry_impl::WifiRouteEntryImpl;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct WifiRouteEntry(ObjectSubclass<wifi_route_entry_impl::WifiRouteEntryImpl>)
|
||||
@extends gtk::Box, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
|
||||
}
|
||||
|
||||
impl WifiRouteEntry {
|
||||
pub fn new(
|
||||
address: Option<usize>,
|
||||
conn: Rc<RefCell<Connection>>,
|
||||
protocol: IpProtocol,
|
||||
) -> Self {
|
||||
let entry: WifiRouteEntry = Object::builder().build();
|
||||
let entry_imp = entry.imp();
|
||||
|
||||
if let Some(address) = address {
|
||||
let conn = conn.borrow();
|
||||
let address = unsafe { conn.ipv4.route_data.get_unchecked(address) };
|
||||
|
||||
entry_imp.resetRouteAddress.set_text(&address.address);
|
||||
entry_imp
|
||||
.resetRoutePrefix
|
||||
.set_text(&address.prefix_length.to_string());
|
||||
if let Some(gateway) = &address.gateway {
|
||||
entry_imp.resetRouteGateway.set_text(gateway);
|
||||
}
|
||||
if let Some(metric) = address.metric {
|
||||
entry_imp.resetRouteMetric.set_text(&metric.to_string());
|
||||
}
|
||||
entry_imp
|
||||
.resetRouteRow
|
||||
.set_title(&format!("{}/{}", &*address.address, address.prefix_length));
|
||||
}
|
||||
entry_imp.protocol.set(protocol);
|
||||
entry.setup_callbacks(conn);
|
||||
entry
|
||||
}
|
||||
|
||||
fn setup_callbacks(&self, connection: Rc<RefCell<Connection>>) {
|
||||
let self_imp = self.imp();
|
||||
|
||||
let conn = connection.clone();
|
||||
self_imp.resetRouteAddress.connect_changed(clone!(@weak self_imp => move |entry| {
|
||||
let address_input = entry.text();
|
||||
let mut conn = conn.borrow_mut();
|
||||
|
||||
if address_input.is_empty() {
|
||||
self_imp.resetRouteAddress.remove_css_class("error");
|
||||
self_imp.resetRouteRow.set_title("Add new address");
|
||||
return;
|
||||
}
|
||||
let result = match self_imp.protocol.get() {
|
||||
IpProtocol::IPv4 => Ipv4Addr::from_str(address_input.as_str()).map(IpAddr::V4),
|
||||
IpProtocol::IPv6 => Ipv6Addr::from_str(address_input.as_str()).map(IpAddr::V6),
|
||||
};
|
||||
match result {
|
||||
Ok(ip_addr) => {
|
||||
self_imp.resetRouteAddress.remove_css_class("error");
|
||||
let address_data = match self_imp.protocol.get() {
|
||||
IpProtocol::IPv4 => &mut conn.ipv4.route_data,
|
||||
IpProtocol::IPv6 => &mut conn.ipv6.route_data,
|
||||
};
|
||||
address_data.push(Address::new(ip_addr.to_string(), self_imp.prefix.get().1 as u32,self_imp.gateway.borrow().clone() ,self_imp.metric.get()));
|
||||
*self_imp.address.borrow_mut() = (true, ip_addr.to_string());
|
||||
}
|
||||
Err(_) => {
|
||||
self_imp.resetRouteAddress.add_css_class("error");
|
||||
*self_imp.address.borrow_mut() = (false, String::default());
|
||||
}
|
||||
}
|
||||
set_row_title(&self_imp);
|
||||
}));
|
||||
|
||||
let conn = connection.clone();
|
||||
self_imp.resetRoutePrefix.connect_changed(clone!(@weak self_imp => move |entry| {
|
||||
let prefix_input = entry.text();
|
||||
let prefix = prefix_input.parse::<u8>();
|
||||
let mut conn = conn.borrow_mut();
|
||||
|
||||
let handle_error = || {
|
||||
if self_imp.resetRoutePrefix.text().is_empty() {
|
||||
self_imp.resetRoutePrefix.remove_css_class("error");
|
||||
} else {
|
||||
self_imp.resetRoutePrefix.add_css_class("error");
|
||||
}
|
||||
self_imp.prefix.set((false, 0));
|
||||
set_row_title(&self_imp);
|
||||
};
|
||||
|
||||
if prefix_input.is_empty() || prefix.is_err() {
|
||||
handle_error();
|
||||
return;
|
||||
}
|
||||
|
||||
let prefix = prefix.unwrap();
|
||||
match self_imp.protocol.get() {
|
||||
IpProtocol::IPv4 if prefix <= 32 => {
|
||||
self_imp.prefix.set((true, prefix as u32));
|
||||
self_imp.resetRoutePrefix.remove_css_class("error");
|
||||
if let Ok(address2) = Ipv4Addr::from_str(self_imp.resetRouteAddress.text().as_str()) {
|
||||
if let Some(addr) = conn.ipv4.route_data.iter_mut()
|
||||
.find(|conn_addr| *conn_addr.address == address2.to_string()) {
|
||||
addr.prefix_length = prefix as u32;
|
||||
}
|
||||
}
|
||||
}
|
||||
IpProtocol::IPv6 if prefix <= 128 => {
|
||||
self_imp.prefix.set((true, prefix as u32));
|
||||
self_imp.resetRoutePrefix.remove_css_class("error");
|
||||
if let Ok(address2) = Ipv6Addr::from_str(self_imp.resetRouteAddress.text().as_str()) {
|
||||
if let Some(addr) = conn.ipv6.route_data.iter_mut()
|
||||
.find(|conn_addr| *conn_addr.address == address2.to_string()) {
|
||||
addr.prefix_length = prefix as u32;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => handle_error()
|
||||
}
|
||||
set_row_title(&self_imp);
|
||||
}));
|
||||
|
||||
let conn = connection.clone();
|
||||
self_imp
|
||||
.resetRouteGateway
|
||||
.connect_changed(clone!(@weak self_imp => move |entry| {
|
||||
let gateway_input = entry.text();
|
||||
let mut conn = conn.borrow_mut();
|
||||
|
||||
if gateway_input.is_empty() {
|
||||
self_imp.resetRouteGateway.remove_css_class("error");
|
||||
*self_imp.gateway.borrow_mut() = None;
|
||||
set_row_subtitle(&self_imp);
|
||||
return;
|
||||
}
|
||||
let result = match self_imp.protocol.get() {
|
||||
IpProtocol::IPv4 => Ipv4Addr::from_str(gateway_input.as_str()).map(IpAddr::V4),
|
||||
IpProtocol::IPv6 => Ipv6Addr::from_str(gateway_input.as_str()).map(IpAddr::V6),
|
||||
};
|
||||
match result {
|
||||
Ok(ip_addr) => {
|
||||
self_imp.resetRouteGateway.remove_css_class("error");
|
||||
let address_data = match self_imp.protocol.get() {
|
||||
IpProtocol::IPv4 => &mut conn.ipv4.route_data,
|
||||
IpProtocol::IPv6 => &mut conn.ipv6.route_data,
|
||||
};
|
||||
if let Some(address) = address_data.iter_mut()
|
||||
.find(|conn_addr| *conn_addr.address == self_imp.resetRouteAddress.text()) {
|
||||
address.gateway = Some(ip_addr.to_string());
|
||||
}
|
||||
*self_imp.gateway.borrow_mut() = Some(ip_addr.to_string());
|
||||
}
|
||||
Err(_) => {
|
||||
self_imp.resetRouteGateway.add_css_class("error");
|
||||
*self_imp.gateway.borrow_mut() = None;
|
||||
}
|
||||
}
|
||||
set_row_subtitle(&self_imp);
|
||||
}));
|
||||
|
||||
let conn = connection.clone();
|
||||
self_imp
|
||||
.resetRouteMetric
|
||||
.connect_changed(clone!(@weak self_imp => move |entry| {
|
||||
let metric_input = entry.text();
|
||||
let mut conn = conn.borrow_mut();
|
||||
|
||||
if metric_input.is_empty() {
|
||||
self_imp.resetRouteMetric.remove_css_class("error");
|
||||
self_imp.metric.set(None);
|
||||
set_row_subtitle(&self_imp);
|
||||
return;
|
||||
}
|
||||
let result = metric_input.parse::<u32>();
|
||||
match result {
|
||||
Ok(metric) => {
|
||||
self_imp.resetRouteMetric.remove_css_class("error");
|
||||
let address_data = match self_imp.protocol.get() {
|
||||
IpProtocol::IPv4 => &mut conn.ipv4.route_data,
|
||||
IpProtocol::IPv6 => &mut conn.ipv6.route_data,
|
||||
};
|
||||
if let Some(address) = address_data.iter_mut()
|
||||
.find(|conn_addr| *conn_addr.address == self_imp.resetRouteAddress.text()) {
|
||||
address.metric = Some(metric);
|
||||
}
|
||||
self_imp.metric.set(Some(metric));
|
||||
}
|
||||
Err(_) => {
|
||||
self_imp.resetRouteMetric.add_css_class("error");
|
||||
self_imp.metric.set(None);
|
||||
}
|
||||
}
|
||||
set_row_subtitle(&self_imp);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
fn set_row_title(self_imp: &WifiRouteEntryImpl) {
|
||||
if self_imp.resetRouteAddress.text().is_empty() {
|
||||
return;
|
||||
}
|
||||
let address = self_imp.address.borrow();
|
||||
let prefix = self_imp.prefix.get();
|
||||
let title = match (address.0, prefix.0) {
|
||||
(true, true) => {
|
||||
format!("{}/{}", address.1, prefix.1)
|
||||
}
|
||||
(true, false) => "Prefix wrong".to_string(),
|
||||
(false, true) => "Address wrong".to_string(),
|
||||
(false, false) => "Address and Prefix wrong".to_string(),
|
||||
};
|
||||
self_imp.resetRouteRow.set_title(&title);
|
||||
}
|
||||
|
||||
fn set_row_subtitle(self_imp: &WifiRouteEntryImpl) {
|
||||
let gateway = self_imp.gateway.borrow().clone();
|
||||
let metric = self_imp.metric.get();
|
||||
let title = match (gateway, metric) {
|
||||
(Some(gateway), Some(metric)) => {
|
||||
format!("{}, {}", gateway, metric)
|
||||
}
|
||||
(Some(gateway), None) => gateway,
|
||||
(None, Some(metric)) => metric.to_string(),
|
||||
(None, None) => String::default(),
|
||||
};
|
||||
self_imp.resetRouteRow.set_subtitle(&title);
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
use crate::components::wifi::utils::IpProtocol;
|
||||
use crate::components::wifi::wifiRouteEntry;
|
||||
use crate::components::wifi::wifi_route_entry;
|
||||
use adw::{EntryRow, ExpanderRow};
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, Button, CompositeTemplate};
|
||||
|
@ -32,7 +32,7 @@ pub struct WifiRouteEntryImpl {
|
|||
impl ObjectSubclass for WifiRouteEntryImpl {
|
||||
const ABSTRACT: bool = false;
|
||||
const NAME: &'static str = "resetWifiRouteEntry";
|
||||
type Type = wifiRouteEntry::WifiRouteEntry;
|
||||
type Type = wifi_route_entry::WifiRouteEntry;
|
||||
type ParentType = gtk::Box;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
Loading…
Add table
Add a link
Reference in a new issue