Files
Cockatrice/cockatrice/src/client/tabs/tab_account.cpp
LunaticCat fa999880ee Major Directory Refactoring (#5118)
* refactored cardzone.cpp, added doc and changed if to switch case

* started moving every files into different folders

* remove undercase to match with other files naming convention

* refactored dialog files

* ran format.sh

* refactored client/tabs folder

* refactored client/tabs folder

* refactored client/tabs folder

* refactored client folder

* refactored carddbparser

* refactored dialogs

* Create sonar-project.properties

temporary file for lint

* Create build.yml

temporary file for lint

* removed all files from root directory

* removed all files from root directory

* added current branch to workflow

* fixed most broken import

* fixed issues while renaming files

* fixed oracle importer

* fixed dbconverter

* updated translations

* made sub-folders for client

* removed linter

* removed linter folder

* fixed oracle import

* revert card_zone documentation

* renamed db parser files name and deck_view imports

* fixed dlg file issue

* ran format file and fixed test file

* fixed carddb test files

* moved player folder in game

* updated translations and format files

* fixed peglib import

* format cmake files

* removing vcpkg to try to add it back later

* tried fixing vcpkg file

* renamed filter to filters and moved database parser to cards folder

* reverted translation files

* reverted oracle translated

* Update cockatrice/src/dialogs/dlg_register.cpp

Co-authored-by: tooomm <tooomm@users.noreply.github.com>

* Update cockatrice/src/client/ui/window_main.cpp

Co-authored-by: tooomm <tooomm@users.noreply.github.com>

* removed empty line at file start

* removed useless include from tab_supervisor.cpp

* refactored cardzone.cpp, added doc and changed if to switch case

* started moving every files into different folders

* remove undercase to match with other files naming convention

* refactored dialog files

* ran format.sh

* refactored client/tabs folder

* refactored client folder

* refactored carddbparser

* refactored dialogs

* removed all files from root directory

* Create sonar-project.properties

temporary file for lint

* Create build.yml

temporary file for lint

* added current branch to workflow

* fixed most broken import

* fixed issues while renaming files

* fixed oracle importer

* fixed dbconverter

* updated translations

* made sub-folders for client

* removed linter

* removed linter folder

* fixed oracle import

* revert card_zone documentation

* renamed db parser files name and deck_view imports

* fixed dlg file issue

* ran format file and fixed test file

* fixed carddb test files

* moved player folder in game

* updated translations and format files

* fixed peglib import

* reverted translation files

* format cmake files

* removing vcpkg to try to add it back later

* tried fixing vcpkg file

* pre-updating of cockatrice changes

* removed empty line at file start

* reverted oracle translated

* Update cockatrice/src/dialogs/dlg_register.cpp

Co-authored-by: tooomm <tooomm@users.noreply.github.com>

* Update cockatrice/src/client/ui/window_main.cpp

Co-authored-by: tooomm <tooomm@users.noreply.github.com>

* removed useless include from tab_supervisor.cpp

---------

Co-authored-by: tooomm <tooomm@users.noreply.github.com>
2024-10-20 10:11:35 -04:00

239 lines
8.3 KiB
C++

#include "tab_account.h"
#include "../../deck/custom_line_edit.h"
#include "../../server/pending_command.h"
#include "../../server/user/user_info_box.h"
#include "../../server/user/user_list.h"
#include "../game_logic/abstract_client.h"
#include "../sound_engine.h"
#include "pb/event_add_to_list.pb.h"
#include "pb/event_remove_from_list.pb.h"
#include "pb/event_user_joined.pb.h"
#include "pb/event_user_left.pb.h"
#include "pb/response_list_users.pb.h"
#include "pb/session_commands.pb.h"
#include "trice_limits.h"
#include <QHBoxLayout>
#include <QPushButton>
#include <QVBoxLayout>
TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor,
AbstractClient *_client,
const ServerInfo_User &userInfo,
QWidget *parent)
: Tab(_tabSupervisor, parent), client(_client)
{
allUsersList = new UserList(_tabSupervisor, client, UserList::AllUsersList);
buddyList = new UserList(_tabSupervisor, client, UserList::BuddyList);
ignoreList = new UserList(_tabSupervisor, client, UserList::IgnoreList);
userInfoBox = new UserInfoBox(client, true);
userInfoBox->updateInfo(userInfo);
connect(allUsersList, 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(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(Response, CommandContainer, QVariant)), this,
SLOT(processListUsersResponse(const Response &)));
client->sendCommand(pend);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(userInfoBox);
vbox->addWidget(allUsersList);
QHBoxLayout *addToBuddyList = new QHBoxLayout;
addBuddyEdit = new LineEditUnfocusable;
addBuddyEdit->setMaxLength(MAX_NAME_LENGTH);
addBuddyEdit->setPlaceholderText(tr("Add to Buddy List"));
connect(addBuddyEdit, SIGNAL(returnPressed()), this, SLOT(addToBuddyList()));
QPushButton *addBuddyButton = new QPushButton("Add");
connect(addBuddyButton, SIGNAL(clicked()), this, SLOT(addToBuddyList()));
addToBuddyList->addWidget(addBuddyEdit);
addToBuddyList->addWidget(addBuddyButton);
QHBoxLayout *addToIgnoreList = new QHBoxLayout;
addIgnoreEdit = new LineEditUnfocusable;
addIgnoreEdit->setMaxLength(MAX_NAME_LENGTH);
addIgnoreEdit->setPlaceholderText(tr("Add to Ignore List"));
connect(addIgnoreEdit, SIGNAL(returnPressed()), this, SLOT(addToIgnoreList()));
QPushButton *addIgnoreButton = new QPushButton("Add");
connect(addIgnoreButton, SIGNAL(clicked()), this, SLOT(addToIgnoreList()));
addToIgnoreList->addWidget(addIgnoreEdit);
addToIgnoreList->addWidget(addIgnoreButton);
QVBoxLayout *buddyPanel = new QVBoxLayout;
buddyPanel->addWidget(buddyList);
buddyPanel->addLayout(addToBuddyList);
QVBoxLayout *ignorePanel = new QVBoxLayout;
ignorePanel->addWidget(ignoreList);
ignorePanel->addLayout(addToIgnoreList);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(buddyPanel);
mainLayout->addLayout(ignorePanel);
mainLayout->addLayout(vbox);
retranslateUi();
QWidget *mainWidget = new QWidget(this);
mainWidget->setLayout(mainLayout);
setCentralWidget(mainWidget);
}
void TabUserLists::addToBuddyList()
{
QString userName = addBuddyEdit->text();
if (userName.length() < 1)
return;
std::string listName = "buddy";
addToList(listName, userName);
addBuddyEdit->clear();
}
void TabUserLists::addToIgnoreList()
{
QString userName = addIgnoreEdit->text();
if (userName.length() < 1)
return;
std::string listName = "ignore";
addToList(listName, userName);
addIgnoreEdit->clear();
}
void TabUserLists::addToList(const std::string &listName, const QString &userName)
{
Command_AddToList cmd;
cmd.set_list(listName);
cmd.set_user_name(userName.toStdString());
client->sendCommand(client->prepareSessionCommand(cmd));
}
void TabUserLists::retranslateUi()
{
allUsersList->retranslateUi();
buddyList->retranslateUi();
ignoreList->retranslateUi();
userInfoBox->retranslateUi();
}
void TabUserLists::processListUsersResponse(const Response &response)
{
const Response_ListUsers &resp = response.GetExtension(Response_ListUsers::ext);
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();
ignoreList->sortItems();
buddyList->sortItems();
}
void TabUserLists::processUserJoinedEvent(const Event_UserJoined &event)
{
const ServerInfo_User &info = event.user_info();
const QString userName = QString::fromStdString(info.name());
allUsersList->processUserInfo(info, true);
ignoreList->setUserOnline(userName, true);
buddyList->setUserOnline(userName, true);
allUsersList->sortItems();
ignoreList->sortItems();
buddyList->sortItems();
if (buddyList->getUsers().keys().contains(userName))
soundEngine->playSound("buddy_join");
emit userJoined(info);
}
void TabUserLists::processUserLeftEvent(const Event_UserLeft &event)
{
QString userName = QString::fromStdString(event.name());
if (buddyList->getUsers().keys().contains(userName))
soundEngine->playSound("buddy_leave");
if (allUsersList->deleteUser(userName)) {
ignoreList->setUserOnline(userName, false);
buddyList->setUserOnline(userName, false);
ignoreList->sortItems();
buddyList->sortItems();
emit userLeft(userName);
}
}
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)
{
for (int i = 0; i < _ignoreList.size(); ++i)
ignoreList->processUserInfo(_ignoreList[i], false);
ignoreList->sortItems();
}
void TabUserLists::processAddToListEvent(const Event_AddToList &event)
{
const ServerInfo_User &info = event.user_info();
bool online = allUsersList->getUsers().contains(QString::fromStdString(info.name()));
QString list = QString::fromStdString(event.list_name());
UserList *userList = 0;
if (list == "buddy")
userList = buddyList;
else if (list == "ignore")
userList = ignoreList;
if (!userList)
return;
userList->processUserInfo(info, online);
userList->sortItems();
}
void TabUserLists::processRemoveFromListEvent(const Event_RemoveFromList &event)
{
QString list = QString::fromStdString(event.list_name());
QString user = QString::fromStdString(event.user_name());
UserList *userList = 0;
if (list == "buddy")
userList = buddyList;
else if (list == "ignore")
userList = ignoreList;
if (!userList)
return;
userList->deleteUser(user);
}