servatrice/cockatrice/src/gameselector.h
Basile Clement 00c9efe541
Enable buttons for current game when receiving server response (#4737)
* Enable buttons for current game when receiving server response

Previously, upon joining a game, we were unconditionally re-enabling the
"Join" button in the lobby, even if it was not enabled in the first
place, causing #4698. This could also lead to issues where if the user
selects a different game after joining (which they can do in case of
e.g. network connectivity issues), the "Join as spectator" button could
get incorrectly disabled.

This fixes #4698 by re-enabling the buttons based on the state of the
currently selected game at the time the response is received. This also
avoids inconsistencies if a different game has been selected in between
joining and receiving a response from the server.

* Typo: enable gameButton in enableButtons

The "create game" button was incorrectly being disabled in enableButtons
whereas (as the name indicates) it should have been enabled

* Remove misleading comment about race conditions
2023-02-06 13:49:45 +01:00

69 lines
1.9 KiB
C++

#ifndef GAMESELECTOR_H
#define GAMESELECTOR_H
#include "gametypemap.h"
#include <QGroupBox>
#include <common/pb/event_add_to_list.pb.h>
#include <common/pb/event_remove_from_list.pb.h>
class QTreeView;
class GamesModel;
class GamesProxyModel;
class QPushButton;
class QCheckBox;
class QLabel;
class AbstractClient;
class TabSupervisor;
class TabRoom;
class ServerInfo_Game;
class Response;
class GameSelector : public QGroupBox
{
Q_OBJECT
private slots:
void actSetFilter();
void actClearFilter();
void actCreate();
void actJoin();
void actSelectedGameChanged(const QModelIndex &current, const QModelIndex &previous);
void checkResponse(const Response &response);
void ignoreListReceived(const QList<ServerInfo_User> &_ignoreList);
void processAddToListEvent(const Event_AddToList &event);
void processRemoveFromListEvent(const Event_RemoveFromList &event);
signals:
void gameJoined(int gameId);
private:
AbstractClient *client;
TabSupervisor *tabSupervisor;
TabRoom *room;
QTreeView *gameListView;
GamesModel *gameListModel;
GamesProxyModel *gameListProxyModel;
QPushButton *filterButton, *clearFilterButton, *createButton, *joinButton, *spectateButton;
const bool showFilters;
GameTypeMap gameTypeMap;
void updateTitle();
void disableButtons();
void enableButtons();
void enableButtonsForIndex(const QModelIndex &current);
public:
GameSelector(AbstractClient *_client,
TabSupervisor *_tabSupervisor,
TabRoom *_room,
const QMap<int, QString> &_rooms,
const QMap<int, GameTypeMap> &_gameTypes,
const bool restoresettings,
const bool _showfilters,
QWidget *parent = nullptr);
void retranslateUi();
void processGameInfo(const ServerInfo_Game &info);
};
#endif