Show errors in image previewer when failed to generate it (#130)
This commit is contained in:
parent
5672431257
commit
880787a67f
|
@ -100,7 +100,7 @@ pub enum Commands {
|
|||
excluded_directories: ExcludedDirectories,
|
||||
#[structopt(short, long, parse(try_from_str = parse_minimal_file_size), default_value = "16384", help = "Minimum size in bytes", long_help = "Minimum size of checked files in bytes, assigning bigger value may speed up searching")]
|
||||
minimal_file_size: u64,
|
||||
#[structopt(short, long, default_value = "High", parse(try_from_str = parse_similar_images_similarity), help = "Similairty level (VerySmall, Small, Medium, High, Very High)", long_help = "Methods to choose similarity level of images which will be considered as duplicated.")]
|
||||
#[structopt(short, long, default_value = "High", parse(try_from_str = parse_similar_images_similarity), help = "Similairty level (Minimal, VerySmall, Small, Medium, High, Very High)", long_help = "Methods to choose similarity level of images which will be considered as duplicated.")]
|
||||
similarity: Similarity,
|
||||
#[structopt(flatten)]
|
||||
excluded_items: ExcludedItems,
|
||||
|
@ -240,6 +240,7 @@ fn parse_delete_method(src: &str) -> Result<DeleteMethod, &'static str> {
|
|||
|
||||
fn parse_similar_images_similarity(src: &str) -> Result<Similarity, &'static str> {
|
||||
match src.to_ascii_lowercase().replace('_', "").as_str() {
|
||||
"minimal" => Ok(Similarity::Minimal),
|
||||
"verysmall" => Ok(Similarity::VerySmall),
|
||||
"small" => Ok(Similarity::Small),
|
||||
"medium" => Ok(Similarity::Medium),
|
||||
|
|
|
@ -30,12 +30,12 @@ pub struct ProgressData {
|
|||
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
|
||||
pub enum Similarity {
|
||||
None,
|
||||
Minimal,
|
||||
VerySmall,
|
||||
Small,
|
||||
Medium,
|
||||
High,
|
||||
VeryHigh,
|
||||
Minimal,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
|
@ -250,7 +250,7 @@ pub fn hide_all_buttons(buttons_array: &[gtk::Button]) {
|
|||
pub fn get_text_from_similarity(similarity: &Similarity) -> &str {
|
||||
match similarity {
|
||||
Similarity::None => "Original",
|
||||
Similarity::Minimal => "Original",
|
||||
Similarity::Minimal => "Minimal",
|
||||
Similarity::VerySmall => "Very Small",
|
||||
Similarity::Small => "Small",
|
||||
Similarity::Medium => "Medium",
|
||||
|
|
|
@ -32,6 +32,7 @@ pub fn initialize_gui(gui_data: &GuiData) {
|
|||
let scrolled_window_excluded_directories = gui_data.scrolled_window_excluded_directories.clone();
|
||||
let image_preview_similar_images = gui_data.image_preview_similar_images.clone();
|
||||
let check_button_settings_show_preview_similar_images = gui_data.check_button_settings_show_preview_similar_images.clone();
|
||||
let text_view_errors = gui_data.text_view_errors.clone();
|
||||
|
||||
// Disable and show buttons
|
||||
buttons_search.show();
|
||||
|
@ -169,21 +170,24 @@ pub fn initialize_gui(gui_data: &GuiData) {
|
|||
let cache_dir = proj_dirs.cache_dir();
|
||||
if cache_dir.exists() {
|
||||
if !cache_dir.is_dir() {
|
||||
add_text_to_text_view(&text_view_errors, format!("Path {} doesn't point at folder, which is needed by image preview", cache_dir.display()).as_str());
|
||||
break 'dir;
|
||||
}
|
||||
} else if fs::create_dir(cache_dir).is_err() {
|
||||
} else if fs::create_dir_all(cache_dir).is_err() {
|
||||
add_text_to_text_view(&text_view_errors, format!("Failed to create dir {} needed by image preview", cache_dir.display()).as_str());
|
||||
break 'dir;
|
||||
}
|
||||
let path = tree_model.get_value(&tree_model.get_iter(&tree_path).unwrap(), ColumnsSimilarImages::Path as i32).get::<String>().unwrap().unwrap();
|
||||
let name = tree_model.get_value(&tree_model.get_iter(&tree_path).unwrap(), ColumnsSimilarImages::Name as i32).get::<String>().unwrap().unwrap();
|
||||
|
||||
let file_name = format!("{}/{}", path, name); //"/home/rafal/Pulpit/karl-fitzgerald-4.jpg";
|
||||
let file_name = format!("{}/{}", path, name);
|
||||
let file_name = file_name.as_str();
|
||||
|
||||
if let Some(extension) = Path::new(file_name).extension() {
|
||||
let img = match image::open(&file_name) {
|
||||
Ok(t) => t,
|
||||
Err(_) => {
|
||||
add_text_to_text_view(&text_view_errors, format!("Failed to open temporary image file {}", file_name).as_str());
|
||||
break 'dir;
|
||||
}
|
||||
};
|
||||
|
@ -204,6 +208,7 @@ pub fn initialize_gui(gui_data: &GuiData) {
|
|||
let img = img.resize(new_size.0, new_size.1, FilterType::Triangle);
|
||||
let file_dir = cache_dir.join(format!("cached_file.{}", extension.to_string_lossy()));
|
||||
if img.save(&file_dir).is_err() {
|
||||
add_text_to_text_view(&text_view_errors, format!("Failed to save temporary image file to {}", file_dir.display()).as_str());
|
||||
break 'dir;
|
||||
}
|
||||
let string_dir = file_dir.to_string_lossy().to_string();
|
||||
|
|
|
@ -33,7 +33,7 @@ pub fn save_configuration(gui_data: &GuiData, manual_execution: bool) {
|
|||
add_text_to_text_view(&text_view_errors, format!("Cannot create save file inside {} because this isn't a folder.", config_dir.display()).as_str());
|
||||
return;
|
||||
}
|
||||
} else if fs::create_dir(config_dir).is_err() {
|
||||
} else if fs::create_dir_all(config_dir).is_err() {
|
||||
add_text_to_text_view(&text_view_errors, format!("Failed configuration to create configuration folder {}", config_dir.display()).as_str());
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue