Files
OrcaSlicer/src/slic3r/GUI/PrinterCloudAuthDialog.cpp
T
HanifKoh 1a5f91d727 Add Missing Includes Across src/slic3r/GUI (#16048)
* Add Missing Includes Across src/slic3r/GUI

Every GUI source and header now directly includes the headers declaring what it uses, rather than relying on the precompiled header or transitive includes. Generated with clang-tidy misc-include-cleaner, plus one hand edit making CalibrationPanel.hpp self-contained.

* Drop the OS-Specific Includes Added Outside Their Platform Guards

GLib, GTK, D-Bus and POSIX headers are only used inside platform #if blocks, which already include them. Added unconditionally at the top of the file they broke the Windows build.

* Add the clang-tidy Configuration That Generated These Includes

Only misc-include-cleaner's missing-include check, with the headers it must never suggest: per-platform, internal and OS-specific ones that would break other platforms or are not meant to be included directly.

* Match Windows Paths in the clang-tidy Ignore List

Header paths use backslashes on Windows, so every / in a pattern is now [/\\]. The Windows SDK headers are ignored alongside the other OS-specific ones, and the list is one pattern per line. Suggested by @raistlin7447 from a Windows clang-cl run.
2026-10-02 14:56:56 +08:00

117 lines
3.5 KiB
C++

#include "PrinterCloudAuthDialog.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/Gizmos/GLGizmoBase.hpp"
#include <boost/log/trivial.hpp>
#include <wx/log.h>
#include <wx/gdicmn.h>
#include <wx/settings.h>
#include <cstddef>
#include "slic3r/GUI/Printer/PrinterFileSystem.h"
#include "slic3r/GUI/GUI.hpp"
#include <exception>
#include <wx/msgdlg.h>
#include <wx/sizer.h>
#include <wx/toolbar.h>
#include <wx/textdlg.h>
#include <wx/webview.h>
#include <wx/wx.h>
#include <wx/fileconf.h>
#include <wx/file.h>
#include <wx/wfstream.h>
#include <boost/cast.hpp>
#include <boost/lexical_cast.hpp>
#include <nlohmann/json.hpp>
#include "MainFrame.hpp"
#include "PrintHost.hpp"
#include <boost/dll.hpp>
#include <sstream>
#include <slic3r/GUI/Widgets/WebView.hpp>
//------------------------------------------
// PrinterCloundAuthDialog
//------------------------------------------
namespace Slic3r { namespace GUI {
PrinterCloudAuthDialog::PrinterCloudAuthDialog(wxWindow* parent, PrintHost* host)
: wxDialog((wxWindow*) (wxGetApp().mainframe), wxID_ANY, _L("Login"))
{
SetBackgroundColour(*wxWHITE);
// Url
host->get_login_url(m_TargetUrl);
BOOST_LOG_TRIVIAL(info) << "login url = " << m_TargetUrl.ToStdString();
// Create the webview
m_browser = WebView::CreateWebView(this, m_TargetUrl);
if (m_browser == nullptr) {
wxLogError("Could not init m_browser");
return;
}
m_browser->Hide();
m_browser->SetSize(0, 0);
// Connect the webview events
Bind(wxEVT_WEBVIEW_NAVIGATING, &PrinterCloudAuthDialog::OnNavigationRequest, this, m_browser->GetId());
Bind(wxEVT_WEBVIEW_NAVIGATED, &PrinterCloudAuthDialog::OnNavigationComplete, this, m_browser->GetId());
Bind(wxEVT_WEBVIEW_LOADED, &PrinterCloudAuthDialog::OnDocumentLoaded, this, m_browser->GetId());
Bind(wxEVT_WEBVIEW_NEWWINDOW, &PrinterCloudAuthDialog::OnNewWindow, this, m_browser->GetId());
Bind(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, &PrinterCloudAuthDialog::OnScriptMessage, this, m_browser->GetId());
// UI
SetTitle(_L("Login"));
// Set a more sensible size for web browsing
wxSize pSize = FromDIP(wxSize(650, 840));
SetSize(pSize);
int screenheight = wxSystemSettings::GetMetric(wxSYS_SCREEN_Y, NULL);
int screenwidth = wxSystemSettings::GetMetric(wxSYS_SCREEN_X, NULL);
int MaxY = (screenheight - pSize.y) > 0 ? (screenheight - pSize.y) / 2 : 0;
wxPoint tmpPT((screenwidth - pSize.x) / 2, MaxY);
Move(tmpPT);
}
PrinterCloudAuthDialog::~PrinterCloudAuthDialog() {}
void PrinterCloudAuthDialog::OnNavigationRequest(wxWebViewEvent& evt)
{
//todo
}
void PrinterCloudAuthDialog::OnNavigationComplete(wxWebViewEvent& evt)
{
m_browser->Show();
Layout();
//fortest
//WebView::RunScript(m_browser, "window.wx.postMessage('This is a web message')");
}
void PrinterCloudAuthDialog::OnDocumentLoaded(wxWebViewEvent& evt)
{
// todo
}
void PrinterCloudAuthDialog::OnNewWindow(wxWebViewEvent& evt) {
}
void PrinterCloudAuthDialog::OnScriptMessage(wxWebViewEvent& evt)
{
wxString str_input = evt.GetString();
try {
json j = json::parse(into_u8(str_input));
wxString strCmd = j["command"];
if (strCmd == "login_token") {
auto token = j["data"]["token"];
m_apikey = token;
}
Close();
} catch (std::exception& e) {
wxMessageBox(e.what(), _L("parse json failed"), wxICON_WARNING);
Close();
}
}
}
} // namespace Slic3r::GUI