1
0
Fork 0
mirror of synced 2024-06-15 08:54:47 +12:00
This commit is contained in:
Rafał Mikrut 2023-01-27 19:09:21 +01:00
parent 1eeb2cb6c7
commit 169f0d5a8b
31 changed files with 216 additions and 236 deletions

View file

@ -307,7 +307,7 @@ impl BadExtensions {
self.files_to_check = files_to_check.clone();
}
self.text_messages.warnings.extend(warnings);
Common::print_time(start_time, SystemTime::now(), "check_files".to_string());
Common::print_time(start_time, SystemTime::now(), "check_files");
true
}
DirTraversalResult::SuccessFolders { .. } => {
@ -476,7 +476,7 @@ impl BadExtensions {
self.information.number_of_files_with_bad_extension = self.bad_extensions_files.len();
Common::print_time(system_time, SystemTime::now(), "bad extension finding".to_string());
Common::print_time(system_time, SystemTime::now(), "bad extension finding");
// Clean unused data
self.files_to_check = Default::default();
@ -551,7 +551,7 @@ impl SaveResults for BadExtensions {
} else {
write!(writer, "Not found any files with invalid extension.").unwrap();
}
Common::print_time(start_time, SystemTime::now(), "save_results_to_file".to_string());
Common::print_time(start_time, SystemTime::now(), "save_results_to_file");
true
}
}
@ -566,6 +566,6 @@ impl PrintResults for BadExtensions {
println!("{} ----- {}", file_entry.path.display(), file_entry.proper_extensions);
}
Common::print_time(start_time, SystemTime::now(), "print_entries".to_string());
Common::print_time(start_time, SystemTime::now(), "print_entries");
}
}

View file

@ -361,7 +361,7 @@ impl BigFile {
}
}
Common::print_time(start_time, SystemTime::now(), "look_for_big_files".to_string());
Common::print_time(start_time, SystemTime::now(), "look_for_big_files");
true
}
@ -404,7 +404,7 @@ impl BigFile {
}
}
Common::print_time(start_time, SystemTime::now(), "delete_files".to_string());
Common::print_time(start_time, SystemTime::now(), "delete_files");
}
}
@ -482,7 +482,7 @@ impl SaveResults for BigFile {
} else {
write!(writer, "Not found any files.").unwrap();
}
Common::print_time(start_time, SystemTime::now(), "save_results_to_file".to_string());
Common::print_time(start_time, SystemTime::now(), "save_results_to_file");
true
}
}
@ -498,6 +498,6 @@ impl PrintResults for BigFile {
for (size, file_entry) in &self.big_files {
println!("{} ({}) - {}", format_size(*size, BINARY), size, file_entry.path.display());
}
Common::print_time(start_time, SystemTime::now(), "print_entries".to_string());
Common::print_time(start_time, SystemTime::now(), "print_entries");
}
}

View file

@ -387,7 +387,7 @@ impl BrokenFiles {
progress_thread_run.store(false, Ordering::Relaxed);
progress_thread_handle.join().unwrap();
Common::print_time(start_time, SystemTime::now(), "check_files".to_string());
Common::print_time(start_time, SystemTime::now(), "check_files");
true
}
fn look_for_broken_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
@ -595,7 +595,7 @@ impl BrokenFiles {
self.information.number_of_broken_files = self.broken_files.len();
Common::print_time(system_time, SystemTime::now(), "sort_images - reading data from files in parallel".to_string());
Common::print_time(system_time, SystemTime::now(), "sort_images - reading data from files in parallel");
// Clean unused data
self.files_to_check = Default::default();
@ -619,7 +619,7 @@ impl BrokenFiles {
}
}
Common::print_time(start_time, SystemTime::now(), "delete_files".to_string());
Common::print_time(start_time, SystemTime::now(), "delete_files");
}
}
@ -692,7 +692,7 @@ impl SaveResults for BrokenFiles {
} else {
write!(writer, "Not found any broken files.").unwrap();
}
Common::print_time(start_time, SystemTime::now(), "save_results_to_file".to_string());
Common::print_time(start_time, SystemTime::now(), "save_results_to_file");
true
}
}
@ -707,7 +707,7 @@ impl PrintResults for BrokenFiles {
println!("{} - {}", file_entry.path.display(), file_entry.error_string);
}
Common::print_time(start_time, SystemTime::now(), "print_entries".to_string());
Common::print_time(start_time, SystemTime::now(), "print_entries");
}
}

View file

@ -199,7 +199,7 @@ pub fn create_crash_message(library_name: &str, file_path: &str, home_library_ur
impl Common {
/// Printing time which took between start and stop point and prints also function name
#[allow(unused_variables)]
pub fn print_time(start_time: SystemTime, end_time: SystemTime, function_name: String) {
pub fn print_time(start_time: SystemTime, end_time: SystemTime, function_name: &str) {
#[cfg(debug_assertions)]
println!(
"Execution of function \"{}\" took {:?}",
@ -230,10 +230,10 @@ impl Common {
let mut warning: String = String::new();
if path.is_dir() {
if let Err(e) = fs::remove_dir_all(entry) {
warning = format!("Failed to remove folder {entry}, reason {e}")
warning = format!("Failed to remove folder {entry}, reason {e}");
}
} else if let Err(e) = fs::remove_file(entry) {
warning = format!("Failed to remove file {entry}, reason {e}")
warning = format!("Failed to remove file {entry}, reason {e}");
}
warning
}

View file

@ -90,7 +90,7 @@ impl Directories {
self.included_directories = checked_directories;
Common::print_time(start_time, SystemTime::now(), "set_included_directory".to_string());
Common::print_time(start_time, SystemTime::now(), "set_included_directory");
true
}
@ -149,7 +149,7 @@ impl Directories {
}
self.excluded_directories = checked_directories;
Common::print_time(start_time, SystemTime::now(), "set_excluded_directory".to_string());
Common::print_time(start_time, SystemTime::now(), "set_excluded_directory");
}
#[cfg(target_family = "unix")]
@ -295,7 +295,7 @@ impl Directories {
// Not needed, but better is to have sorted everything
self.excluded_directories.sort_unstable();
self.included_directories.sort_unstable();
Common::print_time(start_time, SystemTime::now(), "optimize_directories".to_string());
Common::print_time(start_time, SystemTime::now(), "optimize_directories");
// Get device IDs for included directories
#[cfg(target_family = "unix")]

View file

@ -57,7 +57,7 @@ impl Extensions {
.messages
.push("No valid extensions were provided, so allowing all extensions by default.".to_string());
}
Common::print_time(start_time, SystemTime::now(), "set_allowed_extensions".to_string());
Common::print_time(start_time, SystemTime::now(), "set_allowed_extensions");
}
#[must_use]

View file

@ -55,7 +55,7 @@ impl ExcludedItems {
checked_expressions.push(expression);
}
self.items = checked_expressions;
Common::print_time(start_time, SystemTime::now(), "set_excluded_items".to_string());
Common::print_time(start_time, SystemTime::now(), "set_excluded_items");
}
/// Checks whether a specified path is excluded from searching

View file

@ -401,7 +401,7 @@ impl DuplicateFinder {
}
}
Common::print_time(start_time, SystemTime::now(), "check_files_name".to_string());
Common::print_time(start_time, SystemTime::now(), "check_files_name");
true
}
DirTraversalResult::SuccessFolders { .. } => {
@ -503,7 +503,7 @@ impl DuplicateFinder {
}
}
Common::print_time(start_time, SystemTime::now(), "check_files_size".to_string());
Common::print_time(start_time, SystemTime::now(), "check_files_size");
true
}
DirTraversalResult::SuccessFolders { .. } => {
@ -677,7 +677,7 @@ impl DuplicateFinder {
///////////////////////////////////////////////////////////////////////////// PREHASHING END
Common::print_time(start_time, SystemTime::now(), "check_files_hash - prehash".to_string());
Common::print_time(start_time, SystemTime::now(), "check_files_hash - prehash");
let start_time: SystemTime = SystemTime::now();
/////////////////////////
@ -865,9 +865,8 @@ impl DuplicateFinder {
if files_from_referenced_folders.is_empty() || normal_files.is_empty() {
continue;
} else {
all_results_with_same_size.push((files_from_referenced_folders.pop().unwrap(), normal_files));
}
all_results_with_same_size.push((files_from_referenced_folders.pop().unwrap(), normal_files));
}
if all_results_with_same_size.is_empty() {
None
@ -899,7 +898,7 @@ impl DuplicateFinder {
}
}
Common::print_time(start_time, SystemTime::now(), "check_files_hash - full hash".to_string());
Common::print_time(start_time, SystemTime::now(), "check_files_hash - full hash");
// Clean unused data
self.files_with_identical_size = Default::default();
@ -939,7 +938,7 @@ impl DuplicateFinder {
}
}
Common::print_time(start_time, SystemTime::now(), "delete_files".to_string());
Common::print_time(start_time, SystemTime::now(), "delete_files");
}
}
@ -1110,7 +1109,7 @@ impl SaveResults for DuplicateFinder {
panic!();
}
}
Common::print_time(start_time, SystemTime::now(), "save_results_to_file".to_string());
Common::print_time(start_time, SystemTime::now(), "save_results_to_file");
true
}
}
@ -1139,7 +1138,7 @@ impl PrintResults for DuplicateFinder {
}
}
CheckingMethod::Hash => {
for (_size, vector) in &self.files_with_identical_hashes {
for vector in self.files_with_identical_hashes.values() {
for j in vector {
number_of_files += j.len() as u64;
number_of_groups += 1;
@ -1185,7 +1184,7 @@ impl PrintResults for DuplicateFinder {
panic!("Checking Method shouldn't be ever set to None");
}
}
Common::print_time(start_time, SystemTime::now(), "print_entries".to_string());
Common::print_time(start_time, SystemTime::now(), "print_entries");
}
}
@ -1210,7 +1209,8 @@ fn delete_files(vector: &[FileEntry], delete_method: &DeleteMethod, text_message
for (index, file) in vector.iter().enumerate() {
if q_index == index {
continue;
} else if removed_files + failed_to_remove_files >= n {
}
if removed_files + failed_to_remove_files >= n {
break;
}
@ -1299,9 +1299,8 @@ pub fn save_hashes_to_file(hashmap: &BTreeMap<String, FileEntry>, text_messages:
.warnings
.push(format!("Failed to save some data to cache file {}, reason {}", cache_file.display(), e));
return;
} else {
how_much += 1;
}
how_much += 1;
}
}

View file

@ -150,7 +150,7 @@ impl EmptyFiles {
}
self.information.number_of_empty_files = self.empty_files.len();
self.text_messages.warnings.extend(warnings);
Common::print_time(start_time, SystemTime::now(), "check_files_name".to_string());
Common::print_time(start_time, SystemTime::now(), "check_files_name");
true
}
DirTraversalResult::SuccessFolders { .. } => {
@ -177,7 +177,7 @@ impl EmptyFiles {
}
}
Common::print_time(start_time, SystemTime::now(), "delete_files".to_string());
Common::print_time(start_time, SystemTime::now(), "delete_files");
}
}
@ -251,7 +251,7 @@ impl SaveResults for EmptyFiles {
} else {
write!(writer, "Not found any empty files.").unwrap();
}
Common::print_time(start_time, SystemTime::now(), "save_results_to_file".to_string());
Common::print_time(start_time, SystemTime::now(), "save_results_to_file");
true
}
}
@ -266,6 +266,6 @@ impl PrintResults for EmptyFiles {
println!("{}", file_entry.path.display());
}
Common::print_time(start_time, SystemTime::now(), "print_entries".to_string());
Common::print_time(start_time, SystemTime::now(), "print_entries");
}
}

View file

@ -159,7 +159,7 @@ impl EmptyFolder {
self.text_messages.warnings.extend(warnings);
Common::print_time(start_time, SystemTime::now(), "check_for_empty_folder".to_string());
Common::print_time(start_time, SystemTime::now(), "check_for_empty_folder");
true
}
DirTraversalResult::Stopped => false,
@ -177,7 +177,7 @@ impl EmptyFolder {
};
}
Common::print_time(start_time, SystemTime::now(), "delete_files".to_string());
Common::print_time(start_time, SystemTime::now(), "delete_files");
}
/// Set included dir which needs to be relative, exists etc.
@ -247,7 +247,7 @@ impl SaveResults for EmptyFolder {
} else {
write!(writer, "Not found any empty folders.").unwrap();
}
Common::print_time(start_time, SystemTime::now(), "save_results_to_file".to_string());
Common::print_time(start_time, SystemTime::now(), "save_results_to_file");
true
}
}

View file

@ -148,7 +148,7 @@ impl InvalidSymlinks {
}
self.information.number_of_invalid_symlinks = self.invalid_symlinks.len();
self.text_messages.warnings.extend(warnings);
Common::print_time(start_time, SystemTime::now(), "check_files_name".to_string());
Common::print_time(start_time, SystemTime::now(), "check_files_name");
true
}
DirTraversalResult::SuccessFolders { .. } => unreachable!(),
@ -173,7 +173,7 @@ impl InvalidSymlinks {
}
}
Common::print_time(start_time, SystemTime::now(), "delete_files".to_string());
Common::print_time(start_time, SystemTime::now(), "delete_files");
}
}
@ -257,7 +257,7 @@ impl SaveResults for InvalidSymlinks {
} else {
write!(writer, "Not found any invalid symlinks.").unwrap();
}
Common::print_time(start_time, SystemTime::now(), "save_results_to_file".to_string());
Common::print_time(start_time, SystemTime::now(), "save_results_to_file");
true
}
}
@ -280,6 +280,6 @@ impl PrintResults for InvalidSymlinks {
);
}
Common::print_time(start_time, SystemTime::now(), "print_entries".to_string());
Common::print_time(start_time, SystemTime::now(), "print_entries");
}
}

View file

@ -45,10 +45,10 @@ pub fn generate_translation_hashmap(vec: Vec<(&'static str, String)>) -> HashMap
hashmap
}
pub fn fnc_get_similarity_very_high() -> String {
#[must_use] pub fn fnc_get_similarity_very_high() -> String {
flc!("core_similarity_very_high")
}
pub fn fnc_get_similarity_minimal() -> String {
#[must_use] pub fn fnc_get_similarity_minimal() -> String {
flc!("core_similarity_minimal")
}

View file

@ -297,7 +297,7 @@ impl SameMusic {
}
}
self.text_messages.warnings.extend(warnings);
Common::print_time(start_time, SystemTime::now(), "check_files".to_string());
Common::print_time(start_time, SystemTime::now(), "check_files");
true
}
DirTraversalResult::SuccessFolders { .. } => {
@ -396,18 +396,17 @@ impl SameMusic {
}
});
let tagged_file = match result {
Ok(t) => match t {
let tagged_file = if let Ok(t) = result {
match t {
Some(r) => r,
None => {
return Some(Some(music_entry));
}
},
Err(_) => {
let message = create_crash_message("Lofty", &path, "https://github.com/image-rs/image/issues");
println!("{message}");
return Some(None);
}
} else {
let message = create_crash_message("Lofty", &path, "https://github.com/image-rs/image/issues");
println!("{message}");
return Some(None);
};
let properties = tagged_file.properties();
@ -507,7 +506,7 @@ impl SameMusic {
return false;
}
Common::print_time(start_time, SystemTime::now(), "check_records_multithreaded".to_string());
Common::print_time(start_time, SystemTime::now(), "check_records_multithreaded");
true
}
@ -751,7 +750,7 @@ impl SameMusic {
}
}
Common::print_time(start_time, SystemTime::now(), "check_for_duplicates".to_string());
Common::print_time(start_time, SystemTime::now(), "check_for_duplicates");
// Clear unused data
self.music_entries.clear();
@ -783,7 +782,7 @@ impl SameMusic {
// }
// }
Common::print_time(start_time, SystemTime::now(), "delete_files".to_string());
Common::print_time(start_time, SystemTime::now(), "delete_files");
}
}
@ -929,7 +928,7 @@ impl SaveResults for SameMusic {
} else {
write!(writer, "Not found any empty files.").unwrap();
}
Common::print_time(start_time, SystemTime::now(), "save_results_to_file".to_string());
Common::print_time(start_time, SystemTime::now(), "save_results_to_file");
true
}
}
@ -956,7 +955,7 @@ impl PrintResults for SameMusic {
println!();
}
Common::print_time(start_time, SystemTime::now(), "print_entries".to_string());
Common::print_time(start_time, SystemTime::now(), "print_entries");
}
}

View file

@ -479,7 +479,7 @@ impl SimilarImages {
// End thread which send info to gui
progress_thread_run.store(false, Ordering::Relaxed);
progress_thread_handle.join().unwrap();
Common::print_time(start_time, SystemTime::now(), "check_for_similar_images".to_string());
Common::print_time(start_time, SystemTime::now(), "check_for_similar_images");
true
}
@ -522,11 +522,7 @@ impl SimilarImages {
mem::swap(&mut self.images_to_check, &mut non_cached_files_to_check);
}
Common::print_time(
hash_map_modification,
SystemTime::now(),
"sort_images - reading data from cache and preparing them".to_string(),
);
Common::print_time(hash_map_modification, SystemTime::now(), "sort_images - reading data from cache and preparing them");
let hash_map_modification = SystemTime::now();
//// PROGRESS THREAD START
@ -645,7 +641,7 @@ impl SimilarImages {
progress_thread_run.store(false, Ordering::Relaxed);
progress_thread_handle.join().unwrap();
Common::print_time(hash_map_modification, SystemTime::now(), "sort_images - reading data from files in parallel".to_string());
Common::print_time(hash_map_modification, SystemTime::now(), "sort_images - reading data from files in parallel");
let hash_map_modification = SystemTime::now();
// Just connect loaded results with already calculated hashes
@ -682,7 +678,7 @@ impl SimilarImages {
return false;
}
Common::print_time(hash_map_modification, SystemTime::now(), "sort_images - saving data to files".to_string());
Common::print_time(hash_map_modification, SystemTime::now(), "sort_images - saving data to files");
true
}
@ -849,7 +845,7 @@ impl SimilarImages {
#[cfg(debug_assertions)]
if !self.use_reference_folders {
debug_check_for_duplicated_things(hashes_parents.clone(), hashes_similarity.clone(), all_hashed_images.clone(), "BEFORE");
debug_check_for_duplicated_things(&hashes_parents, &hashes_similarity, &all_hashed_images, "BEFORE");
}
Some((hashes_parents, hashes_similarity))
@ -897,7 +893,7 @@ impl SimilarImages {
#[cfg(debug_assertions)]
if !self.use_reference_folders {
debug_check_for_duplicated_things(hashes_parents.clone(), hashes_similarity.clone(), all_hashed_images.clone(), "LATTER");
debug_check_for_duplicated_things(&hashes_parents, &hashes_similarity, &all_hashed_images, "LATTER");
}
// Just simple check if all original hashes with multiple entries are available in end results
@ -967,7 +963,7 @@ impl SimilarImages {
{
let mut result_hashset: HashSet<String> = Default::default();
let mut found = false;
for (_hash, vec_file_entry) in &collected_similar_images {
for vec_file_entry in collected_similar_images.values() {
if vec_file_entry.is_empty() {
println!("Empty Element {vec_file_entry:?}");
found = true;
@ -1036,7 +1032,7 @@ impl SimilarImages {
.collect::<Vec<(FileEntry, Vec<FileEntry>)>>();
}
Common::print_time(hash_map_modification, SystemTime::now(), "sort_images - selecting data from HashMap".to_string());
Common::print_time(hash_map_modification, SystemTime::now(), "sort_images - selecting data from HashMap");
if self.use_reference_folders {
for (_fe, vector) in &self.similar_referenced_vectors {
@ -1204,7 +1200,7 @@ impl SaveResults for SimilarImages {
write!(writer, "Not found any similar images.").unwrap();
}
Common::print_time(start_time, SystemTime::now(), "save_results_to_file".to_string());
Common::print_time(start_time, SystemTime::now(), "save_results_to_file");
true
}
}
@ -1322,6 +1318,7 @@ fn get_cache_file(hash_size: &u8, hash_alg: &HashAlg, image_filter: &FilterType)
)
}
#[must_use]
pub fn get_string_from_similarity(similarity: &u32, hash_size: u8) -> String {
let index_preset = match hash_size {
8 => 0,
@ -1459,15 +1456,15 @@ pub fn test_image_conversion_speed() {
// E.g. /a.jpg is used also as master and similar image which is forbidden, because may
// cause accidentally delete more pictures that user wanted
fn debug_check_for_duplicated_things(
hashes_parents: HashMap<&Vec<u8>, u32>,
hashes_similarity: HashMap<&Vec<u8>, (&Vec<u8>, u32)>,
all_hashed_images: HashMap<Vec<u8>, Vec<FileEntry>>,
hashes_parents: &HashMap<&Vec<u8>, u32>,
hashes_similarity: &HashMap<&Vec<u8>, (&Vec<u8>, u32)>,
all_hashed_images: &HashMap<Vec<u8>, Vec<FileEntry>>,
numm: &str,
) {
let mut found_broken_thing = false;
let mut hashmap_hashes: HashSet<_> = Default::default();
let mut hashmap_names: HashSet<_> = Default::default();
for (hash, number_of_children) in &hashes_parents {
for (hash, number_of_children) in hashes_parents {
if *number_of_children > 0 {
if hashmap_hashes.contains(*hash) {
println!("------1--HASH--{} {:?}", numm, all_hashed_images.get(*hash).unwrap());

View file

@ -442,7 +442,7 @@ impl SimilarVideos {
// End thread which send info to gui
progress_thread_run.store(false, Ordering::Relaxed);
progress_thread_handle.join().unwrap();
Common::print_time(start_time, SystemTime::now(), "check_for_similar_videos".to_string());
Common::print_time(start_time, SystemTime::now(), "check_for_similar_videos");
true
}
@ -478,11 +478,7 @@ impl SimilarVideos {
mem::swap(&mut self.videos_to_check, &mut non_cached_files_to_check);
}
Common::print_time(
hash_map_modification,
SystemTime::now(),
"sort_videos - reading data from cache and preparing them".to_string(),
);
Common::print_time(hash_map_modification, SystemTime::now(), "sort_videos - reading data from cache and preparing them");
let hash_map_modification = SystemTime::now();
//// PROGRESS THREAD START
@ -545,7 +541,7 @@ impl SimilarVideos {
progress_thread_run.store(false, Ordering::Relaxed);
progress_thread_handle.join().unwrap();
Common::print_time(hash_map_modification, SystemTime::now(), "sort_videos - reading data from files in parallel".to_string());
Common::print_time(hash_map_modification, SystemTime::now(), "sort_videos - reading data from files in parallel");
let hash_map_modification = SystemTime::now();
// Just connect loaded results with already calculated hashes
@ -579,7 +575,7 @@ impl SimilarVideos {
return false;
}
Common::print_time(hash_map_modification, SystemTime::now(), "sort_videos - saving data to files".to_string());
Common::print_time(hash_map_modification, SystemTime::now(), "sort_videos - saving data to files");
let hash_map_modification = SystemTime::now();
let match_group = vid_dup_finder_lib::search(vector_of_hashes, NormalizedTolerance::new(self.tolerance as f64 / 100.0f64));
@ -644,7 +640,7 @@ impl SimilarVideos {
}
}
Common::print_time(hash_map_modification, SystemTime::now(), "sort_videos - selecting data from BtreeMap".to_string());
Common::print_time(hash_map_modification, SystemTime::now(), "sort_videos - selecting data from BtreeMap");
// Clean unused data
self.videos_hashes = Default::default();
@ -732,7 +728,7 @@ impl SaveResults for SimilarVideos {
write!(writer, "Not found any similar videos.").unwrap();
}
Common::print_time(start_time, SystemTime::now(), "save_results_to_file".to_string());
Common::print_time(start_time, SystemTime::now(), "save_results_to_file");
true
}
}

View file

@ -331,7 +331,7 @@ impl Temporary {
progress_thread_handle.join().unwrap();
self.information.number_of_temporary_files = self.temporary_files.len();
Common::print_time(start_time, SystemTime::now(), "check_files_size".to_string());
Common::print_time(start_time, SystemTime::now(), "check_files_size");
true
}
@ -352,7 +352,7 @@ impl Temporary {
}
}
Common::print_time(start_time, SystemTime::now(), "delete_files".to_string());
Common::print_time(start_time, SystemTime::now(), "delete_files");
}
}
@ -425,7 +425,7 @@ impl SaveResults for Temporary {
} else {
write!(writer, "Not found any temporary files.").unwrap();
}
Common::print_time(start_time, SystemTime::now(), "save_results_to_file".to_string());
Common::print_time(start_time, SystemTime::now(), "save_results_to_file");
true
}
}
@ -438,6 +438,6 @@ impl PrintResults for Temporary {
println!("{}", file_entry.path.display());
}
Common::print_time(start_time, SystemTime::now(), "print_entries".to_string());
Common::print_time(start_time, SystemTime::now(), "print_entries");
}
}

View file

@ -11,28 +11,28 @@ pub fn connect_about_buttons(gui_data: &GuiData) {
let button_donation = gui_data.about.button_donation.clone();
button_donation.connect_clicked(move |_| {
if let Err(e) = open::that(SPONSOR_SITE) {
println!("Failed to open sponsor site: {SPONSOR_SITE}, reason {e}")
println!("Failed to open sponsor site: {SPONSOR_SITE}, reason {e}");
};
});
let button_instruction = gui_data.about.button_instruction.clone();
button_instruction.connect_clicked(move |_| {
if let Err(e) = open::that(INSTRUCTION_SITE) {
println!("Failed to open instruction site: {INSTRUCTION_SITE}, reason {e}")
println!("Failed to open instruction site: {INSTRUCTION_SITE}, reason {e}");
};
});
let button_repository = gui_data.about.button_repository.clone();
button_repository.connect_clicked(move |_| {
if let Err(e) = open::that(REPOSITORY_SITE) {
println!("Failed to open repository site: {REPOSITORY_SITE}, reason {e}")
println!("Failed to open repository site: {REPOSITORY_SITE}, reason {e}");
};
});
let button_translation = gui_data.about.button_translation.clone();
button_translation.connect_clicked(move |_| {
if let Err(e) = open::that(TRANSLATION_SITE) {
println!("Failed to open repository site: {TRANSLATION_SITE}, reason {e}")
println!("Failed to open repository site: {TRANSLATION_SITE}, reason {e}");
};
});
}

View file

@ -60,7 +60,7 @@ pub fn connect_button_compare(gui_data: &GuiData) {
}
// Check selected items
let (current_group, tree_path) = get_current_group_and_iter_from_selection(&model, tree_view.selection(), nb_object.column_header.unwrap());
let (current_group, tree_path) = get_current_group_and_iter_from_selection(&model, &tree_view.selection(), nb_object.column_header.unwrap());
*shared_current_of_groups.borrow_mut() = current_group;
*shared_numbers_of_groups.borrow_mut() = group_number;
@ -68,7 +68,7 @@ pub fn connect_button_compare(gui_data: &GuiData) {
populate_groups_at_start(
nb_object,
&model,
shared_current_path.clone(),
&shared_current_path,
tree_path,
&image_compare_left,
&image_compare_right,
@ -142,7 +142,7 @@ pub fn connect_button_compare(gui_data: &GuiData) {
populate_groups_at_start(
nb_object,
&model,
shared_current_path.clone(),
&shared_current_path,
tree_path,
&image_compare_left,
&image_compare_right,
@ -194,7 +194,7 @@ pub fn connect_button_compare(gui_data: &GuiData) {
populate_groups_at_start(
nb_object,
&model,
shared_current_path.clone(),
&shared_current_path,
tree_path,
&image_compare_left,
&image_compare_right,
@ -261,7 +261,7 @@ pub fn connect_button_compare(gui_data: &GuiData) {
fn populate_groups_at_start(
nb_object: &NotebookObject,
model: &TreeModel,
shared_current_path: Rc<RefCell<Option<TreePath>>>,
shared_current_path: &Rc<RefCell<Option<TreePath>>>,
tree_path: TreePath,
image_compare_left: &Image,
image_compare_right: &Image,
@ -318,8 +318,8 @@ fn populate_groups_at_start(
&cache_all_images,
image_compare_left,
image_compare_right,
shared_using_for_preview.clone(),
shared_image_cache.clone(),
&shared_using_for_preview,
&shared_image_cache,
check_button_left_preview_text,
check_button_right_preview_text,
model,
@ -332,7 +332,7 @@ fn populate_groups_at_start(
for i in get_all_direct_children(&scrolled_window_compare_choose_images.child().unwrap().downcast::<gtk4::Viewport>().unwrap()) {
if i.widget_name() == "all_box" {
let gtk_box = i.downcast::<gtk4::Box>().unwrap();
update_bottom_buttons(&gtk_box, shared_using_for_preview, shared_image_cache);
update_bottom_buttons(&gtk_box, &shared_using_for_preview, &shared_image_cache);
found = true;
break;
}
@ -414,14 +414,14 @@ fn generate_cache_for_results(vector_with_path: Vec<(String, String, TreePath)>)
#[allow(clippy::never_loop)]
loop {
let pixbuf_big = match resize_pixbuf_dimension(pixbuf, (BIG_PREVIEW_SIZE, BIG_PREVIEW_SIZE), InterpType::Bilinear) {
let pixbuf_big = match resize_pixbuf_dimension(&pixbuf, (BIG_PREVIEW_SIZE, BIG_PREVIEW_SIZE), InterpType::Bilinear) {
None => {
println!("Failed to resize image {full_path}.");
break;
}
Some(pixbuf) => pixbuf,
};
let pixbuf_small = match resize_pixbuf_dimension(pixbuf_big.clone(), (SMALL_PREVIEW_SIZE, SMALL_PREVIEW_SIZE), InterpType::Bilinear) {
let pixbuf_small = match resize_pixbuf_dimension(&pixbuf_big, (SMALL_PREVIEW_SIZE, SMALL_PREVIEW_SIZE), InterpType::Bilinear) {
None => {
println!("Failed to resize image {full_path}.");
break;
@ -517,8 +517,8 @@ fn populate_similar_scrolled_view(
image_cache: &[(String, String, Image, Image, TreePath)],
image_compare_left: &Image,
image_compare_right: &Image,
shared_using_for_preview: Rc<RefCell<(Option<TreePath>, Option<TreePath>)>>,
shared_image_cache: Rc<RefCell<Vec<(String, String, Image, Image, TreePath)>>>,
shared_using_for_preview: &Rc<RefCell<(Option<TreePath>, Option<TreePath>)>>,
shared_image_cache: &Rc<RefCell<Vec<(String, String, Image, Image, TreePath)>>>,
check_button_left_preview_text: &CheckButton,
check_button_right_preview_text: &CheckButton,
model: &TreeModel,
@ -554,7 +554,7 @@ fn populate_similar_scrolled_view(
button_left.connect_clicked(move |_button_left| {
shared_using_for_preview_clone.borrow_mut().0 = Some(tree_path_clone.clone());
update_bottom_buttons(&all_gtk_box_clone, shared_using_for_preview_clone.clone(), shared_image_cache_clone.clone());
update_bottom_buttons(&all_gtk_box_clone, &shared_using_for_preview_clone, &shared_image_cache_clone);
image_compare_left.set_paintable(big_thumbnail_clone.paintable().as_ref());
let is_active = model_clone.get::<bool>(&model_clone.iter(&tree_path_clone).unwrap(), column_selection);
@ -573,7 +573,7 @@ fn populate_similar_scrolled_view(
button_right.connect_clicked(move |_button_right| {
shared_using_for_preview_clone.borrow_mut().1 = Some(tree_path_clone.clone());
update_bottom_buttons(&all_gtk_box_clone, shared_using_for_preview_clone.clone(), shared_image_cache_clone.clone());
update_bottom_buttons(&all_gtk_box_clone, &shared_using_for_preview_clone, &shared_image_cache_clone);
image_compare_right.set_paintable(big_thumbnail_clone.paintable().as_ref());
let is_active = model_clone.get::<bool>(&model_clone.iter(&tree_path_clone).unwrap(), column_selection);
@ -609,8 +609,8 @@ fn populate_similar_scrolled_view(
/// Disables/Enables L/R buttons at the bottom scrolled view
fn update_bottom_buttons(
all_gtk_box: &gtk4::Box,
shared_using_for_preview: Rc<RefCell<(Option<TreePath>, Option<TreePath>)>>,
image_cache: Rc<RefCell<Vec<(String, String, Image, Image, TreePath)>>>,
shared_using_for_preview: &Rc<RefCell<(Option<TreePath>, Option<TreePath>)>>,
image_cache: &Rc<RefCell<Vec<(String, String, Image, Image, TreePath)>>>,
) {
let left_tree_view = (shared_using_for_preview.borrow()).0.clone().unwrap();
let right_tree_view = (shared_using_for_preview.borrow()).1.clone().unwrap();
@ -629,7 +629,7 @@ fn update_bottom_buttons(
}
}
fn get_current_group_and_iter_from_selection(model: &TreeModel, selection: TreeSelection, column_header: i32) -> (u32, TreePath) {
fn get_current_group_and_iter_from_selection(model: &TreeModel, selection: &TreeSelection, column_header: i32) -> (u32, TreePath) {
let mut current_group = 1;
let mut possible_group = 1;
let mut header_clone: TreeIter;

View file

@ -245,22 +245,22 @@ pub async fn check_if_deleting_all_files_in_group(
if !selected_all_records {
return false;
} else {
let (confirmation_dialog_group_delete, check_button) = create_dialog_group_deletion(window_main);
}
let response_type = confirmation_dialog_group_delete.run_future().await;
if response_type == ResponseType::Ok {
if !check_button.is_active() {
check_button_settings_confirm_group_deletion.set_active(false);
}
} else {
confirmation_dialog_group_delete.hide();
confirmation_dialog_group_delete.close();
return true;
let (confirmation_dialog_group_delete, check_button) = create_dialog_group_deletion(window_main);
let response_type = confirmation_dialog_group_delete.run_future().await;
if response_type == ResponseType::Ok {
if !check_button.is_active() {
check_button_settings_confirm_group_deletion.set_active(false);
}
} else {
confirmation_dialog_group_delete.hide();
confirmation_dialog_group_delete.close();
return true;
}
confirmation_dialog_group_delete.hide();
confirmation_dialog_group_delete.close();
false
}

View file

@ -19,6 +19,12 @@ enum TypeOfTool {
Symlinking,
}
#[derive(Debug)]
struct SymHardlinkData {
original_data: String,
files_to_symhardlink: Vec<String>,
}
pub fn connect_button_hardlink_symlink(gui_data: &GuiData) {
// Hardlinking
{
@ -62,7 +68,7 @@ async fn sym_hard_link_things(gui_data: GuiData, hardlinking: TypeOfTool) {
let check_button_settings_confirm_link = gui_data.settings.check_button_settings_confirm_link.clone();
if !check_if_anything_is_selected_async(tree_view, column_header, nb_object.column_selection).await {
if !check_if_anything_is_selected_async(tree_view, column_header, nb_object.column_selection) {
return;
}
@ -110,11 +116,6 @@ fn hardlink_symlink(
let model = get_list_store(tree_view);
#[derive(Debug)]
struct SymHardlinkData {
original_data: String,
files_to_symhardlink: Vec<String>,
}
let mut vec_tree_path_to_remove: Vec<TreePath> = Vec::new(); // List of hardlinked files without its root
let mut vec_symhardlink_data: Vec<SymHardlinkData> = Vec::new();
@ -328,7 +329,7 @@ pub async fn check_if_changing_one_item_in_group_and_continue(tree_view: &gtk4::
true
}
pub async fn check_if_anything_is_selected_async(tree_view: &gtk4::TreeView, column_header: i32, column_selection: i32) -> bool {
pub fn check_if_anything_is_selected_async(tree_view: &gtk4::TreeView, column_header: i32, column_selection: i32) -> bool {
let model = get_list_store(tree_view);
if let Some(iter) = model.iter_first() {

View file

@ -124,9 +124,9 @@ pub fn connect_button_search(
return;
}
let included_directories = get_path_buf_from_vector_of_strings(get_string_from_list_store(&tree_view_included_directories, ColumnsIncludedDirectory::Path as i32, None));
let excluded_directories = get_path_buf_from_vector_of_strings(get_string_from_list_store(&tree_view_excluded_directories, ColumnsExcludedDirectory::Path as i32, None));
let reference_directories = get_path_buf_from_vector_of_strings(get_string_from_list_store(
let included_directories = get_path_buf_from_vector_of_strings(&get_string_from_list_store(&tree_view_included_directories, ColumnsIncludedDirectory::Path as i32, None));
let excluded_directories = get_path_buf_from_vector_of_strings(&get_string_from_list_store(&tree_view_excluded_directories, ColumnsExcludedDirectory::Path as i32, None));
let reference_directories = get_path_buf_from_vector_of_strings(&get_string_from_list_store(
&tree_view_included_directories,
ColumnsIncludedDirectory::Path as i32,
Some(ColumnsIncludedDirectory::ReferenceButton as i32),

View file

@ -23,7 +23,7 @@ fn change_language(gui_data: &GuiData) {
("czkawka_gui", localizer_gui::localizer_gui()),
];
let lang_short = get_language_from_combo_box_text(gui_data.settings.combo_box_settings_language.active_text().unwrap().to_string()).short_text;
let lang_short = get_language_from_combo_box_text(&gui_data.settings.combo_box_settings_language.active_text().unwrap()).short_text;
let lang_identifier = vec![LanguageIdentifier::from_bytes(lang_short.as_bytes()).unwrap()];
for (lib, localizer) in localizers {

View file

@ -172,10 +172,7 @@ fn popover_one_oldest_newest(
let mut tree_iter_array: Vec<TreeIter> = Vec::new();
let mut used_index: Option<usize> = None;
let mut current_index: usize = 0;
let mut modification_time_min_max: u64 = match check_oldest {
true => u64::MAX,
false => 0,
};
let mut modification_time_min_max: u64 = if check_oldest { u64::MAX } else { 0 };
let mut file_length: usize = 0;
@ -242,9 +239,10 @@ fn popover_custom_select_unselect(
) {
popover.popdown();
let window_title = match select_things {
false => flg!("popover_custom_mode_unselect"),
true => flg!("popover_custom_mode_select"),
let window_title = if select_things {
flg!("popover_custom_mode_select")
} else {
flg!("popover_custom_mode_unselect")
};
// Dialog for select/unselect items
@ -382,26 +380,25 @@ fn popover_custom_select_unselect(
let check_all_selected = check_button_select_not_all_results.is_active();
if check_button_path.is_active() || check_button_name.is_active() || check_button_rust_regex.is_active() {
let compiled_regex = match check_regex {
true => match Regex::new(&regex_wildcard) {
Ok(t) => t,
Err(_) => {
eprintln!("What? Regex should compile properly.");
confirmation_dialog_select_unselect.close();
return;
}
},
false => Regex::new("").unwrap(),
let compiled_regex = if check_regex {
if let Ok(t) = Regex::new(&regex_wildcard) {
t
} else {
eprintln!("What? Regex should compile properly.");
confirmation_dialog_select_unselect.close();
return;
}
} else {
Regex::new("").unwrap()
};
let model = get_list_store(&tree_view);
let iter = match model.iter_first() {
Some(t) => t,
None => {
confirmation_dialog_select_unselect.close();
return;
}
let iter = if let Some(t) = model.iter_first() {
t
} else {
confirmation_dialog_select_unselect.close();
return;
};
let mut number_of_all_things = 0;
@ -524,14 +521,8 @@ fn popover_all_except_biggest_smallest(
let mut tree_iter_array: Vec<TreeIter> = Vec::new();
let mut used_index: Option<usize> = None;
let mut current_index: usize = 0;
let mut size_as_bytes_min_max: u64 = match except_biggest {
true => 0,
false => u64::MAX,
};
let mut number_of_pixels_min_max: u64 = match except_biggest {
true => 0,
false => u64::MAX,
};
let mut size_as_bytes_min_max: u64 = if except_biggest { 0 } else { u64::MAX };
let mut number_of_pixels_min_max: u64 = if except_biggest { 0 } else { u64::MAX };
loop {
if model.get::<bool>(&iter, column_header) {
@ -547,7 +538,7 @@ fn popover_all_except_biggest_smallest(
if let Some(column_dimensions) = column_dimensions {
let dimensions_string = model.get::<String>(&iter, column_dimensions);
let dimensions = change_dimension_to_krotka(dimensions_string);
let dimensions = change_dimension_to_krotka(&dimensions_string);
let number_of_pixels = dimensions.0 * dimensions.1;
if except_biggest {

View file

@ -111,7 +111,7 @@ pub fn connect_settings(gui_data: &GuiData) {
let entry_settings_cache_file_minimal_size = gui_data.settings.entry_settings_cache_file_minimal_size.clone();
button_settings_duplicates_clear_cache.connect_clicked(move |_| {
let dialog = create_clear_cache_dialog(flg!("cache_clear_duplicates_title"), &settings_window);
let dialog = create_clear_cache_dialog(&flg!("cache_clear_duplicates_title"), &settings_window);
dialog.show();
let text_view_errors = text_view_errors.clone();
@ -135,7 +135,7 @@ pub fn connect_settings(gui_data: &GuiData) {
type_of_hash,
use_prehash,
entry_settings_cache_file_minimal_size.text().as_str().parse::<u64>().unwrap_or(2 * 1024 * 1024),
)
);
}
}
@ -153,7 +153,7 @@ pub fn connect_settings(gui_data: &GuiData) {
let text_view_errors = gui_data.text_view_errors.clone();
button_settings_similar_images_clear_cache.connect_clicked(move |_| {
let dialog = create_clear_cache_dialog(flg!("cache_clear_similar_images_title"), &settings_window);
let dialog = create_clear_cache_dialog(&flg!("cache_clear_similar_images_title"), &settings_window);
dialog.show();
let text_view_errors = text_view_errors.clone();
@ -190,7 +190,7 @@ pub fn connect_settings(gui_data: &GuiData) {
let text_view_errors = gui_data.text_view_errors.clone();
button_settings_similar_videos_clear_cache.connect_clicked(move |_| {
let dialog = create_clear_cache_dialog(flg!("cache_clear_similar_videos_title"), &settings_window);
let dialog = create_clear_cache_dialog(&flg!("cache_clear_similar_videos_title"), &settings_window);
dialog.show();
let text_view_errors = text_view_errors.clone();
@ -212,8 +212,8 @@ pub fn connect_settings(gui_data: &GuiData) {
}
}
fn create_clear_cache_dialog(title_str: String, window_settings: &Window) -> gtk4::Dialog {
let dialog = gtk4::Dialog::builder().title(&title_str).modal(true).transient_for(window_settings).build();
fn create_clear_cache_dialog(title_str: &str, window_settings: &Window) -> gtk4::Dialog {
let dialog = gtk4::Dialog::builder().title(title_str).modal(true).transient_for(window_settings).build();
dialog.add_button(&flg!("general_ok_button"), ResponseType::Ok);
dialog.add_button(&flg!("general_close_button"), ResponseType::Cancel);

View file

@ -253,7 +253,7 @@ pub fn get_string_from_list_store(tree_view: &TreeView, column_full_path: i32, c
}
}
pub fn get_path_buf_from_vector_of_strings(vec_string: Vec<String>) -> Vec<PathBuf> {
pub fn get_path_buf_from_vector_of_strings(vec_string: &[String]) -> Vec<PathBuf> {
vec_string.iter().map(PathBuf::from).collect()
}
@ -338,7 +338,7 @@ pub fn get_dialog_box_child(dialog: &gtk4::Dialog) -> gtk4::Box {
dialog.child().unwrap().downcast::<gtk4::Box>().unwrap()
}
pub fn change_dimension_to_krotka(dimensions: String) -> (u64, u64) {
pub fn change_dimension_to_krotka(dimensions: &str) -> (u64, u64) {
#[allow(clippy::single_char_pattern)]
let vec = dimensions.split::<&str>("x").collect::<Vec<_>>();
assert_eq!(vec.len(), 2); // 400x400 - should only have two elements, if have more, then something is not good
@ -584,7 +584,7 @@ pub fn count_number_of_groups(tree_view: &TreeView, column_header: i32) -> u32 {
number_of_selected_groups
}
pub fn resize_pixbuf_dimension(pixbuf: Pixbuf, requested_size: (i32, i32), interp_type: InterpType) -> Option<Pixbuf> {
pub fn resize_pixbuf_dimension(pixbuf: &Pixbuf, requested_size: (i32, i32), interp_type: InterpType) -> Option<Pixbuf> {
let current_ratio = pixbuf.width() as f32 / pixbuf.height() as f32;
let mut new_size;
match current_ratio.partial_cmp(&(requested_size.0 as f32 / requested_size.1 as f32)).unwrap() {
@ -634,9 +634,8 @@ pub fn get_custom_label_from_widget<P: IsA<Widget>>(item: &P) -> gtk4::Label {
while let Some(widget) = widgets_to_check.pop() {
if let Ok(label) = widget.clone().downcast::<gtk4::Label>() {
return label;
} else {
widgets_to_check.extend(get_all_direct_children(&widget));
}
widgets_to_check.extend(get_all_direct_children(&widget));
}
panic!("Button doesn't have proper custom label child");
}
@ -647,9 +646,8 @@ pub fn get_custom_image_from_widget<P: IsA<Widget>>(item: &P) -> gtk4::Image {
while let Some(widget) = widgets_to_check.pop() {
if let Ok(image) = widget.clone().downcast::<gtk4::Image>() {
return image;
} else {
widgets_to_check.extend(get_all_direct_children(&widget));
}
widgets_to_check.extend(get_all_direct_children(&widget));
}
panic!("Button doesn't have proper custom label child");
}

View file

@ -440,7 +440,7 @@ fn connect_event_mouse(gui_data: &GuiData) {
&text_view_errors,
&check_button_settings_show_preview,
&image_preview,
preview_path,
&preview_path,
nb_object.column_path,
nb_object.column_name,
);
@ -465,7 +465,7 @@ fn connect_event_mouse(gui_data: &GuiData) {
&text_view_errors,
&check_button_settings_show_preview,
&image_preview,
preview_path,
&preview_path,
nb_object.column_path,
nb_object.column_name,
);
@ -518,7 +518,7 @@ fn connect_event_buttons(gui_data: &GuiData) {
&text_view_errors,
&check_button_settings_show_preview,
&image_preview,
preview_path,
&preview_path,
nb_object.column_path,
nb_object.column_name,
);
@ -546,7 +546,7 @@ fn connect_event_buttons(gui_data: &GuiData) {
&text_view_errors,
&check_button_settings_show_preview_similar_images,
&image_preview,
preview_path,
&preview_path,
nb_object.column_path,
nb_object.column_name,
);
@ -559,7 +559,7 @@ fn show_preview(
text_view_errors: &TextView,
check_button_settings_show_preview: &CheckButton,
image_preview: &Image,
preview_path: Rc<RefCell<String>>,
preview_path: &Rc<RefCell<String>>,
column_path: i32,
column_name: i32,
) {
@ -669,7 +669,7 @@ fn show_preview(
}
};
pixbuf = match resize_pixbuf_dimension(pixbuf, (800, 800), InterpType::Bilinear) {
pixbuf = match resize_pixbuf_dimension(&pixbuf, (800, 800), InterpType::Bilinear) {
None => {
add_text_to_text_view(
text_view_errors,

View file

@ -68,7 +68,7 @@ pub const LANGUAGES_ALL: [Language; 15] = [
},
];
pub fn get_language_from_combo_box_text(combo_box_text: String) -> Language {
pub fn get_language_from_combo_box_text(combo_box_text: &str) -> Language {
for lang in LANGUAGES_ALL {
if lang.combo_box_text == combo_box_text {
return lang;

View file

@ -65,13 +65,13 @@ mod tests;
fn main() {
let application = Application::new(None, ApplicationFlags::HANDLES_OPEN | ApplicationFlags::HANDLES_COMMAND_LINE);
application.connect_command_line(move |app, cmdline| {
build_ui(app, cmdline.arguments());
build_ui(app, &cmdline.arguments());
0
});
application.run_with_args(&env::args().collect::<Vec<_>>());
}
fn build_ui(application: &Application, arguments: Vec<OsString>) {
fn build_ui(application: &Application, arguments: &[OsString]) {
let mut gui_data: GuiData = GuiData::new_with_application(application);
// Used for getting data from thread
@ -134,7 +134,7 @@ fn build_ui(application: &Application, arguments: Vec<OsString>) {
&gui_data.settings,
&gui_data.text_view_errors,
&gui_data.scrolled_window_errors,
arguments.clone(),
arguments.to_owned(),
);
set_number_of_threads(gui_data.settings.scale_settings_number_of_threads.value().round() as usize);
println!("Set thread number to {}", get_number_of_threads());

View file

@ -89,9 +89,9 @@ pub fn opening_double_click_function(gesture_click: &GestureClick, number_of_cli
let nt_object = get_notebook_object_from_tree_view(&tree_view);
if number_of_clicks == 2 {
if gesture_click.current_button() == 1 {
common_open_function(&tree_view, nt_object.column_name, nt_object.column_path, OpenMode::PathAndName);
common_open_function(&tree_view, nt_object.column_name, nt_object.column_path, &OpenMode::PathAndName);
} else if gesture_click.current_button() == 3 {
common_open_function(&tree_view, nt_object.column_name, nt_object.column_path, OpenMode::OnlyPath);
common_open_function(&tree_view, nt_object.column_name, nt_object.column_path, &OpenMode::OnlyPath);
}
}
}
@ -118,7 +118,7 @@ fn common_mark_function(tree_view: &gtk4::TreeView, column_selection: i32, colum
}
}
fn common_open_function(tree_view: &gtk4::TreeView, column_name: i32, column_path: i32, opening_mode: OpenMode) {
fn common_open_function(tree_view: &gtk4::TreeView, column_name: i32, column_path: i32, opening_mode: &OpenMode) {
let selection = tree_view.selection();
let (selected_rows, tree_model) = selection.selected_rows();
@ -212,7 +212,7 @@ fn handle_tree_keypress_upper_directories(tree_view: &gtk4::TreeView, key_code:
fn handle_tree_keypress(tree_view: &gtk4::TreeView, key_code: u32, name_column: i32, path_column: i32, mark_column: i32, column_header: Option<i32>) {
match key_code {
KEY_ENTER => {
common_open_function(tree_view, name_column, path_column, OpenMode::PathAndName);
common_open_function(tree_view, name_column, path_column, &OpenMode::PathAndName);
}
KEY_SPACE => {
common_mark_function(tree_view, mark_column, column_header);

View file

@ -83,10 +83,10 @@ impl LoadSaveStruct {
}
}
pub fn get_vector_string(&self, key: String, default_value: Vec<String>) -> Vec<String> {
if self.loaded_items.contains_key(&key) {
pub fn get_vector_string(&self, key: &str, default_value: Vec<String>) -> Vec<String> {
if self.loaded_items.contains_key(key) {
let mut new_vector = Vec::new();
for i in self.loaded_items.get(&key).unwrap() {
for i in self.loaded_items.get(key).unwrap() {
if !i.trim().is_empty() {
new_vector.push(i.trim().to_string());
}
@ -133,12 +133,11 @@ impl LoadSaveStruct {
let item = self.loaded_items.get(&key).unwrap().clone().into_iter().filter(|e| !e.is_empty()).collect::<Vec<String>>();
return if item.len() == 1 {
match item[0].parse::<T>() {
Ok(t) => t,
Err(_) => {
println!("Failed to decode integer from \"{}\", found {:?}", key, item[0]);
default_value
}
if let Ok(t) = item[0].parse::<T>() {
t
} else {
println!("Failed to decode integer from \"{}\", found {:?}", key, item[0]);
default_value
}
} else {
add_text_to_text_view(
@ -262,39 +261,38 @@ impl LoadSaveStruct {
}
};
return Some((config_file_handler, config_file));
} else {
if !config_file.exists() || !config_file.is_file() {
if manual_execution {
// Don't show errors when there is no configuration file when starting app
add_text_to_text_view(
text_view_errors,
&flg!(
"saving_loading_failed_to_read_config_file",
generate_translation_hashmap(vec![("path", config_file.display().to_string())])
),
);
}
}
if !config_file.exists() || !config_file.is_file() {
if manual_execution {
// Don't show errors when there is no configuration file when starting app
add_text_to_text_view(
text_view_errors,
&flg!(
"saving_loading_failed_to_read_config_file",
generate_translation_hashmap(vec![("path", config_file.display().to_string())])
),
);
}
return None;
}
let config_file_handler = match File::open(&config_file) {
Ok(t) => t,
Err(e) => {
add_text_to_text_view(
text_view_errors,
&flg!(
"saving_loading_failed_to_create_config_file",
generate_translation_hashmap(vec![("path", config_file.display().to_string()), ("reason", e.to_string())])
),
);
return None;
}
let config_file_handler = match File::open(&config_file) {
Ok(t) => t,
Err(e) => {
add_text_to_text_view(
text_view_errors,
&flg!(
"saving_loading_failed_to_create_config_file",
generate_translation_hashmap(vec![("path", config_file.display().to_string()), ("reason", e.to_string())])
),
);
return None;
}
};
return Some((config_file_handler, config_file));
}
} else {
add_text_to_text_view(text_view_errors, flg!("saving_loading_failed_to_get_home_directory").as_str());
};
return Some((config_file_handler, config_file));
}
add_text_to_text_view(text_view_errors, flg!("saving_loading_failed_to_get_home_directory").as_str());
None
}
@ -637,7 +635,7 @@ pub fn save_configuration(manual_execution: bool, upper_notebook: &GuiUpperNoteb
);
saving_struct.save_var(
hashmap_ls.get(&LoadText::Language).unwrap().to_string(),
get_language_from_combo_box_text(settings.combo_box_settings_language.active_text().unwrap().to_string()).short_text,
get_language_from_combo_box_text(&settings.combo_box_settings_language.active_text().unwrap()).short_text,
);
// Comboboxes main notebook
@ -716,7 +714,7 @@ pub fn load_configuration(
loaded_entries.open_and_read_content(&text_view_errors, manual_execution);
// Load here language, default system language could change value in settings so we don't want to lose this value
let short_language = get_language_from_combo_box_text(settings.combo_box_settings_language.active_text().unwrap().to_string())
let short_language = get_language_from_combo_box_text(&settings.combo_box_settings_language.active_text().unwrap())
.short_text
.to_string();
@ -726,8 +724,8 @@ pub fn load_configuration(
// Loading data from hashmaps
let (hashmap_ls, _hashmap_sl) = create_hash_map();
let mut included_directories: Vec<String> = loaded_entries.get_vector_string(hashmap_ls.get(&LoadText::IncludedDirectories).unwrap().clone(), included_directories);
let mut excluded_directories: Vec<String> = loaded_entries.get_vector_string(hashmap_ls.get(&LoadText::ExcludedDirectories).unwrap().clone(), excluded_directories);
let mut included_directories: Vec<String> = loaded_entries.get_vector_string(hashmap_ls.get(&LoadText::IncludedDirectories).unwrap(), included_directories);
let mut excluded_directories: Vec<String> = loaded_entries.get_vector_string(hashmap_ls.get(&LoadText::ExcludedDirectories).unwrap(), excluded_directories);
let excluded_items: String = loaded_entries.get_string(
hashmap_ls.get(&LoadText::ExcludedItems).unwrap().clone(),
upper_notebook.entry_excluded_items.text().to_string(),

View file

@ -1,4 +1,5 @@
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::needless_pass_by_value)]
#![cfg(not(target_os = "windows"))]
use std::convert::From;