2020-11-01 02:23:31 +13:00
use czkawka_core ::big_file ::BigFile ;
2020-09-30 05:44:20 +13:00
use czkawka_core ::common_messages ::Messages ;
2020-11-01 02:23:31 +13:00
use czkawka_core ::duplicate ::DuplicateFinder ;
use czkawka_core ::empty_files ::EmptyFiles ;
use czkawka_core ::empty_folder ::EmptyFolder ;
2020-11-03 09:56:07 +13:00
use czkawka_core ::same_music ::SameMusic ;
2020-11-08 04:26:40 +13:00
use czkawka_core ::similar_images ::{ SimilarImages , Similarity } ;
2020-11-01 02:23:31 +13:00
use czkawka_core ::temporary ::Temporary ;
use czkawka_core ::zeroed ::ZeroedFiles ;
2020-09-30 05:44:20 +13:00
use gtk ::prelude ::* ;
2020-11-08 04:26:40 +13:00
use gtk ::{ ListStore , TreeView } ;
2020-10-08 09:22:39 +13:00
use std ::collections ::HashMap ;
2020-11-01 02:23:31 +13:00
use std ::path ::Path ;
pub enum Message {
Duplicates ( DuplicateFinder ) ,
EmptyFolders ( EmptyFolder ) ,
EmptyFiles ( EmptyFiles ) ,
BigFiles ( BigFile ) ,
Temporary ( Temporary ) ,
SimilarImages ( SimilarImages ) ,
ZeroedFiles ( ZeroedFiles ) ,
2020-11-03 09:56:07 +13:00
SameMusic ( SameMusic ) ,
2020-11-01 02:23:31 +13:00
}
2020-09-30 05:44:20 +13:00
2020-10-01 19:53:17 +13:00
pub enum ColumnsDuplicates {
2020-10-02 02:55:45 +13:00
// Columns for duplicate treeview
2020-10-01 19:53:17 +13:00
Name = 0 ,
Path ,
Modification ,
ModificationAsSecs ,
Color ,
2020-10-02 02:25:58 +13:00
TextColor ,
2020-10-01 19:53:17 +13:00
}
2020-10-02 02:25:58 +13:00
2020-10-02 06:26:25 +13:00
pub enum ColumnsEmptyFolders {
2020-10-02 02:55:45 +13:00
// Columns for empty folder treeview
2020-09-30 05:44:20 +13:00
Name = 0 ,
Path ,
Modification ,
}
pub enum ColumnsDirectory {
// Columns for Included and Excluded Directories in upper Notebook
Path = 0 ,
}
2020-10-02 06:26:25 +13:00
pub enum ColumnsBigFiles {
Size = 0 ,
Name ,
Path ,
Modification ,
}
pub enum ColumnsEmptyFiles {
Name = 0 ,
Path ,
Modification ,
}
pub enum ColumnsTemporaryFiles {
Name = 0 ,
Path ,
Modification ,
}
2020-10-15 20:04:02 +13:00
pub enum ColumnsSimilarImages {
Similarity = 0 ,
2020-10-16 04:51:47 +13:00
Size ,
Dimensions ,
2020-10-15 20:04:02 +13:00
Name ,
Path ,
Modification ,
2020-11-09 22:09:22 +13:00
ModificationAsSecs ,
2020-10-16 04:51:47 +13:00
Color ,
TextColor ,
2020-10-15 20:04:02 +13:00
}
2020-10-31 22:29:11 +13:00
pub enum ColumnsZeroedFiles {
Size = 0 ,
Name ,
Path ,
Modification ,
}
2020-11-03 09:56:07 +13:00
pub enum ColumnsSameMusic {
Size = 0 ,
Name ,
Path ,
Title ,
Artist ,
AlbumTitle ,
AlbumArtist ,
Year ,
Modification ,
2020-11-09 22:09:22 +13:00
ModificationAsSecs ,
2020-11-03 09:56:07 +13:00
Color ,
TextColor ,
}
2020-09-30 05:44:20 +13:00
2020-10-02 02:25:58 +13:00
pub const TEXT_COLOR : & str = " #ffffff " ;
2020-09-30 05:44:20 +13:00
pub const MAIN_ROW_COLOR : & str = " #343434 " ;
pub const HEADER_ROW_COLOR : & str = " #272727 " ;
//pub const MAIN_ROW_COLOR: &str = "#f4f434"; // TEST
//pub const HEADER_ROW_COLOR: &str = "#010101"; // TEST
pub fn get_string_from_list_store ( scrolled_window : & gtk ::ScrolledWindow ) -> String {
2020-11-08 04:26:40 +13:00
let list_store : gtk ::ListStore = get_list_store ( & scrolled_window ) ;
2020-09-30 07:19:36 +13:00
let mut first : bool = true ;
2020-09-30 05:44:20 +13:00
2020-09-30 07:19:36 +13:00
let mut return_string : String = " " . to_string ( ) ;
2020-09-30 05:44:20 +13:00
let tree_iter = match list_store . get_iter_first ( ) {
Some ( t ) = > t ,
2020-09-30 07:19:36 +13:00
None = > return return_string ,
2020-09-30 05:44:20 +13:00
} ;
2020-09-30 07:19:36 +13:00
loop {
if ! first {
return_string + = " , " ;
} else {
first = false ;
}
return_string + = list_store . get_value ( & tree_iter , 0 ) . get ::< String > ( ) . unwrap ( ) . unwrap ( ) . as_str ( ) ;
if ! list_store . iter_next ( & tree_iter ) {
return return_string ;
}
}
2020-09-30 05:44:20 +13:00
}
2020-11-01 02:23:31 +13:00
pub fn split_path ( path : & Path ) -> ( String , String ) {
match ( path . parent ( ) , path . file_name ( ) ) {
( Some ( dir ) , Some ( file ) ) = > ( dir . display ( ) . to_string ( ) , file . to_string_lossy ( ) . into_owned ( ) ) ,
( Some ( dir ) , None ) = > ( dir . display ( ) . to_string ( ) , String ::new ( ) ) ,
( None , _ ) = > ( String ::new ( ) , String ::new ( ) ) ,
}
}
2020-10-02 06:26:25 +13:00
2020-09-30 05:44:20 +13:00
pub fn print_text_messages_to_text_view ( text_messages : & Messages , text_view : & gtk ::TextView ) {
let mut messages : String = String ::from ( " " ) ;
if ! text_messages . messages . is_empty ( ) {
messages + = " ############### MESSAGES ############### \n " ;
}
for text in & text_messages . messages {
messages + = text . as_str ( ) ;
messages + = " \n " ;
}
if ! text_messages . messages . is_empty ( ) {
messages + = " \n " ;
}
if ! text_messages . warnings . is_empty ( ) {
messages + = " ############### WARNINGS ############### \n " ;
}
for text in & text_messages . warnings {
messages + = text . as_str ( ) ;
messages + = " \n " ;
}
if ! text_messages . warnings . is_empty ( ) {
messages + = " \n " ;
}
if ! text_messages . errors . is_empty ( ) {
messages + = " ############### ERRORS ############### \n " ;
}
for text in & text_messages . errors {
messages + = text . as_str ( ) ;
messages + = " \n " ;
}
if ! text_messages . errors . is_empty ( ) {
messages + = " \n " ;
}
text_view . get_buffer ( ) . unwrap ( ) . set_text ( messages . as_str ( ) ) ;
}
2020-10-15 20:04:02 +13:00
pub fn select_function_duplicates ( _tree_selection : & gtk ::TreeSelection , tree_model : & gtk ::TreeModel , tree_path : & gtk ::TreePath , _is_path_currently_selected : bool ) -> bool {
2020-10-01 19:53:17 +13:00
// 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();
let color = tree_model . get_value ( & tree_model . get_iter ( tree_path ) . unwrap ( ) , ColumnsDuplicates ::Color as i32 ) . get ::< String > ( ) . unwrap ( ) . unwrap ( ) ;
2020-09-30 05:44:20 +13:00
if color = = HEADER_ROW_COLOR {
return false ;
}
true
}
2020-11-03 09:56:07 +13:00
pub fn select_function_same_music ( _tree_selection : & gtk ::TreeSelection , tree_model : & gtk ::TreeModel , tree_path : & gtk ::TreePath , _is_path_currently_selected : bool ) -> bool {
let color = tree_model . get_value ( & tree_model . get_iter ( tree_path ) . unwrap ( ) , ColumnsSameMusic ::Color as i32 ) . get ::< String > ( ) . unwrap ( ) . unwrap ( ) ;
if color = = HEADER_ROW_COLOR {
return false ;
}
true
}
2020-11-08 04:26:40 +13:00
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 color = tree_model . get_value ( & tree_model . get_iter ( tree_path ) . unwrap ( ) , ColumnsSimilarImages ::Color as i32 ) . get ::< String > ( ) . unwrap ( ) . unwrap ( ) ;
if color = = HEADER_ROW_COLOR {
return false ;
}
true
}
2020-10-08 09:22:39 +13:00
2020-11-01 02:23:31 +13:00
pub fn set_buttons ( hashmap : & mut HashMap < String , bool > , buttons_array : & [ gtk ::Button ] , button_names : & [ String ] ) {
2020-10-08 09:22:39 +13:00
for ( index , button ) in buttons_array . iter ( ) . enumerate ( ) {
2020-11-01 02:23:31 +13:00
if * hashmap . get_mut ( button_names [ index ] . as_str ( ) ) . unwrap ( ) {
2020-10-08 09:22:39 +13:00
button . show ( ) ;
} else {
button . hide ( ) ;
}
}
}
// pub fn hide_all_buttons(buttons_array: &[gtk::Button]) {
// for button in buttons_array {
// button.hide();
// }
// }
2020-11-01 02:23:31 +13:00
pub fn hide_all_buttons_except ( except_name : & str , buttons_array : & [ gtk ::Button ] , button_names : & [ String ] ) {
2020-10-08 09:22:39 +13:00
for ( index , button ) in buttons_array . iter ( ) . enumerate ( ) {
if except_name = = button_names [ index ] {
button . show ( ) ;
} else {
button . hide ( ) ;
}
}
}
2020-10-15 20:04:02 +13:00
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 " ,
}
}
2020-11-08 04:26:40 +13:00
pub fn get_list_store ( scrolled_window : & gtk ::ScrolledWindow ) -> ListStore {
let list_store = scrolled_window . get_children ( ) . get ( 0 ) . unwrap ( ) . clone ( ) . downcast ::< gtk ::TreeView > ( ) . unwrap ( ) . get_model ( ) . unwrap ( ) . downcast ::< gtk ::ListStore > ( ) . unwrap ( ) ;
list_store
}
pub fn get_tree_view ( scrolled_window : & gtk ::ScrolledWindow ) -> TreeView {
let tree_view = scrolled_window . get_children ( ) . get ( 0 ) . unwrap ( ) . clone ( ) . downcast ::< gtk ::TreeView > ( ) . unwrap ( ) ;
tree_view
}