diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp index 4ab491f04..dad0a3cdb 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 a10d7fe15..ccf695fa5 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 3c2a9f5f5..055627d47 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 8abe84f92..05e696a93 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 620574bd6..247028383 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 3b48b3a95..c06738565 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 9d77b73b6..0b1d85b53 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 c122a5c83..4daafd3a0 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 78a5530dd..707efd5a4 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);