diff --git a/src/source_dialog.cpp b/src/source_dialog.cpp index 8bc7d32..7889003 100644 --- a/src/source_dialog.cpp +++ b/src/source_dialog.cpp @@ -470,7 +470,7 @@ void form_rebuild(Chooser& c, SourceKind& kind, const SourceConfig& initial) { c.form_cfg.description.empty() ? nullptr : c.form_cfg.description.c_str()); c.form_cfg.write(initial); c.form_cfg.on_change([&c] { - if (c.form_connect != nullptr) { + if (c.form_connect != nullptr && c.form_cfg.valid) { gtk_widget_set_sensitive(c.form_connect, c.form_cfg.valid() ? TRUE : FALSE); } }); @@ -570,6 +570,18 @@ void open_form(Chooser& c, int edit_index = -1) { edit_index >= 0 && static_cast(edit_index) < c.known.size() ? &c.known[static_cast(edit_index)] : nullptr; + // An edit of a session whose kind is not registered is refused: the form would rebuild as the first + // kind, and Save would rewrite the file as that kind and delete the original. + if (src != nullptr && !src->kind.empty()) { + bool known_kind = false; + for (SourceKind* k : kinds()) known_kind = known_kind || k->id() == src->kind; + if (!known_kind) { + std::fprintf(stderr, "[sources] cannot edit %s: source kind '%s' is not registered\n", + src->config.c_str(), src->kind.c_str()); + std::fflush(stderr); + return; + } + } c.edit_host = src != nullptr ? src->host : std::string(); c.edit_port = src != nullptr ? src->port : 0; c.edit_config = src != nullptr ? src->config : std::string(); @@ -668,6 +680,8 @@ void open_form(Chooser& c, int edit_index = -1) { ch.form_cfg_rows.clear(); ch.form_kind_row = nullptr; ch.form_source_group = nullptr; + ch.form_connect = nullptr; + ch.form_kinds.clear(); }), &c);