Now engines can be added

This commit is contained in:
Loic Guegan 2022-02-26 21:43:09 +01:00
parent e601902dd5
commit 6c34ef20fb
4 changed files with 126 additions and 41 deletions

View file

@ -22,7 +22,46 @@ EngineTab::EngineTab(wxWindow *parent, uciadapter::UCI *engine,
// conf->Write(confGroup + "/path", wxString(engine_path_or_name));
CONFIG_CLOSE(conf);
InitConfiguration();
LoadConfiguration();
RefreshItemList();
Bind(wxEVT_BUTTON, &EngineTab::OnSave, this, ENGINE_SAVE_CONF_BUTTON);
Bind(wxEVT_BUTTON, &EngineTab::OnDelete, this, ENGINE_DELETE_CONF_BUTTON);
}
EngineTab::EngineTab(wxWindow *parent, std::string name)
: EngineTabBF(parent), TabInfos(TabInfos::ENGINE) {
SetLabel(name);
engineName = name;
confGroup = "engines/" + engineName;
engine_name->SetValue(engineName);
CONFIG_OPEN(conf);
engine_location->SetValue(conf->Read(confGroup + "/path"));
CONFIG_CLOSE(conf);
LoadConfiguration();
Bind(wxEVT_BUTTON, &EngineTab::OnSave, this, ENGINE_SAVE_CONF_BUTTON);
Bind(wxEVT_BUTTON, &EngineTab::OnDelete, this, ENGINE_DELETE_CONF_BUTTON);
}
void EngineTab::OnDelete(wxCommandEvent &event) {
CONFIG_OPEN(conf);
conf->DeleteGroup(confGroup);
CONFIG_CLOSE(conf);
RefreshItemList();
wxCommandEvent closeTabEvent(CLOSE_TAB_EVENT, GetId());
closeTabEvent.SetEventObject(this);
ProcessEvent(closeTabEvent);
}
void EngineTab::RefreshItemList() {
wxCommandEvent refreshEngineList(REFRESH_ENGINE_LIST, GetId());
refreshEngineList.SetEventObject(this);
ProcessEvent(refreshEngineList);
}
void EngineTab::LoadConfiguration() {
// Build wxPropertyGrid according to engine configuration
CONFIG_OPEN(conf2);
long index;
@ -48,28 +87,17 @@ EngineTab::EngineTab(wxWindow *parent, uciadapter::UCI *engine,
} while (conf2->GetNextGroup(opt_name, index));
}
CONFIG_CLOSE(conf2);
Bind(wxEVT_BUTTON, &EngineTab::OnSave, this, ENGINE_SAVE_CONF_BUTTON);
Bind(wxEVT_BUTTON, &EngineTab::OnDelete, this, ENGINE_DELETE_CONF_BUTTON);
}
void EngineTab::OnDelete(wxCommandEvent &event) {
CONFIG_OPEN(conf);
conf->DeleteGroup(confGroup);
CONFIG_CLOSE(conf);
wxCommandEvent closeTabEvent(CLOSE_TAB_EVENT, GetId());
closeTabEvent.SetEventObject(this);
ProcessEvent(closeTabEvent);
}
void EngineTab::OnSave(wxCommandEvent &event) {
CONFIG_OPEN(conf2);
wxString new_engine_name = engine_name->GetValue();
if (new_engine_name != engineName) {
conf2->RenameGroup(confGroup, "engines/" + new_engine_name);
conf2->SetPath("engines/");
conf2->RenameGroup(engineName, new_engine_name);
engineName = new_engine_name;
confGroup = "engines/" + engineName;
conf2->SetPath("..");
}
long index;
std::string optsPath = confGroup + "/options";
@ -91,6 +119,7 @@ void EngineTab::OnSave(wxCommandEvent &event) {
} while (conf2->GetNextGroup(opt_name, index));
}
CONFIG_CLOSE(conf2);
RefreshItemList();
}
void EngineTab::InitConfiguration() {

View file

@ -4,16 +4,19 @@
// Foreign event
wxDECLARE_EVENT(CLOSE_TAB_EVENT, wxCommandEvent);
wxDECLARE_EVENT(REFRESH_ENGINE_LIST, wxCommandEvent);
class EngineTab : public EngineTabBF, public TabInfos {
uciadapter::UCI *engine;
std::string confGroup, enginePath;
std::string engineName;
void InitConfiguration();
void LoadConfiguration();
void RefreshItemList();
public:
EngineTab(wxWindow *parent, uciadapter::UCI *engine,
std::string engine_path_or_name);
EngineTab(wxWindow *parent, std::string name);
void ApplyPreferences() {}
void *GetGame() { return (NULL); }
void *GetBase() { return (NULL); }