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