From 0abd4a0ae0945c65e61a3bab619e5c8ef615b7ab Mon Sep 17 00:00:00 2001 From: David Kocik Date: Mon, 17 Jun 2024 13:49:14 +0200 Subject: [PATCH 01/10] missing includes --- src/slic3r/GUI/UserAccountCommunication.cpp | 1 + src/slic3r/GUI/UserAccountCommunication.hpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/slic3r/GUI/UserAccountCommunication.cpp b/src/slic3r/GUI/UserAccountCommunication.cpp index 25e3c70e09..47422c7bb0 100644 --- a/src/slic3r/GUI/UserAccountCommunication.cpp +++ b/src/slic3r/GUI/UserAccountCommunication.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/src/slic3r/GUI/UserAccountCommunication.hpp b/src/slic3r/GUI/UserAccountCommunication.hpp index bbbe914308..56325e722f 100644 --- a/src/slic3r/GUI/UserAccountCommunication.hpp +++ b/src/slic3r/GUI/UserAccountCommunication.hpp @@ -5,6 +5,8 @@ #include "Event.hpp" #include "libslic3r/AppConfig.hpp" +#include + #include #include #include From 0af38e5507d6090ddaa589ac97852f5f096bd4d3 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Mon, 17 Jun 2024 15:21:42 +0200 Subject: [PATCH 02/10] test of login webview --- src/slic3r/GUI/Plater.cpp | 11 +++++++++-- src/slic3r/GUI/WebViewDialog.hpp | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index cc2ce67606..21115d5602 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -868,7 +868,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) BOOST_LOG_TRIVIAL(trace) << "Received login from other instance event."; user_account->on_login_code_recieved(evt.data); }); - this->q->Bind(EVT_OPEN_PRUSAAUTH, [](OpenPrusaAuthEvent& evt) { + this->q->Bind(EVT_OPEN_PRUSAAUTH, [this](OpenPrusaAuthEvent& evt) { BOOST_LOG_TRIVIAL(info) << "open browser: " << evt.data; // first register url to be sure to get the code back //auto downloader_worker = new DownloaderUtils::Worker(nullptr); @@ -878,7 +878,14 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) DesktopIntegrationDialog::perform_downloader_desktop_integration(); #endif // __linux__ // than open url - wxGetApp().open_login_browser_with_dialog(evt.data); + //wxGetApp().open_login_browser_with_dialog(evt.data); + + WebViewDialog dlg(this->q + , evt.data + , _L("Log in") + , wxSize(std::max(this->q->GetClientSize().x / 2, 100 * wxGetApp().em_unit()), std::max(this->q->GetClientSize().y / 2, 50 * wxGetApp().em_unit())) + ,{}); + dlg.ShowModal(); }); this->q->Bind(EVT_UA_LOGGEDOUT, [this](UserAccountSuccessEvent& evt) { diff --git a/src/slic3r/GUI/WebViewDialog.hpp b/src/slic3r/GUI/WebViewDialog.hpp index 715c645c9e..145304fe33 100644 --- a/src/slic3r/GUI/WebViewDialog.hpp +++ b/src/slic3r/GUI/WebViewDialog.hpp @@ -104,8 +104,8 @@ public: WebViewDialog(wxWindow* parent, const wxString& url, const wxString& dialog_name, const wxSize& size, const std::vector& message_handler_names, const std::string& loading_html = "loading"); virtual ~WebViewDialog(); - virtual void on_show(wxShowEvent& evt) = 0; - virtual void on_script_message(wxWebViewEvent& evt) = 0; + virtual void on_show(wxShowEvent& evt) {}; + virtual void on_script_message(wxWebViewEvent& evt); void on_idle(wxIdleEvent& evt); void on_url(wxCommandEvent& evt); From b2e80bd5be72184ddf33cc9d4837ee51b86c6181 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 19 Jun 2024 09:40:29 +0200 Subject: [PATCH 03/10] prototype of inner login dialog --- src/slic3r/GUI/Plater.cpp | 32 ++++++++++++++++---------------- src/slic3r/GUI/WebViewDialog.cpp | 27 ++++++++++++++++++++++++++- src/slic3r/GUI/WebViewDialog.hpp | 11 +++++++++++ 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 21115d5602..2b10fcfb6b 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -869,24 +869,24 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) user_account->on_login_code_recieved(evt.data); }); this->q->Bind(EVT_OPEN_PRUSAAUTH, [this](OpenPrusaAuthEvent& evt) { - BOOST_LOG_TRIVIAL(info) << "open browser: " << evt.data; - // first register url to be sure to get the code back - //auto downloader_worker = new DownloaderUtils::Worker(nullptr); - DownloaderUtils::Worker::perform_register(wxGetApp().app_config->get("url_downloader_dest")); + BOOST_LOG_TRIVIAL(info) << "open browser: " << evt.data; + // first register url to be sure to get the code back + //auto downloader_worker = new DownloaderUtils::Worker(nullptr); + DownloaderUtils::Worker::perform_register(wxGetApp().app_config->get("url_downloader_dest")); #ifdef __linux__ - if (DownloaderUtils::Worker::perform_registration_linux) - DesktopIntegrationDialog::perform_downloader_desktop_integration(); - #endif // __linux__ - // than open url - //wxGetApp().open_login_browser_with_dialog(evt.data); + if (DownloaderUtils::Worker::perform_registration_linux) + DesktopIntegrationDialog::perform_downloader_desktop_integration(); + #endif // __linux__ + // than open url + //wxGetApp().open_login_browser_with_dialog(evt.data); - WebViewDialog dlg(this->q - , evt.data - , _L("Log in") - , wxSize(std::max(this->q->GetClientSize().x / 2, 100 * wxGetApp().em_unit()), std::max(this->q->GetClientSize().y / 2, 50 * wxGetApp().em_unit())) - ,{}); - dlg.ShowModal(); - }); + std::string dialog_msg; + LoginWebViewDialog dialog(this->q, dialog_msg, evt.data); + if (dialog.ShowModal() != wxID_OK) { + return; + } + user_account->on_login_code_recieved(dialog_msg); + }); this->q->Bind(EVT_UA_LOGGEDOUT, [this](UserAccountSuccessEvent& evt) { user_account->clear(); diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index a370beedb0..2aabf2d927 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -860,6 +860,7 @@ WebViewDialog::WebViewDialog(wxWindow* parent, const wxString& url, const wxStri Bind(wxEVT_MENU, &WebViewDialog::on_run_script_custom, this, m_script_custom->GetId()); Bind(wxEVT_MENU, &WebViewDialog::on_add_user_script, this, addUserScript->GetId()); #endif + Bind(wxEVT_WEBVIEW_NAVIGATING, &WebViewDialog::on_navigation_request, this, m_browser->GetId()); Bind(wxEVT_CLOSE_WINDOW, ([this](wxCloseEvent& evt) { EndModal(wxID_CANCEL); })); @@ -943,6 +944,11 @@ void WebViewDialog::on_reload_button(wxCommandEvent& WXUNUSED(evt)) m_browser->Reload(); } + +void WebViewDialog::on_navigation_request(wxWebViewEvent &evt) +{ +} + void WebViewDialog::on_script_message(wxWebViewEvent& evt) { } @@ -1248,6 +1254,25 @@ void PrinterPickWebViewDialog::request_compatible_printers_SLA() wxString script = GUI::format_wxstr("window._prusaConnect_v1.requestCompatiblePrinter(%1%)", request); run_script(script); } - +LoginWebViewDialog::LoginWebViewDialog(wxWindow *parent, std::string &ret_val, const wxString& url) + : WebViewDialog(parent + , url + , _L("Log in dialog") + , wxSize(std::max(parent->GetClientSize().x / 2, 100 * wxGetApp().em_unit()), std::max(parent->GetClientSize().y / 2, 50 * wxGetApp().em_unit())) + , {}) + , m_ret_val(ret_val) +{ + Centre(); +} +void LoginWebViewDialog::on_navigation_request(wxWebViewEvent &evt) +{ + BOOST_LOG_TRIVIAL(error) << evt.GetURL(); + wxString url = evt.GetURL(); + if (url.starts_with(L"prusaslicer")) { + evt.Veto(); + m_ret_val = into_u8(url); + EndModal(wxID_OK); + } +} } // GUI } // Slic3r diff --git a/src/slic3r/GUI/WebViewDialog.hpp b/src/slic3r/GUI/WebViewDialog.hpp index 145304fe33..4aa7c5d017 100644 --- a/src/slic3r/GUI/WebViewDialog.hpp +++ b/src/slic3r/GUI/WebViewDialog.hpp @@ -127,6 +127,8 @@ public: void on_select_all(wxCommandEvent& evt); void On_enable_context_menu(wxCommandEvent& evt); void On_enable_dev_tools(wxCommandEvent& evt); + + virtual void on_navigation_request(wxWebViewEvent &evt); void run_script(const wxString& javascript); @@ -247,6 +249,15 @@ public: SourceViewDialog(wxWindow* parent, wxString source); }; +class LoginWebViewDialog : public WebViewDialog +{ +public: + LoginWebViewDialog(wxWindow *parent, std::string &ret_val, const wxString& url); + void on_navigation_request(wxWebViewEvent &evt) override; +private: + std::string &m_ret_val; +}; + } // GUI } // Slic3r From fd205c937c6ac571b1d91dc160e5fabafed73e2a Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 19 Jun 2024 17:26:59 +0200 Subject: [PATCH 04/10] login logout dialog --- src/slic3r/GUI/Plater.cpp | 3 +++ src/slic3r/GUI/WebViewDialog.cpp | 18 ++++++++++++++++-- src/slic3r/GUI/WebViewDialog.hpp | 9 +++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 2b10fcfb6b..f3dd42a779 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -901,6 +901,9 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) wxGetApp().update_login_dialog(); #endif // 0 this->show_action_buttons(this->ready_to_slice); + + LogoutWebViewDialog dlg(this->q); + dlg.ShowModal(); }); this->q->Bind(EVT_UA_ID_USER_SUCCESS, [this](UserAccountSuccessEvent& evt) { diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index 2aabf2d927..86afd21280 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -861,6 +861,7 @@ WebViewDialog::WebViewDialog(wxWindow* parent, const wxString& url, const wxStri Bind(wxEVT_MENU, &WebViewDialog::on_add_user_script, this, addUserScript->GetId()); #endif Bind(wxEVT_WEBVIEW_NAVIGATING, &WebViewDialog::on_navigation_request, this, m_browser->GetId()); + Bind(wxEVT_WEBVIEW_LOADED, &WebViewDialog::on_loaded, this, m_browser->GetId()); Bind(wxEVT_CLOSE_WINDOW, ([this](wxCloseEvent& evt) { EndModal(wxID_CANCEL); })); @@ -1258,7 +1259,7 @@ LoginWebViewDialog::LoginWebViewDialog(wxWindow *parent, std::string &ret_val, c : WebViewDialog(parent , url , _L("Log in dialog") - , wxSize(std::max(parent->GetClientSize().x / 2, 100 * wxGetApp().em_unit()), std::max(parent->GetClientSize().y / 2, 50 * wxGetApp().em_unit())) + , wxSize(std::max(parent->GetClientSize().x / 2, 100 * wxGetApp().em_unit()), std::max(parent->GetClientSize().y / 4 * 3, 50 * wxGetApp().em_unit())) , {}) , m_ret_val(ret_val) { @@ -1266,7 +1267,6 @@ LoginWebViewDialog::LoginWebViewDialog(wxWindow *parent, std::string &ret_val, c } void LoginWebViewDialog::on_navigation_request(wxWebViewEvent &evt) { - BOOST_LOG_TRIVIAL(error) << evt.GetURL(); wxString url = evt.GetURL(); if (url.starts_with(L"prusaslicer")) { evt.Veto(); @@ -1274,5 +1274,19 @@ void LoginWebViewDialog::on_navigation_request(wxWebViewEvent &evt) EndModal(wxID_OK); } } + +LogoutWebViewDialog::LogoutWebViewDialog(wxWindow *parent) + : WebViewDialog(parent + , L"https://account.prusa3d.com/logout" + , _L("Logout dialog") + , wxSize(std::max(parent->GetClientSize().x / 4, 10 * wxGetApp().em_unit()), std::max(parent->GetClientSize().y / 4, 10 * wxGetApp().em_unit())) + , {}) +{ + Centre(); +} +void LogoutWebViewDialog::on_loaded(wxWebViewEvent &evt) +{ + EndModal(wxID_OK); +} } // GUI } // Slic3r diff --git a/src/slic3r/GUI/WebViewDialog.hpp b/src/slic3r/GUI/WebViewDialog.hpp index 4aa7c5d017..8f4c9af4b7 100644 --- a/src/slic3r/GUI/WebViewDialog.hpp +++ b/src/slic3r/GUI/WebViewDialog.hpp @@ -129,6 +129,7 @@ public: void On_enable_dev_tools(wxCommandEvent& evt); virtual void on_navigation_request(wxWebViewEvent &evt); + virtual void on_loaded(wxWebViewEvent &evt) {} void run_script(const wxString& javascript); @@ -254,10 +255,18 @@ class LoginWebViewDialog : public WebViewDialog public: LoginWebViewDialog(wxWindow *parent, std::string &ret_val, const wxString& url); void on_navigation_request(wxWebViewEvent &evt) override; + private: std::string &m_ret_val; }; +class LogoutWebViewDialog : public WebViewDialog +{ +public: + LogoutWebViewDialog(wxWindow* parent); + void on_loaded(wxWebViewEvent &evt) override; +}; + } // GUI } // Slic3r From b60fb76a4b5ec0bf78dce0e61b99061c296a82cf Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 20 Jun 2024 16:25:32 +0200 Subject: [PATCH 05/10] Login in config wizard --- src/slic3r/CMakeLists.txt | 2 + src/slic3r/GUI/ConfigWizard.cpp | 12 ++- src/slic3r/GUI/ConfigWizard.hpp | 1 + src/slic3r/GUI/ConfigWizardWebViewPage.cpp | 97 +++++++++++++++++++++ src/slic3r/GUI/ConfigWizardWebViewPage.hpp | 63 +++++++++++++ src/slic3r/GUI/ConfigWizard_private.hpp | 2 + src/slic3r/GUI/GUI_App.cpp | 17 ++-- src/slic3r/GUI/GUI_App.hpp | 11 +-- src/slic3r/GUI/Plater.cpp | 16 ++-- src/slic3r/GUI/UserAccount.hpp | 1 + src/slic3r/GUI/UserAccountCommunication.cpp | 8 +- src/slic3r/GUI/UserAccountCommunication.hpp | 1 + src/slic3r/GUI/WebView.cpp | 2 +- src/slic3r/GUI/WebView.hpp | 2 +- src/slic3r/GUI/WebViewDialog.cpp | 2 +- 15 files changed, 206 insertions(+), 31 deletions(-) create mode 100644 src/slic3r/GUI/ConfigWizardWebViewPage.cpp create mode 100644 src/slic3r/GUI/ConfigWizardWebViewPage.hpp diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index e05de4013f..16ccee31cf 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -215,6 +215,8 @@ set(SLIC3R_GUI_SOURCES GUI/ConfigWizard.cpp GUI/ConfigWizard.hpp GUI/ConfigWizard_private.hpp + GUI/ConfigWizardWebViewPage.cpp + GUI/ConfigWizardWebViewPage.hpp GUI/MsgDialog.cpp GUI/MsgDialog.hpp GUI/UpdateDialogs.cpp diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index e2c5119b6b..ef96b4b1ee 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -10,6 +10,7 @@ // FIXME: extract absolute units -> em #include "ConfigWizard_private.hpp" +#include "ConfigWizardWebViewPage.hpp" #include #include @@ -2586,6 +2587,7 @@ void ConfigWizard::priv::load_pages() index->clear(); index->add_page(page_welcome); + index->add_page(page_login); index->add_page(page_update_manager); if (is_config_from_archive) { @@ -2772,7 +2774,7 @@ void ConfigWizard::priv::load_vendors() void ConfigWizard::priv::add_page(ConfigWizardPage *page) { - const int proportion = (page->shortname == _L("Filaments")) || (page->shortname == _L("SLA Materials")) ? 1 : 0; + const int proportion = (page->shortname == _L("Filaments")) || (page->shortname == _L("SLA Materials") || page->shortname == _L("Log in")) ? 1 : 0; hscroll_sizer->Add(page, proportion, wxEXPAND); all_pages.push_back(page); } @@ -3981,6 +3983,7 @@ ConfigWizard::ConfigWizard(wxWindow *parent) wxGetApp().SetWindowVariantForButton(p->btn_cancel); p->add_page(p->page_welcome = new PageWelcome(this)); + p->add_page(p->page_login = new ConfigWizardWebViewPage(this)); p->add_page(p->page_update_manager = new PageUpdateManager(this)); // other pages will be loaded later after confirm repositories selection @@ -4132,6 +4135,13 @@ bool ConfigWizard::run(RunReason reason, StartPage start_page) } } +void ConfigWizard::update_login() +{ + if(p->page_login) { + p->page_login->login_changed(); + } +} + const wxString& ConfigWizard::name(const bool from_menu/* = false*/) { // A different naming convention is used for the Wizard on Windows & GTK vs. OSX. diff --git a/src/slic3r/GUI/ConfigWizard.hpp b/src/slic3r/GUI/ConfigWizard.hpp index 9156d3dfee..ba39d531ac 100644 --- a/src/slic3r/GUI/ConfigWizard.hpp +++ b/src/slic3r/GUI/ConfigWizard.hpp @@ -87,6 +87,7 @@ public: // Run the Wizard. Return whether it was completed. bool run(RunReason reason, StartPage start_page = SP_WELCOME); + void update_login(); static const wxString& name(const bool from_menu = false); protected: diff --git a/src/slic3r/GUI/ConfigWizardWebViewPage.cpp b/src/slic3r/GUI/ConfigWizardWebViewPage.cpp new file mode 100644 index 0000000000..656bcc05db --- /dev/null +++ b/src/slic3r/GUI/ConfigWizardWebViewPage.cpp @@ -0,0 +1,97 @@ +#include "ConfigWizardWebViewPage.hpp" + +#include "WebView.hpp" +#include "UserAccount.hpp" +#include "GUI_App.hpp" +#include "Plater.hpp" +#include "slic3r/GUI/I18N.hpp" + +#include + +namespace Slic3r { +namespace GUI { +wxDEFINE_EVENT(EVT_LOGIN_VIA_WIZARD, Event); + +ConfigWizardWebViewPage::ConfigWizardWebViewPage(ConfigWizard *parent) + // TRN Config wizard page headline. + : ConfigWizardPage(parent, _L("Log into the Prusa Account"), _L("Log in")) +{ + p_user_account = wxGetApp().plater()->get_user_account(); + assert(p_user_account); + bool logged = p_user_account->is_logged(); + + // Create the webview + m_browser_sizer = new wxBoxSizer(wxHORIZONTAL); + m_browser = WebView::CreateWebView(this, p_user_account->get_login_redirect_url(), {}); + if (!m_browser) { + // TRN Config wizard page with a log in page. + wxStaticText* fail_text = new wxStaticText(this, wxID_ANY, _L("Failed to load a web browser. Logging in is not possible in the moment.")); + append(fail_text); + return; + } + if (logged) { + // TRN Config wizard page with a log in web. + m_text = new wxStaticText(this, wxID_ANY, format_wxstr("You are logged as %1%.", p_user_account->get_username())); + } else { + // TRN Config wizard page with a log in web. + m_text = new wxStaticText(this, wxID_ANY, _L("Please log into your Prusa Account. This step is not mandatory.")); + } + append(m_text); + m_browser_sizer->Add(m_browser, 1, wxEXPAND); + append(m_browser_sizer, 1, wxEXPAND); + + m_browser_sizer->Show(!logged); + + // Connect the webview events + Bind(wxEVT_WEBVIEW_ERROR, &ConfigWizardWebViewPage::on_error, this, m_browser->GetId()); + Bind(wxEVT_WEBVIEW_NAVIGATING, &ConfigWizardWebViewPage::on_navigation_request, this, m_browser->GetId()); + +} + +void ConfigWizardWebViewPage::login_changed() +{ + assert(p_user_account && m_browser_sizer && m_text); + bool logged = p_user_account->is_logged(); + m_browser_sizer->Show(!logged); + if (logged) { + // TRN Config wizard page with a log in web. + m_text->SetLabel(format_wxstr("You are logged as %1%.", p_user_account->get_username())); + } else { + // TRN Config wizard page with a log in web. + m_text->SetLabel(_L("Please log into your Prusa Account. This step is not mandatory.")); + } +} + +void ConfigWizardWebViewPage::on_error(wxWebViewEvent &evt) +{ +#define WX_ERROR_CASE(type) \ +case type: \ + category = #type; \ + break; + + wxString category; + switch (evt.GetInt()) + { + WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_CONNECTION); + WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_CERTIFICATE); + WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_AUTH); + WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_SECURITY); + WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_NOT_FOUND); + WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_REQUEST); + WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_USER_CANCELLED); + WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_OTHER); + } + + BOOST_LOG_TRIVIAL(error) << "WebViewPanel error: " << category; +} + +void ConfigWizardWebViewPage::on_navigation_request(wxWebViewEvent &evt) +{ + wxString url = evt.GetURL(); + if (url.starts_with(L"prusaslicer")) { + evt.Veto(); + wxPostEvent(wxGetApp().plater(), Event(EVT_LOGIN_VIA_WIZARD, into_u8(url))); + } +} + +}} // namespace Slic3r::GUI \ No newline at end of file diff --git a/src/slic3r/GUI/ConfigWizardWebViewPage.hpp b/src/slic3r/GUI/ConfigWizardWebViewPage.hpp new file mode 100644 index 0000000000..193e66db6d --- /dev/null +++ b/src/slic3r/GUI/ConfigWizardWebViewPage.hpp @@ -0,0 +1,63 @@ +#ifndef slic3r_ConfigWizardWebViewPage_hpp_ +#define slic3r_ConfigWizardWebViewPage_hpp_ + +#include "ConfigWizard_private.hpp" +#include "Event.hpp" + +class wxWebView; +class wxWebViewEvent; + +namespace Slic3r { +namespace GUI { + +wxDECLARE_EVENT(EVT_LOGIN_VIA_WIZARD, Event); +/* +struct ConfigWizardPage: wxPanel +{ + ConfigWizard *parent; + const wxString shortname; + wxBoxSizer *content; + const unsigned indent; + + ConfigWizardPage(ConfigWizard *parent, wxString title, wxString shortname, unsigned indent = 0); + virtual ~ConfigWizardPage(); + + template + T* append(T *thing, int proportion = 0, int flag = wxEXPAND|wxTOP|wxBOTTOM, int border = 10) + { + content->Add(thing, proportion, flag, border); + return thing; + } + + wxStaticText* append_text(wxString text); + void append_spacer(int space); + + ConfigWizard::priv *wizard_p() const { return parent->p.get(); } + + virtual void apply_custom_config(DynamicPrintConfig &config) {} + virtual void set_run_reason(ConfigWizard::RunReason run_reason) {} + virtual void on_activate() {} +}; +*/ + +class UserAccount; +class ConfigWizardWebViewPage : public ConfigWizardPage +{ +public: + ConfigWizardWebViewPage( ConfigWizard *parent); + virtual ~ConfigWizardWebViewPage() {} + + void on_error(wxWebViewEvent &evt); + void on_navigation_request(wxWebViewEvent &evt); + + void login_changed(); + +private: + wxWebView *m_browser{nullptr}; + UserAccount *p_user_account{nullptr}; + wxBoxSizer *m_browser_sizer{nullptr}; + wxStaticText *m_text{nullptr}; +}; + +}} // namespace Slic3r::GUI +#endif \ No newline at end of file diff --git a/src/slic3r/GUI/ConfigWizard_private.hpp b/src/slic3r/GUI/ConfigWizard_private.hpp index d224d97146..8f5173f29e 100644 --- a/src/slic3r/GUI/ConfigWizard_private.hpp +++ b/src/slic3r/GUI/ConfigWizard_private.hpp @@ -98,6 +98,7 @@ struct BundleMap : std::map struct Materials; class RepositoryUpdateUIManager; +class ConfigWizardWebViewPage; struct PrinterPickerEvent; @@ -631,6 +632,7 @@ struct ConfigWizard::priv wxButton *btn_cancel = nullptr; PageWelcome *page_welcome = nullptr; + ConfigWizardWebViewPage *page_login = nullptr; PageUpdateManager*page_update_manager = nullptr; PageMaterials *page_filaments = nullptr; PageMaterials *page_sla_materials = nullptr; diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 25b2cb6cef..0e61552b05 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -3286,18 +3286,19 @@ bool GUI_App::run_wizard(ConfigWizard::RunReason reason, ConfigWizard::StartPage preset_updater->config_update(app_config->orig_version(), PresetUpdater::UpdateParams::SHOW_TEXT_BOX, repos); } - auto wizard = new ConfigWizard(mainframe); + m_config_wizard = new ConfigWizard(mainframe); cw_loading_dlg->Close(); - const bool res = wizard->run(reason, start_page); + const bool res = m_config_wizard->run(reason, start_page); // !!! Deallocate memory after close ConfigWizard. // Note, that mainframe is a parent of ConfigWizard. // So, wizard will be destroyed only during destroying of mainframe // To avoid this state the wizard have to be disconnected from mainframe and Destroyed explicitly - mainframe->RemoveChild(wizard); - wizard->Destroy(); + mainframe->RemoveChild(m_config_wizard); + m_config_wizard->Destroy(); + m_config_wizard = nullptr; if (res) { load_current_presets(); @@ -3309,15 +3310,13 @@ bool GUI_App::run_wizard(ConfigWizard::RunReason reason, ConfigWizard::StartPage return res; } -#if 0 -void GUI_App::update_login_dialog() +void GUI_App::update_wizard_login_page() { - if (!m_login_dialog) { + if (!m_config_wizard) { return; } - m_login_dialog->update_account(); + m_config_wizard->update_login(); } -#endif // 0 void GUI_App::show_desktop_integration_dialog() { diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index e540394f7f..a0b2bbe4b3 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -59,7 +59,6 @@ class NotificationManager; class Downloader; struct GUI_InitParams; class GalleryDialog; -class LoginDialog; class PresetArchiveDatabase; enum FileType @@ -371,9 +370,7 @@ public: void open_web_page_localized(const std::string &http_address); bool may_switch_to_SLA_preset(const wxString& caption); bool run_wizard(ConfigWizard::RunReason reason, ConfigWizard::StartPage start_page = ConfigWizard::SP_WELCOME); -#if 0 - void update_login_dialog(); -#endif // 0 + void update_wizard_login_page(); void show_desktop_integration_dialog(); void show_downloader_registration_dialog(); @@ -454,9 +451,9 @@ private: // change to vector of items when adding more items that require update //wxMenuItem* m_login_config_menu_item { nullptr }; std::map< ConfigMenuIDs, wxMenuItem*> m_config_menu_updatable_items; -#if 0 - std::unique_ptr m_login_dialog; -#endif // 0 + + ConfigWizard* m_config_wizard {nullptr}; + }; DECLARE_APP(GUI_App) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f3dd42a779..574f2f370b 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -97,6 +97,7 @@ #include "Mouse3DController.hpp" #include "Tab.hpp" #include "Jobs/ArrangeJob2.hpp" +#include "ConfigWizardWebViewPage.hpp" #include "Jobs/RotoptimizeJob.hpp" #include "Jobs/SLAImportJob.hpp" @@ -868,6 +869,10 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) BOOST_LOG_TRIVIAL(trace) << "Received login from other instance event."; user_account->on_login_code_recieved(evt.data); }); + this->q->Bind(EVT_LOGIN_VIA_WIZARD, [this](Event &evt) { + BOOST_LOG_TRIVIAL(trace) << "Received login from wizard."; + user_account->on_login_code_recieved(evt.data); + }); this->q->Bind(EVT_OPEN_PRUSAAUTH, [this](OpenPrusaAuthEvent& evt) { BOOST_LOG_TRIVIAL(info) << "open browser: " << evt.data; // first register url to be sure to get the code back @@ -897,9 +902,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) this->main_frame->refresh_account_menu(true); // Update sidebar printer status sidebar->update_printer_presets_combobox(); -#if 0 - wxGetApp().update_login_dialog(); -#endif // 0 + wxGetApp().update_wizard_login_page(); this->show_action_buttons(this->ready_to_slice); LogoutWebViewDialog dlg(this->q); @@ -919,9 +922,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) this->main_frame->add_connect_webview_tab(); // Update User name in TopBar this->main_frame->refresh_account_menu(); -#if 0 - wxGetApp().update_login_dialog(); -#endif // 0 + wxGetApp().update_wizard_login_page(); this->show_action_buttons(this->ready_to_slice); } else { @@ -990,9 +991,6 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) fwrite(evt.data.c_str(), 1, evt.data.size(), file); fclose(file); this->main_frame->refresh_account_menu(true); -#if 0 - wxGetApp().update_login_dialog(); -#endif // 0 }); this->q->Bind(EVT_UA_PRUSACONNECT_PRINTER_DATA_SUCCESS, [this](UserAccountSuccessEvent& evt) { this->user_account->set_current_printer_data(evt.data); diff --git a/src/slic3r/GUI/UserAccount.hpp b/src/slic3r/GUI/UserAccount.hpp index d75d1d325f..d241f778be 100644 --- a/src/slic3r/GUI/UserAccount.hpp +++ b/src/slic3r/GUI/UserAccount.hpp @@ -38,6 +38,7 @@ public: bool is_logged(); void do_login(); void do_logout(); + wxString get_login_redirect_url() { return m_communication->get_login_redirect_url(); } void set_remember_session(bool remember); void toggle_remember_session(); diff --git a/src/slic3r/GUI/UserAccountCommunication.cpp b/src/slic3r/GUI/UserAccountCommunication.cpp index 47422c7bb0..9c9df93a76 100644 --- a/src/slic3r/GUI/UserAccountCommunication.cpp +++ b/src/slic3r/GUI/UserAccountCommunication.cpp @@ -257,8 +257,7 @@ void UserAccountCommunication::on_uuid_map_success() } } -void UserAccountCommunication::login_redirect() -{ +wxString UserAccountCommunication::get_login_redirect_url() { const std::string AUTH_HOST = "https://account.prusa3d.com"; const std::string CLIENT_ID = client_id(); const std::string REDIRECT_URI = "prusaslicer://login"; @@ -270,6 +269,11 @@ void UserAccountCommunication::login_redirect() wxString url = GUI::format_wxstr(L"%1%/o/authorize/?client_id=%2%&response_type=code&code_challenge=%3%&code_challenge_method=S256&scope=basic_info&redirect_uri=%4%&choose_account=1", AUTH_HOST, CLIENT_ID, code_challenge, REDIRECT_URI); + return url; +} +void UserAccountCommunication::login_redirect() +{ + wxString url = get_login_redirect_url(); wxQueueEvent(m_evt_handler,new OpenPrusaAuthEvent(GUI::EVT_OPEN_PRUSAAUTH, std::move(url))); } diff --git a/src/slic3r/GUI/UserAccountCommunication.hpp b/src/slic3r/GUI/UserAccountCommunication.hpp index 56325e722f..9dfc8dca49 100644 --- a/src/slic3r/GUI/UserAccountCommunication.hpp +++ b/src/slic3r/GUI/UserAccountCommunication.hpp @@ -42,6 +42,7 @@ public: void do_login(); void do_logout(); void do_clear(); + wxString get_login_redirect_url(); // Trigger function starts various remote operations void enqueue_connect_status_action(); void enqueue_connect_printer_models_action(); diff --git a/src/slic3r/GUI/WebView.cpp b/src/slic3r/GUI/WebView.cpp index d9b5c55e85..85a537ae6c 100644 --- a/src/slic3r/GUI/WebView.cpp +++ b/src/slic3r/GUI/WebView.cpp @@ -7,7 +7,7 @@ #include -wxWebView* WebView::CreateWebView(wxWindow * parent, const wxString& url, std::vector& message_handlers) +wxWebView* WebView::CreateWebView(wxWindow * parent, const wxString& url, const std::vector& message_handlers) { #if wxUSE_WEBVIEW_EDGE bool backend_available = wxWebView::IsBackendAvailable(wxWebViewBackendEdge); diff --git a/src/slic3r/GUI/WebView.hpp b/src/slic3r/GUI/WebView.hpp index 8ea20a44da..c7c4c79ef2 100644 --- a/src/slic3r/GUI/WebView.hpp +++ b/src/slic3r/GUI/WebView.hpp @@ -10,7 +10,7 @@ class wxString; namespace WebView { - wxWebView *CreateWebView(wxWindow *parent, const wxString& url, std::vector& message_handlers); + wxWebView *CreateWebView(wxWindow *parent, const wxString& url, const std::vector& message_handlers); }; #endif // !slic3r_GUI_WebView_hpp_ diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index 86afd21280..2688d1798b 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -1259,7 +1259,7 @@ LoginWebViewDialog::LoginWebViewDialog(wxWindow *parent, std::string &ret_val, c : WebViewDialog(parent , url , _L("Log in dialog") - , wxSize(std::max(parent->GetClientSize().x / 2, 100 * wxGetApp().em_unit()), std::max(parent->GetClientSize().y / 4 * 3, 50 * wxGetApp().em_unit())) + , wxSize(parent->GetClientSize().x / 3, parent->GetClientSize().y / 4 * 3) , {}) , m_ret_val(ret_val) { From bb64571751a8bb24578f683c76caaba5f36cce13 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 20 Jun 2024 16:42:35 +0200 Subject: [PATCH 06/10] embed=1 and language code in url --- src/slic3r/GUI/UserAccountCommunication.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/UserAccountCommunication.cpp b/src/slic3r/GUI/UserAccountCommunication.cpp index 9c9df93a76..4b0e854e0f 100644 --- a/src/slic3r/GUI/UserAccountCommunication.cpp +++ b/src/slic3r/GUI/UserAccountCommunication.cpp @@ -264,10 +264,12 @@ wxString UserAccountCommunication::get_login_redirect_url() { CodeChalengeGenerator ccg; m_code_verifier = ccg.generate_verifier(); std::string code_challenge = ccg.generate_chalenge(m_code_verifier); + wxString language = GUI::wxGetApp().current_language_code(); + language = language.SubString(0, 1); BOOST_LOG_TRIVIAL(info) << "code verifier: " << m_code_verifier; BOOST_LOG_TRIVIAL(info) << "code challenge: " << code_challenge; - wxString url = GUI::format_wxstr(L"%1%/o/authorize/?client_id=%2%&response_type=code&code_challenge=%3%&code_challenge_method=S256&scope=basic_info&redirect_uri=%4%&choose_account=1", AUTH_HOST, CLIENT_ID, code_challenge, REDIRECT_URI); + wxString url = GUI::format_wxstr(L"%1%/o/authorize/?embed=1&client_id=%2%&response_type=code&code_challenge=%3%&code_challenge_method=S256&scope=basic_info&redirect_uri=%4%&choose_account=1&language=%5%", AUTH_HOST, CLIENT_ID, code_challenge, REDIRECT_URI, language); return url; } From c4bc5ef0b09d466bbec0ba3861eeb025c4999aeb Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 20 Jun 2024 17:51:08 +0200 Subject: [PATCH 07/10] Improved text --- src/slic3r/GUI/ConfigWizardWebViewPage.cpp | 19 +++++++++++++------ src/slic3r/GUI/ConfigWizardWebViewPage.hpp | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/ConfigWizardWebViewPage.cpp b/src/slic3r/GUI/ConfigWizardWebViewPage.cpp index 656bcc05db..a97b44f30e 100644 --- a/src/slic3r/GUI/ConfigWizardWebViewPage.cpp +++ b/src/slic3r/GUI/ConfigWizardWebViewPage.cpp @@ -5,6 +5,7 @@ #include "GUI_App.hpp" #include "Plater.hpp" #include "slic3r/GUI/I18N.hpp" +#include "format.hpp" #include @@ -31,12 +32,17 @@ ConfigWizardWebViewPage::ConfigWizardWebViewPage(ConfigWizard *parent) } if (logged) { // TRN Config wizard page with a log in web. - m_text = new wxStaticText(this, wxID_ANY, format_wxstr("You are logged as %1%.", p_user_account->get_username())); + m_text = new wxStaticText(this, wxID_ANY, format_wxstr("You are logged as %1%.", p_user_account->get_username())); } else { - // TRN Config wizard page with a log in web. - m_text = new wxStaticText(this, wxID_ANY, _L("Please log into your Prusa Account. This step is not mandatory.")); + // TRN Config wizard page with a log in web. first line of text. + m_text = new wxStaticText(this, wxID_ANY, _L("Please log into your Prusa Account.")); + // TRN Config wizard page with a log in web. second line of text. + m_bold_text = new wxStaticText(this, wxID_ANY, _L("This step is optional.")); + m_bold_text->SetFont(wxGetApp().bold_font()); + m_bold_text->Wrap(WRAP_WIDTH); } append(m_text); + append(m_bold_text); m_browser_sizer->Add(m_browser, 1, wxEXPAND); append(m_browser_sizer, 1, wxEXPAND); @@ -50,15 +56,16 @@ ConfigWizardWebViewPage::ConfigWizardWebViewPage(ConfigWizard *parent) void ConfigWizardWebViewPage::login_changed() { - assert(p_user_account && m_browser_sizer && m_text); + assert(p_user_account && m_browser_sizer && m_text && m_bold_text); bool logged = p_user_account->is_logged(); m_browser_sizer->Show(!logged); + m_bold_text->Show(!logged); if (logged) { // TRN Config wizard page with a log in web. m_text->SetLabel(format_wxstr("You are logged as %1%.", p_user_account->get_username())); } else { - // TRN Config wizard page with a log in web. - m_text->SetLabel(_L("Please log into your Prusa Account. This step is not mandatory.")); + // TRN Config wizard page with a log in web. first line of text. + m_text->SetLabel(_L("Please log into your Prusa Account.")); } } diff --git a/src/slic3r/GUI/ConfigWizardWebViewPage.hpp b/src/slic3r/GUI/ConfigWizardWebViewPage.hpp index 193e66db6d..89398a49b5 100644 --- a/src/slic3r/GUI/ConfigWizardWebViewPage.hpp +++ b/src/slic3r/GUI/ConfigWizardWebViewPage.hpp @@ -57,6 +57,7 @@ private: UserAccount *p_user_account{nullptr}; wxBoxSizer *m_browser_sizer{nullptr}; wxStaticText *m_text{nullptr}; + wxStaticText *m_bold_text{nullptr}; }; }} // namespace Slic3r::GUI From 09dc8f01de1726e6d0da48d46809f564b01b8b93 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 20 Jun 2024 17:53:37 +0200 Subject: [PATCH 08/10] delete registration code --- src/slic3r/GUI/Plater.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 574f2f370b..dc4be1c4b7 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -874,17 +874,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) user_account->on_login_code_recieved(evt.data); }); this->q->Bind(EVT_OPEN_PRUSAAUTH, [this](OpenPrusaAuthEvent& evt) { - BOOST_LOG_TRIVIAL(info) << "open browser: " << evt.data; - // first register url to be sure to get the code back - //auto downloader_worker = new DownloaderUtils::Worker(nullptr); - DownloaderUtils::Worker::perform_register(wxGetApp().app_config->get("url_downloader_dest")); - #ifdef __linux__ - if (DownloaderUtils::Worker::perform_registration_linux) - DesktopIntegrationDialog::perform_downloader_desktop_integration(); - #endif // __linux__ - // than open url - //wxGetApp().open_login_browser_with_dialog(evt.data); - + BOOST_LOG_TRIVIAL(info) << "open login browser: " << evt.data; std::string dialog_msg; LoginWebViewDialog dialog(this->q, dialog_msg, evt.data); if (dialog.ShowModal() != wxID_OK) { From 68003fa119b5ec53c02f559a8ac8aaa8f7f969a7 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Fri, 21 Jun 2024 11:51:08 +0200 Subject: [PATCH 09/10] Init PageUpdateManager change --- src/slic3r/GUI/ConfigWizard.cpp | 8 ++++++-- src/slic3r/GUI/ConfigWizardWebViewPage.cpp | 3 ++- src/slic3r/GUI/ConfigWizardWebViewPage.hpp | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index ef96b4b1ee..c7bdfd48e5 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -4137,8 +4137,12 @@ bool ConfigWizard::run(RunReason reason, StartPage start_page) void ConfigWizard::update_login() { - if(p->page_login) { - p->page_login->login_changed(); + if(!p->page_login) { + return; + } + if (p->page_login->login_changed()) { + // repos changed - we need rebuild + p->set_config_updated_from_archive(p->is_config_from_archive, true); } } diff --git a/src/slic3r/GUI/ConfigWizardWebViewPage.cpp b/src/slic3r/GUI/ConfigWizardWebViewPage.cpp index a97b44f30e..72124b1af3 100644 --- a/src/slic3r/GUI/ConfigWizardWebViewPage.cpp +++ b/src/slic3r/GUI/ConfigWizardWebViewPage.cpp @@ -54,7 +54,7 @@ ConfigWizardWebViewPage::ConfigWizardWebViewPage(ConfigWizard *parent) } -void ConfigWizardWebViewPage::login_changed() +bool ConfigWizardWebViewPage::login_changed() { assert(p_user_account && m_browser_sizer && m_text && m_bold_text); bool logged = p_user_account->is_logged(); @@ -67,6 +67,7 @@ void ConfigWizardWebViewPage::login_changed() // TRN Config wizard page with a log in web. first line of text. m_text->SetLabel(_L("Please log into your Prusa Account.")); } + return logged; } void ConfigWizardWebViewPage::on_error(wxWebViewEvent &evt) diff --git a/src/slic3r/GUI/ConfigWizardWebViewPage.hpp b/src/slic3r/GUI/ConfigWizardWebViewPage.hpp index 89398a49b5..6c59abb7a7 100644 --- a/src/slic3r/GUI/ConfigWizardWebViewPage.hpp +++ b/src/slic3r/GUI/ConfigWizardWebViewPage.hpp @@ -49,8 +49,8 @@ public: void on_error(wxWebViewEvent &evt); void on_navigation_request(wxWebViewEvent &evt); - - void login_changed(); + // returns true if logged in - wizard needs to update repos + bool login_changed(); private: wxWebView *m_browser{nullptr}; From 4b352d8ff6086e6e0c8ef79329aef9cfe37daf68 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 21 Jun 2024 12:27:25 +0200 Subject: [PATCH 10/10] ConfigWizard: Update of "Configuration sources" page, when user is logged from "Login" page + Fixed some conflicts after "Login" page implementation --- src/slic3r/GUI/ConfigWizard.cpp | 16 ++++++++-------- src/slic3r/GUI/ConfigWizardWebViewPage.cpp | 9 ++------- src/slic3r/GUI/ConfigWizardWebViewPage.hpp | 1 - src/slic3r/GUI/ConfigWizard_private.hpp | 1 + src/slic3r/GUI/UpdatesUIManager.hpp | 4 ++-- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index c7bdfd48e5..427072f16a 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -678,7 +678,7 @@ PageUpdateManager::PageUpdateManager(ConfigWizard* parent_in) auto revert_page_selection = [this]() -> void { CallAfter([this]() { - wizard_p()->index->go_to(1); + wizard_p()->index->go_to(this); if (!this->IsShown()) this->Show(); }); @@ -2774,7 +2774,7 @@ void ConfigWizard::priv::load_vendors() void ConfigWizard::priv::add_page(ConfigWizardPage *page) { - const int proportion = (page->shortname == _L("Filaments")) || (page->shortname == _L("SLA Materials") || page->shortname == _L("Log in")) ? 1 : 0; + const int proportion = (page == page_login || page == page_filaments || page == page_sla_materials); hscroll_sizer->Add(page, proportion, wxEXPAND); all_pages.push_back(page); } @@ -4036,8 +4036,9 @@ ConfigWizard::ConfigWizard(wxWindow *parent) // In that case don't leave the page and the function above queried the user whether to install default materials. return; if (active_page == p->page_update_manager && p->index->active_is_last()) { + size_t next_active = p->index->pages_cnt(); p->page_update_manager->Hide(); - p->index->go_to(2); + p->index->go_to(next_active); return; } this->p->index->go_next(); @@ -4137,12 +4138,11 @@ bool ConfigWizard::run(RunReason reason, StartPage start_page) void ConfigWizard::update_login() { - if(!p->page_login) { - return; - } - if (p->page_login->login_changed()) { + if (p->page_login && p->page_login->login_changed()) { // repos changed - we need rebuild - p->set_config_updated_from_archive(p->is_config_from_archive, true); + wxGetApp().plater()->get_preset_archive_database()->sync_blocking(); + // now change PageUpdateManager + p->page_update_manager->manager->update(); } } diff --git a/src/slic3r/GUI/ConfigWizardWebViewPage.cpp b/src/slic3r/GUI/ConfigWizardWebViewPage.cpp index 72124b1af3..456350140c 100644 --- a/src/slic3r/GUI/ConfigWizardWebViewPage.cpp +++ b/src/slic3r/GUI/ConfigWizardWebViewPage.cpp @@ -15,7 +15,7 @@ wxDEFINE_EVENT(EVT_LOGIN_VIA_WIZARD, Event); ConfigWizardWebViewPage::ConfigWizardWebViewPage(ConfigWizard *parent) // TRN Config wizard page headline. - : ConfigWizardPage(parent, _L("Log into the Prusa Account"), _L("Log in")) + : ConfigWizardPage(parent, _L("Log into the Prusa Account (optional)"), _L("Log in (optional)")) { p_user_account = wxGetApp().plater()->get_user_account(); assert(p_user_account); @@ -37,12 +37,8 @@ ConfigWizardWebViewPage::ConfigWizardWebViewPage(ConfigWizard *parent) // TRN Config wizard page with a log in web. first line of text. m_text = new wxStaticText(this, wxID_ANY, _L("Please log into your Prusa Account.")); // TRN Config wizard page with a log in web. second line of text. - m_bold_text = new wxStaticText(this, wxID_ANY, _L("This step is optional.")); - m_bold_text->SetFont(wxGetApp().bold_font()); - m_bold_text->Wrap(WRAP_WIDTH); } append(m_text); - append(m_bold_text); m_browser_sizer->Add(m_browser, 1, wxEXPAND); append(m_browser_sizer, 1, wxEXPAND); @@ -56,10 +52,9 @@ ConfigWizardWebViewPage::ConfigWizardWebViewPage(ConfigWizard *parent) bool ConfigWizardWebViewPage::login_changed() { - assert(p_user_account && m_browser_sizer && m_text && m_bold_text); + assert(p_user_account && m_browser_sizer && m_text); bool logged = p_user_account->is_logged(); m_browser_sizer->Show(!logged); - m_bold_text->Show(!logged); if (logged) { // TRN Config wizard page with a log in web. m_text->SetLabel(format_wxstr("You are logged as %1%.", p_user_account->get_username())); diff --git a/src/slic3r/GUI/ConfigWizardWebViewPage.hpp b/src/slic3r/GUI/ConfigWizardWebViewPage.hpp index 6c59abb7a7..c05e6ebfeb 100644 --- a/src/slic3r/GUI/ConfigWizardWebViewPage.hpp +++ b/src/slic3r/GUI/ConfigWizardWebViewPage.hpp @@ -57,7 +57,6 @@ private: UserAccount *p_user_account{nullptr}; wxBoxSizer *m_browser_sizer{nullptr}; wxStaticText *m_text{nullptr}; - wxStaticText *m_bold_text{nullptr}; }; }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/ConfigWizard_private.hpp b/src/slic3r/GUI/ConfigWizard_private.hpp index 8f5173f29e..507448adcd 100644 --- a/src/slic3r/GUI/ConfigWizard_private.hpp +++ b/src/slic3r/GUI/ConfigWizard_private.hpp @@ -550,6 +550,7 @@ public: size_t active_item() const { return item_active; } ConfigWizardPage* active_page() const; bool active_is_last() const { return item_active < items.size() && item_active == last_page; } + size_t pages_cnt() const { return items.size(); } void go_prev(); void go_next(); diff --git a/src/slic3r/GUI/UpdatesUIManager.hpp b/src/slic3r/GUI/UpdatesUIManager.hpp index 007694406c..f5d9eda138 100644 --- a/src/slic3r/GUI/UpdatesUIManager.hpp +++ b/src/slic3r/GUI/UpdatesUIManager.hpp @@ -60,8 +60,6 @@ class RepositoryUpdateUIManager void fill_entries(bool init_selection = false); void fill_grids(); - void update(); - void remove_offline_repos(const std::string& id); void load_offline_repos(); void check_selection(); @@ -71,6 +69,8 @@ public: RepositoryUpdateUIManager(wxWindow* parent, PresetArchiveDatabase* pad, int em); ~RepositoryUpdateUIManager() {} + void update(); + wxSizer* get_sizer() { return m_main_sizer; } bool set_selected_repositories(); bool is_selection_changed() const { return m_is_selection_changed; }