mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-25 11:52:05 +00:00
refactor
This commit is contained in:
@@ -518,7 +518,7 @@ namespace Slic3r
|
||||
#if !BBL_RELEASE_TO_PUBLIC
|
||||
it->second->connect(Slic3r::GUI::wxGetApp().app_config->get("enable_ssl_for_mqtt") == "true" ? true : false);
|
||||
#else
|
||||
it->second->connect(it->second->local_use_ssl_for_mqtt);
|
||||
it->second->connect(it->second->local_use_ssl);
|
||||
#endif
|
||||
it->second->set_lan_mode_connection_state(true);
|
||||
}
|
||||
@@ -542,7 +542,7 @@ namespace Slic3r
|
||||
#if !BBL_RELEASE_TO_PUBLIC
|
||||
it->second->connect(Slic3r::GUI::wxGetApp().app_config->get("enable_ssl_for_mqtt") == "true" ? true : false);
|
||||
#else
|
||||
it->second->connect(it->second->local_use_ssl_for_mqtt);
|
||||
it->second->connect(it->second->local_use_ssl);
|
||||
#endif
|
||||
it->second->set_lan_mode_connection_state(true);
|
||||
}
|
||||
|
||||
@@ -363,6 +363,30 @@ std::string MachineObject::get_ftp_folder()
|
||||
return DevPrinterConfigUtil::get_ftp_folder(printer_type);
|
||||
}
|
||||
|
||||
std::string MachineObject::dev_id_from_address(const std::string& host, const std::string& port)
|
||||
{
|
||||
std::string result = host;
|
||||
// Normalize host: strip protocol and path
|
||||
if (result.find("http://") == 0)
|
||||
result = result.substr(7);
|
||||
else if (result.find("https://") == 0)
|
||||
result = result.substr(8);
|
||||
auto slash = result.find('/');
|
||||
if (slash != std::string::npos)
|
||||
result = result.substr(0, slash);
|
||||
|
||||
// Build full address (host:port)
|
||||
if (!port.empty()) {
|
||||
// Strip inline port if present (port comes from printhost_port)
|
||||
auto colon = result.find(':');
|
||||
if (colon != std::string::npos)
|
||||
result = result.substr(0, colon);
|
||||
|
||||
result += ":" + port;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool MachineObject::HasRecentCloudMessage()
|
||||
{
|
||||
auto curr_time = std::chrono::system_clock::now();
|
||||
|
||||
@@ -164,7 +164,11 @@ public:
|
||||
std::string get_dev_id() const { return dev_id; }
|
||||
void set_dev_id(std::string val) { dev_id = val; }
|
||||
|
||||
bool local_use_ssl_for_mqtt { true };
|
||||
// Generate consistent dev_id from host address and optional port
|
||||
// Returns "host:port" or "host" if port is empty
|
||||
static std::string dev_id_from_address(const std::string& host, const std::string& port = "");
|
||||
|
||||
bool local_use_ssl { true };
|
||||
bool local_use_ssl_for_ftp { true };
|
||||
std::string get_ftp_folder();
|
||||
|
||||
|
||||
@@ -3520,32 +3520,6 @@ void GUI_App::switch_printer_agent(const std::string& agent_id)
|
||||
// Swap the agent
|
||||
m_agent->set_printer_agent(new_printer_agent);
|
||||
|
||||
// Update dependent managers
|
||||
if (m_device_manager) {
|
||||
m_device_manager->set_agent(m_agent);
|
||||
|
||||
// If there's a selected machine that was deferred due to no printer agent,
|
||||
// trigger a connection now that the agent is ready
|
||||
MachineObject* selected = m_device_manager->get_selected_machine();
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": checking for deferred connection - selected="
|
||||
<< (selected ? selected->get_dev_id() : "null");
|
||||
if (selected) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": selected machine - is_lan_mode=" << selected->is_lan_mode_printer()
|
||||
<< " is_connected=" << selected->is_connected();
|
||||
}
|
||||
if (selected && selected->is_lan_mode_printer() && !selected->is_connected()) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": connecting deferred LAN machine dev_id=" << selected->get_dev_id();
|
||||
#if !BBL_RELEASE_TO_PUBLIC
|
||||
selected->connect(app_config->get("enable_ssl_for_mqtt") == "true" ? true : false);
|
||||
#else
|
||||
selected->connect(selected->local_use_ssl_for_mqtt);
|
||||
#endif
|
||||
selected->set_lan_mode_connection_state(true);
|
||||
}
|
||||
} else {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": m_device_manager is null, cannot check for deferred connection";
|
||||
}
|
||||
|
||||
// Auto-switch MachineObject
|
||||
select_machine(effective_agent_id);
|
||||
|
||||
@@ -3571,41 +3545,12 @@ void GUI_App::select_machine(const std::string& agent_id)
|
||||
|
||||
std::string print_host = host_cfg->opt_string("print_host");
|
||||
if (print_host.empty()) {
|
||||
if (auto* physical_cfg = preset_bundle->physical_printers.get_selected_printer_config()) {
|
||||
if (!physical_cfg->opt_string("print_host").empty()) {
|
||||
host_cfg = physical_cfg;
|
||||
print_host = host_cfg->opt_string("print_host");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (print_host.empty()) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": no print_host configured, skipping auto-switch";
|
||||
return;
|
||||
}
|
||||
|
||||
// Normalize host: strip protocol and path
|
||||
std::string host = print_host;
|
||||
if (host.find("http://") == 0) host = host.substr(7);
|
||||
else if (host.find("https://") == 0) host = host.substr(8);
|
||||
auto slash = host.find('/');
|
||||
if (slash != std::string::npos) host = host.substr(0, slash);
|
||||
// Strip inline port if present (port comes from printhost_port)
|
||||
auto colon = host.find(':');
|
||||
if (colon != std::string::npos) host = host.substr(0, colon);
|
||||
|
||||
// Get port from separate config
|
||||
std::string port = host_cfg->opt_string("printhost_port");
|
||||
|
||||
// Build full address (host:port) for dev_ip
|
||||
std::string full_addr = host;
|
||||
if (!port.empty()) {
|
||||
full_addr += ":" + port;
|
||||
}
|
||||
|
||||
// Generate dev_id (replace . and : with _)
|
||||
std::string dev_id = full_addr;
|
||||
std::replace(dev_id.begin(), dev_id.end(), '.', '_');
|
||||
std::replace(dev_id.begin(), dev_id.end(), ':', '_');
|
||||
// Generate dev_id from host and port
|
||||
std::string dev_id = MachineObject::dev_id_from_address(print_host, port);
|
||||
|
||||
// Check if already exists by dev_id
|
||||
MachineObject* existing = m_device_manager->get_local_machine(dev_id);
|
||||
@@ -3614,9 +3559,8 @@ void GUI_App::select_machine(const std::string& agent_id)
|
||||
if (!existing) {
|
||||
auto local_machines = m_device_manager->get_local_machinelist();
|
||||
for (auto& [id, machine] : local_machines) {
|
||||
if (machine && machine->get_dev_ip() == full_addr) {
|
||||
if (machine && machine->get_dev_ip() == dev_id) {
|
||||
existing = machine;
|
||||
dev_id = existing->get_dev_id(); // Use existing dev_id
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -3626,8 +3570,9 @@ void GUI_App::select_machine(const std::string& agent_id)
|
||||
if (!existing) {
|
||||
BBLocalMachine machine;
|
||||
machine.dev_id = dev_id;
|
||||
machine.dev_ip = full_addr;
|
||||
machine.dev_name = agent_id + " (" + full_addr + ")";
|
||||
// We use dev_id as dev_ip to store the address (host:port)
|
||||
machine.dev_ip = dev_id;
|
||||
machine.dev_name = dev_id;
|
||||
machine.printer_type = preset.config.opt_string("printer_model");
|
||||
|
||||
existing = m_device_manager->insert_local_device(
|
||||
@@ -3639,6 +3584,7 @@ void GUI_App::select_machine(const std::string& agent_id)
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": created new machine dev_id=" << dev_id;
|
||||
}
|
||||
existing->local_use_ssl = boost::istarts_with(print_host, "https://");
|
||||
|
||||
// Use MonitorPanel::select_machine() to trigger full selection flow
|
||||
// This reuses existing logic for machine switching (UI updates, callbacks, etc.)
|
||||
|
||||
@@ -202,7 +202,7 @@ void PrintJob::process(Ctl &ctl)
|
||||
// local print access
|
||||
params.dev_ip = m_dev_ip;
|
||||
params.use_ssl_for_ftp = m_local_use_ssl_for_ftp;
|
||||
params.use_ssl_for_mqtt = m_local_use_ssl_for_mqtt;
|
||||
params.use_ssl_for_mqtt = m_local_use_ssl;
|
||||
params.username = "bblp";
|
||||
params.password = m_access_code;
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
|
||||
int m_print_from_sdc_plate_idx = 0;
|
||||
|
||||
bool m_local_use_ssl_for_mqtt { true };
|
||||
bool m_local_use_ssl { true };
|
||||
bool m_local_use_ssl_for_ftp { true };
|
||||
bool task_bed_leveling;
|
||||
bool task_flow_cali;
|
||||
|
||||
@@ -183,7 +183,7 @@ void SendJob::process(Ctl &ctl)
|
||||
params.username = "bblp";
|
||||
params.password = m_access_code;
|
||||
params.use_ssl_for_ftp = m_local_use_ssl_for_ftp;
|
||||
params.use_ssl_for_mqtt = m_local_use_ssl_for_mqtt;
|
||||
params.use_ssl_for_mqtt = m_local_use_ssl;
|
||||
wxString error_text;
|
||||
std::string msg_text;
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
std::string connection_type;
|
||||
|
||||
bool m_local_use_ssl_for_ftp{true};
|
||||
bool m_local_use_ssl_for_mqtt{true};
|
||||
bool m_local_use_ssl{true};
|
||||
bool cloud_print_only { false };
|
||||
bool has_sdcard { false };
|
||||
bool task_use_ams { true };
|
||||
|
||||
@@ -1844,10 +1844,10 @@ void InputIpAddressDialog::on_send_retry()
|
||||
m_send_job->m_access_code = str_access_code.ToStdString();
|
||||
|
||||
#if !BBL_RELEASE_TO_PUBLIC
|
||||
m_send_job->m_local_use_ssl_for_mqtt = wxGetApp().app_config->get("enable_ssl_for_mqtt") == "true" ? true : false;
|
||||
m_send_job->m_local_use_ssl = wxGetApp().app_config->get("enable_ssl_for_mqtt") == "true" ? true : false;
|
||||
m_send_job->m_local_use_ssl_for_ftp = wxGetApp().app_config->get("enable_ssl_for_ftp") == "true" ? true : false;
|
||||
#else
|
||||
m_send_job->m_local_use_ssl_for_mqtt = m_obj->local_use_ssl_for_mqtt;
|
||||
m_send_job->m_local_use_ssl = m_obj->local_use_ssl;
|
||||
m_send_job->m_local_use_ssl_for_ftp = m_obj->local_use_ssl_for_ftp;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2464,10 +2464,10 @@ void SelectMachineDialog::on_send_print()
|
||||
m_print_job->m_access_code = obj_->get_access_code();
|
||||
#if !BBL_RELEASE_TO_PUBLIC
|
||||
m_print_job->m_local_use_ssl_for_ftp = wxGetApp().app_config->get("enable_ssl_for_ftp") == "true" ? true : false;
|
||||
m_print_job->m_local_use_ssl_for_mqtt = wxGetApp().app_config->get("enable_ssl_for_mqtt") == "true" ? true : false;
|
||||
m_print_job->m_local_use_ssl = wxGetApp().app_config->get("enable_ssl_for_mqtt") == "true" ? true : false;
|
||||
#else
|
||||
m_print_job->m_local_use_ssl_for_ftp = obj_->local_use_ssl_for_ftp;
|
||||
m_print_job->m_local_use_ssl_for_mqtt = obj_->local_use_ssl_for_mqtt;
|
||||
m_print_job->m_local_use_ssl = obj_->local_use_ssl;
|
||||
#endif
|
||||
m_print_job->connection_type = obj_->connection_type();
|
||||
m_print_job->cloud_print_only = obj_->is_support_cloud_print_only;
|
||||
|
||||
@@ -958,10 +958,10 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event)
|
||||
|
||||
#if !BBL_RELEASE_TO_PUBLIC
|
||||
m_send_job->m_local_use_ssl_for_ftp = wxGetApp().app_config->get("enable_ssl_for_ftp") == "true" ? true : false;
|
||||
m_send_job->m_local_use_ssl_for_mqtt = wxGetApp().app_config->get("enable_ssl_for_mqtt") == "true" ? true : false;
|
||||
m_send_job->m_local_use_ssl = wxGetApp().app_config->get("enable_ssl_for_mqtt") == "true" ? true : false;
|
||||
#else
|
||||
m_send_job->m_local_use_ssl_for_ftp = obj_->local_use_ssl_for_ftp;
|
||||
m_send_job->m_local_use_ssl_for_mqtt = obj_->local_use_ssl_for_mqtt;
|
||||
m_send_job->m_local_use_ssl = obj_->local_use_ssl;
|
||||
|
||||
#endif
|
||||
m_send_job->connection_type = obj_->connection_type();
|
||||
|
||||
Reference in New Issue
Block a user