aboutsummaryrefslogtreecommitdiff
path: root/src/base_tab/BaseImportTab.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/base_tab/BaseImportTab.cpp')
-rw-r--r--src/base_tab/BaseImportTab.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/base_tab/BaseImportTab.cpp b/src/base_tab/BaseImportTab.cpp
index b43cb54..422a76f 100644
--- a/src/base_tab/BaseImportTab.cpp
+++ b/src/base_tab/BaseImportTab.cpp
@@ -2,12 +2,7 @@
#include <algorithm>
#include "gamebase/GameBase.hpp"
-#define NOTIFY_MANAGE_TAB() \
-{ \
- wxCommandEvent e(REFRESH_MANAGE_TAB,GetId()); \
- ProcessEvent(e); \
-}
-
+// Foreign events
wxDECLARE_EVENT(REFRESH_MANAGE_TAB, wxCommandEvent);
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);
RefreshImportLists();
RefreshPendingImports();
+
+ opened_db_list->SetHint("No other database open");
+
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::OnImportSelection, this, ID_IMPORT_SELECTION);
this->Bind(wxEVT_BUTTON, &BaseImportTab::OnImportDatabase, this, ID_IMPORT_DB);
-
- opened_db_list->SetHint("No other database open");
}
void BaseImportTab::OnImportDatabase(wxCommandEvent &event){
@@ -40,25 +36,28 @@ void BaseImportTab::OnImportDatabase(wxCommandEvent &event){
}
void BaseImportTab::RefreshPendingImports(){
+ // Compute metrics
import_ndb=databases_to_import.size();
import_ngames=games_to_import.size();
import_nselect=0;
for (auto it = selected_games_to_import.begin(); it != selected_games_to_import.end(); it++){
import_nselect+=it->second.size();
}
+ // Update message
pending_imports->Clear();
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");
}else
pending_imports->SetHint("No pending imports");
-
- NOTIFY_MANAGE_TAB();
+ // Don't forget to notify BaseManageTab
+ wxCommandEvent e(REFRESH_MANAGE_TAB,GetId());
+ ProcessEvent(e);
}
void BaseImportTab::RefreshImportLists(){
opened_game_list->Clear();
opened_db_list->Clear();
- for (TabInfos *i : wxGetApp().ListTabInfos()) {
+ for (TabInfos *i : wxGetApp().ListTabInfos()) {
if (i->type == TabInfos::GAME) {
wxWindow *win = dynamic_cast<wxWindow *>(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,
wxLIST_STATE_SELECTED)) !=
wxNOT_FOUND) {
+ // Get game id
long game_id=glm->GetItemGameId(selected);
+ // Select the right db hashmap
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()){
game_list[game_id]=selected_base->GetGame(glm->GetItemGameId(selected));
glm->MarkItemAsImported(selected);
@@ -131,7 +133,6 @@ void BaseImportTab::Reset(std::shared_ptr<GameBase> base){
this->selected_games_to_import.clear();
glm->Clear();
RefreshPendingImports();
- NOTIFY_MANAGE_TAB();
}
std::vector<std::shared_ptr<Game>> BaseImportTab::GetGameToImport(){