feat: click envelope image to open with an image viewer
All checks were successful
/ test_alpine_edge (pull_request) Successful in 12m38s
/ test_alpine_stable (pull_request) Successful in 12m40s

This commit is contained in:
jane400 2025-02-02 23:11:13 +01:00 committed by jane400
parent 12de95ca55
commit 464b97f889

View file

@ -23,18 +23,24 @@ pub struct AdviceCard {
#[do_not_track] #[do_not_track]
metadata: Advice, metadata: Advice,
texture: Option<gdk::Texture>, texture: Option<gdk::Texture>,
file: Option<gio::File>,
} }
#[derive(Debug)] #[derive(Debug)]
pub enum AdviceCardCmds { pub enum AdviceCardCmds {
GotTexture(gdk::Texture), GotTexture(gio::File, gdk::Texture),
Error(LibraryError), Error(LibraryError),
} }
#[derive(Debug)]
pub enum AdviceCardInput {
OpenFile
}
#[relm4::factory(pub)] #[relm4::factory(pub)]
impl FactoryComponent for AdviceCard { impl FactoryComponent for AdviceCard {
type Init = Advice; type Init = Advice;
type Input = (); type Input = AdviceCardInput;
type Output = (); type Output = ();
type CommandOutput = AdviceCardCmds; type CommandOutput = AdviceCardCmds;
type ParentWidget = gtk::FlowBox; type ParentWidget = gtk::FlowBox;
@ -42,8 +48,8 @@ impl FactoryComponent for AdviceCard {
/* TODO: /* TODO:
* Action "View in Image viewer": * Action "View in Image viewer":
* Triggers: * Triggers:
* - One click on "enlarge" button * - [x] One click on "enlarge" button
* - Double click on "texture" itself * - [ ] Double click on "texture" itself
* (Is there a better way than this?) * (Is there a better way than this?)
* Create temporary file, let application open this file... * Create temporary file, let application open this file...
*/ */
@ -78,6 +84,8 @@ impl FactoryComponent for AdviceCard {
set_icon_name: "four-arrows-pointing-outward-symbolic", set_icon_name: "four-arrows-pointing-outward-symbolic",
set_margin_all: 8, set_margin_all: 8,
connect_clicked => AdviceCardInput::OpenFile,
}, },
#[wrap(Some)] #[wrap(Some)]
@ -94,6 +102,7 @@ impl FactoryComponent for AdviceCard {
let _self = Self { let _self = Self {
metadata: value.clone(), metadata: value.clone(),
texture: None, texture: None,
file: None,
tracker: 0, tracker: 0,
}; };
@ -119,7 +128,7 @@ impl FactoryComponent for AdviceCard {
file file
}; };
let image = glycin::Loader::new(file) let image = glycin::Loader::new(file.clone())
.load() .load()
.await .await
.expect("Image decoding failed"); .expect("Image decoding failed");
@ -128,7 +137,7 @@ impl FactoryComponent for AdviceCard {
.await .await
.expect("Image frame decoding failed"); .expect("Image frame decoding failed");
AdviceCardCmds::GotTexture(frame.texture()) AdviceCardCmds::GotTexture(file, frame.texture())
}); });
_self _self
@ -136,8 +145,21 @@ impl FactoryComponent for AdviceCard {
fn update_cmd(&mut self, message: Self::CommandOutput, sender: FactorySender<Self>) { fn update_cmd(&mut self, message: Self::CommandOutput, sender: FactorySender<Self>) {
match message { match message {
AdviceCardCmds::GotTexture(texture) => self.set_texture(Some(texture)), AdviceCardCmds::GotTexture(file, texture) => {
self.set_texture(Some(texture));
self.set_file(Some(file));
},
AdviceCardCmds::Error(err) => todo!(), AdviceCardCmds::Error(err) => todo!(),
}; };
} }
fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {
match message {
AdviceCardInput::OpenFile => {
let file_launcher = gtk::FileLauncher::new(self.get_file().as_ref());
file_launcher.set_always_ask(true);
file_launcher.launch(None::<&gtk::Window>, None::<&gio::Cancellable>, |_| {});
},
}
}
} }