Commit 708c5c02 authored by Julian Sparber's avatar Julian Sparber

accountsettings: add button to submit new display name

* Minor: show error dialog for non valid phone numbers

https://gitlab.gnome.org/World/fractal/issues/21
parent e019e48d
......@@ -93,9 +93,34 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="account_settings_name">
<object class="GtkBox" id="account_settings_name_box">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_focus">false</property>
<property name="margin_top">6</property>
<property name="hexpand">True</property>
<style>
<class name="linked"/>
</style>
<child>
<object class="GtkEntry" id="account_settings_name">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
</object>
</child>
<child>
<object class="GtkButton" id="account_settings_name_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">emblem-ok-symbolic</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
......
......@@ -84,7 +84,7 @@ pub fn backend_loop(rx: Receiver<BKResponse>) {
}
Ok(BKResponse::SetUserName(username)) => {
let u = Some(username);
APPOP!(set_username, (u));
APPOP!(show_new_username, (u));
}
Ok(BKResponse::AccountDestruction) => {
APPOP!(account_destruction_logoff);
......@@ -210,6 +210,11 @@ pub fn backend_loop(rx: Receiver<BKResponse>) {
println!("ERROR: {:?}", err);
APPOP!(show_three_pid_error_dialog, (error));
},
Ok(BKResponse::GetTokenPhoneError(err)) => {
let error = gettext("Couldn't add the phone number.");
println!("ERROR: {:?}", err);
APPOP!(show_three_pid_error_dialog, (error));
},
Ok(BKResponse::NewRoomError(err, internal_id)) => {
println!("ERROR: {:?}", err);
......
......@@ -30,6 +30,12 @@ impl App {
let avatar_btn = self.ui.builder
.get_object::<gtk::Button>("account_settings_avatar_button")
.expect("Can't find account_settings_avatar_button in ui file.");
let name_entry = self.ui.builder
.get_object::<gtk::Entry>("account_settings_name")
.expect("Can't find account_settings_name in ui file.");
let name_btn = self.ui.builder
.get_object::<gtk::Button>("account_settings_name_button")
.expect("Can't find account_settings_name_button in ui file.");
let password_btn = self.ui.builder
.get_object::<gtk::Button>("account_settings_password")
.expect("Can't find account_settings_password in ui file.");
......@@ -71,19 +77,39 @@ impl App {
}
}));
let button = name_btn.clone();
name_entry.connect_property_text_notify(move |w| {
if let Some(text) = w.get_text() {
if text != "" {
button.show();
return;
}
}
button.hide();
});
let button = name_btn.clone();
name_entry.connect_activate(move |_w| {
let _ = button.emit("clicked", &[]);
});
name_btn.connect_clicked(clone!(op => move |_w| {
op.lock().unwrap().update_username_account_settings();
}));
/*
fn update_password_strength(builder: &gtk::Builder) {
let bar = builder
.get_object::<gtk::LevelBar>("password-dialog-strength-indicator")
.expect("Can't find password-dialog-strength-indicator in ui file.");
let label = builder
.get_object::<gtk::Label>("password-dialog-hint")
.expect("Can't find password-dialog-hint in ui file.");
let strength_level = 10f64;
bar.set_value(strength_level);
label.set_label("text");
}
*/
fn update_password_strength(builder: &gtk::Builder) {
let bar = builder
.get_object::<gtk::LevelBar>("password-dialog-strength-indicator")
.expect("Can't find password-dialog-strength-indicator in ui file.");
let label = builder
.get_object::<gtk::Label>("password-dialog-hint")
.expect("Can't find password-dialog-hint in ui file.");
let strength_level = 10f64;
bar.set_value(strength_level);
label.set_label("text");
}
*/
fn validate_password_input(builder: &gtk::Builder) {
let hint = builder
......
......@@ -153,6 +153,9 @@ impl AppOp {
let name = self.ui.builder
.get_object::<gtk::Entry>("account_settings_name")
.expect("Can't find account_settings_name in ui file.");
let name_btn = self.ui.builder
.get_object::<gtk::Button>("account_settings_name_button")
.expect("Can't find account_settings_name_button in ui file.");
let uid = self.ui.builder
.get_object::<gtk::Label>("account_settings_uid")
.expect("Can't find account_settings_uid in ui file.");
......@@ -201,6 +204,13 @@ impl AppOp {
avatar.add(&w);
avatar.show();
name_btn.hide();
name.set_editable(true);
let image = gtk::Image::new_from_icon_name("emblem-ok-symbolic", 1);
name_btn.set_image(&image);
name_btn.set_sensitive(true);
/* reset the password button */
password_btn_stack.set_visible_child_name("label");
password_btn.set_sensitive(true);
......@@ -211,7 +221,6 @@ impl AppOp {
advanced_box.set_redraw_on_allocate(true);
delete_box.set_redraw_on_allocate(true);
self.set_state(AppState::AccountSettings);
}
......@@ -312,17 +321,46 @@ impl AppOp {
self.backend.send(command).unwrap();
}
pub fn show_new_username(&mut self, name: Option<String>) {
let entry = self.ui.builder
.get_object::<gtk::Entry>("account_settings_name")
.expect("Can't find account_settings_name in ui file.");
let button = self.ui.builder
.get_object::<gtk::Button>("account_settings_name_button")
.expect("Can't find account_settings_name_button in ui file.");
if let Some(name) = name.clone() {
button.hide();
let image = gtk::Image::new_from_icon_name("emblem-ok-symbolic", 1);
button.set_image(&image);
button.set_sensitive(true);
entry.set_editable(true);
entry.set_text(&name);
}
self.set_username(name);
}
pub fn update_username_account_settings(&self) {
let name = self.ui.builder
.get_object::<gtk::Entry>("account_settings_name")
.expect("Can't find account_settings_name in ui file.");
let button = self.ui.builder
.get_object::<gtk::Button>("account_settings_name_button")
.expect("Can't find account_settings_name_button in ui file.");
let old_username = self.username.clone().unwrap_or_default();
let username = name.get_text().unwrap_or_default();
if old_username != username {
let spinner = gtk::Spinner::new();
spinner.start();
button.set_image(&spinner);
button.set_sensitive(false);
name.set_editable(false);
self.backend.send(BKCommand::SetUserName(username)).unwrap();
}
else {
button.hide();
}
}
pub fn close_account_settings_dialog(&mut self) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment