Skip to content

Commit

Permalink
Jd
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin committed Feb 25, 2025
1 parent 0b4dbfe commit 6037c68
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 40 deletions.
106 changes: 79 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

### GTK GUI
- Added window icon in wayland - [#1400](https://github.com/qarmin/czkawka/pull/1400)
- Disabled broken sort button - [#1400](https://github.com/qarmin/czkawka/pull/1400)

### CLI

Expand Down
3 changes: 3 additions & 0 deletions czkawka_gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ rayon = "1.10"

czkawka_core = { path = "../czkawka_core", version = "8.0.0", features = [] }

[dev-dependencies]
rand = "0.9.0"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.9", features = ["combaseapi", "objbase", "shobjidl_core", "windef", "winerror", "wtypesbase", "winuser"] }

Expand Down
55 changes: 55 additions & 0 deletions czkawka_gui/src/connect_things/connect_popovers_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ mod test {
use glib::types::Type;
use gtk4::prelude::*;
use gtk4::{Popover, TreeView};
use rand::random;

use crate::connect_things::connect_popovers_sort::{popover_sort_general, sort_iters};

Expand Down Expand Up @@ -230,4 +231,58 @@ mod test {
list_store.iter_next(&curr_iter);
}
}

#[gtk4::test]
pub fn _fuzzer_test() {
for _ in 0..10000 {
let columns_types: &[Type] = &[Type::BOOL, Type::STRING];
let list_store = gtk4::ListStore::new(columns_types);
let tree_view = TreeView::builder().model(&list_store).build();
let popover = Popover::new();

let first_row: &[(u32, &dyn ToValue)] = &[(0, &true), (1, &"AAA")];
list_store.set(&list_store.append(), first_row);

let mut since_last_header = 0;

(0..(random::<u32>() % 10 + 5)).for_each(|_| {
let bool_val = if since_last_header < 2 {
since_last_header += 1;
false
} else {
since_last_header = 0;
random()
};
let string_val = rand::random::<u32>().to_string();
let a: Vec<(u32, &dyn ToValue)> = vec![(0, &bool_val), (1, &string_val)];

list_store.set(&list_store.append(), &a);
});

if since_last_header < 2 {
// This is invalid, and should be vec![(0, &false), (1, &"AAA")]
// but this triggers the bug
let a: Vec<(u32, &dyn ToValue)> = vec![(0, &true), (1, &"AAA")];
list_store.set(&list_store.append(), &a);
let b: Vec<(u32, &dyn ToValue)> = vec![(0, &false), (1, &"BBB")];
list_store.set(&list_store.append(), &b);
}

print_two_items_model(&list_store);

popover_sort_general::<String>(&popover, &tree_view, 1, 0);
}
}

fn print_two_items_model(model: &gtk4::ListStore) {
let iter = model.iter_first().expect("Failed to get first iter");
loop {
let bool_val = model.get::<bool>(&iter, 0);
let string_val = model.get::<String>(&iter, 1);
println!("{bool_val} {string_val}");
if !model.iter_next(&iter) {
break;
}
}
}
}
4 changes: 2 additions & 2 deletions czkawka_gui/src/connect_things/connect_progress_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn common_set_data(item: &ProgressData, progress_bar_all_stages: &ProgressBar, p
let all_stages = (item.current_stage_idx as f64 + current_items_checked as f64 / current_stage_items_to_check as f64) / (item.max_stage_idx + 1) as f64;
let all_stages = all_stages.min(0.99);
progress_bar_all_stages.set_fraction(all_stages);
progress_bar_current_stage.set_fraction(current_items_checked as f64 / item.entries_to_check as f64);
progress_bar_current_stage.set_fraction(current_items_checked as f64 / current_stage_items_to_check as f64);

taskbar_state.borrow().set_progress_value(
(item.current_stage_idx as u64) * current_stage_items_to_check + current_items_checked,
Expand All @@ -189,7 +189,7 @@ fn file_number_tm(item: &ProgressData) -> HashMap<&'static str, String> {
fn progress_ratio_tm(item: &ProgressData) -> HashMap<&'static str, String> {
let mut v = vec![("file_checked", item.entries_checked.to_string()), ("all_files", item.entries_to_check.to_string())];
if item.bytes_to_check != 0 {
v.push(("data_to_check", format_size(item.bytes_checked, BINARY)));
v.push(("data_checked", format_size(item.bytes_checked, BINARY)));
v.push(("all_data", format_size(item.bytes_to_check, BINARY)));
}
generate_translation_hashmap(v)
Expand Down
8 changes: 8 additions & 0 deletions czkawka_gui/src/help_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,14 @@ pub fn add_text_to_text_view(text_view: &TextView, string_to_append: &str) {

pub fn set_buttons(hashmap: &mut HashMap<BottomButtonsEnum, bool>, buttons_array: &[Widget], button_names: &[BottomButtonsEnum]) {
for (index, button) in buttons_array.iter().enumerate() {
if button_names[index] == BottomButtonsEnum::Sort {
// TODO - sort button is broken, I don't have skills and time to fix it
// The problem is that to speedup sorting, we operate on item iters
// To fix this, we should just take entire model and sort it, which will be slow in some cases
// Alternatively, just current operations on iters should be fixed(I cannot find exact problem)
continue;
}

if *hashmap.get_mut(&button_names[index]).expect("Invalid button name") {
button.show();
} else {
Expand Down
Loading

0 comments on commit 6037c68

Please sign in to comment.