From 0db9815467d45812f6d727d60ba637613050d964 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Mon, 16 Dec 2019 13:53:12 +0100 Subject: [PATCH] correct beahvior when disconnecting device other way than button in slicer --- src/slic3r/GUI/Plater.cpp | 21 +++++++++++++++------ src/slic3r/GUI/RemovableDriveManager.cpp | 23 +++++++++++++++++++---- src/slic3r/GUI/RemovableDriveManager.hpp | 3 +++ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index ce29120ab..63521815d 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3600,6 +3600,8 @@ void Plater::priv::on_process_completed(wxCommandEvent &evt) else if(RemovableDriveManager::get_instance().get_is_writing()) { RemovableDriveManager::get_instance().set_is_writing(false); + //RemovableDriveManager::get_instance().erase_callbacks(); + //RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, q)); show_action_buttons(false); } } @@ -4168,8 +4170,7 @@ void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const const auto prin_host_opt = config->option("print_host"); const bool send_gcode_shown = prin_host_opt != nullptr && !prin_host_opt->value.empty(); - const bool disconnect_shown = !(RemovableDriveManager::get_instance().is_last_drive_removed()); // #dk_FIXME - + bool disconnect_shown = !RemovableDriveManager::get_instance().is_last_drive_removed() ; // #dk_FIXME // when a background processing is ON, export_btn and/or send_btn are showing if (wxGetApp().app_config->get("background_processing") == "1") { @@ -4735,6 +4736,11 @@ void Plater::export_gcode() p->export_gcode(std::move(output_path), PrintHostJob()); RemovableDriveManager::get_instance().update(0, true); RemovableDriveManager::get_instance().set_last_save_path(path); + if(!RemovableDriveManager::get_instance().is_last_drive_removed()) + { + RemovableDriveManager::get_instance().erase_callbacks(); + RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this)); + } } } @@ -5019,15 +5025,18 @@ void Plater::send_gcode() void Plater::eject_drive() { RemovableDriveManager::get_instance().update(0, true); - RemovableDriveManager::get_instance().erase_callbacks(); - RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this)); + //RemovableDriveManager::get_instance().erase_callbacks(); + //RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this)); RemovableDriveManager::get_instance().eject_drive(RemovableDriveManager::get_instance().get_last_save_path()); } void Plater::drive_ejected_callback() { - wxString message = "Unmounting succesesful. The device " + RemovableDriveManager::get_instance().get_last_save_name() + "(" + RemovableDriveManager::get_instance().get_last_save_path() + ")" + " can now be safely removed from the computer."; - wxMessageBox(message); + if (RemovableDriveManager::get_instance().get_did_eject()) + { + wxString message = "Unmounting succesesful. The device " + RemovableDriveManager::get_instance().get_last_save_name() + "(" + RemovableDriveManager::get_instance().get_last_save_path() + ")" + " can now be safely removed from the computer."; + wxMessageBox(message); + } p->show_action_buttons(false); } diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 535d62f83..5af4362f2 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -106,7 +106,7 @@ void RemovableDriveManager::eject_drive(const std::string &path) return; } CloseHandle(handle); - + m_did_eject = true; m_current_drives.erase(it); break; } @@ -365,6 +365,7 @@ void RemovableDriveManager::eject_drive(const std::string &path) std::cerr<<"Ejecting failed\n"; return; } + m_did_eject = true; m_current_drives.erase(it); break; @@ -401,12 +402,18 @@ RemovableDriveManager::RemovableDriveManager(): m_last_update(0), m_last_save_path(""), m_last_save_name(""), - m_is_writing(false) + m_is_writing(false), + m_did_eject(false) #if __APPLE__ , m_rdmmm(new RDMMMWrapper()) #endif {} - +RemovableDriveManager::~RemovableDriveManager() +{ +#if __APPLE__ + delete m_rdmmm; +#endif +} void RemovableDriveManager::init() { //add_callback([](void) { RemovableDriveManager::get_instance().print(); }); @@ -517,7 +524,7 @@ std::string RemovableDriveManager::get_drive_name(const std::string& path) bool RemovableDriveManager::is_last_drive_removed() { //std::cout<<"is last: "<