image: Use enum for specific errors
This commit is contained in:
parent
134c488dbd
commit
e08866a1da
6 changed files with 112 additions and 66 deletions
|
|
@ -27,6 +27,7 @@ use gtk::prelude::*;
|
|||
use gtk::CompositeTemplate;
|
||||
|
||||
use super::LpErrorDetails;
|
||||
use crate::decoder::DecoderError;
|
||||
use crate::deps::*;
|
||||
use crate::util::gettext::*;
|
||||
use crate::widgets::LpImage;
|
||||
|
|
@ -209,37 +210,47 @@ impl LpImagePage {
|
|||
let imp = self.imp();
|
||||
let image = self.image();
|
||||
|
||||
if image.is_unsupported() {
|
||||
let message = if glycin::Loader::supported_mime_types().await.is_empty() {
|
||||
// Translators: {} is replace with a version number
|
||||
gettext_f(
|
||||
"No image loaders available. Maybe the “glycin-loaders” package with compatibility version “{}+” is not installed.",
|
||||
[ format!("{}+", glycin::COMPAT_VERSION)])
|
||||
} else {
|
||||
let mime_type = image.metadata().mime_type().unwrap_or_default();
|
||||
let content_type = gio::content_type_from_mime_type(&mime_type).unwrap_or_default();
|
||||
let description = gio::content_type_get_description(&content_type).to_string();
|
||||
|
||||
if glycin::Loader::DEFAULT_MIME_TYPES.contains(&mime_type.as_str()) {
|
||||
// Translators: The first occurance of {} is replace with a description of the
|
||||
// format and the second with an id (mime-type) of the format.
|
||||
gettext_f(
|
||||
"The image format “{} ({})” is known but not installed.",
|
||||
[&description, &mime_type],
|
||||
)
|
||||
} else {
|
||||
// Translators: The first occurance of {} is replace with a description of the
|
||||
// format and the second with an id (mime-type) of the format.
|
||||
gettext_f(
|
||||
"Unknown image format “{} ({}).”",
|
||||
[&description, &mime_type],
|
||||
)
|
||||
}
|
||||
};
|
||||
if image.specific_error() == DecoderError::NoLoadersConfigured {
|
||||
// Translators: {} is replaced with a version number
|
||||
let message = gettext_f(
|
||||
"No image loaders available. Maybe the “glycin-loaders” package with compatibility version “{}” is not installed.",
|
||||
[ format!("{}+", glycin::COMPAT_VERSION)]);
|
||||
|
||||
imp.error_page.set_description(Some(&message));
|
||||
imp.stack.set_visible_child(&*imp.error_page);
|
||||
imp.error_more_info.set_visible(false);
|
||||
} else if image.specific_error() == DecoderError::UnsupportedFormat {
|
||||
let mime_type = image.metadata().mime_type().unwrap_or_default();
|
||||
let content_type = gio::content_type_from_mime_type(&mime_type).unwrap_or_default();
|
||||
let description = gio::content_type_get_description(&content_type).to_string();
|
||||
|
||||
let message = if glycin::Loader::DEFAULT_MIME_TYPES.contains(&mime_type.as_str()) {
|
||||
// Translators: The first occurance of {} is replace with a description of the
|
||||
// format and the second with an id (mime-type) of the format.
|
||||
gettext_f(
|
||||
"The image format “{} ({})” is known but not installed.",
|
||||
[&description, &mime_type],
|
||||
)
|
||||
} else {
|
||||
// Translators: The first occurance of {} is replace with a description of the
|
||||
// format and the second with an id (mime-type) of the format.
|
||||
gettext_f(
|
||||
"Unknown image format “{} ({}).”",
|
||||
[&description, &mime_type],
|
||||
)
|
||||
};
|
||||
|
||||
if let Some(err) = image.error() {
|
||||
imp.error_more_info.connect_clicked(glib::clone!(
|
||||
#[weak(rename_to = obj)]
|
||||
self,
|
||||
move |_| {
|
||||
LpErrorDetails::new(&obj.root().unwrap(), &err);
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
imp.error_page.set_description(Some(&message));
|
||||
imp.stack.set_visible_child(&*imp.error_page);
|
||||
} else if let Some(err) = image.error() {
|
||||
imp.error_more_info.connect_clicked(glib::clone!(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue