This commit is contained in:
SoftFever
2026-01-31 01:04:27 +08:00
parent 8d22fad30b
commit 5935832143
6 changed files with 32 additions and 47 deletions

View File

@@ -172,24 +172,16 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr
def.enum_labels.push_back(agent.display_name);
}
// Set initial selection based on current config value or default
const std::string current_agent = m_config->opt_string("printer_agent");
std::string selected_agent = current_agent;
if (selected_agent.empty()) {
selected_agent = ORCA_PRINTER_AGENT_ID;
}
// Verify selected agent is valid
// Resolve selected agent: use config value if valid, otherwise fall back to default
std::string selected_agent = m_config->opt_string("printer_agent");
auto it = std::find_if(agents.begin(), agents.end(), [&selected_agent](const auto& a) { return a.id == selected_agent; });
if (it == agents.end()) {
selected_agent = ORCA_PRINTER_AGENT_ID;
it = std::find_if(agents.begin(), agents.end(), [&selected_agent](const auto& a) { return a.id == selected_agent; });
}
// Set default value for the enum (using the index)
auto def_it = std::find_if(agents.begin(), agents.end(), [&selected_agent](const auto& a) { return a.id == selected_agent; });
if (def_it != agents.end()) {
size_t default_idx = std::distance(agents.begin(), def_it);
if (it != agents.end()) {
size_t default_idx = std::distance(agents.begin(), it);
def.set_default_value(new ConfigOptionInt(static_cast<int>(default_idx)));
}