1
0
Fork 0
mirror of synced 2024-05-17 19:03:08 +12:00
This commit is contained in:
Rafał Mikrut 2024-02-15 08:34:06 +01:00
parent 6567bc7d8f
commit a5481ae759
3 changed files with 98 additions and 33 deletions

View file

@ -3,36 +3,89 @@ use std::path::PathBuf;
use crate::{CurrentTab, ExcludedDirectoriesModel, IncludedDirectoriesModel, MainListModel, MainWindow}; use crate::{CurrentTab, ExcludedDirectoriesModel, IncludedDirectoriesModel, MainListModel, MainWindow};
use slint::{ModelRc, SharedString, VecModel}; use slint::{ModelRc, SharedString, VecModel};
// Int model is used to store data in unchanged(* except that we need to split u64 into two i32) form and is used to sort/select data
// Str model is used to display data in gui
#[repr(u8)]
pub enum IntDataSimilarImages {
ModificationDatePart1 = 0,
ModificationDatePart2,
SizePart1,
SizePart2,
Width,
Height,
}
#[repr(u8)]
pub enum StrDataSimilarImages {
Similarity = 0,
Size,
Resolution,
Name,
Path,
ModificationDate,
}
#[repr(u8)]
pub enum IntDataEmptyFiles {
ModificationDatePart1 = 0,
ModificationDatePart2,
SizePart1,
SizePart2,
}
#[repr(u8)]
pub enum StrDataEmptyFiles {
Name = 0,
Path,
ModificationDate,
}
#[repr(u8)]
pub enum IntDataEmptyFolders {
ModificationDatePart1 = 0,
ModificationDatePart2,
}
#[repr(u8)]
pub enum StrDataEmptyFolders {
Name = 0,
Path,
ModificationDate,
}
// Remember to match updated this according to ui/main_lists.slint and connect_scan.rs files // Remember to match updated this according to ui/main_lists.slint and connect_scan.rs files
pub fn get_str_path_idx(active_tab: CurrentTab) -> usize { pub fn get_str_path_idx(active_tab: CurrentTab) -> usize {
match active_tab { match active_tab {
CurrentTab::EmptyFolders => 1, CurrentTab::EmptyFolders => StrDataEmptyFolders::Path as usize,
CurrentTab::EmptyFiles => 1, CurrentTab::EmptyFiles => StrDataEmptyFiles::Path as usize,
CurrentTab::SimilarImages => 4, CurrentTab::SimilarImages => StrDataSimilarImages::Path as usize,
CurrentTab::Settings | CurrentTab::About => panic!("Button should be disabled"), CurrentTab::Settings | CurrentTab::About => panic!("Button should be disabled"),
} }
} }
pub fn get_str_name_idx(active_tab: CurrentTab) -> usize { pub fn get_str_name_idx(active_tab: CurrentTab) -> usize {
match active_tab { match active_tab {
CurrentTab::EmptyFolders => 0, CurrentTab::EmptyFolders => StrDataEmptyFolders::Name as usize,
CurrentTab::EmptyFiles => 0, CurrentTab::EmptyFiles => StrDataEmptyFiles::Name as usize,
CurrentTab::SimilarImages => 3, CurrentTab::SimilarImages => StrDataSimilarImages::Name as usize,
CurrentTab::Settings | CurrentTab::About => panic!("Button should be disabled"), CurrentTab::Settings | CurrentTab::About => panic!("Button should be disabled"),
} }
} }
pub fn get_int_modification_date_idx(active_tab: CurrentTab) -> usize { pub fn get_int_modification_date_idx(active_tab: CurrentTab) -> usize {
match active_tab { match active_tab {
CurrentTab::EmptyFiles => 0, CurrentTab::EmptyFiles => IntDataEmptyFiles::ModificationDatePart1 as usize,
CurrentTab::SimilarImages => 0, CurrentTab::EmptyFolders => IntDataEmptyFolders::ModificationDatePart1 as usize,
CurrentTab::EmptyFolders => 0, CurrentTab::SimilarImages => IntDataSimilarImages::ModificationDatePart1 as usize,
CurrentTab::Settings | CurrentTab::About => panic!("Button should be disabled"), CurrentTab::Settings | CurrentTab::About => panic!("Button should be disabled"),
} }
} }
pub fn get_int_size_idx(active_tab: CurrentTab) -> usize { pub fn get_int_size_idx(active_tab: CurrentTab) -> usize {
match active_tab { match active_tab {
CurrentTab::EmptyFiles => 2, CurrentTab::EmptyFiles => IntDataEmptyFiles::SizePart1 as usize,
CurrentTab::SimilarImages => 2, CurrentTab::SimilarImages => IntDataSimilarImages::SizePart1 as usize,
CurrentTab::Settings | CurrentTab::About => panic!("Button should be disabled"), CurrentTab::Settings | CurrentTab::About => panic!("Button should be disabled"),
CurrentTab::EmptyFolders => panic!("Unable to get size from this tab"), CurrentTab::EmptyFolders => panic!("Unable to get size from this tab"),
} }
@ -40,14 +93,15 @@ pub fn get_int_size_idx(active_tab: CurrentTab) -> usize {
pub fn get_int_width_idx(active_tab: CurrentTab) -> usize { pub fn get_int_width_idx(active_tab: CurrentTab) -> usize {
match active_tab { match active_tab {
CurrentTab::SimilarImages => 4, CurrentTab::SimilarImages => IntDataSimilarImages::Width as usize,
CurrentTab::Settings | CurrentTab::About => panic!("Button should be disabled"), CurrentTab::Settings | CurrentTab::About => panic!("Button should be disabled"),
_ => panic!("Unable to get height from this tab"), _ => panic!("Unable to get height from this tab"),
} }
} }
pub fn get_int_height_idx(active_tab: CurrentTab) -> usize { pub fn get_int_height_idx(active_tab: CurrentTab) -> usize {
match active_tab { match active_tab {
CurrentTab::SimilarImages => 5, CurrentTab::SimilarImages => IntDataSimilarImages::Height as usize,
CurrentTab::Settings | CurrentTab::About => panic!("Button should be disabled"), CurrentTab::Settings | CurrentTab::About => panic!("Button should be disabled"),
_ => panic!("Unable to get height from this tab"), _ => panic!("Unable to get height from this tab"),
} }
@ -140,6 +194,7 @@ pub fn split_u64_into_i32s(value: u64) -> (i32, i32) {
let part2: i32 = value as i32; let part2: i32 = value as i32;
(part1, part2) (part1, part2)
} }
pub fn connect_i32_into_u64(part1: i32, part2: i32) -> u64 { pub fn connect_i32_into_u64(part1: i32, part2: i32) -> u64 {
((part1 as u64) << 32) | (part2 as u64 & 0xFFFFFFFF) ((part1 as u64) << 32) | (part2 as u64 & 0xFFFFFFFF)
} }
@ -155,6 +210,7 @@ mod test {
assert_eq!(part1, 0); assert_eq!(part1, 0);
assert_eq!(part2, 1); assert_eq!(part2, 1);
} }
#[test] #[test]
fn test_split_u64_into_i32s_big() { fn test_split_u64_into_i32s_big() {
let value = u64::MAX; let value = u64::MAX;
@ -162,6 +218,7 @@ mod test {
assert_eq!(part1, -1); assert_eq!(part1, -1);
assert_eq!(part2, -1); assert_eq!(part2, -1);
} }
#[test] #[test]
fn test_connect_i32_into_u64_small() { fn test_connect_i32_into_u64_small() {
let part1 = 0; let part1 = 0;
@ -169,6 +226,7 @@ mod test {
let value = super::connect_i32_into_u64(part1, part2); let value = super::connect_i32_into_u64(part1, part2);
assert_eq!(value, 1); assert_eq!(value, 1);
} }
#[test] #[test]
fn test_connect_i32_into_u64_big() { fn test_connect_i32_into_u64_big() {
let part1 = -1; let part1 = -1;
@ -176,6 +234,7 @@ mod test {
let value = super::connect_i32_into_u64(part1, part2); let value = super::connect_i32_into_u64(part1, part2);
assert_eq!(value, u64::MAX); assert_eq!(value, u64::MAX);
} }
#[test] #[test]
fn test_connect_split_zero() { fn test_connect_split_zero() {
for start_value in [0, 1, 10, u32::MAX as u64, i32::MAX as u64, u64::MAX] { for start_value in [0, 1, 10, u32::MAX as u64, i32::MAX as u64, u64::MAX] {

View file

@ -1,11 +1,13 @@
use std::panic;
use std::path::Path; use std::path::Path;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use czkawka_core::broken_files::BrokenEntry;
use image::DynamicImage; use image::DynamicImage;
use log::{debug, error}; use log::{debug, error};
use slint::ComponentHandle; use slint::ComponentHandle;
use czkawka_core::common::{get_dynamic_image_from_raw_image, IMAGE_RS_EXTENSIONS, RAW_IMAGE_EXTENSIONS}; use czkawka_core::common::{create_crash_message, get_dynamic_image_from_raw_image, IMAGE_RS_EXTENSIONS, RAW_IMAGE_EXTENSIONS};
use crate::{Callabler, CurrentTab, GuiState, MainWindow, Settings}; use crate::{Callabler, CurrentTab, GuiState, MainWindow, Settings};
@ -80,30 +82,32 @@ fn load_image(image_path: &Path) -> Option<(Duration, image::DynamicImage)> {
let is_raw_image = RAW_IMAGE_EXTENSIONS.contains(&image_extension.as_str()); let is_raw_image = RAW_IMAGE_EXTENSIONS.contains(&image_extension.as_str());
let is_normal_image = IMAGE_RS_EXTENSIONS.contains(&image_extension.as_str()); let is_normal_image = IMAGE_RS_EXTENSIONS.contains(&image_extension.as_str());
if !is_raw_image && !is_normal_image {
return None;
}
let load_img_start_timer = Instant::now(); let load_img_start_timer = Instant::now();
// TODO this needs to be run inside closure let img = panic::catch_unwind(|| {
let img = if is_normal_image { let int_img = if is_normal_image {
match image::open(image_name) { match image::open(image_name) {
Ok(img) => img, Ok(img) => img,
Err(e) => { Err(e) => {
error!("Error while loading image: {}", e); error!("Error while loading image: {}", e);
return None;
}
}
} else if is_raw_image {
if let Some(img) = get_dynamic_image_from_raw_image(image_name) {
img
} else {
error!("Error while loading raw image - not sure why - try to guess");
return None; return None;
} }
}
} else if is_raw_image {
if let Some(img) = get_dynamic_image_from_raw_image(image_name) {
img
} else { } else {
error!("Error while loading raw image - not sure why - try to guess");
return None; return None;
} };
} else { Some(int_img)
panic!("Used not supported image extension"); })
}; .unwrap_or_else(|e| {
error!("Error while loading image: {e:?}");
None
})?;
Some((load_img_start_timer.elapsed(), img)) Some((load_img_start_timer.elapsed(), img))
} }

View file

@ -28,6 +28,8 @@ export component MainWindow inherits Window {
callback show_move_folders_dialog(string); callback show_move_folders_dialog(string);
callback folders_move_choose_requested(); callback folders_move_choose_requested();
title: "Krokiet - Data Cleaner";
min-width: 300px; min-width: 300px;
preferred-width: 800px; preferred-width: 800px;
min-height: 300px; min-height: 300px;