mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-23 06:33:57 -06:00
Save binded local machines
This commit is contained in:
parent
82ce8c94b4
commit
2e64cc2f7e
5 changed files with 129 additions and 12 deletions
|
@ -431,7 +431,7 @@ std::string MachineObject::get_ftp_folder()
|
|||
return DeviceManager::get_ftp_folder(printer_type);
|
||||
}
|
||||
|
||||
std::string MachineObject::get_access_code()
|
||||
std::string MachineObject::get_access_code() const
|
||||
{
|
||||
if (get_user_access_code().empty())
|
||||
return access_code;
|
||||
|
@ -445,6 +445,7 @@ void MachineObject::set_access_code(std::string code, bool only_refresh)
|
|||
AppConfig* config = GUI::wxGetApp().app_config;
|
||||
if (config && !code.empty()) {
|
||||
GUI::wxGetApp().app_config->set_str("access_code", dev_id, code);
|
||||
DeviceManager::update_local_machine(*this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -466,11 +467,12 @@ void MachineObject::set_user_access_code(std::string code, bool only_refresh)
|
|||
AppConfig* config = GUI::wxGetApp().app_config;
|
||||
if (config && !code.empty()) {
|
||||
GUI::wxGetApp().app_config->set_str("user_access_code", dev_id, code);
|
||||
DeviceManager::update_local_machine(*this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string MachineObject::get_user_access_code()
|
||||
std::string MachineObject::get_user_access_code() const
|
||||
{
|
||||
AppConfig* config = GUI::wxGetApp().app_config;
|
||||
if (config) {
|
||||
|
@ -479,7 +481,7 @@ std::string MachineObject::get_user_access_code()
|
|||
return "";
|
||||
}
|
||||
|
||||
bool MachineObject::is_lan_mode_printer()
|
||||
bool MachineObject::is_lan_mode_printer() const
|
||||
{
|
||||
bool result = false;
|
||||
if (!dev_connection_type.empty() && dev_connection_type == "lan")
|
||||
|
@ -4822,6 +4824,7 @@ int MachineObject::parse_json(std::string payload, bool key_field_only)
|
|||
if (diff.count() > 10.0f) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "parse_json timeout = " << diff.count();
|
||||
}
|
||||
DeviceManager::update_local_machine(*this);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -5263,6 +5266,49 @@ bool DeviceManager::key_field_only = false;
|
|||
DeviceManager::DeviceManager(NetworkAgent* agent)
|
||||
{
|
||||
m_agent = agent;
|
||||
|
||||
// Load saved local machines
|
||||
if (agent) {
|
||||
AppConfig* config = GUI::wxGetApp().app_config;
|
||||
const auto local_machines = config->get_local_machines();
|
||||
for (auto& it : local_machines) {
|
||||
const auto& m = it.second;
|
||||
MachineObject* obj = new MachineObject(m_agent, m.dev_name, m.dev_id, m.dev_ip);
|
||||
obj->printer_type = m.printer_type;
|
||||
obj->dev_connection_type = "lan";
|
||||
obj->bind_state = "free";
|
||||
obj->bind_sec_link = "secure";
|
||||
obj->m_is_online = true;
|
||||
obj->last_alive = Slic3r::Utils::get_current_time_utc();
|
||||
obj->set_access_code(config->get("access_code", m.dev_id), false);
|
||||
obj->set_user_access_code(config->get("user_access_code", m.dev_id), false);
|
||||
if (obj->has_access_right()) {
|
||||
localMachineList.insert(std::make_pair(m.dev_id, obj));
|
||||
} else {
|
||||
config->erase_local_machine(m.dev_id);
|
||||
delete obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManager::update_local_machine(const MachineObject& m)
|
||||
{
|
||||
AppConfig* config = GUI::wxGetApp().app_config;
|
||||
if (config) {
|
||||
if (m.is_lan_mode_printer()) {
|
||||
if (m.has_access_right()) {
|
||||
BBLocalMachine local_machine;
|
||||
local_machine.dev_id = m.dev_id;
|
||||
local_machine.dev_name = m.dev_name;
|
||||
local_machine.dev_ip = m.dev_ip;
|
||||
local_machine.printer_type = m.printer_type;
|
||||
config->update_local_machine(local_machine);
|
||||
}
|
||||
} else {
|
||||
config->erase_local_machine(m.dev_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DeviceManager::~DeviceManager()
|
||||
|
@ -5443,6 +5489,7 @@ void DeviceManager::on_machine_alive(std::string json_str)
|
|||
|
||||
BOOST_LOG_TRIVIAL(info) << "SsdpDiscovery::New Machine, ip = " << Slic3r::GUI::wxGetApp().format_IP(dev_ip) << ", printer_name= " << dev_name << ", printer_type = " << printer_type_str << ", signal = " << printer_signal;
|
||||
}
|
||||
update_local_machine(*obj);
|
||||
}
|
||||
catch (...) {
|
||||
;
|
||||
|
|
|
@ -426,14 +426,14 @@ public:
|
|||
std::string dev_connection_name; /* lan | eth */
|
||||
void set_dev_ip(std::string ip) {dev_ip = ip;}
|
||||
std::string get_ftp_folder();
|
||||
bool has_access_right() { return !get_access_code().empty(); }
|
||||
std::string get_access_code();
|
||||
bool has_access_right() const { return !get_access_code().empty(); }
|
||||
std::string get_access_code() const;
|
||||
|
||||
void set_access_code(std::string code, bool only_refresh = true);
|
||||
void set_user_access_code(std::string code, bool only_refresh = true);
|
||||
void erase_user_access_code();
|
||||
std::string get_user_access_code();
|
||||
bool is_lan_mode_printer();
|
||||
std::string get_user_access_code() const;
|
||||
bool is_lan_mode_printer() const;
|
||||
|
||||
//PRINTER_TYPE printer_type = PRINTER_3DPrinter_UKNOWN;
|
||||
std::string printer_type; /* model_id */
|
||||
|
@ -1085,6 +1085,8 @@ public:
|
|||
static std::vector<std::string> get_compatible_machine(std::string type_str);
|
||||
static boost::bimaps::bimap<std::string, std::string> get_all_model_id_with_name();
|
||||
static std::string load_gcode(std::string type_str, std::string gcode_file);
|
||||
|
||||
static void update_local_machine(const MachineObject& m);
|
||||
};
|
||||
|
||||
// change the opacity
|
||||
|
|
|
@ -740,6 +740,11 @@ void SelectMachinePopup::update_user_devices()
|
|||
op->Bind(EVT_UNBIND_MACHINE, [this, dev, mobj](wxCommandEvent& e) {
|
||||
dev->set_selected_machine("");
|
||||
if (mobj) {
|
||||
AppConfig* config = wxGetApp().app_config;
|
||||
if (config) {
|
||||
config->erase_local_machine(mobj->dev_id);
|
||||
}
|
||||
|
||||
mobj->set_access_code("");
|
||||
mobj->erase_user_access_code();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue