From 5daaaa2845922f15b819c9b7d1460f072cea66ba Mon Sep 17 00:00:00 2001 From: David Kocik Date: Mon, 15 Mar 2021 17:40:17 +0100 Subject: [PATCH] Fixed upload notification cancel button --- src/slic3r/GUI/NotificationManager.cpp | 26 +++++--------------------- src/slic3r/GUI/NotificationManager.hpp | 2 +- src/slic3r/GUI/PrintHostDialogs.cpp | 5 ++--- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index 4c0bf3734..358f709a7 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -5,6 +5,7 @@ #include "ImGuiWrapper.hpp" #include "PrintHostDialogs.hpp" #include "wxExtensions.hpp" +#include "../Utils/PrintHost.hpp" #include #include @@ -827,8 +828,6 @@ void NotificationManager::ProgressBarNotification::render_bar(ImGuiWrapper& imgu //------PrintHostUploadNotification---------------- void NotificationManager::PrintHostUploadNotification::set_percentage(float percent) { - if (m_uj_state == UploadJobState::PB_CANCELLED) - return; m_percentage = percent; if (percent >= 1.0f) { m_uj_state = UploadJobState::PB_COMPLETED; @@ -914,11 +913,7 @@ void NotificationManager::PrintHostUploadNotification::render_cancel_button(ImGu ImGui::SetCursorPosY(win_size.y / 2 - button_size.y); if (imgui.button(button_text.c_str(), button_size.x, button_size.y)) { - assert(m_evt_handler != nullptr); - if (m_evt_handler != nullptr) { - auto evt = new PrintHostQueueDialog::Event(GUI::EVT_PRINTHOST_CANCEL, m_job_id, m_job_id); - wxQueueEvent(m_evt_handler, evt); - } + wxGetApp().printhost_job_queue().cancel(m_job_id - 1); } //invisible large button @@ -926,11 +921,7 @@ void NotificationManager::PrintHostUploadNotification::render_cancel_button(ImGu ImGui::SetCursorPosY(0); if (imgui.button(" ", m_line_height * 2.f, win_size.y)) { - assert(m_evt_handler != nullptr); - if (m_evt_handler != nullptr) { - auto evt = new PrintHostQueueDialog::Event(GUI::EVT_PRINTHOST_CANCEL, m_job_id, m_job_id); - wxQueueEvent(m_evt_handler, evt); - } + wxGetApp().printhost_job_queue().cancel(m_job_id - 1); } ImGui::PopStyleColor(); ImGui::PopStyleColor(); @@ -1129,28 +1120,21 @@ void NotificationManager::push_exporting_finished_notification(const std::string push_notification_data(std::make_unique(data, m_id_provider, m_evt_handler, on_removable, path, dir_path), 0); } -void NotificationManager::push_upload_job_notification(wxEvtHandler* evt_handler, int id, float filesize, const std::string& filename, const std::string& host, float percentage) +void NotificationManager::push_upload_job_notification(int id, float filesize, const std::string& filename, const std::string& host, float percentage) { std::string text = PrintHostUploadNotification::get_upload_job_text(id, filename, host); NotificationData data{ NotificationType::PrintHostUpload, NotificationLevel::ProgressBarNotification, 0, text }; - push_notification_data(std::make_unique(data, m_id_provider, evt_handler, 0, id, filesize), 0); + push_notification_data(std::make_unique(data, m_id_provider, m_evt_handler, 0, id, filesize), 0); } void NotificationManager::set_upload_job_notification_percentage(int id, const std::string& filename, const std::string& host, float percentage) { std::string text = PrintHostUploadNotification::get_upload_job_text(id, filename, host); -// bool found = false; for (std::unique_ptr& notification : m_pop_notifications) { if (notification->get_type() == NotificationType::PrintHostUpload && notification->compare_text(text)) { dynamic_cast(notification.get())->set_percentage(percentage); wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); -// found = true; } } - /* - if (!found) { - push_upload_job_notification(id, filename, host, percentage); - } - */ } void NotificationManager::upload_job_notification_show_canceled(int id, const std::string& filename, const std::string& host) { diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index 651deace8..f709a2a7d 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -147,7 +147,7 @@ public: // Exporting finished, show this information with path, button to open containing folder and if ejectable - eject button void push_exporting_finished_notification(const std::string& path, const std::string& dir_path, bool on_removable); // notification with progress bar - void push_upload_job_notification(wxEvtHandler* evt_handler, int id, float filesize, const std::string& filename, const std::string& host, float percentage = 0); + void push_upload_job_notification(int id, float filesize, const std::string& filename, const std::string& host, float percentage = 0); void set_upload_job_notification_percentage(int id, const std::string& filename, const std::string& host, float percentage); void upload_job_notification_show_canceled(int id, const std::string& filename, const std::string& host); void upload_job_notification_show_error(int id, const std::string& filename, const std::string& host); diff --git a/src/slic3r/GUI/PrintHostDialogs.cpp b/src/slic3r/GUI/PrintHostDialogs.cpp index d99584c1e..afbc604bc 100644 --- a/src/slic3r/GUI/PrintHostDialogs.cpp +++ b/src/slic3r/GUI/PrintHostDialogs.cpp @@ -225,7 +225,7 @@ PrintHostQueueDialog::PrintHostQueueDialog(wxWindow *parent) SetSize(load_user_data(UDT_SIZE, size) ? wxSize(size[0] * em, size[1] * em) : wxSize(HEIGHT * em, WIDTH * em)); Bind(wxEVT_SIZE, [this, em](wxSizeEvent& evt) { - OnSize(evt); + OnSize(evt); save_user_data(UDT_SIZE | UDT_POSITION | UDT_COLS); }); @@ -245,7 +245,6 @@ PrintHostQueueDialog::PrintHostQueueDialog(wxWindow *parent) const JobState state = get_state(selected); if (state < ST_ERROR) { - // TODO: cancel GUI::wxGetApp().printhost_job_queue().cancel(selected); } }); @@ -282,7 +281,7 @@ void PrintHostQueueDialog::append_job(const PrintHostJob &job) // Both strings are UTF-8 encoded. upload_names.emplace_back(job.printhost->get_host(), job.upload_data.upload_path.string()); - wxGetApp().notification_manager()->push_upload_job_notification(this, job_list->GetItemCount(), (float)size_i / 1024 / 1024, job.upload_data.upload_path.string(), job.printhost->get_host()); + wxGetApp().notification_manager()->push_upload_job_notification(job_list->GetItemCount(), (float)size_i / 1024 / 1024, job.upload_data.upload_path.string(), job.printhost->get_host()); } void PrintHostQueueDialog::on_dpi_changed(const wxRect &suggested_rect)