ENH:add network detection for LAN mode printer

Change-Id: I0e3616b08f1a455df05c98c3b194ff9177df3ff1
This commit is contained in:
tao wang 2023-02-02 16:41:56 +08:00 committed by Lane.Wei
parent 9936c2b823
commit c000ab2d8a
7 changed files with 29 additions and 16 deletions

View file

@ -148,7 +148,7 @@ void ConnectPrinterDialog::on_button_confirm(wxCommandEvent &event)
}
}
if (m_obj) {
m_obj->set_access_code(code.ToStdString());
m_obj->set_user_access_code(code.ToStdString());
wxGetApp().getDeviceManager()->set_selected_machine(m_obj->dev_id);
}
EndModal(wxID_OK);

View file

@ -2032,7 +2032,7 @@ int MachineObject::connect(bool is_anonymous)
std::string password;
if (!is_anonymous) {
username = "bblp";
password = access_code;
password = get_access_code();
}
if (m_agent) {
try {

View file

@ -404,7 +404,7 @@ public:
std::string dev_connection_type; /* lan | cloud */
std::string connection_type() { return dev_connection_type; }
void set_dev_ip(std::string ip) {dev_ip = ip;};
bool has_access_right() { return !access_code.empty(); }
bool has_access_right() { return !get_access_code().empty(); }
void set_access_code(std::string code);
std::string get_access_code();
void set_user_access_code(std::string code);

View file

@ -1714,7 +1714,7 @@ void GUI_App::init_networking_callbacks()
event.SetInt(1);
event.SetString(obj->dev_id);
} else if (state == ConnectStatus::ConnectStatusFailed) {
obj->set_access_code("");
obj->set_user_access_code("");
m_device_manager->set_selected_machine("");
wxString text;
if (msg == "5") {

View file

@ -141,13 +141,17 @@ void SendJob::process()
if (result != 0) {
BOOST_LOG_TRIVIAL(error) << "access code is invalid";
m_enter_ip_address_fun_fail();
}
else {
m_enter_ip_address_fun_success();
}
m_job_finished = true;
return;
}
else {
if (!m_chck_and_continue) {
m_enter_ip_address_fun_success();
m_job_finished = true;
return;
}
}
}
/* display info */
if (this->connection_type == "lan") {

View file

@ -21,6 +21,7 @@ class SendJob : public PlaterJob
bool m_job_finished{ false };
int m_print_job_completed_id = 0;
bool m_is_check_mode{false};
bool m_chck_and_continue{false};
std::function<void()> m_success_fun{nullptr};
std::function<void()> m_enter_ip_address_fun_fail{nullptr};
std::function<void()> m_enter_ip_address_fun_success{nullptr};
@ -54,6 +55,7 @@ public:
wxString get_http_error_msg(unsigned int status, std::string body);
void set_check_mode() {m_is_check_mode = true;};
void check_and_continue() {m_chck_and_continue = true;};
bool is_finished() { return m_job_finished; }
void process() override;
void on_success(std::function<void()> success);

View file

@ -571,10 +571,14 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event)
if (!dev) return;
MachineObject *obj_ = dev->get_selected_machine();
assert(obj_->dev_id == m_printer_last_select);
if (obj_ == nullptr) {
m_printer_last_select = "";
m_comboBox_printer->SetTextLabel("");
return;
}
assert(obj_->dev_id == m_printer_last_select);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", print_job: for send task, current printer id = " << m_printer_last_select << std::endl;
show_status(PrintDialogStatus::PrintStatusSending);
@ -649,7 +653,6 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event)
m_send_job = std::make_shared<SendJob>(m_status_bar, m_plater, m_printer_last_select);
m_send_job->m_dev_ip = obj_->dev_ip;
m_send_job->m_access_code = obj_->get_access_code();
m_send_job->m_local_use_ssl = obj_->local_use_ssl;
m_send_job->connection_type = obj_->connection_type();
@ -657,10 +660,7 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event)
m_send_job->has_sdcard = obj_->has_sdcard();
m_send_job->set_project_name(m_current_project_name.utf8_string());
/*m_send_job->on_check_ip_address_success([this, obj_]() {
wxCommandEvent* evt = new wxCommandEvent(EVT_CLEAR_IPADDRESS);
wxQueueEvent(this, evt);
});*/
enable_prepare_mode = false;
m_send_job->on_check_ip_address_fail([this]() {
wxCommandEvent* evt = new wxCommandEvent(EVT_CLEAR_IPADDRESS);
@ -668,8 +668,15 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event)
wxGetApp().show_ip_address_enter_dialog();
});
enable_prepare_mode = false;
if (obj_->is_lan_mode_printer()) {
m_send_job->set_check_mode();
m_send_job->check_and_continue();
m_send_job->start();
}
else {
m_send_job->start();
}
BOOST_LOG_TRIVIAL(info) << "send_job: send print job";
}