2021-12-26 01:19:41 +13:00
|
|
|
use std::collections::HashMap;
|
2022-04-17 04:31:01 +12:00
|
|
|
use std::ffi::OsString;
|
2020-12-08 03:25:44 +13:00
|
|
|
use std::fs::File;
|
2021-12-26 01:19:41 +13:00
|
|
|
use std::io::{Read, Write};
|
|
|
|
use std::path::{Path, PathBuf};
|
2020-12-08 03:25:44 +13:00
|
|
|
use std::{env, fs};
|
|
|
|
|
2021-11-28 08:49:20 +13:00
|
|
|
use directories_next::ProjectDirs;
|
2022-05-22 20:59:09 +12:00
|
|
|
use gtk4::prelude::*;
|
2023-02-19 22:21:14 +13:00
|
|
|
use gtk4::{ComboBoxText, ScrolledWindow, TextView, TreeView};
|
2021-11-28 08:49:20 +13:00
|
|
|
|
2023-04-05 18:08:43 +12:00
|
|
|
use czkawka_core::common::get_default_number_of_threads;
|
2022-06-01 03:52:55 +12:00
|
|
|
use czkawka_core::common_dir_traversal::CheckingMethod;
|
2023-10-08 06:55:23 +13:00
|
|
|
use czkawka_core::common_items::DEFAULT_EXCLUDED_ITEMS;
|
2022-01-16 07:02:27 +13:00
|
|
|
use czkawka_core::similar_images::SIMILAR_VALUES;
|
2021-12-20 02:45:10 +13:00
|
|
|
|
2022-06-01 03:52:55 +12:00
|
|
|
use crate::flg;
|
|
|
|
use crate::gui_structs::gui_main_notebook::GuiMainNotebook;
|
2022-01-14 03:58:33 +13:00
|
|
|
use crate::gui_structs::gui_settings::GuiSettings;
|
|
|
|
use crate::gui_structs::gui_upper_notebook::GuiUpperNotebook;
|
2022-04-10 21:59:41 +12:00
|
|
|
use crate::help_combo_box::DUPLICATES_CHECK_METHOD_COMBO_BOX;
|
2021-11-28 08:49:20 +13:00
|
|
|
use crate::help_functions::*;
|
2021-12-12 04:16:14 +13:00
|
|
|
use crate::language_functions::{get_language_from_combo_box_text, LANGUAGES_ALL};
|
2022-01-20 10:35:07 +13:00
|
|
|
use crate::localizer_core::generate_translation_hashmap;
|
2021-11-28 08:49:20 +13:00
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
const SAVE_FILE_NAME: &str = "czkawka_gui_config_4.txt";
|
|
|
|
|
|
|
|
const DEFAULT_SAVE_ON_EXIT: bool = true;
|
|
|
|
const DEFAULT_LOAD_AT_START: bool = true;
|
|
|
|
const DEFAULT_CONFIRM_DELETION: bool = true;
|
|
|
|
const DEFAULT_CONFIRM_GROUP_DELETION: bool = true;
|
|
|
|
const DEFAULT_SHOW_IMAGE_PREVIEW: bool = true;
|
|
|
|
const DEFAULT_SHOW_DUPLICATE_IMAGE_PREVIEW: bool = true;
|
|
|
|
const DEFAULT_BOTTOM_TEXT_VIEW: bool = true;
|
|
|
|
const DEFAULT_USE_CACHE: bool = true;
|
2022-01-06 10:47:27 +13:00
|
|
|
const DEFAULT_SAVE_ALSO_AS_JSON: bool = false;
|
2021-12-26 01:19:41 +13:00
|
|
|
const DEFAULT_HIDE_HARD_LINKS: bool = true;
|
|
|
|
const DEFAULT_USE_PRECACHE: bool = false;
|
|
|
|
const DEFAULT_USE_TRASH: bool = false;
|
2022-01-08 04:45:08 +13:00
|
|
|
pub const DEFAULT_MINIMAL_CACHE_SIZE: &str = "257144";
|
2021-12-26 01:19:41 +13:00
|
|
|
const DEFAULT_PREHASH_MINIMAL_CACHE_SIZE: &str = "0";
|
|
|
|
const DEFAULT_VIDEO_REMOVE_AUTO_OUTDATED_CACHE: bool = false;
|
|
|
|
const DEFAULT_IMAGE_REMOVE_AUTO_OUTDATED_CACHE: bool = true;
|
|
|
|
const DEFAULT_DUPLICATE_REMOVE_AUTO_OUTDATED_CACHE: bool = true;
|
2022-04-10 21:59:41 +12:00
|
|
|
const DEFAULT_DUPLICATE_CASE_SENSITIVE_NAME_CHECKING: bool = false;
|
2022-07-20 05:09:52 +12:00
|
|
|
const DEFAULT_GENERAL_IGNORE_OTHER_FILESYSTEMS: bool = false;
|
2021-12-26 01:19:41 +13:00
|
|
|
|
2022-06-11 04:58:53 +12:00
|
|
|
const DEFAULT_BROKEN_FILES_PDF: bool = true;
|
|
|
|
const DEFAULT_BROKEN_FILES_AUDIO: bool = true;
|
|
|
|
const DEFAULT_BROKEN_FILES_ARCHIVE: bool = true;
|
|
|
|
const DEFAULT_BROKEN_FILES_IMAGE: bool = true;
|
|
|
|
|
2022-11-26 08:38:27 +13:00
|
|
|
const DEFAULT_THREAD_NUMBER: u32 = 0;
|
|
|
|
|
2022-01-16 07:02:27 +13:00
|
|
|
const DEFAULT_NUMBER_OF_BIGGEST_FILES: &str = "50";
|
2022-07-03 07:30:59 +12:00
|
|
|
const DEFAULT_SIMILAR_IMAGES_SIMILARITY: f32 = 0.0;
|
2022-01-16 07:02:27 +13:00
|
|
|
const DEFAULT_SIMILAR_IMAGES_IGNORE_SAME_SIZE: bool = false;
|
2022-07-03 07:30:59 +12:00
|
|
|
const DEFAULT_SIMILAR_VIDEOS_SIMILARITY: f32 = 15.0;
|
2022-01-16 07:02:27 +13:00
|
|
|
const DEFAULT_SIMILAR_VIDEOS_IGNORE_SAME_SIZE: bool = false;
|
|
|
|
|
2022-01-08 04:45:08 +13:00
|
|
|
pub const DEFAULT_MINIMAL_FILE_SIZE: &str = "16384";
|
|
|
|
pub const DEFAULT_MAXIMAL_FILE_SIZE: &str = "999999999999";
|
|
|
|
|
|
|
|
#[cfg(target_family = "unix")]
|
2022-05-17 04:23:07 +12:00
|
|
|
const DEFAULT_EXCLUDED_DIRECTORIES: &[&str] = &["/proc", "/dev", "/sys", "/run", "/snap"];
|
2022-01-08 04:45:08 +13:00
|
|
|
#[cfg(not(target_family = "unix"))]
|
2022-05-17 04:23:07 +12:00
|
|
|
const DEFAULT_EXCLUDED_DIRECTORIES: &[&str] = &["C:\\Windows"];
|
2022-01-08 04:45:08 +13:00
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
struct LoadSaveStruct {
|
|
|
|
loaded_items: HashMap<String, Vec<String>>,
|
2022-06-01 03:52:55 +12:00
|
|
|
text_view: TextView,
|
2021-12-26 01:19:41 +13:00
|
|
|
}
|
2020-12-08 03:25:44 +13:00
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
impl LoadSaveStruct {
|
2022-06-01 03:52:55 +12:00
|
|
|
pub fn with_text_view(text_view: TextView) -> Self {
|
2021-12-27 00:08:37 +13:00
|
|
|
Self {
|
|
|
|
loaded_items: Default::default(),
|
|
|
|
text_view,
|
|
|
|
}
|
2021-12-26 01:19:41 +13:00
|
|
|
}
|
2020-12-08 03:25:44 +13:00
|
|
|
|
2023-01-29 06:54:02 +13:00
|
|
|
pub fn get_vector_string(&self, key: &str, default_value: Vec<String>) -> Vec<String> {
|
|
|
|
if self.loaded_items.contains_key(key) {
|
2021-12-26 10:23:18 +13:00
|
|
|
let mut new_vector = Vec::new();
|
2023-01-29 06:54:02 +13:00
|
|
|
for i in self.loaded_items.get(key).unwrap() {
|
2021-12-26 10:23:18 +13:00
|
|
|
if !i.trim().is_empty() {
|
|
|
|
new_vector.push(i.trim().to_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new_vector;
|
2021-12-26 01:19:41 +13:00
|
|
|
}
|
2020-12-19 22:03:04 +13:00
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
default_value
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
2022-01-16 07:02:27 +13:00
|
|
|
pub fn get_integer_string(&self, key: String, default_value: String) -> String {
|
|
|
|
if default_value.parse::<i64>().is_err() {
|
2022-12-21 20:44:26 +13:00
|
|
|
println!("Default value {default_value} can't be convert to integer value");
|
2022-01-16 07:02:27 +13:00
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
let mut returned_value = self.get_string(key, default_value.clone());
|
|
|
|
if returned_value.parse::<i64>().is_err() {
|
|
|
|
returned_value = default_value;
|
|
|
|
}
|
|
|
|
returned_value
|
|
|
|
}
|
2021-12-26 01:19:41 +13:00
|
|
|
pub fn get_string(&self, key: String, default_value: String) -> String {
|
|
|
|
if self.loaded_items.contains_key(&key) {
|
|
|
|
let item = self.loaded_items.get(&key).unwrap().clone().into_iter().filter(|e| !e.is_empty()).collect::<Vec<String>>();
|
|
|
|
return if item.len() == 1 {
|
|
|
|
item[0].clone()
|
|
|
|
} else if item.is_empty() {
|
2023-01-29 06:54:02 +13:00
|
|
|
String::new()
|
2021-12-26 01:19:41 +13:00
|
|
|
} else {
|
2021-12-27 00:08:37 +13:00
|
|
|
add_text_to_text_view(
|
|
|
|
&self.text_view,
|
2022-01-20 10:35:07 +13:00
|
|
|
&flg!(
|
2021-12-27 00:08:37 +13:00
|
|
|
"saving_loading_invalid_string",
|
2022-12-21 20:44:26 +13:00
|
|
|
generate_translation_hashmap(vec![("key", key), ("result", format!("{item:?}"))])
|
2021-12-27 00:08:37 +13:00
|
|
|
),
|
|
|
|
);
|
2021-12-26 01:19:41 +13:00
|
|
|
default_value
|
|
|
|
};
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
default_value
|
|
|
|
}
|
2022-07-03 07:30:59 +12:00
|
|
|
pub fn get_object<T: std::str::FromStr>(&self, key: String, default_value: T) -> T {
|
2021-12-26 01:19:41 +13:00
|
|
|
if self.loaded_items.contains_key(&key) {
|
|
|
|
let item = self.loaded_items.get(&key).unwrap().clone().into_iter().filter(|e| !e.is_empty()).collect::<Vec<String>>();
|
|
|
|
|
|
|
|
return if item.len() == 1 {
|
2023-01-29 06:54:02 +13:00
|
|
|
if let Ok(t) = item[0].parse::<T>() {
|
|
|
|
t
|
|
|
|
} else {
|
|
|
|
println!("Failed to decode integer from \"{}\", found {:?}", key, item[0]);
|
|
|
|
default_value
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
2021-12-26 01:19:41 +13:00
|
|
|
} else {
|
2021-12-27 00:08:37 +13:00
|
|
|
add_text_to_text_view(
|
|
|
|
&self.text_view,
|
2022-01-20 10:35:07 +13:00
|
|
|
&flg!(
|
2021-12-27 00:08:37 +13:00
|
|
|
"saving_loading_invalid_int",
|
2022-12-21 20:44:26 +13:00
|
|
|
generate_translation_hashmap(vec![("key", key), ("result", format!("{item:?}"))])
|
2021-12-27 00:08:37 +13:00
|
|
|
),
|
|
|
|
);
|
2021-12-26 01:19:41 +13:00
|
|
|
default_value
|
|
|
|
};
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
default_value
|
2022-01-08 04:45:08 +13:00
|
|
|
}
|
2021-12-26 01:19:41 +13:00
|
|
|
pub fn get_bool(&self, key: String, default_value: bool) -> bool {
|
|
|
|
if self.loaded_items.contains_key(&key) {
|
|
|
|
let item = self.loaded_items.get(&key).unwrap().clone().into_iter().filter(|e| !e.is_empty()).collect::<Vec<String>>();
|
|
|
|
return if item.len() == 1 {
|
2023-02-19 22:21:14 +13:00
|
|
|
let text = item[0].trim().to_lowercase();
|
2021-12-26 01:19:41 +13:00
|
|
|
if text == "false" || text == "0" {
|
|
|
|
false
|
|
|
|
} else if text == "true" || text == "1" {
|
|
|
|
true
|
|
|
|
} else {
|
2021-12-27 00:08:37 +13:00
|
|
|
add_text_to_text_view(
|
|
|
|
&self.text_view,
|
2022-01-20 10:35:07 +13:00
|
|
|
&flg!(
|
2021-12-27 00:08:37 +13:00
|
|
|
"saving_loading_decode_problem_bool",
|
|
|
|
generate_translation_hashmap(vec![("key", key), ("result", item[0].to_string())])
|
|
|
|
),
|
|
|
|
);
|
2021-12-26 01:19:41 +13:00
|
|
|
default_value
|
|
|
|
}
|
|
|
|
} else {
|
2021-12-27 00:08:37 +13:00
|
|
|
add_text_to_text_view(
|
|
|
|
&self.text_view,
|
2022-01-20 10:35:07 +13:00
|
|
|
&flg!(
|
2021-12-27 00:08:37 +13:00
|
|
|
"saving_loading_invalid_bool",
|
2022-12-21 20:44:26 +13:00
|
|
|
generate_translation_hashmap(vec![("key", key), ("result", format!("{item:?}"))])
|
2021-12-27 00:08:37 +13:00
|
|
|
),
|
|
|
|
);
|
2021-12-26 01:19:41 +13:00
|
|
|
default_value
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
default_value
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bool, int, string
|
2023-01-29 06:54:02 +13:00
|
|
|
pub fn save_var<T: ToString>(&mut self, key: String, value: &T) {
|
2021-12-26 01:19:41 +13:00
|
|
|
if self.loaded_items.contains_key(&key) {
|
2021-12-27 00:08:37 +13:00
|
|
|
add_text_to_text_view(
|
|
|
|
&self.text_view,
|
2022-01-20 10:35:07 +13:00
|
|
|
&flg!("saving_loading_saving_same_keys", generate_translation_hashmap(vec![("key", key.clone())])),
|
2021-12-27 00:08:37 +13:00
|
|
|
);
|
2021-12-26 01:19:41 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
self.loaded_items.insert(key, vec![value.to_string()]);
|
|
|
|
}
|
|
|
|
|
2023-02-19 22:21:14 +13:00
|
|
|
pub fn save_list_store(&mut self, key: String, tree_view: &TreeView, column_path: i32) {
|
2021-12-26 01:19:41 +13:00
|
|
|
let mut vec_string = vec![];
|
|
|
|
let list_store = get_list_store(tree_view);
|
2021-06-26 04:07:13 +12:00
|
|
|
if let Some(iter) = list_store.iter_first() {
|
2020-12-08 03:25:44 +13:00
|
|
|
loop {
|
2021-12-26 01:19:41 +13:00
|
|
|
// TODO maybe save also here reference directories?
|
2022-05-22 20:59:09 +12:00
|
|
|
vec_string.push(list_store.get::<String>(&iter, column_path));
|
2020-12-08 03:25:44 +13:00
|
|
|
if !list_store.iter_next(&iter) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-26 01:19:41 +13:00
|
|
|
self.loaded_items.insert(key, vec_string);
|
|
|
|
}
|
2020-12-08 03:25:44 +13:00
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
pub fn open_save_file(&self, text_view_errors: &TextView, save_configuration: bool, manual_execution: bool) -> Option<(File, PathBuf)> {
|
|
|
|
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
|
|
|
|
// Lin: /home/username/.config/czkawka
|
|
|
|
// Win: C:\Users\Username\AppData\Roaming\Qarmin\Czkawka\config
|
|
|
|
// Mac: /Users/Username/Library/Application Support/pl.Qarmin.Czkawka
|
|
|
|
|
|
|
|
let config_dir = proj_dirs.config_dir();
|
|
|
|
let config_file = config_dir.join(Path::new(SAVE_FILE_NAME));
|
|
|
|
|
|
|
|
if save_configuration {
|
|
|
|
if config_dir.exists() {
|
|
|
|
if !config_dir.is_dir() {
|
|
|
|
add_text_to_text_view(
|
|
|
|
text_view_errors,
|
2022-01-20 10:35:07 +13:00
|
|
|
&flg!(
|
2021-12-27 00:08:37 +13:00
|
|
|
"saving_loading_folder_config_instead_file",
|
|
|
|
generate_translation_hashmap(vec![("path", config_dir.display().to_string())])
|
|
|
|
),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
} else if let Err(e) = fs::create_dir_all(config_dir) {
|
|
|
|
add_text_to_text_view(
|
|
|
|
text_view_errors,
|
2022-01-20 10:35:07 +13:00
|
|
|
&flg!(
|
2021-12-27 00:08:37 +13:00
|
|
|
"saving_loading_failed_to_create_configuration_folder",
|
|
|
|
generate_translation_hashmap(vec![("path", config_dir.display().to_string()), ("reason", e.to_string())])
|
|
|
|
),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
return None;
|
2020-12-19 22:15:25 +13:00
|
|
|
}
|
2020-12-08 03:25:44 +13:00
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
let config_file_handler = match File::create(&config_file) {
|
|
|
|
Ok(t) => t,
|
|
|
|
Err(e) => {
|
2021-12-27 00:08:37 +13:00
|
|
|
add_text_to_text_view(
|
|
|
|
text_view_errors,
|
2022-01-20 10:35:07 +13:00
|
|
|
&flg!(
|
2021-12-27 00:08:37 +13:00
|
|
|
"saving_loading_failed_to_create_config_file",
|
|
|
|
generate_translation_hashmap(vec![("path", config_file.display().to_string()), ("reason", e.to_string())])
|
|
|
|
),
|
|
|
|
);
|
2021-12-26 01:19:41 +13:00
|
|
|
return None;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return Some((config_file_handler, config_file));
|
2023-01-29 06:54:02 +13:00
|
|
|
}
|
|
|
|
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())])
|
|
|
|
),
|
|
|
|
);
|
2020-12-19 22:15:25 +13:00
|
|
|
}
|
2023-01-29 06:54:02 +13:00
|
|
|
return None;
|
2021-12-26 01:19:41 +13:00
|
|
|
}
|
2023-01-29 06:54:02 +13:00
|
|
|
|
|
|
|
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));
|
2020-12-19 22:15:25 +13:00
|
|
|
}
|
2023-01-29 06:54:02 +13:00
|
|
|
add_text_to_text_view(text_view_errors, flg!("saving_loading_failed_to_get_home_directory").as_str());
|
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
None
|
|
|
|
}
|
2020-12-19 22:03:04 +13:00
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
pub fn open_and_read_content(&mut self, text_view_errors: &TextView, manual_execution: bool) {
|
|
|
|
if let Some((mut config_file_handler, config_file)) = self.open_save_file(text_view_errors, false, manual_execution) {
|
|
|
|
let mut loaded_data: String = String::new();
|
|
|
|
if let Err(e) = config_file_handler.read_to_string(&mut loaded_data) {
|
2021-12-27 00:08:37 +13:00
|
|
|
add_text_to_text_view(
|
|
|
|
text_view_errors,
|
2022-01-20 10:35:07 +13:00
|
|
|
&flg!(
|
2021-12-27 00:08:37 +13:00
|
|
|
"saving_loading_failed_to_read_data_from_file",
|
|
|
|
generate_translation_hashmap(vec![("path", config_file.display().to_string()), ("reason", e.to_string())])
|
|
|
|
),
|
|
|
|
);
|
2020-12-08 03:25:44 +13:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-29 06:54:02 +13:00
|
|
|
let mut header: String = String::new();
|
2021-12-26 01:19:41 +13:00
|
|
|
let lines: Vec<String> = loaded_data.replace('\r', "").split('\n').map(String::from).collect::<Vec<String>>();
|
|
|
|
for (index, line) in lines.iter().enumerate() {
|
|
|
|
let line = line.trim();
|
|
|
|
if line.starts_with("--") {
|
|
|
|
header = line.to_string();
|
|
|
|
} else if !header.is_empty() {
|
2023-10-05 19:06:47 +13:00
|
|
|
self.loaded_items.entry(header.clone()).or_default().push(line.to_string());
|
2021-12-26 01:19:41 +13:00
|
|
|
} else {
|
2021-12-27 00:08:37 +13:00
|
|
|
add_text_to_text_view(
|
|
|
|
text_view_errors,
|
2022-01-20 10:35:07 +13:00
|
|
|
&flg!(
|
2021-12-27 00:08:37 +13:00
|
|
|
"saving_loading_orphan_data",
|
|
|
|
generate_translation_hashmap(vec![("data", line.to_string()), ("index", index.to_string())])
|
|
|
|
),
|
|
|
|
);
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
2021-12-26 01:19:41 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
let (_, hashmap_sl) = create_hash_map();
|
|
|
|
for setting in self.loaded_items.keys() {
|
|
|
|
if !hashmap_sl.contains_key(setting) {
|
2021-12-27 00:08:37 +13:00
|
|
|
add_text_to_text_view(
|
|
|
|
text_view_errors,
|
2022-01-20 10:35:07 +13:00
|
|
|
&flg!("saving_loading_not_valid", generate_translation_hashmap(vec![("data", setting.to_string())])),
|
2021-12-27 00:08:37 +13:00
|
|
|
);
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
|
|
|
}
|
2021-12-26 01:19:41 +13:00
|
|
|
|
2021-12-27 00:08:37 +13:00
|
|
|
if manual_execution {
|
2022-01-20 10:35:07 +13:00
|
|
|
add_text_to_text_view(text_view_errors, &flg!("saving_loading_loading_success"));
|
2021-12-27 00:08:37 +13:00
|
|
|
}
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
2021-12-26 01:19:41 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn save_to_file(&self, text_view_errors: &TextView) {
|
|
|
|
if let Some((mut config_file_handler, config_file)) = self.open_save_file(text_view_errors, true, false) {
|
|
|
|
let mut data_saved: bool = false;
|
|
|
|
for (key, vec_string) in &self.loaded_items {
|
2022-12-21 20:44:26 +13:00
|
|
|
match writeln!(config_file_handler, "{key}") {
|
2021-12-26 01:19:41 +13:00
|
|
|
Ok(_inspected) => {
|
|
|
|
data_saved = true;
|
|
|
|
}
|
|
|
|
Err(_inspected) => {
|
|
|
|
data_saved = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for data in vec_string {
|
2022-12-21 20:44:26 +13:00
|
|
|
match writeln!(config_file_handler, "{data}") {
|
2021-12-26 01:19:41 +13:00
|
|
|
Ok(_inspected) => {
|
|
|
|
data_saved = true;
|
|
|
|
}
|
|
|
|
Err(_inspected) => {
|
|
|
|
data_saved = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if data_saved {
|
|
|
|
add_text_to_text_view(
|
|
|
|
text_view_errors,
|
2022-01-20 10:35:07 +13:00
|
|
|
flg!(
|
2021-12-26 01:19:41 +13:00
|
|
|
"saving_loading_saving_success",
|
|
|
|
generate_translation_hashmap(vec![("name", config_file.display().to_string())])
|
|
|
|
)
|
|
|
|
.as_str(),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
add_text_to_text_view(
|
|
|
|
text_view_errors,
|
2022-01-20 10:35:07 +13:00
|
|
|
flg!(
|
2021-12-26 01:19:41 +13:00
|
|
|
"saving_loading_saving_failure",
|
|
|
|
generate_translation_hashmap(vec![("name", config_file.display().to_string())])
|
|
|
|
)
|
|
|
|
.as_str(),
|
|
|
|
);
|
|
|
|
}
|
2020-12-19 22:15:25 +13:00
|
|
|
}
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
#[derive(Copy, Clone, Hash, Eq, PartialEq)]
|
|
|
|
enum LoadText {
|
2020-12-08 03:25:44 +13:00
|
|
|
IncludedDirectories,
|
|
|
|
ExcludedDirectories,
|
|
|
|
ExcludedItems,
|
|
|
|
AllowedExtensions,
|
2022-01-08 04:45:08 +13:00
|
|
|
MinimalFileSize,
|
|
|
|
MaximalFileSize,
|
2021-12-26 01:19:41 +13:00
|
|
|
SaveAtExit,
|
|
|
|
LoadAtStart,
|
|
|
|
ConfirmDeletionFiles,
|
|
|
|
ConfirmDeletionAllFilesInGroup,
|
|
|
|
ShowBottomTextPanel,
|
2021-02-23 21:40:19 +13:00
|
|
|
HideHardLinks,
|
2021-03-05 00:09:53 +13:00
|
|
|
UseCache,
|
2022-01-06 10:47:27 +13:00
|
|
|
UseJsonCacheFile,
|
2021-12-26 01:19:41 +13:00
|
|
|
DeleteToTrash,
|
|
|
|
MinimalCacheSize,
|
|
|
|
ImagePreviewImage,
|
|
|
|
DuplicatePreviewImage,
|
|
|
|
DuplicateDeleteOutdatedCacheEntries,
|
|
|
|
ImageDeleteOutdatedCacheEntries,
|
|
|
|
VideoDeleteOutdatedCacheEntries,
|
2021-12-02 08:09:04 +13:00
|
|
|
UsePrehashCache,
|
2021-12-26 01:19:41 +13:00
|
|
|
MinimalPrehashCacheSize,
|
2022-07-20 05:09:52 +12:00
|
|
|
GeneralIgnoreOtherFilesystems,
|
2021-12-12 04:16:14 +13:00
|
|
|
Language,
|
2022-01-08 04:45:08 +13:00
|
|
|
ComboBoxDuplicateHashType,
|
|
|
|
ComboBoxDuplicateCheckMethod,
|
|
|
|
ComboBoxImageResizeAlgorithm,
|
|
|
|
ComboBoxImageHashType,
|
|
|
|
ComboBoxImageHashSize,
|
2022-06-05 07:20:21 +12:00
|
|
|
ComboBoxBigFiles,
|
2022-01-16 07:02:27 +13:00
|
|
|
NumberOfBiggestFiles,
|
|
|
|
SimilarImagesSimilarity,
|
|
|
|
SimilarImagesIgnoreSameSize,
|
|
|
|
SimilarVideosSimilarity,
|
|
|
|
SimilarVideosIgnoreSameSize,
|
|
|
|
MusicApproximateComparison,
|
2022-04-10 21:59:41 +12:00
|
|
|
DuplicateNameCaseSensitive,
|
2022-06-11 04:58:53 +12:00
|
|
|
BrokenFilesPdf,
|
|
|
|
BrokenFilesAudio,
|
|
|
|
BrokenFilesImage,
|
|
|
|
BrokenFilesArchive,
|
2022-11-26 08:38:27 +13:00
|
|
|
ThreadNumber,
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
fn create_hash_map() -> (HashMap<LoadText, String>, HashMap<String, LoadText>) {
|
|
|
|
let values = [
|
|
|
|
(LoadText::IncludedDirectories, "included_directories"),
|
|
|
|
(LoadText::ExcludedDirectories, "excluded_directories"),
|
|
|
|
(LoadText::ExcludedItems, "excluded_items"),
|
|
|
|
(LoadText::AllowedExtensions, "allowed_extensions"),
|
2022-01-08 04:45:08 +13:00
|
|
|
(LoadText::MinimalFileSize, "minimal_file_size"),
|
|
|
|
(LoadText::MaximalFileSize, "maximal_file_size"),
|
2021-12-26 01:19:41 +13:00
|
|
|
(LoadText::SaveAtExit, "save_at_exit"),
|
|
|
|
(LoadText::LoadAtStart, "load_at_start"),
|
|
|
|
(LoadText::ConfirmDeletionFiles, "confirm_deletion_files"),
|
|
|
|
(LoadText::ConfirmDeletionAllFilesInGroup, "confirm_deletion_all_files_in_group"),
|
|
|
|
(LoadText::ShowBottomTextPanel, "show_bottom_text_panel"),
|
|
|
|
(LoadText::HideHardLinks, "hide_hard_links"),
|
|
|
|
(LoadText::UseCache, "use_cache"),
|
2022-01-06 10:47:27 +13:00
|
|
|
(LoadText::UseJsonCacheFile, "use_json_cache_file"),
|
2021-12-26 01:19:41 +13:00
|
|
|
(LoadText::DeleteToTrash, "delete_to_trash"),
|
|
|
|
(LoadText::MinimalCacheSize, "minimal_cache_size"),
|
|
|
|
(LoadText::ImagePreviewImage, "image_preview_image"),
|
|
|
|
(LoadText::DuplicatePreviewImage, "duplicate_preview_image"),
|
|
|
|
(LoadText::DuplicateDeleteOutdatedCacheEntries, "duplicate_delete_outdated_cache_entries"),
|
|
|
|
(LoadText::ImageDeleteOutdatedCacheEntries, "image_delete_outdated_cache_entries"),
|
|
|
|
(LoadText::VideoDeleteOutdatedCacheEntries, "video_delete_outdated_cache_entries"),
|
|
|
|
(LoadText::UsePrehashCache, "use_prehash_cache"),
|
|
|
|
(LoadText::MinimalPrehashCacheSize, "minimal_prehash_cache_size"),
|
|
|
|
(LoadText::Language, "language"),
|
2022-01-08 04:45:08 +13:00
|
|
|
(LoadText::ComboBoxDuplicateHashType, "combo_box_duplicate_hash_type"),
|
|
|
|
(LoadText::ComboBoxDuplicateCheckMethod, "combo_box_duplicate_check_method"),
|
|
|
|
(LoadText::ComboBoxImageResizeAlgorithm, "combo_box_image_resize_algorithm"),
|
|
|
|
(LoadText::ComboBoxImageHashType, "combo_box_image_hash_type"),
|
|
|
|
(LoadText::ComboBoxImageHashSize, "combo_box_image_hash_size"),
|
2022-01-16 07:02:27 +13:00
|
|
|
(LoadText::NumberOfBiggestFiles, "number_of_biggest_files"),
|
|
|
|
(LoadText::SimilarImagesSimilarity, "similar_images_similarity"),
|
|
|
|
(LoadText::SimilarImagesIgnoreSameSize, "similar_images_ignore_same_size"),
|
|
|
|
(LoadText::SimilarVideosSimilarity, "similar_videos_similarity"),
|
|
|
|
(LoadText::SimilarVideosIgnoreSameSize, "similar_videos_ignore_same_size"),
|
|
|
|
(LoadText::MusicApproximateComparison, "music_approximate_comparison"),
|
2022-04-10 21:59:41 +12:00
|
|
|
(LoadText::DuplicateNameCaseSensitive, "duplicate_name_case_sensitive"),
|
2022-06-05 07:20:21 +12:00
|
|
|
(LoadText::ComboBoxBigFiles, "combo_box_big_files_mode"),
|
2022-06-11 04:58:53 +12:00
|
|
|
(LoadText::BrokenFilesPdf, "broken_files_pdf"),
|
|
|
|
(LoadText::BrokenFilesAudio, "broken_files_audio"),
|
|
|
|
(LoadText::BrokenFilesImage, "broken_files_image"),
|
|
|
|
(LoadText::BrokenFilesArchive, "broken_files_archive"),
|
2022-07-20 05:09:52 +12:00
|
|
|
(LoadText::GeneralIgnoreOtherFilesystems, "ignore_other_filesystems"),
|
2022-11-26 08:38:27 +13:00
|
|
|
(LoadText::ThreadNumber, "thread_number"),
|
2021-12-26 01:19:41 +13:00
|
|
|
];
|
|
|
|
let mut hashmap_ls: HashMap<LoadText, String> = Default::default();
|
|
|
|
let mut hashmap_sl: HashMap<String, LoadText> = Default::default();
|
|
|
|
|
|
|
|
for (load_text, string) in values {
|
2022-12-21 20:44:26 +13:00
|
|
|
hashmap_ls.insert(load_text, format!("--{string}"));
|
|
|
|
hashmap_sl.insert(format!("--{string}"), load_text);
|
2021-12-26 01:19:41 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
(hashmap_ls, hashmap_sl)
|
|
|
|
}
|
|
|
|
|
2022-01-08 04:45:08 +13:00
|
|
|
pub fn save_configuration(manual_execution: bool, upper_notebook: &GuiUpperNotebook, main_notebook: &GuiMainNotebook, settings: &GuiSettings, text_view_errors: &TextView) {
|
2021-12-26 01:19:41 +13:00
|
|
|
let check_button_settings_save_at_exit = settings.check_button_settings_save_at_exit.clone();
|
2021-11-25 20:36:49 +13:00
|
|
|
let text_view_errors = text_view_errors.clone();
|
2020-12-19 22:03:04 +13:00
|
|
|
|
|
|
|
reset_text_view(&text_view_errors);
|
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
if !manual_execution && !check_button_settings_save_at_exit.is_active() {
|
|
|
|
// When check button is deselected, not save configuration at exit
|
|
|
|
return;
|
|
|
|
}
|
2020-12-08 03:25:44 +13:00
|
|
|
|
2021-12-27 00:08:37 +13:00
|
|
|
let mut saving_struct = LoadSaveStruct::with_text_view(text_view_errors.clone());
|
2021-12-26 01:19:41 +13:00
|
|
|
|
|
|
|
let (hashmap_ls, _hashmap_sl) = create_hash_map();
|
|
|
|
|
|
|
|
// Upper notebook
|
|
|
|
saving_struct.save_list_store(
|
|
|
|
hashmap_ls.get(&LoadText::IncludedDirectories).unwrap().to_string(),
|
|
|
|
&upper_notebook.tree_view_included_directories.clone(),
|
|
|
|
ColumnsIncludedDirectory::Path as i32,
|
|
|
|
);
|
|
|
|
saving_struct.save_list_store(
|
|
|
|
hashmap_ls.get(&LoadText::ExcludedDirectories).unwrap().to_string(),
|
|
|
|
&upper_notebook.tree_view_excluded_directories.clone(),
|
|
|
|
ColumnsExcludedDirectory::Path as i32,
|
|
|
|
);
|
2023-01-29 06:54:02 +13:00
|
|
|
saving_struct.save_var(hashmap_ls.get(&LoadText::ExcludedItems).unwrap().to_string(), &upper_notebook.entry_excluded_items.text());
|
2021-12-26 01:19:41 +13:00
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::AllowedExtensions).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&upper_notebook.entry_allowed_extensions.text(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
2022-01-08 04:45:08 +13:00
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::MinimalFileSize).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&upper_notebook.entry_general_minimal_size.text(),
|
2022-01-08 04:45:08 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::MaximalFileSize).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&upper_notebook.entry_general_maximal_size.text(),
|
2022-01-08 04:45:08 +13:00
|
|
|
);
|
2021-12-26 01:19:41 +13:00
|
|
|
|
|
|
|
// Check buttons
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::SaveAtExit).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_save_at_exit.is_active(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::LoadAtStart).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_load_at_start.is_active(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::ConfirmDeletionFiles).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_confirm_deletion.is_active(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::ConfirmDeletionAllFilesInGroup).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_confirm_group_deletion.is_active(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::ImagePreviewImage).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_show_preview_similar_images.is_active(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::DuplicatePreviewImage).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_show_preview_duplicates.is_active(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::HideHardLinks).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_hide_hard_links.is_active(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::UseCache).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_use_cache.is_active(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
2022-01-06 10:47:27 +13:00
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::UseJsonCacheFile).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_save_also_json.is_active(),
|
2022-01-06 10:47:27 +13:00
|
|
|
);
|
2021-12-26 01:19:41 +13:00
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::DeleteToTrash).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_use_trash.is_active(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::ImageDeleteOutdatedCacheEntries).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_similar_images_delete_outdated_cache.is_active(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::DuplicateDeleteOutdatedCacheEntries).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_duplicates_delete_outdated_cache.is_active(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::VideoDeleteOutdatedCacheEntries).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_similar_videos_delete_outdated_cache.is_active(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::UsePrehashCache).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_duplicates_use_prehash_cache.is_active(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::ShowBottomTextPanel).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_show_text_view.is_active(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
2022-07-20 05:09:52 +12:00
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::GeneralIgnoreOtherFilesystems).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.check_button_settings_one_filesystem.is_active(),
|
2022-07-20 05:09:52 +12:00
|
|
|
);
|
2021-12-26 01:19:41 +13:00
|
|
|
|
2022-06-11 04:58:53 +12:00
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::BrokenFilesArchive).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.check_button_broken_files_archive.is_active(),
|
2022-06-11 04:58:53 +12:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::BrokenFilesImage).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.check_button_broken_files_image.is_active(),
|
2022-06-11 04:58:53 +12:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::BrokenFilesAudio).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.check_button_broken_files_audio.is_active(),
|
2022-06-11 04:58:53 +12:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::BrokenFilesPdf).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.check_button_broken_files_pdf.is_active(),
|
2022-06-11 04:58:53 +12:00
|
|
|
);
|
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
// Others
|
2022-11-26 08:38:27 +13:00
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::ThreadNumber).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.scale_settings_number_of_threads.value().round(),
|
2022-11-26 08:38:27 +13:00
|
|
|
);
|
2021-12-26 01:19:41 +13:00
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::MinimalCacheSize).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.entry_settings_cache_file_minimal_size.text(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::MinimalPrehashCacheSize).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&settings.entry_settings_prehash_cache_file_minimal_size.text(),
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::Language).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&get_language_from_combo_box_text(&settings.combo_box_settings_language.active_text().unwrap()).short_text,
|
2021-12-26 01:19:41 +13:00
|
|
|
);
|
|
|
|
|
2022-01-08 04:45:08 +13:00
|
|
|
// Comboboxes main notebook
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::ComboBoxDuplicateHashType).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.combo_box_duplicate_hash_type.active().unwrap_or(0),
|
2022-01-08 04:45:08 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::ComboBoxDuplicateCheckMethod).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.combo_box_duplicate_check_method.active().unwrap_or(0),
|
2022-01-08 04:45:08 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::ComboBoxImageResizeAlgorithm).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.combo_box_image_resize_algorithm.active().unwrap_or(0),
|
2022-01-08 04:45:08 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::ComboBoxImageHashType).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.combo_box_image_hash_algorithm.active().unwrap_or(0),
|
2022-01-08 04:45:08 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::ComboBoxImageHashSize).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.combo_box_image_hash_size.active().unwrap_or(0),
|
2022-01-08 04:45:08 +13:00
|
|
|
);
|
2022-06-05 07:20:21 +12:00
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::ComboBoxBigFiles).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.combo_box_big_files_mode.active().unwrap_or(0),
|
2022-06-05 07:20:21 +12:00
|
|
|
);
|
2022-01-08 04:45:08 +13:00
|
|
|
|
2022-01-16 07:02:27 +13:00
|
|
|
// Other2
|
2022-04-10 21:59:41 +12:00
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::DuplicateNameCaseSensitive).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.check_button_duplicate_case_sensitive_name.is_active(),
|
2022-04-10 21:59:41 +12:00
|
|
|
);
|
2022-01-16 07:02:27 +13:00
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::NumberOfBiggestFiles).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.entry_big_files_number.text(),
|
2022-01-16 07:02:27 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::SimilarImagesSimilarity).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.scale_similarity_similar_images.value(),
|
2022-01-16 07:02:27 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::SimilarImagesIgnoreSameSize).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.check_button_image_ignore_same_size.is_active(),
|
2022-01-16 07:02:27 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::SimilarVideosSimilarity).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.scale_similarity_similar_videos.value(),
|
2022-01-16 07:02:27 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::SimilarVideosIgnoreSameSize).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.check_button_video_ignore_same_size.is_active(),
|
2022-01-16 07:02:27 +13:00
|
|
|
);
|
|
|
|
saving_struct.save_var(
|
|
|
|
hashmap_ls.get(&LoadText::MusicApproximateComparison).unwrap().to_string(),
|
2023-01-29 06:54:02 +13:00
|
|
|
&main_notebook.check_button_music_approximate_comparison.is_active(),
|
2022-01-16 07:02:27 +13:00
|
|
|
);
|
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
saving_struct.save_to_file(&text_view_errors);
|
|
|
|
}
|
2021-12-19 11:45:37 +13:00
|
|
|
|
2022-01-08 04:45:08 +13:00
|
|
|
pub fn load_configuration(
|
|
|
|
manual_execution: bool,
|
|
|
|
upper_notebook: &GuiUpperNotebook,
|
|
|
|
main_notebook: &GuiMainNotebook,
|
|
|
|
settings: &GuiSettings,
|
|
|
|
text_view_errors: &TextView,
|
|
|
|
scrolled_window_errors: &ScrolledWindow,
|
2023-01-29 06:54:02 +13:00
|
|
|
arguments: &[OsString],
|
2022-01-08 04:45:08 +13:00
|
|
|
) {
|
2021-12-26 01:19:41 +13:00
|
|
|
let text_view_errors = text_view_errors.clone();
|
2021-12-19 11:45:37 +13:00
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
reset_text_view(&text_view_errors);
|
2020-12-08 03:25:44 +13:00
|
|
|
|
2021-12-27 00:08:37 +13:00
|
|
|
let mut loaded_entries = LoadSaveStruct::with_text_view(text_view_errors.clone());
|
2021-12-26 01:19:41 +13:00
|
|
|
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
|
2023-01-29 06:54:02 +13:00
|
|
|
let short_language = get_language_from_combo_box_text(&settings.combo_box_settings_language.active_text().unwrap())
|
2021-12-26 01:19:41 +13:00
|
|
|
.short_text
|
|
|
|
.to_string();
|
|
|
|
|
2022-01-11 00:19:28 +13:00
|
|
|
let included_directories = get_string_from_list_store(&upper_notebook.tree_view_included_directories, ColumnsIncludedDirectory::Path as i32, None);
|
|
|
|
let excluded_directories = get_string_from_list_store(&upper_notebook.tree_view_excluded_directories, ColumnsExcludedDirectory::Path as i32, None);
|
|
|
|
|
2022-01-14 18:34:43 +13:00
|
|
|
// Loading data from hashmaps
|
2021-12-26 01:19:41 +13:00
|
|
|
let (hashmap_ls, _hashmap_sl) = create_hash_map();
|
|
|
|
|
2023-01-29 06:54:02 +13:00
|
|
|
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);
|
2022-01-11 00:19:28 +13:00
|
|
|
let excluded_items: String = loaded_entries.get_string(
|
|
|
|
hashmap_ls.get(&LoadText::ExcludedItems).unwrap().clone(),
|
|
|
|
upper_notebook.entry_excluded_items.text().to_string(),
|
|
|
|
);
|
2023-01-29 06:54:02 +13:00
|
|
|
let allowed_extensions: String = loaded_entries.get_string(hashmap_ls.get(&LoadText::AllowedExtensions).unwrap().clone(), String::new());
|
2022-01-16 07:02:27 +13:00
|
|
|
let minimal_file_size: String = loaded_entries.get_integer_string(hashmap_ls.get(&LoadText::MinimalFileSize).unwrap().clone(), DEFAULT_MINIMAL_FILE_SIZE.to_string());
|
|
|
|
let maximal_file_size: String = loaded_entries.get_integer_string(hashmap_ls.get(&LoadText::MaximalFileSize).unwrap().clone(), DEFAULT_MAXIMAL_FILE_SIZE.to_string());
|
2021-12-26 01:19:41 +13:00
|
|
|
|
|
|
|
let loading_at_start: bool = loaded_entries.get_bool(hashmap_ls.get(&LoadText::LoadAtStart).unwrap().clone(), DEFAULT_LOAD_AT_START);
|
2023-02-19 22:21:14 +13:00
|
|
|
let mut saving_at_exit: bool = loaded_entries.get_bool(hashmap_ls.get(&LoadText::SaveAtExit).unwrap().clone(), DEFAULT_SAVE_ON_EXIT);
|
2021-12-26 01:19:41 +13:00
|
|
|
let confirm_deletion: bool = loaded_entries.get_bool(hashmap_ls.get(&LoadText::ConfirmDeletionFiles).unwrap().clone(), DEFAULT_CONFIRM_DELETION);
|
|
|
|
let confirm_group_deletion: bool = loaded_entries.get_bool(hashmap_ls.get(&LoadText::ConfirmDeletionAllFilesInGroup).unwrap().clone(), DEFAULT_CONFIRM_GROUP_DELETION);
|
|
|
|
let show_previews_similar_images: bool = loaded_entries.get_bool(hashmap_ls.get(&LoadText::ImagePreviewImage).unwrap().clone(), DEFAULT_SHOW_IMAGE_PREVIEW);
|
|
|
|
let show_previews_duplicates: bool = loaded_entries.get_bool(hashmap_ls.get(&LoadText::DuplicatePreviewImage).unwrap().clone(), DEFAULT_SHOW_DUPLICATE_IMAGE_PREVIEW);
|
|
|
|
let bottom_text_panel: bool = loaded_entries.get_bool(hashmap_ls.get(&LoadText::ShowBottomTextPanel).unwrap().clone(), DEFAULT_BOTTOM_TEXT_VIEW);
|
|
|
|
let hide_hard_links: bool = loaded_entries.get_bool(hashmap_ls.get(&LoadText::HideHardLinks).unwrap().clone(), DEFAULT_HIDE_HARD_LINKS);
|
|
|
|
let use_cache: bool = loaded_entries.get_bool(hashmap_ls.get(&LoadText::UseCache).unwrap().clone(), DEFAULT_USE_CACHE);
|
2022-01-06 10:47:27 +13:00
|
|
|
let use_json_cache: bool = loaded_entries.get_bool(hashmap_ls.get(&LoadText::UseJsonCacheFile).unwrap().clone(), DEFAULT_SAVE_ALSO_AS_JSON);
|
2021-12-26 01:19:41 +13:00
|
|
|
let use_trash: bool = loaded_entries.get_bool(hashmap_ls.get(&LoadText::DeleteToTrash).unwrap().clone(), DEFAULT_USE_TRASH);
|
2022-07-20 05:09:52 +12:00
|
|
|
let ignore_other_fs: bool = loaded_entries.get_bool(
|
|
|
|
hashmap_ls.get(&LoadText::GeneralIgnoreOtherFilesystems).unwrap().clone(),
|
|
|
|
DEFAULT_GENERAL_IGNORE_OTHER_FILESYSTEMS,
|
|
|
|
);
|
2021-12-26 01:19:41 +13:00
|
|
|
let delete_outdated_cache_duplicates: bool = loaded_entries.get_bool(
|
|
|
|
hashmap_ls.get(&LoadText::DuplicateDeleteOutdatedCacheEntries).unwrap().clone(),
|
|
|
|
DEFAULT_DUPLICATE_REMOVE_AUTO_OUTDATED_CACHE,
|
|
|
|
);
|
|
|
|
let delete_outdated_cache_similar_images: bool = loaded_entries.get_bool(
|
|
|
|
hashmap_ls.get(&LoadText::ImageDeleteOutdatedCacheEntries).unwrap().clone(),
|
|
|
|
DEFAULT_IMAGE_REMOVE_AUTO_OUTDATED_CACHE,
|
|
|
|
);
|
|
|
|
let delete_outdated_cache_similar_videos: bool = loaded_entries.get_bool(
|
|
|
|
hashmap_ls.get(&LoadText::VideoDeleteOutdatedCacheEntries).unwrap().clone(),
|
|
|
|
DEFAULT_VIDEO_REMOVE_AUTO_OUTDATED_CACHE,
|
|
|
|
);
|
|
|
|
let use_prehash_cache: bool = loaded_entries.get_bool(hashmap_ls.get(&LoadText::UsePrehashCache).unwrap().clone(), DEFAULT_USE_PRECACHE);
|
|
|
|
|
2022-01-16 07:02:27 +13:00
|
|
|
let cache_prehash_minimal_size: String = loaded_entries.get_integer_string(
|
2021-12-26 01:19:41 +13:00
|
|
|
hashmap_ls.get(&LoadText::MinimalPrehashCacheSize).unwrap().clone(),
|
|
|
|
DEFAULT_PREHASH_MINIMAL_CACHE_SIZE.to_string(),
|
|
|
|
);
|
2022-01-16 07:02:27 +13:00
|
|
|
let cache_minimal_size: String = loaded_entries.get_integer_string(hashmap_ls.get(&LoadText::MinimalCacheSize).unwrap().clone(), DEFAULT_MINIMAL_CACHE_SIZE.to_string());
|
2021-12-26 01:19:41 +13:00
|
|
|
let short_language = loaded_entries.get_string(hashmap_ls.get(&LoadText::Language).unwrap().clone(), short_language);
|
|
|
|
|
2022-07-03 07:30:59 +12:00
|
|
|
let combo_box_duplicate_hash_type = loaded_entries.get_object(hashmap_ls.get(&LoadText::ComboBoxDuplicateHashType).unwrap().clone(), 0);
|
|
|
|
let combo_box_duplicate_checking_method = loaded_entries.get_object(hashmap_ls.get(&LoadText::ComboBoxDuplicateCheckMethod).unwrap().clone(), 0);
|
2022-07-06 05:58:57 +12:00
|
|
|
let combo_box_image_hash_size = loaded_entries.get_object(hashmap_ls.get(&LoadText::ComboBoxImageHashSize).unwrap().clone(), 1); // 16 instead default 8
|
2022-07-03 07:30:59 +12:00
|
|
|
let combo_box_image_hash_algorithm = loaded_entries.get_object(hashmap_ls.get(&LoadText::ComboBoxImageHashType).unwrap().clone(), 0);
|
|
|
|
let combo_box_image_resize_algorithm = loaded_entries.get_object(hashmap_ls.get(&LoadText::ComboBoxImageResizeAlgorithm).unwrap().clone(), 0);
|
|
|
|
let combo_box_big_files_mode = loaded_entries.get_object(hashmap_ls.get(&LoadText::ComboBoxBigFiles).unwrap().clone(), 0);
|
2022-01-08 04:45:08 +13:00
|
|
|
|
2022-01-16 07:02:27 +13:00
|
|
|
let number_of_biggest_files = loaded_entries.get_integer_string(
|
|
|
|
hashmap_ls.get(&LoadText::NumberOfBiggestFiles).unwrap().clone(),
|
|
|
|
DEFAULT_NUMBER_OF_BIGGEST_FILES.to_string(),
|
|
|
|
);
|
2022-07-03 07:30:59 +12:00
|
|
|
let similar_images_similarity = loaded_entries.get_object(hashmap_ls.get(&LoadText::SimilarImagesSimilarity).unwrap().clone(), DEFAULT_SIMILAR_IMAGES_SIMILARITY);
|
2022-01-16 07:02:27 +13:00
|
|
|
let similar_images_ignore_same_size = loaded_entries.get_bool(
|
|
|
|
hashmap_ls.get(&LoadText::SimilarImagesIgnoreSameSize).unwrap().clone(),
|
|
|
|
DEFAULT_SIMILAR_IMAGES_IGNORE_SAME_SIZE,
|
|
|
|
);
|
2022-07-03 07:30:59 +12:00
|
|
|
let similar_videos_similarity = loaded_entries.get_object(hashmap_ls.get(&LoadText::SimilarVideosSimilarity).unwrap().clone(), DEFAULT_SIMILAR_VIDEOS_SIMILARITY);
|
2022-01-16 07:02:27 +13:00
|
|
|
let similar_videos_ignore_same_size = loaded_entries.get_bool(
|
|
|
|
hashmap_ls.get(&LoadText::SimilarVideosIgnoreSameSize).unwrap().clone(),
|
|
|
|
DEFAULT_SIMILAR_VIDEOS_IGNORE_SAME_SIZE,
|
|
|
|
);
|
2022-07-03 07:30:59 +12:00
|
|
|
let check_button_case_sensitive_name = loaded_entries.get_object(
|
2022-04-10 21:59:41 +12:00
|
|
|
hashmap_ls.get(&LoadText::DuplicateNameCaseSensitive).unwrap().clone(),
|
|
|
|
DEFAULT_DUPLICATE_CASE_SENSITIVE_NAME_CHECKING,
|
|
|
|
);
|
2022-01-16 07:02:27 +13:00
|
|
|
|
2022-07-03 07:30:59 +12:00
|
|
|
let check_button_broken_files_archive = loaded_entries.get_object(hashmap_ls.get(&LoadText::BrokenFilesArchive).unwrap().clone(), DEFAULT_BROKEN_FILES_ARCHIVE);
|
2022-11-26 08:38:27 +13:00
|
|
|
let check_button_broken_files_pdf = loaded_entries.get_object(hashmap_ls.get(&LoadText::BrokenFilesPdf).unwrap().clone(), DEFAULT_BROKEN_FILES_PDF);
|
|
|
|
let check_button_broken_files_image = loaded_entries.get_object(hashmap_ls.get(&LoadText::BrokenFilesImage).unwrap().clone(), DEFAULT_BROKEN_FILES_IMAGE);
|
|
|
|
let check_button_broken_files_audio = loaded_entries.get_object(hashmap_ls.get(&LoadText::BrokenFilesAudio).unwrap().clone(), DEFAULT_BROKEN_FILES_AUDIO);
|
|
|
|
let thread_number = loaded_entries.get_object(hashmap_ls.get(&LoadText::ThreadNumber).unwrap().clone(), DEFAULT_THREAD_NUMBER);
|
2022-06-11 04:58:53 +12:00
|
|
|
|
2023-02-19 22:21:14 +13:00
|
|
|
let mut set_start_folders = false;
|
|
|
|
if !manual_execution {
|
|
|
|
// Handle here arguments that were added to app e.g. czkawka_gui /home --/home/roman
|
|
|
|
if arguments.len() > 1 {
|
|
|
|
let iter_i = arguments.iter().skip(1);
|
|
|
|
let iter_e = iter_i.clone();
|
|
|
|
let inc_dir = iter_i
|
|
|
|
.filter_map(|e| {
|
|
|
|
let r = e.to_string_lossy().to_string();
|
|
|
|
if !r.starts_with("--") {
|
|
|
|
let path = Path::new(&r);
|
|
|
|
if !path.exists() {
|
|
|
|
return None;
|
2022-04-17 04:31:01 +12:00
|
|
|
}
|
2023-02-19 22:21:14 +13:00
|
|
|
match path.canonicalize() {
|
|
|
|
Ok(r) => Some(r.to_string_lossy().to_string()),
|
|
|
|
Err(_) => None,
|
2022-04-17 04:31:01 +12:00
|
|
|
}
|
2023-02-19 22:21:14 +13:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let exc_dir = iter_e
|
|
|
|
.filter_map(|e| {
|
|
|
|
let r = e.to_string_lossy().to_string();
|
|
|
|
if let Some(r) = r.strip_prefix("--") {
|
|
|
|
let path = Path::new(&r);
|
|
|
|
if !path.exists() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
match path.canonicalize() {
|
|
|
|
Ok(r) => Some(r.to_string_lossy().to_string()),
|
|
|
|
Err(_) => None,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
2022-04-17 04:31:01 +12:00
|
|
|
|
2023-02-19 22:21:14 +13:00
|
|
|
if inc_dir.is_empty() {
|
|
|
|
println!("Arguments {arguments:?} should contains at least one directory to include");
|
|
|
|
} else {
|
|
|
|
included_directories = inc_dir;
|
|
|
|
excluded_directories = exc_dir;
|
|
|
|
saving_at_exit = false;
|
|
|
|
set_start_folders = true;
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
2023-02-19 22:21:14 +13:00
|
|
|
}
|
|
|
|
}
|
2020-12-08 03:25:44 +13:00
|
|
|
|
2023-02-19 22:21:14 +13:00
|
|
|
if manual_execution || loading_at_start || set_start_folders {
|
|
|
|
set_directories(
|
|
|
|
&upper_notebook.tree_view_included_directories,
|
|
|
|
&upper_notebook.tree_view_excluded_directories,
|
|
|
|
&included_directories,
|
|
|
|
&excluded_directories,
|
|
|
|
);
|
|
|
|
}
|
2020-12-08 03:25:44 +13:00
|
|
|
|
2023-02-19 22:21:14 +13:00
|
|
|
// Setting data
|
|
|
|
if loading_at_start || manual_execution {
|
2022-01-08 04:45:08 +13:00
|
|
|
//// Language ComboBoxText
|
2021-12-26 01:19:41 +13:00
|
|
|
{
|
|
|
|
for (index, lang) in LANGUAGES_ALL.iter().enumerate() {
|
|
|
|
if short_language == lang.short_text {
|
|
|
|
settings.combo_box_settings_language.set_active(Some(index as u32));
|
2021-12-12 04:16:14 +13:00
|
|
|
}
|
|
|
|
}
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
|
|
|
|
2021-12-26 01:19:41 +13:00
|
|
|
upper_notebook.entry_excluded_items.set_text(&excluded_items);
|
|
|
|
upper_notebook.entry_allowed_extensions.set_text(&allowed_extensions);
|
2022-01-08 04:45:08 +13:00
|
|
|
upper_notebook.entry_general_minimal_size.set_text(&minimal_file_size);
|
|
|
|
upper_notebook.entry_general_maximal_size.set_text(&maximal_file_size);
|
2021-12-26 01:19:41 +13:00
|
|
|
|
|
|
|
//// Buttons
|
|
|
|
settings.check_button_settings_load_at_start.set_active(loading_at_start);
|
|
|
|
settings.check_button_settings_save_at_exit.set_active(saving_at_exit);
|
|
|
|
settings.check_button_settings_confirm_deletion.set_active(confirm_deletion);
|
|
|
|
settings.check_button_settings_confirm_group_deletion.set_active(confirm_group_deletion);
|
|
|
|
settings.check_button_settings_show_preview_similar_images.set_active(show_previews_similar_images);
|
|
|
|
settings.check_button_settings_show_preview_duplicates.set_active(show_previews_duplicates);
|
|
|
|
|
|
|
|
settings
|
|
|
|
.check_button_settings_similar_videos_delete_outdated_cache
|
|
|
|
.set_active(delete_outdated_cache_similar_videos);
|
|
|
|
settings
|
|
|
|
.check_button_settings_similar_images_delete_outdated_cache
|
|
|
|
.set_active(delete_outdated_cache_similar_images);
|
|
|
|
settings.check_button_settings_duplicates_delete_outdated_cache.set_active(delete_outdated_cache_duplicates);
|
|
|
|
|
|
|
|
settings.check_button_settings_show_text_view.set_active(bottom_text_panel);
|
|
|
|
if !bottom_text_panel {
|
|
|
|
scrolled_window_errors.hide();
|
|
|
|
} else {
|
|
|
|
scrolled_window_errors.show();
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
2021-12-26 01:19:41 +13:00
|
|
|
settings.check_button_settings_hide_hard_links.set_active(hide_hard_links);
|
|
|
|
settings.check_button_settings_use_cache.set_active(use_cache);
|
2022-01-06 10:47:27 +13:00
|
|
|
settings.check_button_settings_save_also_json.set_active(use_json_cache);
|
2021-12-26 01:19:41 +13:00
|
|
|
settings.check_button_duplicates_use_prehash_cache.set_active(use_prehash_cache);
|
|
|
|
settings.check_button_settings_use_trash.set_active(use_trash);
|
|
|
|
settings.entry_settings_cache_file_minimal_size.set_text(&cache_minimal_size);
|
|
|
|
settings.entry_settings_prehash_cache_file_minimal_size.set_text(&cache_prehash_minimal_size);
|
2022-07-20 05:09:52 +12:00
|
|
|
settings.check_button_settings_one_filesystem.set_active(ignore_other_fs);
|
2022-01-08 04:45:08 +13:00
|
|
|
|
|
|
|
save_proper_value_to_combo_box(&main_notebook.combo_box_duplicate_hash_type, combo_box_duplicate_hash_type);
|
|
|
|
save_proper_value_to_combo_box(&main_notebook.combo_box_duplicate_check_method, combo_box_duplicate_checking_method);
|
|
|
|
save_proper_value_to_combo_box(&main_notebook.combo_box_image_hash_algorithm, combo_box_image_hash_algorithm);
|
|
|
|
save_proper_value_to_combo_box(&main_notebook.combo_box_image_hash_size, combo_box_image_hash_size);
|
|
|
|
save_proper_value_to_combo_box(&main_notebook.combo_box_image_resize_algorithm, combo_box_image_resize_algorithm);
|
2022-06-05 07:20:21 +12:00
|
|
|
save_proper_value_to_combo_box(&main_notebook.combo_box_big_files_mode, combo_box_big_files_mode);
|
2022-01-16 07:02:27 +13:00
|
|
|
|
2022-04-10 21:59:41 +12:00
|
|
|
main_notebook.check_button_duplicate_case_sensitive_name.set_active(check_button_case_sensitive_name);
|
2022-01-16 07:02:27 +13:00
|
|
|
main_notebook.entry_big_files_number.set_text(&number_of_biggest_files);
|
|
|
|
main_notebook.check_button_image_ignore_same_size.set_active(similar_images_ignore_same_size);
|
|
|
|
main_notebook.check_button_video_ignore_same_size.set_active(similar_videos_ignore_same_size);
|
|
|
|
main_notebook.scale_similarity_similar_videos.set_value(similar_videos_similarity as f64);
|
|
|
|
|
2022-06-11 04:58:53 +12:00
|
|
|
main_notebook.check_button_broken_files_audio.set_active(check_button_broken_files_audio);
|
|
|
|
main_notebook.check_button_broken_files_pdf.set_active(check_button_broken_files_pdf);
|
|
|
|
main_notebook.check_button_broken_files_image.set_active(check_button_broken_files_image);
|
|
|
|
main_notebook.check_button_broken_files_archive.set_active(check_button_broken_files_archive);
|
|
|
|
|
2022-04-10 21:59:41 +12:00
|
|
|
{
|
|
|
|
let combo_chosen_index = main_notebook.combo_box_duplicate_check_method.active().unwrap();
|
|
|
|
|
|
|
|
if DUPLICATES_CHECK_METHOD_COMBO_BOX[combo_chosen_index as usize].check_method == CheckingMethod::Hash {
|
|
|
|
main_notebook.combo_box_duplicate_hash_type.set_visible(true);
|
|
|
|
main_notebook.label_duplicate_hash_type.set_visible(true);
|
|
|
|
} else {
|
|
|
|
main_notebook.combo_box_duplicate_hash_type.set_visible(false);
|
|
|
|
main_notebook.label_duplicate_hash_type.set_visible(false);
|
|
|
|
}
|
|
|
|
|
2023-04-05 18:08:43 +12:00
|
|
|
if [CheckingMethod::Name, CheckingMethod::SizeName].contains(&DUPLICATES_CHECK_METHOD_COMBO_BOX[combo_chosen_index as usize].check_method) {
|
2022-04-10 21:59:41 +12:00
|
|
|
main_notebook.check_button_duplicate_case_sensitive_name.set_visible(true);
|
|
|
|
} else {
|
|
|
|
main_notebook.check_button_duplicate_case_sensitive_name.set_visible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-16 07:02:27 +13:00
|
|
|
// Set size of similarity scale gtk node, must be set BEFORE setting value of this
|
|
|
|
let index = main_notebook.combo_box_image_hash_size.active().unwrap() as usize;
|
|
|
|
|
|
|
|
main_notebook.scale_similarity_similar_images.set_range(0_f64, SIMILAR_VALUES[index][5] as f64);
|
2022-01-20 07:30:16 +13:00
|
|
|
main_notebook.scale_similarity_similar_images.set_fill_level(SIMILAR_VALUES[index][5] as f64);
|
2022-11-26 08:38:27 +13:00
|
|
|
main_notebook.scale_similarity_similar_images.connect_change_value(scale_step_function);
|
2022-01-16 07:02:27 +13:00
|
|
|
main_notebook.scale_similarity_similar_images.set_value(similar_images_similarity as f64);
|
2022-11-26 08:38:27 +13:00
|
|
|
|
|
|
|
settings.scale_settings_number_of_threads.set_range(0_f64, get_default_number_of_threads() as f64);
|
|
|
|
settings.scale_settings_number_of_threads.set_fill_level(get_default_number_of_threads() as f64);
|
|
|
|
settings.scale_settings_number_of_threads.connect_change_value(scale_step_function);
|
|
|
|
settings.scale_settings_number_of_threads.set_value(thread_number as f64);
|
2020-12-08 03:25:44 +13:00
|
|
|
} else {
|
2021-12-26 01:19:41 +13:00
|
|
|
settings.check_button_settings_load_at_start.set_active(false);
|
|
|
|
}
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
|
|
|
|
2023-02-19 22:21:14 +13:00
|
|
|
fn set_directories(tree_view_included_directories: &TreeView, tree_view_excluded_directories: &TreeView, included_directories: &[String], excluded_directories: &[String]) {
|
|
|
|
// Include Directories
|
|
|
|
let list_store = get_list_store(tree_view_included_directories);
|
|
|
|
list_store.clear();
|
|
|
|
|
|
|
|
for directory in included_directories {
|
|
|
|
let values: [(u32, &dyn ToValue); 2] = [
|
|
|
|
(ColumnsIncludedDirectory::Path as u32, &directory),
|
|
|
|
(ColumnsIncludedDirectory::ReferenceButton as u32, &false),
|
|
|
|
];
|
|
|
|
list_store.set(&list_store.append(), &values);
|
|
|
|
}
|
|
|
|
|
|
|
|
//// Exclude Directories
|
|
|
|
let list_store = get_list_store(tree_view_excluded_directories);
|
|
|
|
list_store.clear();
|
|
|
|
|
|
|
|
for directory in excluded_directories {
|
|
|
|
let values: [(u32, &dyn ToValue); 1] = [(ColumnsExcludedDirectory::Path as u32, &directory)];
|
|
|
|
list_store.set(&list_store.append(), &values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-08 04:45:08 +13:00
|
|
|
fn save_proper_value_to_combo_box(combo_box: &ComboBoxText, what_to_save: u32) {
|
|
|
|
combo_box.set_active(Some(what_to_save));
|
|
|
|
if combo_box.active().is_none() {
|
|
|
|
combo_box.set_active(Some(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn reset_configuration(manual_clearing: bool, upper_notebook: &GuiUpperNotebook, main_notebook: &GuiMainNotebook, settings: &GuiSettings, text_view_errors: &TextView) {
|
2020-12-08 03:25:44 +13:00
|
|
|
// TODO Maybe add popup dialog to confirm resetting
|
2021-11-25 20:36:49 +13:00
|
|
|
let text_view_errors = text_view_errors.clone();
|
2020-12-19 22:03:04 +13:00
|
|
|
|
|
|
|
reset_text_view(&text_view_errors);
|
|
|
|
|
2020-12-08 03:25:44 +13:00
|
|
|
// Resetting included directories
|
|
|
|
{
|
2021-11-25 20:36:49 +13:00
|
|
|
let tree_view_included_directories = upper_notebook.tree_view_included_directories.clone();
|
2021-01-11 01:45:05 +13:00
|
|
|
let list_store = get_list_store(&tree_view_included_directories);
|
2020-12-08 03:25:44 +13:00
|
|
|
list_store.clear();
|
|
|
|
|
|
|
|
let current_dir: String = match env::current_dir() {
|
|
|
|
Ok(t) => t.to_str().unwrap().to_string(),
|
2021-11-15 03:53:55 +13:00
|
|
|
Err(_inspected) => {
|
2020-12-08 03:25:44 +13:00
|
|
|
if cfg!(target_family = "unix") {
|
2020-12-19 22:03:04 +13:00
|
|
|
add_text_to_text_view(&text_view_errors, "Failed to read current directory, setting /home instead");
|
2020-12-08 03:25:44 +13:00
|
|
|
"/home".to_string()
|
|
|
|
} else if cfg!(target_family = "windows") {
|
2020-12-19 22:03:04 +13:00
|
|
|
add_text_to_text_view(&text_view_errors, "Failed to read current directory, setting C:\\ instead");
|
2020-12-08 03:25:44 +13:00
|
|
|
"C:\\".to_string()
|
|
|
|
} else {
|
2023-01-29 06:54:02 +13:00
|
|
|
String::new()
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-12-24 21:18:55 +13:00
|
|
|
let values: [(u32, &dyn ToValue); 2] = [
|
|
|
|
(ColumnsIncludedDirectory::Path as u32, ¤t_dir),
|
|
|
|
(ColumnsIncludedDirectory::ReferenceButton as u32, &false),
|
|
|
|
];
|
2021-06-26 04:07:13 +12:00
|
|
|
list_store.set(&list_store.append(), &values);
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
|
|
|
// Resetting excluded directories
|
|
|
|
{
|
2021-11-25 20:36:49 +13:00
|
|
|
let tree_view_excluded_directories = upper_notebook.tree_view_excluded_directories.clone();
|
2021-01-11 01:45:05 +13:00
|
|
|
let list_store = get_list_store(&tree_view_excluded_directories);
|
2020-12-08 03:25:44 +13:00
|
|
|
list_store.clear();
|
2023-10-05 19:06:47 +13:00
|
|
|
for i in DEFAULT_EXCLUDED_DIRECTORIES {
|
2022-01-08 04:45:08 +13:00
|
|
|
let values: [(u32, &dyn ToValue); 1] = [(ColumnsExcludedDirectory::Path as u32, &i)];
|
|
|
|
list_store.set(&list_store.append(), &values);
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Resetting excluded items
|
|
|
|
{
|
2022-01-08 04:45:08 +13:00
|
|
|
upper_notebook.entry_excluded_items.set_text(DEFAULT_EXCLUDED_ITEMS);
|
|
|
|
upper_notebook.entry_allowed_extensions.set_text("");
|
2022-01-16 07:02:27 +13:00
|
|
|
upper_notebook.entry_general_minimal_size.set_text(DEFAULT_MINIMAL_FILE_SIZE);
|
|
|
|
upper_notebook.entry_general_maximal_size.set_text(DEFAULT_MAXIMAL_FILE_SIZE);
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
|
|
|
|
2021-12-01 00:45:09 +13:00
|
|
|
// Set default settings
|
2020-12-08 03:25:44 +13:00
|
|
|
{
|
2021-12-26 01:19:41 +13:00
|
|
|
settings.check_button_settings_save_at_exit.set_active(DEFAULT_SAVE_ON_EXIT);
|
|
|
|
settings.check_button_settings_load_at_start.set_active(DEFAULT_LOAD_AT_START);
|
|
|
|
settings.check_button_settings_confirm_deletion.set_active(DEFAULT_CONFIRM_DELETION);
|
|
|
|
settings.check_button_settings_confirm_group_deletion.set_active(DEFAULT_CONFIRM_GROUP_DELETION);
|
|
|
|
settings.check_button_settings_show_preview_similar_images.set_active(DEFAULT_SHOW_IMAGE_PREVIEW);
|
|
|
|
settings.check_button_settings_show_preview_duplicates.set_active(DEFAULT_SHOW_DUPLICATE_IMAGE_PREVIEW);
|
|
|
|
settings.check_button_settings_show_text_view.set_active(DEFAULT_BOTTOM_TEXT_VIEW);
|
|
|
|
settings.check_button_settings_hide_hard_links.set_active(DEFAULT_HIDE_HARD_LINKS);
|
|
|
|
settings.check_button_settings_use_cache.set_active(DEFAULT_USE_CACHE);
|
2022-01-06 10:47:27 +13:00
|
|
|
settings.check_button_settings_save_also_json.set_active(DEFAULT_SAVE_ALSO_AS_JSON);
|
2021-12-26 01:19:41 +13:00
|
|
|
settings.check_button_settings_use_trash.set_active(DEFAULT_USE_TRASH);
|
|
|
|
settings.entry_settings_cache_file_minimal_size.set_text(DEFAULT_MINIMAL_CACHE_SIZE);
|
|
|
|
settings
|
|
|
|
.check_button_settings_similar_videos_delete_outdated_cache
|
|
|
|
.set_active(DEFAULT_VIDEO_REMOVE_AUTO_OUTDATED_CACHE);
|
|
|
|
settings
|
|
|
|
.check_button_settings_similar_images_delete_outdated_cache
|
|
|
|
.set_active(DEFAULT_IMAGE_REMOVE_AUTO_OUTDATED_CACHE);
|
|
|
|
settings
|
|
|
|
.check_button_settings_duplicates_delete_outdated_cache
|
|
|
|
.set_active(DEFAULT_DUPLICATE_REMOVE_AUTO_OUTDATED_CACHE);
|
|
|
|
settings.check_button_duplicates_use_prehash_cache.set_active(DEFAULT_USE_PRECACHE);
|
|
|
|
settings.entry_settings_prehash_cache_file_minimal_size.set_text(DEFAULT_PREHASH_MINIMAL_CACHE_SIZE);
|
2021-12-12 04:16:14 +13:00
|
|
|
settings.combo_box_settings_language.set_active(Some(0));
|
2022-07-20 05:09:52 +12:00
|
|
|
settings.check_button_settings_one_filesystem.set_active(DEFAULT_GENERAL_IGNORE_OTHER_FILESYSTEMS);
|
2022-01-08 04:45:08 +13:00
|
|
|
|
|
|
|
main_notebook.combo_box_duplicate_hash_type.set_active(Some(0));
|
|
|
|
main_notebook.combo_box_duplicate_check_method.set_active(Some(0));
|
|
|
|
main_notebook.combo_box_image_hash_algorithm.set_active(Some(0));
|
2022-07-27 08:20:28 +12:00
|
|
|
main_notebook.combo_box_image_resize_algorithm.set_active(Some(1)); // Nearest by default
|
2022-07-06 05:58:57 +12:00
|
|
|
main_notebook.combo_box_image_hash_size.set_active(Some(1)); // Set as 16 instead 8
|
2022-06-05 07:20:21 +12:00
|
|
|
main_notebook.combo_box_big_files_mode.set_active(Some(0));
|
2022-01-16 07:02:27 +13:00
|
|
|
|
2022-06-11 04:58:53 +12:00
|
|
|
main_notebook.check_button_broken_files_audio.set_active(DEFAULT_BROKEN_FILES_AUDIO);
|
|
|
|
main_notebook.check_button_broken_files_pdf.set_active(DEFAULT_BROKEN_FILES_PDF);
|
|
|
|
main_notebook.check_button_broken_files_archive.set_active(DEFAULT_BROKEN_FILES_ARCHIVE);
|
|
|
|
main_notebook.check_button_broken_files_image.set_active(DEFAULT_BROKEN_FILES_IMAGE);
|
|
|
|
|
2022-01-16 07:02:27 +13:00
|
|
|
main_notebook.scale_similarity_similar_images.set_range(0_f64, SIMILAR_VALUES[0][5] as f64); // DEFAULT FOR MAX of 8
|
2022-01-20 07:30:16 +13:00
|
|
|
main_notebook.scale_similarity_similar_images.set_fill_level(SIMILAR_VALUES[0][5] as f64);
|
2022-01-16 07:02:27 +13:00
|
|
|
|
|
|
|
main_notebook.entry_big_files_number.set_text(DEFAULT_NUMBER_OF_BIGGEST_FILES);
|
|
|
|
main_notebook.scale_similarity_similar_images.set_value(DEFAULT_SIMILAR_IMAGES_SIMILARITY as f64);
|
|
|
|
main_notebook.check_button_image_ignore_same_size.set_active(DEFAULT_SIMILAR_IMAGES_IGNORE_SAME_SIZE);
|
|
|
|
main_notebook.check_button_video_ignore_same_size.set_active(DEFAULT_SIMILAR_VIDEOS_IGNORE_SAME_SIZE);
|
|
|
|
main_notebook.scale_similarity_similar_videos.set_value(DEFAULT_SIMILAR_VIDEOS_SIMILARITY as f64);
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
|
|
|
if manual_clearing {
|
2022-01-20 10:35:07 +13:00
|
|
|
add_text_to_text_view(&text_view_errors, &flg!("saving_loading_reset_configuration"));
|
2020-12-08 03:25:44 +13:00
|
|
|
}
|
|
|
|
}
|