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
|
|
@ -32,7 +32,6 @@ use crate::deps::*;
|
|||
use crate::decoder::tiling::FrameBufferExt;
|
||||
use crate::decoder::{self, tiling, Decoder, DecoderUpdate};
|
||||
use crate::image_metadata::LpImageMetadata;
|
||||
use crate::util::gettext::*;
|
||||
use crate::util::Gesture;
|
||||
|
||||
use crate::util::spawn;
|
||||
|
|
@ -43,7 +42,6 @@ use once_cell::sync::Lazy;
|
|||
use once_cell::unsync::OnceCell;
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Default background color around images and behind transparent images
|
||||
|
|
@ -107,7 +105,6 @@ mod imp {
|
|||
#[derive(Debug, Default)]
|
||||
pub struct LpImage {
|
||||
pub(super) file: RefCell<Option<gio::File>>,
|
||||
pub(super) path: RefCell<Option<PathBuf>>,
|
||||
pub(super) is_deleted: Cell<bool>,
|
||||
/// Track changes to this image
|
||||
pub(super) file_monitor: RefCell<Option<gio::FileMonitor>>,
|
||||
|
|
@ -194,9 +191,6 @@ mod imp {
|
|||
glib::ParamSpecObject::builder::<gio::File>("file")
|
||||
.read_only()
|
||||
.build(),
|
||||
glib::ParamSpecVariant::builder("path", glib::VariantTy::BYTE_STRING)
|
||||
.read_only()
|
||||
.build(),
|
||||
glib::ParamSpecBoolean::builder("is-deleted")
|
||||
.read_only()
|
||||
.build(),
|
||||
|
|
@ -242,7 +236,6 @@ mod imp {
|
|||
let obj = self.obj();
|
||||
match pspec.name() {
|
||||
"file" => obj.file().to_value(),
|
||||
"path" => obj.path().to_variant().to_value(),
|
||||
"is-deleted" => obj.is_deleted().to_value(),
|
||||
"is-loaded" => obj.is_loaded().to_value(),
|
||||
"error" => obj.error().to_value(),
|
||||
|
|
@ -743,15 +736,9 @@ glib::wrapper! {
|
|||
|
||||
impl LpImage {
|
||||
pub async fn load(&self, file: &gio::File) {
|
||||
let path = file.path().unwrap();
|
||||
self.set_file(&file);
|
||||
log::debug!("Loading file {}", file.uri());
|
||||
|
||||
if !path.is_file() {
|
||||
self.set_error(anyhow::Error::msg(gettext("File does not exist")));
|
||||
return;
|
||||
}
|
||||
|
||||
log::debug!("Loading file {path:?}");
|
||||
self.set_file(file);
|
||||
|
||||
let tiles = &self.imp().frame_buffer;
|
||||
|
||||
|
|
@ -920,16 +907,10 @@ impl LpImage {
|
|||
self.imp().file.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn path(&self) -> Option<PathBuf> {
|
||||
self.imp().path.borrow().clone()
|
||||
}
|
||||
|
||||
pub(super) fn set_file(&self, file: &gio::File) {
|
||||
let imp = self.imp();
|
||||
|
||||
imp.file.replace(Some(file.clone()));
|
||||
imp.path.replace(file.path());
|
||||
self.notify("path");
|
||||
|
||||
let monitor = file.monitor_file(gio::FileMonitorFlags::WATCH_MOVES, gio::Cancellable::NONE);
|
||||
if let Ok(m) = &monitor {
|
||||
|
|
@ -953,7 +934,7 @@ impl LpImage {
|
|||
match event {
|
||||
gio::FileMonitorEvent::Renamed => {
|
||||
if let Some(file) = file_b {
|
||||
log::debug!("Moved to {:?}", file.path());
|
||||
log::debug!("Moved to {}", file.uri());
|
||||
self.set_file(file);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@ use gtk::prelude::*;
|
|||
use gtk::CompositeTemplate;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
|
|
@ -151,7 +149,7 @@ impl LpImagePage {
|
|||
pub fn from_file(file: &gio::File) -> Self {
|
||||
let obj = glib::Object::new::<Self>();
|
||||
|
||||
obj.imp().image.set_file(&file);
|
||||
obj.imp().image.set_file(file);
|
||||
|
||||
spawn(clone!(@weak obj, @strong file => async move {
|
||||
let imp = obj.imp();
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ use gtk::CompositeTemplate;
|
|||
use once_cell::sync::Lazy;
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
// The number of pages we want to buffer
|
||||
// on either side of the current page.
|
||||
|
|
@ -139,7 +138,7 @@ mod imp {
|
|||
|
||||
let view = &*obj;
|
||||
signal_group.connect_closure(
|
||||
"notify::path",
|
||||
"notify::file",
|
||||
true,
|
||||
glib::closure_local!(@watch view => move |_: LpImage, _: glib::ParamSpec| {
|
||||
view.current_image_path_changed();
|
||||
|
|
@ -333,7 +332,7 @@ impl LpImageView {
|
|||
.and_then(|x| self.model().index_of(&x))
|
||||
.unwrap_or_default();
|
||||
|
||||
let page = if let Some(page) = sliding_view.get(&new_file) {
|
||||
let page = if let Some(page) = sliding_view.get(new_file) {
|
||||
page
|
||||
} else {
|
||||
let page = LpImagePage::from_file(new_file);
|
||||
|
|
@ -362,22 +361,22 @@ impl LpImageView {
|
|||
|
||||
self.imp().preserve_content.set(false);
|
||||
|
||||
let existing = dbg!(sliding_view.pages());
|
||||
let target = dbg!(self.model().files_around(current_file, BUFFER));
|
||||
let existing = sliding_view.pages();
|
||||
let target = self.model().files_around(current_file, BUFFER);
|
||||
|
||||
// remove old pages
|
||||
for (uri, page) in &existing {
|
||||
if !target.contains_key(uri) {
|
||||
sliding_view.remove(dbg!(page));
|
||||
sliding_view.remove(page);
|
||||
}
|
||||
}
|
||||
|
||||
// add missing pages or put in correct position
|
||||
for (position, (_, file)) in target.iter().enumerate() {
|
||||
if let Some(page) = existing.get(&file.uri()) {
|
||||
sliding_view.move_to(page, dbg!(position));
|
||||
sliding_view.move_to(page, position);
|
||||
} else {
|
||||
sliding_view.insert(&LpImagePage::from_file(file), dbg!(position));
|
||||
sliding_view.insert(&LpImagePage::from_file(file), position);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ use indexmap::IndexMap;
|
|||
use once_cell::sync::{Lazy, OnceCell};
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
//use std::path::{Path, PathBuf};
|
||||
|
||||
static SCROLL_DAMPING_RATIO: f64 = 1.;
|
||||
static SCROLL_MASS: f64 = 0.5;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue