parent
fcc909ffd7
commit
581e8cf83f
|
@ -5,6 +5,7 @@ use crate::notebook_enums::*;
|
||||||
use czkawka_core::duplicate::make_hard_link;
|
use czkawka_core::duplicate::make_hard_link;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{TreeIter, TreePath};
|
use gtk::{TreeIter, TreePath};
|
||||||
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub fn connect_button_hardlink(gui_data: &GuiData) {
|
pub fn connect_button_hardlink(gui_data: &GuiData) {
|
||||||
|
@ -21,17 +22,35 @@ pub fn connect_button_hardlink(gui_data: &GuiData) {
|
||||||
|
|
||||||
buttons_hardlink.connect_clicked(move |_| match to_notebook_main_enum(notebook_main.current_page().unwrap()) {
|
buttons_hardlink.connect_clicked(move |_| match to_notebook_main_enum(notebook_main.current_page().unwrap()) {
|
||||||
NotebookMainEnum::Duplicate => {
|
NotebookMainEnum::Duplicate => {
|
||||||
hardlink(tree_view_duplicate_finder.clone(), ColumnsDuplicates::Name as i32, ColumnsDuplicates::Path as i32, ColumnsDuplicates::Color as i32, &gui_data);
|
hardlink_symlink(
|
||||||
|
tree_view_duplicate_finder.clone(),
|
||||||
|
ColumnsDuplicates::Name as i32,
|
||||||
|
ColumnsDuplicates::Path as i32,
|
||||||
|
ColumnsDuplicates::Color as i32,
|
||||||
|
ColumnsDuplicates::ActiveSelectButton as i32,
|
||||||
|
true,
|
||||||
|
&gui_data,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
NotebookMainEnum::SameMusic => {
|
NotebookMainEnum::SameMusic => {
|
||||||
hardlink(tree_view_same_music_finder.clone(), ColumnsSameMusic::Name as i32, ColumnsSameMusic::Path as i32, ColumnsSameMusic::Color as i32, &gui_data);
|
hardlink_symlink(
|
||||||
|
tree_view_same_music_finder.clone(),
|
||||||
|
ColumnsSameMusic::Name as i32,
|
||||||
|
ColumnsSameMusic::Path as i32,
|
||||||
|
ColumnsSameMusic::Color as i32,
|
||||||
|
ColumnsSameMusic::ActiveSelectButton as i32,
|
||||||
|
true,
|
||||||
|
&gui_data,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
NotebookMainEnum::SimilarImages => {
|
NotebookMainEnum::SimilarImages => {
|
||||||
hardlink(
|
hardlink_symlink(
|
||||||
tree_view_similar_images_finder.clone(),
|
tree_view_similar_images_finder.clone(),
|
||||||
ColumnsSimilarImages::Name as i32,
|
ColumnsSimilarImages::Name as i32,
|
||||||
ColumnsSimilarImages::Path as i32,
|
ColumnsSimilarImages::Path as i32,
|
||||||
ColumnsSimilarImages::Color as i32,
|
ColumnsSimilarImages::Color as i32,
|
||||||
|
ColumnsSimilarImages::ActiveSelectButton as i32,
|
||||||
|
true,
|
||||||
&gui_data,
|
&gui_data,
|
||||||
);
|
);
|
||||||
image_preview_similar_images.hide();
|
image_preview_similar_images.hide();
|
||||||
|
@ -39,159 +58,208 @@ pub fn connect_button_hardlink(gui_data: &GuiData) {
|
||||||
e => panic!("Not existent {:?}", e),
|
e => panic!("Not existent {:?}", e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
fn hardlink(tree_view: gtk::TreeView, column_file_name: i32, column_path: i32, column_color: i32, gui_data: &GuiData) {
|
|
||||||
|
pub fn hardlink_symlink(tree_view: gtk::TreeView, column_file_name: i32, column_path: i32, column_color: i32, column_selection: i32, hardlinking: bool, gui_data: &GuiData) {
|
||||||
let text_view_errors = gui_data.text_view_errors.clone();
|
let text_view_errors = gui_data.text_view_errors.clone();
|
||||||
reset_text_view(&text_view_errors);
|
reset_text_view(&text_view_errors);
|
||||||
|
|
||||||
let list_store = get_list_store(&tree_view);
|
let model = get_list_store(&tree_view);
|
||||||
let selection = tree_view.selection();
|
|
||||||
|
|
||||||
let (selection_rows, tree_model) = selection.selected_rows();
|
#[derive(Debug)]
|
||||||
if selection_rows.is_empty() {
|
struct SymHardlinkData {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct HardlinkData {
|
|
||||||
original_data: String,
|
original_data: String,
|
||||||
files_to_hardlink: Vec<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_tree_path_to_remove: Vec<TreePath> = Vec::new(); // List of hardlinked files without its root
|
||||||
let mut vec_hardlink_data: Vec<HardlinkData> = Vec::new();
|
let mut vec_symhardlink_data: Vec<SymHardlinkData> = Vec::new();
|
||||||
|
|
||||||
let current_iter: TreeIter = tree_model.iter_first().unwrap(); // Hardlink button should be only visible when more than 1 element is visible, otherwise it needs to be fixed
|
let current_iter: TreeIter = match model.iter_first() {
|
||||||
let mut current_hardlink_data: Option<HardlinkData> = None;
|
Some(t) => t,
|
||||||
|
None => return, // No records
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut selected_rows = Vec::new();
|
||||||
|
if let Some(iter) = model.iter_first() {
|
||||||
|
loop {
|
||||||
|
if model.value(&iter, column_color).get::<String>().unwrap() == MAIN_ROW_COLOR && model.value(&iter, column_selection).get::<bool>().unwrap() {
|
||||||
|
selected_rows.push(model.path(&iter).unwrap());
|
||||||
|
}
|
||||||
|
if !model.iter_next(&iter) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut current_symhardlink_data: Option<SymHardlinkData> = None;
|
||||||
let mut current_selected_index = 0;
|
let mut current_selected_index = 0;
|
||||||
loop {
|
loop {
|
||||||
if tree_model.value(¤t_iter, column_color).get::<String>().unwrap() == HEADER_ROW_COLOR {
|
if model.value(¤t_iter, column_color).get::<String>().unwrap() == HEADER_ROW_COLOR {
|
||||||
if let Some(current_hardlink_data) = current_hardlink_data {
|
if let Some(current_symhardlink_data) = current_symhardlink_data {
|
||||||
if !current_hardlink_data.files_to_hardlink.is_empty() {
|
if !current_symhardlink_data.files_to_symhardlink.is_empty() {
|
||||||
vec_hardlink_data.push(current_hardlink_data);
|
vec_symhardlink_data.push(current_symhardlink_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
current_hardlink_data = None;
|
current_symhardlink_data = None;
|
||||||
if !tree_model.iter_next(¤t_iter) {
|
if !model.iter_next(¤t_iter) {
|
||||||
panic!("HEADER, shouldn't be a last item.");
|
panic!("HEADER, shouldn't be a last item.");
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if tree_model.path(¤t_iter).unwrap() == selection_rows[current_selected_index] {
|
if model.path(¤t_iter).unwrap() == selected_rows[current_selected_index] {
|
||||||
let file_name = tree_model.value(¤t_iter, column_file_name).get::<String>().unwrap();
|
let file_name = model.value(¤t_iter, column_file_name).get::<String>().unwrap();
|
||||||
let path = tree_model.value(¤t_iter, column_path).get::<String>().unwrap();
|
let path = model.value(¤t_iter, column_path).get::<String>().unwrap();
|
||||||
let full_file_path = format!("{}/{}", path, file_name);
|
let full_file_path = format!("{}/{}", path, file_name);
|
||||||
|
|
||||||
if current_hardlink_data.is_some() {
|
if current_symhardlink_data.is_some() {
|
||||||
vec_tree_path_to_remove.push(tree_model.path(¤t_iter).unwrap());
|
vec_tree_path_to_remove.push(model.path(¤t_iter).unwrap());
|
||||||
let mut temp_data = current_hardlink_data.unwrap();
|
let mut temp_data = current_symhardlink_data.unwrap();
|
||||||
temp_data.files_to_hardlink.push(full_file_path);
|
temp_data.files_to_symhardlink.push(full_file_path);
|
||||||
current_hardlink_data = Some(temp_data);
|
current_symhardlink_data = Some(temp_data);
|
||||||
} else {
|
} else {
|
||||||
current_hardlink_data = Some(HardlinkData {
|
current_symhardlink_data = Some(SymHardlinkData {
|
||||||
original_data: full_file_path,
|
original_data: full_file_path,
|
||||||
files_to_hardlink: vec![],
|
files_to_symhardlink: vec![],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if current_selected_index != selection_rows.len() - 1 {
|
if current_selected_index != selected_rows.len() - 1 {
|
||||||
current_selected_index += 1;
|
current_selected_index += 1;
|
||||||
} else {
|
} else {
|
||||||
if let Some(current_hardlink_data) = current_hardlink_data {
|
if let Some(current_symhardlink_data) = current_symhardlink_data {
|
||||||
if !current_hardlink_data.files_to_hardlink.is_empty() {
|
if !current_symhardlink_data.files_to_symhardlink.is_empty() {
|
||||||
vec_hardlink_data.push(current_hardlink_data);
|
vec_symhardlink_data.push(current_symhardlink_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break; // There is no more selected items, so we just end checking
|
break; // There is no more selected items, so we just end checking
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !tree_model.iter_next(¤t_iter) {
|
if !model.iter_next(¤t_iter) {
|
||||||
if let Some(current_hardlink_data) = current_hardlink_data {
|
if let Some(current_symhardlink_data) = current_symhardlink_data {
|
||||||
if !current_hardlink_data.files_to_hardlink.is_empty() {
|
if !current_symhardlink_data.files_to_symhardlink.is_empty() {
|
||||||
vec_hardlink_data.push(current_hardlink_data);
|
vec_symhardlink_data.push(current_symhardlink_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for hardlink_data in vec_hardlink_data {
|
if hardlinking {
|
||||||
for file_to_hardlink in hardlink_data.files_to_hardlink {
|
dbg!(&vec_symhardlink_data);
|
||||||
match make_hard_link(&PathBuf::from(&hardlink_data.original_data), &PathBuf::from(&file_to_hardlink)) {
|
for symhardlink_data in vec_symhardlink_data {
|
||||||
Ok(_) => (),
|
dbg!(&symhardlink_data);
|
||||||
Err(_) => {
|
for file_to_hardlink in symhardlink_data.files_to_symhardlink {
|
||||||
add_text_to_text_view(&text_view_errors, format!("Failed to hardlink {}.", file_to_hardlink).as_str());
|
match make_hard_link(&PathBuf::from(&symhardlink_data.original_data), &PathBuf::from(&file_to_hardlink)) {
|
||||||
continue;
|
Ok(_) => (),
|
||||||
|
Err(_) => {
|
||||||
|
add_text_to_text_view(&text_view_errors, format!("Failed to hardlink {}.", file_to_hardlink).as_str());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for symhardlink_data in vec_symhardlink_data {
|
||||||
|
for file_to_symlink in symhardlink_data.files_to_symhardlink {
|
||||||
|
match fs::remove_file(&file_to_symlink) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(_) => {
|
||||||
|
add_text_to_text_view(&text_view_errors, format!("Failed to remove file {} when creating symlink.", file_to_symlink).as_str());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
{
|
||||||
|
match std::os::unix::fs::symlink(&symhardlink_data.original_data, &file_to_symlink) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(_) => {
|
||||||
|
add_text_to_text_view(&text_view_errors, format!("Failed to remove file {} when creating symlink.", file_to_symlink).as_str());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// TODO Add this, because for now it not working ()
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
|
{
|
||||||
|
match std::os::windows::fs::symlink_file(&symhardlink_data.original_data, &file_to_symlink) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(_) => {
|
||||||
|
add_text_to_text_view(&text_view_errors, format!("Failed to remove file {} when creating symlink.", file_to_symlink).as_str());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!();
|
||||||
}
|
}
|
||||||
println!();
|
|
||||||
}
|
}
|
||||||
for tree_path in vec_tree_path_to_remove.iter().rev() {
|
for tree_path in vec_tree_path_to_remove.iter().rev() {
|
||||||
list_store.remove(&tree_model.iter(tree_path).unwrap());
|
model.remove(&model.iter(tree_path).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove only child from header
|
// Remove only child from header
|
||||||
if let Some(first_iter) = list_store.iter_first() {
|
if let Some(first_iter) = model.iter_first() {
|
||||||
let mut vec_tree_path_to_delete: Vec<gtk::TreePath> = Vec::new();
|
let mut vec_tree_path_to_delete: Vec<gtk::TreePath> = Vec::new();
|
||||||
let mut current_iter = first_iter;
|
let mut current_iter = first_iter;
|
||||||
if tree_model.value(¤t_iter, column_color).get::<String>().unwrap() != HEADER_ROW_COLOR {
|
if model.value(¤t_iter, column_color).get::<String>().unwrap() != HEADER_ROW_COLOR {
|
||||||
panic!(); // First element should be header
|
panic!(); // First element should be header
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut next_iter;
|
let mut next_iter;
|
||||||
let mut next_next_iter;
|
let mut next_next_iter;
|
||||||
'main: loop {
|
'main: loop {
|
||||||
if tree_model.value(¤t_iter, column_color).get::<String>().unwrap() != HEADER_ROW_COLOR {
|
if model.value(¤t_iter, column_color).get::<String>().unwrap() != HEADER_ROW_COLOR {
|
||||||
panic!(); // First element should be header
|
panic!(); // First element should be header
|
||||||
};
|
};
|
||||||
|
|
||||||
next_iter = current_iter.clone();
|
next_iter = current_iter.clone();
|
||||||
if !list_store.iter_next(&next_iter) {
|
if !model.iter_next(&next_iter) {
|
||||||
// There is only single header left (H1 -> END) -> (NOTHING)
|
// There is only single header left (H1 -> END) -> (NOTHING)
|
||||||
vec_tree_path_to_delete.push(list_store.path(¤t_iter).unwrap());
|
vec_tree_path_to_delete.push(model.path(¤t_iter).unwrap());
|
||||||
break 'main;
|
break 'main;
|
||||||
}
|
}
|
||||||
|
|
||||||
if tree_model.value(&next_iter, column_color).get::<String>().unwrap() == HEADER_ROW_COLOR {
|
if model.value(&next_iter, column_color).get::<String>().unwrap() == HEADER_ROW_COLOR {
|
||||||
// There are two headers each others(we remove just first) -> (H1 -> H2) -> (H2)
|
// There are two headers each others(we remove just first) -> (H1 -> H2) -> (H2)
|
||||||
vec_tree_path_to_delete.push(list_store.path(¤t_iter).unwrap());
|
vec_tree_path_to_delete.push(model.path(¤t_iter).unwrap());
|
||||||
current_iter = next_iter.clone();
|
current_iter = next_iter.clone();
|
||||||
continue 'main;
|
continue 'main;
|
||||||
}
|
}
|
||||||
|
|
||||||
next_next_iter = next_iter.clone();
|
next_next_iter = next_iter.clone();
|
||||||
if !list_store.iter_next(&next_next_iter) {
|
if !model.iter_next(&next_next_iter) {
|
||||||
// There is only one child of header left, so we remove it with header (H1 -> C1 -> END) -> (NOTHING)
|
// There is only one child of header left, so we remove it with header (H1 -> C1 -> END) -> (NOTHING)
|
||||||
vec_tree_path_to_delete.push(list_store.path(¤t_iter).unwrap());
|
vec_tree_path_to_delete.push(model.path(¤t_iter).unwrap());
|
||||||
vec_tree_path_to_delete.push(list_store.path(&next_iter).unwrap());
|
vec_tree_path_to_delete.push(model.path(&next_iter).unwrap());
|
||||||
break 'main;
|
break 'main;
|
||||||
}
|
}
|
||||||
|
|
||||||
if tree_model.value(&next_next_iter, column_color).get::<String>().unwrap() == HEADER_ROW_COLOR {
|
if model.value(&next_next_iter, column_color).get::<String>().unwrap() == HEADER_ROW_COLOR {
|
||||||
// One child between two headers, we can remove them (H1 -> C1 -> H2) -> (H2)
|
// One child between two headers, we can remove them (H1 -> C1 -> H2) -> (H2)
|
||||||
vec_tree_path_to_delete.push(list_store.path(¤t_iter).unwrap());
|
vec_tree_path_to_delete.push(model.path(¤t_iter).unwrap());
|
||||||
vec_tree_path_to_delete.push(list_store.path(&next_iter).unwrap());
|
vec_tree_path_to_delete.push(model.path(&next_iter).unwrap());
|
||||||
current_iter = next_next_iter.clone();
|
current_iter = next_next_iter.clone();
|
||||||
continue 'main;
|
continue 'main;
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// (H1 -> C1 -> C2 -> Cn -> END) -> (NO CHANGE, BECAUSE IS GOOD)
|
// (H1 -> C1 -> C2 -> Cn -> END) -> (NO CHANGE, BECAUSE IS GOOD)
|
||||||
if !list_store.iter_next(&next_next_iter) {
|
if !model.iter_next(&next_next_iter) {
|
||||||
break 'main;
|
break 'main;
|
||||||
}
|
}
|
||||||
// Move to next header
|
// Move to next header
|
||||||
if tree_model.value(&next_next_iter, column_color).get::<String>().unwrap() == HEADER_ROW_COLOR {
|
if model.value(&next_next_iter, column_color).get::<String>().unwrap() == HEADER_ROW_COLOR {
|
||||||
current_iter = next_next_iter.clone();
|
current_iter = next_next_iter.clone();
|
||||||
continue 'main;
|
continue 'main;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for tree_path in vec_tree_path_to_delete.iter().rev() {
|
for tree_path in vec_tree_path_to_delete.iter().rev() {
|
||||||
list_store.remove(&list_store.iter(tree_path).unwrap());
|
model.remove(&model.iter(tree_path).unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selection.unselect_all();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
extern crate gtk;
|
extern crate gtk;
|
||||||
|
use crate::connect_button_hardlink::hardlink_symlink;
|
||||||
use crate::gui_data::GuiData;
|
use crate::gui_data::GuiData;
|
||||||
use crate::help_functions::*;
|
use crate::help_functions::*;
|
||||||
use crate::notebook_enums::*;
|
use crate::notebook_enums::*;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{TreeIter, TreePath};
|
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
pub fn connect_button_symlink(gui_data: &GuiData) {
|
pub fn connect_button_symlink(gui_data: &GuiData) {
|
||||||
let gui_data = gui_data.clone();
|
let gui_data = gui_data.clone();
|
||||||
|
@ -17,20 +16,40 @@ pub fn connect_button_symlink(gui_data: &GuiData) {
|
||||||
let tree_view_same_music_finder = gui_data.main_notebook.tree_view_same_music_finder.clone();
|
let tree_view_same_music_finder = gui_data.main_notebook.tree_view_same_music_finder.clone();
|
||||||
|
|
||||||
let image_preview_similar_images = gui_data.main_notebook.image_preview_similar_images.clone();
|
let image_preview_similar_images = gui_data.main_notebook.image_preview_similar_images.clone();
|
||||||
|
let image_preview_duplicates = gui_data.main_notebook.image_preview_duplicates.clone();
|
||||||
|
|
||||||
buttons_symlink.connect_clicked(move |_| match to_notebook_main_enum(notebook_main.current_page().unwrap()) {
|
buttons_symlink.connect_clicked(move |_| match to_notebook_main_enum(notebook_main.current_page().unwrap()) {
|
||||||
NotebookMainEnum::Duplicate => {
|
NotebookMainEnum::Duplicate => {
|
||||||
symlink(tree_view_duplicate_finder.clone(), ColumnsDuplicates::Name as i32, ColumnsDuplicates::Path as i32, ColumnsDuplicates::Color as i32, &gui_data);
|
hardlink_symlink(
|
||||||
|
tree_view_duplicate_finder.clone(),
|
||||||
|
ColumnsDuplicates::Name as i32,
|
||||||
|
ColumnsDuplicates::Path as i32,
|
||||||
|
ColumnsDuplicates::Color as i32,
|
||||||
|
ColumnsDuplicates::ActiveSelectButton as i32,
|
||||||
|
false,
|
||||||
|
&gui_data,
|
||||||
|
);
|
||||||
|
image_preview_duplicates.hide();
|
||||||
}
|
}
|
||||||
NotebookMainEnum::SameMusic => {
|
NotebookMainEnum::SameMusic => {
|
||||||
symlink(tree_view_same_music_finder.clone(), ColumnsSameMusic::Name as i32, ColumnsSameMusic::Path as i32, ColumnsSameMusic::Color as i32, &gui_data);
|
hardlink_symlink(
|
||||||
|
tree_view_same_music_finder.clone(),
|
||||||
|
ColumnsSameMusic::Name as i32,
|
||||||
|
ColumnsSameMusic::Path as i32,
|
||||||
|
ColumnsSameMusic::Color as i32,
|
||||||
|
ColumnsSameMusic::ActiveSelectButton as i32,
|
||||||
|
false,
|
||||||
|
&gui_data,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
NotebookMainEnum::SimilarImages => {
|
NotebookMainEnum::SimilarImages => {
|
||||||
symlink(
|
hardlink_symlink(
|
||||||
tree_view_similar_images_finder.clone(),
|
tree_view_similar_images_finder.clone(),
|
||||||
ColumnsSimilarImages::Name as i32,
|
ColumnsSimilarImages::Name as i32,
|
||||||
ColumnsSimilarImages::Path as i32,
|
ColumnsSimilarImages::Path as i32,
|
||||||
ColumnsSimilarImages::Color as i32,
|
ColumnsSimilarImages::Color as i32,
|
||||||
|
ColumnsSimilarImages::ActiveSelectButton as i32,
|
||||||
|
false,
|
||||||
&gui_data,
|
&gui_data,
|
||||||
);
|
);
|
||||||
image_preview_similar_images.hide();
|
image_preview_similar_images.hide();
|
||||||
|
@ -38,181 +57,3 @@ pub fn connect_button_symlink(gui_data: &GuiData) {
|
||||||
e => panic!("Not existent {:?}", e),
|
e => panic!("Not existent {:?}", e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
fn symlink(tree_view: gtk::TreeView, column_file_name: i32, column_path: i32, column_color: i32, gui_data: &GuiData) {
|
|
||||||
let text_view_errors = gui_data.text_view_errors.clone();
|
|
||||||
reset_text_view(&text_view_errors);
|
|
||||||
|
|
||||||
let list_store = get_list_store(&tree_view);
|
|
||||||
let selection = tree_view.selection();
|
|
||||||
|
|
||||||
let (selection_rows, tree_model) = selection.selected_rows();
|
|
||||||
if selection_rows.is_empty() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SymlinkData {
|
|
||||||
original_data: String,
|
|
||||||
files_to_symlink: Vec<String>,
|
|
||||||
}
|
|
||||||
let mut vec_tree_path_to_remove: Vec<TreePath> = Vec::new(); // List of symlinked files without its root
|
|
||||||
let mut vec_symlink_data: Vec<SymlinkData> = Vec::new();
|
|
||||||
|
|
||||||
let current_iter: TreeIter = tree_model.iter_first().unwrap(); // Symlink button should be only visible when more than 1 element is visible, otherwise it needs to be fixed
|
|
||||||
let mut current_symlink_data: Option<SymlinkData> = None;
|
|
||||||
let mut current_selected_index = 0;
|
|
||||||
loop {
|
|
||||||
if tree_model.value(¤t_iter, column_color).get::<String>().unwrap() == HEADER_ROW_COLOR {
|
|
||||||
if let Some(current_symlink_data) = current_symlink_data {
|
|
||||||
if !current_symlink_data.files_to_symlink.is_empty() {
|
|
||||||
vec_symlink_data.push(current_symlink_data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
current_symlink_data = None;
|
|
||||||
if !tree_model.iter_next(¤t_iter) {
|
|
||||||
panic!("HEADER, shouldn't be a last item.");
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if tree_model.path(¤t_iter).unwrap() == selection_rows[current_selected_index] {
|
|
||||||
let file_name = tree_model.value(¤t_iter, column_file_name).get::<String>().unwrap();
|
|
||||||
let path = tree_model.value(¤t_iter, column_path).get::<String>().unwrap();
|
|
||||||
let full_file_path = format!("{}/{}", path, file_name);
|
|
||||||
|
|
||||||
if current_symlink_data.is_some() {
|
|
||||||
vec_tree_path_to_remove.push(tree_model.path(¤t_iter).unwrap());
|
|
||||||
let mut temp_data = current_symlink_data.unwrap();
|
|
||||||
temp_data.files_to_symlink.push(full_file_path);
|
|
||||||
current_symlink_data = Some(temp_data);
|
|
||||||
} else {
|
|
||||||
current_symlink_data = Some(SymlinkData {
|
|
||||||
original_data: full_file_path,
|
|
||||||
files_to_symlink: vec![],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if current_selected_index != selection_rows.len() - 1 {
|
|
||||||
current_selected_index += 1;
|
|
||||||
} else {
|
|
||||||
if let Some(current_symlink_data) = current_symlink_data {
|
|
||||||
if !current_symlink_data.files_to_symlink.is_empty() {
|
|
||||||
vec_symlink_data.push(current_symlink_data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break; // There is no more selected items, so we just end checking
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !tree_model.iter_next(¤t_iter) {
|
|
||||||
if let Some(current_symlink_data) = current_symlink_data {
|
|
||||||
if !current_symlink_data.files_to_symlink.is_empty() {
|
|
||||||
vec_symlink_data.push(current_symlink_data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for symlink_data in vec_symlink_data {
|
|
||||||
for file_to_symlink in symlink_data.files_to_symlink {
|
|
||||||
match fs::remove_file(&file_to_symlink) {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(_) => {
|
|
||||||
add_text_to_text_view(&text_view_errors, format!("Failed to remove file {} when creating symlink.", file_to_symlink).as_str());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(target_family = "unix")]
|
|
||||||
{
|
|
||||||
match std::os::unix::fs::symlink(&symlink_data.original_data, &file_to_symlink) {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(_) => {
|
|
||||||
add_text_to_text_view(&text_view_errors, format!("Failed to remove file {} when creating symlink.", file_to_symlink).as_str());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// TODO Add this, because for now it not working ()
|
|
||||||
// #[cfg(target_family = "windows")]
|
|
||||||
// {
|
|
||||||
// match std::os::windows::fs::symlink(&symlink_data.original_data, &file_to_symlink) {
|
|
||||||
// Ok(_) => (),
|
|
||||||
// Err(_) => {
|
|
||||||
// add_text_to_text_view(&text_view_errors, format!("Failed to remove file {} when creating symlink.", file_to_symlink).as_str());
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
println!();
|
|
||||||
}
|
|
||||||
for tree_path in vec_tree_path_to_remove.iter().rev() {
|
|
||||||
list_store.remove(&tree_model.iter(tree_path).unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove only child from header
|
|
||||||
if let Some(first_iter) = list_store.iter_first() {
|
|
||||||
let mut vec_tree_path_to_delete: Vec<gtk::TreePath> = Vec::new();
|
|
||||||
let mut current_iter = first_iter;
|
|
||||||
if tree_model.value(¤t_iter, column_color).get::<String>().unwrap() != HEADER_ROW_COLOR {
|
|
||||||
panic!(); // First element should be header
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut next_iter;
|
|
||||||
let mut next_next_iter;
|
|
||||||
'main: loop {
|
|
||||||
if tree_model.value(¤t_iter, column_color).get::<String>().unwrap() != HEADER_ROW_COLOR {
|
|
||||||
panic!(); // First element should be header
|
|
||||||
};
|
|
||||||
|
|
||||||
next_iter = current_iter.clone();
|
|
||||||
if !list_store.iter_next(&next_iter) {
|
|
||||||
// There is only single header left (H1 -> END) -> (NOTHING)
|
|
||||||
vec_tree_path_to_delete.push(list_store.path(¤t_iter).unwrap());
|
|
||||||
break 'main;
|
|
||||||
}
|
|
||||||
|
|
||||||
if tree_model.value(&next_iter, column_color).get::<String>().unwrap() == HEADER_ROW_COLOR {
|
|
||||||
// There are two headers each others(we remove just first) -> (H1 -> H2) -> (H2)
|
|
||||||
vec_tree_path_to_delete.push(list_store.path(¤t_iter).unwrap());
|
|
||||||
current_iter = next_iter.clone();
|
|
||||||
continue 'main;
|
|
||||||
}
|
|
||||||
|
|
||||||
next_next_iter = next_iter.clone();
|
|
||||||
if !list_store.iter_next(&next_next_iter) {
|
|
||||||
// There is only one child of header left, so we remove it with header (H1 -> C1 -> END) -> (NOTHING)
|
|
||||||
vec_tree_path_to_delete.push(list_store.path(¤t_iter).unwrap());
|
|
||||||
vec_tree_path_to_delete.push(list_store.path(&next_iter).unwrap());
|
|
||||||
break 'main;
|
|
||||||
}
|
|
||||||
|
|
||||||
if tree_model.value(&next_next_iter, column_color).get::<String>().unwrap() == HEADER_ROW_COLOR {
|
|
||||||
// One child between two headers, we can remove them (H1 -> C1 -> H2) -> (H2)
|
|
||||||
vec_tree_path_to_delete.push(list_store.path(¤t_iter).unwrap());
|
|
||||||
vec_tree_path_to_delete.push(list_store.path(&next_iter).unwrap());
|
|
||||||
current_iter = next_next_iter.clone();
|
|
||||||
continue 'main;
|
|
||||||
}
|
|
||||||
|
|
||||||
loop {
|
|
||||||
// (H1 -> C1 -> C2 -> Cn -> END) -> (NO CHANGE, BECAUSE IS GOOD)
|
|
||||||
if !list_store.iter_next(&next_next_iter) {
|
|
||||||
break 'main;
|
|
||||||
}
|
|
||||||
// Move to next header
|
|
||||||
if tree_model.value(&next_next_iter, column_color).get::<String>().unwrap() == HEADER_ROW_COLOR {
|
|
||||||
current_iter = next_next_iter.clone();
|
|
||||||
continue 'main;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for tree_path in vec_tree_path_to_delete.iter().rev() {
|
|
||||||
list_store.remove(&list_store.iter(tree_path).unwrap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
selection.unselect_all();
|
|
||||||
}
|
|
||||||
|
|
|
@ -258,6 +258,10 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::Duplicate).unwrap().get_mut("select").unwrap() = true;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::Duplicate).unwrap().get_mut("select").unwrap() = true;
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::Duplicate).unwrap().get_mut("symlink").unwrap() = true;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::Duplicate).unwrap().get_mut("symlink").unwrap() = true;
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::Duplicate).unwrap().get_mut("hardlink").unwrap() = true;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::Duplicate).unwrap().get_mut("hardlink").unwrap() = true;
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::Duplicate).unwrap().get_mut("hardlink").unwrap() = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::Duplicate).unwrap().get_mut("save").unwrap() = false;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::Duplicate).unwrap().get_mut("save").unwrap() = false;
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::Duplicate).unwrap().get_mut("delete").unwrap() = false;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::Duplicate).unwrap().get_mut("delete").unwrap() = false;
|
||||||
|
@ -551,6 +555,10 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SimilarImages).unwrap().get_mut("select").unwrap() = true;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SimilarImages).unwrap().get_mut("select").unwrap() = true;
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SimilarImages).unwrap().get_mut("symlink").unwrap() = true;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SimilarImages).unwrap().get_mut("symlink").unwrap() = true;
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SimilarImages).unwrap().get_mut("hardlink").unwrap() = true;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SimilarImages).unwrap().get_mut("hardlink").unwrap() = true;
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SimilarImages).unwrap().get_mut("hardlink").unwrap() = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SimilarImages).unwrap().get_mut("save").unwrap() = false;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SimilarImages).unwrap().get_mut("save").unwrap() = false;
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SimilarImages).unwrap().get_mut("delete").unwrap() = false;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SimilarImages).unwrap().get_mut("delete").unwrap() = false;
|
||||||
|
@ -741,6 +749,10 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SameMusic).unwrap().get_mut("select").unwrap() = true;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SameMusic).unwrap().get_mut("select").unwrap() = true;
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SameMusic).unwrap().get_mut("symlink").unwrap() = true;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SameMusic).unwrap().get_mut("symlink").unwrap() = true;
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SameMusic).unwrap().get_mut("hardlink").unwrap() = true;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SameMusic).unwrap().get_mut("hardlink").unwrap() = true;
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SameMusic).unwrap().get_mut("hardlink").unwrap() = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SameMusic).unwrap().get_mut("save").unwrap() = false;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SameMusic).unwrap().get_mut("save").unwrap() = false;
|
||||||
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SameMusic).unwrap().get_mut("delete").unwrap() = false;
|
*shared_buttons.borrow_mut().get_mut(&NotebookMainEnum::SameMusic).unwrap().get_mut("delete").unwrap() = false;
|
||||||
|
|
Loading…
Reference in a new issue