mirror of
https://github.com/narrrl/proton-drive-linux.git
synced 2026-11-03 16:41:26 +01:00
feat(core,fuse,gui,cli): filter the photos timeline to photos in no album
A new pill next to the favorites filter narrows the timeline to the photos no album of ours holds yet, so what is left to file is easy to find. A RAW+JPEG pair counts as filed when any of its files is in an album. PhotosTimeline gains an optional not_in_album flag; older front-ends omit it and get the whole timeline. Album contents are fetched lazily, so the first filtered page fetches the contents of any album not yet listed. Photos added to an album while the filter is on leave the timeline at once.
This commit is contained in:
1 parent
0135c29a4f
commit
5c1da9d7a5
20 files changed
+2304
-1995
No files matched your search
@@ -2074,6 +2074,7 @@ fn cmd_photos(limit: usize, offset: usize, favorites: bool) -> Result<()> {
|
||||
kind: None,
|
||||
range: None,
|
||||
favorites,
|
||||
not_in_album: false,
|
||||
})? {
|
||||
CtlResponse::Photos {
|
||||
available: false, ..
|
||||
|
||||
@@ -67,6 +67,10 @@ pub enum Request {
|
||||
/// get the whole timeline, as before.
|
||||
#[serde(default)]
|
||||
favorites: bool,
|
||||
/// Restrict the page to photos no album of ours holds — what is left to
|
||||
/// file. Older front-ends omit it and get the whole timeline, as before.
|
||||
#[serde(default)]
|
||||
not_in_album: bool,
|
||||
},
|
||||
/// Every photo of one photo's group — the JPEG and the RAW of one shot, a
|
||||
/// live photo and its clip. Replies with [`Response::Photos`], holding one
|
||||
@@ -2790,6 +2794,7 @@ mod tests {
|
||||
decoded,
|
||||
Request::PhotosTimeline {
|
||||
favorites: false,
|
||||
not_in_album: false,
|
||||
kind: None,
|
||||
range: None,
|
||||
..
|
||||
|
||||
@@ -455,7 +455,8 @@ impl Db {
|
||||
/// restricts the page to one tab (Photos / Videos / Raw); `range`, when set,
|
||||
/// restricts it to a `[from, to)` capture-time window (epoch seconds) — the
|
||||
/// date scrubber's jump. `offset` is relative to whatever the filters leave.
|
||||
/// `favorites` restricts the page to favorited photos.
|
||||
/// `favorites` restricts the page to favorited photos, and `not_in_album`
|
||||
/// to the shots no album holds any file of.
|
||||
///
|
||||
/// The page holds one row per *group*: the RAW and the JPEG of one shot are
|
||||
/// one tile. The Raw tab is the exception and lists every raw file, because
|
||||
@@ -467,6 +468,7 @@ impl Db {
|
||||
kind: Option<crate::control::PhotoKind>,
|
||||
range: Option<(i64, i64)>,
|
||||
favorites: bool,
|
||||
not_in_album: bool,
|
||||
) -> Result<Vec<StoredPhoto>> {
|
||||
let conn = self.read();
|
||||
// Built up so any combination of the optional filters is one indexed
|
||||
@@ -490,6 +492,15 @@ impl Db {
|
||||
if favorites {
|
||||
conds.push("p.favorite = 1".to_string());
|
||||
}
|
||||
// By group, not by file: a shot filed as its JPEG is filed, even though
|
||||
// its RAW was never added anywhere.
|
||||
if not_in_album {
|
||||
conds.push(
|
||||
"NOT EXISTS (SELECT 1 FROM album_photos a JOIN photos m ON m.uid = a.uid \
|
||||
WHERE COALESCE(m.group_key, m.uid) = COALESCE(p.group_key, p.uid))"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
if !conds.is_empty() {
|
||||
sql.push_str(" WHERE ");
|
||||
sql.push_str(&conds.join(" AND "));
|
||||
|
||||
@@ -140,7 +140,7 @@ fn photos_replace_keeps_what_was_learned_and_drops_what_left() {
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
let page = db.photos_page(0, 10, None, None, false).unwrap();
|
||||
let page = db.photos_page(0, 10, None, None, false, false).unwrap();
|
||||
assert_eq!(
|
||||
page.iter().map(|p| p.uid.as_str()).collect::<Vec<_>>(),
|
||||
["p0", "p1", "p2"],
|
||||
@@ -163,7 +163,14 @@ fn photos_replace_keeps_what_was_learned_and_drops_what_left() {
|
||||
// The counts break down by tab, and a filtered page returns only its tab.
|
||||
assert_eq!(db.photos_counts().unwrap(), (2, 1, 0));
|
||||
let videos = db
|
||||
.photos_page(0, 10, Some(crate::control::PhotoKind::Video), None, false)
|
||||
.photos_page(
|
||||
0,
|
||||
10,
|
||||
Some(crate::control::PhotoKind::Video),
|
||||
None,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
videos.iter().map(|p| p.uid.as_str()).collect::<Vec<_>>(),
|
||||
@@ -176,7 +183,7 @@ fn photos_replace_keeps_what_was_learned_and_drops_what_left() {
|
||||
// A date-range page keeps only the window's photos: [150, 350) is p1+p2,
|
||||
// not p0 at 400. Combined with a kind filter both conditions apply.
|
||||
let ranged = db
|
||||
.photos_page(0, 10, None, Some((150, 350)), false)
|
||||
.photos_page(0, 10, None, Some((150, 350)), false, false)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
ranged.iter().map(|p| p.uid.as_str()).collect::<Vec<_>>(),
|
||||
@@ -189,6 +196,7 @@ fn photos_replace_keeps_what_was_learned_and_drops_what_left() {
|
||||
Some(crate::control::PhotoKind::Video),
|
||||
Some((150, 350)),
|
||||
false,
|
||||
false,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
@@ -218,7 +226,7 @@ fn favorites_are_remembered_across_refreshes_and_filter_a_page() {
|
||||
},
|
||||
])
|
||||
.unwrap();
|
||||
let favorites = db.photos_page(0, 10, None, None, true).unwrap();
|
||||
let favorites = db.photos_page(0, 10, None, None, true, false).unwrap();
|
||||
assert_eq!(
|
||||
favorites.iter().map(|p| p.uid.as_str()).collect::<Vec<_>>(),
|
||||
["p1"],
|
||||
@@ -236,7 +244,7 @@ fn favorites_are_remembered_across_refreshes_and_filter_a_page() {
|
||||
TimelineRow::new("p2", 200),
|
||||
])
|
||||
.unwrap();
|
||||
let favorites = db.photos_page(0, 10, None, None, true).unwrap();
|
||||
let favorites = db.photos_page(0, 10, None, None, true, false).unwrap();
|
||||
assert_eq!(
|
||||
favorites.iter().map(|p| p.uid.as_str()).collect::<Vec<_>>(),
|
||||
["p2"],
|
||||
@@ -245,6 +253,57 @@ fn favorites_are_remembered_across_refreshes_and_filter_a_page() {
|
||||
assert!(db.photos_by_uid(&["p2".into()]).unwrap()[0].favorite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_in_album_hides_photos_any_album_holds() {
|
||||
let db = Db::open_in_memory().unwrap();
|
||||
db.photos_replace(&[
|
||||
TimelineRow::new("p1", 300),
|
||||
TimelineRow::new("p2", 200),
|
||||
TimelineRow::new("p3", 100),
|
||||
])
|
||||
.unwrap();
|
||||
db.album_photos_replace("a1", &[("p1".into(), 300, None, None)])
|
||||
.unwrap();
|
||||
db.album_photos_replace("a2", &[("p3".into(), 100, None, None)])
|
||||
.unwrap();
|
||||
|
||||
let page = db.photos_page(0, 10, None, None, false, true).unwrap();
|
||||
assert_eq!(
|
||||
page.iter().map(|p| p.uid.as_str()).collect::<Vec<_>>(),
|
||||
["p2"]
|
||||
);
|
||||
}
|
||||
|
||||
/// Filing the JPEG of a RAW+JPEG shot files the shot: the grid shows it as
|
||||
/// one tile, and that tile is in an album.
|
||||
#[test]
|
||||
fn not_in_album_counts_a_raw_pair_as_filed() {
|
||||
let db = Db::open_in_memory().unwrap();
|
||||
db.photos_replace(&[
|
||||
TimelineRow {
|
||||
name: Some("IMG_1234.JPG".into()),
|
||||
..TimelineRow::new("jpeg", 300)
|
||||
},
|
||||
TimelineRow {
|
||||
name: Some("img_1234.cr2".into()),
|
||||
..TimelineRow::new("raw", 300)
|
||||
},
|
||||
TimelineRow {
|
||||
name: Some("IMG_9999.JPG".into()),
|
||||
..TimelineRow::new("alone", 200)
|
||||
},
|
||||
])
|
||||
.unwrap();
|
||||
db.album_photos_replace("a1", &[("raw".into(), 300, None, None)])
|
||||
.unwrap();
|
||||
|
||||
let page = db.photos_page(0, 10, None, None, false, true).unwrap();
|
||||
assert_eq!(
|
||||
page.iter().map(|p| p.uid.as_str()).collect::<Vec<_>>(),
|
||||
["alone"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn photos_page_slices_the_timeline_in_order() {
|
||||
let db = Db::open_in_memory().unwrap();
|
||||
@@ -253,12 +312,16 @@ fn photos_page_slices_the_timeline_in_order() {
|
||||
.collect();
|
||||
db.photos_replace(&items).unwrap();
|
||||
|
||||
let page = db.photos_page(2, 2, None, None, false).unwrap();
|
||||
let page = db.photos_page(2, 2, None, None, false, false).unwrap();
|
||||
assert_eq!(
|
||||
page.iter().map(|p| p.uid.as_str()).collect::<Vec<_>>(),
|
||||
["p2", "p3"]
|
||||
);
|
||||
assert!(db.photos_page(9, 2, None, None, false).unwrap().is_empty());
|
||||
assert!(
|
||||
db.photos_page(9, 2, None, None, false, false)
|
||||
.unwrap()
|
||||
.is_empty()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -4077,7 +4140,7 @@ fn photos_delete_removes_the_photo_and_its_album_membership() {
|
||||
|
||||
assert_eq!(db.photos_delete(&["p2".into()]).unwrap(), 1);
|
||||
|
||||
let page = db.photos_page(0, 10, None, None, false).unwrap();
|
||||
let page = db.photos_page(0, 10, None, None, false, false).unwrap();
|
||||
assert_eq!(
|
||||
page.iter().map(|p| p.uid.as_str()).collect::<Vec<_>>(),
|
||||
["p1", "p3"],
|
||||
@@ -4117,7 +4180,7 @@ fn a_raw_and_its_jpeg_are_one_entry_in_the_grid() {
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
let page = db.photos_page(0, 10, None, None, false).unwrap();
|
||||
let page = db.photos_page(0, 10, None, None, false, false).unwrap();
|
||||
assert_eq!(
|
||||
page.iter().map(|p| p.uid.as_str()).collect::<Vec<_>>(),
|
||||
["jpeg", "alone"],
|
||||
@@ -4130,7 +4193,14 @@ fn a_raw_and_its_jpeg_are_one_entry_in_the_grid() {
|
||||
|
||||
// The Raw tab answers "which raws do I have", so it lists files.
|
||||
let raws = db
|
||||
.photos_page(0, 10, Some(crate::control::PhotoKind::Raw), None, false)
|
||||
.photos_page(
|
||||
0,
|
||||
10,
|
||||
Some(crate::control::PhotoKind::Raw),
|
||||
None,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
raws.iter().map(|p| p.uid.as_str()).collect::<Vec<_>>(),
|
||||
@@ -4175,7 +4245,7 @@ fn a_pixel_raw_capture_groups_with_its_cover_jpeg() {
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
let page = db.photos_page(0, 10, None, None, false).unwrap();
|
||||
let page = db.photos_page(0, 10, None, None, false, false).unwrap();
|
||||
assert_eq!(
|
||||
page.iter().map(|p| p.uid.as_str()).collect::<Vec<_>>(),
|
||||
["cover", "notes", "other"],
|
||||
@@ -4214,7 +4284,7 @@ fn a_shared_name_alone_does_not_group_photos() {
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
let page = db.photos_page(0, 10, None, None, false).unwrap();
|
||||
let page = db.photos_page(0, 10, None, None, false, false).unwrap();
|
||||
assert_eq!(page.len(), 3, "three shots, three tiles");
|
||||
assert!(page.iter().all(|p| p.group_size == 1));
|
||||
}
|
||||
@@ -4237,7 +4307,7 @@ fn the_servers_photo_relation_groups_a_live_photo() {
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
let page = db.photos_page(0, 10, None, None, false).unwrap();
|
||||
let page = db.photos_page(0, 10, None, None, false, false).unwrap();
|
||||
assert_eq!(
|
||||
page.iter().map(|p| p.uid.as_str()).collect::<Vec<_>>(),
|
||||
["main"]
|
||||
@@ -4339,7 +4409,7 @@ fn migration_v30_leaves_a_v29_timeline_intact() {
|
||||
}
|
||||
|
||||
let db = Db::open(&path).unwrap();
|
||||
let page = db.photos_page(0, 10, None, None, false).unwrap();
|
||||
let page = db.photos_page(0, 10, None, None, false, false).unwrap();
|
||||
assert_eq!(
|
||||
page.iter().map(|p| p.uid.as_str()).collect::<Vec<_>>(),
|
||||
["jpeg", "raw"],
|
||||
@@ -4360,7 +4430,7 @@ fn migration_v30_leaves_a_v29_timeline_intact() {
|
||||
},
|
||||
])
|
||||
.unwrap();
|
||||
let page = db.photos_page(0, 10, None, None, false).unwrap();
|
||||
let page = db.photos_page(0, 10, None, None, false, false).unwrap();
|
||||
assert_eq!(page.len(), 1);
|
||||
assert_eq!(page[0].uid, "jpeg");
|
||||
|
||||
@@ -4389,14 +4459,14 @@ fn photos_replace_keeps_a_skipped_photos_name() {
|
||||
},
|
||||
])
|
||||
.unwrap();
|
||||
let page = db.photos_page(0, 10, None, None, false).unwrap();
|
||||
let page = db.photos_page(0, 10, None, None, false, false).unwrap();
|
||||
assert_eq!(page.len(), 1, "one shot, two files");
|
||||
assert!(page[0].has_raw);
|
||||
|
||||
// The next refresh resolves neither, because both are already resolved.
|
||||
db.photos_replace(&[TimelineRow::new("jpeg", 300), TimelineRow::new("raw", 300)])
|
||||
.unwrap();
|
||||
let page = db.photos_page(0, 10, None, None, false).unwrap();
|
||||
let page = db.photos_page(0, 10, None, None, false, false).unwrap();
|
||||
assert_eq!(page.len(), 1, "the group survives a skipped refresh");
|
||||
assert_eq!(page[0].name.as_deref(), Some("IMG_1234.JPG"));
|
||||
assert!(page[0].has_raw, "the raw file is still a raw file");
|
||||
|
||||
@@ -175,6 +175,40 @@ impl Core {
|
||||
Ok(page.into_iter().map(|p| self.photo_item(p)).collect())
|
||||
}
|
||||
|
||||
/// Make sure every album of ours has its contents on disk, for a filter
|
||||
/// that asks which photos no album holds. Contents are otherwise fetched
|
||||
/// the first time an album is opened, so an album never opened would read
|
||||
/// as empty and its photos as unfiled.
|
||||
///
|
||||
/// Shared-with-me albums are skipped: their photos live on the sharer's
|
||||
/// volume and are never in our timeline. The freshness stamps are no guide
|
||||
/// here — any album change clears all of them — so only an album whose
|
||||
/// server count disagrees with an empty local copy is waited for.
|
||||
pub(crate) fn ensure_album_contents(&self) -> CoreResult<()> {
|
||||
if self.db.albums_count().map_err(CoreError::from)? == 0
|
||||
&& !self.rt.block_on(self.refresh_albums())?
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
let albums = self.db.albums_list().map_err(CoreError::from)?;
|
||||
for album in albums.iter().filter(|a| !a.shared && a.photo_count > 0) {
|
||||
let stored = self
|
||||
.db
|
||||
.album_photos_count(&album.uid)
|
||||
.map_err(CoreError::from)?;
|
||||
if stored > 0 {
|
||||
continue;
|
||||
}
|
||||
let Some(uid) = parse_uid(&album.uid) else {
|
||||
continue;
|
||||
};
|
||||
if let Err(error) = self.rt.block_on(self.refresh_album(&uid)) {
|
||||
warn!(album = %album.uid, %error, "fetching an album's contents failed");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Re-enumerate one album's photos and replace its persisted contents.
|
||||
pub(crate) async fn refresh_album(&self, album: &NodeUid) -> CoreResult<()> {
|
||||
let photos = self.photos();
|
||||
|
||||
@@ -440,7 +440,15 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
kind,
|
||||
range,
|
||||
favorites,
|
||||
}) => match core.photos_timeline(offset, clamp_limit(limit), kind, range, favorites) {
|
||||
not_in_album,
|
||||
}) => match core.photos_timeline(
|
||||
offset,
|
||||
clamp_limit(limit),
|
||||
kind,
|
||||
range,
|
||||
favorites,
|
||||
not_in_album,
|
||||
) {
|
||||
Ok(Some(items)) => CtlResponse::Photos {
|
||||
available: true,
|
||||
items,
|
||||
|
||||
@@ -637,6 +637,7 @@ impl Core {
|
||||
kind: Option<PhotoKind>,
|
||||
range: Option<(i64, i64)>,
|
||||
favorites: bool,
|
||||
not_in_album: bool,
|
||||
) -> CoreResult<Option<Vec<PhotoItem>>> {
|
||||
let count = self.db.photos_count().map_err(CoreError::from)?;
|
||||
if count == 0 {
|
||||
@@ -653,10 +654,16 @@ impl Core {
|
||||
} else if self.listing_stale(PHOTOS_SYNCED_MS, TIMELINE_TTL) {
|
||||
self.spawn_timeline_refresh();
|
||||
}
|
||||
// The filter is only as good as the album contents on disk, and those
|
||||
// are fetched lazily, per album opened. Fill in the missing ones before
|
||||
// the first page; later pages reuse what that fetch stored.
|
||||
if not_in_album && offset == 0 {
|
||||
self.ensure_album_contents()?;
|
||||
}
|
||||
|
||||
let page = self
|
||||
.db
|
||||
.photos_page(offset, limit, kind, range, favorites)
|
||||
.photos_page(offset, limit, kind, range, favorites, not_in_album)
|
||||
.map_err(CoreError::from)?;
|
||||
Ok(Some(page.into_iter().map(|p| self.photo_item(p)).collect()))
|
||||
}
|
||||
|
||||
@@ -561,6 +561,8 @@ fn build_window(app: &adw::Application) {
|
||||
range: Cell::new(None),
|
||||
favorites_btn: gallery_widgets.favorites_btn.clone(),
|
||||
favorites: Cell::new(false),
|
||||
not_in_album_btn: gallery_widgets.not_in_album_btn.clone(),
|
||||
not_in_album: Cell::new(false),
|
||||
date_suppress: Cell::new(false),
|
||||
loading: Cell::new(false),
|
||||
has_more: Cell::new(false),
|
||||
|
||||
@@ -468,6 +468,16 @@ fn add_to_album(ui: &Rc<Ui>, album: String, photos: Vec<String>) {
|
||||
),
|
||||
);
|
||||
}
|
||||
// Filed photos no longer belong in a timeline of unfiled ones.
|
||||
// The daemon's filter drops them too, so the paging offset stays
|
||||
// in step with what is left.
|
||||
if ui.gallery.not_in_album.get() && ui.gallery.album.borrow().is_none() {
|
||||
ui.gallery
|
||||
.selected
|
||||
.borrow_mut()
|
||||
.retain(|uid| !changed.contains(uid));
|
||||
remove_photos(&ui, &changed);
|
||||
}
|
||||
reload_album_grid(&ui);
|
||||
}
|
||||
Ok(Ok(Response::Error { message, kind })) => {
|
||||
|
||||
@@ -813,7 +813,10 @@ fn gallery_total(ui: &Rc<Ui>) -> Option<usize> {
|
||||
if let Some(album) = ui.gallery.album.borrow().as_ref() {
|
||||
return Some(album.photo_count);
|
||||
}
|
||||
if ui.gallery.range.get().is_some() || ui.gallery.favorites.get() {
|
||||
if ui.gallery.range.get().is_some()
|
||||
|| ui.gallery.favorites.get()
|
||||
|| ui.gallery.not_in_album.get()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let (photos, videos, raw) = ui.gallery.counts.get()?;
|
||||
|
||||
@@ -108,6 +108,10 @@ pub(crate) struct GalleryState {
|
||||
/// restricted to photos carrying Proton's `Favorite` tag.
|
||||
pub(crate) favorites_btn: gtk4::ToggleButton,
|
||||
pub(crate) favorites: Cell<bool>,
|
||||
/// The album filter toggle, and whether it is on. When on, the timeline is
|
||||
/// restricted to photos no album of ours holds yet.
|
||||
pub(crate) not_in_album_btn: gtk4::ToggleButton,
|
||||
pub(crate) not_in_album: Cell<bool>,
|
||||
/// Set while the date dropdown is being repopulated, so resetting its model
|
||||
/// doesn't fire the selection handler and kick off a spurious reload.
|
||||
pub(crate) date_suppress: Cell<bool>,
|
||||
@@ -355,6 +359,7 @@ pub(crate) struct GalleryWidgets {
|
||||
/// to [`kind_for_tab`]).
|
||||
pub(crate) tabs: [gtk4::ToggleButton; 4],
|
||||
pub(crate) favorites_btn: gtk4::ToggleButton,
|
||||
pub(crate) not_in_album_btn: gtk4::ToggleButton,
|
||||
/// The date-jump dropdown, populated with the timeline's months.
|
||||
pub(crate) dates: gtk4::DropDown,
|
||||
}
|
||||
@@ -564,6 +569,13 @@ pub(crate) fn build_gallery_page() -> (gtk4::Widget, GalleryWidgets) {
|
||||
.build();
|
||||
favorites_btn.add_css_class("pill");
|
||||
|
||||
// Not in an album: a filter like favorites, for filing what is left.
|
||||
let not_in_album_btn = gtk4::ToggleButton::builder()
|
||||
.icon_name("view-grid-symbolic")
|
||||
.tooltip_text(gettext("Show only photos not in an album"))
|
||||
.build();
|
||||
not_in_album_btn.add_css_class("pill");
|
||||
|
||||
// Date jump: "All dates" plus a row per month, filled in once the timeline's
|
||||
// months are known (see [`refresh_photo_months`]). Pushed to the far end of
|
||||
// the filter row, opposite the kind toggles.
|
||||
@@ -577,6 +589,7 @@ pub(crate) fn build_gallery_page() -> (gtk4::Widget, GalleryWidgets) {
|
||||
filters.set_hexpand(true);
|
||||
filters.append(&tab_group);
|
||||
filters.append(&favorites_btn);
|
||||
filters.append(¬_in_album_btn);
|
||||
let spacer = gtk4::Box::new(gtk4::Orientation::Horizontal, 0);
|
||||
spacer.set_hexpand(true);
|
||||
filters.append(&spacer);
|
||||
@@ -709,6 +722,7 @@ pub(crate) fn build_gallery_page() -> (gtk4::Widget, GalleryWidgets) {
|
||||
select_done,
|
||||
tabs,
|
||||
favorites_btn,
|
||||
not_in_album_btn,
|
||||
dates,
|
||||
albums,
|
||||
albums_stack,
|
||||
@@ -1059,6 +1073,17 @@ pub(crate) fn wire_gallery(
|
||||
load_gallery(&ui_fav, false);
|
||||
});
|
||||
|
||||
// Not in an album: the same kind of filter, and just as independent.
|
||||
let ui_unfiled = ui.clone();
|
||||
ui.gallery.not_in_album_btn.connect_toggled(move |btn| {
|
||||
let on = btn.is_active();
|
||||
if ui_unfiled.gallery.not_in_album.get() == on {
|
||||
return;
|
||||
}
|
||||
ui_unfiled.gallery.not_in_album.set(on);
|
||||
load_gallery(&ui_unfiled, false);
|
||||
});
|
||||
|
||||
// Date jump: selecting a month loads that window; "All dates" (row 0) clears
|
||||
// it. Skipped while the model is being repopulated (see `gallery_date_suppress`).
|
||||
let ui_dates = ui.clone();
|
||||
@@ -2150,9 +2175,13 @@ pub(crate) fn update_gallery_subtitle(ui: &Rc<Ui>) {
|
||||
let kind = ui.gallery.kind.get();
|
||||
// The whole library for this filter, not the page count — the subtitle sits
|
||||
// next to tabs carrying the same totals, and the two disagreeing reads as a
|
||||
// bug. A date jump is the exception: there the window is the subject.
|
||||
let total = match (ui.gallery.range.get(), ui.gallery.counts.get()) {
|
||||
(None, Some((photos, videos, raw))) => match kind {
|
||||
// bug. A date jump or a filter is the exception: the counts are the
|
||||
// library's, not the filter's, so there the loaded count is the honest one.
|
||||
let narrowed = ui.gallery.range.get().is_some()
|
||||
|| ui.gallery.favorites.get()
|
||||
|| ui.gallery.not_in_album.get();
|
||||
let total = match (narrowed, ui.gallery.counts.get()) {
|
||||
(false, Some((photos, videos, raw))) => match kind {
|
||||
Some(PhotoKind::Photo) => photos,
|
||||
Some(PhotoKind::Video) => videos,
|
||||
Some(PhotoKind::Raw) => raw,
|
||||
@@ -2261,16 +2290,23 @@ pub(crate) fn short_capture_time(secs: i64) -> String {
|
||||
|
||||
/// Fetch a timeline page from the daemon. When `append` is false the model is
|
||||
/// cleared first (fresh load); otherwise the next page is tacked on.
|
||||
/// The empty state for a timeline filtered to `kind`, favorites and/or a
|
||||
/// `month`: what is missing, in the filter's own words.
|
||||
/// The empty state for a timeline filtered to `kind`, favorites, the photos
|
||||
/// in no album and/or a `month`: what is missing, in the filter's own words.
|
||||
pub(crate) fn empty_timeline_text(
|
||||
kind: Option<PhotoKind>,
|
||||
favorites: bool,
|
||||
not_in_album: bool,
|
||||
month: Option<&str>,
|
||||
) -> (String, String) {
|
||||
let args = [("month", month.unwrap_or_default())];
|
||||
let video = kind == Some(PhotoKind::Video);
|
||||
let raw = kind == Some(PhotoKind::Raw);
|
||||
if not_in_album && !favorites && kind.is_none() && month.is_none() {
|
||||
return (
|
||||
gettext("Every photo is in an album"),
|
||||
gettext("Turn off the album filter to see everything."),
|
||||
);
|
||||
}
|
||||
match (favorites, kind, month) {
|
||||
(false, None, None) => (
|
||||
gettext("No photos yet"),
|
||||
@@ -2333,11 +2369,12 @@ fn fill_scrubber(ui: &Rc<Ui>, months: &[PhotoMonth]) {
|
||||
}
|
||||
|
||||
/// Show the scrubber only where a month jump makes sense: the whole timeline,
|
||||
/// not an album, a date window or the favorites.
|
||||
/// not an album, a date window, the favorites or the unfiled photos.
|
||||
pub(crate) fn sync_scrubber(ui: &Rc<Ui>) {
|
||||
let whole = ui.gallery.album.borrow().is_none()
|
||||
&& ui.gallery.range.get().is_none()
|
||||
&& !ui.gallery.favorites.get();
|
||||
&& !ui.gallery.favorites.get()
|
||||
&& !ui.gallery.not_in_album.get();
|
||||
ui.gallery
|
||||
.scrubber
|
||||
.set_visible(whole && ui.gallery.months.borrow().len() > 1);
|
||||
@@ -2644,6 +2681,7 @@ pub(crate) fn load_gallery(ui: &Rc<Ui>, append: bool) {
|
||||
kind: ui.gallery.kind.get(),
|
||||
range: ui.gallery.range.get(),
|
||||
favorites: ui.gallery.favorites.get(),
|
||||
not_in_album: ui.gallery.not_in_album.get(),
|
||||
},
|
||||
};
|
||||
let rx = spawn_request(ui.dirs.control_socket(), request);
|
||||
@@ -2697,6 +2735,7 @@ pub(crate) fn load_gallery(ui: &Rc<Ui>, append: bool) {
|
||||
if ui.gallery.model.n_items() == 0 {
|
||||
let filtered = ui.gallery.kind.get().is_some()
|
||||
|| ui.gallery.favorites.get()
|
||||
|| ui.gallery.not_in_album.get()
|
||||
|| ui.gallery.range.get().is_some();
|
||||
let (title, description) = if ui.gallery.album.borrow().is_some() {
|
||||
(
|
||||
@@ -2714,6 +2753,7 @@ pub(crate) fn load_gallery(ui: &Rc<Ui>, append: bool) {
|
||||
empty_timeline_text(
|
||||
ui.gallery.kind.get(),
|
||||
ui.gallery.favorites.get(),
|
||||
ui.gallery.not_in_album.get(),
|
||||
month.as_deref(),
|
||||
)
|
||||
};
|
||||
@@ -2843,15 +2883,25 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn an_empty_filter_names_what_it_filtered() {
|
||||
assert_eq!(empty_timeline_text(None, false, None).0, "No photos yet");
|
||||
assert_eq!(empty_timeline_text(None, true, None).0, "No favorites yet");
|
||||
assert_eq!(
|
||||
empty_timeline_text(Some(PhotoKind::Video), false, Some("June 2024")).0,
|
||||
empty_timeline_text(None, false, false, None).0,
|
||||
"No photos yet"
|
||||
);
|
||||
assert_eq!(
|
||||
empty_timeline_text(None, true, false, None).0,
|
||||
"No favorites yet"
|
||||
);
|
||||
assert_eq!(
|
||||
empty_timeline_text(Some(PhotoKind::Video), false, false, Some("June 2024")).0,
|
||||
"No videos in June 2024"
|
||||
);
|
||||
assert_eq!(
|
||||
empty_timeline_text(Some(PhotoKind::Raw), true, None).0,
|
||||
empty_timeline_text(Some(PhotoKind::Raw), true, false, None).0,
|
||||
"No favorite raw files"
|
||||
);
|
||||
assert_eq!(
|
||||
empty_timeline_text(None, false, true, None).0,
|
||||
"Every photo is in an album"
|
||||
);
|
||||
}
|
||||
}
|
||||
+230
-218
File diff suppressed because it is too large.
Load diff
+231
-219
File diff suppressed because it is too large.
Load diff
+230
-218
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user