Resolved IP dialog before uploading - needs better design and to not show if only 1x v4 and v6 is resolved.
This commit is contained in:
parent
36f473c984
commit
9fd3108726
@ -233,7 +233,49 @@ void BonjourDialog::on_timer_process()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IPListDialog::IPListDialog(wxWindow* parent, const wxString& hostname, const std::vector<boost::asio::ip::address>& ips, size_t& selected_index)
|
||||||
|
: wxDialog(parent, wxID_ANY, _(L("Multiple resolved IP addresses")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||||
|
, m_list(new wxListView(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxSIMPLE_BORDER))
|
||||||
|
, m_selected_index (selected_index)
|
||||||
|
{
|
||||||
|
const int em = GUI::wxGetApp().em_unit();
|
||||||
|
m_list->SetMinSize(wxSize(20 * em, 30 * em));
|
||||||
|
|
||||||
|
wxBoxSizer* vsizer = new wxBoxSizer(wxVERTICAL);
|
||||||
|
|
||||||
|
auto* label = new wxStaticText(this, wxID_ANY, GUI::format_wxstr(_L("There are several IP addresses resolving to hostname %1%.\n Please select one that should be used."), hostname));
|
||||||
|
vsizer->Add(label, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, em);
|
||||||
|
|
||||||
|
m_list->SetSingleStyle(wxLC_SINGLE_SEL);
|
||||||
|
m_list->AppendColumn(_(L("Address")), wxLIST_FORMAT_LEFT, 20 * em);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < ips.size(); i++)
|
||||||
|
auto item = m_list->InsertItem(i, boost::nowide::widen(ips[i].to_string()));
|
||||||
|
|
||||||
|
m_list->Select(0);
|
||||||
|
|
||||||
|
vsizer->Add(m_list, 1, wxEXPAND | wxALL, em);
|
||||||
|
|
||||||
|
wxBoxSizer* button_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
button_sizer->Add(new wxButton(this, wxID_OK, "OK"), 0, wxALL, em);
|
||||||
|
button_sizer->Add(new wxButton(this, wxID_CANCEL, "Cancel"), 0, wxALL, em);
|
||||||
|
|
||||||
|
vsizer->Add(button_sizer, 0, wxALIGN_CENTER);
|
||||||
|
SetSizerAndFit(vsizer);
|
||||||
|
|
||||||
|
GUI::wxGetApp().UpdateDlgDarkUI(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
IPListDialog::~IPListDialog()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void IPListDialog::EndModal(int retCode)
|
||||||
|
{
|
||||||
|
if (retCode == wxID_OK) {
|
||||||
|
m_selected_index = (size_t)m_list->GetFirstSelected();
|
||||||
|
}
|
||||||
|
wxDialog::EndModal(retCode);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <wx/dialog.h>
|
#include <wx/dialog.h>
|
||||||
|
#include <wx/string.h>
|
||||||
|
|
||||||
#include "libslic3r/PrintConfig.hpp"
|
#include "libslic3r/PrintConfig.hpp"
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ class wxListView;
|
|||||||
class wxStaticText;
|
class wxStaticText;
|
||||||
class wxTimer;
|
class wxTimer;
|
||||||
class wxTimerEvent;
|
class wxTimerEvent;
|
||||||
|
class boost::asio::ip::address;
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
@ -41,12 +42,26 @@ private:
|
|||||||
unsigned timer_state;
|
unsigned timer_state;
|
||||||
Slic3r::PrinterTechnology tech;
|
Slic3r::PrinterTechnology tech;
|
||||||
|
|
||||||
void on_reply(BonjourReplyEvent &);
|
virtual void on_reply(BonjourReplyEvent &);
|
||||||
void on_timer(wxTimerEvent &);
|
void on_timer(wxTimerEvent &);
|
||||||
void on_timer_process();
|
void on_timer_process();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class IPListDialog : public wxDialog
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IPListDialog(wxWindow* parent, const wxString& hostname, const std::vector<boost::asio::ip::address>& ips, size_t& selected_index);
|
||||||
|
IPListDialog(IPListDialog&&) = delete;
|
||||||
|
IPListDialog(const IPListDialog&) = delete;
|
||||||
|
IPListDialog& operator=(IPListDialog&&) = delete;
|
||||||
|
IPListDialog& operator=(const IPListDialog&) = delete;
|
||||||
|
~IPListDialog();
|
||||||
|
|
||||||
|
virtual void EndModal(int retCode) wxOVERRIDE;
|
||||||
|
private:
|
||||||
|
wxListView* m_list;
|
||||||
|
size_t& m_selected_index;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "Http.hpp"
|
#include "Http.hpp"
|
||||||
#include "libslic3r/AppConfig.hpp"
|
#include "libslic3r/AppConfig.hpp"
|
||||||
#include "Bonjour.hpp"
|
#include "Bonjour.hpp"
|
||||||
|
#include "slic3r/GUI/BonjourDialog.hpp"
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
namespace pt = boost::property_tree;
|
namespace pt = boost::property_tree;
|
||||||
@ -115,7 +116,7 @@ bool OctoPrint::test_with_resolved_ip(wxString &msg) const
|
|||||||
auto url = substitute_host(make_url("api/version"), GUI::into_u8(msg));
|
auto url = substitute_host(make_url("api/version"), GUI::into_u8(msg));
|
||||||
msg.Clear();
|
msg.Clear();
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Get version at: %2%") % name % url;
|
BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Get version at: %2%") % name % url;
|
||||||
|
|
||||||
auto http = Http::get(std::move(url));
|
auto http = Http::get(std::move(url));
|
||||||
set_auth(http);
|
set_auth(http);
|
||||||
@ -126,7 +127,7 @@ bool OctoPrint::test_with_resolved_ip(wxString &msg) const
|
|||||||
msg = format_error(body, error, status);
|
msg = format_error(body, error, status);
|
||||||
})
|
})
|
||||||
.on_complete([&, this](std::string body, unsigned) {
|
.on_complete([&, this](std::string body, unsigned) {
|
||||||
BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: Got version: %2%") % name % body;
|
BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Got version: %2%") % name % body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::stringstream ss(body);
|
std::stringstream ss(body);
|
||||||
@ -253,30 +254,40 @@ bool OctoPrint::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Erro
|
|||||||
}
|
}
|
||||||
if (resolved_addr.empty()) {
|
if (resolved_addr.empty()) {
|
||||||
BOOST_LOG_TRIVIAL(error) << "PrusaSlicer failed to resolve hostname " << m_host << " into the IP address. Starting upload with system resolving.";
|
BOOST_LOG_TRIVIAL(error) << "PrusaSlicer failed to resolve hostname " << m_host << " into the IP address. Starting upload with system resolving.";
|
||||||
return false;//upload_inner_with_host(upload_data, prorgess_fn, error_fn);
|
return upload_inner_with_host(upload_data, prorgess_fn, error_fn);
|
||||||
}
|
}
|
||||||
return upload_inner_with_resolved_ip(upload_data, prorgess_fn, error_fn, resolved_addr);
|
if (resolved_addr.size() > 1) {
|
||||||
|
size_t selected_index = resolved_addr.size();
|
||||||
|
IPListDialog dialog(nullptr, boost::nowide::widen(m_host), resolved_addr, selected_index);
|
||||||
|
if (dialog.ShowModal() == wxID_OK && selected_index < resolved_addr.size()) {
|
||||||
|
return upload_inner_with_resolved_ip(upload_data, prorgess_fn, error_fn, resolved_addr[selected_index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
}
|
}
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
bool OctoPrint::upload_inner_with_resolved_ip(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, const std::vector<boost::asio::ip::address>& resolved_addr) const
|
bool OctoPrint::upload_inner_with_resolved_ip(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, const boost::asio::ip::address& resolved_addr) const
|
||||||
{
|
{
|
||||||
wxString error_message;
|
wxString error_message;
|
||||||
for (const auto& ip : resolved_addr) {
|
//for (const auto& ip : resolved_addr)
|
||||||
|
{
|
||||||
// If test fails, test_msg_or_host_ip contains the error message.
|
// If test fails, test_msg_or_host_ip contains the error message.
|
||||||
// Otherwise on Windows it contains the resolved IP address of the host.
|
// Otherwise on Windows it contains the resolved IP address of the host.
|
||||||
// Test_msg already contains resolved ip and will be cleared on start of test().
|
// Test_msg already contains resolved ip and will be cleared on start of test().
|
||||||
wxString test_msg_or_host_ip = GUI::from_u8(ip.to_string());
|
wxString test_msg_or_host_ip = GUI::from_u8(resolved_addr.to_string());
|
||||||
if (!test_with_resolved_ip(test_msg_or_host_ip)) {
|
if (!test_with_resolved_ip(test_msg_or_host_ip)) {
|
||||||
error_message = test_msg_or_host_ip;
|
error_message = test_msg_or_host_ip;
|
||||||
BOOST_LOG_TRIVIAL(info) << test_msg_or_host_ip;
|
//BOOST_LOG_TRIVIAL(info) << test_msg_or_host_ip;
|
||||||
continue;
|
error_fn(std::move(error_message));
|
||||||
|
//continue;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* name = get_name();
|
const char* name = get_name();
|
||||||
const auto upload_filename = upload_data.upload_path.filename();
|
const auto upload_filename = upload_data.upload_path.filename();
|
||||||
const auto upload_parent_path = upload_data.upload_path.parent_path();
|
const auto upload_parent_path = upload_data.upload_path.parent_path();
|
||||||
std::string url = substitute_host(make_url("api/files/local"), ip.to_string());
|
std::string url = substitute_host(make_url("api/files/local"), resolved_addr.to_string());
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Uploading file %2% at %3%, filename: %4%, path: %5%, print: %6%")
|
BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Uploading file %2% at %3%, filename: %4%, path: %5%, print: %6%")
|
||||||
|
@ -37,12 +37,11 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual bool validate_version_text(const boost::optional<std::string> &version_text) const;
|
virtual bool validate_version_text(const boost::optional<std::string> &version_text) const;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
virtual bool upload_inner_with_resolved_ip(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, const std::vector<boost::asio::ip::address>& resolved_addr) const;
|
virtual bool upload_inner_with_resolved_ip(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, const boost::asio::ip::address& resolved_addr) const;
|
||||||
virtual bool test_with_resolved_ip(wxString& curl_msg) const;
|
virtual bool test_with_resolved_ip(wxString& curl_msg) const;
|
||||||
#endif
|
#endif
|
||||||
virtual bool upload_inner_with_host(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn) const;
|
virtual bool upload_inner_with_host(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_host;
|
std::string m_host;
|
||||||
std::string m_apikey;
|
std::string m_apikey;
|
||||||
|
Loading…
Reference in New Issue
Block a user