Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add similar images support for GUI #69

Merged
merged 1 commit into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Version 1.1.1 -
- Add test suite to PR
- Replace String with PathBuf for paths [#59](https://github.com/qarmin/czkawka/pull/59)
- Add test suite to PR [#65](https://github.com/qarmin/czkawka/pull/65)
- Support for finding similar images to CLI [#66](https://github.com/qarmin/czkawka/pull/66)
- Fix grammar-related errors and Ponglish expressions [#62](https://github.com/qarmin/czkawka/pull/62), [#63](https://github.com/qarmin/czkawka/pull/63)
- Don't delete by default files in duplicate finder in CLI - [23f203](https://github.com/qarmin/czkawka/commit/23f203a061e254275c95ca23ca4f1a78bd941f02)



Expand All @@ -19,6 +23,7 @@
- Fixed crash with invalid file modification date [#33](https://github.com/qarmin/czkawka/issues/33)
- Upper tabs can hide and show when this is necessary [#38](https://github.com/qarmin/czkawka/pull/38)
- Fixed crash when file/folder name have non Unicode character [#44](https://github.com/qarmin/czkawka/issues/44)
- Added support for finding similar pictures in GUI [#69](https://github.com/qarmin/czkawka/issues/69)

## Version 1.0.0 - 02.10.2020r
- Added confirmation button to delete button
Expand Down
2 changes: 1 addition & 1 deletion Instruction.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Instruction

TODO
## GUI


Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Differences should be more visible when using slower CPU or faster disk.
| Empty folders | X | X |
| Temporary files | X | X |
| Big files | X | |
| Similar images | X | |
| Installed packages | | X |
| Invalid names | | X |
| Names conflict | | X |
Expand Down
7 changes: 7 additions & 0 deletions czkawka_core/src/similar_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ impl SimilarImages {
&self.text_messages
}

pub const fn get_similar_images(&self) -> &Vec<StructSimilar> {
&self.similar_vectors
}

pub const fn get_information(&self) -> &Info {
&self.information
}
Expand Down Expand Up @@ -259,6 +263,9 @@ impl SimilarImages {

let mut new_vector: Vec<StructSimilar> = Vec::new();
for (string_hash, vec_file_entry) in &self.image_hashes {
if rx.is_some() && rx.unwrap().try_recv().is_ok() {
return false;
}
let vector_with_found_similar_hashes = self.bktree.find(string_hash.as_str(), 3).collect::<Vec<_>>();
if vector_with_found_similar_hashes.len() == 1 && vec_file_entry.len() == 1 {
// Exists only 1 unique picture, so there is no need to use it
Expand Down
78 changes: 78 additions & 0 deletions czkawka_gui/czkawka.glade
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,84 @@ Author: Rafał Mikrut
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkBox" id="notebook_main_similar_images_finder_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">8</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Minimal file size(in bytes)</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry_similar_images_minimal_size">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_length">15</property>
<property name="text" translatable="yes">16384</property>
<property name="caps_lock_warning">False</property>
<property name="input_purpose">number</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolled_window_similar_images_finder">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="position">5</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Similar Images</property>
</object>
<packing>
<property name="position">5</property>
<property name="tab_fill">False</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
Expand Down
68 changes: 67 additions & 1 deletion czkawka_gui/src/help_functions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use czkawka_core::common_messages::Messages;
use czkawka_core::similar_files::Similarity;
use gtk::prelude::*;
use gtk::TreeViewColumn;
use std::collections::HashMap;
Expand Down Expand Up @@ -39,6 +40,12 @@ pub enum ColumnsTemporaryFiles {
Path,
Modification,
}
pub enum ColumnsSimilarImages {
Similarity = 0,
Name,
Path,
Modification,
}

pub const TEXT_COLOR: &str = "#ffffff";
pub const MAIN_ROW_COLOR: &str = "#343434";
Expand Down Expand Up @@ -216,6 +223,46 @@ pub fn create_tree_view_empty_files(tree_view: &mut gtk::TreeView) {
tree_view.set_vexpand(true);
}

pub fn create_tree_view_similar_images(tree_view: &mut gtk::TreeView) {
let renderer = gtk::CellRendererText::new();
let name_column: gtk::TreeViewColumn = TreeViewColumn::new();
name_column.pack_start(&renderer, true);
name_column.set_title("Similarity");
name_column.set_resizable(true);
name_column.set_min_width(50);
name_column.add_attribute(&renderer, "text", ColumnsSimilarImages::Similarity as i32);

tree_view.append_column(&name_column);
let renderer = gtk::CellRendererText::new();
let name_column: gtk::TreeViewColumn = TreeViewColumn::new();
name_column.pack_start(&renderer, true);
name_column.set_title("File Name");
name_column.set_resizable(true);
name_column.set_min_width(50);
name_column.add_attribute(&renderer, "text", ColumnsSimilarImages::Name as i32);
tree_view.append_column(&name_column);

let renderer = gtk::CellRendererText::new();
let path_column: gtk::TreeViewColumn = TreeViewColumn::new();
path_column.pack_start(&renderer, true);
path_column.set_title("Path");
path_column.set_resizable(true);
path_column.set_min_width(100);
path_column.add_attribute(&renderer, "text", ColumnsSimilarImages::Path as i32);
tree_view.append_column(&path_column);

let renderer = gtk::CellRendererText::new();
let modification_date_column: gtk::TreeViewColumn = TreeViewColumn::new();
modification_date_column.pack_start(&renderer, true);
modification_date_column.set_title("Modification Date");
modification_date_column.set_resizable(true);
modification_date_column.set_min_width(100);
modification_date_column.add_attribute(&renderer, "text", ColumnsSimilarImages::Modification as i32);
tree_view.append_column(&modification_date_column);

tree_view.set_vexpand(true);
}

pub fn create_tree_view_directories(tree_view: &mut gtk::TreeView) {
let renderer = gtk::CellRendererText::new();
let name_column: gtk::TreeViewColumn = TreeViewColumn::new();
Expand Down Expand Up @@ -285,7 +332,7 @@ pub fn print_text_messages_to_text_view(text_messages: &Messages, text_view: &gt
text_view.get_buffer().unwrap().set_text(messages.as_str());
}

pub fn select_function_3column(_tree_selection: &gtk::TreeSelection, tree_model: &gtk::TreeModel, tree_path: &gtk::TreePath, _is_path_currently_selected: bool) -> bool {
pub fn select_function_duplicates(_tree_selection: &gtk::TreeSelection, tree_model: &gtk::TreeModel, tree_path: &gtk::TreePath, _is_path_currently_selected: bool) -> bool {
// let name = tree_model.get_value(&tree_model.get_iter(tree_path).unwrap(),ColumnsDuplicates::Name as i32).get::<String>().unwrap().unwrap();
// let path = tree_model.get_value(&tree_model.get_iter(tree_path).unwrap(), ColumnsDuplicates::Path as i32).get::<String>().unwrap().unwrap();
// let modification = tree_model.get_value(&tree_model.get_iter(tree_path).unwrap(),ColumnsDuplicates::Modification as i32).get::<String>().unwrap().unwrap();
Expand All @@ -297,6 +344,15 @@ pub fn select_function_3column(_tree_selection: &gtk::TreeSelection, tree_model:

true
}
pub fn select_function_similar_images(_tree_selection: &gtk::TreeSelection, tree_model: &gtk::TreeModel, tree_path: &gtk::TreePath, _is_path_currently_selected: bool) -> bool {
let path = tree_model.get_value(&tree_model.get_iter(tree_path).unwrap(), ColumnsSimilarImages::Path as i32).get::<String>().unwrap().unwrap();

if path.trim() == "" {
return false;
}

true
}

pub fn set_buttons(hashmap: &mut HashMap<String, bool>, buttons_array: &[gtk::Button], button_names: &[&str]) {
for (index, button) in buttons_array.iter().enumerate() {
Expand All @@ -322,3 +378,13 @@ pub fn hide_all_buttons_except(except_name: &str, buttons_array: &[gtk::Button],
}
}
}

pub fn get_text_from_similarity(similarity: &Similarity) -> &str {
match similarity {
Similarity::None => "Original",
Similarity::Small => "Small",
Similarity::Medium => "Medium",
Similarity::High => "High",
Similarity::VeryHigh => "Very High",
}
}