From 40ad54c5c7cb1d47e36f82db1a3bdd8616a1464f Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Sat, 20 Apr 2019 12:38:19 +0800 Subject: [PATCH] citra_qt: Update the multiplayer dialogs when game list is repopulated The multiplayer state object and dialogs hold a (modified) game list model, but it isn't updated when the actual game list changes. This updates the multiplayer dialogs with the new game list when it got repopulated. --- src/citra_qt/game_list.cpp | 2 ++ src/citra_qt/game_list.h | 1 + src/citra_qt/main.cpp | 2 ++ src/citra_qt/multiplayer/host_room.cpp | 18 +++++++++++------- src/citra_qt/multiplayer/host_room.h | 5 +++++ src/citra_qt/multiplayer/lobby.cpp | 24 +++++++++++++++++------- src/citra_qt/multiplayer/lobby.h | 18 +++++++++++++++--- src/citra_qt/multiplayer/state.cpp | 10 ++++++++++ src/citra_qt/multiplayer/state.h | 6 ++++++ 9 files changed, 69 insertions(+), 17 deletions(-) diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp index 4ab491f04e..dad0a3cdb2 100644 --- a/src/citra_qt/game_list.cpp +++ b/src/citra_qt/game_list.cpp @@ -421,6 +421,8 @@ void GameList::DonePopulating(QStringList watch_list) { if (childrenTotal > 0) { search_field->setFocus(); } + + emit PopulatingCompleted(); } void GameList::PopupContextMenu(const QPoint& menu_location) { diff --git a/src/citra_qt/game_list.h b/src/citra_qt/game_list.h index a10d7fe15e..ccf695fa5d 100644 --- a/src/citra_qt/game_list.h +++ b/src/citra_qt/game_list.h @@ -76,6 +76,7 @@ signals: void OpenDirectory(QString directory); void AddDirectory(); void ShowList(bool show); + void PopulatingCompleted(); private slots: void onItemExpanded(const QModelIndex& item); diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 3c2a9f5f52..055627d475 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -506,6 +506,8 @@ void GMainWindow::ConnectWidgetEvents() { connect(game_list_placeholder, &GameListPlaceholder::AddDirectory, this, &GMainWindow::OnGameListAddDirectory); connect(game_list, &GameList::ShowList, this, &GMainWindow::OnGameListShowList); + connect(game_list, &GameList::PopulatingCompleted, + [this] { multiplayer_state->UpdateGameList(game_list->GetModel()); }); connect(this, &GMainWindow::EmulationStarting, render_window, &GRenderWindow::OnEmulationStarting); diff --git a/src/citra_qt/multiplayer/host_room.cpp b/src/citra_qt/multiplayer/host_room.cpp index 8abe84f92e..05e696a93c 100644 --- a/src/citra_qt/multiplayer/host_room.cpp +++ b/src/citra_qt/multiplayer/host_room.cpp @@ -41,13 +41,7 @@ HostRoomWindow::HostRoomWindow(QWidget* parent, QStandardItemModel* list, // Create a proxy to the game list to display the list of preferred games game_list = new QStandardItemModel; - - for (int i = 0; i < list->rowCount(); i++) { - auto parent = list->item(i, 0); - for (int j = 0; j < parent->rowCount(); j++) { - game_list->appendRow(parent->child(j)->clone()); - } - } + UpdateGameList(list); proxy = new ComboBoxProxyModel; proxy->setSourceModel(game_list); @@ -79,6 +73,16 @@ HostRoomWindow::HostRoomWindow(QWidget* parent, QStandardItemModel* list, HostRoomWindow::~HostRoomWindow() = default; +void HostRoomWindow::UpdateGameList(QStandardItemModel* list) { + game_list->clear(); + for (int i = 0; i < list->rowCount(); i++) { + auto parent = list->item(i, 0); + for (int j = 0; j < parent->rowCount(); j++) { + game_list->appendRow(parent->child(j)->clone()); + } + } +} + void HostRoomWindow::RetranslateUi() { ui->retranslateUi(this); } diff --git a/src/citra_qt/multiplayer/host_room.h b/src/citra_qt/multiplayer/host_room.h index 620574bd61..247028383b 100644 --- a/src/citra_qt/multiplayer/host_room.h +++ b/src/citra_qt/multiplayer/host_room.h @@ -38,6 +38,11 @@ public: std::shared_ptr session); ~HostRoomWindow(); + /** + * Updates the dialog with a new game list model. + * This model should be the original model of the game list. + */ + void UpdateGameList(QStandardItemModel* list); void RetranslateUi(); private: diff --git a/src/citra_qt/multiplayer/lobby.cpp b/src/citra_qt/multiplayer/lobby.cpp index 3b48b3a955..c067385656 100644 --- a/src/citra_qt/multiplayer/lobby.cpp +++ b/src/citra_qt/multiplayer/lobby.cpp @@ -35,13 +35,7 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list, // Create a proxy to the game list to get the list of games owned game_list = new QStandardItemModel; - - for (int i = 0; i < list->rowCount(); i++) { - auto parent = list->item(i, 0); - for (int j = 0; j < parent->rowCount(); j++) { - game_list->appendRow(parent->child(j)->clone()); - } - } + UpdateGameList(list); proxy = new LobbyFilterProxyModel(this, game_list); proxy->setSourceModel(model); @@ -88,6 +82,18 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list, RefreshLobby(); } +void Lobby::UpdateGameList(QStandardItemModel* list) { + game_list->clear(); + for (int i = 0; i < list->rowCount(); i++) { + auto parent = list->item(i, 0); + for (int j = 0; j < parent->rowCount(); j++) { + game_list->appendRow(parent->child(j)->clone()); + } + } + if (proxy) + proxy->UpdateGameList(game_list); +} + void Lobby::RetranslateUi() { ui->retranslateUi(this); } @@ -260,6 +266,10 @@ void Lobby::OnRefreshLobby() { LobbyFilterProxyModel::LobbyFilterProxyModel(QWidget* parent, QStandardItemModel* list) : QSortFilterProxyModel(parent), game_list(list) {} +void LobbyFilterProxyModel::UpdateGameList(QStandardItemModel* list) { + game_list = list; +} + bool LobbyFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { // Prioritize filters by fastest to compute diff --git a/src/citra_qt/multiplayer/lobby.h b/src/citra_qt/multiplayer/lobby.h index 9d77b73b6a..0b1d85b53a 100644 --- a/src/citra_qt/multiplayer/lobby.h +++ b/src/citra_qt/multiplayer/lobby.h @@ -30,6 +30,11 @@ public: std::shared_ptr session); ~Lobby() = default; + /** + * Updates the lobby with a new game list model. + * This model should be the original model of the game list. + */ + void UpdateGameList(QStandardItemModel* list); void RetranslateUi(); public slots: @@ -76,9 +81,9 @@ private: */ QString PasswordPrompt(); - QStandardItemModel* model; - QStandardItemModel* game_list; - LobbyFilterProxyModel* proxy; + QStandardItemModel* model{}; + QStandardItemModel* game_list{}; + LobbyFilterProxyModel* proxy{}; QFutureWatcher room_list_watcher; std::weak_ptr announce_multiplayer_session; @@ -95,6 +100,13 @@ class LobbyFilterProxyModel : public QSortFilterProxyModel { public: explicit LobbyFilterProxyModel(QWidget* parent, QStandardItemModel* list); + + /** + * Updates the filter with a new game list model. + * This model should be the processed one created by the Lobby. + */ + void UpdateGameList(QStandardItemModel* list); + bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override; void sort(int column, Qt::SortOrder order) override; diff --git a/src/citra_qt/multiplayer/state.cpp b/src/citra_qt/multiplayer/state.cpp index c122a5c83c..4daafd3a0c 100644 --- a/src/citra_qt/multiplayer/state.cpp +++ b/src/citra_qt/multiplayer/state.cpp @@ -286,3 +286,13 @@ bool MultiplayerState::IsHostingPublicRoom() const { void MultiplayerState::UpdateCredentials() { announce_multiplayer_session->UpdateCredentials(); } + +void MultiplayerState::UpdateGameList(QStandardItemModel* game_list) { + game_list_model = game_list; + if (lobby) { + lobby->UpdateGameList(game_list); + } + if (host_room) { + host_room->UpdateGameList(game_list); + } +} diff --git a/src/citra_qt/multiplayer/state.h b/src/citra_qt/multiplayer/state.h index 78a5530dd8..707efd5a44 100644 --- a/src/citra_qt/multiplayer/state.h +++ b/src/citra_qt/multiplayer/state.h @@ -46,6 +46,12 @@ public: void UpdateCredentials(); + /** + * Updates the multiplayer dialogs with a new game list model. + * This model should be the original model of the game list. + */ + void UpdateGameList(QStandardItemModel* game_list); + public slots: void OnNetworkStateChanged(const Network::RoomMember::State& state); void OnNetworkError(const Network::RoomMember::Error& error);