[fractal] Display error when settings can't load
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] Display error when settings can't load
- Date: Fri, 18 Oct 2019 09:05:01 +0000 (UTC)
commit 91a1e66a8556a142be673ca71067936d3d30ed79
Author: sonjita <sonjaleaheinze gmail com>
Date: Tue Oct 15 18:53:04 2019 +0200
Display error when settings can't load
Before, when an error occurred trying to load account settings,
the user would see a spinner until pressing the "go back" button manually.
With this commit, when an error occurs trying to load account settings,
an error dialog opens. Furthermore the "go back" button is activated automatically.
In particular, when the user closes the error dialog,
they find themselves back in the state they came from.
fractal-gtk/src/actions/global.rs | 15 +++++++++++++++
fractal-gtk/src/actions/mod.rs | 1 +
fractal-gtk/src/app/backend_loop.rs | 20 ++++++++++++++------
fractal-gtk/src/appop/account.rs | 27 +++++++++++++++------------
4 files changed, 45 insertions(+), 18 deletions(-)
---
diff --git a/fractal-gtk/src/actions/global.rs b/fractal-gtk/src/actions/global.rs
index 9497d6e3..4e9e28fa 100644
--- a/fractal-gtk/src/actions/global.rs
+++ b/fractal-gtk/src/actions/global.rs
@@ -344,3 +344,18 @@ fn open_viewer(data: Option<&glib::Variant>) -> Option<()> {
op.create_media_viewer(msg);
None
}
+
+pub fn activate_action(action_group_name: &str, action_name: &str) {
+ if let Some(op) = App::get_op() {
+ let mutexguard = op.lock().unwrap();
+ let main_window = mutexguard
+ .ui
+ .builder
+ .get_object::<gtk::Window>("main_window")
+ .expect("Can't find main_window in ui file.");
+ std::mem::drop(mutexguard);
+ if let Some(action_group) = main_window.get_action_group(action_group_name) {
+ action_group.activate_action(action_name, None);
+ }
+ }
+}
diff --git a/fractal-gtk/src/actions/mod.rs b/fractal-gtk/src/actions/mod.rs
index 9ca00650..2f33eedd 100644
--- a/fractal-gtk/src/actions/mod.rs
+++ b/fractal-gtk/src/actions/mod.rs
@@ -12,6 +12,7 @@ pub mod room_settings;
pub use self::account_settings as AccountSettings;
pub use self::global as Global;
+pub use self::global::activate_action;
pub use self::global::AppState;
pub use self::login as Login;
pub use self::login::LoginState;
diff --git a/fractal-gtk/src/app/backend_loop.rs b/fractal-gtk/src/app/backend_loop.rs
index 0efb0e90..cbb0cc67 100644
--- a/fractal-gtk/src/app/backend_loop.rs
+++ b/fractal-gtk/src/app/backend_loop.rs
@@ -2,7 +2,7 @@ use crate::app::App;
use crate::i18n::i18n;
use log::{error, info};
-use crate::actions::AppState;
+use crate::actions::{activate_action, AppState};
use glib;
use std::process::Command;
@@ -52,11 +52,11 @@ pub fn backend_loop(rx: Receiver<BKResponse>) {
}
Ok(BKResponse::GetTokenEmail(Err(Error::TokenUsed))) => {
let error = i18n("Email is already in use");
- APPOP!(show_three_pid_error_dialog, (error));
+ APPOP!(show_error_dialog_in_settings, (error));
}
Ok(BKResponse::GetTokenPhone(Err(Error::TokenUsed))) => {
let error = i18n("Phone number is already in use");
- APPOP!(show_three_pid_error_dialog, (error));
+ APPOP!(show_error_dialog_in_settings, (error));
}
Ok(BKResponse::SubmitPhoneToken(Ok((sid, secret)))) => {
let secret = Some(secret);
@@ -191,22 +191,30 @@ pub fn backend_loop(rx: Receiver<BKResponse>) {
Ok(BKResponse::AccountDestruction(Err(err))) => {
let error = i18n("Couldn’t delete the account");
error!("{:?}", err);
- APPOP!(show_error_dialog, (error));
+ APPOP!(show_error_dialog_in_settings, (error));
}
Ok(BKResponse::ChangePassword(Err(err))) => {
let error = i18n("Couldn’t change the password");
error!("{:?}", err);
APPOP!(show_password_error_dialog, (error));
}
+ Ok(BKResponse::GetThreePID(Err(_))) => {
+ let error = i18n("Sorry, account settings can't be loaded.");
+ APPOP!(show_load_settings_error_dialog, (error));
+ let ctx = glib::MainContext::default();
+ ctx.invoke(move || {
+ activate_action("app", "back");
+ })
+ }
Ok(BKResponse::GetTokenEmail(Err(err))) => {
let error = i18n("Couldn’t add the email address.");
error!("{:?}", err);
- APPOP!(show_three_pid_error_dialog, (error));
+ APPOP!(show_error_dialog_in_settings, (error));
}
Ok(BKResponse::GetTokenPhone(Err(err))) => {
let error = i18n("Couldn’t add the phone number.");
error!("{:?}", err);
- APPOP!(show_three_pid_error_dialog, (error));
+ APPOP!(show_error_dialog_in_settings, (error));
}
Ok(BKResponse::NewRoom(Err(err), internal_id)) => {
error!("{:?}", err);
diff --git a/fractal-gtk/src/appop/account.rs b/fractal-gtk/src/appop/account.rs
index 47adcbd3..f5a7e671 100644
--- a/fractal-gtk/src/appop/account.rs
+++ b/fractal-gtk/src/appop/account.rs
@@ -38,8 +38,7 @@ impl AppOp {
));
}
} else {
- self.show_error_dialog(i18n("The validation code is not correct."));
- self.get_three_pid();
+ self.show_error_dialog_in_settings(i18n("The validation code is not correct."));
}
}
@@ -143,11 +142,20 @@ impl AppOp {
dialog.show_all();
}
- pub fn show_three_pid_error_dialog(&self, error: String) {
- self.show_error_dialog(error);
+ pub fn show_error_dialog_in_settings(&self, error: String) {
+ let dialog = self.create_error_dialog(error);
+ dialog.connect_response(move |w, _| w.destroy());
+ self.get_three_pid();
+ dialog.show_all();
+ }
+
+ pub fn show_load_settings_error_dialog(&self, error: String) {
+ let dialog = self.create_error_dialog(error);
+ dialog.connect_response(move |w, _| w.destroy());
+ dialog.show_all();
}
- pub fn show_error_dialog(&self, error: String) {
+ pub fn create_error_dialog(&self, error: String) -> gtk::MessageDialog {
let parent = self
.ui
.builder
@@ -166,12 +174,7 @@ impl AppOp {
dialog.add_button(&i18n("OK"), gtk::ResponseType::Ok.into());
- let backend = self.backend.clone();
- dialog.connect_response(move |w, _| {
- backend.send(BKCommand::GetThreePID).unwrap();
- w.destroy();
- });
- dialog.show_all();
+ dialog
}
pub fn get_token_email(&mut self, sid: Option<String>, secret: Option<String>) {
@@ -630,7 +633,7 @@ impl AppOp {
.builder
.get_object::<gtk::Stack>("account_settings_password_stack")
.expect("Can't find account_settings_password_stack in ui file.");
- self.show_error_dialog(error);
+ self.show_error_dialog_in_settings(error);
password_btn.set_sensitive(true);
password_btn_stack.set_visible_child_name("label");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]