Commit d5c62896 authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

PB: everything compiles except for deck storage

parent 695fde75
......@@ -6,8 +6,8 @@
class AbstractClient;
class ChatView;
class QLineEdit;
class Event_Message;
class ProtocolResponse;
class Event_UserMessage;
class Response;
class TabMessage : public Tab {
Q_OBJECT
......@@ -25,7 +25,7 @@ signals:
private slots:
void sendMessage();
void actLeave();
void messageSent(ProtocolResponse *response);
void messageSent(const Response &response);
public:
TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, const QString &_userName);
~TabMessage();
......@@ -34,7 +34,7 @@ public:
QString getUserName() const { return userName; }
QString getTabText() const { return tr("Talking to %1").arg(userName); }
void processMessageEvent(Event_Message *event);
void processUserMessageEvent(const Event_UserMessage &event);
void processUserLeft();
void processUserJoined();
};
......
......@@ -15,21 +15,25 @@
#include "abstractclient.h"
#include "chatview.h"
#include "gameselector.h"
#include "protocol_items.h"
#include "pending_command.h"
#include <google/protobuf/descriptor.h>
#include "get_pb_extension.h"
#include "pb/room_commands.pb.h"
#include "pb/serverinfo_room.pb.h"
#include "pb/event_list_games.pb.h"
#include "pb/event_join_room.pb.h"
#include "pb/event_leave_room.pb.h"
#include "pb/event_room_say.pb.h"
#include "pending_command.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, const QString &_ownName, const ServerInfo_Room &info)
: Tab(_tabSupervisor), client(_client), roomId(info.room_id()), roomName(QString::fromStdString(info.name())), ownName(_ownName)
{
const QList<ServerInfo_GameType *> gameTypeList = info->getGameTypeList();
for (int i = 0; i < gameTypeList.size(); ++i)
gameTypes.insert(gameTypeList[i]->getGameTypeId(), gameTypeList[i]->getDescription());
const int gameTypeListSize = info.gametype_list_size();
for (int i = 0; i < gameTypeListSize; ++i)
gameTypes.insert(info.gametype_list(i).game_type_id(), QString::fromStdString(info.gametype_list(i).description()));
QMap<int, GameTypeMap> tempMap;
tempMap.insert(info->getRoomId(), gameTypes);
tempMap.insert(info.room_id(), gameTypes);
gameSelector = new GameSelector(client, tabSupervisor, this, QMap<int, QString>(), tempMap);
userList = new UserList(tabSupervisor, client, UserList::RoomList);
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
......@@ -70,14 +74,14 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
retranslateUi();
setLayout(hbox);
const QList<ServerInfo_User *> users = info->getUserList();
for (int i = 0; i < users.size(); ++i)
userList->processUserInfo(users[i], true);
const int userListSize = info.user_list_size();
for (int i = 0; i < userListSize; ++i)
userList->processUserInfo(info.user_list(i), true);
userList->sortItems();
const QList<ServerInfo_Game *> games = info->getGameList();
for (int i = 0; i < games.size(); ++i)
gameSelector->processGameInfo(games[i]);
const int gameListSize = info.game_list_size();
for (int i = 0; i < gameListSize; ++i)
gameSelector->processGameInfo(info.game_list(i));
}
TabRoom::~TabRoom()
......@@ -116,14 +120,14 @@ void TabRoom::sendMessage()
cmd.set_message(sayEdit->text().toStdString());
PendingCommand *pend = prepareRoomCommand(cmd);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(sayFinished(ProtocolResponse *)));
connect(pend, SIGNAL(finished(const Response &)), this, SLOT(sayFinished(const Response &)));
sendRoomCommand(pend);
sayEdit->clear();
}
void TabRoom::sayFinished(ProtocolResponse *response)
void TabRoom::sayFinished(const Response &response)
{
if (response->getResponseCode() == RespChatFlood)
if (response.response_code() == Response::RespChatFlood)
chatView->appendMessage(QString(), tr("You are flooding the chat. Please wait a couple of seconds."));
}
......@@ -133,39 +137,39 @@ void TabRoom::actLeaveRoom()
deleteLater();
}
void TabRoom::processRoomEvent(RoomEvent *event)
void TabRoom::processRoomEvent(const RoomEvent &event)
{
switch (event->getItemId()) {
case ItemId_Event_ListGames: processListGamesEvent(qobject_cast<Event_ListGames *>(event)); break;
case ItemId_Event_JoinRoom: processJoinRoomEvent(qobject_cast<Event_JoinRoom *>(event)); break;
case ItemId_Event_LeaveRoom: processLeaveRoomEvent(qobject_cast<Event_LeaveRoom *>(event)); break;
case ItemId_Event_RoomSay: processSayEvent(qobject_cast<Event_RoomSay *>(event)); break;
switch (static_cast<RoomEvent::RoomEventType>(getPbExtension(event))) {
case RoomEvent::LIST_GAMES: processListGamesEvent(event.GetExtension(Event_ListGames::ext)); break;
case RoomEvent::JOIN_ROOM: processJoinRoomEvent(event.GetExtension(Event_JoinRoom::ext)); break;
case RoomEvent::LEAVE_ROOM: processLeaveRoomEvent(event.GetExtension(Event_LeaveRoom::ext)); break;
case RoomEvent::ROOM_SAY: processRoomSayEvent(event.GetExtension(Event_RoomSay::ext)); break;
default: ;
}
}
void TabRoom::processListGamesEvent(Event_ListGames *event)
void TabRoom::processListGamesEvent(const Event_ListGames &event)
{
const QList<ServerInfo_Game *> &gameList = event->getGameList();
for (int i = 0; i < gameList.size(); ++i)
gameSelector->processGameInfo(gameList[i]);
const int gameListSize = event.game_list_size();
for (int i = 0; i < gameListSize; ++i)
gameSelector->processGameInfo(event.game_list(i));
}
void TabRoom::processJoinRoomEvent(Event_JoinRoom *event)
void TabRoom::processJoinRoomEvent(const Event_JoinRoom &event)
{
userList->processUserInfo(event->getUserInfo(), true);
userList->processUserInfo(event.user_info(), true);
userList->sortItems();
}
void TabRoom::processLeaveRoomEvent(Event_LeaveRoom *event)
void TabRoom::processLeaveRoomEvent(const Event_LeaveRoom &event)
{
userList->deleteUser(event->getPlayerName());
userList->deleteUser(QString::fromStdString(event.name()));
}
void TabRoom::processSayEvent(Event_RoomSay *event)
void TabRoom::processRoomSayEvent(const Event_RoomSay &event)
{
if (!tabSupervisor->getUserListsTab()->getIgnoreList()->userInList(event->getPlayerName()))
chatView->appendMessage(event->getPlayerName(), event->getMessage());
if (!tabSupervisor->getUserListsTab()->getIgnoreList()->userInList(QString::fromStdString(event.name())))
chatView->appendMessage(QString::fromStdString(event.name()), QString::fromStdString(event.message()));
emit userEvent(false);
}
......
......@@ -4,8 +4,8 @@
#include "tab.h"
#include <QGroupBox>
#include <QMap>
#include <google/protobuf/message.h>
namespace google { namespace protobuf { class Message; } }
class AbstractClient;
class UserList;
class QLabel;
......@@ -20,8 +20,8 @@ class Event_ListGames;
class Event_JoinRoom;
class Event_LeaveRoom;
class Event_RoomSay;
class ProtocolResponse;
class GameSelector;
class Response;
class PendingCommand;
class TabRoom : public Tab {
......@@ -48,18 +48,18 @@ signals:
private slots:
void sendMessage();
void actLeaveRoom();
void sayFinished(ProtocolResponse *response);
void sayFinished(const Response &response);
void processListGamesEvent(Event_ListGames *event);
void processJoinRoomEvent(Event_JoinRoom *event);
void processLeaveRoomEvent(Event_LeaveRoom *event);
void processSayEvent(Event_RoomSay *event);
void processListGamesEvent(const Event_ListGames &event);
void processJoinRoomEvent(const Event_JoinRoom &event);
void processLeaveRoomEvent(const Event_LeaveRoom &event);
void processRoomSayEvent(const Event_RoomSay &event);
public:
TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info);
TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, const ServerInfo_Room &info);
~TabRoom();
void retranslateUi();
void closeRequest();
void processRoomEvent(RoomEvent *event);
void processRoomEvent(const RoomEvent &event);
int getRoomId() const { return roomId; }
const QMap<int, QString> &getGameTypes() const { return gameTypes; }
QString getChannelName() const { return roomName; }
......
......@@ -12,13 +12,15 @@
#include "tab_server.h"
#include "abstractclient.h"
#include "protocol.h"
#include "protocol_items.h"
#include "userlist.h"
#include "userinfobox.h"
#include <QDebug>
#include "pending_command.h"
#include "pb/session_commands.pb.h"
#include "pb/event_list_rooms.pb.h"
#include "pb/event_server_message.pb.h"
#include "pb/response_join_room.pb.h"
RoomSelector::RoomSelector(AbstractClient *_client, QWidget *parent)
: QGroupBox(parent), client(_client)
......@@ -44,7 +46,7 @@ RoomSelector::RoomSelector(AbstractClient *_client, QWidget *parent)
retranslateUi();
setLayout(vbox);
connect(client, SIGNAL(listRoomsEventReceived(Event_ListRooms *)), this, SLOT(processListRoomsEvent(Event_ListRooms *)));
connect(client, SIGNAL(listRoomsEventReceived(const Event_ListRooms &)), this, SLOT(processListRoomsEvent(const Event_ListRooms &)));
client->sendCommand(client->prepareSessionCommand(Command_ListRooms()));
}
......@@ -62,33 +64,33 @@ void RoomSelector::retranslateUi()
header->setTextAlignment(3, Qt::AlignRight);
}
void RoomSelector::processListRoomsEvent(Event_ListRooms *event)
void RoomSelector::processListRoomsEvent(const Event_ListRooms &event)
{
const QList<ServerInfo_Room *> &roomsToUpdate = event->getRoomList();
for (int i = 0; i < roomsToUpdate.size(); ++i) {
ServerInfo_Room *room = roomsToUpdate[i];
const int roomListSize = event.room_list_size();
for (int i = 0; i < roomListSize; ++i) {
const ServerInfo_Room &room = event.room_list(i);
for (int j = 0; j < roomList->topLevelItemCount(); ++j) {
QTreeWidgetItem *twi = roomList->topLevelItem(j);
if (twi->data(0, Qt::UserRole).toInt() == room->getRoomId()) {
twi->setData(0, Qt::DisplayRole, room->getName());
twi->setData(1, Qt::DisplayRole, room->getDescription());
twi->setData(2, Qt::DisplayRole, room->getPlayerCount());
twi->setData(3, Qt::DisplayRole, room->getGameCount());
if (twi->data(0, Qt::UserRole).toInt() == room.room_id()) {
twi->setData(0, Qt::DisplayRole, QString::fromStdString(room.name()));
twi->setData(1, Qt::DisplayRole, QString::fromStdString(room.description()));
twi->setData(2, Qt::DisplayRole, room.player_count());
twi->setData(3, Qt::DisplayRole, room.game_count());
return;
}
}
QTreeWidgetItem *twi = new QTreeWidgetItem;
twi->setData(0, Qt::UserRole, room->getRoomId());
twi->setData(0, Qt::DisplayRole, room->getName());
twi->setData(1, Qt::DisplayRole, room->getDescription());
twi->setData(2, Qt::DisplayRole, room->getPlayerCount());
twi->setData(3, Qt::DisplayRole, room->getGameCount());
twi->setData(0, Qt::UserRole, room.room_id());
twi->setData(0, Qt::DisplayRole, QString::fromStdString(room.name()));
twi->setData(1, Qt::DisplayRole, QString::fromStdString(room.description()));
twi->setData(2, Qt::DisplayRole, room.player_count());
twi->setData(3, Qt::DisplayRole, room.game_count());
twi->setTextAlignment(2, Qt::AlignRight);
twi->setTextAlignment(3, Qt::AlignRight);
roomList->addTopLevelItem(twi);
if (room->getAutoJoin())
joinRoom(room->getRoomId(), false);
if (room.auto_join())
joinRoom(room.room_id(), false);
}
}
......@@ -99,7 +101,7 @@ void RoomSelector::joinRoom(int id, bool setCurrent)
PendingCommand *pend = client->prepareSessionCommand(cmd);
pend->setExtraData(setCurrent);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(joinFinished(ProtocolResponse *)));
connect(pend, SIGNAL(finished(const Response &)), this, SLOT(joinFinished(const Response &)));
client->sendCommand(pend);
}
......@@ -113,15 +115,13 @@ void RoomSelector::joinClicked()
joinRoom(twi->data(0, Qt::UserRole).toInt(), true);
}
void RoomSelector::joinFinished(ProtocolResponse *r)
void RoomSelector::joinFinished(const Response &r)
{
if (r->getResponseCode() != RespOk)
return;
Response_JoinRoom *resp = qobject_cast<Response_JoinRoom *>(r);
if (!resp)
if (r.response_code() != Response::RespOk)
return;
const Response_JoinRoom &resp = r.GetExtension(Response_JoinRoom::ext);
emit roomJoined(resp->getRoomInfo(), static_cast<PendingCommand *>(sender())->getExtraData().toBool());
emit roomJoined(resp.room_info(), static_cast<PendingCommand *>(sender())->getExtraData().toBool());
}
TabServer::TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent)
......@@ -131,9 +131,9 @@ TabServer::TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWi
serverInfoBox = new QTextBrowser;
serverInfoBox->setOpenExternalLinks(true);
connect(roomSelector, SIGNAL(roomJoined(ServerInfo_Room *, bool)), this, SIGNAL(roomJoined(ServerInfo_Room *, bool)));
connect(roomSelector, SIGNAL(roomJoined(const ServerInfo_Room &, bool)), this, SIGNAL(roomJoined(const ServerInfo_Room &, bool)));
connect(client, SIGNAL(serverMessageEventReceived(Event_ServerMessage *)), this, SLOT(processServerMessageEvent(Event_ServerMessage *)));
connect(client, SIGNAL(serverMessageEventReceived(const Event_ServerMessage &)), this, SLOT(processServerMessageEvent(const Event_ServerMessage &)));
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(roomSelector);
......@@ -147,8 +147,8 @@ void TabServer::retranslateUi()
roomSelector->retranslateUi();
}
void TabServer::processServerMessageEvent(Event_ServerMessage *event)
void TabServer::processServerMessageEvent(const Event_ServerMessage &event)
{
serverInfoBox->setHtml(event->getMessage());
serverInfoBox->setHtml(QString::fromStdString(event.message()));
emit userEvent();
}
......@@ -14,7 +14,7 @@ class QPushButton;
class Event_ListRooms;
class Event_ServerMessage;
class ProtocolResponse;
class Response;
class ServerInfo_Room;
class RoomSelector : public QGroupBox {
......@@ -26,11 +26,11 @@ private:
void joinRoom(int id, bool setCurrent);
private slots:
void processListRoomsEvent(Event_ListRooms *event);
void processListRoomsEvent(const Event_ListRooms &event);
void joinClicked();
void joinFinished(ProtocolResponse *resp);
void joinFinished(const Response &resp);
signals:
void roomJoined(ServerInfo_Room *info, bool setCurrent);
void roomJoined(const ServerInfo_Room &info, bool setCurrent);
public:
RoomSelector(AbstractClient *_client, QWidget *parent = 0);
void retranslateUi();
......@@ -39,9 +39,9 @@ public:
class TabServer : public Tab {
Q_OBJECT
signals:
void roomJoined(ServerInfo_Room *info, bool setCurrent);
void roomJoined(const ServerInfo_Room &info, bool setCurrent);
private slots:
void processServerMessageEvent(Event_ServerMessage *event);
void processServerMessageEvent(const Event_ServerMessage &event);
private:
AbstractClient *client;
RoomSelector *roomSelector;
......
......@@ -8,12 +8,17 @@
#include "tab_admin.h"
#include "tab_message.h"
#include "tab_userlists.h"
#include "protocol_items.h"
#include "pixmapgenerator.h"
#include <QDebug>
#include <QPainter>
#include "pb/room_commands.pb.h"
#include "pb/room_event.pb.h"
#include "pb/game_event_container.pb.h"
#include "pb/event_user_message.pb.h"
#include "pb/event_game_joined.pb.h"
#include "pb/serverinfo_user.pb.h"
#include "pb/serverinfo_room.pb.h"
CloseButton::CloseButton(QWidget *parent)
: QAbstractButton(parent)
......@@ -107,22 +112,22 @@ int TabSupervisor::myAddTab(Tab *tab)
return addTab(tab, tab->getTabText());
}
void TabSupervisor::start(AbstractClient *_client, ServerInfo_User *_userInfo)
void TabSupervisor::start(AbstractClient *_client, const ServerInfo_User &_userInfo)
{
client = _client;
userInfo = new ServerInfo_User(_userInfo);
connect(client, SIGNAL(roomEventReceived(RoomEvent *)), this, SLOT(processRoomEvent(RoomEvent *)));
connect(client, SIGNAL(gameEventContainerReceived(GameEventContainer *)), this, SLOT(processGameEventContainer(GameEventContainer *)));
connect(client, SIGNAL(gameJoinedEventReceived(Event_GameJoined *)), this, SLOT(gameJoined(Event_GameJoined *)));
connect(client, SIGNAL(messageEventReceived(Event_Message *)), this, SLOT(processMessageEvent(Event_Message *)));
connect(client, SIGNAL(roomEventReceived(const RoomEvent &)), this, SLOT(processRoomEvent(const RoomEvent &)));
connect(client, SIGNAL(gameEventContainerReceived(const GameEventContainer &)), this, SLOT(processGameEventContainer(const GameEventContainer &)));
connect(client, SIGNAL(gameJoinedEventReceived(const Event_GameJoined &)), this, SLOT(gameJoined(const Event_GameJoined &)));
connect(client, SIGNAL(userMessageEventReceived(const Event_UserMessage &)), this, SLOT(processUserMessageEvent(const Event_UserMessage &)));
connect(client, SIGNAL(maxPingTime(int, int)), this, SLOT(updatePingTime(int, int)));
tabServer = new TabServer(this, client);
connect(tabServer, SIGNAL(roomJoined(ServerInfo_Room *, bool)), this, SLOT(addRoomTab(ServerInfo_Room *, bool)));
connect(tabServer, SIGNAL(roomJoined(const ServerInfo_Room &, bool)), this, SLOT(addRoomTab(const ServerInfo_Room &, bool)));
myAddTab(tabServer);
tabUserLists = new TabUserLists(this, client, userInfo);
tabUserLists = new TabUserLists(this, client, *userInfo);
connect(tabUserLists, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool)));
connect(tabUserLists, SIGNAL(userJoined(const QString &)), this, SLOT(processUserJoined(const QString &)));
connect(tabUserLists, SIGNAL(userLeft(const QString &)), this, SLOT(processUserLeft(const QString &)));
......@@ -130,14 +135,14 @@ void TabSupervisor::start(AbstractClient *_client, ServerInfo_User *_userInfo)
updatePingTime(0, -1);
if (userInfo->getUserLevel() & ServerInfo_User::IsRegistered) {
if (userInfo->user_level() & ServerInfo_User::IsRegistered) {
tabDeckStorage = new TabDeckStorage(this, client);
myAddTab(tabDeckStorage);
} else
tabDeckStorage = 0;
if (userInfo->getUserLevel() & ServerInfo_User::IsModerator) {
tabAdmin = new TabAdmin(this, client, (userInfo->getUserLevel() & ServerInfo_User::IsAdmin));
if (userInfo->user_level() & ServerInfo_User::IsModerator) {
tabAdmin = new TabAdmin(this, client, (userInfo->user_level() & ServerInfo_User::IsAdmin));
connect(tabAdmin, SIGNAL(adminLockChanged(bool)), this, SIGNAL(adminLockChanged(bool)));
myAddTab(tabAdmin);
} else
......@@ -154,8 +159,8 @@ void TabSupervisor::startLocal(const QList<AbstractClient *> &_clients)
userInfo = new ServerInfo_User;
localClients = _clients;
for (int i = 0; i < localClients.size(); ++i)
connect(localClients[i], SIGNAL(gameEventContainerReceived(GameEventContainer *)), this, SLOT(processGameEventContainer(GameEventContainer *)));
connect(localClients.first(), SIGNAL(gameJoinedEventReceived(Event_GameJoined *)), this, SLOT(localGameJoined(Event_GameJoined *)));
connect(localClients[i], SIGNAL(gameEventContainerReceived(const GameEventContainer &)), this, SLOT(processGameEventContainer(const GameEventContainer &)));
connect(localClients.first(), SIGNAL(gameJoinedEventReceived(const Event_GameJoined &)), this, SLOT(localGameJoined(const Event_GameJoined &)));
}
void TabSupervisor::stop()
......@@ -228,29 +233,29 @@ void TabSupervisor::addCloseButtonToTab(Tab *tab, int tabIndex)
tabBar()->setTabButton(tabIndex, closeSide, closeButton);
}
void TabSupervisor::gameJoined(Event_GameJoined *event)
void TabSupervisor::gameJoined(const Event_GameJoined &event)
{
TabGame *tab = new TabGame(this, QList<AbstractClient *>() << client, event->getGameId(), event->getGameDescription(), event->getHostId(), event->getPlayerId(), event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming());
TabGame *tab = new TabGame(this, QList<AbstractClient *>() << client, event);
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
connect(tab, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool)));
int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex);
gameTabs.insert(event->getGameId(), tab);
gameTabs.insert(event.game_id(), tab);
setCurrentWidget(tab);
}
void TabSupervisor::localGameJoined(Event_GameJoined *event)
void TabSupervisor::localGameJoined(const Event_GameJoined &event)
{
TabGame *tab = new TabGame(this, localClients, event->getGameId(), event->getGameDescription(), event->getHostId(), event->getPlayerId(), event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming());
TabGame *tab = new TabGame(this, localClients, event);
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex);
gameTabs.insert(event->getGameId(), tab);
gameTabs.insert(event.game_id(), tab);
setCurrentWidget(tab);
for (int i = 1; i < localClients.size(); ++i) {
Command_JoinGame cmd;
cmd.set_game_id(event->getGameId());
cmd.set_game_id(event.game_id());
localClients[i]->sendCommand(localClients[i]->prepareRoomCommand(cmd, 0));
}
}
......@@ -266,14 +271,14 @@ void TabSupervisor::gameLeft(TabGame *tab)
stop();
}
void TabSupervisor::addRoomTab(ServerInfo_Room *info, bool setCurrent)
void TabSupervisor::addRoomTab(const ServerInfo_Room &info, bool setCurrent)
{
TabRoom *tab = new TabRoom(this, client, userInfo->getName(), info);
TabRoom *tab = new TabRoom(this, client, QString::fromStdString(userInfo->name()), 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);
addCloseButtonToTab(tab, tabIndex);
roomTabs.insert(info->getRoomId(), tab);
roomTabs.insert(info.room_id(), tab);
if (setCurrent)
setCurrentWidget(tab);
}
......@@ -288,10 +293,10 @@ void TabSupervisor::roomLeft(TabRoom *tab)
TabMessage *TabSupervisor::addMessageTab(const QString &receiverName, bool focus)
{
if (receiverName == userInfo->getName())
if (receiverName == QString::fromStdString(userInfo->name()))
return 0;
TabMessage *tab = new TabMessage(this, client, userInfo->getName(), receiverName);
TabMessage *tab = new TabMessage(this, client, QString::fromStdString(userInfo->name()), receiverName);
connect(tab, SIGNAL(talkClosing(TabMessage *)), this, SLOT(talkLeft(TabMessage *)));
int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex);
......@@ -320,33 +325,33 @@ void TabSupervisor::tabUserEvent(bool globalEvent)
QApplication::alert(this);
}
void TabSupervisor::processRoomEvent(RoomEvent *event)
void TabSupervisor::processRoomEvent(const RoomEvent &event)
{
TabRoom *tab = roomTabs.value(event->getRoomId(), 0);
TabRoom *tab = roomTabs.value(event.room_id(), 0);
if (tab)
tab->processRoomEvent(event);
}
void TabSupervisor::processGameEventContainer(GameEventContainer *cont)
void TabSupervisor::processGameEventContainer(const GameEventContainer &cont)
{
TabGame *tab = gameTabs.value(cont->getGameId());
TabGame *tab = gameTabs.value(cont.game_id());
if (tab) {
qDebug() << "gameEvent gameId =" << cont->getGameId();
qDebug() << "gameEvent gameId =" << cont.game_id();
tab->processGameEventContainer(cont, qobject_cast<AbstractClient *>(sender()));
} else
qDebug() << "gameEvent: invalid gameId";
}
void TabSupervisor::processMessageEvent(Event_Message *event)
void TabSupervisor::processUserMessageEvent(const Event_UserMessage &event)
{
TabMessage *tab = messageTabs.value(event->getSenderName());
TabMessage *tab = messageTabs.value(QString::fromStdString(event.sender_name()));
if (!tab)
tab = messageTabs.value(event->getReceiverName());
tab = messageTabs.value(QString::fromStdString(event.receiver_name()));
if (!tab)
tab = addMessageTab(event->getSenderName(), false);
tab = addMessageTab(QString::fromStdString(event.sender_name()), false);
if (!tab)
return;
tab->processMessageEvent(event);
tab->processUserMessageEvent(event);
}
void TabSupervisor::processUserLeft(const QString &userName)
......@@ -385,5 +390,5 @@ bool TabSupervisor::getAdminLocked() const
int TabSupervisor::getUserLevel() const
{
return userInfo->getUserLevel();
return userInfo->user_level();
}
......@@ -18,7 +18,7 @@ class TabUserLists;
class RoomEvent;
class GameEventContainer;
class Event_GameJoined;
class Event_Message;
class Event_UserMessage;
class ServerInfo_Room;
class ServerInfo_User;
......@@ -54,7 +54,7 @@ public:
TabSupervisor(QWidget *parent = 0);
~TabSupervisor();
void retranslateUi();
void start(AbstractClient *_client, ServerInfo_User *userInfo);
void start(AbstractClient *_client, const ServerInfo_User &userInfo);
void startLocal(const QList<AbstractClient *> &_clients);
void stop();
int getGameCount() const { return gameTabs.size(); }
......@@ -71,19 +71,19 @@ private slots:
void closeButtonPressed();
void updateCurrent(int index);
void updatePingTime(int value, int max);
void gameJoined(Event_GameJoined *event);
void localGameJoined(Event_GameJoined *event);
void gameJoined(const Event_GameJoined &event);
void localGameJoined(const Event_GameJoined &event);
void gameLeft(TabGame *tab);
void addRoomTab(ServerInfo_Room *info, bool setCurrent);
void addRoomTab(const ServerInfo_Room &info, bool setCurrent);
void roomLeft(TabRoom *tab);
TabMessage *addMessageTab(const QString &userName, bool focus);
void processUserLeft(const QString &userName);
void processUserJoined(const QString &userName);
void talkLeft(TabMessage *tab);
void tabUserEvent(bool globalEvent);
void processRoomEvent(RoomEvent *event);
void processGameEventContainer(GameEventContainer *cont);
void processMessageEvent(Event_Message *event);
void processRoomEvent(const RoomEvent &event);
void processGameEventContainer(const GameEventContainer &cont);
void processUserMessageEvent(const Event_UserMessage &event);
};
#endif
......@@ -5,12 +5,16 @@
#include <QDebug>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include "protocol_items.h"
#include "pending_command.h"
#include "pb/session_commands.pb.h"
#include "pb/response_list_users.pb.h"
#include "pb/event_user_joined.pb.h"
#include "pb/event_user_left.pb.h"
#include "pb/event_add_to_list.pb.h"
#include "pb/event_remove_from_list.pb.h"
TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerInfo_User *userInfo, QWidget *parent)
TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User &userInfo, QWidget *parent)
: Tab(_tabSupervisor, parent), client(_client)
{
allUsersList = new UserList(_tabSupervisor, client, UserList::AllUsersList);
......@@ -23,15 +27,15 @@ TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_clien
connect(buddyList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
connect(ignoreList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
connect(client, SIGNAL(userJoinedEventReceived(Event_UserJoined *)), this, SLOT(processUserJoinedEvent(Event_UserJoined *)));
connect(client, SIGNAL(userLeftEventReceived(Event_UserLeft *)), this, SLOT(processUserLeftEvent(Event_UserLeft *)));
connect(client, SIGNAL(buddyListReceived(const QList<ServerInfo_User *> &)), this, SLOT(buddyListReceived(const QList<ServerInfo_User *> &)));
connect(client, SIGNAL(ignoreListReceived(const QList<ServerInfo_User *> &)), this, SLOT(ignoreListReceived(const QList<ServerInfo_User *> &)));
connect(client, SIGNAL(addToListEventReceived(Event_AddToList *)), this, SLOT(processAddToListEvent(Event_AddToList *)));
connect(client, SIGNAL(removeFromListEventReceived(Event_RemoveFromList *)), this, SLOT(processRemoveFromListEvent(Event_RemoveFromList *)));
connect(client, SIGNAL(userJoinedEventReceived(const Event_UserJoined &)), this, SLOT(processUserJoinedEvent(const Event_UserJoined &)));
connect(client, SIGNAL(userLeftEventReceived(const Event_UserLeft &)), this, SLOT(processUserLeftEvent(const Event_UserLeft &)));
connect(client, SIGNAL(buddyListReceived(const QList<ServerInfo_User> &)), this, SLOT(buddyListReceived(const QList<ServerInfo_User> &)));
connect(client, SIGNAL(ignoreListReceived(const QList<ServerInfo_User> &)), this, SLOT(ignoreListReceived(const QList<ServerInfo_User> &)));
connect(client, SIGNAL(addToListEventReceived(const Event_AddToList *)), this, SLOT(processAddToListEvent(const Event_AddToList &)));
connect(client, SIGNAL(removeFromListEventReceived(const Event_RemoveFromList *)), this, SLOT(processRemoveFromListEvent(const Event_RemoveFromList &)));
PendingCommand *pend = client->prepareSessionCommand(Command_ListUsers());
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(processListUsersResponse(ProtocolResponse *)));
connect(pend, SIGNAL(finished(const Response &)), this, SLOT(processListUsersResponse(const Response &)));
client->sendCommand(pend);
QVBoxLayout *vbox = new QVBoxLayout;
......@@ -54,17 +58,17 @@ void TabUserLists::retranslateUi()
userInfoBox->retranslateUi();
}
void TabUserLists::processListUsersResponse(ProtocolResponse *response)
void TabUserLists::processListUsersResponse(const Response &response)
{
Response_ListUsers *resp = qobject_cast<Response_ListUsers *>(response);
if (!resp)
return;
const Response_ListUsers &resp = response.GetExtension(Response_ListUsers::ext);
const QList<ServerInfo_User *> &respList = resp->getUserList();
for (int i = 0; i < respList.size(); ++i) {
allUsersList->processUserInfo(respList[i], true);
ignoreList->setUserOnline(respList[i]->getName(), true);
buddyList->setUserOnline(respList[i]->getName(), true);
const int userListSize = resp.user_list_size();
for (int i = 0; i < userListSize; ++i) {
const ServerInfo_User &info = resp.user_list(i);
const QString userName = QString::fromStdString(info.name());
allUsersList->processUserInfo(info, true);
ignoreList->setUserOnline(userName, true);
buddyList->setUserOnline(userName, true);
}
allUsersList->sortItems();
......@@ -72,23 +76,25 @@ void TabUserLists::processListUsersResponse(ProtocolResponse *response)
buddyList->sortItems();
}
void TabUserLists::processUserJoinedEvent(Event_UserJoined *event)
void TabUserLists::processUserJoinedEvent(const Event_UserJoined &event)
{
ServerInfo_User *info = event->getUserInfo();
const ServerInfo_User &info = event.user_info();
const QString userName = QString::fromStdString(info.name());
allUsersList->processUserInfo(info, true);
ignoreList->setUserOnline(info->getName(), true);
buddyList->setUserOnline(info->getName(), true);
ignoreList->setUserOnline(userName, true);
buddyList->setUserOnline(userName, true);
allUsersList->sortItems();
ignoreList->sortItems();
buddyList->sortItems();
emit userJoined(event->getUserInfo()->getName());
emit userJoined(userName);
}
void TabUserLists::processUserLeftEvent(Event_UserLeft *event)
void TabUserLists::processUserLeftEvent(const Event_UserLeft &event)
{
QString userName = event->getUserName();
QString userName = QString::fromStdString(event.name());
if (allUsersList->deleteUser(userName)) {
ignoreList->setUserOnline(userName, false);
buddyList->setUserOnline(userName, false);
......@@ -99,25 +105,25 @@ void TabUserLists::processUserLeftEvent(Event_UserLeft *event)
}
}
void TabUserLists::buddyListReceived(const QList<ServerInfo_User *> &_buddyList)
void TabUserLists::buddyListReceived(const QList<ServerInfo_User> &_buddyList)
{
for (int i = 0; i < _buddyList.size(); ++i)
buddyList->processUserInfo(_buddyList[i], false);
buddyList->sortItems();
}
void TabUserLists::ignoreListReceived(const QList<ServerInfo_User *> &_ignoreList)
void TabUserLists::ignoreListReceived(const QList<ServerInfo_User> &_ignoreList)
{
for (int i = 0; i < _ignoreList.size(); ++i)
ignoreList->processUserInfo(_ignoreList[i], false);
ignoreList->sortItems();
}
void TabUserLists::processAddToListEvent(Event_AddToList *event)
void TabUserLists::processAddToListEvent(const Event_AddToList &event)
{
ServerInfo_User *info = event->getUserInfo();
bool online = allUsersList->userInList(info->getName());
QString list = event->getList();
const ServerInfo_User &info = event.user_info();
bool online = allUsersList->userInList(QString::fromStdString(info.name()));
QString list = QString::fromStdString(event.list_name());
UserList *userList = 0;
if (list == "buddy")
userList = buddyList;
......@@ -130,10 +136,10 @@ void TabUserLists::processAddToListEvent(Event_AddToList *event)
userList->sortItems();
}
void TabUserLists::processRemoveFromListEvent(Event_RemoveFromList *event)
void TabUserLists::processRemoveFromListEvent(const Event_RemoveFromList &event)
{
QString list = event->getList();
QString user = event->getUserName();
QString list = QString::fromStdString(event.list_name());
QString user = QString::fromStdString(event.user_name());
UserList *userList = 0;
if (list == "buddy")
userList = buddyList;
......
......@@ -2,6 +2,7 @@
#define TAB_USERLISTS_H
#include "tab.h"
#include "pb/serverinfo_user.pb.h"
class AbstractClient;
class UserList;
......@@ -10,7 +11,7 @@ class UserInfoBox;
class Event_ListRooms;
class Event_UserJoined;
class Event_UserLeft;
class ProtocolResponse;
class Response;
class ServerInfo_User;
class Event_AddToList;
class Event_RemoveFromList;
......@@ -22,13 +23,13 @@ signals:
void userLeft(const QString &userName);
void userJoined(const QString &userName);
private slots:
void processListUsersResponse(ProtocolResponse *response);
void processUserJoinedEvent(Event_UserJoined *event);
void processUserLeftEvent(Event_UserLeft *event);
void buddyListReceived(const QList<ServerInfo_User *> &_buddyList);
void ignoreListReceived(const QList<ServerInfo_User *> &_ignoreList);
void processAddToListEvent(Event_AddToList *event);
void processRemoveFromListEvent(Event_RemoveFromList *event);
void processListUsersResponse(const Response &response);
void processUserJoinedEvent(const Event_UserJoined &event);
void processUserLeftEvent(const Event_UserLeft &event);
void buddyListReceived(const QList<ServerInfo_User> &_buddyList);
void ignoreListReceived(const QList<ServerInfo_User> &_ignoreList);
void processAddToListEvent(const Event_AddToList &event);
void processRemoveFromListEvent(const Event_RemoveFromList &event);
private:
AbstractClient *client;
UserList *allUsersList;
......@@ -36,7 +37,7 @@ private:
UserList *ignoreList;
UserInfoBox *userInfoBox;
public:
TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerInfo_User *userInfo, QWidget *parent = 0);
TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User &userInfo, QWidget *parent = 0);
void retranslateUi();
QString getTabText() const { return tr("User lists"); }
UserList *getBuddyList() const { return buddyList; }
......
......@@ -8,6 +8,7 @@
#include "arrowitem.h"
#include "carddragitem.h"
#include "carddatabase.h"
#include "carditem.h"
#include "pb/command_move_card.pb.h"
#include "pb/command_set_card_attr.pb.h"
......
#include "userinfobox.h"
#include "protocol_datastructures.h"
#include "pixmapgenerator.h"
#include "protocol_items.h"
#include "abstractclient.h"
#include <QLabel>
#include <QGridLayout>
#include "pending_command.h"
#include "pb/session_commands.pb.h"
#include "pb/response_get_user_info.pb.h"
UserInfoBox::UserInfoBox(AbstractClient *_client, bool _fullInfo, QWidget *parent, Qt::WindowFlags flags)
: QWidget(parent, flags), client(_client), fullInfo(_fullInfo)
......@@ -55,19 +54,20 @@ void UserInfoBox::retranslateUi()
userLevelLabel1->setText(tr("User level:"));
}
void UserInfoBox::updateInfo(ServerInfo_User *user)
void UserInfoBox::updateInfo(const ServerInfo_User &user)
{
int userLevel = user->getUserLevel();
const int userLevel = user.user_level();
QPixmap avatarPixmap;
if (!avatarPixmap.loadFromData(user->getAvatarBmp()))
const std::string bmp = user.avatar_bmp();
if (!avatarPixmap.loadFromData((const uchar *) bmp.data(), bmp.size()))
avatarPixmap = UserLevelPixmapGenerator::generatePixmap(64, userLevel);
avatarLabel->setPixmap(avatarPixmap);
nameLabel->setText(user->getName());
realNameLabel2->setText(user->getRealName());
genderLabel2->setPixmap(GenderPixmapGenerator::generatePixmap(15, user->getGender()));
countryLabel2->setPixmap(CountryPixmapGenerator::generatePixmap(15, user->getCountry()));
nameLabel->setText(QString::fromStdString(user.name()));
realNameLabel2->setText(QString::fromStdString(user.real_name()));
genderLabel2->setPixmap(GenderPixmapGenerator::generatePixmap(15, user.gender()));
countryLabel2->setPixmap(CountryPixmapGenerator::generatePixmap(15, QString::fromStdString(user.country())));
userLevelLabel2->setPixmap(UserLevelPixmapGenerator::generatePixmap(15, userLevel));
QString userLevelText;
if (userLevel & ServerInfo_User::IsAdmin)
......@@ -87,18 +87,15 @@ void UserInfoBox::updateInfo(const QString &userName)
cmd.set_user_name(userName.toStdString());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(processResponse(ProtocolResponse *)));
connect(pend, SIGNAL(finished(const Response &)), this, SLOT(processResponse(const Response &)));
client->sendCommand(pend);
}
void UserInfoBox::processResponse(ProtocolResponse *r)
void UserInfoBox::processResponse(const Response &r)
{
Response_GetUserInfo *response = qobject_cast<Response_GetUserInfo *>(r);
if (!response)
return;
updateInfo(response->getUserInfo());
const Response_GetUserInfo &response = r.GetExtension(Response_GetUserInfo::ext);
updateInfo(response.user_info());
setFixedSize(sizeHint());
show();
}
......@@ -6,7 +6,7 @@
class QLabel;
class ServerInfo_User;
class AbstractClient;
class ProtocolResponse;
class Response;
class UserInfoBox : public QWidget {
Q_OBJECT
......@@ -18,9 +18,9 @@ public:
UserInfoBox(AbstractClient *_client, bool fullInfo, QWidget *parent = 0, Qt::WindowFlags flags = 0);
void retranslateUi();
private slots:
void processResponse(ProtocolResponse *r);
void processResponse(const Response &r);
public slots:
void updateInfo(ServerInfo_User *user);
void updateInfo(const ServerInfo_User &user);
void updateInfo(const QString &userName);
};
......
......@@ -4,7 +4,6 @@
#include "abstractclient.h"
#include "pixmapgenerator.h"
#include "userinfobox.h"
#include "protocol_items.h"
#include "gameselector.h"
#include <QHeaderView>
#include <QVBoxLayout>
......@@ -23,18 +22,20 @@
#include "pending_command.h"
#include "pb/session_commands.pb.h"
#include "pb/moderator_commands.pb.h"
#include "pb/response_get_games_of_user.pb.h"
#include "pb/response_get_user_info.pb.h"
BanDialog::BanDialog(ServerInfo_User *info, QWidget *parent)
BanDialog::BanDialog(const ServerInfo_User &info, QWidget *parent)
: QDialog(parent)
{
setAttribute(Qt::WA_DeleteOnClose);
nameBanCheckBox = new QCheckBox(tr("ban &user name"));
nameBanCheckBox->setChecked(true);
nameBanEdit = new QLineEdit(info->getName());
nameBanEdit = new QLineEdit(QString::fromStdString(info.name()));
ipBanCheckBox = new QCheckBox(tr("ban &IP address"));
ipBanCheckBox->setChecked(true);
ipBanEdit = new QLineEdit(info->getAddress());
ipBanEdit = new QLineEdit(QString::fromStdString(info.address()));
QGridLayout *banTypeGrid = new QGridLayout;
banTypeGrid->addWidget(nameBanCheckBox, 0, 0);
banTypeGrid->addWidget(nameBanEdit, 0, 1);
......@@ -211,12 +212,12 @@ void UserList::retranslateUi()
updateCount();
}
void UserList::processUserInfo(ServerInfo_User *user, bool online)
void UserList::processUserInfo(const ServerInfo_User &user, bool online)
{
QTreeWidgetItem *item = 0;
for (int i = 0; i < userTree->topLevelItemCount(); ++i) {
QTreeWidgetItem *temp = userTree->topLevelItem(i);
if (temp->data(2, Qt::UserRole) == user->getName()) {
if (temp->data(2, Qt::UserRole) == QString::fromStdString(user.name())) {
item = temp;
break;
}
......@@ -228,11 +229,11 @@ void UserList::processUserInfo(ServerInfo_User *user, bool online)
++onlineCount;
updateCount();
}
item->setData(0, Qt::UserRole, user->getUserLevel());
item->setIcon(0, QIcon(UserLevelPixmapGenerator::generatePixmap(12, user->getUserLevel())));
item->setIcon(1, QIcon(CountryPixmapGenerator::generatePixmap(12, user->getCountry())));
item->setData(2, Qt::UserRole, user->getName());
item->setData(2, Qt::DisplayRole, user->getName());
item->setData(0, Qt::UserRole, user.user_level());
item->setIcon(0, QIcon(UserLevelPixmapGenerator::generatePixmap(12, user.user_level())));
item->setIcon(1, QIcon(CountryPixmapGenerator::generatePixmap(12, QString::fromStdString(user.country()))));
item->setData(2, Qt::UserRole, QString::fromStdString(user.name()));
item->setData(2, Qt::DisplayRole, QString::fromStdString(user.name()));
item->setData(0, Qt::UserRole + 1, online);
if (online)
......@@ -294,43 +295,42 @@ void UserList::userClicked(QTreeWidgetItem *item, int /*column*/)
emit openMessageDialog(item->data(2, Qt::UserRole).toString(), true);
}
void UserList::gamesOfUserReceived(ProtocolResponse *resp)
void UserList::gamesOfUserReceived(const Response &resp)
{
Response_GetGamesOfUser *response = qobject_cast<Response_GetGamesOfUser *>(resp);
if (!response)
return;
const Response_GetGamesOfUser &response = resp.GetExtension(Response_GetGamesOfUser::ext);
const Command_GetGamesOfUser &cmd = static_cast<const Command_GetGamesOfUser &>(static_cast<PendingCommand *>(sender())->getCommandContainer().session_command(0).GetExtension(Command_GetGamesOfUser::ext));
QMap<int, GameTypeMap> gameTypeMap;
QMap<int, QString> roomMap;
const QList<ServerInfo_Room *> roomList = response->getRoomList();
for (int i = 0; i < roomList.size(); ++i) {
roomMap.insert(roomList[i]->getRoomId(), roomList[i]->getName());
const QList<ServerInfo_GameType *> gameTypeList = roomList[i]->getGameTypeList();
const int roomListSize = response.room_list_size();
for (int i = 0; i < roomListSize; ++i) {
const ServerInfo_Room &roomInfo = response.room_list(i);
roomMap.insert(roomInfo.room_id(), QString::fromStdString(roomInfo.name()));
GameTypeMap tempMap;
for (int j = 0; j < gameTypeList.size(); ++j)
tempMap.insert(gameTypeList[j]->getGameTypeId(), gameTypeList[j]->getDescription());
gameTypeMap.insert(roomList[i]->getRoomId(), tempMap);
const int gameTypeListSize = roomInfo.gametype_list_size();
for (int j = 0; j < gameTypeListSize; ++j) {
const ServerInfo_GameType &gameTypeInfo = roomInfo.gametype_list(j);
tempMap.insert(gameTypeInfo.game_type_id(), QString::fromStdString(gameTypeInfo.description()));
}
gameTypeMap.insert(roomInfo.room_id(), tempMap);
}
GameSelector *selector = new GameSelector(client, tabSupervisor, 0, roomMap, gameTypeMap);
const QList<ServerInfo_Game *> gameList = response->getGameList();
for (int i = 0; i < gameList.size(); ++i)
selector->processGameInfo(gameList[i]);
const int gameListSize = response.game_list_size();
for (int i = 0; i < gameListSize; ++i)
selector->processGameInfo(response.game_list(i));
selector->setWindowTitle(tr("%1's games").arg(QString::fromStdString(cmd.user_name())));
selector->setAttribute(Qt::WA_DeleteOnClose);
selector->show();
}
void UserList::banUser_processUserInfoResponse(ProtocolResponse *r)
void UserList::banUser_processUserInfoResponse(const Response &r)
{
Response_GetUserInfo *response = qobject_cast<Response_GetUserInfo *>(r);
if (!response)
return;
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.
BanDialog *dlg = new BanDialog(response->getUserInfo(), this);
BanDialog *dlg = new BanDialog(response.user_info(), this);
connect(dlg, SIGNAL(accepted()), this, SLOT(banUser_dialogFinished()));
dlg->show();
}
......@@ -385,7 +385,7 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
menu->addSeparator();
menu->addAction(aBan);
}
if (userName == tabSupervisor->getUserInfo()->getName()) {
if (userName == QString::fromStdString(tabSupervisor->getUserInfo()->name())) {
aChat->setEnabled(false);
aAddToBuddyList->setEnabled(false);
aRemoveFromBuddyList->setEnabled(false);
......
......@@ -15,7 +15,7 @@ class QCheckBox;
class QSpinBox;
class QRadioButton;
class QPlainTextEdit;
class ProtocolResponse;
class Response;
class BanDialog : public QDialog {
Q_OBJECT
......@@ -30,7 +30,7 @@ private slots:
void okClicked();
void enableTemporaryEdits(bool enabled);
public:
BanDialog(ServerInfo_User *info, QWidget *parent = 0);
BanDialog(const ServerInfo_User &info, QWidget *parent = 0);
QString getBanName() const;
QString getBanIP() const;
int getMinutes() const;
......@@ -65,9 +65,9 @@ private:
void setUserOnline(QTreeWidgetItem *user, bool online);
private slots:
void userClicked(QTreeWidgetItem *item, int column);
void banUser_processUserInfoResponse(ProtocolResponse *resp);
void banUser_processUserInfoResponse(const Response &resp);
void banUser_dialogFinished();
void gamesOfUserReceived(ProtocolResponse *resp);
void gamesOfUserReceived(const Response &resp);
signals:
void openMessageDialog(const QString &userName, bool focus);
void addBuddy(const QString &userName);
......@@ -77,7 +77,7 @@ signals:
public:
UserList(TabSupervisor *_tabSupervisor, AbstractClient *_client, UserListType _type, QWidget *parent = 0);
void retranslateUi();
void processUserInfo(ServerInfo_User *user, bool online);
void processUserInfo(const ServerInfo_User &user, bool online);
bool deleteUser(const QString &userName);
void setUserOnline(const QString &userName, bool online);
bool userInList(const QString &userName) const;
......
......@@ -96,7 +96,7 @@ void MainWindow::statusChanged(ClientStatus _status)
}
}
void MainWindow::userInfoReceived(ServerInfo_User *info)
void MainWindow::userInfoReceived(const ServerInfo_User &info)
{
tabSupervisor->start(client, info);
}
......@@ -302,14 +302,14 @@ MainWindow::MainWindow(QWidget *parent)
QPixmapCache::setCacheLimit(200000);
client = new RemoteClient(this);
connect(client, SIGNAL(connectionClosedEventReceived(Event_ConnectionClosed *)), this, SLOT(processConnectionClosedEvent(Event_ConnectionClosed *)));
connect(client, SIGNAL(serverShutdownEventReceived(Event_ServerShutdown *)), this, SLOT(processServerShutdownEvent(Event_ServerShutdown *)));
connect(client, SIGNAL(connectionClosedEventReceived(const Event_ConnectionClosed &)), this, SLOT(processConnectionClosedEvent(const Event_ConnectionClosed &)));
connect(client, SIGNAL(serverShutdownEventReceived(const Event_ServerShutdown &)), this, SLOT(processServerShutdownEvent(const Event_ServerShutdown &)));
connect(client, SIGNAL(serverError(Response::ResponseCode)), this, SLOT(serverError(Response::ResponseCode)));
connect(client, SIGNAL(socketError(const QString &)), this, SLOT(socketError(const QString &)));
connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout()));
connect(client, SIGNAL(statusChanged(ClientStatus)), this, SLOT(statusChanged(ClientStatus)));
connect(client, SIGNAL(protocolVersionMismatch(int, int)), this, SLOT(protocolVersionMismatch(int, int)));
connect(client, SIGNAL(userInfoChanged(ServerInfo_User *)), this, SLOT(userInfoReceived(ServerInfo_User *)));
connect(client, SIGNAL(userInfoChanged(const ServerInfo_User &)), this, SLOT(userInfoReceived(const ServerInfo_User &)));
tabSupervisor = new TabSupervisor;
connect(tabSupervisor, SIGNAL(setMenu(QMenu *)), this, SLOT(updateTabMenu(QMenu *)));
......
......@@ -41,7 +41,7 @@ private slots:
void serverError(Response::ResponseCode r);
void socketError(const QString &errorStr);
void protocolVersionMismatch(int localVersion, int remoteVersion);
void userInfoReceived(ServerInfo_User *userInfo);
void userInfoReceived(const ServerInfo_User &userInfo);
void localGameEnded();
void actConnect();
......
......@@ -11,7 +11,6 @@
#include "zoneviewzone.h"
#include "player.h"
#include "gamescene.h"
#include "protocol_items.h"
#include "settingscache.h"
#include "gamescene.h"
......@@ -56,7 +55,7 @@ void TitleLabel::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
emit mouseMoved(event->scenePos() - buttonDownPos);
}
ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards, bool _revealZone, const QList<ServerInfo_Card *> &cardList)
ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards, bool _revealZone, const QList<const ServerInfo_Card *> &cardList)
: QGraphicsWidget(0, Qt::Tool | Qt::FramelessWindowHint), player(_player)
{
setAcceptHoverEvents(true);
......
......@@ -51,7 +51,7 @@ private slots:
void zoneDeleted();
void moveWidget(QPointF scenePos);
public:
ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards = 0, bool _revealZone = false, const QList<ServerInfo_Card *> &cardList = QList<ServerInfo_Card *>());
ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards = 0, bool _revealZone = false, const QList<const ServerInfo_Card *> &cardList = QList<const ServerInfo_Card *>());
ZoneViewZone *getZone() const { return zone; }
void retranslateUi();
protected:
......
......@@ -3,11 +3,11 @@
#include "zoneviewzone.h"
#include "player.h"
#include "carddragitem.h"
#include "protocol_items.h"
#include "protocol_datastructures.h"
#include "carditem.h"
#include "pb/command_dump_zone.pb.h"
#include "pb/command_move_card.pb.h"
#include "pb/serverinfo_card.pb.h"
#include "pb/response_dump_zone.pb.h"
#include "pending_command.h"
ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, bool _revealZone, QGraphicsItem *parent)
......@@ -34,11 +34,11 @@ void ZoneViewZone::paint(QPainter */*painter*/, const QStyleOptionGraphicsItem *
{
}
void ZoneViewZone::initializeCards(const QList<ServerInfo_Card *> &cardList)
void ZoneViewZone::initializeCards(const QList<const ServerInfo_Card *> &cardList)
{
if (!cardList.isEmpty()) {
for (int i = 0; i < cardList.size(); ++i)
addCard(new CardItem(player, cardList[i]->getName(), cardList[i]->getId(), revealZone, this), false, i);
addCard(new CardItem(player, QString::fromStdString(cardList[i]->name()), cardList[i]->id(), revealZone, this), false, i);
reorganizeCards();
} else if (!origZone->contentsKnown()) {
Command_DumpZone cmd;
......@@ -47,7 +47,7 @@ void ZoneViewZone::initializeCards(const QList<ServerInfo_Card *> &cardList)
cmd.set_number_cards(numberCards);
PendingCommand *pend = player->prepareGameCommand(cmd);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(zoneDumpReceived(ProtocolResponse *)));
connect(pend, SIGNAL(finished(const Response &)), this, SLOT(zoneDumpReceived(const Response &)));
player->sendGameCommand(pend);
} else {
const CardList &c = origZone->getCards();
......@@ -60,15 +60,13 @@ void ZoneViewZone::initializeCards(const QList<ServerInfo_Card *> &cardList)
}
}
void ZoneViewZone::zoneDumpReceived(ProtocolResponse *r)
void ZoneViewZone::zoneDumpReceived(const Response &r)
{
Response_DumpZone *resp = qobject_cast<Response_DumpZone *>(r);
if (!resp)
return;
const QList<ServerInfo_Card *> &respCardList = resp->getZone()->getCardList();
for (int i = 0; i < respCardList.size(); i++) {
CardItem *card = new CardItem(player, respCardList[i]->getName(), respCardList[i]->getId(), revealZone, this);
const Response_DumpZone &resp = r.GetExtension(Response_DumpZone::ext);
const int respCardListSize = resp.zone_info().card_list_size();
for (int i = 0; i < respCardListSize; ++i) {
const ServerInfo_Card &cardInfo = resp.zone_info().card_list(i);
CardItem *card = new CardItem(player, QString::fromStdString(cardInfo.name()), cardInfo.id(), revealZone, this);
addCard(card, false, i);
}
......
......@@ -5,7 +5,7 @@
#include <QGraphicsLayoutItem>
class ZoneViewWidget;
class ProtocolResponse;
class Response;
class ServerInfo_Card;
class ZoneViewZone : public SelectZone, public QGraphicsLayoutItem {
......@@ -23,7 +23,7 @@ public:
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards();
void initializeCards(const QList<ServerInfo_Card *> &cardList = QList<ServerInfo_Card *>());
void initializeCards(const QList<const ServerInfo_Card *> &cardList = QList<const ServerInfo_Card *>());
void removeCard(int position);
int getNumberCards() const { return numberCards; }
void setGeometry(const QRectF &rect);
......@@ -32,7 +32,7 @@ public slots:
void setSortByName(int _sortByName);
void setSortByType(int _sortByType);
private slots:
void zoneDumpReceived(ProtocolResponse *r);
void zoneDumpReceived(const Response &r);
signals:
void beingDeleted();
void optimumRectChanged();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment