[fractal] account-settings: Use the toast macro
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] account-settings: Use the toast macro
- Date: Tue, 31 May 2022 13:59:57 +0000 (UTC)
commit e01e3ce93a27e6fa82b8c343b43deb975eed5808
Author: Kévin Commaille <zecakeh tedomum fr>
Date: Tue May 31 14:49:14 2022 +0200
account-settings: Use the toast macro
src/components/editable_avatar.rs | 21 ++++--------
.../account_settings/devices_page/device_row.rs | 14 ++++----
.../user_page/change_password_subpage.rs | 17 +++-------
.../user_page/deactivate_account_subpage.rs | 5 +--
src/session/account_settings/user_page/mod.rs | 37 +++++-----------------
5 files changed, 25 insertions(+), 69 deletions(-)
---
diff --git a/src/components/editable_avatar.rs b/src/components/editable_avatar.rs
index c03a01e0c..7582d859d 100644
--- a/src/components/editable_avatar.rs
+++ b/src/components/editable_avatar.rs
@@ -10,7 +10,7 @@ use gtk::{
use log::error;
use super::{ActionButton, ActionState};
-use crate::{session::Avatar, spawn};
+use crate::{session::Avatar, spawn, toast};
mod imp {
use std::cell::{Cell, RefCell};
@@ -361,27 +361,18 @@ impl EditableAvatar {
self.emit_by_name::<()>("edit-avatar", &[&file]);
} else {
error!("The chosen file is not an image");
- let _ = self.activate_action(
- "win.add-toast",
- Some(&gettext("The chosen file is not an image").to_variant()),
- );
+ toast!(self, gettext("The chosen file is not an image"));
}
} else {
error!("Could not get the content type of the file");
- let _ = self.activate_action(
- "win.add-toast",
- Some(
- &gettext("Could not determine the type of the chosen file")
- .to_variant(),
- ),
+ toast!(
+ self,
+ gettext("Could not determine the type of the chosen file")
);
}
} else {
error!("No file chosen");
- let _ = self.activate_action(
- "win.add-toast",
- Some(&gettext("No file was chosen").to_variant()),
- );
+ toast!(self, gettext("No file was chosen"));
}
}
}
diff --git a/src/session/account_settings/devices_page/device_row.rs
b/src/session/account_settings/devices_page/device_row.rs
index ba11ced14..6d657b33f 100644
--- a/src/session/account_settings/devices_page/device_row.rs
+++ b/src/session/account_settings/devices_page/device_row.rs
@@ -5,8 +5,8 @@ use log::error;
use super::Device;
use crate::{
- components::{AuthError, SpinnerButton, Toast},
- gettext_f, spawn,
+ components::{AuthError, SpinnerButton},
+ gettext_f, spawn, toast,
};
mod imp {
@@ -210,12 +210,10 @@ impl DeviceRow {
Err(AuthError::UserCancelled) => {},
Err(err) => {
error!("Failed to disconnect device {}: {err:?}", device.device_id());
- if let Some(adw_window) = window.and_then(|w|
w.downcast::<adw::PreferencesWindow>().ok()) {
- let device_name = device.display_name();
- // Translators: Do NOT translate the content between '{' and '}', this is a
variable name.
- let error_message = gettext_f("Failed to disconnect device “{device_name}”",
&[("device_name", device_name)]);
- adw_window.add_toast(&Toast::new(&error_message).into());
- }
+ let device_name = device.display_name();
+ // Translators: Do NOT translate the content between '{' and '}', this is a variable
name.
+ let error_message = gettext_f("Failed to disconnect device “{device_name}”",
&[("device_name", device_name)]);
+ toast!(obj, error_message);
},
}
obj.imp().delete_logout_button.set_loading(false);
diff --git a/src/session/account_settings/user_page/change_password_subpage.rs
b/src/session/account_settings/user_page/change_password_subpage.rs
index 5008d7a59..0e2a71f1a 100644
--- a/src/session/account_settings/user_page/change_password_subpage.rs
+++ b/src/session/account_settings/user_page/change_password_subpage.rs
@@ -20,7 +20,7 @@ use matrix_sdk::{
use crate::{
components::{AuthDialog, AuthError, PasswordEntryRow, SpinnerButton},
session::Session,
- spawn,
+ spawn, toast,
utils::validate_password,
};
@@ -308,10 +308,7 @@ impl ChangePasswordSubpage {
match result {
Ok(_) => {
- let _ = self.activate_action(
- "win.add-toast",
- Some(&gettext("Password changed successfully").to_variant()),
- );
+ toast!(self, gettext("Password changed successfully"));
priv_.password.set_text("");
priv_.confirm_password.set_text("");
self.activate_action("win.close-subpage", None).unwrap();
@@ -326,17 +323,11 @@ impl ChangePasswordSubpage {
)) if error.kind == ErrorKind::WeakPassword) =>
{
error!("Weak password: {:?}", error);
- let _ = self.activate_action(
- "win.add-toast",
- Some(&gettext("Password rejected for being too weak").to_variant()),
- );
+ toast!(self, gettext("Password rejected for being too weak"));
}
_ => {
error!("Failed to change the password: {:?}", err);
- let _ = self.activate_action(
- "win.add-toast",
- Some(&gettext("Could not change password").to_variant()),
- );
+ toast!(self, gettext("Could not change password"));
}
},
}
diff --git a/src/session/account_settings/user_page/deactivate_account_subpage.rs
b/src/session/account_settings/user_page/deactivate_account_subpage.rs
index 0f64908a1..a7816b1ac 100644
--- a/src/session/account_settings/user_page/deactivate_account_subpage.rs
+++ b/src/session/account_settings/user_page/deactivate_account_subpage.rs
@@ -202,10 +202,7 @@ impl DeactivateAccountSubpage {
}
Err(err) => {
error!("Failed to deactivate account: {:?}", err);
- let _ = self.activate_action(
- "win.add-toast",
- Some(&gettext("Could not deactivate account").to_variant()),
- );
+ toast!(self, gettext("Could not deactivate account"));
}
}
priv_.button.set_loading(false);
diff --git a/src/session/account_settings/user_page/mod.rs b/src/session/account_settings/user_page/mod.rs
index c10891c76..f2ff309c1 100644
--- a/src/session/account_settings/user_page/mod.rs
+++ b/src/session/account_settings/user_page/mod.rs
@@ -20,7 +20,7 @@ use deactivate_account_subpage::DeactivateAccountSubpage;
use crate::{
components::{ActionState, ButtonRow, EditableAvatar, EntryRow},
session::{Session, User, UserExt},
- spawn, spawn_tokio,
+ spawn, spawn_tokio, toast,
utils::TemplateCallbacks,
};
@@ -222,10 +222,7 @@ impl UserPage {
avatar.show_temp_image(false);
avatar.set_remove_state(ActionState::Success);
avatar.set_edit_sensitive(true);
- let _ = self.activate_action(
- "win.add-toast",
- Some(&gettext("Avatar removed successfully").to_variant()),
- );
+ toast!(self, gettext("Avatar removed successfully"));
glib::timeout_add_local_once(
Duration::from_secs(2),
clone!(@weak avatar => move || {
@@ -240,10 +237,7 @@ impl UserPage {
avatar.show_temp_image(false);
avatar.set_temp_image_from_file(None);
avatar.set_remove_sensitive(true);
- let _ = self.activate_action(
- "win.add-toast",
- Some(&gettext("Avatar changed successfully").to_variant()),
- );
+ toast!(self, gettext("Avatar changed successfully"));
glib::timeout_add_local_once(
Duration::from_secs(2),
clone!(@weak avatar => move || {
@@ -286,10 +280,7 @@ impl UserPage {
Ok(res) => res.content_uri,
Err(error) => {
error!("Could not upload user avatar: {}", error);
- let _ = self.activate_action(
- "win.add-toast",
- Some(&gettext("Could not upload avatar").to_variant()),
- );
+ toast!(self, gettext("Could not upload avatar"));
avatar.show_temp_image(false);
avatar.set_temp_image_from_file(None);
avatar.set_edit_state(ActionState::Default);
@@ -311,10 +302,7 @@ impl UserPage {
Err(error) => {
if priv_.changing_avatar_to.take().is_some() {
error!("Could not change user avatar: {}", error);
- let _ = self.activate_action(
- "win.add-toast",
- Some(&gettext("Could not change avatar").to_variant()),
- );
+ toast!(self, gettext("Could not change avatar"));
avatar.show_temp_image(false);
avatar.set_temp_image_from_file(None);
avatar.set_edit_state(ActionState::Default);
@@ -343,10 +331,7 @@ impl UserPage {
if priv_.removing_avatar.get() {
priv_.removing_avatar.set(false);
error!("Couldn’t remove user avatar: {}", error);
- let _ = self.activate_action(
- "win.add-toast",
- Some(&gettext("Could not remove avatar").to_variant()),
- );
+ toast!(self, gettext("Could not remove avatar"));
avatar.show_temp_image(false);
avatar.set_remove_state(ActionState::Default);
avatar.set_edit_sensitive(true);
@@ -392,10 +377,7 @@ impl UserPage {
entry.remove_css_class("error");
entry.set_action_state(ActionState::Success);
entry.set_entry_sensitive(true);
- let _ = self.activate_action(
- "win.add-toast",
- Some(&gettext("Name changed successfully").to_variant()),
- );
+ toast!(self, gettext("Name changed successfully"));
glib::timeout_add_local_once(
Duration::from_secs(2),
clone!(@weak entry => move || {
@@ -431,10 +413,7 @@ impl UserPage {
}
Err(err) => {
error!("Couldn’t change user display name: {}", err);
- let _ = self.activate_action(
- "win.add-toast",
- Some(&gettext("Could not change display name").to_variant()),
- );
+ toast!(self, gettext("Could not change display name"));
entry.set_action_state(ActionState::Retry);
entry.add_css_class("error");
entry.set_entry_sensitive(true);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]