Update MainFrame.cpp

This commit is contained in:
sunsets
2023-11-27 13:33:04 +08:00
parent 7d152a9d82
commit 1c1786d922

View File

@@ -2132,12 +2132,8 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/)
size_t new_selection = tab == (size_t)(-1) ? m_last_selected_tab : (m_layout == ESettingsLayout::Dlg && tab != 0) ? tab - 1 : tab; size_t new_selection = tab == (size_t)(-1) ? m_last_selected_tab : (m_layout == ESettingsLayout::Dlg && tab != 0) ? tab - 1 : tab;
//B4 //B4
if (m_tabpanel->GetSelection() == 4) { if (m_tabpanel->GetSelection() == 4) {
if (const DynamicPrintConfig *cfg = wxGetApp().preset_bundle->physical_printers.get_selected_printer_config(); cfg) {
std::string select_name = wxGetApp().preset_bundle->physical_printers.get_selected_full_printer_name();
PresetBundle & preset_bundle = *wxGetApp().preset_bundle;
const PhysicalPrinter &pp = preset_bundle.physical_printers.get_selected_printer();
wxString host = pp.config.opt_string("print_host");
// B45 // B45
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
const PhysicalPrinterCollection &ph_printers = preset_bundle.physical_printers; const PhysicalPrinterCollection &ph_printers = preset_bundle.physical_printers;
struct PhysicalPrinterPresetData struct PhysicalPrinterPresetData
{ {
@@ -2178,10 +2174,6 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/)
} }
} }
for (const PhysicalPrinterPresetData &data : preset_data) { for (const PhysicalPrinterPresetData &data : preset_data) {
bool foundButton = false; bool foundButton = false;
for (MachineListButton *button : m_buttons) { for (MachineListButton *button : m_buttons) {
@@ -2198,15 +2190,8 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/)
Preset *preset = m_collection->find_preset(data->name); Preset *preset = m_collection->find_preset(data->name);
if (!preset || !preset->is_visible) if (!preset || !preset->is_visible)
continue; continue;
//auto printer = preset_bundle.physical_printers.printer(count);
wxStringTokenizer tokenizer((data->fullname), " "); wxStringTokenizer tokenizer((data->fullname), " ");
auto *printer = preset_bundle.physical_printers.find_printer(std::string(tokenizer.GetNextToken().mb_str())); auto *printer = preset_bundle.physical_printers.find_printer(std::string(tokenizer.GetNextToken().mb_str()));
//wxString host = printer.config.opt_string("print_host");
wxString host = (printer->config.opt_string("print_host")); wxString host = (printer->config.opt_string("print_host"));
std::regex ipRegex(R"(\b(?:\d{1,3}\.){3}\d{1,3}\b)"); std::regex ipRegex(R"(\b(?:\d{1,3}\.){3}\d{1,3}\b)");
@@ -2229,7 +2214,16 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/)
} }
m_printer_view->ResumeButton(); m_printer_view->ResumeButton();
if (host.empty()) {
if (const DynamicPrintConfig *cfg = wxGetApp().preset_bundle->physical_printers.get_selected_printer_config(); cfg) {
const PhysicalPrinter &pp = preset_bundle.physical_printers.get_selected_printer();
wxString host = pp.config.opt_string("print_host");
//B45
std::regex ipRegex(R"(\b(?:\d{1,3}\.){3}\d{1,3}\b)");
bool isValidIPAddress = std::regex_match(host.ToStdString(), ipRegex);
if (host.empty() || !isValidIPAddress) {
tem_host = ""; tem_host = "";
host = wxString::Format("file://%s/web/qidi/missing_connection.html", from_u8(resources_dir())); host = wxString::Format("file://%s/web/qidi/missing_connection.html", from_u8(resources_dir()));
} }