Load posters by UUID from XDG data directory
This commit is contained in:
parent
ab2e4ab0ad
commit
0d841f95c4
2 changed files with 37 additions and 36 deletions
|
|
@ -8,8 +8,8 @@ use gtk4 :: pango :: * ;
|
|||
use gtk4 :: pango :: Weight :: * ;
|
||||
use gtk4 :: prelude :: * ;
|
||||
use std :: cell :: * ;
|
||||
use std :: env :: * ;
|
||||
use std :: iter :: * ;
|
||||
use std :: path :: PathBuf ;
|
||||
|
||||
use crate :: ui :: collatable_container :: * ;
|
||||
use crate :: ui :: component :: * ;
|
||||
|
|
@ -63,20 +63,36 @@ impl < A : MediaAdapter > CollatedMediaGrid <A> {
|
|||
@ margin_top : 20 ;
|
||||
@ margin_bottom : 20 ;
|
||||
|
||||
match media . get_poster_file_path () {
|
||||
Some (poster_file_path) => {
|
||||
let poster_file_path = PathBuf :: from (poster_file_path) ; // God forbid `Path` would work with `clone ! ()`
|
||||
let poster_texture = spawn_blocking (
|
||||
move || Texture :: from_filename (poster_file_path) . unwrap () ,
|
||||
) . await . unwrap () ;
|
||||
Some ( image ! (
|
||||
{
|
||||
let home_directory = var_os ("HOME") . unwrap () ;
|
||||
let xdg_data_home = var_os ("XDG_DATA_HOME") ;
|
||||
|
||||
let data_dir = match xdg_data_home {
|
||||
Some (xdg_data_home) => concat_os_str ! ( xdg_data_home , "/zoodex" ) ,
|
||||
None => concat_os_str ! ( home_directory , "/.local/share/zoodex" ) ,
|
||||
} ;
|
||||
|
||||
let poster_file_path = concat_os_str ! ( data_dir , "/posters/" , media . get_uuid () ) ;
|
||||
|
||||
let poster_texture = spawn_blocking (
|
||||
move || Texture :: from_filename (poster_file_path) ,
|
||||
) . await . unwrap () ;
|
||||
|
||||
match poster_texture {
|
||||
Ok (poster_texture) => Some ( image ! (
|
||||
@ paintable : & poster_texture ;
|
||||
@ width_request : 300 ;
|
||||
@ height_request : 300 ;
|
||||
@ margin_bottom : 10 ;
|
||||
) )
|
||||
} ,
|
||||
None => None ,
|
||||
) ) ,
|
||||
Err (error) => {
|
||||
if error . matches ( IOErrorEnum :: NotFound ) {
|
||||
None // The file not existing simply means there is no poster for this piece of media
|
||||
} else {
|
||||
panic ! ( "{}" , error ) // Any other error means something unexpected went wrong
|
||||
}
|
||||
} ,
|
||||
}
|
||||
} . as_ref () ,
|
||||
|
||||
Some ( & label ! (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue