Skip to content

Commit

Permalink
Basic year view implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
blissd committed Mar 26, 2024
1 parent bdcf5ca commit 6142fd1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ gettext-rs = { version = "0.7", features = ["gettext-system"] }
tracing = "0.1.37"
tracing-subscriber = "0.3"
relm4 = { version = "0.8.1", features = ["libadwaita", "gnome_45"] }
chrono = "0.4.35"
itertools = "0.12.1"


[dependencies.photos_core]
Expand Down
8 changes: 8 additions & 0 deletions core/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ pub struct Picture {
pub order_by_ts: Option<DateTime<Utc>>,
}

impl Picture {
pub fn year(&self) -> u32 {
self.order_by_ts
.map(|ts| ts.date_naive().year_ce().1)
.unwrap_or(0)
}
}

/// Repository of picture metadata.
/// Repository is backed by a Sqlite database.
#[derive(Debug)]
Expand Down
3 changes: 1 addition & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use gtk::{gio, glib};
use relm4::adw::prelude::AdwApplicationWindowExt;

use crate::all_photos::AllPhotos;
use crate::year_photos::YearPhotos;
use crate::config::{APP_ID, PROFILE};
use crate::modals::about::AboutDialog;
use crate::year_photos::YearPhotos;

pub(super) struct App {
about_dialog: Controller<AboutDialog>,
Expand Down Expand Up @@ -140,7 +140,6 @@ impl SimpleComponent for App {
let all_photos = AllPhotos::builder().launch(()).detach();
let year_photos = YearPhotos::builder().launch(()).detach();


let model = Self {
about_dialog,
all_photos,
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#[rustfmt::skip]
mod config;
mod all_photos;
mod year_photos;
mod app;
mod modals;
mod year_photos;

use app::App;
use config::{APP_ID, GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE};
Expand Down
35 changes: 20 additions & 15 deletions src/year_photos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@
use gtk::glib;
use gtk::prelude::{BoxExt, OrientableExt};
use photos_core;
use chrono::Datelike;

use itertools::Itertools;
use relm4::gtk;
use relm4::gtk::prelude::FrameExt;
use relm4::gtk::prelude::WidgetExt;
use relm4::typed_view::grid::{RelmGridItem, TypedGridView};
use relm4::*;
use std::cell::RefCell;
use std::path;
use std::rc::Rc;
use relm4::gtk::prelude::FrameExt;

#[derive(Debug)]
pub struct PicturePreview {
controller: Rc<RefCell<photos_core::Controller>>,
picture: photos_core::repo::Picture,
year: u32,
}

pub struct Widgets {
picture: gtk::Picture,
frame: gtk::Frame,
label: gtk::Label,
}

impl RelmGridItem for PicturePreview {
Expand All @@ -38,26 +37,35 @@ impl RelmGridItem for PicturePreview {
set_orientation: gtk::Orientation::Vertical,
set_margin_all: 1,

#[name = "frame"]
#[name(label)]
gtk::Label {},

adw::Clamp {
set_maximum_size: 200,

gtk::Frame {
#[name = "picture"]

#[name(picture)]
gtk::Picture {
set_can_shrink: true,
set_valign: gtk::Align::Center,
set_width_request: 200,
set_height_request: 200,
}
}
}
}
}

let widgets = Widgets { picture, frame };
let widgets = Widgets { picture, label };

(my_box, widgets)
}

fn bind(&mut self, widgets: &mut Self::Widgets, _root: &mut Self::Root) {
widgets.frame.set_label(Some(format!("{}", self.year).as_str()));
widgets
.label
.set_label(format!("{}", self.picture.year()).as_str());

// compute preview image if it is absent
if self.picture.square_preview_path.is_none() {
Expand Down Expand Up @@ -160,13 +168,10 @@ impl SimpleComponent for YearPhotos {
.all_with_previews()
.unwrap()
.into_iter()
.map(|picture| {
let year = picture.order_by_ts.map(|ts| ts.date_naive().year_ce().1).unwrap();
PicturePreview {
picture,
year,
controller: controller.clone(),
}
.dedup_by(|x, y| x.year() == y.year())
.map(|picture| PicturePreview {
picture,
controller: controller.clone(),
});

let mut grid_view_wrapper: TypedGridView<PicturePreview, gtk::SingleSelection> =
Expand Down

0 comments on commit 6142fd1

Please sign in to comment.