decoder: Use GFile instead of PathBuf
This allows to show images from locations that don't have a representation with path. This also works around not being able to read files in trash:/// Closes #56 Part-of: <https://gitlab.gnome.org/Incubator/loupe/-/merge_requests/174>
This commit is contained in:
parent
032707a210
commit
fad8bb7939
15 changed files with 119 additions and 107 deletions
|
|
@ -154,6 +154,25 @@ pub async fn untrash(path: &Path) -> anyhow::Result<()> {
|
|||
error
|
||||
}
|
||||
|
||||
pub trait BufReadSeek: std::io::BufRead + std::io::Seek {}
|
||||
|
||||
impl BufReadSeek for std::io::BufReader<gio::InputStreamRead<gio::FileInputStream>> {}
|
||||
|
||||
pub trait ToBufRead {
|
||||
fn to_buf_read(&self) -> anyhow::Result<Box<dyn BufReadSeek>>;
|
||||
}
|
||||
|
||||
impl ToBufRead for gio::File {
|
||||
fn to_buf_read(&self) -> anyhow::Result<Box<dyn BufReadSeek>> {
|
||||
let read = self
|
||||
.read(gio::Cancellable::NONE)
|
||||
.context(gettext("Failed to open image"))?
|
||||
.into_read();
|
||||
|
||||
Ok(Box::new(std::io::BufReader::new(read)))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Position {
|
||||
First,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue