aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-12-27 20:32:13 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-12-27 20:32:13 +0100
commit4eeb110f807cd175fc778a5c19e9964589b4d885 (patch)
treeab3b8cb87dc5f495fec66cdab0d44cc14f2c7ec9 /src
parentcb6fbd18f374773a6cd6ea1db42f6d6ff6147a1e (diff)
Cleaning code
Diffstat (limited to 'src')
-rw-r--r--src/base_tab/BaseGameTab.cpp1
-rw-r--r--src/base_tab/BaseImportTab.cpp25
-rw-r--r--src/base_tab/BaseImportTab.hpp5
-rw-r--r--src/base_tab/BaseManageTab.hpp4
-rw-r--r--src/base_tab/BaseTab.hpp2
5 files changed, 21 insertions, 16 deletions
diff --git a/src/base_tab/BaseGameTab.cpp b/src/base_tab/BaseGameTab.cpp
index 157358e..fc617a5 100644
--- a/src/base_tab/BaseGameTab.cpp
+++ b/src/base_tab/BaseGameTab.cpp
@@ -57,7 +57,6 @@ std::shared_ptr<Game> BaseGameTab::OpenGame(long gameid, long item) {
return g;
}
}
-
return nullptr;
}
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(){
diff --git a/src/base_tab/BaseImportTab.hpp b/src/base_tab/BaseImportTab.hpp
index dacf868..9a2386d 100644
--- a/src/base_tab/BaseImportTab.hpp
+++ b/src/base_tab/BaseImportTab.hpp
@@ -9,10 +9,13 @@
class BaseImportTab : public TabBase_TabImport {
TabInfos *main_tab;
std::shared_ptr<GameListManager> glm;
+
+ // Import states data structures
std::vector<std::shared_ptr<Game>> games_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::shared_ptr<GameBase> base;
std::shared_ptr<GameBase> selected_base;
diff --git a/src/base_tab/BaseManageTab.hpp b/src/base_tab/BaseManageTab.hpp
index e6bfc71..863754c 100644
--- a/src/base_tab/BaseManageTab.hpp
+++ b/src/base_tab/BaseManageTab.hpp
@@ -8,9 +8,11 @@
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<GameBase> base;
+
+ /// Pointers for data access
BaseImportTab *import_tab;
BaseGameTab *games_tab;
diff --git a/src/base_tab/BaseTab.hpp b/src/base_tab/BaseTab.hpp
index 7782b43..e7e4208 100644
--- a/src/base_tab/BaseTab.hpp
+++ b/src/base_tab/BaseTab.hpp
@@ -19,7 +19,7 @@ class BaseTab : public TabBase, public TabInfos {
/// @brief The last opened game
std::shared_ptr<Game> game;
- /// All sub tabs
+ /// All sub tabs from this main table
BaseGameTab *games_tab;
BaseImportTab *import_tab;
BaseManageTab *manage_tab;