-
-
Notifications
You must be signed in to change notification settings - Fork 939
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Obico cloud integration (#4116)
support obico (#3) Add printer support for Obico cloud. --------- Co-authored-by: zzh <[email protected]>
- Loading branch information
1 parent
047b889
commit 8c941df
Showing
11 changed files
with
519 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include "PrinterCloudAuthDialog.hpp" | ||
#include <wx/sizer.h> | ||
#include <wx/toolbar.h> | ||
#include <wx/textdlg.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 <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, "Login"), m_host(host) | ||
{ | ||
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_host->set_api_key(token); | ||
m_apikey = token; | ||
} | ||
Close(); | ||
} catch (std::exception& e) { | ||
wxMessageBox(e.what(), "parse json failed", wxICON_WARNING); | ||
Close(); | ||
} | ||
} | ||
|
||
} | ||
} // namespace Slic3r::GUI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef slic3r_GUI_PrinterCloudAuthDialog_hpp_ | ||
#define slic3r_GUI_PrinterCloudAuthDialog_hpp_ | ||
|
||
#include <wx/wx.h> | ||
#include <wx/font.h> | ||
#include <wx/colour.h> | ||
#include <wx/string.h> | ||
#include <wx/sizer.h> | ||
#include <wx/dialog.h> | ||
#include "wx/webview.h" | ||
|
||
#if wxUSE_WEBVIEW_IE | ||
#include "wx/msw/webview_ie.h" | ||
#endif | ||
#if wxUSE_WEBVIEW_EDGE | ||
#include "wx/msw/webview_edge.h" | ||
#endif | ||
|
||
#include "GUI_Utils.hpp" | ||
#include "PrintHost.hpp" | ||
|
||
namespace Slic3r { namespace GUI { | ||
|
||
class PrinterCloudAuthDialog : public wxDialog | ||
{ | ||
protected: | ||
wxWebView* m_browser; | ||
wxString m_TargetUrl; | ||
|
||
wxString m_javascript; | ||
wxString m_response_js; | ||
PrintHost* m_host; | ||
std::string m_apikey; | ||
|
||
public: | ||
PrinterCloudAuthDialog(wxWindow* parent, PrintHost* host); | ||
~PrinterCloudAuthDialog(); | ||
|
||
std::string GetApiKey() { return m_apikey; }; | ||
|
||
void OnNavigationRequest(wxWebViewEvent& evt); | ||
void OnNavigationComplete(wxWebViewEvent& evt); | ||
void OnDocumentLoaded(wxWebViewEvent& evt); | ||
void OnNewWindow(wxWebViewEvent& evt); | ||
void OnScriptMessage(wxWebViewEvent& evt); | ||
|
||
}; | ||
|
||
}} // namespace Slic3r::GUI | ||
|
||
#endif |
Oops, something went wrong.