window: i18n for filter name and add 'all files'

Part-of: <https://gitlab.gnome.org/Incubator/loupe/-/merge_requests/195>
This commit is contained in:
Sophie Herold 2023-04-21 16:53:12 +02:00
parent 8cbe670498
commit 9d5dfd8728
2 changed files with 19 additions and 15 deletions

View file

@ -171,7 +171,7 @@ impl Decoder {
gio::Cancellable::NONE, gio::Cancellable::NONE,
) )
.context("Could not read content type information")?; .context("Could not read content type information")?;
if let Some(content_type) = file_info if let Some(mime_type) = file_info
.content_type() .content_type()
.as_ref() .as_ref()
.and_then(|x| gio::content_type_get_mime_type(x)) .and_then(|x| gio::content_type_get_mime_type(x))
@ -179,19 +179,14 @@ impl Decoder {
// Known things we want to match here are // Known things we want to match here are
// - image/svg+xml // - image/svg+xml
// - image/svg+xml-compressed // - image/svg+xml-compressed
if content_type.split('+').next() == Some("image/svg") { if mime_type.split('+').next() == Some("image/svg") {
update_sender.send(DecoderUpdate::Format(ImageFormat::Svg)); update_sender.send(DecoderUpdate::Format(ImageFormat::Svg));
return Ok(FormatDecoder::Svg(Svg::new(file, update_sender, tiles))); return Ok(FormatDecoder::Svg(Svg::new(file, update_sender, tiles)));
} else if ["image/avif", "image/heif", "image/heic"] } else if ["image/avif", "image/heif", "image/heic"].contains(&mime_type.as_str()) {
.contains(&content_type.as_str())
{
update_sender.send(DecoderUpdate::Format(ImageFormat::Heif)); update_sender.send(DecoderUpdate::Format(ImageFormat::Heif));
return Ok(FormatDecoder::Heif(Heif::new(file, update_sender, tiles))); return Ok(FormatDecoder::Heif(Heif::new(file, update_sender, tiles)));
} else { } else {
bail!(gettext_f( bail!(gettext_f("Unknown image format: {}", &[mime_type.as_str()]));
"Unknown image format: {}",
&[content_type.as_str()]
));
} }
} }
} }

View file

@ -415,16 +415,25 @@ impl LpWindow {
} }
async fn pick_file(&self) { async fn pick_file(&self) {
let filter_store = gio::ListStore::new(gtk::FileFilter::static_type()); let filter_list = gio::ListStore::new(gtk::FileFilter::static_type());
let filter = gtk::FileFilter::new(); let filter_supported_formats = gtk::FileFilter::new();
filter.set_property("name", &String::from("Supported image files")); filter_supported_formats.set_name(Some(&gettext("Supported image formats")));
filter.add_mime_type("image/*"); filter_supported_formats.add_mime_type("image/*");
filter_store.append(&filter); // Manual support for Farbfeld since it has no mime type
filter_supported_formats.add_suffix("ff");
let filter_all_files = gtk::FileFilter::new();
filter_all_files.set_name(Some(&gettext("All files")));
filter_all_files.add_pattern("*");
filter_list.append(&filter_supported_formats);
filter_list.append(&filter_all_files);
let chooser = gtk::FileDialog::builder() let chooser = gtk::FileDialog::builder()
.title(gettext("Open Image")) .title(gettext("Open Image"))
.filters(&filter_store) .filters(&filter_list)
.default_filter(&filter_supported_formats)
.modal(true) .modal(true)
.build(); .build();