From eebc615c1c900d2e9f03b21f3127497b551b437c Mon Sep 17 00:00:00 2001 From: Daenyth Date: Sat, 3 Dec 2011 22:54:57 -0500 Subject: [PATCH 1/4] Change "Show full" "Show running" checkboxes to a single box IMO these should not have been split --- cockatrice/src/gameselector.cpp | 21 ++++++--------------- cockatrice/src/gameselector.h | 7 +++---- cockatrice/src/gamesmodel.cpp | 22 +++++++++------------- cockatrice/src/gamesmodel.h | 6 ++---- 4 files changed, 20 insertions(+), 36 deletions(-) diff --git a/cockatrice/src/gameselector.cpp b/cockatrice/src/gameselector.cpp index 63ede6ec..db6402c5 100644 --- a/cockatrice/src/gameselector.cpp +++ b/cockatrice/src/gameselector.cpp @@ -29,12 +29,10 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso gameListView->header()->hideSection(1); gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents); - showFullGamesCheckBox = new QCheckBox; - showRunningGamesCheckBox = new QCheckBox; + showUnjoinableGamesCheckBox = new QCheckBox; QVBoxLayout *filterLayout = new QVBoxLayout; - filterLayout->addWidget(showFullGamesCheckBox); - filterLayout->addWidget(showRunningGamesCheckBox); + filterLayout->addWidget(showUnjoinableGamesCheckBox); if (room) createButton = new QPushButton; @@ -65,21 +63,15 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso setMinimumWidth((qreal) (gameListView->columnWidth(0) * gameListModel->columnCount()) / 1.5); setMinimumHeight(200); - connect(showFullGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showFullGamesChanged(int))); - connect(showRunningGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showRunningGamesChanged(int))); + connect(showUnjoinableGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showUnjoinableGamesChanged(int))); connect(createButton, SIGNAL(clicked()), this, SLOT(actCreate())); connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin())); connect(spectateButton, SIGNAL(clicked()), this, SLOT(actJoin())); } -void GameSelector::showFullGamesChanged(int state) +void GameSelector::showUnjoinableGamesChanged(int state) { - gameListProxyModel->setFullGamesVisible(state); -} - -void GameSelector::showRunningGamesChanged(int state) -{ - gameListProxyModel->setRunningGamesVisible(state); + gameListProxyModel->setUnjoinableGamesVisible(state); } void GameSelector::actCreate() @@ -138,8 +130,7 @@ void GameSelector::actJoin() void GameSelector::retranslateUi() { setTitle(tr("Games")); - showFullGamesCheckBox->setText(tr("Show &full games")); - showRunningGamesCheckBox->setText(tr("Show &running games")); + showUnjoinableGamesCheckBox->setText(tr("Show u&njoinable games")); if (createButton) createButton->setText(tr("C&reate")); joinButton->setText(tr("&Join")); diff --git a/cockatrice/src/gameselector.h b/cockatrice/src/gameselector.h index 16fc2d7d..38acda2d 100644 --- a/cockatrice/src/gameselector.h +++ b/cockatrice/src/gameselector.h @@ -18,8 +18,7 @@ class TabRoom; class GameSelector : public QGroupBox { Q_OBJECT private slots: - void showFullGamesChanged(int state); - void showRunningGamesChanged(int state); + void showUnjoinableGamesChanged(int state); void actCreate(); void actJoin(); void checkResponse(ResponseCode response); @@ -34,11 +33,11 @@ private: GamesModel *gameListModel; GamesProxyModel *gameListProxyModel; QPushButton *createButton, *joinButton, *spectateButton; - QCheckBox *showFullGamesCheckBox, *showRunningGamesCheckBox; + QCheckBox *showUnjoinableGamesCheckBox; public: GameSelector(AbstractClient *_client, TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap &_rooms, const QMap &_gameTypes, QWidget *parent = 0); void retranslateUi(); void processGameInfo(ServerInfo_Game *info); }; -#endif \ No newline at end of file +#endif diff --git a/cockatrice/src/gamesmodel.cpp b/cockatrice/src/gamesmodel.cpp index 031c4207..46a93d73 100644 --- a/cockatrice/src/gamesmodel.cpp +++ b/cockatrice/src/gamesmodel.cpp @@ -107,20 +107,14 @@ void GamesModel::updateGameList(ServerInfo_Game *_game) } GamesProxyModel::GamesProxyModel(QObject *parent) - : QSortFilterProxyModel(parent), fullGamesVisible(false) + : QSortFilterProxyModel(parent), unjoinableGamesVisible(false) { setDynamicSortFilter(true); } -void GamesProxyModel::setFullGamesVisible(bool _fullGamesVisible) +void GamesProxyModel::setUnjoinableGamesVisible(bool _unjoinableGamesVisible) { - fullGamesVisible = _fullGamesVisible; - invalidateFilter(); -} - -void GamesProxyModel::setRunningGamesVisible(bool _runningGamesVisible) -{ - runningGamesVisible = _runningGamesVisible; + unjoinableGamesVisible = _unjoinableGamesVisible; invalidateFilter(); } @@ -131,10 +125,12 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc return false; ServerInfo_Game *game = model->getGame(sourceRow); - if ((game->getPlayerCount() == game->getMaxPlayers()) && !fullGamesVisible) - return false; - if (game->getStarted() && !runningGamesVisible) - return false; + if (!unjoinableGamesVisible) { + if (game->getPlayerCount() == game->getMaxPlayers()) + return false; + if (game->getStarted()) + return false; + } return true; } diff --git a/cockatrice/src/gamesmodel.h b/cockatrice/src/gamesmodel.h index 8461faf6..5a859abe 100644 --- a/cockatrice/src/gamesmodel.h +++ b/cockatrice/src/gamesmodel.h @@ -29,12 +29,10 @@ public: class GamesProxyModel : public QSortFilterProxyModel { Q_OBJECT private: - bool fullGamesVisible; - bool runningGamesVisible; + bool unjoinableGamesVisible; public: GamesProxyModel(QObject *parent = 0); - void setFullGamesVisible(bool _fullGamesVisible); - void setRunningGamesVisible(bool _runningGamesVisible); + void setUnjoinableGamesVisible(bool _unjoinableGamesVisible); protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; }; From edd429d874e14cb5e815fe355c0abaa27e7db1cb Mon Sep 17 00:00:00 2001 From: Daenyth Date: Sun, 4 Dec 2011 12:16:19 -0500 Subject: [PATCH 2/4] Filter registered-only games as unavailable when user isn't regged --- cockatrice/src/gameselector.cpp | 2 +- cockatrice/src/gamesmodel.cpp | 7 +++++-- cockatrice/src/gamesmodel.h | 4 +++- cockatrice/src/tab_room.cpp | 6 +++--- cockatrice/src/tab_room.h | 6 ++++-- cockatrice/src/tab_supervisor.cpp | 2 +- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cockatrice/src/gameselector.cpp b/cockatrice/src/gameselector.cpp index db6402c5..4ec06863 100644 --- a/cockatrice/src/gameselector.cpp +++ b/cockatrice/src/gameselector.cpp @@ -18,7 +18,7 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso { gameListView = new QTreeView; gameListModel = new GamesModel(_rooms, _gameTypes, this); - gameListProxyModel = new GamesProxyModel(this); + gameListProxyModel = new GamesProxyModel(this, room->getCurrentUser()); gameListProxyModel->setSourceModel(gameListModel); gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); gameListView->setModel(gameListProxyModel); diff --git a/cockatrice/src/gamesmodel.cpp b/cockatrice/src/gamesmodel.cpp index 46a93d73..5f5f05da 100644 --- a/cockatrice/src/gamesmodel.cpp +++ b/cockatrice/src/gamesmodel.cpp @@ -106,8 +106,8 @@ void GamesModel::updateGameList(ServerInfo_Game *_game) endInsertRows(); } -GamesProxyModel::GamesProxyModel(QObject *parent) - : QSortFilterProxyModel(parent), unjoinableGamesVisible(false) +GamesProxyModel::GamesProxyModel(QObject *parent, ServerInfo_User *_ownUser) + : QSortFilterProxyModel(parent), ownUser(_ownUser), unjoinableGamesVisible(false) { setDynamicSortFilter(true); } @@ -130,6 +130,9 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc return false; if (game->getStarted()) return false; + if (!(ownUser->getUserLevel() & ServerInfo_User::IsRegistered)) + if (game->getOnlyRegistered()) + return false; } return true; diff --git a/cockatrice/src/gamesmodel.h b/cockatrice/src/gamesmodel.h index 5a859abe..bafd15b4 100644 --- a/cockatrice/src/gamesmodel.h +++ b/cockatrice/src/gamesmodel.h @@ -5,6 +5,7 @@ #include #include #include "gametypemap.h" +#include "protocol_datastructures.h" class ServerInfo_Game; @@ -29,9 +30,10 @@ public: class GamesProxyModel : public QSortFilterProxyModel { Q_OBJECT private: + ServerInfo_User *ownUser; bool unjoinableGamesVisible; public: - GamesProxyModel(QObject *parent = 0); + GamesProxyModel(QObject *parent = 0, ServerInfo_User *_ownUser = 0); void setUnjoinableGamesVisible(bool _unjoinableGamesVisible); protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; diff --git a/cockatrice/src/tab_room.cpp b/cockatrice/src/tab_room.cpp index ed418824..49090cd6 100644 --- a/cockatrice/src/tab_room.cpp +++ b/cockatrice/src/tab_room.cpp @@ -17,8 +17,8 @@ #include "chatview.h" #include "gameselector.h" -TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info) - : Tab(_tabSupervisor), client(_client), roomId(info->getRoomId()), roomName(info->getName()), ownName(_ownName) +TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerInfo_User *_ownUser, ServerInfo_Room *info) + : Tab(_tabSupervisor), client(_client), roomId(info->getRoomId()), roomName(info->getName()), ownUser(_ownUser) { const QList gameTypeList = info->getGameTypeList(); for (int i = 0; i < gameTypeList.size(); ++i) @@ -30,7 +30,7 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q userList = new UserList(tabSupervisor, client, UserList::RoomList); connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool))); - chatView = new ChatView(ownName, true); + chatView = new ChatView(ownUser->getName(), true); connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString))); connect(chatView, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString))); sayLabel = new QLabel; diff --git a/cockatrice/src/tab_room.h b/cockatrice/src/tab_room.h index 37e6a3d1..a3b767ec 100644 --- a/cockatrice/src/tab_room.h +++ b/cockatrice/src/tab_room.h @@ -2,6 +2,7 @@ #define TAB_ROOM_H #include "tab.h" +#include "protocol_datastructures.h" #include #include @@ -28,7 +29,7 @@ private: AbstractClient *client; int roomId; QString roomName; - QString ownName; + ServerInfo_User *ownUser; QMap gameTypes; GameSelector *gameSelector; @@ -53,7 +54,7 @@ private slots: void processLeaveRoomEvent(Event_LeaveRoom *event); void processSayEvent(Event_RoomSay *event); public: - TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info); + TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerInfo_User *_ownUser, ServerInfo_Room *info); ~TabRoom(); void retranslateUi(); void closeRequest(); @@ -62,6 +63,7 @@ public: const QMap &getGameTypes() const { return gameTypes; } QString getChannelName() const { return roomName; } QString getTabText() const { return roomName; } + ServerInfo_User *getCurrentUser() { return ownUser; } }; #endif diff --git a/cockatrice/src/tab_supervisor.cpp b/cockatrice/src/tab_supervisor.cpp index 62bf331e..6f56d1ae 100644 --- a/cockatrice/src/tab_supervisor.cpp +++ b/cockatrice/src/tab_supervisor.cpp @@ -265,7 +265,7 @@ void TabSupervisor::gameLeft(TabGame *tab) void TabSupervisor::addRoomTab(ServerInfo_Room *info, bool setCurrent) { - TabRoom *tab = new TabRoom(this, client, userInfo->getName(), info); + TabRoom *tab = new TabRoom(this, client, userInfo, info); connect(tab, SIGNAL(roomClosing(TabRoom *)), this, SLOT(roomLeft(TabRoom *))); connect(tab, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool))); int tabIndex = myAddTab(tab); From 86ae8a47a8549aa9f772f95bdf211a74c83b34d5 Mon Sep 17 00:00:00 2001 From: Daenyth Date: Sun, 4 Dec 2011 12:25:51 -0500 Subject: [PATCH 3/4] Rename 'unjoinable' games to 'unavailable' --- cockatrice/src/gameselector.cpp | 12 ++++++------ cockatrice/src/gameselector.h | 4 ++-- cockatrice/src/gamesmodel.cpp | 8 ++++---- cockatrice/src/gamesmodel.h | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cockatrice/src/gameselector.cpp b/cockatrice/src/gameselector.cpp index 4ec06863..743d5263 100644 --- a/cockatrice/src/gameselector.cpp +++ b/cockatrice/src/gameselector.cpp @@ -29,10 +29,10 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso gameListView->header()->hideSection(1); gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents); - showUnjoinableGamesCheckBox = new QCheckBox; + showUnavailableGamesCheckBox = new QCheckBox; QVBoxLayout *filterLayout = new QVBoxLayout; - filterLayout->addWidget(showUnjoinableGamesCheckBox); + filterLayout->addWidget(showUnavailableGamesCheckBox); if (room) createButton = new QPushButton; @@ -63,15 +63,15 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso setMinimumWidth((qreal) (gameListView->columnWidth(0) * gameListModel->columnCount()) / 1.5); setMinimumHeight(200); - connect(showUnjoinableGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showUnjoinableGamesChanged(int))); + connect(showUnavailableGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showUnavailableGamesChanged(int))); connect(createButton, SIGNAL(clicked()), this, SLOT(actCreate())); connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin())); connect(spectateButton, SIGNAL(clicked()), this, SLOT(actJoin())); } -void GameSelector::showUnjoinableGamesChanged(int state) +void GameSelector::showUnavailableGamesChanged(int state) { - gameListProxyModel->setUnjoinableGamesVisible(state); + gameListProxyModel->setUnavailableGamesVisible(state); } void GameSelector::actCreate() @@ -130,7 +130,7 @@ void GameSelector::actJoin() void GameSelector::retranslateUi() { setTitle(tr("Games")); - showUnjoinableGamesCheckBox->setText(tr("Show u&njoinable games")); + showUnavailableGamesCheckBox->setText(tr("Show u&navailable games")); if (createButton) createButton->setText(tr("C&reate")); joinButton->setText(tr("&Join")); diff --git a/cockatrice/src/gameselector.h b/cockatrice/src/gameselector.h index 38acda2d..13ec71a5 100644 --- a/cockatrice/src/gameselector.h +++ b/cockatrice/src/gameselector.h @@ -18,7 +18,7 @@ class TabRoom; class GameSelector : public QGroupBox { Q_OBJECT private slots: - void showUnjoinableGamesChanged(int state); + void showUnavailableGamesChanged(int state); void actCreate(); void actJoin(); void checkResponse(ResponseCode response); @@ -33,7 +33,7 @@ private: GamesModel *gameListModel; GamesProxyModel *gameListProxyModel; QPushButton *createButton, *joinButton, *spectateButton; - QCheckBox *showUnjoinableGamesCheckBox; + QCheckBox *showUnavailableGamesCheckBox; public: GameSelector(AbstractClient *_client, TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap &_rooms, const QMap &_gameTypes, QWidget *parent = 0); void retranslateUi(); diff --git a/cockatrice/src/gamesmodel.cpp b/cockatrice/src/gamesmodel.cpp index 5f5f05da..5b9dd77e 100644 --- a/cockatrice/src/gamesmodel.cpp +++ b/cockatrice/src/gamesmodel.cpp @@ -107,14 +107,14 @@ void GamesModel::updateGameList(ServerInfo_Game *_game) } GamesProxyModel::GamesProxyModel(QObject *parent, ServerInfo_User *_ownUser) - : QSortFilterProxyModel(parent), ownUser(_ownUser), unjoinableGamesVisible(false) + : QSortFilterProxyModel(parent), ownUser(_ownUser), unavailableGamesVisible(false) { setDynamicSortFilter(true); } -void GamesProxyModel::setUnjoinableGamesVisible(bool _unjoinableGamesVisible) +void GamesProxyModel::setUnavailableGamesVisible(bool _unavailableGamesVisible) { - unjoinableGamesVisible = _unjoinableGamesVisible; + unavailableGamesVisible = _unavailableGamesVisible; invalidateFilter(); } @@ -125,7 +125,7 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc return false; ServerInfo_Game *game = model->getGame(sourceRow); - if (!unjoinableGamesVisible) { + if (!unavailableGamesVisible) { if (game->getPlayerCount() == game->getMaxPlayers()) return false; if (game->getStarted()) diff --git a/cockatrice/src/gamesmodel.h b/cockatrice/src/gamesmodel.h index bafd15b4..3832157c 100644 --- a/cockatrice/src/gamesmodel.h +++ b/cockatrice/src/gamesmodel.h @@ -31,10 +31,10 @@ class GamesProxyModel : public QSortFilterProxyModel { Q_OBJECT private: ServerInfo_User *ownUser; - bool unjoinableGamesVisible; + bool unavailableGamesVisible; public: GamesProxyModel(QObject *parent = 0, ServerInfo_User *_ownUser = 0); - void setUnjoinableGamesVisible(bool _unjoinableGamesVisible); + void setUnavailableGamesVisible(bool _unavailableGamesVisible); protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; }; From 6b7da3223a81816b4eccb184aa85b37a1e31e506 Mon Sep 17 00:00:00 2001 From: Daenyth Date: Wed, 7 Dec 2011 23:37:04 -0500 Subject: [PATCH 4/4] Fix NPE in GameSelector::GameSelector when called from UserList::gamesOfUserReceived --- cockatrice/src/gameselector.cpp | 2 +- cockatrice/src/tab_room.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/cockatrice/src/gameselector.cpp b/cockatrice/src/gameselector.cpp index 743d5263..927d2e62 100644 --- a/cockatrice/src/gameselector.cpp +++ b/cockatrice/src/gameselector.cpp @@ -18,7 +18,7 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso { gameListView = new QTreeView; gameListModel = new GamesModel(_rooms, _gameTypes, this); - gameListProxyModel = new GamesProxyModel(this, room->getCurrentUser()); + gameListProxyModel = new GamesProxyModel(this, tabSupervisor->getUserInfo()); gameListProxyModel->setSourceModel(gameListModel); gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); gameListView->setModel(gameListProxyModel); diff --git a/cockatrice/src/tab_room.h b/cockatrice/src/tab_room.h index a3b767ec..676bd8e0 100644 --- a/cockatrice/src/tab_room.h +++ b/cockatrice/src/tab_room.h @@ -63,7 +63,6 @@ public: const QMap &getGameTypes() const { return gameTypes; } QString getChannelName() const { return roomName; } QString getTabText() const { return roomName; } - ServerInfo_User *getCurrentUser() { return ownUser; } }; #endif