error: Remove matrix_error field from Error

This commit is contained in:
Enterprisey 2021-09-30 02:25:57 -07:00 committed by Daniel Glus
parent 6639708f99
commit 41083196ea
3 changed files with 15 additions and 38 deletions

View file

@ -1,17 +1,13 @@
use gtk::{glib, subclass::prelude::*};
use matrix_sdk::Error as MatrixError;
type WidgetBuilderFn = Box<dyn Fn(&super::Error) -> Option<gtk::Widget> + 'static>;
mod imp {
use super::*;
use once_cell::sync::OnceCell;
use std::cell::RefCell;
#[derive(Default)]
pub struct Error {
pub matrix_error: OnceCell<MatrixError>,
pub widget_builder: RefCell<Option<WidgetBuilderFn>>,
}
@ -31,23 +27,12 @@ glib::wrapper! {
}
impl Error {
pub fn new<F: Fn(&Self) -> Option<gtk::Widget> + 'static>(error: MatrixError, f: F) -> Self {
pub fn new<F: Fn(&Self) -> Option<gtk::Widget> + 'static>(f: F) -> Self {
let obj: Self = glib::Object::new(&[]).expect("Failed to create Error");
obj.set_matrix_error(error);
obj.set_widget_builder(f);
obj
}
fn set_matrix_error(&self, error: MatrixError) {
let priv_ = imp::Error::from_instance(self);
priv_.matrix_error.set(error).unwrap()
}
pub fn matrix_error(&self) -> &MatrixError {
let priv_ = imp::Error::from_instance(self);
priv_.matrix_error.get().unwrap()
}
/// Set a function that builds the widget used to display this error in the UI
pub fn set_widget_builder<F: Fn(&Self) -> Option<gtk::Widget> + 'static>(&self, f: F) {
let priv_ = imp::Error::from_instance(self);

View file

@ -414,7 +414,6 @@ impl Room {
Err(error) => {
error!("Couldnt set the room category: {}", error);
let error = Error::new(
error,
clone!(@weak obj => @default-return None, move |_| {
let error_message = gettext!(
"Failed to move <widget> from {} to {}.",
@ -889,16 +888,13 @@ impl Room {
Ok(result) => Ok(result),
Err(error) => {
error!("Accepting invitation failed: {}", error);
let error = Error::new(
error,
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()));
let error_label = LabelWithWidgets::new(&error_message, vec![room_pill]);
Some(error_label.upcast())
}),
);
let error = Error::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()));
let error_label = LabelWithWidgets::new(&error_message, vec![room_pill]);
Some(error_label.upcast())
}));
if let Some(window) = self.session().parent_window() {
window.append_error(&error);
@ -923,16 +919,13 @@ impl Room {
Ok(result) => Ok(result),
Err(error) => {
error!("Rejecting invitation failed: {}", error);
let error = Error::new(
error,
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()));
let error_label = LabelWithWidgets::new(&error_message, vec![room_pill]);
Some(error_label.upcast())
}),
);
let error = Error::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()));
let error_label = LabelWithWidgets::new(&error_message, vec![room_pill]);
Some(error_label.upcast())
}));
if let Some(window) = self.session().parent_window() {
window.append_error(&error);

View file

@ -329,7 +329,6 @@ impl RoomList {
obj.pending_rooms_remove(&identifier);
error!("Joining room {} failed: {}", identifier, error);
let error = Error::new(
matrix_sdk::Error::Http(error),
clone!(@strong obj => move |_| {
let error_message = gettext!(
"Failed to join room {}. Try again later.", identifier