mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
implement separated mod with options for failure component
This commit is contained in:
parent
1d4a3cbd42
commit
931dc1cfc2
5 changed files with 92 additions and 26 deletions
|
|
@ -190,7 +190,7 @@ impl Page {
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
self.content
|
self.content
|
||||||
.set_status_failure(title.as_str(), description.as_str());
|
.set_status_failure(Some(title.as_str()), Some(description.as_str()));
|
||||||
|
|
||||||
// Update meta
|
// Update meta
|
||||||
self.meta.replace(Meta {
|
self.meta.replace(Meta {
|
||||||
|
|
@ -523,8 +523,8 @@ impl Page {
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
content.set_status_failure(
|
content.set_status_failure(
|
||||||
title.as_str(),
|
Some(title.as_str()),
|
||||||
description.as_str(),
|
Some(description.as_str())
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update meta
|
// Update meta
|
||||||
|
|
@ -545,6 +545,16 @@ impl Page {
|
||||||
ClientMime::ImagePng | ClientMime::ImageGif |
|
ClientMime::ImagePng | ClientMime::ImageGif |
|
||||||
ClientMime::ImageJpeg | ClientMime::ImageWebp
|
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
|
match Pixbuf::from_stream( // @TODO async
|
||||||
&connection.input_stream(),
|
&connection.input_stream(),
|
||||||
None::<&Cancellable>,
|
None::<&Cancellable>,
|
||||||
|
|
@ -567,7 +577,10 @@ impl Page {
|
||||||
let description = gformat!("{}", reason.message());
|
let description = gformat!("{}", reason.message());
|
||||||
|
|
||||||
// Update widget
|
// 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
|
// Update meta
|
||||||
meta.replace(Meta {
|
meta.replace(Meta {
|
||||||
|
|
@ -601,8 +614,8 @@ impl Page {
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
content.set_status_failure(
|
content.set_status_failure(
|
||||||
title.as_str(),
|
Some(title.as_str()),
|
||||||
description.as_str(),
|
Some(description.as_str()),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update meta
|
// Update meta
|
||||||
|
|
@ -642,8 +655,8 @@ impl Page {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
None => content.set_status_failure(
|
None => content.set_status_failure(
|
||||||
&"Oops",
|
Some(&"Oops"),
|
||||||
&"Could not parse redirect meta"
|
Some(&"Could not parse redirect meta")
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -679,8 +692,10 @@ impl Page {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
content
|
content.set_status_failure(
|
||||||
.set_status_failure(title.as_str(), description.as_str());
|
Some(title.as_str()),
|
||||||
|
Some(description.as_str())
|
||||||
|
);
|
||||||
|
|
||||||
// Update meta
|
// Update meta
|
||||||
meta.replace(Meta {
|
meta.replace(Meta {
|
||||||
|
|
@ -702,8 +717,10 @@ impl Page {
|
||||||
let description = gformat!("Request error: {}", reason.message());
|
let description = gformat!("Request error: {}", reason.message());
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
content
|
content.set_status_failure(
|
||||||
.set_status_failure(title.as_str(), description.as_str());
|
Some(title.as_str()),
|
||||||
|
Some(description.as_str())
|
||||||
|
);
|
||||||
|
|
||||||
// Update meta
|
// Update meta
|
||||||
meta.replace(Meta {
|
meta.replace(Meta {
|
||||||
|
|
@ -725,8 +742,10 @@ impl Page {
|
||||||
let description = gformat!("Connection error: {}", reason.message());
|
let description = gformat!("Connection error: {}", reason.message());
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
content
|
content.set_status_failure(
|
||||||
.set_status_failure(title.as_str(), description.as_str());
|
Some(title.as_str()),
|
||||||
|
Some(description.as_str())
|
||||||
|
);
|
||||||
|
|
||||||
// Update meta
|
// Update meta
|
||||||
meta.replace(Meta {
|
meta.replace(Meta {
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,10 @@ impl Content {
|
||||||
self.gobject.append(image.gobject());
|
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();
|
self.clean();
|
||||||
|
|
||||||
let status_default = Status::new_error(title, description);
|
let status_default = Status::new_failure(title, description);
|
||||||
|
|
||||||
self.gobject.append(status_default.gobject());
|
self.gobject.append(status_default.gobject());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
mod failure;
|
mod failure;
|
||||||
|
mod loading;
|
||||||
|
|
||||||
use failure::Failure;
|
use failure::Failure;
|
||||||
|
use loading::Loading;
|
||||||
|
|
||||||
use adw::StatusPage;
|
use adw::StatusPage;
|
||||||
|
|
||||||
|
|
@ -9,14 +11,26 @@ pub struct Status {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Status {
|
impl Status {
|
||||||
// Construct
|
// Constructors
|
||||||
pub fn new_error(title: &str, description: &str) -> Self {
|
|
||||||
|
/// Create new default failure component
|
||||||
|
pub fn new_failure(title: Option<&str>, description: Option<&str>) -> Self {
|
||||||
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
|
// Getters
|
||||||
|
|
||||||
pub fn gobject(&self) -> &StatusPage {
|
pub fn gobject(&self) -> &StatusPage {
|
||||||
&self.gobject
|
&self.gobject
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,20 @@
|
||||||
|
mod widget;
|
||||||
|
use widget::Widget;
|
||||||
|
|
||||||
use adw::StatusPage;
|
use adw::StatusPage;
|
||||||
|
|
||||||
pub struct Failure {
|
pub struct Failure {
|
||||||
// nothing yet..
|
widget: Widget,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Failure {
|
impl Failure {
|
||||||
pub fn new(title: &str, description: &str) -> StatusPage {
|
pub fn new(title: Option<&str>, description: Option<&str>) -> Self {
|
||||||
StatusPage::builder()
|
Self {
|
||||||
.description(description)
|
widget: Widget::new(title, description),
|
||||||
.icon_name("dialog-error-symbolic")
|
}
|
||||||
.title(title)
|
}
|
||||||
.build()
|
|
||||||
|
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…
Add table
Add a link
Reference in a new issue