1
0
Fork 0
mirror of synced 2024-06-02 10:35:02 +12:00

Do not allow to add multiple same directories to check

This commit is contained in:
Rafał Mikrut 2022-07-23 20:17:42 +02:00
parent 34f7ecb9bc
commit 90d1eda08f
4 changed files with 92 additions and 33 deletions

View file

@ -549,7 +549,7 @@ impl SameMusic {
}
let mut hash_map: BTreeMap<String, Vec<MusicEntry>> = Default::default();
for file_entry in vec_file_entry {
let mut thing = file_entry.track_title.to_lowercase().trim().to_string();
let mut thing = file_entry.track_title.trim().to_lowercase();
if self.approximate_comparison {
get_approximate_conversion(&mut thing);
}
@ -577,7 +577,7 @@ impl SameMusic {
}
let mut hash_map: BTreeMap<String, Vec<MusicEntry>> = Default::default();
for file_entry in vec_file_entry {
let mut thing = file_entry.track_artist.to_lowercase().trim().to_string();
let mut thing = file_entry.track_artist.trim().to_lowercase();
if self.approximate_comparison {
get_approximate_conversion(&mut thing);
}
@ -605,7 +605,7 @@ impl SameMusic {
}
let mut hash_map: BTreeMap<String, Vec<MusicEntry>> = Default::default();
for file_entry in vec_file_entry {
let thing = file_entry.year.to_lowercase().trim().to_string();
let thing = file_entry.year.trim().to_lowercase();
if !thing.is_empty() {
hash_map.entry(thing.clone()).or_insert_with(Vec::new).push(file_entry);
}
@ -630,7 +630,7 @@ impl SameMusic {
}
let mut hash_map: BTreeMap<String, Vec<MusicEntry>> = Default::default();
for file_entry in vec_file_entry {
let thing = file_entry.length.to_lowercase().trim().to_string();
let thing = file_entry.length.trim().to_lowercase();
if !thing.is_empty() {
hash_map.entry(thing.clone()).or_insert_with(Vec::new).push(file_entry);
}
@ -655,7 +655,7 @@ impl SameMusic {
}
let mut hash_map: BTreeMap<String, Vec<MusicEntry>> = Default::default();
for file_entry in vec_file_entry {
let thing = file_entry.genre.to_lowercase().trim().to_string();
let thing = file_entry.genre.trim().to_lowercase();
if !thing.is_empty() {
hash_map.entry(thing.clone()).or_insert_with(Vec::new).push(file_entry);
}

View file

@ -140,7 +140,12 @@ upper_manual_add_included_button_tooltip =
/home/roman;/home/rozkaz will add two directories /home/roman and /home/rozkaz
upper_add_included_button_tooltip = Add new directory to search.
upper_remove_included_button_tooltip = Delete directory from search.
upper_manual_add_excluded_button_tooltip = Add excluded directory name by hand.
upper_manual_add_excluded_button_tooltip =
Add excluded directory name by hand.
To add multiple paths at once, separate them by ;
/home/roman;/home/krokiet will add two directories /home/roman and /home/keokiet
upper_add_excluded_button_tooltip = Add directory to be excluded in search.
upper_remove_excluded_button_tooltip = Delete directory from excluded.

View file

@ -8,7 +8,7 @@ use czkawka_core::common::Common;
use crate::flg;
use crate::gui_structs::gui_data::GuiData;
use crate::help_functions::{get_list_store, ColumnsExcludedDirectory, ColumnsIncludedDirectory};
use crate::help_functions::{check_if_value_is_in_list_store, get_list_store, ColumnsExcludedDirectory, ColumnsIncludedDirectory};
pub fn connect_selection_of_directories(gui_data: &GuiData) {
// Add manually directory
@ -158,19 +158,27 @@ fn add_manually_directories(window_main: &Window, tree_view: &TreeView, excluded
dialog.connect_response(move |dialog, response_type| {
if response_type == gtk4::ResponseType::Ok {
for text in entry.text().split(';') {
let text = text.trim().to_string();
let mut text = text.trim().to_string();
#[cfg(target_family = "windows")]
let text = Common::normalize_windows_path(text).to_string_lossy().to_string();
let mut text = Common::normalize_windows_path(text).to_string_lossy().to_string();
while text != "/" && (text.ends_with('/') || text.ends_with('\\')) {
text.pop();
}
if !text.is_empty() {
let list_store = get_list_store(&tree_view);
if excluded_items {
let values: [(u32, &dyn ToValue); 1] = [(ColumnsExcludedDirectory::Path as u32, &text)];
list_store.set(&list_store.append(), &values);
if !(check_if_value_is_in_list_store(&list_store, ColumnsExcludedDirectory::Path as i32, &text)) {
let values: [(u32, &dyn ToValue); 1] = [(ColumnsExcludedDirectory::Path as u32, &text)];
list_store.set(&list_store.append(), &values);
}
} else {
let values: [(u32, &dyn ToValue); 2] = [(ColumnsIncludedDirectory::Path as u32, &text), (ColumnsIncludedDirectory::ReferenceButton as u32, &false)];
list_store.set(&list_store.append(), &values);
if !check_if_value_is_in_list_store(&list_store, ColumnsIncludedDirectory::Path as i32, &text) {
let values: [(u32, &dyn ToValue); 2] = [(ColumnsIncludedDirectory::Path as u32, &text), (ColumnsIncludedDirectory::ReferenceButton as u32, &false)];
list_store.set(&list_store.append(), &values);
}
}
}
}

View file

@ -725,25 +725,22 @@ pub fn get_pixbuf_from_dynamic_image(dynamic_image: &DynamicImage) -> Result<Pix
Pixbuf::from_read(arra)
}
#[test]
fn test_file_name_shortener() {
let name_to_check = "/home/rafal/czkawek/romek/atomek.txt";
assert_eq!(get_max_file_name(name_to_check, 20), "/home/rafa ... atomek.txt");
assert_eq!(get_max_file_name(name_to_check, 21), "/home/rafa ... /atomek.txt");
let name_to_check = "/home/rafal/czkawek/romek/czekistan/atomek.txt";
assert_eq!(get_max_file_name(name_to_check, 21), "/home/rafa ... /atomek.txt");
assert_eq!(get_max_file_name(name_to_check, 80), name_to_check);
let name_to_check = "/home/rafal/‍🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈.txt";
assert_eq!(get_max_file_name(name_to_check, 21), "/home/rafa ... 🌈🌈🌈🌈🌈🌈🌈.txt");
assert_eq!(get_max_file_name(name_to_check, 20), "/home/rafa ... 🌈🌈🌈🌈🌈🌈.txt");
assert_eq!(get_max_file_name(name_to_check, 19), "/home/rafa ... 🌈🌈🌈🌈🌈.txt");
let name_to_check = "/home/rafal/‍🏳️‍🌈️🏳️‍🌈️🏳️‍🌈️🏳️‍🌈️🏳️‍🌈️🏳️‍🌈️🏳️‍🌈️🏳️‍🌈️🏳️‍🌈️.txt";
assert_eq!(get_max_file_name(name_to_check, 21), "/home/rafa ... 🌈\u{fe0f}🏳\u{fe0f}\u{200d}🌈\u{fe0f}.txt");
assert_eq!(get_max_file_name(name_to_check, 20), "/home/rafa ... \u{fe0f}🏳\u{fe0f}\u{200d}🌈\u{fe0f}.txt");
assert_eq!(get_max_file_name(name_to_check, 19), "/home/rafa ... 🏳\u{fe0f}\u{200d}🌈\u{fe0f}.txt");
assert_eq!(get_max_file_name(name_to_check, 18), "/home/rafa ... \u{fe0f}\u{200d}🌈\u{fe0f}.txt");
assert_eq!(get_max_file_name(name_to_check, 17), "/home/rafa ... \u{200d}🌈\u{fe0f}.txt");
assert_eq!(get_max_file_name(name_to_check, 16), "/home/rafa ... 🌈\u{fe0f}.txt");
pub fn check_if_value_is_in_list_store(list_store: &ListStore, column: i32, value: &str) -> bool {
if let Some(iter) = list_store.iter_first() {
loop {
let list_store_value: String = list_store.get::<String>(&iter, column as i32);
if value == list_store_value {
return true;
}
if !list_store.iter_next(&iter) {
break;
}
}
}
false
}
#[cfg(test)]
@ -752,7 +749,56 @@ mod test {
use gtk4::Orientation;
use image::DynamicImage;
use crate::help_functions::{change_dimension_to_krotka, get_all_boxes_from_widget, get_all_direct_children, get_pixbuf_from_dynamic_image};
use crate::help_functions::{
change_dimension_to_krotka, check_if_value_is_in_list_store, get_all_boxes_from_widget, get_all_direct_children, get_max_file_name, get_pixbuf_from_dynamic_image,
};
#[gtk4::test]
fn test_check_if_value_is_in_list_store() {
let columns_types: &[glib::types::Type] = &[glib::types::Type::STRING];
let list_store = gtk4::ListStore::new(columns_types);
let values_to_add: &[(u32, &dyn ToValue)] = &[(0, &"Koczkodan"), (0, &"Kachir")];
for i in values_to_add {
list_store.set(&list_store.append(), &[*i]);
}
assert_eq!(check_if_value_is_in_list_store(&list_store, 0, "Koczkodan"), true);
assert_eq!(check_if_value_is_in_list_store(&list_store, 0, "Kachir"), true);
assert_eq!(check_if_value_is_in_list_store(&list_store, 0, "Koczkodan2"), false);
let columns_types: &[glib::types::Type] = &[glib::types::Type::STRING, glib::types::Type::STRING];
let list_store = gtk4::ListStore::new(columns_types);
let values_to_add: &[&[(u32, &dyn ToValue)]] = &[&[(0, &"Koczkodan"), (1, &"Krakus")], &[(0, &"Kachir"), (1, &"Wodnica")]];
for i in values_to_add {
list_store.set(&list_store.append(), i);
}
assert_eq!(check_if_value_is_in_list_store(&list_store, 0, "Koczkodan"), true);
assert_eq!(check_if_value_is_in_list_store(&list_store, 1, "Krakus"), true);
assert_eq!(check_if_value_is_in_list_store(&list_store, 0, "Kachir"), true);
assert_eq!(check_if_value_is_in_list_store(&list_store, 1, "Wodnica"), true);
assert_eq!(check_if_value_is_in_list_store(&list_store, 0, "Krakus"), false);
assert_eq!(check_if_value_is_in_list_store(&list_store, 1, "Kachir"), false);
}
#[test]
fn test_file_name_shortener() {
let name_to_check = "/home/rafal/czkawek/romek/atomek.txt";
assert_eq!(get_max_file_name(name_to_check, 20), "/home/rafa ... atomek.txt");
assert_eq!(get_max_file_name(name_to_check, 21), "/home/rafa ... /atomek.txt");
let name_to_check = "/home/rafal/czkawek/romek/czekistan/atomek.txt";
assert_eq!(get_max_file_name(name_to_check, 21), "/home/rafa ... /atomek.txt");
assert_eq!(get_max_file_name(name_to_check, 80), name_to_check);
let name_to_check = "/home/rafal/‍🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈.txt";
assert_eq!(get_max_file_name(name_to_check, 21), "/home/rafa ... 🌈🌈🌈🌈🌈🌈🌈.txt");
assert_eq!(get_max_file_name(name_to_check, 20), "/home/rafa ... 🌈🌈🌈🌈🌈🌈.txt");
assert_eq!(get_max_file_name(name_to_check, 19), "/home/rafa ... 🌈🌈🌈🌈🌈.txt");
let name_to_check = "/home/rafal/‍🏳️‍🌈️🏳️‍🌈️🏳️‍🌈️🏳️‍🌈️🏳️‍🌈️🏳️‍🌈️🏳️‍🌈️🏳️‍🌈️🏳️‍🌈️.txt";
assert_eq!(get_max_file_name(name_to_check, 21), "/home/rafa ... 🌈\u{fe0f}🏳\u{fe0f}\u{200d}🌈\u{fe0f}.txt");
assert_eq!(get_max_file_name(name_to_check, 20), "/home/rafa ... \u{fe0f}🏳\u{fe0f}\u{200d}🌈\u{fe0f}.txt");
assert_eq!(get_max_file_name(name_to_check, 19), "/home/rafa ... 🏳\u{fe0f}\u{200d}🌈\u{fe0f}.txt");
assert_eq!(get_max_file_name(name_to_check, 18), "/home/rafa ... \u{fe0f}\u{200d}🌈\u{fe0f}.txt");
assert_eq!(get_max_file_name(name_to_check, 17), "/home/rafa ... \u{200d}🌈\u{fe0f}.txt");
assert_eq!(get_max_file_name(name_to_check, 16), "/home/rafa ... 🌈\u{fe0f}.txt");
}
#[test]
fn test_pixbuf_from_dynamic_image() {