mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 02:15:55 +08:00
SPE-2561: Printables Print dialog
Fix of opening webview dialog from webview panel CLOSE_DIALOG connect action Login on logged out Print request Register CLOSE_DIALOG callback. refactoring
This commit is contained in:
parent
668d73b2ea
commit
3bdaef4910
@ -26,7 +26,7 @@ ConnectRequestHandler::ConnectRequestHandler()
|
|||||||
m_actions["ERROR"] = std::bind(&ConnectRequestHandler::on_connect_action_error, this, std::placeholders::_1);
|
m_actions["ERROR"] = std::bind(&ConnectRequestHandler::on_connect_action_error, this, std::placeholders::_1);
|
||||||
m_actions["LOG"] = std::bind(&ConnectRequestHandler::on_connect_action_log, this, std::placeholders::_1);
|
m_actions["LOG"] = std::bind(&ConnectRequestHandler::on_connect_action_log, this, std::placeholders::_1);
|
||||||
m_actions["RELOAD_HOME_PAGE"] = std::bind(&ConnectRequestHandler::on_reload_event, this, std::placeholders::_1);
|
m_actions["RELOAD_HOME_PAGE"] = std::bind(&ConnectRequestHandler::on_reload_event, this, std::placeholders::_1);
|
||||||
|
m_actions["CLOSE_DIALOG"] = std::bind(&ConnectRequestHandler::on_connect_action_close_dialog, this, std::placeholders::_1);
|
||||||
}
|
}
|
||||||
ConnectRequestHandler::~ConnectRequestHandler()
|
ConnectRequestHandler::~ConnectRequestHandler()
|
||||||
{
|
{
|
||||||
|
@ -29,6 +29,7 @@ protected:
|
|||||||
virtual void on_connect_action_select_printer(const std::string& message_data) = 0;
|
virtual void on_connect_action_select_printer(const std::string& message_data) = 0;
|
||||||
virtual void on_connect_action_print(const std::string& message_data) = 0;
|
virtual void on_connect_action_print(const std::string& message_data) = 0;
|
||||||
virtual void on_connect_action_webapp_ready(const std::string& message_data) = 0;
|
virtual void on_connect_action_webapp_ready(const std::string& message_data) = 0;
|
||||||
|
virtual void on_connect_action_close_dialog(const std::string& message_data) = 0;
|
||||||
virtual void on_reload_event(const std::string& message_data) = 0;
|
virtual void on_reload_event(const std::string& message_data) = 0;
|
||||||
virtual void run_script_bridge(const wxString &script) = 0;
|
virtual void run_script_bridge(const wxString &script) = 0;
|
||||||
|
|
||||||
|
@ -4190,10 +4190,6 @@ void GUI_App::printables_slice_request(const std::string& download_url, const st
|
|||||||
m_downloader->init(dest_folder);
|
m_downloader->init(dest_folder);
|
||||||
m_downloader->start_download_printables(download_url, true, model_url, this);
|
m_downloader->start_download_printables(download_url, true, model_url, this);
|
||||||
}
|
}
|
||||||
void GUI_App::printables_print_request(const std::string& download_url, const std::string& model_url)
|
|
||||||
{
|
|
||||||
plater()->printables_to_connect_gcode(Utils::ServiceConfig::instance().printables_url() + model_url);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GUI_App::printables_login_request()
|
void GUI_App::printables_login_request()
|
||||||
{
|
{
|
||||||
|
@ -413,14 +413,6 @@ public:
|
|||||||
void open_wifi_config_dialog(bool forced, const wxString& drive_path = {});
|
void open_wifi_config_dialog(bool forced, const wxString& drive_path = {});
|
||||||
bool get_wifi_config_dialog_shown() const { return m_wifi_config_dialog_shown; }
|
bool get_wifi_config_dialog_shown() const { return m_wifi_config_dialog_shown; }
|
||||||
|
|
||||||
void request_login(bool show_user_info = false) {}
|
|
||||||
bool check_login() { return false; }
|
|
||||||
void get_login_info() {}
|
|
||||||
bool is_user_login() { return true; }
|
|
||||||
|
|
||||||
void request_user_login(int online_login) {}
|
|
||||||
void request_user_logout() {}
|
|
||||||
int request_user_unbind(std::string dev_id) { return 0; }
|
|
||||||
bool select_printer_from_connect(const std::string& cmd);
|
bool select_printer_from_connect(const std::string& cmd);
|
||||||
void select_filament_from_connect(const std::string& cmd);
|
void select_filament_from_connect(const std::string& cmd);
|
||||||
void handle_connect_request_printer_select(const std::string& cmd);
|
void handle_connect_request_printer_select(const std::string& cmd);
|
||||||
@ -438,7 +430,6 @@ public:
|
|||||||
void request_remove_project(std::string project_id) {}
|
void request_remove_project(std::string project_id) {}
|
||||||
void printables_download_request(const std::string& download_url, const std::string& model_url);
|
void printables_download_request(const std::string& download_url, const std::string& model_url);
|
||||||
void printables_slice_request(const std::string& download_url, const std::string& model_url);
|
void printables_slice_request(const std::string& download_url, const std::string& model_url);
|
||||||
void printables_print_request(const std::string& download_url, const std::string& model_url);
|
|
||||||
void printables_login_request();
|
void printables_login_request();
|
||||||
void open_link_in_printables(const std::string& url);
|
void open_link_in_printables(const std::string& url);
|
||||||
private:
|
private:
|
||||||
|
@ -127,6 +127,7 @@
|
|||||||
#include "UserAccountUtils.hpp"
|
#include "UserAccountUtils.hpp"
|
||||||
#include "DesktopIntegrationDialog.hpp"
|
#include "DesktopIntegrationDialog.hpp"
|
||||||
#include "WebViewDialog.hpp"
|
#include "WebViewDialog.hpp"
|
||||||
|
#include "WebViewPanel.hpp"
|
||||||
#include "ConfigWizardWebViewPage.hpp"
|
#include "ConfigWizardWebViewPage.hpp"
|
||||||
#include "PresetArchiveDatabase.hpp"
|
#include "PresetArchiveDatabase.hpp"
|
||||||
|
|
||||||
@ -1044,6 +1045,15 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
|||||||
this->q->Bind(EVT_UA_ENQUEUED_REFRESH, [this](SimpleEvent& evt) {
|
this->q->Bind(EVT_UA_ENQUEUED_REFRESH, [this](SimpleEvent& evt) {
|
||||||
this->main_frame->on_account_will_refresh();
|
this->main_frame->on_account_will_refresh();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this->q->Bind(EVT_PRINTABLES_CONNECT_PRINT, [this](wxCommandEvent& evt) {
|
||||||
|
if (!this->user_account->is_logged()) {
|
||||||
|
// show login dialog instead of print dialog
|
||||||
|
this->user_account->do_login();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->q->printables_to_connect_gcode(into_u8(evt.GetString()));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGetApp().other_instance_message_handler()->init(this->q);
|
wxGetApp().other_instance_message_handler()->init(this->q);
|
||||||
@ -6059,12 +6069,9 @@ bool load_secret(const std::string& id, const std::string& opt, std::string& usr
|
|||||||
|
|
||||||
void Plater::printables_to_connect_gcode(const std::string& url)
|
void Plater::printables_to_connect_gcode(const std::string& url)
|
||||||
{
|
{
|
||||||
{
|
PrintablesConnectUploadDialog dialog(this, url);
|
||||||
PrintablesConnectUploadDialog dialog(this, url);
|
dialog.ShowModal();
|
||||||
if (dialog.ShowModal() != wxID_OK) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plater::connect_gcode()
|
void Plater::connect_gcode()
|
||||||
|
@ -10,8 +10,6 @@ class wxString;
|
|||||||
|
|
||||||
namespace WebView
|
namespace WebView
|
||||||
{
|
{
|
||||||
// When using WebView in Panel, it is benfitable to call create only when it is being shown. (lower CPU usage)
|
|
||||||
// But when using WebView in Dialog, call both.
|
|
||||||
wxWebView* webview_new();
|
wxWebView* webview_new();
|
||||||
void webview_create(wxWebView* webview, wxWindow *parent, const wxString& url, const std::vector<std::string>& message_handlers);
|
void webview_create(wxWebView* webview, wxWindow *parent, const wxString& url, const std::vector<std::string>& message_handlers);
|
||||||
};
|
};
|
||||||
|
@ -219,13 +219,20 @@ void WebViewDialog::on_reload_button(wxCommandEvent& WXUNUSED(evt))
|
|||||||
m_browser->Reload();
|
m_browser->Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WebViewDialog::on_navigation_request(wxWebViewEvent &evt)
|
void WebViewDialog::on_navigation_request(wxWebViewEvent &evt)
|
||||||
{
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "WebViewDialog::on_navigation_request " << evt.GetURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebViewDialog::on_loaded(wxWebViewEvent &evt)
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "WebViewDialog::on_loaded " << evt.GetURL();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void WebViewDialog::on_script_message(wxWebViewEvent& evt)
|
void WebViewDialog::on_script_message(wxWebViewEvent& evt)
|
||||||
{
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "Unhandled script message: " << evt.GetString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -634,13 +641,14 @@ void PrinterPickWebViewDialog::on_reload_event(const std::string& message_data)
|
|||||||
m_browser->LoadURL(m_default_url);
|
m_browser->LoadURL(m_default_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PrintablesConnectUploadDialog::PrintablesConnectUploadDialog(wxWindow* parent, const std::string url)
|
PrintablesConnectUploadDialog::PrintablesConnectUploadDialog(wxWindow* parent, const std::string url)
|
||||||
: WebViewDialog(parent
|
: WebViewDialog(parent
|
||||||
, GUI::from_u8(url)
|
, GUI::from_u8(url)
|
||||||
, _L("Choose a printer")
|
, _L("Choose a printer")
|
||||||
, wxSize(parent->GetClientSize().x / 4 * 3, parent->GetClientSize().y/ 4 * 3)
|
, wxSize(parent->GetClientSize().x / 4 * 3, parent->GetClientSize().y/ 4 * 3)
|
||||||
,{"_prusaSlicer"}
|
,{"_prusaSlicer"}
|
||||||
, "connect_loading")
|
, "connect_loading")
|
||||||
{
|
{
|
||||||
wxDisplay display(wxDisplay::GetFromWindow(this));
|
wxDisplay display(wxDisplay::GetFromWindow(this));
|
||||||
wxRect geometry = display.GetGeometry();
|
wxRect geometry = display.GetGeometry();
|
||||||
@ -657,7 +665,39 @@ void PrintablesConnectUploadDialog::on_dpi_changed(const wxRect &suggested_rect)
|
|||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PrintablesConnectUploadDialog::on_script_message(wxWebViewEvent& evt)
|
||||||
|
{
|
||||||
|
handle_message(into_u8(evt.GetString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintablesConnectUploadDialog::on_connect_action_select_printer(const std::string& message_data)
|
||||||
|
{
|
||||||
|
// SELECT_PRINTER request is not defined for PrintablesConnectUploadDialog
|
||||||
|
assert(true);
|
||||||
|
}
|
||||||
|
void PrintablesConnectUploadDialog::on_connect_action_print(const std::string& message_data)
|
||||||
|
{
|
||||||
|
assert(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintablesConnectUploadDialog::on_connect_action_webapp_ready(const std::string& message_data)
|
||||||
|
{
|
||||||
|
// WEBAPP_READY request is not defined for PrintablesConnectUploadDialog
|
||||||
|
assert(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintablesConnectUploadDialog::on_reload_event(const std::string& message_data)
|
||||||
|
{
|
||||||
|
if (!m_browser) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_browser->LoadURL(m_default_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintablesConnectUploadDialog::on_connect_action_close_dialog(const std::string& message_data)
|
||||||
|
{
|
||||||
|
this->EndModal(wxID_OK);
|
||||||
|
}
|
||||||
|
|
||||||
LoginWebViewDialog::LoginWebViewDialog(wxWindow *parent, std::string &ret_val, const wxString& url, wxEvtHandler* evt_handler)
|
LoginWebViewDialog::LoginWebViewDialog(wxWindow *parent, std::string &ret_val, const wxString& url, wxEvtHandler* evt_handler)
|
||||||
: WebViewDialog(parent, url, _L("Log in dialog"), wxSize(50 * wxGetApp().em_unit(), 80 * wxGetApp().em_unit()), {})
|
: WebViewDialog(parent, url, _L("Log in dialog"), wxSize(50 * wxGetApp().em_unit(), 80 * wxGetApp().em_unit()), {})
|
||||||
|
@ -52,7 +52,7 @@ public:
|
|||||||
void On_enable_dev_tools(wxCommandEvent& evt);
|
void On_enable_dev_tools(wxCommandEvent& evt);
|
||||||
|
|
||||||
virtual void on_navigation_request(wxWebViewEvent &evt);
|
virtual void on_navigation_request(wxWebViewEvent &evt);
|
||||||
virtual void on_loaded(wxWebViewEvent &evt) {}
|
virtual void on_loaded(wxWebViewEvent &evt);
|
||||||
|
|
||||||
void run_script(const wxString& javascript);
|
void run_script(const wxString& javascript);
|
||||||
|
|
||||||
@ -105,17 +105,25 @@ protected:
|
|||||||
void run_script_bridge(const wxString& script) override { run_script(script); }
|
void run_script_bridge(const wxString& script) override { run_script(script); }
|
||||||
void on_dpi_changed(const wxRect &suggested_rect) override;
|
void on_dpi_changed(const wxRect &suggested_rect) override;
|
||||||
void on_reload_event(const std::string& message_data) override;
|
void on_reload_event(const std::string& message_data) override;
|
||||||
|
void on_connect_action_close_dialog(const std::string& message_data) override {assert(true);}
|
||||||
private:
|
private:
|
||||||
std::string& m_ret_val;
|
std::string& m_ret_val;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PrintablesConnectUploadDialog : public WebViewDialog
|
class PrintablesConnectUploadDialog : public WebViewDialog, public ConnectRequestHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PrintablesConnectUploadDialog(wxWindow* parent, const std::string url);
|
PrintablesConnectUploadDialog(wxWindow* parent, const std::string url);
|
||||||
|
void on_script_message(wxWebViewEvent& evt) override;
|
||||||
protected:
|
protected:
|
||||||
void on_dpi_changed(const wxRect &suggested_rect) override;
|
void on_dpi_changed(const wxRect &suggested_rect) override;
|
||||||
|
|
||||||
|
void on_connect_action_select_printer(const std::string& message_data) override;
|
||||||
|
void on_connect_action_print(const std::string& message_data) override;
|
||||||
|
void on_connect_action_webapp_ready(const std::string& message_data) override;
|
||||||
|
void on_reload_event(const std::string& message_data) override;
|
||||||
|
void run_script_bridge(const wxString &script) override { run_script(script); }
|
||||||
|
void on_connect_action_close_dialog(const std::string& message_data) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LoginWebViewDialog : public WebViewDialog
|
class LoginWebViewDialog : public WebViewDialog
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#include <wx/webview.h>
|
#include <wx/webview.h>
|
||||||
#include <wx/url.h>
|
#include <wx/url.h>
|
||||||
|
#include <curl/curl.h>
|
||||||
#include <boost/log/trivial.hpp>
|
#include <boost/log/trivial.hpp>
|
||||||
#include <boost/property_tree/ptree.hpp>
|
#include <boost/property_tree/ptree.hpp>
|
||||||
#include <boost/property_tree/json_parser.hpp>
|
#include <boost/property_tree/json_parser.hpp>
|
||||||
@ -30,6 +30,8 @@
|
|||||||
// to set authorization cookie for all WebKit requests to Connect
|
// to set authorization cookie for all WebKit requests to Connect
|
||||||
#define AUTH_VIA_FETCH_OVERRIDE 0
|
#define AUTH_VIA_FETCH_OVERRIDE 0
|
||||||
|
|
||||||
|
wxDEFINE_EVENT(EVT_PRINTABLES_CONNECT_PRINT, wxCommandEvent);
|
||||||
|
|
||||||
namespace pt = boost::property_tree;
|
namespace pt = boost::property_tree;
|
||||||
|
|
||||||
namespace Slic3r::GUI {
|
namespace Slic3r::GUI {
|
||||||
@ -1162,6 +1164,24 @@ void PrintablesWebViewPanel::on_reload_event(const std::string& message_data)
|
|||||||
// Event from our error / loading html pages
|
// Event from our error / loading html pages
|
||||||
load_default_url();
|
load_default_url();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::string escape_url(const std::string& unescaped)
|
||||||
|
{
|
||||||
|
std::string ret_val;
|
||||||
|
CURL* curl = curl_easy_init();
|
||||||
|
if (curl) {
|
||||||
|
char* decoded = curl_easy_escape(curl, unescaped.c_str(), unescaped.size());
|
||||||
|
if (decoded) {
|
||||||
|
ret_val = std::string(decoded);
|
||||||
|
curl_free(decoded);
|
||||||
|
}
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
}
|
||||||
|
return ret_val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PrintablesWebViewPanel::on_printables_event_print_gcode(const std::string& message_data)
|
void PrintablesWebViewPanel::on_printables_event_print_gcode(const std::string& message_data)
|
||||||
{
|
{
|
||||||
// { "event": "downloadFile", "url": "https://media.printables.com/somesecure.stl", "modelUrl": "https://www.printables.com/model/123" }
|
// { "event": "downloadFile", "url": "https://media.printables.com/somesecure.stl", "modelUrl": "https://www.printables.com/model/123" }
|
||||||
@ -1182,7 +1202,9 @@ void PrintablesWebViewPanel::on_printables_event_print_gcode(const std::string&
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert(!download_url.empty() && !model_url.empty());
|
assert(!download_url.empty() && !model_url.empty());
|
||||||
wxGetApp().printables_print_request(download_url, model_url);
|
wxCommandEvent* evt = new wxCommandEvent(EVT_PRINTABLES_CONNECT_PRINT);
|
||||||
|
evt->SetString(from_u8(Utils::ServiceConfig::instance().connect_printables_print_url() +"?url=" + escape_url(download_url)));
|
||||||
|
wxQueueEvent(GUI::wxGetApp().mainframe->m_plater, evt);
|
||||||
}
|
}
|
||||||
void PrintablesWebViewPanel::on_printables_event_download_file(const std::string& message_data)
|
void PrintablesWebViewPanel::on_printables_event_download_file(const std::string& message_data)
|
||||||
{
|
{
|
||||||
@ -1207,6 +1229,7 @@ void PrintablesWebViewPanel::on_printables_event_download_file(const std::string
|
|||||||
assert(!download_url.empty() && !model_url.empty());
|
assert(!download_url.empty() && !model_url.empty());
|
||||||
boost::filesystem::path url_path(download_url);
|
boost::filesystem::path url_path(download_url);
|
||||||
show_download_notification(url_path.filename().string());
|
show_download_notification(url_path.filename().string());
|
||||||
|
|
||||||
wxGetApp().printables_download_request(download_url, model_url);
|
wxGetApp().printables_download_request(download_url, model_url);
|
||||||
}
|
}
|
||||||
void PrintablesWebViewPanel::on_printables_event_slice_file(const std::string& message_data)
|
void PrintablesWebViewPanel::on_printables_event_slice_file(const std::string& message_data)
|
||||||
@ -1230,6 +1253,7 @@ void PrintablesWebViewPanel::on_printables_event_slice_file(const std::string& m
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert(!download_url.empty() && !model_url.empty());
|
assert(!download_url.empty() && !model_url.empty());
|
||||||
|
|
||||||
wxGetApp().printables_slice_request(download_url, model_url);
|
wxGetApp().printables_slice_request(download_url, model_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
class wxWebView;
|
class wxWebView;
|
||||||
class wxWebViewEvent;
|
class wxWebViewEvent;
|
||||||
|
|
||||||
wxDECLARE_EVENT(EVT_OPEN_EXTERNAL_LOGIN, wxCommandEvent);
|
wxDECLARE_EVENT(EVT_PRINTABLES_CONNECT_PRINT, wxCommandEvent);
|
||||||
|
|
||||||
namespace Slic3r::GUI {
|
namespace Slic3r::GUI {
|
||||||
|
|
||||||
@ -141,6 +141,7 @@ protected:
|
|||||||
void on_page_will_load() override;
|
void on_page_will_load() override;
|
||||||
void on_connect_action_error(const std::string &message_data) override;
|
void on_connect_action_error(const std::string &message_data) override;
|
||||||
void on_reload_event(const std::string& message_data) override;
|
void on_reload_event(const std::string& message_data) override;
|
||||||
|
void on_connect_action_close_dialog(const std::string& message_data) override {assert(true);}
|
||||||
private:
|
private:
|
||||||
static wxString get_login_script(bool refresh);
|
static wxString get_login_script(bool refresh);
|
||||||
static wxString get_logout_script();
|
static wxString get_logout_script();
|
||||||
|
@ -14,6 +14,7 @@ public:
|
|||||||
std::string connect_select_printer_url() const { return m_connect_url + "/slicer-select-printer"; }
|
std::string connect_select_printer_url() const { return m_connect_url + "/slicer-select-printer"; }
|
||||||
std::string connect_printers_url() const { return m_connect_url + "/app/printers/"; }
|
std::string connect_printers_url() const { return m_connect_url + "/app/printers/"; }
|
||||||
std::string connect_teams_url() const { return m_connect_url + "/app/teams"; }
|
std::string connect_teams_url() const { return m_connect_url + "/app/teams"; }
|
||||||
|
std::string connect_printables_print_url() const { return m_connect_url + "/slicer-print"; }
|
||||||
|
|
||||||
const std::string& account_url() const { return m_account_url; }
|
const std::string& account_url() const { return m_account_url; }
|
||||||
const std::string& account_client_id() const { return m_account_client_id; }
|
const std::string& account_client_id() const { return m_account_client_id; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user