From 41ab733cd896d794c86865c043baad5d01d640c6 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Mon, 6 Feb 2023 15:31:01 +0100 Subject: [PATCH] Refactoring of DownloaderUtils (remove including ConfigWizard_private.hpp)) --- src/slic3r/GUI/ConfigWizard.cpp | 18 ++++++------- src/slic3r/GUI/ConfigWizard.hpp | 30 +++++++++++++++++++++ src/slic3r/GUI/ConfigWizard_private.hpp | 36 +------------------------ src/slic3r/GUI/GUI_App.cpp | 5 ++-- src/slic3r/GUI/GUI_App.hpp | 4 +-- src/slic3r/GUI/Preferences.cpp | 2 +- src/slic3r/GUI/Preferences.hpp | 2 +- 7 files changed, 46 insertions(+), 51 deletions(-) diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index 1cf647ed7..0fb934996 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -1315,10 +1315,12 @@ PageUpdate::PageUpdate(ConfigWizard *parent) box_presets->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &event) { this->preset_update = event.IsChecked(); }); } + + namespace DownloaderUtils { +namespace { #ifdef _WIN32 - wxString get_downloads_path() { wxString ret; @@ -1330,7 +1332,6 @@ namespace DownloaderUtils CoTaskMemFree(path); return ret; } - #elif __APPLE__ wxString get_downloads_path() { @@ -1348,9 +1349,8 @@ namespace DownloaderUtils } return wxString(); } - #endif - + } Worker::Worker(wxWindow* parent) : wxBoxSizer(wxHORIZONTAL) , m_parent(parent) @@ -1432,16 +1432,16 @@ PageDownloader::PageDownloader(ConfigWizard* parent) ))); #endif - box_allow_downloads->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& event) { this->downloader->allow(event.IsChecked()); }); + box_allow_downloads->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& event) { this->m_downloader->allow(event.IsChecked()); }); - downloader = new DownloaderUtils::Worker(this); - append(downloader); - downloader->allow(box_allow_value); + m_downloader = new DownloaderUtils::Worker(this); + append(m_downloader); + m_downloader->allow(box_allow_value); } bool PageDownloader::on_finish_downloader() const { - return downloader->on_finish(); + return m_downloader->on_finish(); } bool DownloaderUtils::Worker::perform_register(const std::string& path_override/* = {}*/) diff --git a/src/slic3r/GUI/ConfigWizard.hpp b/src/slic3r/GUI/ConfigWizard.hpp index 88d2e2d7c..4520dbb8f 100644 --- a/src/slic3r/GUI/ConfigWizard.hpp +++ b/src/slic3r/GUI/ConfigWizard.hpp @@ -14,6 +14,36 @@ class PresetUpdater; namespace GUI { +namespace DownloaderUtils { + class Worker : public wxBoxSizer + { + wxWindow* m_parent{ nullptr }; + wxTextCtrl* m_input_path{ nullptr }; + bool downloader_checked{ false }; +#ifdef __linux__ + bool perform_registration_linux{ false }; +#endif // __linux__ + + void deregister(); + + public: + Worker(wxWindow* parent); + ~Worker() {} + + void allow(bool allow_) { downloader_checked = allow_; } + bool is_checked() const { return downloader_checked; } + wxString path_name() const { return m_input_path ? m_input_path->GetValue() : wxString(); } + + void set_path_name(wxString name); + void set_path_name(const std::string& name); + + bool on_finish(); + bool perform_register(const std::string& path_override = {}); +#ifdef __linux__ + bool get_perform_registration_linux() { return perform_registration_linux; } +#endif // __linux__ + }; +} class ConfigWizard: public DPIDialog { diff --git a/src/slic3r/GUI/ConfigWizard_private.hpp b/src/slic3r/GUI/ConfigWizard_private.hpp index c7c6e5152..832bef46c 100644 --- a/src/slic3r/GUI/ConfigWizard_private.hpp +++ b/src/slic3r/GUI/ConfigWizard_private.hpp @@ -418,44 +418,10 @@ struct PageUpdate: ConfigWizardPage PageUpdate(ConfigWizard *parent); }; -namespace DownloaderUtils { - wxString get_downloads_path(); - -class Worker : public wxBoxSizer -{ - wxWindow* m_parent {nullptr}; - wxTextCtrl* m_input_path {nullptr}; - bool downloader_checked {false}; -#ifdef __linux__ - bool perform_registration_linux { false }; -#endif // __linux__ - - void deregister(); - -public: - Worker(wxWindow* parent); - ~Worker(){} - - void allow(bool allow_) { downloader_checked = allow_; } - bool is_checked() const { return downloader_checked; } - wxString path_name() const { return m_input_path ? m_input_path->GetValue() : wxString(); } - - void set_path_name(wxString name); - void set_path_name(const std::string& name); - - bool on_finish(); - bool perform_register(const std::string& path_override = {}); -#ifdef __linux__ - bool get_perform_registration_linux() { return perform_registration_linux; } -#endif // __linux__ -}; - -} - struct PageDownloader : ConfigWizardPage { - DownloaderUtils::Worker* downloader{ nullptr }; + DownloaderUtils::Worker* m_downloader { nullptr }; PageDownloader(ConfigWizard* parent); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index a4cfc0cb9..6d49e22f1 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -79,7 +79,6 @@ #include "DesktopIntegrationDialog.hpp" #include "SendSystemInfoDialog.hpp" #include "Downloader.hpp" -#include "ConfigWizard_private.hpp" #include "BitmapCache.hpp" #include "Notebook.hpp" @@ -3081,8 +3080,8 @@ void GUI_App::show_downloader_registration_dialog() ), SLIC3R_APP_NAME, SLIC3R_VERSION) , true, wxYES_NO); if (msg.ShowModal() == wxID_YES) { - auto downloader = new DownloaderUtils::Worker(nullptr); - downloader->perform_register(app_config->get("url_downloader_dest")); + auto downloader_worker = new DownloaderUtils::Worker(nullptr); + downloader_worker->perform_register(app_config->get("url_downloader_dest")); #ifdef __linux__ if (downloader->get_perform_registration_linux()) DesktopIntegrationDialog::perform_desktop_integration(true); diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 1a58bd809..3f8d47fd7 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -306,8 +306,8 @@ public: Plater* plater(); const Plater* plater() const; Model& model(); - NotificationManager * notification_manager(); - GalleryDialog * gallery_dialog(); + NotificationManager* notification_manager(); + GalleryDialog * gallery_dialog(); Downloader* downloader(); // Parameters extracted from the command line to be passed to GUI after initialization. diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 40c5314ee..0b17043ef 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -10,7 +10,7 @@ #include "ButtonsDescription.hpp" #include "OG_CustomCtrl.hpp" #include "GLCanvas3D.hpp" -#include "ConfigWizard_private.hpp" +#include "ConfigWizard.hpp" #include diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp index 15a957692..4ae93f6f9 100644 --- a/src/slic3r/GUI/Preferences.hpp +++ b/src/slic3r/GUI/Preferences.hpp @@ -59,7 +59,7 @@ class PreferencesDialog : public DPIDialog wxColourPickerCtrl* m_mode_advanced { nullptr }; wxColourPickerCtrl* m_mode_expert { nullptr }; - DownloaderUtils::Worker* downloader{ nullptr }; + DownloaderUtils::Worker* downloader { nullptr }; wxBookCtrlBase* tabs {nullptr};