fix segfault that happens when account tab is closed (#5474)

This commit is contained in:
RickyRister 2025-01-14 22:10:03 -08:00 committed by GitHub
parent d09b9eb533
commit 23bd18a04c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 332 additions and 121 deletions

View file

@ -9,6 +9,7 @@
#include "../dialogs/dlg_create_game.h"
#include "../dialogs/dlg_filter_games.h"
#include "../server/pending_command.h"
#include "../server/user/user_list_manager.h"
#include "games_model.h"
#include "pb/response.pb.h"
#include "pb/room_commands.pb.h"
@ -39,7 +40,7 @@ GameSelector::GameSelector(AbstractClient *_client,
gameListView = new QTreeView;
gameListModel = new GamesModel(_rooms, _gameTypes, this);
if (showFilters) {
gameListProxyModel = new GamesProxyModel(this, tabSupervisor);
gameListProxyModel = new GamesProxyModel(this, tabSupervisor->getUserListManager());
gameListProxyModel->setSourceModel(gameListModel);
gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
gameListView->setModel(gameListProxyModel);

View file

@ -2,6 +2,7 @@
#include "../client/tabs/tab_account.h"
#include "../client/ui/pixel_map_generator.h"
#include "../server/user/user_list_manager.h"
#include "../server/user/user_list_widget.h"
#include "../settings/cache_settings.h"
#include "pb/serverinfo_game.pb.h"
@ -284,9 +285,8 @@ void GamesModel::updateGameList(const ServerInfo_Game &game)
endInsertRows();
}
GamesProxyModel::GamesProxyModel(QObject *parent, const TabSupervisor *_tabSupervisor)
: QSortFilterProxyModel(parent), ownUserIsRegistered(_tabSupervisor->isOwnUserRegistered()),
tabSupervisor(_tabSupervisor)
GamesProxyModel::GamesProxyModel(QObject *parent, const UserlistProxy *_userListProxy)
: QSortFilterProxyModel(parent), userListProxy(_userListProxy)
{
resetFilterParameters();
setSortRole(GamesModel::SORT_ROLE);
@ -508,15 +508,14 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow) const
if (!showBuddiesOnlyGames && game.only_buddies()) {
return false;
}
if (hideIgnoredUserGames && tabSupervisor->getTabAccount()->getIgnoreList()->getUsers().contains(
QString::fromStdString(game.creator_info().name()))) {
if (hideIgnoredUserGames && userListProxy->isUserIgnored(QString::fromStdString(game.creator_info().name()))) {
return false;
}
if (!showFullGames && game.player_count() == game.max_players())
return false;
if (!showGamesThatStarted && game.started())
return false;
if (!ownUserIsRegistered)
if (!userListProxy->isOwnUserRegistered())
if (game.only_registered())
return false;
if (!showPasswordProtectedGames && game.with_password())

View file

@ -1,7 +1,6 @@
#ifndef GAMESMODEL_H
#define GAMESMODEL_H
#include "../client/tabs/tab_supervisor.h"
#include "game_type_map.h"
#include "pb/serverinfo_game.pb.h"
@ -12,6 +11,8 @@
#include <QStringList>
#include <QTime>
class UserlistProxy;
class GamesModel : public QAbstractTableModel
{
Q_OBJECT
@ -65,8 +66,7 @@ class GamesProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
private:
bool ownUserIsRegistered;
const TabSupervisor *tabSupervisor;
const UserlistProxy *userListProxy;
// If adding any additional filters, make sure to update:
// - GamesProxyModel()
@ -88,7 +88,7 @@ private:
showOnlyIfSpectatorsCanSeeHands;
public:
GamesProxyModel(QObject *parent = nullptr, const TabSupervisor *_tabSupervisor = nullptr);
GamesProxyModel(QObject *parent = nullptr, const UserlistProxy *_userListProxy = nullptr);
bool getShowBuddiesOnlyGames() const
{

View file

@ -6,6 +6,7 @@
#include "../../client/tabs/tab_supervisor.h"
#include "../../client/ui/pixel_map_generator.h"
#include "../../server/user/user_context_menu.h"
#include "../../server/user/user_list_manager.h"
#include "../../server/user/user_list_widget.h"
#include "pb/command_kick_from_game.pb.h"
#include "pb/serverinfo_playerproperties.pb.h"
@ -71,7 +72,7 @@ PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor,
itemDelegate = new PlayerListItemDelegate(this);
setItemDelegate(itemDelegate);
userContextMenu = new UserContextMenu(tabSupervisor, this, game);
userContextMenu = new UserContextMenu(tabSupervisor, tabSupervisor->getUserListManager(), this, game);
connect(userContextMenu, &UserContextMenu::openMessageDialog, this, &PlayerListWidget::openMessageDialog);
} else {
userContextMenu = nullptr;