mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-12 21:51:20 +00:00
implement separated mod with options for failure component
This commit is contained in:
parent
1d4a3cbd42
commit
931dc1cfc2
@ -190,7 +190,7 @@ impl Page {
|
||||
|
||||
// Update widget
|
||||
self.content
|
||||
.set_status_failure(title.as_str(), description.as_str());
|
||||
.set_status_failure(Some(title.as_str()), Some(description.as_str()));
|
||||
|
||||
// Update meta
|
||||
self.meta.replace(Meta {
|
||||
@ -523,8 +523,8 @@ impl Page {
|
||||
|
||||
// Update widget
|
||||
content.set_status_failure(
|
||||
title.as_str(),
|
||||
description.as_str(),
|
||||
Some(title.as_str()),
|
||||
Some(description.as_str())
|
||||
);
|
||||
|
||||
// Update meta
|
||||
@ -545,6 +545,16 @@ impl Page {
|
||||
ClientMime::ImagePng | ClientMime::ImageGif |
|
||||
ClientMime::ImageJpeg | ClientMime::ImageWebp
|
||||
) => {
|
||||
// Init loading placeholder
|
||||
/* @TODO count bytes on download
|
||||
let title = gformat!("Loading..");
|
||||
let description = gformat!(""); // collect totals here, invisible on start
|
||||
|
||||
content.set_status_loading(
|
||||
Some(&title),
|
||||
Some(&description)
|
||||
); */
|
||||
|
||||
match Pixbuf::from_stream( // @TODO async
|
||||
&connection.input_stream(),
|
||||
None::<&Cancellable>,
|
||||
@ -567,7 +577,10 @@ impl Page {
|
||||
let description = gformat!("{}", reason.message());
|
||||
|
||||
// Update widget
|
||||
content.set_status_failure(title.as_str(), description.as_str());
|
||||
content.set_status_failure(
|
||||
Some(title.as_str()),
|
||||
Some(description.as_str())
|
||||
);
|
||||
|
||||
// Update meta
|
||||
meta.replace(Meta {
|
||||
@ -601,8 +614,8 @@ impl Page {
|
||||
|
||||
// Update widget
|
||||
content.set_status_failure(
|
||||
title.as_str(),
|
||||
description.as_str(),
|
||||
Some(title.as_str()),
|
||||
Some(description.as_str()),
|
||||
);
|
||||
|
||||
// Update meta
|
||||
@ -642,8 +655,8 @@ impl Page {
|
||||
);
|
||||
},
|
||||
None => content.set_status_failure(
|
||||
&"Oops",
|
||||
&"Could not parse redirect meta"
|
||||
Some(&"Oops"),
|
||||
Some(&"Could not parse redirect meta")
|
||||
),
|
||||
}
|
||||
|
||||
@ -679,8 +692,10 @@ impl Page {
|
||||
};
|
||||
|
||||
// Update widget
|
||||
content
|
||||
.set_status_failure(title.as_str(), description.as_str());
|
||||
content.set_status_failure(
|
||||
Some(title.as_str()),
|
||||
Some(description.as_str())
|
||||
);
|
||||
|
||||
// Update meta
|
||||
meta.replace(Meta {
|
||||
@ -702,8 +717,10 @@ impl Page {
|
||||
let description = gformat!("Request error: {}", reason.message());
|
||||
|
||||
// Update widget
|
||||
content
|
||||
.set_status_failure(title.as_str(), description.as_str());
|
||||
content.set_status_failure(
|
||||
Some(title.as_str()),
|
||||
Some(description.as_str())
|
||||
);
|
||||
|
||||
// Update meta
|
||||
meta.replace(Meta {
|
||||
@ -725,8 +742,10 @@ impl Page {
|
||||
let description = gformat!("Connection error: {}", reason.message());
|
||||
|
||||
// Update widget
|
||||
content
|
||||
.set_status_failure(title.as_str(), description.as_str());
|
||||
content.set_status_failure(
|
||||
Some(title.as_str()),
|
||||
Some(description.as_str())
|
||||
);
|
||||
|
||||
// Update meta
|
||||
meta.replace(Meta {
|
||||
|
@ -40,10 +40,10 @@ impl Content {
|
||||
self.gobject.append(image.gobject());
|
||||
}
|
||||
|
||||
pub fn set_status_failure(&self, title: &str, description: &str) {
|
||||
pub fn set_status_failure(&self, title: Option<&str>, description: Option<&str>) {
|
||||
self.clean();
|
||||
|
||||
let status_default = Status::new_error(title, description);
|
||||
let status_default = Status::new_failure(title, description);
|
||||
|
||||
self.gobject.append(status_default.gobject());
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
mod failure;
|
||||
mod loading;
|
||||
|
||||
use failure::Failure;
|
||||
use loading::Loading;
|
||||
|
||||
use adw::StatusPage;
|
||||
|
||||
@ -9,14 +11,26 @@ pub struct Status {
|
||||
}
|
||||
|
||||
impl Status {
|
||||
// Construct
|
||||
pub fn new_error(title: &str, description: &str) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Create new default failure component
|
||||
pub fn new_failure(title: Option<&str>, description: Option<&str>) -> Self {
|
||||
Self {
|
||||
gobject: Failure::new(title, description),
|
||||
gobject: Failure::new(title, description).gobject().clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create new default loading component
|
||||
///
|
||||
/// Useful as the placeholder widget for async operations
|
||||
pub fn new_loading(title: Option<&str>, description: Option<&str>) -> Self {
|
||||
Self {
|
||||
gobject: Loading::new(title, description).gobject().clone(),
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn gobject(&self) -> &StatusPage {
|
||||
&self.gobject
|
||||
}
|
||||
|
@ -1,15 +1,20 @@
|
||||
mod widget;
|
||||
use widget::Widget;
|
||||
|
||||
use adw::StatusPage;
|
||||
|
||||
pub struct Failure {
|
||||
// nothing yet..
|
||||
widget: Widget,
|
||||
}
|
||||
|
||||
impl Failure {
|
||||
pub fn new(title: &str, description: &str) -> StatusPage {
|
||||
StatusPage::builder()
|
||||
.description(description)
|
||||
.icon_name("dialog-error-symbolic")
|
||||
.title(title)
|
||||
.build()
|
||||
pub fn new(title: Option<&str>, description: Option<&str>) -> Self {
|
||||
Self {
|
||||
widget: Widget::new(title, description),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn gobject(&self) -> &StatusPage {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
use adw::StatusPage;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: StatusPage,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Constructors
|
||||
|
||||
/// Create new default widget configuration
|
||||
pub fn new(title: Option<&str>, description: Option<&str>) -> Self {
|
||||
let gobject = StatusPage::new();
|
||||
|
||||
if let Some(value) = title {
|
||||
gobject.set_title(value);
|
||||
}
|
||||
|
||||
gobject.set_description(description);
|
||||
|
||||
Self { gobject }
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn gobject(&self) -> &StatusPage {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user