Add a bool to the gameselector constructor to choose whether or not we should
load settings from saved values or use defaults.
This commit is contained in:
parent
8be659ba47
commit
223b38c27b
4 changed files with 38 additions and 37 deletions
|
@ -17,7 +17,7 @@
|
||||||
#include "pb/serverinfo_game.pb.h"
|
#include "pb/serverinfo_game.pb.h"
|
||||||
#include "pb/response.pb.h"
|
#include "pb/response.pb.h"
|
||||||
|
|
||||||
GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent)
|
GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, const bool restoresettings, QWidget *parent)
|
||||||
: QGroupBox(parent), client(_client), tabSupervisor(_tabSupervisor), room(_room)
|
: QGroupBox(parent), client(_client), tabSupervisor(_tabSupervisor), room(_room)
|
||||||
{
|
{
|
||||||
gameListView = new QTreeView;
|
gameListView = new QTreeView;
|
||||||
|
@ -36,7 +36,8 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup
|
||||||
if (room)
|
if (room)
|
||||||
gameTypeMap = gameListModel->getGameTypes().value(room->getRoomId());
|
gameTypeMap = gameListModel->getGameTypes().value(room->getRoomId());
|
||||||
|
|
||||||
gameListProxyModel->loadFilterParameters(gameTypeMap);
|
if (restoresettings)
|
||||||
|
gameListProxyModel->loadFilterParameters(gameTypeMap);
|
||||||
|
|
||||||
#if QT_VERSION < 0x050000
|
#if QT_VERSION < 0x050000
|
||||||
gameListView->header()->setResizeMode(0, QHeaderView::ResizeToContents);
|
gameListView->header()->setResizeMode(0, QHeaderView::ResizeToContents);
|
||||||
|
|
|
@ -36,7 +36,7 @@ private:
|
||||||
QPushButton *filterButton, *clearFilterButton, *createButton, *joinButton, *spectateButton;
|
QPushButton *filterButton, *clearFilterButton, *createButton, *joinButton, *spectateButton;
|
||||||
GameTypeMap gameTypeMap;
|
GameTypeMap gameTypeMap;
|
||||||
public:
|
public:
|
||||||
GameSelector(AbstractClient *_client, const TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent = 0);
|
GameSelector(AbstractClient *_client, const TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, const bool restoresettings, QWidget *parent = 0);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void processGameInfo(const ServerInfo_Game &info);
|
void processGameInfo(const ServerInfo_Game &info);
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,13 +34,13 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerI
|
||||||
const int gameTypeListSize = info.gametype_list_size();
|
const int gameTypeListSize = info.gametype_list_size();
|
||||||
for (int i = 0; i < gameTypeListSize; ++i)
|
for (int i = 0; i < gameTypeListSize; ++i)
|
||||||
gameTypes.insert(info.gametype_list(i).game_type_id(), QString::fromStdString(info.gametype_list(i).description()));
|
gameTypes.insert(info.gametype_list(i).game_type_id(), QString::fromStdString(info.gametype_list(i).description()));
|
||||||
|
|
||||||
QMap<int, GameTypeMap> tempMap;
|
QMap<int, GameTypeMap> tempMap;
|
||||||
tempMap.insert(info.room_id(), gameTypes);
|
tempMap.insert(info.room_id(), gameTypes);
|
||||||
gameSelector = new GameSelector(client, tabSupervisor, this, QMap<int, QString>(), tempMap);
|
gameSelector = new GameSelector(client, tabSupervisor, this, QMap<int, QString>(), tempMap, true);
|
||||||
userList = new UserList(tabSupervisor, client, UserList::RoomList);
|
userList = new UserList(tabSupervisor, client, UserList::RoomList);
|
||||||
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
|
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
|
||||||
|
|
||||||
chatView = new ChatView(tabSupervisor, 0, true);
|
chatView = new ChatView(tabSupervisor, 0, true);
|
||||||
connect(chatView, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
|
connect(chatView, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
|
||||||
connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
|
connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
|
||||||
|
@ -50,7 +50,7 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerI
|
||||||
sayEdit = new QLineEdit;
|
sayEdit = new QLineEdit;
|
||||||
sayLabel->setBuddy(sayEdit);
|
sayLabel->setBuddy(sayEdit);
|
||||||
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(sendMessage()));
|
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(sendMessage()));
|
||||||
|
|
||||||
QMenu *chatSettingsMenu = new QMenu(this);
|
QMenu *chatSettingsMenu = new QMenu(this);
|
||||||
|
|
||||||
aClearChat = chatSettingsMenu->addAction(QString());
|
aClearChat = chatSettingsMenu->addAction(QString());
|
||||||
|
@ -60,32 +60,32 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerI
|
||||||
|
|
||||||
aOpenChatSettings = chatSettingsMenu->addAction(QString());
|
aOpenChatSettings = chatSettingsMenu->addAction(QString());
|
||||||
connect(aOpenChatSettings, SIGNAL(triggered()), this, SLOT(actOpenChatSettings()));
|
connect(aOpenChatSettings, SIGNAL(triggered()), this, SLOT(actOpenChatSettings()));
|
||||||
|
|
||||||
QToolButton *chatSettingsButton = new QToolButton;
|
QToolButton *chatSettingsButton = new QToolButton;
|
||||||
chatSettingsButton->setIcon(QIcon(":/resources/icon_settings.svg"));
|
chatSettingsButton->setIcon(QIcon(":/resources/icon_settings.svg"));
|
||||||
chatSettingsButton->setMenu(chatSettingsMenu);
|
chatSettingsButton->setMenu(chatSettingsMenu);
|
||||||
chatSettingsButton->setPopupMode(QToolButton::InstantPopup);
|
chatSettingsButton->setPopupMode(QToolButton::InstantPopup);
|
||||||
|
|
||||||
QHBoxLayout *sayHbox = new QHBoxLayout;
|
QHBoxLayout *sayHbox = new QHBoxLayout;
|
||||||
sayHbox->addWidget(sayLabel);
|
sayHbox->addWidget(sayLabel);
|
||||||
sayHbox->addWidget(sayEdit);
|
sayHbox->addWidget(sayEdit);
|
||||||
sayHbox->addWidget(chatSettingsButton);
|
sayHbox->addWidget(chatSettingsButton);
|
||||||
|
|
||||||
QVBoxLayout *chatVbox = new QVBoxLayout;
|
QVBoxLayout *chatVbox = new QVBoxLayout;
|
||||||
chatVbox->addWidget(chatView);
|
chatVbox->addWidget(chatView);
|
||||||
chatVbox->addLayout(sayHbox);
|
chatVbox->addLayout(sayHbox);
|
||||||
|
|
||||||
chatGroupBox = new QGroupBox;
|
chatGroupBox = new QGroupBox;
|
||||||
chatGroupBox->setLayout(chatVbox);
|
chatGroupBox->setLayout(chatVbox);
|
||||||
|
|
||||||
QSplitter *splitter = new QSplitter(Qt::Vertical);
|
QSplitter *splitter = new QSplitter(Qt::Vertical);
|
||||||
splitter->addWidget(gameSelector);
|
splitter->addWidget(gameSelector);
|
||||||
splitter->addWidget(chatGroupBox);
|
splitter->addWidget(chatGroupBox);
|
||||||
|
|
||||||
QHBoxLayout *hbox = new QHBoxLayout;
|
QHBoxLayout *hbox = new QHBoxLayout;
|
||||||
hbox->addWidget(splitter, 3);
|
hbox->addWidget(splitter, 3);
|
||||||
hbox->addWidget(userList, 1);
|
hbox->addWidget(userList, 1);
|
||||||
|
|
||||||
aLeaveRoom = new QAction(this);
|
aLeaveRoom = new QAction(this);
|
||||||
connect(aLeaveRoom, SIGNAL(triggered()), this, SLOT(actLeaveRoom()));
|
connect(aLeaveRoom, SIGNAL(triggered()), this, SLOT(actLeaveRoom()));
|
||||||
|
|
||||||
|
@ -95,12 +95,12 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerI
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
setLayout(hbox);
|
setLayout(hbox);
|
||||||
|
|
||||||
const int userListSize = info.user_list_size();
|
const int userListSize = info.user_list_size();
|
||||||
for (int i = 0; i < userListSize; ++i)
|
for (int i = 0; i < userListSize; ++i)
|
||||||
userList->processUserInfo(info.user_list(i), true);
|
userList->processUserInfo(info.user_list(i), true);
|
||||||
userList->sortItems();
|
userList->sortItems();
|
||||||
|
|
||||||
const int gameListSize = info.game_list_size();
|
const int gameListSize = info.game_list_size();
|
||||||
for (int i = 0; i < gameListSize; ++i)
|
for (int i = 0; i < gameListSize; ++i)
|
||||||
gameSelector->processGameInfo(info.game_list(i));
|
gameSelector->processGameInfo(info.game_list(i));
|
||||||
|
@ -147,10 +147,10 @@ void TabRoom::sendMessage()
|
||||||
{
|
{
|
||||||
if (sayEdit->text().isEmpty())
|
if (sayEdit->text().isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Command_RoomSay cmd;
|
Command_RoomSay cmd;
|
||||||
cmd.set_message(sayEdit->text().toStdString());
|
cmd.set_message(sayEdit->text().toStdString());
|
||||||
|
|
||||||
PendingCommand *pend = prepareRoomCommand(cmd);
|
PendingCommand *pend = prepareRoomCommand(cmd);
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(sayFinished(const Response &)));
|
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(sayFinished(const Response &)));
|
||||||
sendRoomCommand(pend);
|
sendRoomCommand(pend);
|
||||||
|
|
|
@ -31,7 +31,7 @@ UserContextMenu::UserContextMenu(const TabSupervisor *_tabSupervisor, QWidget *p
|
||||||
aRemoveFromIgnoreList = new QAction(QString(), this);
|
aRemoveFromIgnoreList = new QAction(QString(), this);
|
||||||
aKick = new QAction(QString(), this);
|
aKick = new QAction(QString(), this);
|
||||||
aBan = new QAction(QString(), this);
|
aBan = new QAction(QString(), this);
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ void UserContextMenu::gamesOfUserReceived(const Response &resp, const CommandCon
|
||||||
{
|
{
|
||||||
const Response_GetGamesOfUser &response = resp.GetExtension(Response_GetGamesOfUser::ext);
|
const Response_GetGamesOfUser &response = resp.GetExtension(Response_GetGamesOfUser::ext);
|
||||||
const Command_GetGamesOfUser &cmd = commandContainer.session_command(0).GetExtension(Command_GetGamesOfUser::ext);
|
const Command_GetGamesOfUser &cmd = commandContainer.session_command(0).GetExtension(Command_GetGamesOfUser::ext);
|
||||||
|
|
||||||
QMap<int, GameTypeMap> gameTypeMap;
|
QMap<int, GameTypeMap> gameTypeMap;
|
||||||
QMap<int, QString> roomMap;
|
QMap<int, QString> roomMap;
|
||||||
const int roomListSize = response.room_list_size();
|
const int roomListSize = response.room_list_size();
|
||||||
|
@ -67,12 +67,12 @@ void UserContextMenu::gamesOfUserReceived(const Response &resp, const CommandCon
|
||||||
}
|
}
|
||||||
gameTypeMap.insert(roomInfo.room_id(), tempMap);
|
gameTypeMap.insert(roomInfo.room_id(), tempMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameSelector *selector = new GameSelector(client, tabSupervisor, 0, roomMap, gameTypeMap);
|
GameSelector *selector = new GameSelector(client, tabSupervisor, 0, roomMap, gameTypeMap, false);
|
||||||
const int gameListSize = response.game_list_size();
|
const int gameListSize = response.game_list_size();
|
||||||
for (int i = 0; i < gameListSize; ++i)
|
for (int i = 0; i < gameListSize; ++i)
|
||||||
selector->processGameInfo(response.game_list(i));
|
selector->processGameInfo(response.game_list(i));
|
||||||
|
|
||||||
selector->setWindowTitle(tr("%1's games").arg(QString::fromStdString(cmd.user_name())));
|
selector->setWindowTitle(tr("%1's games").arg(QString::fromStdString(cmd.user_name())));
|
||||||
selector->setAttribute(Qt::WA_DeleteOnClose);
|
selector->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
selector->show();
|
selector->show();
|
||||||
|
@ -81,7 +81,7 @@ void UserContextMenu::gamesOfUserReceived(const Response &resp, const CommandCon
|
||||||
void UserContextMenu::banUser_processUserInfoResponse(const Response &r)
|
void UserContextMenu::banUser_processUserInfoResponse(const Response &r)
|
||||||
{
|
{
|
||||||
const Response_GetUserInfo &response = r.GetExtension(Response_GetUserInfo::ext);
|
const Response_GetUserInfo &response = r.GetExtension(Response_GetUserInfo::ext);
|
||||||
|
|
||||||
// The dialog needs to be non-modal in order to not block the event queue of the client.
|
// The dialog needs to be non-modal in order to not block the event queue of the client.
|
||||||
BanDialog *dlg = new BanDialog(response.user_info(), static_cast<QWidget *>(parent()));
|
BanDialog *dlg = new BanDialog(response.user_info(), static_cast<QWidget *>(parent()));
|
||||||
connect(dlg, SIGNAL(accepted()), this, SLOT(banUser_dialogFinished()));
|
connect(dlg, SIGNAL(accepted()), this, SLOT(banUser_dialogFinished()));
|
||||||
|
@ -91,21 +91,21 @@ void UserContextMenu::banUser_processUserInfoResponse(const Response &r)
|
||||||
void UserContextMenu::banUser_dialogFinished()
|
void UserContextMenu::banUser_dialogFinished()
|
||||||
{
|
{
|
||||||
BanDialog *dlg = static_cast<BanDialog *>(sender());
|
BanDialog *dlg = static_cast<BanDialog *>(sender());
|
||||||
|
|
||||||
Command_BanFromServer cmd;
|
Command_BanFromServer cmd;
|
||||||
cmd.set_user_name(dlg->getBanName().toStdString());
|
cmd.set_user_name(dlg->getBanName().toStdString());
|
||||||
cmd.set_address(dlg->getBanIP().toStdString());
|
cmd.set_address(dlg->getBanIP().toStdString());
|
||||||
cmd.set_minutes(dlg->getMinutes());
|
cmd.set_minutes(dlg->getMinutes());
|
||||||
cmd.set_reason(dlg->getReason().toStdString());
|
cmd.set_reason(dlg->getReason().toStdString());
|
||||||
cmd.set_visible_reason(dlg->getVisibleReason().toStdString());
|
cmd.set_visible_reason(dlg->getVisibleReason().toStdString());
|
||||||
|
|
||||||
client->sendCommand(client->prepareModeratorCommand(cmd));
|
client->sendCommand(client->prepareModeratorCommand(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName, UserLevelFlags userLevel, bool online, int playerId)
|
void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName, UserLevelFlags userLevel, bool online, int playerId)
|
||||||
{
|
{
|
||||||
aUserName->setText(userName);
|
aUserName->setText(userName);
|
||||||
|
|
||||||
QMenu *menu = new QMenu(static_cast<QWidget *>(parent()));
|
QMenu *menu = new QMenu(static_cast<QWidget *>(parent()));
|
||||||
menu->addAction(aUserName);
|
menu->addAction(aUserName);
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
@ -141,7 +141,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
|
||||||
aRemoveFromIgnoreList->setEnabled(anotherUser);
|
aRemoveFromIgnoreList->setEnabled(anotherUser);
|
||||||
aKick->setEnabled(anotherUser);
|
aKick->setEnabled(anotherUser);
|
||||||
aBan->setEnabled(anotherUser);
|
aBan->setEnabled(anotherUser);
|
||||||
|
|
||||||
QAction *actionClicked = menu->exec(pos);
|
QAction *actionClicked = menu->exec(pos);
|
||||||
if (actionClicked == aDetails) {
|
if (actionClicked == aDetails) {
|
||||||
UserInfoBox *infoWidget = new UserInfoBox(client, true, static_cast<QWidget *>(parent()), Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
|
UserInfoBox *infoWidget = new UserInfoBox(client, true, static_cast<QWidget *>(parent()), Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
|
||||||
|
@ -152,34 +152,34 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
|
||||||
else if (actionClicked == aShowGames) {
|
else if (actionClicked == aShowGames) {
|
||||||
Command_GetGamesOfUser cmd;
|
Command_GetGamesOfUser cmd;
|
||||||
cmd.set_user_name(userName.toStdString());
|
cmd.set_user_name(userName.toStdString());
|
||||||
|
|
||||||
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(gamesOfUserReceived(Response, CommandContainer)));
|
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(gamesOfUserReceived(Response, CommandContainer)));
|
||||||
|
|
||||||
client->sendCommand(pend);
|
client->sendCommand(pend);
|
||||||
} else if (actionClicked == aAddToBuddyList) {
|
} else if (actionClicked == aAddToBuddyList) {
|
||||||
Command_AddToList cmd;
|
Command_AddToList cmd;
|
||||||
cmd.set_list("buddy");
|
cmd.set_list("buddy");
|
||||||
cmd.set_user_name(userName.toStdString());
|
cmd.set_user_name(userName.toStdString());
|
||||||
|
|
||||||
client->sendCommand(client->prepareSessionCommand(cmd));
|
client->sendCommand(client->prepareSessionCommand(cmd));
|
||||||
} else if (actionClicked == aRemoveFromBuddyList) {
|
} else if (actionClicked == aRemoveFromBuddyList) {
|
||||||
Command_RemoveFromList cmd;
|
Command_RemoveFromList cmd;
|
||||||
cmd.set_list("buddy");
|
cmd.set_list("buddy");
|
||||||
cmd.set_user_name(userName.toStdString());
|
cmd.set_user_name(userName.toStdString());
|
||||||
|
|
||||||
client->sendCommand(client->prepareSessionCommand(cmd));
|
client->sendCommand(client->prepareSessionCommand(cmd));
|
||||||
} else if (actionClicked == aAddToIgnoreList) {
|
} else if (actionClicked == aAddToIgnoreList) {
|
||||||
Command_AddToList cmd;
|
Command_AddToList cmd;
|
||||||
cmd.set_list("ignore");
|
cmd.set_list("ignore");
|
||||||
cmd.set_user_name(userName.toStdString());
|
cmd.set_user_name(userName.toStdString());
|
||||||
|
|
||||||
client->sendCommand(client->prepareSessionCommand(cmd));
|
client->sendCommand(client->prepareSessionCommand(cmd));
|
||||||
} else if (actionClicked == aRemoveFromIgnoreList) {
|
} else if (actionClicked == aRemoveFromIgnoreList) {
|
||||||
Command_RemoveFromList cmd;
|
Command_RemoveFromList cmd;
|
||||||
cmd.set_list("ignore");
|
cmd.set_list("ignore");
|
||||||
cmd.set_user_name(userName.toStdString());
|
cmd.set_user_name(userName.toStdString());
|
||||||
|
|
||||||
client->sendCommand(client->prepareSessionCommand(cmd));
|
client->sendCommand(client->prepareSessionCommand(cmd));
|
||||||
} else if (actionClicked == aKick) {
|
} else if (actionClicked == aKick) {
|
||||||
Command_KickFromGame cmd;
|
Command_KickFromGame cmd;
|
||||||
|
@ -188,12 +188,12 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
|
||||||
} else if (actionClicked == aBan) {
|
} else if (actionClicked == aBan) {
|
||||||
Command_GetUserInfo cmd;
|
Command_GetUserInfo cmd;
|
||||||
cmd.set_user_name(userName.toStdString());
|
cmd.set_user_name(userName.toStdString());
|
||||||
|
|
||||||
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(banUser_processUserInfoResponse(Response)));
|
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(banUser_processUserInfoResponse(Response)));
|
||||||
|
|
||||||
client->sendCommand(pend);
|
client->sendCommand(pend);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete menu;
|
delete menu;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue