[fractal/fractal-next] app: Rename Error to Toast and move to components
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] app: Rename Error to Toast and move to components
- Date: Wed, 23 Feb 2022 17:06:55 +0000 (UTC)
commit 757373f87b61e9b747ac962c48c501a596ff2106
Author: Kévin Commaille <zecakeh tedomum fr>
Date: Wed Feb 16 11:49:51 2022 +0100
app: Rename Error to Toast and move to components
data/resources/ui/window.ui | 2 +-
src/components/in_app_notification.rs | 4 ++--
src/components/mod.rs | 2 ++
src/{error.rs => components/toast.rs} | 20 ++++++++++----------
src/login.rs | 11 +++++++----
src/main.rs | 3 +--
.../content/verification/session_verification.rs | 6 +++---
src/session/mod.rs | 15 ++++++++-------
src/session/room/event_actions.rs | 7 ++++---
src/session/room/mod.rs | 17 ++++++++---------
src/session/room_list.rs | 5 +++--
src/session/verification/identity_verification.rs | 5 +++--
src/window.rs | 10 +++++-----
13 files changed, 57 insertions(+), 50 deletions(-)
---
diff --git a/data/resources/ui/window.ui b/data/resources/ui/window.ui
index 3ddae4837..c0cab8f4d 100644
--- a/data/resources/ui/window.ui
+++ b/data/resources/ui/window.ui
@@ -9,7 +9,7 @@
<object class="InAppNotification">
<property name="error-list">
<object class="GListStore" id="error_list">
- <property name="item-type">Error</property>
+ <property name="item-type">ComponentsToast</property>
</object>
</property>
</object>
diff --git a/src/components/in_app_notification.rs b/src/components/in_app_notification.rs
index 31d78e12a..64dbf7edb 100644
--- a/src/components/in_app_notification.rs
+++ b/src/components/in_app_notification.rs
@@ -1,7 +1,7 @@
use adw::subclass::prelude::*;
use gtk::{gio, glib, glib::clone, prelude::*, subclass::prelude::*, CompositeTemplate};
-use crate::Error;
+use crate::components::Toast;
mod imp {
use std::cell::{Cell, RefCell};
@@ -154,7 +154,7 @@ impl InAppNotification {
.borrow()
.as_ref()
.and_then(|error_list| error_list.item(0))
- .and_then(|obj| obj.downcast::<Error>().ok())
+ .and_then(|obj| obj.downcast::<Toast>().ok())
.and_then(|error| error.widget())
{
if let Some(current_widget) = priv_.current_widget.take() {
diff --git a/src/components/mod.rs b/src/components/mod.rs
index 7ad75e413..53eb2f89b 100644
--- a/src/components/mod.rs
+++ b/src/components/mod.rs
@@ -11,6 +11,7 @@ mod pill;
mod reaction_chooser;
mod room_title;
mod spinner_button;
+mod toast;
mod video_player;
mod video_player_renderer;
@@ -28,6 +29,7 @@ pub use self::{
reaction_chooser::ReactionChooser,
room_title::RoomTitle,
spinner_button::SpinnerButton,
+ toast::Toast,
video_player::VideoPlayer,
video_player_renderer::VideoPlayerRenderer,
};
diff --git a/src/error.rs b/src/components/toast.rs
similarity index 73%
rename from src/error.rs
rename to src/components/toast.rs
index f7fd750c0..8a9f52d38 100644
--- a/src/error.rs
+++ b/src/components/toast.rs
@@ -1,6 +1,6 @@
use gtk::{glib, subclass::prelude::*};
-type WidgetBuilderFn = Box<dyn Fn(&super::Error) -> Option<gtk::Widget> + 'static>;
+type WidgetBuilderFn = Box<dyn Fn(&super::Toast) -> Option<gtk::Widget> + 'static>;
mod imp {
use std::cell::RefCell;
@@ -8,28 +8,28 @@ mod imp {
use super::*;
#[derive(Default)]
- pub struct Error {
+ pub struct Toast {
pub widget_builder: RefCell<Option<WidgetBuilderFn>>,
}
#[glib::object_subclass]
- impl ObjectSubclass for Error {
- const NAME: &'static str = "Error";
- type Type = super::Error;
+ impl ObjectSubclass for Toast {
+ const NAME: &'static str = "ComponentsToast";
+ type Type = super::Toast;
type ParentType = glib::Object;
}
- impl ObjectImpl for Error {}
+ impl ObjectImpl for Toast {}
}
glib::wrapper! {
- /// An `Error` that can be shown in the UI.
- pub struct Error(ObjectSubclass<imp::Error>);
+ /// A `Toast` that can be shown in the UI.
+ pub struct Toast(ObjectSubclass<imp::Toast>);
}
-impl Error {
+impl Toast {
pub fn new<F: Fn(&Self) -> Option<gtk::Widget> + 'static>(f: F) -> Self {
- let obj: Self = glib::Object::new(&[]).expect("Failed to create Error");
+ let obj: Self = glib::Object::new(&[]).expect("Failed to create Toast");
obj.set_widget_builder(f);
obj
}
diff --git a/src/login.rs b/src/login.rs
index 2ee7f2703..13692fe8d 100644
--- a/src/login.rs
+++ b/src/login.rs
@@ -14,8 +14,11 @@ use tokio::task::JoinHandle;
use url::{ParseError, Url};
use crate::{
- components::SpinnerButton, error::Error, login_advanced_dialog::LoginAdvancedDialog, spawn,
- spawn_tokio, user_facing_error::UserFacingError, Session,
+ components::{SpinnerButton, Toast},
+ login_advanced_dialog::LoginAdvancedDialog,
+ spawn, spawn_tokio,
+ user_facing_error::UserFacingError,
+ Session,
};
mod imp {
@@ -310,7 +313,7 @@ impl Login {
warn!("Failed to discover homeserver: {}", error);
let error_string = error.to_user_facing();
- obj.parent_window().append_error(&Error::new(move |_| {
+ obj.parent_window().append_error(&Toast::new(move |_| {
let error_label = gtk::Label::builder()
.label(&error_string)
.wrap(true)
@@ -352,7 +355,7 @@ impl Login {
warn!("Failed to check homeserver: {}", error);
let error_string = error.to_user_facing();
- obj.parent_window().append_error(&Error::new(move |_| {
+ obj.parent_window().append_error(&Toast::new(move |_| {
let error_label = gtk::Label::builder()
.label(&error_string)
.wrap(true)
diff --git a/src/main.rs b/src/main.rs
index 97162920b..9dd0791fa 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,7 +9,6 @@ mod prelude;
mod components;
mod contrib;
-mod error;
mod greeter;
mod login;
mod login_advanced_dialog;
@@ -25,7 +24,7 @@ use gtk::{gdk::Display, gio, IconTheme};
use once_cell::sync::Lazy;
use self::{
- application::Application, error::Error, greeter::Greeter, login::Login, session::Session,
+ application::Application, greeter::Greeter, login::Login, session::Session,
user_facing_error::UserFacingError, window::Window,
};
diff --git a/src/session/content/verification/session_verification.rs
b/src/session/content/verification/session_verification.rs
index 3dc72ab05..4bf642c49 100644
--- a/src/session/content/verification/session_verification.rs
+++ b/src/session/content/verification/session_verification.rs
@@ -5,9 +5,9 @@ use log::error;
use super::IdentityVerificationWidget;
use crate::{
- components::{AuthDialog, AuthError, SpinnerButton},
+ components::{AuthDialog, AuthError, SpinnerButton, Toast},
session::verification::{IdentityVerification, VerificationState},
- spawn, Error, Session, Window,
+ spawn, Session, Window,
};
mod imp {
@@ -315,7 +315,7 @@ impl SessionVerification {
};
if let Some(error_message) = error_message {
- let error = Error::new(move |_| {
+ let error = Toast::new(move |_| {
let error_label = gtk::Label::builder()
.label(&error_message)
.wrap(true)
diff --git a/src/session/mod.rs b/src/session/mod.rs
index 2cabad370..653e9cec8 100644
--- a/src/session/mod.rs
+++ b/src/session/mod.rs
@@ -61,10 +61,11 @@ pub use self::{
user::{User, UserActions, UserExt},
};
use crate::{
+ components::Toast,
secret,
secret::{Secret, StoredSession},
session::sidebar::ItemList,
- spawn, spawn_tokio, Error, UserFacingError, Window,
+ spawn, spawn_tokio, UserFacingError, Window,
};
mod imp {
@@ -209,7 +210,7 @@ mod imp {
vec![
Signal::builder(
"prepared",
- &[Option::<Error>::static_type().into()],
+ &[Option::<Toast>::static_type().into()],
<()>::static_type().into(),
)
.build(),
@@ -422,7 +423,7 @@ impl Session {
Err(error) => {
warn!("Couldn't store session: {:?}", error);
let error_string = error.to_user_facing();
- Some(Error::new(move |_| {
+ Some(Toast::new(move |_| {
let error_label = gtk::Label::builder()
.label(
&(gettext("Unable to store session")
@@ -454,7 +455,7 @@ impl Session {
let error_string = error.to_user_facing();
- Some(Error::new(move |_| {
+ Some(Toast::new(move |_| {
let error_label = gtk::Label::builder()
.label(&error_string)
.wrap(true)
@@ -610,13 +611,13 @@ impl Session {
}
/// Connects the prepared signals to the function f given in input
- pub fn connect_prepared<F: Fn(&Self, Option<Error>) + 'static>(
+ pub fn connect_prepared<F: Fn(&Self, Option<Toast>) + 'static>(
&self,
f: F,
) -> glib::SignalHandlerId {
self.connect_local("prepared", true, move |values| {
let obj = values[0].get::<Self>().unwrap();
- let err = values[1].get::<Option<Error>>().unwrap();
+ let err = values[1].get::<Option<Toast>>().unwrap();
f(&obj, err);
@@ -714,7 +715,7 @@ impl Session {
Ok(_) => self.cleanup_session(),
Err(error) => {
error!("Couldn’t logout the session {}", error);
- let error = Error::new(move |_| {
+ let error = Toast::new(move |_| {
let label = gtk::Label::new(Some(&gettext("Failed to logout the session.")));
Some(label.upcast())
});
diff --git a/src/session/room/event_actions.rs b/src/session/room/event_actions.rs
index a4eeefba8..bfcba25da 100644
--- a/src/session/room/event_actions.rs
+++ b/src/session/room/event_actions.rs
@@ -5,6 +5,7 @@ use matrix_sdk::ruma::events::{room::message::MessageType, AnyMessageEventConten
use once_cell::sync::Lazy;
use crate::{
+ components::Toast,
session::{
event_source_dialog::EventSourceDialog,
room::{Event, RoomAction},
@@ -12,7 +13,7 @@ use crate::{
},
spawn,
utils::cache_dir,
- Error, UserFacingError, Window,
+ UserFacingError, Window,
};
// This is only save because the trait `EventActions` can
@@ -196,7 +197,7 @@ where
error!("Could not get file: {}", err);
let error_message = err.to_user_facing();
- let error = Error::new(move |_| {
+ let error = Toast::new(move |_| {
let error_label = gtk::Label::builder()
.label(&error_message)
.wrap(true)
@@ -254,7 +255,7 @@ where
error!("Could not get file: {}", err);
let error_message = err.to_user_facing();
- let error = Error::new(move |_| {
+ let error = Toast::new(move |_| {
let error_label = gtk::Label::builder()
.label(&error_message)
.wrap(true)
diff --git a/src/session/room/mod.rs b/src/session/room/mod.rs
index 4e1eba2a7..0996f0677 100644
--- a/src/session/room/mod.rs
+++ b/src/session/room/mod.rs
@@ -56,14 +56,13 @@ pub use self::{
timeline::{Timeline, TimelineState},
};
use crate::{
- components::{LabelWithWidgets, Pill},
+ components::{LabelWithWidgets, Pill, Toast},
prelude::*,
session::{
avatar::update_room_avatar_from_file, room::member_list::MemberList, Avatar, Session, User,
},
spawn, spawn_tokio,
utils::pending_event_ids,
- Error,
};
mod imp {
@@ -407,7 +406,7 @@ impl Room {
}
Err(error) => {
error!("Couldn’t forget the room: {}", error);
- let error = Error::new(
+ let error = Toast::new(
clone!(@weak obj => @default-return None, move |_| {
let error_message = gettext(
"Failed to forget <widget>."
@@ -558,7 +557,7 @@ impl Room {
Ok(_) => {},
Err(error) => {
error!("Couldn’t set the room category: {}", error);
- let error = Error::new(
+ let error = Toast::new(
clone!(@weak obj => @default-return None, move |_| {
let error_message = gettext!(
"Failed to move <widget> from {} to {}.",
@@ -1056,7 +1055,7 @@ impl Room {
);
}
- pub async fn accept_invite(&self) -> Result<(), Error> {
+ pub async fn accept_invite(&self) -> Result<(), Toast> {
let matrix_room = self.matrix_room();
if let MatrixRoom::Invited(matrix_room) = matrix_room {
@@ -1065,7 +1064,7 @@ impl Room {
Ok(result) => Ok(result),
Err(error) => {
error!("Accepting invitation failed: {}", error);
- let error = Error::new(clone!(@strong self as room => move |_| {
+ let error = Toast::new(clone!(@strong self as room => move |_| {
let error_message = gettext("Failed to accept invitation for <widget>. Try again
later.");
let room_pill = Pill::new();
room_pill.set_room(Some(room.clone()));
@@ -1086,7 +1085,7 @@ impl Room {
}
}
- pub async fn reject_invite(&self) -> Result<(), Error> {
+ pub async fn reject_invite(&self) -> Result<(), Toast> {
let matrix_room = self.matrix_room();
if let MatrixRoom::Invited(matrix_room) = matrix_room {
@@ -1095,7 +1094,7 @@ impl Room {
Ok(result) => Ok(result),
Err(error) => {
error!("Rejecting invitation failed: {}", error);
- let error = Error::new(clone!(@strong self as room => move |_| {
+ let error = Toast::new(clone!(@strong self as room => move |_| {
let error_message = gettext("Failed to reject invitation for <widget>. Try again
later.");
let room_pill = Pill::new();
room_pill.set_room(Some(room.clone()));
@@ -1242,7 +1241,7 @@ impl Room {
if !failed_invites.is_empty() {
let no_failed = failed_invites.len();
let first_failed = failed_invites.first().unwrap();
- let error = Error::new(
+ let error = Toast::new(
clone!(@strong self as room, @strong first_failed => move |_| {
// TODO: should we show all the failed users?
let error_message = if no_failed == 1 {
diff --git a/src/session/room_list.rs b/src/session/room_list.rs
index 5aaac3bc6..b4c0c09cb 100644
--- a/src/session/room_list.rs
+++ b/src/session/room_list.rs
@@ -10,8 +10,9 @@ use matrix_sdk::{
};
use crate::{
+ components::Toast,
session::{room::Room, Session},
- spawn, spawn_tokio, Error,
+ spawn, spawn_tokio,
};
mod imp {
@@ -321,7 +322,7 @@ impl RoomList {
Err(error) => {
obj.pending_rooms_remove(&identifier);
error!("Joining room {} failed: {}", identifier, error);
- let error = Error::new(
+ let error = Toast::new(
clone!(@strong obj => move |_| {
let error_message = gettext!(
"Failed to join room {}. Try again later.", identifier
diff --git a/src/session/verification/identity_verification.rs
b/src/session/verification/identity_verification.rs
index 0d6598536..9a3ea6dad 100644
--- a/src/session/verification/identity_verification.rs
+++ b/src/session/verification/identity_verification.rs
@@ -22,9 +22,10 @@ use tokio::sync::mpsc;
use super::{VERIFICATION_CREATION_TIMEOUT, VERIFICATION_RECEIVE_TIMEOUT};
use crate::{
+ components::Toast,
contrib::Camera,
session::{user::UserExt, Session, User},
- spawn, spawn_tokio, Error,
+ spawn, spawn_tokio,
};
#[derive(Debug, Eq, PartialEq, Clone, Copy, glib::Enum)]
@@ -653,7 +654,7 @@ impl IdentityVerification {
gettext("An unknown error occurred during the verification process.")
});
- let error = Error::new(move |_| {
+ let error = Toast::new(move |_| {
let error_label = gtk::Label::builder()
.label(&error_message)
.wrap(true)
diff --git a/src/window.rs b/src/window.rs
index 843ead1a0..ad4cf1f27 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -5,9 +5,9 @@ use gtk::{self, gio, glib, glib::clone, prelude::*, subclass::prelude::*, Compos
use log::warn;
use crate::{
- components::InAppNotification,
+ components::{InAppNotification, Toast},
config::{APP_ID, PROFILE},
- secret, Application, Error, Greeter, Login, Session, UserFacingError,
+ secret, Application, Greeter, Login, Session, UserFacingError,
};
mod imp {
@@ -38,7 +38,7 @@ mod imp {
type ParentType = adw::ApplicationWindow;
fn class_init(klass: &mut Self::Class) {
- Error::static_type();
+ Toast::static_type();
InAppNotification::static_type();
Self::bind_template(klass);
}
@@ -181,7 +181,7 @@ impl Window {
Err(error) => {
warn!("Failed to restore previous sessions: {:?}", error);
let error_string = error.to_user_facing();
- self.append_error(&Error::new(move |_| {
+ self.append_error(&Toast::new(move |_| {
let error_label = gtk::Label::builder()
.label(
&(gettext("Unable to restore previous sessions")
@@ -261,7 +261,7 @@ impl Window {
}
/// This appends a new error to the list of errors
- pub fn append_error(&self, error: &Error) {
+ pub fn append_error(&self, error: &Toast) {
self.imp().error_list.append(error);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]