Merge branch 'dashie' into ina

This commit is contained in:
Dashie 2023-11-12 12:57:08 +01:00 committed by GitHub
commit 831baee601
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 444 additions and 101 deletions

View file

@ -1,17 +1,17 @@
use adw::glib;
use adw::glib::{IsA, Object};
use gtk::Widget;
use adw::glib::Object;
use gtk::{gdk, Editable, Popover};
use super::popupImpl;
glib::wrapper! {
pub struct Popup(ObjectSubclass<popupImpl::Popup>)
@extends adw::Window, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
@extends Popover, gtk::Widget,
@implements Editable,gdk::Popup, gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
}
impl Popup {
pub fn new(child: &impl IsA<Widget>) -> Self {
pub fn new() -> Self {
let popup: Popup = Object::builder().build();
// popup.set_child(child);
popup

View file

@ -1,19 +1,41 @@
use std::cell::RefCell;
use std::sync::Arc;
use adw::subclass::prelude::{ActionRowImpl, PreferencesRowImpl};
use adw::subclass::window::AdwWindowImpl;
use gtk::gdk_pixbuf::subclass::prelude::{
PixbufAnimationImpl, PixbufAnimationIterImpl, PixbufLoaderImpl,
};
use gtk::prelude::PopupExt;
use gtk::subclass::prelude::*;
use gtk::{glib, CompositeTemplate};
use gtk::{
gdk, glib, Button, CompositeTemplate, Entry, EntryBuffer, Label, PasswordEntry,
PasswordEntryBuffer, Popover,
};
use super::popup;
#[allow(non_snake_case)]
#[derive(Default, CompositeTemplate)]
#[template(resource = "/org/Xetibo/ReSet/resetPopup.ui")]
pub struct Popup {}
pub struct Popup {
#[template_child]
pub resetPopupLabel: TemplateChild<Label>,
#[template_child]
pub resetPopupEntry: TemplateChild<PasswordEntry>,
#[template_child]
pub resetPopupButton: TemplateChild<Button>,
pub resetPopupText: Arc<RefCell<PasswordEntryBuffer>>,
}
unsafe impl Send for Popup {}
unsafe impl Sync for Popup {}
#[glib::object_subclass]
impl ObjectSubclass for Popup {
const NAME: &'static str = "resetPopup";
type Type = popup::Popup;
type ParentType = adw::Window;
type ParentType = Popover;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
@ -30,12 +52,12 @@ impl ObjectImpl for Popup {
}
}
impl BoxImpl for Popup {}
impl WidgetImpl for Popup {}
impl AdwWindowImpl for Popup {}
impl WindowImpl for Popup {}
impl PopoverImpl for Popup {}
impl ApplicationWindowImpl for Popup {}
impl EditableImpl for Popup {}

View file

@ -1,5 +1,7 @@
#![allow(non_snake_case)]
pub mod savedWifiEntry;
pub mod wifiBox;
pub mod wifiBoxImpl;
pub mod wifiEntry;
pub mod wifiEntryImpl;
pub mod wifiEntryImpl;
pub mod savedWifiEntryImpl;

View file

@ -0,0 +1,46 @@
use std::sync::Arc;
use std::time::Duration;
use crate::components::wifi::savedWifiEntryImpl;
use adw::glib;
use adw::glib::Object;
use adw::prelude::{ButtonExt, WidgetExt};
use dbus::{Error, Path};
use dbus::blocking::Connection;
use glib::{clone, PropertySet};
use glib::subclass::types::ObjectSubclassIsExt;
glib::wrapper! {
pub struct SavedWifiEntry(ObjectSubclass<savedWifiEntryImpl::SavedWifiEntry>)
@extends gtk::Box, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget;
}
impl SavedWifiEntry {
pub fn new(name: &String, path: Path<'static>) -> Self {
let entry: SavedWifiEntry = Object::builder().build();
let entryImp = entry.imp();
// TODO handle edit
entryImp.resetSavedWifiLabel.set_text(name);
entryImp.resetConnectionPath.set(path);
entryImp.resetDeleteSavedWifiButton.connect_clicked(clone!(@weak entry as entry => move |_| {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> = proxy.method_call("org.xetibo.ReSet", "DeleteConnection", (entry.imp().resetConnectionPath.take(),));
if res.is_err() || res.unwrap() == (false,) {
// TODO handle error -> inform user
println!("no worky");
return;
}
println!("worked, should be ded");
let parent = entry.parent().unwrap();
parent.set_visible(false);
parent.unparent();
}));
entry
}
}

View file

@ -0,0 +1,52 @@
use std::cell::RefCell;
use dbus::Path;
use gtk::subclass::prelude::*;
use gtk::{glib, Button, CompositeTemplate, Label};
use super::savedWifiEntry;
#[allow(non_snake_case)]
#[derive(Default, CompositeTemplate)]
#[template(resource = "/org/Xetibo/ReSet/resetSavedWifiEntry.ui")]
pub struct SavedWifiEntry {
#[template_child]
pub resetDeleteSavedWifiButton: TemplateChild<Button>,
#[template_child]
pub resetEditSavedWifiButton: TemplateChild<Button>,
#[template_child]
pub resetSavedWifiLabel: TemplateChild<Label>,
pub resetConnectionPath: RefCell<Path<'static>>,
}
unsafe impl Send for SavedWifiEntry {}
unsafe impl Sync for SavedWifiEntry {}
#[glib::object_subclass]
impl ObjectSubclass for SavedWifiEntry {
const NAME: &'static str = "resetSavedWifiEntry";
type Type = savedWifiEntry::SavedWifiEntry;
type ParentType = gtk::Box;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for SavedWifiEntry {
fn constructed(&self) {
self.parent_constructed();
}
}
impl BoxImpl for SavedWifiEntry {}
impl WidgetImpl for SavedWifiEntry {}
impl WindowImpl for SavedWifiEntry {}
impl ApplicationWindowImpl for SavedWifiEntry {}

View file

@ -6,19 +6,26 @@ use std::time::Duration;
use crate::components::base::listEntry::ListEntry;
use adw::glib;
use adw::glib::Object;
use adw::prelude::{BoxExt, ButtonExt, ListBoxRowExt};
use adw::subclass::prelude::ObjectSubclassIsExt;
use dbus::blocking::Connection;
use dbus::Error;
use dbus::Path;
use gtk::glib::Variant;
use gtk::prelude::ActionableExt;
use ReSet_Lib::network::network::AccessPoint;
use ReSet_Lib::signals::{AccessPointAdded, AccessPointRemoved};
use gtk::{Button, Label, Orientation};
use ReSet_Lib::network::network::{AccessPoint, WifiStrength};
use ReSet_Lib::signals::{
AccessPointAdded, AccessPointRemoved, BluetoothDeviceAdded, BluetoothDeviceRemoved,
};
use ReSet_Lib::utils::Events;
use crate::components::wifi::wifiBoxImpl;
use crate::components::wifi::wifiEntry::WifiEntry;
use super::savedWifiEntry::SavedWifiEntry;
glib::wrapper! {
pub struct WifiBox(ObjectSubclass<wifiBoxImpl::WifiBox>)
@extends gtk::Box, gtk::Widget,
@ -40,18 +47,18 @@ impl WifiBox {
selfImp.resetWifiSwitchRow.set_action_target_value(Some(&Variant::from("saved")))
}
pub fn donotdisturb() {
thread::spawn(|| {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
Duration::from_millis(1000),
);
let _: Result<(), Error> =
proxy.method_call("org.freedesktop.Notifications", "DoNotDisturb", ());
});
}
// pub fn donotdisturb() {
// thread::spawn(|| {
// let conn = Connection::new_session().unwrap();
// let proxy = conn.with_proxy(
// "org.freedesktop.Notifications",
// "/org/freedesktop/Notifications",
// Duration::from_millis(1000),
// );
// let _: Result<(), Error> =
// proxy.method_call("org.freedesktop.Notifications", "DoNotDisturb", ());
// });
// }
}
pub fn scanForWifi(wifiBox: Arc<WifiBox>) {
@ -59,7 +66,7 @@ pub fn scanForWifi(wifiBox: Arc<WifiBox>) {
let wifiEntries = wifiBox.imp().wifiEntries.clone();
glib::spawn_future_local(async move {
let accessPoints = wat().await;
let accessPoints = get_access_points().await;
let wifiEntries = wifiEntries.clone();
{
let mut wifiEntries = wifiEntries.lock().unwrap();
@ -103,7 +110,37 @@ pub fn scanForWifi(wifiBox: Arc<WifiBox>) {
}
});
}
pub async fn wat() -> Vec<AccessPoint> {
pub fn show_stored_connections(wifiBox: Arc<WifiBox>) {
let wifibox_ref = wifiBox.clone();
let wifiEntries = wifiBox.imp().savedWifiEntries.clone();
glib::spawn_future_local(async move {
let connections = get_stored_connections().await;
let wifiEntries = wifiEntries.clone();
{
let mut wifiEntries = wifiEntries.lock().unwrap();
for connection in connections {
// TODO include button for settings
let name = &String::from_utf8(connection.1).unwrap_or_else(|_| String::from(""));
let entry = ListEntry::new(&SavedWifiEntry::new(name, connection.0));
entry.set_activatable(false);
wifiEntries.push(entry);
}
}
glib::MainContext::default().spawn_local(async move {
glib::idle_add_once(move || {
let wifiEntries = wifiEntries.lock().unwrap();
let selfImp = wifibox_ref.imp();
for wifiEntry in wifiEntries.iter() {
selfImp.resetStoredWifiList.append(wifiEntry);
}
});
});
});
}
pub async fn get_access_points() -> Vec<AccessPoint> {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
@ -118,3 +155,21 @@ pub async fn wat() -> Vec<AccessPoint> {
let (accessPoints,) = res.unwrap();
accessPoints
}
pub async fn get_stored_connections() -> Vec<(Path<'static>, Vec<u8>)> {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<(Vec<(Path<'static>, Vec<u8>)>,), Error> =
proxy.method_call("org.xetibo.ReSet", "ListStoredConnections", ());
if res.is_err() {
println!("we got error...");
return Vec::new();
}
let (connections,) = res.unwrap();
dbg!(connections.clone());
connections
}

View file

@ -26,7 +26,10 @@ pub struct WifiBox {
pub resetWifiList: TemplateChild<ListBox>,
#[template_child]
pub resetWifiAdvanced: TemplateChild<Button>,
#[template_child]
pub resetStoredWifiList: TemplateChild<ListBox>,
pub wifiEntries: Arc<Mutex<Vec<ListEntry>>>,
pub savedWifiEntries: Arc<Mutex<Vec<ListEntry>>>,
}
unsafe impl Send for WifiBox {}

View file

@ -1,12 +1,15 @@
use crate::components::base::popup::{self, Popup};
use crate::components::wifi::wifiEntryImpl;
use adw::glib;
use adw::glib::{Object, PropertySet};
use adw::prelude::{ButtonExt, EditableExt, EntryExt, PopoverExt};
use adw::subclass::prelude::ObjectSubclassIsExt;
use dbus::blocking::Connection;
use dbus::Error;
use glib::clone;
use glib::{clone, Cast};
use gtk::prelude::WidgetExt;
use gtk::GestureClick;
use gtk::{AlertDialog, Editable, GestureClick, PasswordEntry, PasswordEntryBuffer, Window};
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use std::time::Duration;
use ReSet_Lib::network::network::{AccessPoint, WifiStrength};
@ -75,6 +78,14 @@ impl WifiEntry {
}
pub fn click_stored_network(entry: Arc<WifiEntry>) {
let alert = AlertDialog::builder().build();
let root = &entry.root().unwrap();
let root = root.downcast_ref::<gtk::Window>();
if root.is_none() {
println!("ERROR BRO");
return;
}
let root = root.unwrap();
// TODO handle unknown access point -> should be done by having 2 different categories
let entryImp = entry.imp();
let conn = Connection::new_session().unwrap();
@ -88,12 +99,14 @@ pub fn click_stored_network(entry: Arc<WifiEntry>) {
let res: Result<(bool,), Error> =
proxy.method_call("org.xetibo.ReSet", "DisconnectFromCurrentAccessPoint", ());
if res.is_err() {
// TODO handle error
println!("no worky");
alert.set_message("Error on connecting to dbus.");
alert.show(Some(root));
return;
}
let (res,) = res.unwrap();
if res == false {
alert.set_message("Could not disconnect from access point.");
alert.show(Some(root));
} else {
entryImp.resetWifiConnected.get().set_from_icon_name(None);
let mut access_point = entryImp.accessPoint.borrow_mut();
@ -108,14 +121,14 @@ pub fn click_stored_network(entry: Arc<WifiEntry>) {
(access_point,),
);
if res.is_err() {
// TODO handle error
println!("no worky");
alert.set_message("Error on connecting to dbus.");
alert.show(Some(root));
} else {
let (res,) = res.unwrap();
if res == false {
println!("no worky but it connected");
alert.set_message("Could not connect to access point.");
alert.show(Some(root));
} else {
println!("worky");
entryImp
.resetWifiConnected
.get()
@ -127,5 +140,76 @@ pub fn click_stored_network(entry: Arc<WifiEntry>) {
}
pub fn click_new_network(entry: Arc<WifiEntry>) {
println!("Not implemented yet :)");
let connect_new_network =
|result: Arc<AtomicBool>, entry: Arc<WifiEntry>, access_point: AccessPoint, password: String| {
let entry_ref = entry.clone();
let popup = entry.imp().resetWifiPopup.imp();
popup.resetPopupLabel.set_text("Connecting...");
popup.resetPopupLabel.set_visible(true);
popup.resetPopupEntry.set_sensitive(false);
popup.resetPopupButton.set_sensitive(false);
glib::spawn_future_local(async move {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(10000),
);
let res: Result<(bool,), Error> = proxy.method_call(
"org.xetibo.ReSet",
"ConnectToNewAccessPoint",
(access_point, password),
);
glib::MainContext::default().spawn_local(async move {
glib::idle_add_once(move || {
if res.is_err() {
entry_ref
.imp()
.resetWifiPopup
.imp()
.resetPopupLabel
.set_text("Could not connect to dbus.");
result.store(false, std::sync::atomic::Ordering::SeqCst);
return;
}
if res.unwrap() == (false,) {
entry_ref
.imp()
.resetWifiPopup
.imp()
.resetPopupLabel
.set_text("Could not connect to access point.");
result.store(false, std::sync::atomic::Ordering::SeqCst);
return;
}
entry_ref.imp().resetWifiPopup.popdown();
result.store(true, std::sync::atomic::Ordering::SeqCst);
});
});
});
// TODO crate spinner animation and block UI
};
let result = Arc::new(AtomicBool::new(false));
let result_ref = result.clone();
let result_ref_button = result.clone();
let entryImp = entry.imp();
let popupImp = entryImp.resetWifiPopup.imp();
popupImp
.resetPopupEntry
.connect_activate(clone!(@weak entry as origEntry, @weak entryImp => move |entry| {
connect_new_network(result_ref.clone(), origEntry, entryImp.accessPoint.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(result_ref_button.clone(), origEntry, entryImp.accessPoint.clone().take(), entry);
}),
);
entryImp.resetWifiPopup.popup();
println!(
"result is {}",
result.load(std::sync::atomic::Ordering::SeqCst)
);
}

View file

@ -1,8 +1,9 @@
use std::cell::RefCell;
use ReSet_Lib::network::network::{WifiStrength, AccessPoint};
use gtk::{Button, CompositeTemplate, glib, Image, Label, Gesture, GestureClick};
use gtk::subclass::prelude::*;
use crate::components::base::popup::Popup;
use crate::components::wifi::wifiEntry;
use gtk::subclass::prelude::*;
use gtk::{glib, Button, CompositeTemplate, Image, Label};
use std::cell::RefCell;
use ReSet_Lib::network::network::{AccessPoint, WifiStrength};
#[allow(non_snake_case)]
#[derive(Default, CompositeTemplate)]
@ -20,6 +21,8 @@ pub struct WifiEntry {
pub resetWifiConnected: TemplateChild<Image>,
#[template_child]
pub resetWifiStored: TemplateChild<Image>,
#[template_child]
pub resetWifiPopup: TemplateChild<Popup>,
pub wifiName: RefCell<String>,
pub wifiStrength: RefCell<WifiStrength>,
pub accessPoint: RefCell<AccessPoint>,

View file

@ -1,13 +1,17 @@
use std::sync::Arc;
use gtk::{FlowBox, Label};
use crate::components::audio::audioBox::AudioBox;
use crate::components::bluetooth::bluetoothBox::BluetoothBox;
use crate::components::base::settingBox::SettingBox;
use crate::components::wifi::wifiBox::{WifiBox, scanForWifi};
use crate::components::bluetooth::bluetoothBox::BluetoothBox;
use crate::components::wifi::wifiBox::{scanForWifi, show_stored_connections, WifiBox};
use adw::prelude::ButtonExt;
use glib::clone;
use glib::subclass::types::ObjectSubclassIsExt;
use gtk::{FlowBox, Label};
pub const HANDLE_CONNECTIVITY_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
pub const HANDLE_CONNECTIVITY_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
let wifiBox = Arc::new(WifiBox::new());
show_stored_connections(wifiBox.clone());
scanForWifi(wifiBox.clone());
let wifiBox = SettingBox::new(&*wifiBox, "WiFi");
let bluetoothBox = SettingBox::new(&BluetoothBox::new(), "Bluetooth");
@ -33,7 +37,7 @@ pub const HANDLE_BLUETOOTH_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
resetMain.set_max_children_per_line(1);
};
pub const HANDLE_VPN_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
pub const HANDLE_VPN_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
let label = Label::new(Some("not implemented yet"));
resetMain.remove_all();
resetMain.insert(&label, -1);
@ -54,35 +58,39 @@ pub const HANDLE_VOLUME_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
resetMain.set_max_children_per_line(1);
};
pub const HANDLE_MICROPHONE_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
pub const HANDLE_MICROPHONE_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
let label = Label::new(Some("not implemented yet"));
resetMain.remove_all();
resetMain.insert(&label, -1);
resetMain.set_max_children_per_line(1);
};
pub const HANDLE_PERIPHERALS_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
pub const HANDLE_HOME: fn(FlowBox) = |resetMain: FlowBox| {
resetMain.remove_all();
};
pub const HANDLE_PERIPHERALS_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
let label = Label::new(Some("not implemented yet"));
resetMain.remove_all();
resetMain.insert(&label, -1);
resetMain.set_max_children_per_line(1);
};
pub const HANDLE_MONITOR_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
pub const HANDLE_MONITOR_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
let label = Label::new(Some("not implemented yet"));
resetMain.remove_all();
resetMain.insert(&label, -1);
resetMain.set_max_children_per_line(1);
};
pub const HANDLE_MOUSE_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
pub const HANDLE_MOUSE_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
let label = Label::new(Some("not implemented yet"));
resetMain.remove_all();
resetMain.insert(&label, -1);
resetMain.set_max_children_per_line(1);
};
pub const HANDLE_KEYBOARD_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
pub const HANDLE_KEYBOARD_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
let label = Label::new(Some("not implemented yet"));
resetMain.remove_all();
resetMain.insert(&label, -1);