2020-11-01 02:23:31 +13:00
|
|
|
extern crate gtk;
|
2021-01-25 00:01:02 +13:00
|
|
|
use crate::gui_about::GUIAbout;
|
2021-01-11 08:12:08 +13:00
|
|
|
use crate::gui_bottom_buttons::GUIBottomButtons;
|
2021-01-25 00:01:02 +13:00
|
|
|
use crate::gui_header::GUIHeader;
|
2021-01-11 01:45:05 +13:00
|
|
|
use crate::gui_main_notebook::GUIMainNotebook;
|
2021-01-25 00:01:02 +13:00
|
|
|
use crate::gui_options::GUIOptions;
|
2021-01-11 08:12:08 +13:00
|
|
|
use crate::gui_popovers::GUIPopovers;
|
|
|
|
use crate::gui_progress_dialog::GUIProgressDialog;
|
|
|
|
use crate::gui_upper_notepad::GUIUpperNotebook;
|
2021-01-11 00:06:25 +13:00
|
|
|
use crate::notebook_enums::*;
|
2021-02-21 00:24:36 +13:00
|
|
|
use crate::taskbar_progress::TaskbarProgress;
|
2020-11-01 02:23:31 +13:00
|
|
|
use crossbeam_channel::unbounded;
|
|
|
|
use czkawka_core::big_file::BigFile;
|
2021-01-13 08:06:12 +13:00
|
|
|
use czkawka_core::broken_files::BrokenFiles;
|
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-12-22 04:09:39 +13:00
|
|
|
use czkawka_core::invalid_symlinks::InvalidSymlinks;
|
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;
|
2020-11-01 02:23:31 +13:00
|
|
|
use czkawka_core::temporary::Temporary;
|
|
|
|
use czkawka_core::zeroed::ZeroedFiles;
|
|
|
|
use gtk::prelude::*;
|
2021-01-11 08:12:08 +13:00
|
|
|
use gtk::Builder;
|
2020-11-01 02:23:31 +13:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct GuiData {
|
2020-11-03 09:56:07 +13:00
|
|
|
// Glade builder
|
2020-11-01 02:23:31 +13:00
|
|
|
pub glade_src: String,
|
|
|
|
pub builder: Builder,
|
2020-11-03 09:56:07 +13:00
|
|
|
|
2020-11-01 02:23:31 +13:00
|
|
|
// Windows
|
|
|
|
pub window_main: gtk::Window,
|
2020-11-03 09:56:07 +13:00
|
|
|
|
2021-01-11 01:45:05 +13:00
|
|
|
pub main_notebook: GUIMainNotebook,
|
2021-01-11 08:12:08 +13:00
|
|
|
pub upper_notebook: GUIUpperNotebook,
|
|
|
|
pub popovers: GUIPopovers,
|
|
|
|
pub bottom_buttons: GUIBottomButtons,
|
2021-01-26 06:23:42 +13:00
|
|
|
pub progress_window: GUIProgressDialog,
|
2021-01-25 00:01:02 +13:00
|
|
|
pub about: GUIAbout,
|
|
|
|
pub options: GUIOptions,
|
|
|
|
pub header: GUIHeader,
|
2020-12-22 04:09:39 +13:00
|
|
|
|
2021-02-21 00:24:36 +13:00
|
|
|
// Taskbar state
|
|
|
|
pub taskbar_state: Rc<RefCell<TaskbarProgress>>,
|
|
|
|
|
2020-11-01 02:23:31 +13:00
|
|
|
// Buttons state
|
2021-01-11 00:06:25 +13:00
|
|
|
pub shared_buttons: Rc<RefCell<HashMap<NotebookMainEnum, HashMap<String, bool>>>>,
|
2020-11-01 02:23:31 +13:00
|
|
|
|
|
|
|
// Upper Notebook state
|
2021-01-11 00:06:25 +13:00
|
|
|
pub shared_upper_notebooks: Rc<RefCell<HashMap<NotebookMainEnum, HashMap<NotebookUpperEnum, bool>>>>,
|
2020-11-01 02:23:31 +13:00
|
|
|
|
|
|
|
// State of search results
|
|
|
|
pub shared_duplication_state: Rc<RefCell<DuplicateFinder>>,
|
|
|
|
pub shared_empty_folders_state: Rc<RefCell<EmptyFolder>>,
|
|
|
|
pub shared_empty_files_state: Rc<RefCell<EmptyFiles>>,
|
|
|
|
pub shared_temporary_files_state: Rc<RefCell<Temporary>>,
|
|
|
|
pub shared_big_files_state: Rc<RefCell<BigFile>>,
|
|
|
|
pub shared_similar_images_state: Rc<RefCell<SimilarImages>>,
|
|
|
|
pub shared_zeroed_files_state: Rc<RefCell<ZeroedFiles>>,
|
2020-11-03 09:56:07 +13:00
|
|
|
pub shared_same_music_state: Rc<RefCell<SameMusic>>,
|
2020-12-22 04:09:39 +13:00
|
|
|
pub shared_same_invalid_symlinks: Rc<RefCell<InvalidSymlinks>>,
|
2021-01-13 08:06:12 +13:00
|
|
|
pub shared_broken_files_state: Rc<RefCell<BrokenFiles>>,
|
2020-11-01 02:23:31 +13:00
|
|
|
|
|
|
|
//// Entry
|
2021-01-11 08:12:08 +13:00
|
|
|
pub entry_info: gtk::Entry,
|
2020-11-01 02:23:31 +13:00
|
|
|
|
2020-12-13 12:21:43 +13:00
|
|
|
//// Bottom
|
2020-11-01 02:23:31 +13:00
|
|
|
pub text_view_errors: gtk::TextView,
|
2020-12-13 12:21:43 +13:00
|
|
|
pub scrolled_window_errors: gtk::ScrolledWindow,
|
2020-11-01 02:23:31 +13:00
|
|
|
|
|
|
|
// Used for sending stop signal to thread
|
2020-11-05 06:15:06 +13:00
|
|
|
pub stop_sender: crossbeam_channel::Sender<()>,
|
|
|
|
pub stop_receiver: crossbeam_channel::Receiver<()>,
|
2020-11-01 02:23:31 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
impl GuiData {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
//// Loading glade file content and build with it help UI
|
|
|
|
let glade_src = include_str!("../czkawka.glade").to_string();
|
|
|
|
let builder = Builder::from_string(glade_src.as_str());
|
|
|
|
|
|
|
|
//// Windows
|
|
|
|
let window_main: gtk::Window = builder.get_object("window_main").unwrap();
|
|
|
|
window_main.show_all();
|
|
|
|
window_main.set_title("Czkawka");
|
|
|
|
|
2021-01-11 01:45:05 +13:00
|
|
|
let main_notebook = GUIMainNotebook::create_from_builder(&builder);
|
2021-01-11 08:12:08 +13:00
|
|
|
let upper_notebook = GUIUpperNotebook::create_from_builder(&builder);
|
|
|
|
let popovers = GUIPopovers::create_from_builder(&builder);
|
|
|
|
let bottom_buttons = GUIBottomButtons::create_from_builder(&builder);
|
2021-01-26 06:23:42 +13:00
|
|
|
let progress_window = GUIProgressDialog::create_from_builder(&builder);
|
2021-01-25 00:01:02 +13:00
|
|
|
let options = GUIOptions::create_from_builder(&builder);
|
|
|
|
let about = GUIAbout::create_from_builder(&builder);
|
|
|
|
let header = GUIHeader::create_from_builder(&builder);
|
2021-01-11 01:45:05 +13:00
|
|
|
|
2020-11-01 02:23:31 +13:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-02-21 00:24:36 +13:00
|
|
|
// Taskbar state
|
|
|
|
let taskbar_state = Rc::new(RefCell::new(TaskbarProgress::new()));
|
|
|
|
|
2020-11-01 02:23:31 +13:00
|
|
|
// Buttons State - to remember existence of different buttons on pages
|
2021-01-11 00:06:25 +13:00
|
|
|
let shared_buttons: Rc<RefCell<_>> = Rc::new(RefCell::new(HashMap::<NotebookMainEnum, HashMap<String, bool>>::new()));
|
2020-11-01 02:23:31 +13:00
|
|
|
|
|
|
|
// Show by default only search button
|
2021-01-11 00:06:25 +13:00
|
|
|
for i in get_all_main_tabs().iter() {
|
2020-11-01 02:23:31 +13:00
|
|
|
let mut temp_hashmap: HashMap<String, bool> = Default::default();
|
2021-01-11 08:12:08 +13:00
|
|
|
for button_name in bottom_buttons.buttons_names.iter() {
|
|
|
|
if *button_name == "search" {
|
|
|
|
temp_hashmap.insert(button_name.to_string(), true);
|
2020-11-01 02:23:31 +13:00
|
|
|
} else {
|
2021-01-11 08:12:08 +13:00
|
|
|
temp_hashmap.insert(button_name.to_string(), false);
|
2020-11-01 02:23:31 +13:00
|
|
|
}
|
|
|
|
}
|
2021-01-11 00:06:25 +13:00
|
|
|
shared_buttons.borrow_mut().insert(i.clone(), temp_hashmap);
|
2020-11-01 02:23:31 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
// Upper Notebook state
|
2021-01-11 00:06:25 +13:00
|
|
|
let shared_upper_notebooks: Rc<RefCell<_>> = Rc::new(RefCell::new(HashMap::<NotebookMainEnum, HashMap<NotebookUpperEnum, bool>>::new()));
|
2020-11-01 02:23:31 +13:00
|
|
|
|
2021-01-11 00:06:25 +13:00
|
|
|
for i in get_all_main_tabs().iter() {
|
|
|
|
let mut temp_hashmap: HashMap<NotebookUpperEnum, bool> = Default::default();
|
|
|
|
for j in get_all_upper_tabs().iter() {
|
|
|
|
temp_hashmap.insert(j.clone(), true);
|
2020-11-01 02:23:31 +13:00
|
|
|
}
|
2021-01-11 00:06:25 +13:00
|
|
|
shared_upper_notebooks.borrow_mut().insert(i.clone(), temp_hashmap);
|
2020-11-01 02:23:31 +13:00
|
|
|
}
|
|
|
|
// Some upper notebook tabs are disabled
|
2021-01-11 00:06:25 +13:00
|
|
|
*shared_upper_notebooks.borrow_mut().get_mut(&NotebookMainEnum::Temporary).unwrap().get_mut(&NotebookUpperEnum::AllowedExtensions).unwrap() = false;
|
2020-11-01 02:23:31 +13:00
|
|
|
|
|
|
|
// State of search results
|
|
|
|
|
|
|
|
let shared_duplication_state: Rc<RefCell<_>> = Rc::new(RefCell::new(DuplicateFinder::new()));
|
|
|
|
let shared_empty_folders_state: Rc<RefCell<_>> = Rc::new(RefCell::new(EmptyFolder::new()));
|
|
|
|
let shared_empty_files_state: Rc<RefCell<_>> = Rc::new(RefCell::new(EmptyFiles::new()));
|
|
|
|
let shared_temporary_files_state: Rc<RefCell<_>> = Rc::new(RefCell::new(Temporary::new()));
|
|
|
|
let shared_big_files_state: Rc<RefCell<_>> = Rc::new(RefCell::new(BigFile::new()));
|
|
|
|
let shared_similar_images_state: Rc<RefCell<_>> = Rc::new(RefCell::new(SimilarImages::new()));
|
|
|
|
let shared_zeroed_files_state: Rc<RefCell<_>> = Rc::new(RefCell::new(ZeroedFiles::new()));
|
2020-11-03 09:56:07 +13:00
|
|
|
let shared_same_music_state: Rc<RefCell<_>> = Rc::new(RefCell::new(SameMusic::new()));
|
2020-12-22 04:09:39 +13:00
|
|
|
let shared_same_invalid_symlinks: Rc<RefCell<_>> = Rc::new(RefCell::new(InvalidSymlinks::new()));
|
2021-01-13 08:06:12 +13:00
|
|
|
let shared_broken_files_state: Rc<RefCell<_>> = Rc::new(RefCell::new(BrokenFiles::new()));
|
2020-11-01 02:23:31 +13:00
|
|
|
|
|
|
|
//// Entry
|
2020-12-19 22:03:04 +13:00
|
|
|
let entry_info: gtk::Entry = builder.get_object("entry_info").unwrap();
|
2020-11-01 02:23:31 +13:00
|
|
|
|
2020-12-13 12:21:43 +13:00
|
|
|
//// Bottom
|
2020-11-01 02:23:31 +13:00
|
|
|
let text_view_errors: gtk::TextView = builder.get_object("text_view_errors").unwrap();
|
2020-12-13 12:21:43 +13:00
|
|
|
let scrolled_window_errors: gtk::ScrolledWindow = builder.get_object("scrolled_window_errors").unwrap();
|
2021-01-25 00:01:02 +13:00
|
|
|
scrolled_window_errors.show_all(); // Not sure why needed, but without it text view errors sometimes hide itself
|
2020-11-01 02:23:31 +13:00
|
|
|
|
|
|
|
// Used for sending stop signal to thread
|
2020-11-05 06:15:06 +13:00
|
|
|
let (stop_sender, stop_receiver): (crossbeam_channel::Sender<()>, crossbeam_channel::Receiver<()>) = unbounded();
|
2020-11-01 02:23:31 +13:00
|
|
|
|
|
|
|
Self {
|
|
|
|
glade_src,
|
|
|
|
builder,
|
|
|
|
window_main,
|
2021-01-11 01:45:05 +13:00
|
|
|
main_notebook,
|
2021-01-11 08:12:08 +13:00
|
|
|
upper_notebook,
|
|
|
|
popovers,
|
|
|
|
bottom_buttons,
|
2021-01-26 06:23:42 +13:00
|
|
|
progress_window,
|
2021-01-25 00:01:02 +13:00
|
|
|
about,
|
|
|
|
options,
|
|
|
|
header,
|
2021-02-21 00:24:36 +13:00
|
|
|
taskbar_state,
|
2020-11-01 02:23:31 +13:00
|
|
|
shared_buttons,
|
|
|
|
shared_upper_notebooks,
|
|
|
|
shared_duplication_state,
|
|
|
|
shared_empty_folders_state,
|
|
|
|
shared_empty_files_state,
|
|
|
|
shared_temporary_files_state,
|
|
|
|
shared_big_files_state,
|
|
|
|
shared_similar_images_state,
|
|
|
|
shared_zeroed_files_state,
|
2020-11-03 09:56:07 +13:00
|
|
|
shared_same_music_state,
|
2020-12-22 04:09:39 +13:00
|
|
|
shared_same_invalid_symlinks,
|
2021-01-13 08:06:12 +13:00
|
|
|
shared_broken_files_state,
|
2020-11-01 02:23:31 +13:00
|
|
|
entry_info,
|
|
|
|
text_view_errors,
|
2020-12-13 12:21:43 +13:00
|
|
|
scrolled_window_errors,
|
2020-11-05 06:15:06 +13:00
|
|
|
stop_sender,
|
|
|
|
stop_receiver,
|
2020-11-01 02:23:31 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|