mirror of
https://github.com/narrrl/proton-drive-linux.git
synced 2026-11-14 17:32:00 +01:00
feat(gui,fuse,core): share photos, copy image, thumbnail strip in the viewer
- Share… in the grid's photo menu and the viewer's ⋮ menu opens the Share dialog by uid. The daemon accepts a uid from the Photos timeline for sharing (resolve_shareable), since the photos volume is in no mount. Photos in an album someone else shared are not offered. - Copy Image (Ctrl+C) puts the shown still on the clipboard. The viewer has its own toast overlay, so this and Save a Copy confirm over it instead of behind it. - A thumbnail strip along the viewer's bottom edge, on the gallery model, marks the shown photo and jumps on click. Several pictures can now wait for one thumbnail, so the strip and the grid tile don't steal it from each other. - PhotoItem carries place_id (serde default); the line under the viewer's title reads "Berlin · 12 of 340".
This commit is contained in:
1 parent
5f0b15fe70
commit
41212efdf3
24 files changed
+3307
-2780
No files matched your search
@@ -1792,6 +1792,11 @@ pub struct PhotoItem {
|
||||
/// the JPEG it shows is not the whole of what is stored.
|
||||
#[serde(default)]
|
||||
pub has_raw: bool,
|
||||
/// GeoNames id of the town the photo was taken in, when its location is
|
||||
/// known; [`crate::places::city`] names it. Older daemons omit it, and
|
||||
/// album entries do not carry it.
|
||||
#[serde(default)]
|
||||
pub place_id: Option<u32>,
|
||||
}
|
||||
|
||||
/// A daemon too old to classify a timeline entry is assumed to have served a
|
||||
|
||||
@@ -186,6 +186,8 @@ impl Db {
|
||||
// made, and it shows exactly what they put in it.
|
||||
group_size: 1,
|
||||
has_raw: false,
|
||||
// Album rows carry no location.
|
||||
place_id: None,
|
||||
})
|
||||
})?
|
||||
.collect::<rusqlite::Result<_>>()?;
|
||||
@@ -247,6 +249,8 @@ impl Db {
|
||||
// made, and it shows exactly what they put in it.
|
||||
group_size: 1,
|
||||
has_raw: false,
|
||||
// Album rows carry no location.
|
||||
place_id: None,
|
||||
})
|
||||
})?
|
||||
.collect::<rusqlite::Result<_>>()?;
|
||||
|
||||
@@ -40,6 +40,8 @@ pub struct StoredPhoto {
|
||||
/// Whether any member of the group is a camera raw file. The grid badges
|
||||
/// that, because the JPEG it shows is not the whole of what is stored.
|
||||
pub has_raw: bool,
|
||||
/// The town the photo was taken in, once its location has been read.
|
||||
pub place_id: Option<u32>,
|
||||
}
|
||||
|
||||
/// A town photos were taken in: its GeoNames id (see [`crate::places`]), how
|
||||
@@ -256,7 +258,7 @@ fn group_photos(entries: &[Grouped]) -> Vec<String> {
|
||||
/// own group: the column is `NULL` until the next refresh computes it, and a
|
||||
/// `NULL` would otherwise match nothing and drop the photo off the page.
|
||||
const PHOTO_SELECT: &str = "SELECT p.uid, p.capture_time, p.name, p.ratio, p.thumb_state, \
|
||||
p.kind, p.favorite, g.n, g.raw \
|
||||
p.kind, p.favorite, g.n, g.raw, p.place_id \
|
||||
FROM photos p JOIN (SELECT COALESCE(group_key, uid) AS k, COUNT(*) AS n, \
|
||||
MAX(kind = 2) AS raw FROM photos GROUP BY k) g ON g.k = COALESCE(p.group_key, p.uid)";
|
||||
|
||||
@@ -272,6 +274,7 @@ fn stored_photo(r: &rusqlite::Row<'_>) -> rusqlite::Result<StoredPhoto> {
|
||||
favorite: r.get::<_, i64>(6)? != 0,
|
||||
group_size: r.get::<_, i64>(7)?.max(1) as usize,
|
||||
has_raw: r.get::<_, i64>(8)? != 0,
|
||||
place_id: r.get(9)?,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -363,6 +363,23 @@ fn place_photos_carry_their_own_location() {
|
||||
);
|
||||
}
|
||||
|
||||
/// A timeline photo names the town it was taken in, so the viewer can show it;
|
||||
/// one without a location names none.
|
||||
#[test]
|
||||
fn timeline_photos_name_their_town() {
|
||||
let db = Db::open_in_memory().unwrap();
|
||||
db.photos_replace(&[
|
||||
located("b", 500, "IMG_5.JPG", BERLIN),
|
||||
TimelineRow::new("n", 400),
|
||||
])
|
||||
.unwrap();
|
||||
let berlin = db.photo_places().unwrap()[0].id;
|
||||
let mut photos = db.photos_by_uid(&["b".into(), "n".into()]).unwrap();
|
||||
photos.sort_by(|a, b| a.uid.cmp(&b.uid));
|
||||
let towns: Vec<Option<u32>> = photos.iter().map(|photo| photo.place_id).collect();
|
||||
assert_eq!(towns, [Some(berlin), None]);
|
||||
}
|
||||
|
||||
/// A refresh that skips an already-resolved photo keeps where it was taken; one
|
||||
/// that reads the node again takes what the node now says.
|
||||
#[test]
|
||||
|
||||
@@ -3168,6 +3168,28 @@ impl Core {
|
||||
)
|
||||
}
|
||||
|
||||
/// [`Core::resolve_anywhere`], widened to the Photos timeline for sharing.
|
||||
///
|
||||
/// A photo lives on the photos volume, which no location shows, so the
|
||||
/// residency proof above never finds it. The timeline in the `photos` table
|
||||
/// is this daemon's proof instead: it lists only photos on the user's own
|
||||
/// volume, which are theirs to share. A photo in an album someone else
|
||||
/// shared is not in it and stays refused.
|
||||
pub(crate) fn resolve_shareable(&self, uid: &str) -> CoreResult<NodeUid> {
|
||||
resolve_anywhere_with(
|
||||
uid,
|
||||
|uid| self.owns_visible_uid(uid),
|
||||
|uid| {
|
||||
let uid = uid.to_string();
|
||||
Ok(self.db.mirror_contains_uid(&uid)?
|
||||
|| !self
|
||||
.db
|
||||
.photos_by_uid(std::slice::from_ref(&uid))?
|
||||
.is_empty())
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn source_parent_uid(&self, ino: u64, rel: &Path) -> CoreResult<NodeUid> {
|
||||
let state = self.state();
|
||||
let entry = state
|
||||
|
||||
@@ -1027,6 +1027,7 @@ impl Core {
|
||||
favorite: photo.favorite,
|
||||
group_size: photo.group_size as u32,
|
||||
has_raw: photo.has_raw,
|
||||
place_id: photo.place_id,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ impl Core {
|
||||
role: &str,
|
||||
message: Option<&str>,
|
||||
) -> CoreResult<(usize, usize)> {
|
||||
let uid = self.resolve_anywhere(uid)?;
|
||||
let uid = self.resolve_shareable(uid)?;
|
||||
self.share_node_for_uid(&uid, emails, role, message)
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ impl Core {
|
||||
&self,
|
||||
uid: &str,
|
||||
) -> CoreResult<(Vec<ShareEntry>, Option<PublicLinkInfo>)> {
|
||||
let uid = self.resolve_anywhere(uid)?;
|
||||
let uid = self.resolve_shareable(uid)?;
|
||||
self.list_share_for_uid(&uid)
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ impl Core {
|
||||
kind: ShareEntryKind,
|
||||
role: &str,
|
||||
) -> CoreResult<()> {
|
||||
let uid = self.resolve_anywhere(uid)?;
|
||||
let uid = self.resolve_shareable(uid)?;
|
||||
self.update_share_role_for_uid(&uid, id, kind, role)
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ impl Core {
|
||||
id: &str,
|
||||
kind: ShareEntryKind,
|
||||
) -> CoreResult<()> {
|
||||
let uid = self.resolve_anywhere(uid)?;
|
||||
let uid = self.resolve_shareable(uid)?;
|
||||
self.remove_share_entry_for_uid(&uid, id, kind)
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ impl Core {
|
||||
password: Option<&str>,
|
||||
expires: Option<i64>,
|
||||
) -> CoreResult<PublicLinkInfo> {
|
||||
let uid = self.resolve_anywhere(uid)?;
|
||||
let uid = self.resolve_shareable(uid)?;
|
||||
self.create_public_link_for_uid(&uid, role, password, expires)
|
||||
}
|
||||
|
||||
@@ -391,7 +391,7 @@ impl Core {
|
||||
password: LinkChange<String>,
|
||||
expires: LinkChange<i64>,
|
||||
) -> CoreResult<PublicLinkInfo> {
|
||||
let uid = self.resolve_anywhere(uid)?;
|
||||
let uid = self.resolve_shareable(uid)?;
|
||||
self.update_public_link_for_uid(&uid, id, role, password, expires)
|
||||
}
|
||||
|
||||
@@ -460,7 +460,7 @@ impl Core {
|
||||
/// [`Core::remove_public_link`] for a node addressed through any daemon
|
||||
/// location.
|
||||
pub(crate) fn remove_public_link_by_uid(&self, uid: &str, id: &str) -> CoreResult<()> {
|
||||
let uid = self.resolve_anywhere(uid)?;
|
||||
let uid = self.resolve_shareable(uid)?;
|
||||
self.remove_public_link_for_uid(&uid, id)
|
||||
}
|
||||
|
||||
@@ -486,7 +486,7 @@ impl Core {
|
||||
|
||||
/// [`Core::stop_sharing`] for a node addressed through any daemon location.
|
||||
pub(crate) fn stop_sharing_by_uid(&self, uid: &str) -> CoreResult<StopSharingOutcome> {
|
||||
let uid = self.resolve_anywhere(uid)?;
|
||||
let uid = self.resolve_shareable(uid)?;
|
||||
self.stop_sharing_for_uid(&uid)
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,13 @@ scale.browser-status-meter trough { min-width: 140px; min-height: 6px; }
|
||||
.viewer-group-pill { color: white; background-color: rgba(0, 0, 0, 0.5); border-radius: 999px; min-height: 36px; padding: 0 14px; font-weight: 700; font-size: 0.85rem; }
|
||||
.viewer-group-pill:hover { background-color: rgba(0, 0, 0, 0.75); color: white; }
|
||||
.viewer-group-pill.lit { background-color: var(--accent-bg-color); color: var(--accent-fg-color); }
|
||||
/* The thumbnail strip along the lightbox's bottom edge, the photo on screen ringed in the accent. */
|
||||
.viewer-strip-bar { background: linear-gradient(to top, rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0)); padding: 28px 12px 10px 12px; }
|
||||
.viewer-strip { background: none; }
|
||||
.viewer-strip > row { padding: 2px; margin: 0 2px; border-radius: 8px; background: none; }
|
||||
.viewer-strip > row:hover { background-color: rgba(255, 255, 255, 0.15); }
|
||||
.viewer-strip > row:selected { background-color: var(--accent-bg-color); }
|
||||
.viewer-strip-thumb { border-radius: 6px; background-color: rgba(255, 255, 255, 0.08); }
|
||||
.viewer-nav-btn { background-color: rgba(0, 0, 0, 0.45); color: white; margin: 20px; min-width: 44px; min-height: 44px; border-radius: 50%; opacity: 0.7; transition: opacity 150ms ease, background-color 150ms ease; }
|
||||
.viewer-nav-btn:hover { background-color: rgba(0, 0, 0, 0.85); color: white; opacity: 1; }
|
||||
.viewer-nav-btn:disabled { opacity: 0; }
|
||||
|
||||
@@ -1562,6 +1562,7 @@ fn show_shortcuts(window: &adw::ApplicationWindow) {
|
||||
("f", gettext_noop("Fullscreen")),
|
||||
("F5", gettext_noop("Slideshow")),
|
||||
("F10", gettext_noop("More")),
|
||||
("<Control>c", gettext_noop("Copy Image")),
|
||||
("Delete", gettext_noop("Move to Trash")),
|
||||
("Escape <Alt>Left", gettext_noop("Close")),
|
||||
],
|
||||
@@ -2012,6 +2013,7 @@ mod tests {
|
||||
favorite: false,
|
||||
group_size: 2,
|
||||
has_raw: kind == PhotoKind::Raw,
|
||||
place_id: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -598,10 +598,7 @@ pub(crate) fn want_cover(ui: &Rc<Ui>, uid: String, picture: >k4::Picture) {
|
||||
if ui.gallery.photo_nothumb.borrow().contains(&uid) {
|
||||
return;
|
||||
}
|
||||
ui.gallery
|
||||
.thumb_wanted
|
||||
.borrow_mut()
|
||||
.insert(uid.clone(), picture.clone());
|
||||
ui.gallery.await_thumb(&uid, picture);
|
||||
let mut queue = ui.gallery.thumb_queue.borrow_mut();
|
||||
if !queue.contains(&uid) {
|
||||
queue.push_back(uid);
|
||||
|
||||
@@ -81,6 +81,11 @@ pub(crate) struct Viewer {
|
||||
/// rests; whether the pointer is over one of them (which keeps them up);
|
||||
/// and the pending fade-out.
|
||||
pub(crate) chrome: Vec<gtk4::Revealer>,
|
||||
/// The strip of thumbnails along the bottom, its selection (the photo on
|
||||
/// screen), and the revealer it fades with. Hidden in a slideshow.
|
||||
pub(crate) strip: gtk4::ListView,
|
||||
pub(crate) strip_selection: gtk4::SingleSelection,
|
||||
pub(crate) strip_reveal: gtk4::Revealer,
|
||||
pub(crate) chrome_hover: Cell<bool>,
|
||||
pub(crate) chrome_source: RefCell<Option<glib::SourceId>>,
|
||||
/// The ⋮ button, and whether its menu is open, which keeps the controls
|
||||
@@ -93,6 +98,8 @@ pub(crate) struct Viewer {
|
||||
pub(crate) slideshow: Cell<bool>,
|
||||
pub(crate) slide_source: RefCell<Option<glib::SourceId>>,
|
||||
pub(crate) slide_fullscreened: Cell<bool>,
|
||||
/// Toasts over the lightbox. The main window's would land behind it.
|
||||
pub(crate) toasts: adw::ToastOverlay,
|
||||
}
|
||||
|
||||
/// Camera/exposure/location facts pulled from a photo's own EXIF tags, as
|
||||
@@ -389,6 +396,7 @@ fn start_slideshow(ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
viewer.slide_fullscreened.set(true);
|
||||
}
|
||||
hide_chrome(viewer);
|
||||
viewer.strip_reveal.set_visible(false);
|
||||
if !viewer.loading.get() {
|
||||
arm_slide(ui, viewer);
|
||||
}
|
||||
@@ -397,6 +405,9 @@ fn start_slideshow(ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
/// Stop the slideshow, leaving fullscreen only if the slideshow entered it.
|
||||
fn stop_slideshow(viewer: &Rc<Viewer>) {
|
||||
viewer.slideshow.set(false);
|
||||
viewer
|
||||
.strip_reveal
|
||||
.set_visible(viewer.strip_selection.n_items() > 1);
|
||||
disarm_slide(viewer);
|
||||
if viewer.slide_fullscreened.replace(false) {
|
||||
viewer.window.unfullscreen();
|
||||
@@ -854,14 +865,14 @@ fn hide_chrome(viewer: &Rc<Viewer>) {
|
||||
}
|
||||
|
||||
/// Copy the photo on screen to where the user picks, under its Drive name.
|
||||
pub(crate) fn save_photo_to_disk(ui: &Rc<Ui>, window: >k4::Window, source: &str, name: &str) {
|
||||
pub(crate) fn save_photo_to_disk(viewer: &Rc<Viewer>, source: &str, name: &str) {
|
||||
let dialog = gtk4::FileDialog::builder()
|
||||
.title(gettext("Save a Copy"))
|
||||
.initial_name(name)
|
||||
.build();
|
||||
let source = source.to_string();
|
||||
let ui = ui.clone();
|
||||
dialog.save(Some(window), gio::Cancellable::NONE, move |res| {
|
||||
let toasts = viewer.toasts.clone();
|
||||
dialog.save(Some(&viewer.window), gio::Cancellable::NONE, move |res| {
|
||||
// An error here is the dialog being dismissed.
|
||||
let Some(dest) = res.ok().and_then(|file| file.path()) else {
|
||||
return;
|
||||
@@ -870,26 +881,67 @@ pub(crate) fn save_photo_to_disk(ui: &Rc<Ui>, window: >k4::Window, source: &st
|
||||
glib::spawn_future_local(async move {
|
||||
let copied =
|
||||
gio::spawn_blocking(move || std::fs::copy(&source, &dest).map(|_| dest)).await;
|
||||
match copied {
|
||||
let message = match copied {
|
||||
Ok(Ok(dest)) => {
|
||||
let saved = dest.file_name().map_or_else(
|
||||
|| dest.display().to_string(),
|
||||
|name| name.to_string_lossy().into_owned(),
|
||||
);
|
||||
// Translators: {name} is the saved file's name.
|
||||
toast(&ui, &gettext_f("Saved “{name}”", &[("name", &saved)]));
|
||||
gettext_f("Saved “{name}”", &[("name", &saved)])
|
||||
}
|
||||
Ok(Err(e)) => toast_error(&ui, &gettext("Couldn't save the copy"), &e.to_string()),
|
||||
Err(_) => toast_error(
|
||||
&ui,
|
||||
Ok(Err(e)) => failure(&gettext("Couldn't save the copy"), &e.to_string()),
|
||||
Err(_) => failure(
|
||||
&gettext("Couldn't save the copy"),
|
||||
&gettext("The copy was interrupted."),
|
||||
),
|
||||
}
|
||||
};
|
||||
toasts.add_toast(
|
||||
adw::Toast::builder()
|
||||
.title(&message)
|
||||
.use_markup(false)
|
||||
.build(),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// A failed action's toast text, worded like [`toast_error`]'s.
|
||||
fn failure(what: &str, detail: &str) -> String {
|
||||
tracing::warn!("{what}: {detail}");
|
||||
// Translators: a failed action's toast. {what} says what failed, such as
|
||||
// "Couldn't rename"; {detail} is the reason, usually untranslated text
|
||||
// from the mount service.
|
||||
gettext_f("{what}: {detail}", &[("what", what), ("detail", detail)])
|
||||
}
|
||||
|
||||
/// Put the photo on screen on the clipboard as an image, for pasting into a
|
||||
/// chat or a document.
|
||||
fn copy_shown_photo(_ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
let Some(texture) = viewer
|
||||
.picture
|
||||
.paintable()
|
||||
.and_downcast::<gtk4::gdk::Texture>()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
viewer.window.clipboard().set_texture(&texture);
|
||||
viewer.toasts.add_toast(
|
||||
adw::Toast::builder()
|
||||
// Translators: toast after the photo viewer put the photo on the clipboard.
|
||||
.title(gettext("Image copied"))
|
||||
.use_markup(false)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Open the Share dialog for the photo on screen, over the lightbox.
|
||||
fn share_shown_photo(ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
let uid = viewer.uid.borrow().clone();
|
||||
let name = viewer.name.borrow().clone().unwrap_or_default();
|
||||
share_photo(ui, uid, name, Some(viewer.window.clone()));
|
||||
}
|
||||
|
||||
/// A symlink to the cached file `path` under its Drive `name`, in a directory
|
||||
/// of its own below `base`. The cache names files by content hash, with no
|
||||
/// extension; the app chooser and the app it launches both need the real name
|
||||
@@ -1040,16 +1092,105 @@ fn photo_title(capture_time: i64) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the lightbox's title (the photo's date) and its "12 of 340" counter.
|
||||
/// Set the lightbox's title (the photo's date) and the line under it: the town
|
||||
/// it was taken in, when known, and its "12 of 340" counter.
|
||||
fn show_photo_position(ui: &Rc<Ui>, viewer: &Rc<Viewer>, index: u32, capture_time: i64) {
|
||||
let loaded = ui.gallery.model.n_items();
|
||||
let more = ui.gallery.has_more.get();
|
||||
viewer.prev.set_sensitive(index > 0);
|
||||
viewer.next.set_sensitive(index + 1 < loaded || more);
|
||||
viewer.title.set_label(&photo_title(capture_time));
|
||||
let position = position_label(index, loaded, more, gallery_total(ui));
|
||||
let place = viewer_item(ui, viewer, &viewer.uid.borrow())
|
||||
.and_then(|item| item.place_id)
|
||||
.and_then(pdfs_core::places::city)
|
||||
.map(|city| city.name);
|
||||
let line = match place {
|
||||
Some(place) => {
|
||||
let args = [("place", place), ("position", position.as_str())];
|
||||
// Translators: the line under the photo viewer's title, such as "Berlin · 12 of 340"; {place} is a town, {position} the counter.
|
||||
gettext_f("{place} · {position}", &args)
|
||||
}
|
||||
None => position,
|
||||
};
|
||||
viewer.counter.set_label(&line);
|
||||
viewer
|
||||
.counter
|
||||
.set_label(&position_label(index, loaded, more, gallery_total(ui)));
|
||||
.strip_reveal
|
||||
.set_visible(loaded > 1 && !viewer.slideshow.get());
|
||||
mark_in_strip(viewer, index);
|
||||
}
|
||||
|
||||
/// Mark the photo at `index` in the strip and bring it into view.
|
||||
fn mark_in_strip(viewer: &Rc<Viewer>, index: u32) {
|
||||
if index >= viewer.strip_selection.n_items() {
|
||||
return;
|
||||
}
|
||||
viewer.strip_selection.set_selected(index);
|
||||
viewer
|
||||
.strip
|
||||
.scroll_to(index, gtk4::ListScrollFlags::NONE, None);
|
||||
}
|
||||
|
||||
/// The strip of thumbnails along the lightbox's bottom edge: the gallery's
|
||||
/// photos in its order, the one on screen marked. A click steps straight to a
|
||||
/// photo; the thumbnails come through the gallery's own pipeline and cache.
|
||||
fn build_strip(ui: &Rc<Ui>) -> (gtk4::ListView, gtk4::SingleSelection) {
|
||||
let selection = gtk4::SingleSelection::new(Some(ui.gallery.model.clone()));
|
||||
selection.set_autoselect(false);
|
||||
selection.set_can_unselect(true);
|
||||
|
||||
let factory = gtk4::SignalListItemFactory::new();
|
||||
factory.connect_setup(|_, item| {
|
||||
let item = item.downcast_ref::<gtk4::ListItem>().unwrap();
|
||||
let picture = gtk4::Picture::builder()
|
||||
.content_fit(gtk4::ContentFit::Cover)
|
||||
.width_request(56)
|
||||
.height_request(56)
|
||||
.can_shrink(true)
|
||||
.build();
|
||||
picture.add_css_class("viewer-strip-thumb");
|
||||
// The arrow keys belong to the lightbox, not to the strip.
|
||||
item.set_focusable(false);
|
||||
item.set_child(Some(&picture));
|
||||
});
|
||||
let ui_bind = ui.clone();
|
||||
factory.connect_bind(move |_, item| {
|
||||
let item = item.downcast_ref::<gtk4::ListItem>().unwrap();
|
||||
let Some(picture) = item.child().and_downcast::<gtk4::Picture>() else {
|
||||
return;
|
||||
};
|
||||
let Some(boxed) = item.item().and_downcast::<BoxedAnyObject>() else {
|
||||
return;
|
||||
};
|
||||
let photo = boxed.borrow::<PhotoItem>().clone();
|
||||
picture.set_paintable(gtk4::gdk::Paintable::NONE);
|
||||
picture.set_tooltip_text(Some(&dates::full(photo.capture_time)));
|
||||
want_thumb(&ui_bind, &photo, &picture);
|
||||
schedule_thumbs(&ui_bind);
|
||||
});
|
||||
let ui_unbind = ui.clone();
|
||||
factory.connect_unbind(move |_, item| {
|
||||
let item = item.downcast_ref::<gtk4::ListItem>().unwrap();
|
||||
let (Some(picture), Some(boxed)) = (
|
||||
item.child().and_downcast::<gtk4::Picture>(),
|
||||
item.item().and_downcast::<BoxedAnyObject>(),
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
let uid = boxed.borrow::<PhotoItem>().uid.clone();
|
||||
ui_unbind
|
||||
.gallery
|
||||
.release_thumb(&uid, |waiting| waiting == &picture);
|
||||
});
|
||||
|
||||
let list = gtk4::ListView::builder()
|
||||
.model(&selection)
|
||||
.factory(&factory)
|
||||
.orientation(gtk4::Orientation::Horizontal)
|
||||
.focusable(false)
|
||||
.build();
|
||||
list.add_css_class("viewer-strip");
|
||||
(list, selection)
|
||||
}
|
||||
|
||||
/// The in-app lightbox: the photo or video, edge-to-edge on a dark backdrop,
|
||||
@@ -1208,6 +1349,20 @@ pub(crate) fn open_photo_viewer(ui: &Rc<Ui>, initial_uid: String) -> gtk4::Windo
|
||||
let top_reveal = fade(top_bar.upcast_ref(), gtk4::Align::Fill, gtk4::Align::Start);
|
||||
overlay.add_overlay(&top_reveal);
|
||||
|
||||
let (strip, strip_selection) = build_strip(ui);
|
||||
let strip_scroll = gtk4::ScrolledWindow::builder()
|
||||
.hscrollbar_policy(gtk4::PolicyType::External)
|
||||
.vscrollbar_policy(gtk4::PolicyType::Never)
|
||||
.child(&strip)
|
||||
.build();
|
||||
strip_scroll.add_css_class("viewer-strip-bar");
|
||||
let strip_reveal = fade(
|
||||
strip_scroll.upcast_ref(),
|
||||
gtk4::Align::Fill,
|
||||
gtk4::Align::End,
|
||||
);
|
||||
overlay.add_overlay(&strip_reveal);
|
||||
|
||||
// Details panel: docked beside the image as a real surface, so opening it
|
||||
// narrows the photo instead of covering part of it.
|
||||
let info_rows = gtk4::Box::new(gtk4::Orientation::Vertical, 12);
|
||||
@@ -1295,7 +1450,9 @@ pub(crate) fn open_photo_viewer(ui: &Rc<Ui>, initial_uid: String) -> gtk4::Windo
|
||||
narrow.add_setter(&info_split, "collapsed", Some(&true.to_value()));
|
||||
adw_window.add_breakpoint(narrow);
|
||||
let body = info_split.clone();
|
||||
adw_window.set_content(Some(&body));
|
||||
let toasts = adw::ToastOverlay::new();
|
||||
toasts.set_child(Some(&body));
|
||||
adw_window.set_content(Some(&toasts));
|
||||
|
||||
let viewer = Rc::new(Viewer {
|
||||
window: window.clone(),
|
||||
@@ -1326,7 +1483,15 @@ pub(crate) fn open_photo_viewer(ui: &Rc<Ui>, initial_uid: String) -> gtk4::Windo
|
||||
pinch_start: Cell::new(1.0),
|
||||
drag_start: Cell::new((0.0, 0.0)),
|
||||
pointer: Cell::new((0.0, 0.0)),
|
||||
chrome: vec![top_reveal.clone(), prev_reveal.clone(), next_reveal.clone()],
|
||||
chrome: vec![
|
||||
top_reveal.clone(),
|
||||
prev_reveal.clone(),
|
||||
next_reveal.clone(),
|
||||
strip_reveal.clone(),
|
||||
],
|
||||
strip: strip.clone(),
|
||||
strip_selection: strip_selection.clone(),
|
||||
strip_reveal: strip_reveal.clone(),
|
||||
chrome_hover: Cell::new(false),
|
||||
chrome_source: RefCell::new(None),
|
||||
more: more_btn.clone(),
|
||||
@@ -1334,6 +1499,7 @@ pub(crate) fn open_photo_viewer(ui: &Rc<Ui>, initial_uid: String) -> gtk4::Windo
|
||||
slideshow: Cell::new(false),
|
||||
slide_source: RefCell::new(None),
|
||||
slide_fullscreened: Cell::new(false),
|
||||
toasts,
|
||||
});
|
||||
|
||||
let initial_idx = find_photo_index(&ui.gallery.model, &initial_uid).unwrap_or(0);
|
||||
@@ -1359,7 +1525,7 @@ pub(crate) fn open_photo_viewer(ui: &Rc<Ui>, initial_uid: String) -> gtk4::Windo
|
||||
}
|
||||
});
|
||||
body.add_controller(motion);
|
||||
for revealer in [&top_reveal, &prev_reveal, &next_reveal] {
|
||||
for revealer in [&top_reveal, &prev_reveal, &next_reveal, &strip_reveal] {
|
||||
let hover = gtk4::EventControllerMotion::new();
|
||||
let viewer_enter = Rc::downgrade(&viewer);
|
||||
hover.connect_enter(move |_, _, _| {
|
||||
@@ -1475,13 +1641,53 @@ pub(crate) fn open_photo_viewer(ui: &Rc<Ui>, initial_uid: String) -> gtk4::Windo
|
||||
w_close.close();
|
||||
});
|
||||
|
||||
// A click on a thumbnail selects it; step there. Every selection the
|
||||
// lightbox sets itself is the photo on screen, and the model's own changes
|
||||
// (a page landing, a favorite rewritten in place) keep the selected photo
|
||||
// or drop it, so a selection elsewhere can only be the user's.
|
||||
let ui_strip = ui.clone();
|
||||
let viewer_strip = Rc::downgrade(&viewer);
|
||||
strip_selection.connect_selection_changed(move |selection, _, _| {
|
||||
let Some(viewer) = viewer_strip.upgrade() else {
|
||||
return;
|
||||
};
|
||||
let picked = selection.selected();
|
||||
let Some(current) = find_photo_index(&ui_strip.gallery.model, &viewer.uid.borrow()) else {
|
||||
return;
|
||||
};
|
||||
if picked != gtk4::INVALID_LIST_POSITION && picked != current {
|
||||
navigate_photo(&ui_strip, &viewer, picked as i32 - current as i32);
|
||||
}
|
||||
});
|
||||
let viewer_items = Rc::downgrade(&viewer);
|
||||
let ui_items = ui.clone();
|
||||
let items_handler = ui
|
||||
.gallery
|
||||
.model
|
||||
.connect_items_changed(move |model, _, _, _| {
|
||||
let Some(viewer) = viewer_items.upgrade() else {
|
||||
return;
|
||||
};
|
||||
if let Some(index) = find_photo_index(model, &viewer.uid.borrow()) {
|
||||
viewer.strip_selection.set_selected(index);
|
||||
}
|
||||
viewer
|
||||
.strip_reveal
|
||||
.set_visible(ui_items.gallery.model.n_items() > 1 && !viewer.slideshow.get());
|
||||
});
|
||||
|
||||
// The one strong handle on the viewer. Every handler holds a weak one: a
|
||||
// strong one in a handler of a widget the viewer holds is a cycle, which
|
||||
// kept every closed lightbox, its window and its full-size photo in memory
|
||||
// for the life of the app.
|
||||
let keep = RefCell::new(Some(viewer.clone()));
|
||||
let ui_close = ui.clone();
|
||||
let items_handler = RefCell::new(Some(items_handler));
|
||||
window.connect_close_request(move |_| {
|
||||
// The gallery's model outlives the lightbox.
|
||||
if let Some(handler) = items_handler.borrow_mut().take() {
|
||||
ui_close.gallery.model.disconnect(handler);
|
||||
}
|
||||
if let Some(viewer) = keep.borrow_mut().take() {
|
||||
reveal_photo(&ui_close, &viewer.uid.borrow());
|
||||
stop_video(&viewer);
|
||||
@@ -1700,6 +1906,9 @@ pub(crate) fn open_photo_viewer(ui: &Rc<Ui>, initial_uid: String) -> gtk4::Windo
|
||||
Some("Delete" | "KP_Delete") => trash_shown_photo(&ui_key, &viewer_key),
|
||||
Some("Escape" | "q") => w_key.close(),
|
||||
Some("w") if ctrl => w_key.close(),
|
||||
Some("c") if ctrl && viewer_key.path.borrow().is_some() && !playing_video => {
|
||||
copy_shown_photo(&ui_key, &viewer_key)
|
||||
}
|
||||
_ => return glib::Propagation::Proceed,
|
||||
}
|
||||
glib::Propagation::Stop
|
||||
@@ -1726,11 +1935,19 @@ fn open_viewer_menu(ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
let mut menu = ActionMenu::new();
|
||||
menu.item(&gettext("Slideshow"), with_viewer(toggle_slideshow, ui));
|
||||
menu.section();
|
||||
// Both need the full-size file, which may still be downloading.
|
||||
// These need the full-size file, which may still be downloading.
|
||||
if viewer.path.borrow().is_some() {
|
||||
let still = viewer.media.visible_child_name().as_deref() == Some("photo");
|
||||
if still {
|
||||
// Translators: menu item that puts the photo on the clipboard as an image.
|
||||
menu.item(&gettext("Copy Image"), with_viewer(copy_shown_photo, ui));
|
||||
}
|
||||
menu.item(&gettext("Save a Copy…"), with_viewer(save_shown_photo, ui));
|
||||
menu.item(&gettext("Open With…"), with_viewer(open_shown_photo, ui));
|
||||
}
|
||||
if photo_shareable(ui) {
|
||||
menu.item(&gettext("Share…"), with_viewer(share_shown_photo, ui));
|
||||
}
|
||||
// A RAW is not on the timeline, and an album holds the shot it belongs to.
|
||||
if find_photo_index(&ui.gallery.model, &viewer.uid.borrow()).is_some() {
|
||||
menu.item(
|
||||
@@ -1766,10 +1983,10 @@ fn open_viewer_menu(ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
});
|
||||
}
|
||||
|
||||
fn save_shown_photo(ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
fn save_shown_photo(_ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
if let Some(path) = viewer.path.borrow().as_deref() {
|
||||
let name = viewer.name.borrow();
|
||||
save_photo_to_disk(ui, &viewer.window, path, name.as_deref().unwrap_or("photo"));
|
||||
save_photo_to_disk(viewer, path, name.as_deref().unwrap_or("photo"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -157,10 +157,11 @@ pub(crate) struct GalleryState {
|
||||
/// Photos the daemon reported as having no thumbnail at all, so a tile that
|
||||
/// can never be filled isn't requested again on every scroll past it.
|
||||
pub(crate) photo_nothumb: RefCell<HashSet<String>>,
|
||||
/// Tiles on screen still waiting for their thumbnail, by uid. Populated as
|
||||
/// sections are bound, drained as batches land, cleared on unbind — so a
|
||||
/// batch only ever paints a widget that is still showing that photo.
|
||||
pub(crate) thumb_wanted: RefCell<HashMap<String, gtk4::Picture>>,
|
||||
/// Pictures on screen still waiting for their thumbnail, by uid. Populated
|
||||
/// as they are bound, drained as batches land, cleared on unbind — so a
|
||||
/// batch only ever paints a widget that is still showing that photo. One
|
||||
/// photo can be waited for twice: by its tile and by the lightbox's strip.
|
||||
pub(crate) thumb_wanted: RefCell<HashMap<String, Vec<gtk4::Picture>>>,
|
||||
/// Uids queued for the next [`Request::PhotoThumbs`] batch, and whether a
|
||||
/// batch is already in flight (only one at a time, so a long scroll can't
|
||||
/// stack requests on the daemon).
|
||||
@@ -243,6 +244,27 @@ impl GalleryState {
|
||||
pub(crate) fn in_collection(&self) -> bool {
|
||||
self.album.borrow().is_some() || self.place.borrow().is_some()
|
||||
}
|
||||
|
||||
/// Have `picture` painted with the thumbnail of `uid` once it lands.
|
||||
pub(crate) fn await_thumb(&self, uid: &str, picture: >k4::Picture) {
|
||||
let mut wanted = self.thumb_wanted.borrow_mut();
|
||||
let waiting = wanted.entry(uid.to_string()).or_default();
|
||||
if !waiting.contains(picture) {
|
||||
waiting.push(picture.clone());
|
||||
}
|
||||
}
|
||||
|
||||
/// Stop waiting for `uid` in the pictures `drop` picks, because they show
|
||||
/// another photo now.
|
||||
pub(crate) fn release_thumb(&self, uid: &str, drop: impl Fn(>k4::Picture) -> bool) {
|
||||
let mut wanted = self.thumb_wanted.borrow_mut();
|
||||
if let Some(waiting) = wanted.get_mut(uid) {
|
||||
waiting.retain(|picture| !drop(picture));
|
||||
if waiting.is_empty() {
|
||||
wanted.remove(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// How many photos to pull per [`Request::PhotosTimeline`] page.
|
||||
@@ -1314,14 +1336,10 @@ pub(crate) fn wire_gallery(
|
||||
if let Some(obj) = item.item().and_downcast::<BoxedAnyObject>()
|
||||
&& let GalleryRow::Tiles { tiles, .. } = &*obj.borrow::<GalleryRow>()
|
||||
{
|
||||
let mut wanted = ui_unbind.gallery.thumb_wanted.borrow_mut();
|
||||
for tile in tiles {
|
||||
if wanted
|
||||
.get(&tile.photo.uid)
|
||||
.is_some_and(|picture| picture.is_ancestor(&row_box))
|
||||
{
|
||||
wanted.remove(&tile.photo.uid);
|
||||
}
|
||||
ui_unbind
|
||||
.gallery
|
||||
.release_thumb(&tile.photo.uid, |picture| picture.is_ancestor(&row_box));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -2455,10 +2473,8 @@ impl TileWidget {
|
||||
let Some(photo) = self.photo.borrow_mut().take() else {
|
||||
return;
|
||||
};
|
||||
let mut wanted = ui.gallery.thumb_wanted.borrow_mut();
|
||||
if wanted.get(&photo.uid) == Some(&self.picture) {
|
||||
wanted.remove(&photo.uid);
|
||||
}
|
||||
ui.gallery
|
||||
.release_thumb(&photo.uid, |picture| picture == &self.picture);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2964,10 +2980,7 @@ pub(crate) fn want_thumb(ui: &Rc<Ui>, photo: &PhotoItem, picture: >k4::Picture
|
||||
return;
|
||||
}
|
||||
|
||||
ui.gallery
|
||||
.thumb_wanted
|
||||
.borrow_mut()
|
||||
.insert(photo.uid.clone(), picture.clone());
|
||||
ui.gallery.await_thumb(&photo.uid, picture);
|
||||
|
||||
match photo.thumb_path.as_deref() {
|
||||
Some(path) => {
|
||||
@@ -3186,7 +3199,8 @@ pub(crate) fn schedule_decode(ui: &Rc<Ui>) {
|
||||
}
|
||||
};
|
||||
ui.store_texture(&uid, texture.clone());
|
||||
if let Some(picture) = ui.gallery.thumb_wanted.borrow_mut().remove(&uid) {
|
||||
let waiting = ui.gallery.thumb_wanted.borrow_mut().remove(&uid);
|
||||
for picture in waiting.into_iter().flatten() {
|
||||
picture.set_paintable(Some(&texture));
|
||||
}
|
||||
}
|
||||
@@ -3994,6 +4008,16 @@ fn show_photo_menu(ui: &Rc<Ui>, photo: &PhotoItem, anchor: >k4::Button, x: f64
|
||||
menu.item(&gettext("Add to Album…"), move || {
|
||||
prompt_add_to_album(&ui_c, vec![uid.clone()], None)
|
||||
});
|
||||
if photo_shareable(ui) {
|
||||
let (ui_c, uid, name) = (
|
||||
ui.clone(),
|
||||
photo.uid.clone(),
|
||||
photo.name.clone().unwrap_or_default(),
|
||||
);
|
||||
menu.item(&gettext("Share…"), move || {
|
||||
share_photo(&ui_c, uid.clone(), name.clone(), None)
|
||||
});
|
||||
}
|
||||
let open_album = ui.gallery.album.borrow().clone();
|
||||
if let Some(album) = open_album.filter(|album| !album.shared) {
|
||||
let (ui_c, uid) = (ui.clone(), photo.uid.clone());
|
||||
@@ -4045,6 +4069,27 @@ fn set_photo_favorite(ui: &Rc<Ui>, uid: String, favorite: bool) {
|
||||
});
|
||||
}
|
||||
|
||||
/// Whether the photos on show are the user's own to share: everything but an
|
||||
/// album someone else shared, whose photos live on that person's volume.
|
||||
pub(crate) fn photo_shareable(ui: &Ui) -> bool {
|
||||
!ui.gallery
|
||||
.album
|
||||
.borrow()
|
||||
.as_ref()
|
||||
.is_some_and(|album| album.shared)
|
||||
}
|
||||
|
||||
/// Open the Share dialog for one photo, addressed by uid: the photos volume
|
||||
/// has no path in any mount. Over `parent` when the lightbox is open.
|
||||
pub(crate) fn share_photo(ui: &Rc<Ui>, uid: String, name: String, parent: Option<gtk4::Window>) {
|
||||
let entry = DirEntry {
|
||||
uid,
|
||||
name,
|
||||
..DirEntry::default()
|
||||
};
|
||||
open_share_dialog_over(ui, &entry, parent);
|
||||
}
|
||||
|
||||
/// Whether the photo grid is the view the Photos page shows: an album or a
|
||||
/// place, or the timeline itself. Under Albums or Places it is out of sight.
|
||||
pub(crate) fn photo_grid_shown(ui: &Ui) -> bool {
|
||||
@@ -4503,6 +4548,7 @@ mod tests {
|
||||
favorite: false,
|
||||
group_size: 1,
|
||||
has_raw: false,
|
||||
place_id: None,
|
||||
}
|
||||
};
|
||||
// Newest first, the way the daemon sends them.
|
||||
|
||||
@@ -267,7 +267,12 @@ fn want_map_thumb(ui: &Rc<Ui>, photo: &PhotoItem) {
|
||||
}
|
||||
// A town's card may be waiting for the same photo: share its picture
|
||||
// rather than take its place in the queue.
|
||||
let waiting = ui.gallery.thumb_wanted.borrow().get(&photo.uid).cloned();
|
||||
let waiting = ui
|
||||
.gallery
|
||||
.thumb_wanted
|
||||
.borrow()
|
||||
.get(&photo.uid)
|
||||
.and_then(|waiting| waiting.first().cloned());
|
||||
let picture = waiting.unwrap_or_else(|| {
|
||||
let picture = gtk4::Picture::new();
|
||||
want_thumb(ui, photo, &picture);
|
||||
@@ -362,7 +367,12 @@ fn show_spot_photos(ui: &Rc<Ui>, photos: Vec<(PlaceInfo, PhotoItem)>, (x, y): (f
|
||||
/// Show photo's thumbnail in `picture`, sharing one another widget is
|
||||
/// already waiting for.
|
||||
fn spot_thumb(ui: &Rc<Ui>, photo: &PhotoItem, picture: >k4::Picture) {
|
||||
let waiting = ui.gallery.thumb_wanted.borrow().get(&photo.uid).cloned();
|
||||
let waiting = ui
|
||||
.gallery
|
||||
.thumb_wanted
|
||||
.borrow()
|
||||
.get(&photo.uid)
|
||||
.and_then(|waiting| waiting.first().cloned());
|
||||
match waiting {
|
||||
Some(waiting) => {
|
||||
waiting
|
||||
|
||||
@@ -334,6 +334,13 @@ pub(crate) struct ShareDialog {
|
||||
/// Open the per-node Share dialog: invite Proton/external users, manage who has
|
||||
/// access and their roles, and create/copy/remove a public link.
|
||||
pub(crate) fn open_share_dialog(ui: &Rc<Ui>, entry: &DirEntry) {
|
||||
open_share_dialog_over(ui, entry, None);
|
||||
}
|
||||
|
||||
/// [`open_share_dialog`] over `parent` rather than the main window. The photo
|
||||
/// viewer is a window of its own, and a dialog on the main window would open
|
||||
/// behind it.
|
||||
pub(crate) fn open_share_dialog_over(ui: &Rc<Ui>, entry: &DirEntry, parent: Option<gtk4::Window>) {
|
||||
if !*ui.mounted.borrow() {
|
||||
toast_error(
|
||||
ui,
|
||||
@@ -491,7 +498,7 @@ pub(crate) fn open_share_dialog(ui: &Rc<Ui>, entry: &DirEntry) {
|
||||
}
|
||||
});
|
||||
share_dialog_reload(&state);
|
||||
dialog.present(ui_window(ui).as_ref());
|
||||
dialog.present(parent.or_else(|| ui_window(ui)).as_ref());
|
||||
}
|
||||
|
||||
/// Re-fetch the node's share and rebuild the people + public-link sections.
|
||||
|
||||
Reference in new issue
Block a user