Skip to content

Commit

Permalink
Display 10 images... badly
Browse files Browse the repository at this point in the history
  • Loading branch information
blissd committed Mar 22, 2024
1 parent afccf2d commit 452f101
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 1 deletion.
113 changes: 113 additions & 0 deletions src/all_photos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
use gtk::glib;
use gtk::prelude::{BoxExt, OrientableExt};
use photos_core;
use relm4::factory::{DynamicIndex, FactoryComponent, FactorySender, FactoryVecDeque};
use relm4::*;
use std::path;

#[derive(Debug)]
pub enum InputMsg {
View,
}

#[derive(Debug)]
pub struct PicturePreview {
path: path::PathBuf,
//controller: photos_core::Controller,
//pictures: Vec<photos_core::repo::Picture>,
}

#[relm4::factory(pub)]
impl FactoryComponent for PicturePreview {
type Init = path::PathBuf;
type Input = InputMsg;
type Output = ();
type CommandOutput = ();
type ParentWidget = gtk::Box;

view! {
#[root]
gtk::Box {
set_orientation: gtk::Orientation::Vertical,
set_spacing: 5,
set_margin_all: 5,

gtk::Picture {
set_filename: Some(&self.path),
}
}
}

fn init_model(path: Self::Init, _index: &DynamicIndex, _sender: FactorySender<Self>) -> Self {
Self { path }
}

fn update(&mut self, msg: Self::Input, _sender: FactorySender<Self>) {}
}

pub struct AllPhotos {
// controller: photos_core::Controller,
pictures: FactoryVecDeque<PicturePreview>,
}

#[relm4::component(pub)]
impl SimpleComponent for AllPhotos {
type Init = ();
type Input = ();
type Output = ();

view! {
gtk::Box {
set_orientation: gtk::Orientation::Vertical,
set_spacing: 5,
set_margin_all: 5,

#[local_ref]
pictures_box -> gtk::Box {
set_orientation: gtk::Orientation::Vertical,
set_spacing: 5,
set_margin_all: 5,
}
}
}

fn init(
counter: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let repo = {
let db_path = glib::user_data_dir().join("photos");
let _ = std::fs::create_dir_all(&db_path);
let db_path = db_path.join("pictures.sqlite");
photos_core::Repository::open(&db_path).unwrap()
};

let scan = {
let pic_dir = path::Path::new("/var/home/david/Pictures");
photos_core::Scanner::build(&pic_dir).unwrap()
};

let mut controller = photos_core::Controller::new(repo, scan);
let _ = controller.scan();
let all_pictures = controller.all().unwrap();

let mut pictures = FactoryVecDeque::builder()
.launch(gtk::Box::default())
.forward(sender.input_sender(), |_output| {});

for p in all_pictures.iter().take(10) {
let path = path::PathBuf::from("/var/home/david/Pictures").join(&p.relative_path);
pictures.guard().push_back(path);
}

let model = AllPhotos { pictures };

let pictures_box = model.pictures.widget();
let widgets = view_output!();

ComponentParts { model, widgets }
}

fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {}
}
16 changes: 15 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ use gtk::prelude::{
};
use gtk::{gio, glib};

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

pub(super) struct App {
about_dialog: Controller<AboutDialog>,
all_photos: Controller<AllPhotos>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -82,11 +84,18 @@ impl SimpleComponent for App {
}
},


gtk::Label {
set_label: "Hello world!",
add_css_class: "title-header",
set_vexpand: true,
},

gtk::Stack {

add_child = model.all_photos.widget(),
}

}

}
Expand All @@ -102,7 +111,12 @@ impl SimpleComponent for App {
.launch(())
.detach();

let model = Self { about_dialog };
let all_photos = AllPhotos::builder().launch(()).detach();

let model = Self {
about_dialog,
all_photos,
};

let widgets = view_output!();

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#[rustfmt::skip]
mod config;
mod all_photos;
mod app;
mod modals;

Expand Down

0 comments on commit 452f101

Please sign in to comment.