From 8c4183185b514154c911b4d615fad6e0d9a42c89 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Fri, 7 Feb 2025 18:32:10 +0100 Subject: [PATCH 1/3] New avatar path for download. Get without access token. TODO: using webp as picture format. --- src/slic3r/GUI/UserAccount.cpp | 21 ++++++++++++++++---- src/slic3r/GUI/UserAccount.hpp | 3 ++- src/slic3r/GUI/UserAccountCommunication.cpp | 14 +++++++++++-- src/slic3r/GUI/UserAccountCommunication.hpp | 3 ++- src/slic3r/GUI/UserAccountSession.cpp | 3 ++- src/slic3r/GUI/UserAccountSession.hpp | 22 ++++++++++++--------- 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/slic3r/GUI/UserAccount.cpp b/src/slic3r/GUI/UserAccount.cpp index cd8b4da8bf..7192ec6a0f 100644 --- a/src/slic3r/GUI/UserAccount.cpp +++ b/src/slic3r/GUI/UserAccount.cpp @@ -98,9 +98,13 @@ void UserAccount::enqueue_connect_status_action() { m_communication->enqueue_connect_status_action(); } -void UserAccount::enqueue_avatar_action() +void UserAccount::enqueue_avatar_old_action() { - m_communication->enqueue_avatar_action(m_account_user_data["avatar"]); + m_communication->enqueue_avatar_old_action(m_account_user_data["avatar"]); +} +void UserAccount::enqueue_avatar_new_action(const std::string& url) +{ + m_communication->enqueue_avatar_new_action(url); } void UserAccount::enqueue_printer_data_action(const std::string& uuid) { @@ -145,10 +149,19 @@ bool UserAccount::on_user_id_success(const std::string data, std::string& out_us set_username(public_username); out_username = public_username; // enqueue GET with avatar url - if (m_account_user_data.find("avatar") != m_account_user_data.end()) { + + if (m_account_user_data.find("avatar_small") != m_account_user_data.end()) { + const boost::filesystem::path server_file(m_account_user_data["avatar_small"]); + m_avatar_extension = server_file.extension().string(); + enqueue_avatar_new_action(m_account_user_data["avatar_small"]); + } else if (m_account_user_data.find("avatar_large") != m_account_user_data.end()) { + const boost::filesystem::path server_file(m_account_user_data["avatar_large"]); + m_avatar_extension = server_file.extension().string(); + enqueue_avatar_new_action(m_account_user_data["avatar_large"]); + } else if (m_account_user_data.find("avatar") != m_account_user_data.end()) { const boost::filesystem::path server_file(m_account_user_data["avatar"]); m_avatar_extension = server_file.extension().string(); - enqueue_avatar_action(); + enqueue_avatar_old_action(); } else { BOOST_LOG_TRIVIAL(error) << "User ID message from PrusaAuth did not contain avatar."; diff --git a/src/slic3r/GUI/UserAccount.hpp b/src/slic3r/GUI/UserAccount.hpp index ed535c9ef8..6a1730735a 100644 --- a/src/slic3r/GUI/UserAccount.hpp +++ b/src/slic3r/GUI/UserAccount.hpp @@ -46,7 +46,8 @@ public: bool get_remember_session(); void enqueue_connect_status_action(); void enqueue_connect_printer_models_action(); - void enqueue_avatar_action(); + void enqueue_avatar_old_action(); + void enqueue_avatar_new_action(const std::string& url); void enqueue_printer_data_action(const std::string& uuid); void request_refresh(); // Clears all data and connections, called on logout or EVT_UA_RESET diff --git a/src/slic3r/GUI/UserAccountCommunication.cpp b/src/slic3r/GUI/UserAccountCommunication.cpp index 395986400d..cc0cdf6318 100644 --- a/src/slic3r/GUI/UserAccountCommunication.cpp +++ b/src/slic3r/GUI/UserAccountCommunication.cpp @@ -421,13 +421,23 @@ void UserAccountCommunication::enqueue_test_connection() wakeup_session_thread(); } -void UserAccountCommunication::enqueue_avatar_action(const std::string& url) +void UserAccountCommunication::enqueue_avatar_old_action(const std::string& url) { if (!m_session->is_initialized()) { BOOST_LOG_TRIVIAL(error) << "Connect Printers endpoint connection failed - Not Logged in."; return; } - m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR, nullptr, nullptr, url); + m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR_OLD, nullptr, nullptr, url); + wakeup_session_thread(); +} + +void UserAccountCommunication::enqueue_avatar_new_action(const std::string& url) +{ + if (!m_session->is_initialized()) { + BOOST_LOG_TRIVIAL(error) << "Connect Printers endpoint connection failed - Not Logged in."; + return; + } + m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR_NEW, nullptr, nullptr, url); wakeup_session_thread(); } diff --git a/src/slic3r/GUI/UserAccountCommunication.hpp b/src/slic3r/GUI/UserAccountCommunication.hpp index 645af09961..e8d1e42aa0 100644 --- a/src/slic3r/GUI/UserAccountCommunication.hpp +++ b/src/slic3r/GUI/UserAccountCommunication.hpp @@ -49,7 +49,8 @@ public: // Trigger function starts various remote operations void enqueue_connect_status_action(); void enqueue_connect_printer_models_action(); - void enqueue_avatar_action(const std::string& url); + void enqueue_avatar_old_action(const std::string& url); + void enqueue_avatar_new_action(const std::string& url); void enqueue_test_connection(); void enqueue_printer_data_action(const std::string& uuid); void enqueue_refresh(); diff --git a/src/slic3r/GUI/UserAccountSession.cpp b/src/slic3r/GUI/UserAccountSession.cpp index 5d94542258..62b7bb00c4 100644 --- a/src/slic3r/GUI/UserAccountSession.cpp +++ b/src/slic3r/GUI/UserAccountSession.cpp @@ -131,7 +131,8 @@ void UserAccountSession::process_action_queue_inner() } } if (call_priority || call_standard) { - m_actions[selected_data.action_id]->perform(p_evt_handler, get_access_token(), selected_data.success_callback, selected_data.fail_callback, selected_data.input); + bool use_token = m_actions[selected_data.action_id]->get_requires_auth_token(); + m_actions[selected_data.action_id]->perform(p_evt_handler, use_token ? get_access_token() : std::string(), selected_data.success_callback, selected_data.fail_callback, selected_data.input); process_action_queue_inner(); } } diff --git a/src/slic3r/GUI/UserAccountSession.hpp b/src/slic3r/GUI/UserAccountSession.hpp index 8b807aeff3..23ae62263a 100644 --- a/src/slic3r/GUI/UserAccountSession.hpp +++ b/src/slic3r/GUI/UserAccountSession.hpp @@ -45,28 +45,30 @@ enum class UserAccountActionID { USER_ACCOUNT_ACTION_TEST_CONNECTION, USER_ACCOUNT_ACTION_CONNECT_STATUS, // status of all printers by UUID USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS, // status of all printers by UUID with printer_model. Should be called once to save printer models. - USER_ACCOUNT_ACTION_AVATAR, + USER_ACCOUNT_ACTION_AVATAR_OLD, + USER_ACCOUNT_ACTION_AVATAR_NEW, USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID, }; class UserAction { public: - UserAction(const std::string name, const std::string url) : m_action_name(name), m_url(url){} + UserAction(const std::string name, const std::string url, bool requires_auth_token) : m_action_name(name), m_url(url), m_requires_auth_token(requires_auth_token){} virtual ~UserAction() = default; virtual void perform(wxEvtHandler* evt_handler, const std::string& access_token, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input) const = 0; - + bool get_requires_auth_token() { return m_requires_auth_token; } protected: std::string m_action_name; std::string m_url; + bool m_requires_auth_token; }; class UserActionGetWithEvent : public UserAction { public: - UserActionGetWithEvent(const std::string name, const std::string url, wxEventType succ_event_type, wxEventType fail_event_type) + UserActionGetWithEvent(const std::string name, const std::string url, wxEventType succ_event_type, wxEventType fail_event_type, bool requires_auth_token = true) : m_succ_evt_type(succ_event_type) , m_fail_evt_type(fail_event_type) - , UserAction(name, url) + , UserAction(name, url, requires_auth_token) {} ~UserActionGetWithEvent() {} void perform(wxEvtHandler* evt_handler, const std::string& access_token, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input) const override; @@ -78,7 +80,7 @@ private: class UserActionPost : public UserAction { public: - UserActionPost(const std::string name, const std::string url) : UserAction(name, url) {} + UserActionPost(const std::string name, const std::string url, bool requires_auth_token = true) : UserAction(name, url, requires_auth_token) {} ~UserActionPost() {} void perform(wxEvtHandler* evt_handler, const std::string& access_token, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input) const override; }; @@ -86,7 +88,7 @@ public: class DummyUserAction : public UserAction { public: - DummyUserAction() : UserAction("Dummy", {}) {} + DummyUserAction() : UserAction("Dummy", {}, false) {} ~DummyUserAction() {} void perform(wxEvtHandler* evt_handler, const std::string& access_token, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input) const override { } }; @@ -121,7 +123,8 @@ public: m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_CONNECTION] = std::make_unique("TEST_CONNECTION", sc.account_me_url(), wxEVT_NULL, EVT_UA_RESET); m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS] = std::make_unique("CONNECT_STATUS", sc.connect_status_url(), EVT_UA_PRUSACONNECT_STATUS_SUCCESS, EVT_UA_FAIL); m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS] = std::make_unique("CONNECT_PRINTER_MODELS", sc.connect_printer_list_url(), EVT_UA_PRUSACONNECT_PRINTER_MODELS_SUCCESS, EVT_UA_FAIL); - m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR] = std::make_unique("AVATAR", sc.media_url(), EVT_UA_AVATAR_SUCCESS, EVT_UA_FAIL); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR_OLD] = std::make_unique("AVATAR", sc.media_url(), EVT_UA_AVATAR_SUCCESS, EVT_UA_FAIL, false); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR_NEW] = std::make_unique("AVATAR", std::string(), EVT_UA_AVATAR_SUCCESS, EVT_UA_FAIL, false); m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID] = std::make_unique("USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID", sc.connect_printers_url(), EVT_UA_PRUSACONNECT_PRINTER_DATA_SUCCESS, EVT_UA_PRUSACONNECT_PRINTER_DATA_FAIL); } ~UserAccountSession() @@ -133,7 +136,8 @@ public: m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN].reset(nullptr); m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_CONNECTION].reset(nullptr); m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS].reset(nullptr); - m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR].reset(nullptr); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR_OLD].reset(nullptr); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR_NEW].reset(nullptr); m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID].reset(nullptr); } void clear() { From e6925fd86b9b18c22824635a9e502d49e3fa78d3 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Mon, 10 Feb 2025 12:37:21 +0100 Subject: [PATCH 2/3] SPE-2656: Fix of failed Load file in ScalableBitmap constructor. --- src/slic3r/GUI/Plater.cpp | 22 +++++++++++----------- src/slic3r/GUI/wxExtensions.cpp | 7 +++++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 0d16e1ea6d..ef3d164865 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1034,17 +1034,17 @@ void Plater::priv::init() user_account->on_communication_fail(); } }); - this->q->Bind(EVT_UA_AVATAR_SUCCESS, [this](UserAccountSuccessEvent& evt) { - boost::filesystem::path path = user_account->get_avatar_path(true); - FILE* file; - file = boost::nowide::fopen(path.generic_string().c_str(), "wb"); - if (file == NULL) { - BOOST_LOG_TRIVIAL(error) << "Failed to create file to store avatar picture at: " << path; - return; - } - fwrite(evt.data.c_str(), 1, evt.data.size(), file); - fclose(file); - this->main_frame->refresh_account_menu(true); + this->q->Bind(EVT_UA_AVATAR_SUCCESS, [this](UserAccountSuccessEvent& evt) { + boost::filesystem::path path = user_account->get_avatar_path(true); + FILE* file; + file = boost::nowide::fopen(path.generic_string().c_str(), "wb"); + if (file == NULL) { + BOOST_LOG_TRIVIAL(error) << "Failed to create file to store avatar picture at: " << path; + return; + } + fwrite(evt.data.c_str(), 1, evt.data.size(), file); + fclose(file); + this->main_frame->refresh_account_menu(true); }); 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/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 602bf4c601..cdc62fe67a 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -487,8 +487,11 @@ ScalableBitmap::ScalableBitmap(wxWindow* parent, boost::filesystem::path& icon_p const std::string ext = icon_path.extension().string(); if (ext == ".png" || ext == ".jpg") { - bitmap.LoadFile(path, ext == ".png" ? wxBITMAP_TYPE_PNG : wxBITMAP_TYPE_JPEG); - + if (!bitmap.LoadFile(path, ext == ".png" ? wxBITMAP_TYPE_PNG : wxBITMAP_TYPE_JPEG)) { + BOOST_LOG_TRIVIAL(error) << "Failed to load bitmap " << path; + return; + } + // check if the bitmap has a square shape if (wxSize sz = bitmap.GetSize(); sz.x != sz.y) { From a2e6b72b7d813e0c1a451ba075662476206dd480 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Mon, 10 Feb 2025 13:50:53 +0100 Subject: [PATCH 3/3] Missing include. --- src/slic3r/GUI/wxExtensions.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index cdc62fe67a..a0d9577288 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -12,6 +12,7 @@ #include #include +#include #include "BitmapCache.hpp" #include "GUI.hpp"