Improve UI

This commit is contained in:
takotori 2023-11-26 11:25:31 +01:00
parent 02e63f5984
commit c6efced326
28 changed files with 609 additions and 1035 deletions

View file

@ -10,4 +10,5 @@ pub mod wifiOptionsImpl;
pub mod wifiAddressEntry;
pub mod wifiAddressEntryImpl;
pub mod wifiRouteEntry;
pub mod wifiRouteEntryImpl;
pub mod wifiRouteEntryImpl;
pub mod utils;

View file

@ -10,6 +10,7 @@ use glib::subclass::types::ObjectSubclassIsExt;
use glib::{clone, PropertySet};
use gtk::gio;
use gtk::prelude::ListBoxRowExt;
use crate::components::wifi::wifiBoxImpl::WifiBox;
glib::wrapper! {
pub struct SavedWifiEntry(ObjectSubclass<savedWifiEntryImpl::SavedWifiEntry>)
@ -18,11 +19,17 @@ glib::wrapper! {
}
impl SavedWifiEntry {
pub fn new(name: &String, path: Path<'static>) -> Self {
pub fn new(name: &String, path: Path<'static>, wifiBox: &WifiBox) -> Self {
let entry: SavedWifiEntry = Object::builder().build();
entry.set_activatable(false);
let entryImp = entry.imp();
// TODO handle edit
entryImp.resetEditSavedWifiButton.connect_clicked(clone!(@ weak entryImp, @ weak wifiBox => 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(

View file

@ -6,6 +6,7 @@ use adw::subclass::prelude::ActionRowImpl;
use dbus::Path;
use gtk::subclass::prelude::*;
use gtk::{glib, Button, CompositeTemplate, Label};
use ReSet_Lib::network::network::AccessPoint;
use super::savedWifiEntry;
@ -20,6 +21,7 @@ pub struct SavedWifiEntry {
#[template_child]
pub resetSavedWifiLabel: TemplateChild<Label>,
pub resetConnectionPath: RefCell<Path<'static>>,
pub accessPoint: RefCell<AccessPoint>,
}
unsafe impl Send for SavedWifiEntry {}

View file

@ -0,0 +1,29 @@
use std::collections::HashMap;
use std::time::Duration;
use dbus::arg::{RefArg};
use dbus::blocking::Connection;
use dbus::Error;
use dbus::Path;
use ReSet_Lib::network::connection::Connection as ResetConnection;
pub fn getConnectionSettings(path: Path<'static>) -> ResetConnection {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<
(HashMap<String, HashMap<String, dbus::arg::Variant<Box<dyn RefArg>>>>,),
Error,
> = proxy.method_call("org.xetibo.ReSet", "GetConnectionSettings", (path,));
if res.is_err() {
ResetConnection::default();
}
let (res,) = res.unwrap();
let res = ResetConnection::convert_from_propmap(res);
if res.is_err() {
ResetConnection::default();
}
res.unwrap()
}

View file

@ -1,5 +1,3 @@
use std::collections::HashMap;
use std::sync::atomic::Ordering;
use std::sync::Arc;
@ -31,7 +29,6 @@ use crate::components::wifi::wifiEntry::WifiEntry;
use super::savedWifiEntry::SavedWifiEntry;
use ReSet_Lib::network::connection::Connection as ResetConnection;
glib::wrapper! {
pub struct WifiBox(ObjectSubclass<wifiBoxImpl::WifiBox>)
@ -57,9 +54,8 @@ impl WifiBox {
.resetSavedNetworks
.set_action_target_value(Some(&Variant::from("saved")));
selfImp
.resetAvailableNetworks
.set_action_name(Some("navigation.pop"));
selfImp.resetAvailableNetworks.set_activatable(true);
selfImp.resetAvailableNetworks.set_action_name(Some("navigation.pop"));
}
}
@ -103,7 +99,7 @@ pub fn show_stored_connections(wifiBox: Arc<WifiBox>) {
// TODO include button for settings
let name =
&String::from_utf8(connection.1).unwrap_or_else(|_| String::from(""));
let entry = SavedWifiEntry::new(name, connection.0);
let entry = SavedWifiEntry::new(name, connection.0, selfImp);
selfImp.resetStoredWifiList.add(&entry);
}
});
@ -154,28 +150,6 @@ pub fn get_stored_connections() -> Vec<(Path<'static>, Vec<u8>)> {
connections
}
pub fn getConnectionSettings(path: Path<'static>) -> ResetConnection {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<
(HashMap<String, HashMap<String, dbus::arg::Variant<Box<dyn RefArg>>>>,),
Error,
> = proxy.method_call("org.xetibo.ReSet", "GetConnectionSettings", (path,));
if res.is_err() {
ResetConnection::default();
}
let (res,) = res.unwrap();
let res = ResetConnection::convert_from_propmap(res);
if res.is_err() {
ResetConnection::default();
}
res.unwrap()
}
pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
gio::spawn_blocking(move || {
if listeners.network_listener.load(Ordering::SeqCst) {

View file

@ -29,7 +29,7 @@ pub struct WifiBox {
#[template_child]
pub resetStoredWifiList: TemplateChild<PreferencesGroup>,
#[template_child]
pub resetAvailableNetworks: TemplateChild<ListEntry>,
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>>>,

View file

@ -12,8 +12,8 @@ use glib::clone;
use gtk::gio;
use gtk::prelude::{ListBoxRowExt, WidgetExt};
use ReSet_Lib::network::network::{AccessPoint, WifiStrength};
use crate::components::wifi::utils::getConnectionSettings;
use crate::components::wifi::wifiBox::getConnectionSettings;
use crate::components::wifi::wifiBoxImpl::WifiBox;
use crate::components::wifi::wifiEntryImpl;
use crate::components::wifi::wifiOptions::WifiOptions;