1
0
Fork 0
mirror of synced 2024-05-15 01:42:27 +12:00
czkawka/czkawka_gui/src/main.rs

145 lines
5.5 KiB
Rust
Raw Normal View History

// Remove console window in Windows OS
#![windows_subsystem = "windows"]
2021-07-16 16:51:54 +12:00
#![allow(clippy::collapsible_else_if)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::type_complexity)]
#![allow(clippy::needless_late_init)]
2022-06-01 03:52:55 +12:00
use std::env;
use std::ffi::OsString;
use crossbeam_channel::{unbounded, Receiver, Sender};
2022-05-22 20:59:09 +12:00
use gtk4::gio::ApplicationFlags;
use gtk4::prelude::*;
use gtk4::Application;
use log::info;
2021-11-28 08:49:20 +13:00
use connect_things::connect_about_buttons::*;
use connect_things::connect_button_compare::*;
use connect_things::connect_button_delete::*;
use connect_things::connect_button_hardlink::*;
use connect_things::connect_button_move::*;
use connect_things::connect_button_save::*;
use connect_things::connect_button_search::*;
use connect_things::connect_button_select::*;
use connect_things::connect_button_stop::*;
use connect_things::connect_change_language::*;
use connect_things::connect_duplicate_buttons::connect_duplicate_combo_box;
use connect_things::connect_header_buttons::*;
use connect_things::connect_notebook_tabs::*;
use connect_things::connect_progress_window::*;
use connect_things::connect_selection_of_directories::*;
use connect_things::connect_settings::*;
use connect_things::connect_show_hide_ui::*;
use connect_things::connect_similar_image_size_change::*;
use czkawka_core::common::{get_number_of_threads, print_version_mode, set_number_of_threads, setup_logger};
use czkawka_core::common_dir_traversal::ProgressData;
2022-06-01 03:52:55 +12:00
use czkawka_core::*;
use gui_structs::gui_data::*;
2021-11-28 08:49:20 +13:00
2022-06-01 03:52:55 +12:00
use crate::compute_results::*;
use crate::connect_things::connect_button_sort::connect_button_sort;
use crate::connect_things::connect_popovers_select::connect_popover_select;
use crate::connect_things::connect_popovers_sort::connect_popover_sort;
use crate::connect_things::connect_same_music_mode_changed::connect_same_music_change_mode;
2022-06-01 03:52:55 +12:00
use crate::initialize_gui::*;
use crate::language_functions::LANGUAGES_ALL;
use crate::saving_loading::*;
use crate::tests::validate_notebook_data;
mod compute_results;
mod connect_things;
mod create_tree_view;
mod gui_structs;
2021-12-14 07:13:53 +13:00
mod help_combo_box;
mod help_functions;
mod initialize_gui;
mod language_functions;
mod localizer_gui;
2021-01-11 00:06:25 +13:00
mod notebook_enums;
mod notebook_info;
mod opening_selecting_records;
mod saving_loading;
Windows taskbar progress support (#264) * Initial Windows taskbar progress support * Changes to COM (un)init It turns out winapi exposes IIDs through a `uuidof()` function of interfaces, so the copied one can be removed. * Don't return error codes Now the `TaskbarProgress` functions fail silently. The `TaskbarProgress` struct now will always be created (even in case of errors in initialisation), but it won't do anything. * Fix builds for other systems * Formatted code * Fix progress shown after the operation finished A progress update was received after the stop event. Also `as_ref()` was removed in many places (I don't even know why it was there). * Remove redundant call to hide It's already called by the `glib_stop_receiver` receiver. * Release the ITaskbarList3 and call CoUninitialize at exit Because objects moved to closures used as fallbacks in GTK have [static lifetimes](https://gtk-rs.org/docs-src/tutorial/closures#closures), the `TaskbarProgress` will never be dropped. To workaround this problem a `release` function is called when the main window is closed. This function behaves like `drop`, but sets the struct in a valid "empty" state, so that calling `release`/`drop` again won't cause problems. * Don't set the NORMAL state manually Because only NOPROGRESS and INDETERMINATE states are used, there is no need to set the NORMAL state when changing the progress value. Now `set_progress_value` will also change the `TaskbarProgress::current_state` if such situation occurs. > Unless [SetProgressState](https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-setprogressstate) > has set a blocking state (TBPF_ERROR or TBPF_PAUSED) for the window, a call to **SetProgressValue** assumes the TBPF_NORMAL > state even if it is not explicitly set. A call to **SetProgressValue** overrides and clears the TBPF_INDETERMINATE state. See the [SetProgressValue documentation](https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-setprogressvalue#how-the-taskbar-button-chooses-the-progress-indicator-for-a-group)
2021-02-21 00:24:36 +13:00
mod taskbar_progress;
#[cfg(not(target_os = "windows"))]
mod taskbar_progress_dummy;
#[cfg(target_os = "windows")]
mod taskbar_progress_win;
mod tests;
fn main() {
let application = Application::new(None::<String>, ApplicationFlags::HANDLES_OPEN | ApplicationFlags::HANDLES_COMMAND_LINE);
application.connect_command_line(move |app, cmdline| {
setup_logger(false);
print_version_mode();
build_ui(app, &cmdline.arguments());
0
});
application.run_with_args(&env::args().collect::<Vec<_>>());
}
2022-06-01 03:52:55 +12:00
fn build_ui(application: &Application, arguments: &[OsString]) {
let gui_data: GuiData = GuiData::new_with_application(application);
let (result_sender, result_receiver) = unbounded();
// Futures progress report
let (progress_sender, progress_receiver): (Sender<ProgressData>, Receiver<ProgressData>) = unbounded();
2020-09-05 07:12:18 +12:00
initialize_gui(&gui_data);
validate_notebook_data(&gui_data); // Must be run after initialization of gui, to check if everything was properly setup
reset_configuration(false, &gui_data.upper_notebook, &gui_data.main_notebook, &gui_data.settings, &gui_data.text_view_errors); // Fallback for invalid loading setting project
load_system_language(&gui_data); // Check for default system language, must be loaded after initializing GUI and before loading settings from file
load_configuration(
false,
&gui_data.upper_notebook,
&gui_data.main_notebook,
&gui_data.settings,
&gui_data.text_view_errors,
&gui_data.scrolled_window_errors,
arguments,
);
set_number_of_threads(gui_data.settings.scale_settings_number_of_threads.value().round() as usize);
info!("Set thread number to {}", get_number_of_threads());
// Needs to run when entire GUI is initialized
connect_change_language(&gui_data);
connect_button_delete(&gui_data);
connect_button_save(&gui_data);
connect_button_search(&gui_data, result_sender, progress_sender);
connect_button_select(&gui_data);
connect_button_sort(&gui_data);
connect_button_stop(&gui_data);
connect_button_hardlink_symlink(&gui_data);
connect_button_move(&gui_data);
connect_button_compare(&gui_data);
connect_duplicate_combo_box(&gui_data);
connect_notebook_tabs(&gui_data);
connect_selection_of_directories(&gui_data);
connect_popover_select(&gui_data);
connect_popover_sort(&gui_data);
connect_compute_results(&gui_data, result_receiver);
connect_progress_window(&gui_data, progress_receiver);
connect_show_hide_ui(&gui_data);
connect_settings(&gui_data);
connect_button_about(&gui_data);
connect_about_buttons(&gui_data);
connect_similar_image_size_change(&gui_data);
connect_same_music_change_mode(&gui_data);
2020-12-02 22:25:27 +13:00
let window_main = gui_data.window_main.clone();
let taskbar_state = gui_data.taskbar_state.clone();
let used_additional_arguments = arguments.len() > 1;
2022-05-22 20:59:09 +12:00
window_main.connect_close_request(move |_| {
// Not save configuration when using non default arguments
if !used_additional_arguments {
save_configuration(false, &gui_data.upper_notebook, &gui_data.main_notebook, &gui_data.settings, &gui_data.text_view_errors);
// Save configuration at exit
}
taskbar_state.borrow_mut().release();
glib::Propagation::Proceed
});
}