Skip to content

Commit

Permalink
Fixed crash in similar images, added icons to krokiet, changed a litt…
Browse files Browse the repository at this point in the history
…e gui, modified logo (#1359)
  • Loading branch information
qarmin authored Oct 6, 2024
1 parent 3925f03 commit b3ff7e3
Show file tree
Hide file tree
Showing 28 changed files with 301 additions and 128 deletions.
20 changes: 17 additions & 3 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

### Breaking changes

- Due removing image_type from image struct, old cache files are incompatible with new version and should be regenerated
- Due to the removal image_type from image struct, old cache files are incompatible with new version and should be
regenerated
from scratch(it uses new name)

### Known regressions

- Slint 1.8 which Krokiet uses requires femtovg 0.9.2 which broke font
rendering - https://github.com/slint-ui/slint/issues/6298

### Core

- Removed some unnecessary panics - [#1354](https://github.com/qarmin/czkawka/pull/1354)
Expand All @@ -26,14 +32,22 @@
- Added avif support(via external C library, not enabled by
default) - [#1358](https://github.com/qarmin/czkawka/pull/1358)
- Integer overflow are enabled by default(prepare for reporting bugs, slower performance and
unstability) - [#1358](https://github.com/qarmin/czkawka/pull/1358)
general unstability) - [#1358](https://github.com/qarmin/czkawka/pull/1358)
- Fixed crash when loading invalid image cache - [#1230](https://github.com/qarmin/czkawka/pull/1230)

### Krokiet

- Fixed invalid default hash size in similar images - [#1354](https://github.com/qarmin/czkawka/pull/1354)
- Fixed and added more input parameters to the application - [#1354](https://github.com/qarmin/czkawka/pull/1354)
- Fixed problem with loading invalid preset - [#1226](https://github.com/qarmin/czkawka/pull/1226)
- Fixed crash when using 8 hash size with small similarity - [#1359](https://github.com/qarmin/czkawka/pull/1359)
- Disabling buttons when no files were found - [#1359](https://github.com/qarmin/czkawka/pull/1359)
- Changed way to close/open panel at bottom - [#1359](https://github.com/qarmin/czkawka/pull/1359)
- Modify logo a little - [#1359](https://github.com/qarmin/czkawka/pull/1359)
- Avoid errors when trying to load preview of not supported file - [#1359](https://github.com/qarmin/czkawka/pull/1359)
- Added ability to show preview of referenced folders - [#1359](https://github.com/qarmin/czkawka/pull/1359)
- Enable selecting with space and jumping over entries with
arrows and opening with enter - [#1359](https://github.com/qarmin/czkawka/pull/1359)

### GTK GUI

Expand All @@ -47,7 +61,7 @@

- Added options to find/remove images by size - [#1255](https://github.com/qarmin/czkawka/pull/1255)
- Fixed and added more input parameters to the application - [#1354](https://github.com/qarmin/czkawka/pull/1354)
- Fixed crash when stopping scan mutliple times - [#1355](https://github.com/qarmin/czkawka/pull/1355)
- Fixed crash when stopping scan multiple times - [#1355](https://github.com/qarmin/czkawka/pull/1355)
- Print results also in debug build - [#1355](https://github.com/qarmin/czkawka/pull/1355)

## Version 7.0.0 - 19.02.2024r
Expand Down
16 changes: 15 additions & 1 deletion czkawka_core/src/common_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use rawloader::RawLoader;
use symphonia::core::conv::IntoSample;

use crate::common;
use crate::common::{create_crash_message, HEIC_EXTENSIONS, JXL_IMAGE_EXTENSIONS, RAW_IMAGE_EXTENSIONS};
use crate::common::{create_crash_message, HEIC_EXTENSIONS, IMAGE_RS_EXTENSIONS, IMAGE_RS_SIMILAR_IMAGES_EXTENSIONS, JXL_IMAGE_EXTENSIONS, RAW_IMAGE_EXTENSIONS};
// #[cfg(feature = "heif")]
// use libheif_rs::LibHeif;

Expand Down Expand Up @@ -171,3 +171,17 @@ pub fn get_raw_image(path: impl AsRef<Path> + std::fmt::Debug) -> Result<Dynamic
debug!("Loading raw image --- {str_timer}");
Ok(res)
}

pub fn check_if_can_display_image(path: &str) -> bool {
let Some(extension) = Path::new(path).extension() else {
return false;
};
let extension_str = extension.to_string_lossy().to_lowercase();
#[cfg(feature = "heif")]
let allowed_extensions = &[IMAGE_RS_EXTENSIONS, RAW_IMAGE_EXTENSIONS, JXL_IMAGE_EXTENSIONS, HEIC_EXTENSIONS].concat();

#[cfg(not(feature = "heif"))]
let allowed_extensions = &[IMAGE_RS_EXTENSIONS, RAW_IMAGE_EXTENSIONS, JXL_IMAGE_EXTENSIONS].concat();

allowed_extensions.iter().any(|ext| extension_str.ends_with(ext))
}
8 changes: 5 additions & 3 deletions czkawka_core/src/similar_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ use crate::progress_data::{CurrentStage, ProgressData};

type ImHash = Vec<u8>;

// 40 is, similar like previous 20 in 8 hash size is useless
// But since Krowka have problems with proper changing max value in fly
// hardcode 40 as max value
pub const SIMILAR_VALUES: [[u32; 6]; 4] = [
[1, 2, 5, 7, 14, 20], // 8
[1, 2, 5, 7, 14, 40], // 8
[2, 5, 15, 30, 40, 40], // 16
[4, 10, 20, 40, 40, 40], // 32
[6, 20, 40, 40, 40, 40], // 64
Expand Down Expand Up @@ -357,7 +360,6 @@ impl SimilarImages {
.hash_alg(self.get_params().hash_alg)
.resize_filter(self.get_params().image_filter);
let hasher = hasher_config.to_hasher();

let hash = hasher.hash_image(&img);
file_entry.hash = hash.as_bytes().to_vec();

Expand Down Expand Up @@ -818,7 +820,7 @@ pub fn get_string_from_similarity(similarity: &u32, hash_size: u8) -> String {
} else if *similarity <= SIMILAR_VALUES[index_preset][5] {
flc!("core_similarity_minimal")
} else {
panic!();
panic!("Invalid similarity value {similarity} for hash size {hash_size} (index {index_preset})");
}
}

Expand Down
9 changes: 9 additions & 0 deletions krokiet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ should print something like
Slint: Build config: debug; Backend: software
```

## Scaling application

If you have high DPI monitor, you may want to scale application. You can do it by setting `SLINT_SCALE_FACTOR`
environment

```
SLINT_SCALE_FACTOR=2 cargo run
```

## Different theme

App was created with dark fluent theme in mind, but is possible to use light theme by setting `SLINT_STYLE` environment
Expand Down
1 change: 1 addition & 0 deletions krokiet/icons/krokiet_delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions krokiet/icons/krokiet_move.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions krokiet/icons/krokiet_search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions krokiet/icons/krokiet_select.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions krokiet/icons/krokiet_stop.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified krokiet/icons/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added krokiet/icons/logo_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 1 addition & 5 deletions krokiet/icons/settings.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 1 addition & 17 deletions krokiet/icons/subsettings.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions krokiet/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ pub fn create_excluded_directories_model_from_pathbuf(items: &[PathBuf]) -> Mode
ModelRc::new(VecModel::from(converted))
}

pub fn check_if_there_are_any_included_folders(app: &MainWindow) -> bool {
let included = app.global::<Settings>().get_included_directories_model();
included.iter().count() > 0
}

pub fn check_if_all_included_dirs_are_referenced(app: &MainWindow) -> bool {
let included = app.global::<Settings>().get_included_directories_model();
included.iter().all(|x| x.referenced_folder)
Expand Down
7 changes: 6 additions & 1 deletion krokiet/src/connect_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use humansize::{format_size, BINARY};
use rayon::prelude::*;
use slint::{ComponentHandle, ModelRc, SharedString, VecModel, Weak};

use crate::common::{check_if_all_included_dirs_are_referenced, split_u64_into_i32s};
use crate::common::{check_if_all_included_dirs_are_referenced, check_if_there_are_any_included_folders, split_u64_into_i32s};
use crate::settings::{
collect_settings, get_audio_check_type_idx, get_biggest_item_idx, get_duplicates_check_method_idx, get_duplicates_hash_type_idx, get_image_hash_alg_idx,
get_resize_algorithm_idx, SettingsCustom, ALLOWED_AUDIO_CHECK_TYPE_VALUES, ALLOWED_BIG_FILE_SIZE_VALUES, ALLOWED_DUPLICATES_CHECK_METHOD_VALUES,
Expand All @@ -37,6 +37,11 @@ pub fn connect_scan_button(app: &MainWindow, progress_sender: Sender<ProgressDat
app.on_scan_starting(move |active_tab| {
let app = a.upgrade().expect("Failed to upgrade app :(");

if !check_if_there_are_any_included_folders(&app) {
app.invoke_scan_ended("Cannot start scan when no included directories are set.".into());
return;
}

if check_if_all_included_dirs_are_referenced(&app) {
app.invoke_scan_ended("Cannot start scan when all included directories are set as referenced folders.".into());
return;
Expand Down
7 changes: 6 additions & 1 deletion krokiet/src/connect_show_preview.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::Path;
use std::time::{Duration, Instant};

use czkawka_core::common_image::get_dynamic_image_from_path;
use czkawka_core::common_image::{check_if_can_display_image, get_dynamic_image_from_path};
use image::DynamicImage;
use log::{debug, error};
use slint::ComponentHandle;
Expand All @@ -27,6 +27,11 @@ pub fn connect_show_preview(app: &MainWindow) {
return;
}

if !check_if_can_display_image(&image_path) {
set_preview_visible(&gui_state, None);
return;
}

// Do not load the same image again
if image_path == gui_state.get_preview_image_path() {
return;
Expand Down
Loading

0 comments on commit b3ff7e3

Please sign in to comment.