This commit is contained in:
supermerill 2021-10-23 12:02:45 +02:00
parent 46549625d5
commit 75b59455b6
2 changed files with 21 additions and 2 deletions

View File

@ -653,6 +653,7 @@ void PhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect)
void PhysicalPrinterDialog::OnOK(wxEvent& event) void PhysicalPrinterDialog::OnOK(wxEvent& event)
{ {
BOOST_LOG_TRIVIAL(info) << "begin of pysical update";
wxString printer_name = m_printer_name->GetValue(); wxString printer_name = m_printer_name->GetValue();
if (printer_name.IsEmpty()) { if (printer_name.IsEmpty()) {
warning_catcher(this, _L("The supplied name is empty. It can't be saved.")); warning_catcher(this, _L("The supplied name is empty. It can't be saved."));
@ -675,11 +676,14 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event)
return; return;
m_printer.name = existing->name; m_printer.name = existing->name;
BOOST_LOG_TRIVIAL(info) << "Using existing name";
} }
BOOST_LOG_TRIVIAL(info) << "Adding physical to all presets";
std::set<std::string> repeat_presets; std::set<std::string> repeat_presets;
m_printer.reset_presets(); m_printer.reset_presets();
for (PresetForPrinter* preset : m_presets) { for (PresetForPrinter* preset : m_presets) {
BOOST_LOG_TRIVIAL(info) << "check repeat preset " << preset->get_preset_name() << " : " << (!m_printer.add_preset(preset->get_preset_name()));
if (!m_printer.add_preset(preset->get_preset_name())) if (!m_printer.add_preset(preset->get_preset_name()))
repeat_presets.emplace(preset->get_preset_name()); repeat_presets.emplace(preset->get_preset_name());
} }
@ -698,18 +702,22 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event)
return; return;
} }
BOOST_LOG_TRIVIAL(info) << "check rename";
std::string renamed_from; std::string renamed_from;
// temporary save previous printer name if it was edited // temporary save previous printer name if it was edited
if (m_printer.name != into_u8(m_default_name) && if (m_printer.name != into_u8(m_default_name) &&
m_printer.name != into_u8(printer_name)) m_printer.name != into_u8(printer_name))
renamed_from = m_printer.name; renamed_from = m_printer.name;
BOOST_LOG_TRIVIAL(info) << "update printer name, if it was changed, to "<< printer_name;
//update printer name, if it was changed //update printer name, if it was changed
m_printer.set_name(into_u8(printer_name)); m_printer.set_name(into_u8(printer_name));
BOOST_LOG_TRIVIAL(info) << "save new physical printer";
// save new physical printer // save new physical printer
printers.save_printer(m_printer, renamed_from); printers.save_printer(m_printer, renamed_from);
BOOST_LOG_TRIVIAL(info) << "refresh preset list on Printer Settings Tab";
if (m_printer.preset_names.find(printers.get_selected_printer_preset_name()) == m_printer.preset_names.end()) { if (m_printer.preset_names.find(printers.get_selected_printer_preset_name()) == m_printer.preset_names.end()) {
// select first preset for this printer // select first preset for this printer
printers.select_printer(m_printer); printers.select_printer(m_printer);
@ -719,6 +727,7 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event)
else else
wxGetApp().get_tab(Preset::TYPE_PRINTER)->update_preset_choice(); wxGetApp().get_tab(Preset::TYPE_PRINTER)->update_preset_choice();
BOOST_LOG_TRIVIAL(info) << "end of pysical update";
event.Skip(); event.Skip();
} }

View File

@ -44,37 +44,47 @@ bool OctoPrint::test(wxString &msg) const
auto http = Http::get(std::move(url)); auto http = Http::get(std::move(url));
set_auth(http); set_auth(http);
BOOST_LOG_TRIVIAL(info) << "auth set";
http.on_error([&](std::string body, std::string error, unsigned status) { http.on_error([&](std::string body, std::string error, unsigned status) {
BOOST_LOG_TRIVIAL(info) << "Error with '"<< body<<"'";
BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error getting version: %2%, HTTP %3%, body: `%4%`") % name % error % status % body; BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error getting version: %2%, HTTP %3%, body: `%4%`") % name % error % status % body;
res = false; res = false;
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(info) << boost::format("%1%: Got version: %2%") % name % body;
try { try {
std::stringstream ss(body); std::stringstream ss(body);
pt::ptree ptree; pt::ptree ptree;
BOOST_LOG_TRIVIAL(info) << "ready to read json";
pt::read_json(ss, ptree); pt::read_json(ss, ptree);
BOOST_LOG_TRIVIAL(info) << "json read";
if (! ptree.get_optional<std::string>("api")) { if (! ptree.get_optional<std::string>("api")) {
BOOST_LOG_TRIVIAL(info) << "Error: no api";
res = false; res = false;
return; return;
} }
BOOST_LOG_TRIVIAL(info) << "text?";
const auto text = ptree.get_optional<std::string>("text"); const auto text = ptree.get_optional<std::string>("text");
BOOST_LOG_TRIVIAL(info) << "text="<<text;
res = validate_version_text(text); res = validate_version_text(text);
BOOST_LOG_TRIVIAL(info) << "version validated=" << res;
if (! res) { if (! res) {
msg = GUI::from_u8((boost::format(_utf8(L("Mismatched type of print host: %s"))) % (text ? *text : "OctoPrint")).str()); msg = GUI::from_u8((boost::format(_utf8(L("Mismatched type of print host: %s"))) % (text ? *text : "OctoPrint")).str());
} }
} }
catch (const std::exception &) { catch (const std::exception &e) {
BOOST_LOG_TRIVIAL(info) << "Error: exception: " << e.what();
res = false; res = false;
msg = "Could not parse server response"; msg = "Could not parse server response";
} }
}) })
.perform_sync(); .perform_sync();
BOOST_LOG_TRIVIAL(info) << "test successful";
return res; return res;
} }