fileModel: Use next_files_future instead of next

Fixes #429
This commit is contained in:
Sophie Herold 2024-11-20 17:06:54 +01:00
parent 9546def0fb
commit dca62a85df

View file

@ -1,6 +1,5 @@
// Copyright (c) 2022-2024 Sophie Herold // Copyright (c) 2022-2024 Sophie Herold
// Copyright (c) 2022 Christopher Davis // Copyright (c) 2022 Christopher Davis
// Copyright (c) 2023 Gage Berz
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -177,32 +176,40 @@ impl LpFileModel {
.await .await
.context(gettext("Could not list other files in directory."))?; .context(gettext("Could not list other files in directory."))?;
for info in enumerator { loop {
let info = enumerator.next_files_future(1, glib::Priority::LOW).await;
match info { match info {
Err(err) => { Err(err) => {
log::warn!("Unreadable entry in directory: {err}"); log::warn!("Unreadable entry in directory: {err}");
break;
} }
Ok(info) => { Ok(info) => {
// GVfs smb does not provide a CONTENT_TYPE if the content type is ambiguous. if let Some(info) = info.first() {
// This happens for png/apng. Since we only need to know if something is // GVfs smb does not provide a CONTENT_TYPE if the content type is
// probably an image, we can use the FAST_CONTENT_TYPE in these cases. // ambiguous. This happens for png/apng. Since we
let content_type = // only need to know if something is probably an
if info.has_attribute(gio::FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) { // image, we can use the FAST_CONTENT_TYPE in these cases.
let content_type = if info
.has_attribute(gio::FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)
{
info.content_type() info.content_type()
} else { } else {
info.attribute_string(gio::FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE) info.attribute_string(gio::FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE)
}; };
if let Some(content_type) = if let Some(content_type) =
content_type.and_then(|x| gio::content_type_get_mime_type(&x)) content_type.and_then(|x| gio::content_type_get_mime_type(&x))
{ {
// Filter out non-images types. The final decision if images are // Filter out non-images types. The final decision if images are
// supported/kept will later be done by glycin when starting to load the // supported/kept will later be done by glycin when starting to load the
// images. Usually by inspecting the magic bytes. // images. Usually by inspecting the magic bytes.
if content_type.starts_with("image/") && !info.is_hidden() { if content_type.starts_with("image/") && !info.is_hidden() {
let file = directory.child(info.name()); let file = directory.child(info.name());
new_files.insert(file.uri(), Entry::new(file).await); new_files.insert(file.uri(), Entry::new(file).await);
}
} }
} else {
break;
} }
} }
} }