RR: Finalize User creation page!

This commit is contained in:
Ward from fusion-voyager-3 2024-02-05 19:52:54 +03:00
parent 6a8245f0ff
commit 0b2014af37
4 changed files with 109 additions and 16 deletions

View File

@ -60,7 +60,7 @@ pub fn update_carousel(first_setup_carousel: &adw::Carousel, internet_connected:
let internet_loop_context = MainContext::default(); let internet_loop_context = MainContext::default();
// The main loop executes the asynchronous block // The main loop executes the asynchronous block
internet_loop_context.spawn_local(clone!(@strong internet_connected_status, @weak first_setup_start_button => async move { internet_loop_context.spawn_local(clone!(@strong internet_connected_status, @weak first_setup_start_button => async move {
while let Ok(state) = internet_loop_receiver.recv().await { while let Ok(_state) = internet_loop_receiver.recv().await {
if *internet_connected_status.borrow_mut() == true { if *internet_connected_status.borrow_mut() == true {
first_setup_start_button.set_label("true"); first_setup_start_button.set_label("true");
} else { } else {

View File

@ -14,7 +14,7 @@ use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
use std::borrow::Borrow as the_rc_borrow; use std::borrow::Borrow as the_rc_borrow;
use regex::Regex; use regex::Regex;
use std::env; use std::{env, thread, time};
use gtk::Align::Center; use gtk::Align::Center;
use gtk::gio::ffi::GAsyncReadyCallback; use gtk::gio::ffi::GAsyncReadyCallback;
use gtk::pango::TextTransform::Capitalize; use gtk::pango::TextTransform::Capitalize;
@ -37,7 +37,15 @@ pub fn user_carousel(first_setup_carousel: &adw::Carousel) {
let user_info_full_name_valid = Rc::new(RefCell::new(false)); let user_info_full_name_valid = Rc::new(RefCell::new(false));
let user_info_passwords_valid = Rc::new(RefCell::new(false)); let user_info_passwords_valid = Rc::new(RefCell::new(false));
let (user_loop_sender, user_loop_receiver) = async_channel::unbounded();
let user_loop_sender = user_loop_sender.clone();
// The long running operation runs now in a separate thread
gio::spawn_blocking(move || {
loop {
thread::sleep(time::Duration::from_secs(1));
user_loop_sender.send_blocking(true).expect("The channel needs to be open.");
}
});
let first_setup_user_box = gtk::Box::builder() let first_setup_user_box = gtk::Box::builder()
// that puts items vertically // that puts items vertically
@ -91,12 +99,21 @@ pub fn user_carousel(first_setup_carousel: &adw::Carousel) {
let user_info_password_verify = adw::PasswordEntryRow::builder() let user_info_password_verify = adw::PasswordEntryRow::builder()
.hexpand(true) .hexpand(true)
.title("Enter User password again:") .title("Enter User password again:")
.visible(false) .build();
let user_info_password_verify_revealer = gtk::Revealer::builder()
.child(&user_info_password_verify)
.reveal_child(false)
.transition_type(RevealerTransitionType::SwingDown)
.build(); .build();
let user_info_avatar = adw::Avatar::builder() let user_info_avatar = adw::Avatar::builder()
.show_initials(true) .show_initials(true)
.size(128) .size(128)
.margin_top(15)
.margin_bottom(15)
.margin_start(15)
.margin_end(15)
.build(); .build();
let _user_info_avatar_full_name_binding = user_info_full_name let _user_info_avatar_full_name_binding = user_info_full_name
@ -112,6 +129,17 @@ pub fn user_carousel(first_setup_carousel: &adw::Carousel) {
.build(); .build();
user_info_listbox.add_css_class("boxed-list"); user_info_listbox.add_css_class("boxed-list");
let error_label = gtk::Label::builder()
.margin_top(15)
.margin_bottom(15)
.margin_start(15)
.margin_end(15)
.visible(false)
.label("NULL")
.build();
error_label.add_css_class("red-text");
let user_next_button = gtk::Button::builder() let user_next_button = gtk::Button::builder()
.label("Next") .label("Next")
.sensitive(false) .sensitive(false)
@ -129,17 +157,30 @@ pub fn user_carousel(first_setup_carousel: &adw::Carousel) {
user_info_listbox.append(&user_info_username); user_info_listbox.append(&user_info_username);
user_info_listbox.append(&user_info_full_name); user_info_listbox.append(&user_info_full_name);
user_info_listbox.append(&user_info_password); user_info_listbox.append(&user_info_password);
user_info_listbox.append(&user_info_password_verify); user_info_listbox.append(&user_info_password_verify_revealer);
user_info_box.append(&user_info_avatar); user_info_box.append(&user_info_avatar);
user_info_box.append(&user_info_listbox); user_info_box.append(&user_info_listbox);
first_setup_user_box.append(&first_setup_user_box_text); first_setup_user_box.append(&first_setup_user_box_text);
first_setup_user_box.append(&user_info_box_clamp); first_setup_user_box.append(&user_info_box_clamp);
first_setup_user_box.append(&error_label);
first_setup_user_box.append(&user_next_button); first_setup_user_box.append(&user_next_button);
// The main loop executes the asynchronous block
let user_loop_context = MainContext::default();
user_loop_context.spawn_local(clone!(@strong user_info_username_valid, @strong user_info_full_name_valid, @strong user_info_passwords_valid, @weak user_next_button => async move {
while let Ok(_state) = user_loop_receiver.recv().await {
if *user_info_username_valid.borrow_mut() == true && *user_info_full_name_valid.borrow_mut() == true && *user_info_passwords_valid.borrow_mut() == true {
user_next_button.set_sensitive(true);
} else {
user_next_button.set_sensitive(false);
}
}
}));
user_info_username.connect_changed(clone!(@strong user_info_username_valid, @weak user_info_username, @weak user_info_full_name => move |_| {
user_info_username.connect_changed(clone!(@strong user_info_username_valid, @weak user_info_username, @weak user_info_full_name, @weak error_label => move |_| {
let user_info_username_string = user_info_username.text().to_string(); let user_info_username_string = user_info_username.text().to_string();
user_info_full_name.set_text(&uppercase_first_letter(&user_info_username_string)); user_info_full_name.set_text(&uppercase_first_letter(&user_info_username_string));
@ -154,32 +195,85 @@ pub fn user_carousel(first_setup_carousel: &adw::Carousel) {
user_info_username.set_position(-1); user_info_username.set_position(-1);
} }
if !only_alphanumeric(&user_info_username_string) { let mut username_is_root = false;
*user_info_username_valid.borrow_mut()=true; let mut username_is_pikaos = false;
let mut username_is_special = false;
if only_alphanumeric(&user_info_username_string) {
error_label.set_visible(false);
username_is_root=false;
} else { } else {
*user_info_username_valid.borrow_mut()=false; error_label.set_visible(true);
error_label.set_label("Username can not contain special characters.");
username_is_root=true;
} }
if user_info_username_string != "pikaos" { if user_info_username_string != "pikaos" {
*user_info_username_valid.borrow_mut()=true; error_label.set_visible(false);
username_is_pikaos=false;
} else { } else {
*user_info_username_valid.borrow_mut()=false; error_label.set_visible(true);
error_label.set_label("Username can not be pikaos.");
username_is_pikaos=true;
} }
if user_info_username_string != "root" { if user_info_username_string != "root" {
error_label.set_visible(false);
username_is_special=false;
} else {
error_label.set_visible(true);
error_label.set_label("Username can not be root.");
username_is_special=true;
}
if username_is_root == false && username_is_pikaos == false && username_is_special == false {
if !user_info_username.text().is_empty() {
*user_info_username_valid.borrow_mut()=true; *user_info_username_valid.borrow_mut()=true;
}
} else { } else {
*user_info_username_valid.borrow_mut()=false; *user_info_username_valid.borrow_mut()=false;
} }
})); }));
user_info_full_name.connect_changed(clone!(@strong user_info_full_name_valid, @weak user_info_full_name => move |_| { user_info_full_name.connect_changed(clone!(@strong user_info_full_name_valid, @weak user_info_full_name, @weak error_label => move |_| {
let user_info_full_name_string = user_info_full_name.text().to_string(); let user_info_full_name_string = user_info_full_name.text().to_string();
if user_info_full_name_string.len() > 32 { if user_info_full_name_string.len() > 32 {
user_info_full_name.set_text(&user_info_full_name_string[..32]); user_info_full_name.set_text(&user_info_full_name_string[..32]);
user_info_full_name.set_position(-1); user_info_full_name.set_position(-1);
} }
if user_info_full_name.text().is_empty() {
*user_info_full_name_valid.borrow_mut()=false;
} else {
*user_info_full_name_valid.borrow_mut()=true;
}
}));
user_info_password.connect_changed(clone!(@strong user_info_passwords_valid,@weak user_info_password_verify_revealer, @weak user_info_password, @weak user_info_password_verify, @weak error_label => move |_| {
if user_info_password.text().is_empty() {
user_info_password_verify_revealer.set_reveal_child(false)
} else {
user_info_password_verify_revealer.set_reveal_child(true)
}
if user_info_password.text() == user_info_password_verify.text() {
error_label.set_visible(false);
*user_info_passwords_valid.borrow_mut()=true;
} else {
*user_info_passwords_valid.borrow_mut()=false;
}
}));
user_info_password_verify.connect_changed(clone!(@strong user_info_passwords_valid, @weak user_info_password, @weak user_info_password_verify, @weak error_label => move |_| {
if user_info_password.text() == user_info_password_verify.text() {
error_label.set_visible(false);
*user_info_passwords_valid.borrow_mut()=true;
} else {
error_label.set_visible(true);
error_label.set_label("Passwords do not match!");
*user_info_passwords_valid.borrow_mut()=false;
}
})); }));

View File

@ -1,4 +1,3 @@
.bigREDTEXT { .red-text {
font-size: 14px;
color: red; color: red;
} }

View File

@ -1 +1 @@
{"rustc_fingerprint":11104695642277176061,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.75.0 (82e1608df 2023-12-21)\nbinary: rustc\ncommit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112\ncommit-date: 2023-12-21\nhost: x86_64-unknown-linux-gnu\nrelease: 1.75.0\nLLVM version: 17.0.6\n","stderr":""},"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/ward/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""}},"successes":{}} {"rustc_fingerprint":11104695642277176061,"outputs":{"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/ward/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.75.0 (82e1608df 2023-12-21)\nbinary: rustc\ncommit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112\ncommit-date: 2023-12-21\nhost: x86_64-unknown-linux-gnu\nrelease: 1.75.0\nLLVM version: 17.0.6\n","stderr":""}},"successes":{}}