mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Cleaning code
This commit is contained in:
parent
cb6fbd18f3
commit
4eeb110f80
5 changed files with 21 additions and 16 deletions
|
@ -57,7 +57,6 @@ std::shared_ptr<Game> BaseGameTab::OpenGame(long gameid, long item) {
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "gamebase/GameBase.hpp"
|
#include "gamebase/GameBase.hpp"
|
||||||
|
|
||||||
#define NOTIFY_MANAGE_TAB() \
|
// Foreign events
|
||||||
{ \
|
|
||||||
wxCommandEvent e(REFRESH_MANAGE_TAB,GetId()); \
|
|
||||||
ProcessEvent(e); \
|
|
||||||
}
|
|
||||||
|
|
||||||
wxDECLARE_EVENT(REFRESH_MANAGE_TAB, wxCommandEvent);
|
wxDECLARE_EVENT(REFRESH_MANAGE_TAB, wxCommandEvent);
|
||||||
|
|
||||||
BaseImportTab::BaseImportTab(wxFrame *parent, std::shared_ptr<GameBase> db, TabInfos *main_tab):
|
BaseImportTab::BaseImportTab(wxFrame *parent, std::shared_ptr<GameBase> db, TabInfos *main_tab):
|
||||||
|
@ -21,12 +16,13 @@ TabBase_TabImport(parent), main_tab(main_tab), base(db)
|
||||||
glm=std::make_shared<GameListManager>(game_list);
|
glm=std::make_shared<GameListManager>(game_list);
|
||||||
RefreshImportLists();
|
RefreshImportLists();
|
||||||
RefreshPendingImports();
|
RefreshPendingImports();
|
||||||
|
|
||||||
|
opened_db_list->SetHint("No other database open");
|
||||||
|
|
||||||
this->Bind(wxEVT_BUTTON, &BaseImportTab::OnLoad, this, ID_LOAD_BUTTON);
|
this->Bind(wxEVT_BUTTON, &BaseImportTab::OnLoad, this, ID_LOAD_BUTTON);
|
||||||
this->Bind(wxEVT_BUTTON, &BaseImportTab::OnImportGame, this, ID_IMPORT_GAME_BUTTON);
|
this->Bind(wxEVT_BUTTON, &BaseImportTab::OnImportGame, this, ID_IMPORT_GAME_BUTTON);
|
||||||
this->Bind(wxEVT_BUTTON, &BaseImportTab::OnImportSelection, this, ID_IMPORT_SELECTION);
|
this->Bind(wxEVT_BUTTON, &BaseImportTab::OnImportSelection, this, ID_IMPORT_SELECTION);
|
||||||
this->Bind(wxEVT_BUTTON, &BaseImportTab::OnImportDatabase, this, ID_IMPORT_DB);
|
this->Bind(wxEVT_BUTTON, &BaseImportTab::OnImportDatabase, this, ID_IMPORT_DB);
|
||||||
|
|
||||||
opened_db_list->SetHint("No other database open");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseImportTab::OnImportDatabase(wxCommandEvent &event){
|
void BaseImportTab::OnImportDatabase(wxCommandEvent &event){
|
||||||
|
@ -40,25 +36,28 @@ void BaseImportTab::OnImportDatabase(wxCommandEvent &event){
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseImportTab::RefreshPendingImports(){
|
void BaseImportTab::RefreshPendingImports(){
|
||||||
|
// Compute metrics
|
||||||
import_ndb=databases_to_import.size();
|
import_ndb=databases_to_import.size();
|
||||||
import_ngames=games_to_import.size();
|
import_ngames=games_to_import.size();
|
||||||
import_nselect=0;
|
import_nselect=0;
|
||||||
for (auto it = selected_games_to_import.begin(); it != selected_games_to_import.end(); it++){
|
for (auto it = selected_games_to_import.begin(); it != selected_games_to_import.end(); it++){
|
||||||
import_nselect+=it->second.size();
|
import_nselect+=it->second.size();
|
||||||
}
|
}
|
||||||
|
// Update message
|
||||||
pending_imports->Clear();
|
pending_imports->Clear();
|
||||||
if(import_ndb+import_ngames+import_nselect>0){
|
if(import_ndb+import_ngames+import_nselect>0){
|
||||||
pending_imports->AppendText(" Pending imports: "+std::to_string(import_ngames+import_nselect)+" games and "+std::to_string(import_ndb)+" databases");
|
pending_imports->AppendText(" Pending imports: "+std::to_string(import_ngames+import_nselect)+" games and "+std::to_string(import_ndb)+" databases");
|
||||||
}else
|
}else
|
||||||
pending_imports->SetHint("No pending imports");
|
pending_imports->SetHint("No pending imports");
|
||||||
|
// Don't forget to notify BaseManageTab
|
||||||
NOTIFY_MANAGE_TAB();
|
wxCommandEvent e(REFRESH_MANAGE_TAB,GetId());
|
||||||
|
ProcessEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseImportTab::RefreshImportLists(){
|
void BaseImportTab::RefreshImportLists(){
|
||||||
opened_game_list->Clear();
|
opened_game_list->Clear();
|
||||||
opened_db_list->Clear();
|
opened_db_list->Clear();
|
||||||
for (TabInfos *i : wxGetApp().ListTabInfos()) {
|
for (TabInfos *i : wxGetApp().ListTabInfos()) {
|
||||||
if (i->type == TabInfos::GAME) {
|
if (i->type == TabInfos::GAME) {
|
||||||
wxWindow *win = dynamic_cast<wxWindow *>(i);
|
wxWindow *win = dynamic_cast<wxWindow *>(i);
|
||||||
opened_game_list->Append(win->GetLabel(),i);
|
opened_game_list->Append(win->GetLabel(),i);
|
||||||
|
@ -78,8 +77,11 @@ void BaseImportTab::OnImportSelection(wxCommandEvent &event){
|
||||||
while ((selected = game_list->GetNextItem(selected, wxLIST_NEXT_ALL,
|
while ((selected = game_list->GetNextItem(selected, wxLIST_NEXT_ALL,
|
||||||
wxLIST_STATE_SELECTED)) !=
|
wxLIST_STATE_SELECTED)) !=
|
||||||
wxNOT_FOUND) {
|
wxNOT_FOUND) {
|
||||||
|
// Get game id
|
||||||
long game_id=glm->GetItemGameId(selected);
|
long game_id=glm->GetItemGameId(selected);
|
||||||
|
// Select the right db hashmap
|
||||||
auto &game_list=selected_games_to_import[selected_base->GetFilePath()];
|
auto &game_list=selected_games_to_import[selected_base->GetFilePath()];
|
||||||
|
// If game not in this hasmap add it
|
||||||
if(game_list.find(game_id) == game_list.end()){
|
if(game_list.find(game_id) == game_list.end()){
|
||||||
game_list[game_id]=selected_base->GetGame(glm->GetItemGameId(selected));
|
game_list[game_id]=selected_base->GetGame(glm->GetItemGameId(selected));
|
||||||
glm->MarkItemAsImported(selected);
|
glm->MarkItemAsImported(selected);
|
||||||
|
@ -131,7 +133,6 @@ void BaseImportTab::Reset(std::shared_ptr<GameBase> base){
|
||||||
this->selected_games_to_import.clear();
|
this->selected_games_to_import.clear();
|
||||||
glm->Clear();
|
glm->Clear();
|
||||||
RefreshPendingImports();
|
RefreshPendingImports();
|
||||||
NOTIFY_MANAGE_TAB();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Game>> BaseImportTab::GetGameToImport(){
|
std::vector<std::shared_ptr<Game>> BaseImportTab::GetGameToImport(){
|
||||||
|
|
|
@ -9,10 +9,13 @@
|
||||||
class BaseImportTab : public TabBase_TabImport {
|
class BaseImportTab : public TabBase_TabImport {
|
||||||
TabInfos *main_tab;
|
TabInfos *main_tab;
|
||||||
std::shared_ptr<GameListManager> glm;
|
std::shared_ptr<GameListManager> glm;
|
||||||
|
|
||||||
|
// Import states data structures
|
||||||
std::vector<std::shared_ptr<Game>> games_to_import;
|
std::vector<std::shared_ptr<Game>> games_to_import;
|
||||||
std::vector<std::string> databases_to_import;
|
std::vector<std::string> databases_to_import;
|
||||||
/// @brief Old for each pair of DB (file path) and game id, the given game object
|
/// @brief Hold games for each databases
|
||||||
std::unordered_map<std::string, std::unordered_map<long,std::shared_ptr<Game>>> selected_games_to_import;
|
std::unordered_map<std::string, std::unordered_map<long,std::shared_ptr<Game>>> selected_games_to_import;
|
||||||
|
|
||||||
std::shared_ptr<GameBase> base;
|
std::shared_ptr<GameBase> base;
|
||||||
std::shared_ptr<GameBase> selected_base;
|
std::shared_ptr<GameBase> selected_base;
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,11 @@
|
||||||
|
|
||||||
class BaseManageTab : public TabBase_TabManage {
|
class BaseManageTab : public TabBase_TabManage {
|
||||||
|
|
||||||
/// @brief Never free the following pointers in that class
|
/// Never free the following pointers in that class
|
||||||
std::shared_ptr<GameListManager> glm;
|
std::shared_ptr<GameListManager> glm;
|
||||||
std::shared_ptr<GameBase> base;
|
std::shared_ptr<GameBase> base;
|
||||||
|
|
||||||
|
/// Pointers for data access
|
||||||
BaseImportTab *import_tab;
|
BaseImportTab *import_tab;
|
||||||
BaseGameTab *games_tab;
|
BaseGameTab *games_tab;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class BaseTab : public TabBase, public TabInfos {
|
||||||
/// @brief The last opened game
|
/// @brief The last opened game
|
||||||
std::shared_ptr<Game> game;
|
std::shared_ptr<Game> game;
|
||||||
|
|
||||||
/// All sub tabs
|
/// All sub tabs from this main table
|
||||||
BaseGameTab *games_tab;
|
BaseGameTab *games_tab;
|
||||||
BaseImportTab *import_tab;
|
BaseImportTab *import_tab;
|
||||||
BaseManageTab *manage_tab;
|
BaseManageTab *manage_tab;
|
||||||
|
|
Loading…
Add table
Reference in a new issue