Small Cleanup

This commit is contained in:
ZeldaZach 2025-01-14 00:31:19 -05:00
parent a0c26b9985
commit 63c9cbcf12
No known key found for this signature in database
5 changed files with 27 additions and 34 deletions

View file

@ -21,8 +21,8 @@
TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor, TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor,
AbstractClient *_client, AbstractClient *_client,
const ServerInfo_User &userInfo, UserListManager *_userListManager,
UserListManager *_userListManager) const ServerInfo_User &userInfo)
: Tab(_tabSupervisor), client(_client), userListManager(_userListManager) : Tab(_tabSupervisor), client(_client), userListManager(_userListManager)
{ {
userInfoBox = new UserInfoBox(client, true); userInfoBox = new UserInfoBox(client, true);
@ -88,8 +88,7 @@ void TabUserLists::addToBuddyList()
if (userName.length() < 1) if (userName.length() < 1)
return; return;
std::string listName = "buddy"; userListManager->addToList("buddy", userName);
userListManager->addToList(listName, userName);
addBuddyEdit->clear(); addBuddyEdit->clear();
} }
@ -99,8 +98,7 @@ void TabUserLists::addToIgnoreList()
if (userName.length() < 1) if (userName.length() < 1)
return; return;
std::string listName = "ignore"; userListManager->addToList("ignore", userName);
userListManager->addToList(listName, userName);
addIgnoreEdit->clear(); addIgnoreEdit->clear();
} }

View file

@ -36,8 +36,8 @@ private:
public: public:
TabUserLists(TabSupervisor *_tabSupervisor, TabUserLists(TabSupervisor *_tabSupervisor,
AbstractClient *_client, AbstractClient *_client,
const ServerInfo_User &userInfo, UserListManager *_userListManager,
UserListManager *_userListManager); const ServerInfo_User &userInfo);
void retranslateUi() override; void retranslateUi() override;
QString getTabText() const override QString getTabText() const override
{ {

View file

@ -431,7 +431,7 @@ void TabSupervisor::actTabServer(bool checked)
void TabSupervisor::actTabUserLists(bool checked) void TabSupervisor::actTabUserLists(bool checked)
{ {
if (checked && !tabUserLists) { if (checked && !tabUserLists) {
tabUserLists = new TabUserLists(this, client, *userInfo, userListManager); tabUserLists = new TabUserLists(this, client, userListManager, *userInfo);
connect(tabUserLists, &TabUserLists::openMessageDialog, this, &TabSupervisor::addMessageTab); connect(tabUserLists, &TabUserLists::openMessageDialog, this, &TabSupervisor::addMessageTab);
connect(userListManager, &UserListManager::userJoined, this, &TabSupervisor::processUserJoined); connect(userListManager, &UserListManager::userJoined, this, &TabSupervisor::processUserJoined);
connect(userListManager, &UserListManager::userLeft, this, &TabSupervisor::processUserLeft); connect(userListManager, &UserListManager::userLeft, this, &TabSupervisor::processUserLeft);

View file

@ -14,12 +14,11 @@
#include "trice_limits.h" #include "trice_limits.h"
UserListManager::UserListManager(TabSupervisor *_tabSupervisor, AbstractClient *_client) UserListManager::UserListManager(TabSupervisor *_tabSupervisor, AbstractClient *_client)
: client(_client), tabSupervisor(_tabSupervisor) : client(_client), tabSupervisor(_tabSupervisor),
allUsersList(new UserList(tabSupervisor, client, UserList::AllUsersList)),
buddyList(new UserList(tabSupervisor, client, UserList::BuddyList)),
ignoreList(new UserList(tabSupervisor, client, UserList::IgnoreList))
{ {
allUsersList = new UserList(_tabSupervisor, _client, UserList::AllUsersList);
buddyList = new UserList(_tabSupervisor, _client, UserList::BuddyList);
ignoreList = new UserList(_tabSupervisor, _client, UserList::IgnoreList);
connect(client, &AbstractClient::userJoinedEventReceived, this, &UserListManager::processUserJoinedEvent); connect(client, &AbstractClient::userJoinedEventReceived, this, &UserListManager::processUserJoinedEvent);
connect(client, &AbstractClient::userLeftEventReceived, this, &UserListManager::processUserLeftEvent); connect(client, &AbstractClient::userLeftEventReceived, this, &UserListManager::processUserLeftEvent);
connect(client, &AbstractClient::buddyListReceived, this, &UserListManager::buddyListReceived); connect(client, &AbstractClient::buddyListReceived, this, &UserListManager::buddyListReceived);
@ -30,17 +29,15 @@ UserListManager::UserListManager(TabSupervisor *_tabSupervisor, AbstractClient *
void UserListManager::handleConnect() void UserListManager::handleConnect()
{ {
} }
void UserListManager::handleDisconnect() void UserListManager::handleDisconnect()
{ {
} }
void UserListManager::processListUsersResponse(const Response &response) void UserListManager::processListUsersResponse(const Response &response)
{ {
const Response_ListUsers &resp = response.GetExtension(Response_ListUsers::ext); const auto &resp = response.GetExtension(Response_ListUsers::ext);
const int userListSize = resp.user_list_size(); const int userListSize = resp.user_list_size();
for (int i = 0; i < userListSize; ++i) { for (int i = 0; i < userListSize; ++i) {
@ -58,8 +55,8 @@ void UserListManager::processListUsersResponse(const Response &response)
void UserListManager::processUserJoinedEvent(const Event_UserJoined &event) void UserListManager::processUserJoinedEvent(const Event_UserJoined &event)
{ {
const ServerInfo_User &info = event.user_info(); const auto &info = event.user_info();
const QString userName = QString::fromStdString(info.name()); const auto &userName = QString::fromStdString(info.name());
allUsersList->processUserInfo(info, true); allUsersList->processUserInfo(info, true);
ignoreList->setUserOnline(userName, true); ignoreList->setUserOnline(userName, true);
@ -78,7 +75,7 @@ void UserListManager::processUserJoinedEvent(const Event_UserJoined &event)
void UserListManager::processUserLeftEvent(const Event_UserLeft &event) void UserListManager::processUserLeftEvent(const Event_UserLeft &event)
{ {
QString userName = QString::fromStdString(event.name()); const auto &userName = QString::fromStdString(event.name());
if (buddyList->getUsers().keys().contains(userName)) { if (buddyList->getUsers().keys().contains(userName)) {
soundEngine->playSound("buddy_leave"); soundEngine->playSound("buddy_leave");
@ -96,25 +93,25 @@ void UserListManager::processUserLeftEvent(const Event_UserLeft &event)
void UserListManager::buddyListReceived(const QList<ServerInfo_User> &_buddyList) void UserListManager::buddyListReceived(const QList<ServerInfo_User> &_buddyList)
{ {
for (int i = 0; i < _buddyList.size(); ++i) { for (const auto &buddyUser : _buddyList) {
buddyList->processUserInfo(_buddyList[i], false); buddyList->processUserInfo(buddyUser, false);
} }
buddyList->sortItems(); buddyList->sortItems();
} }
void UserListManager::ignoreListReceived(const QList<ServerInfo_User> &_ignoreList) void UserListManager::ignoreListReceived(const QList<ServerInfo_User> &_ignoreList)
{ {
for (int i = 0; i < _ignoreList.size(); ++i) { for (const auto &ignoredUser : _ignoreList) {
ignoreList->processUserInfo(_ignoreList[i], false); ignoreList->processUserInfo(ignoredUser, false);
} }
ignoreList->sortItems(); ignoreList->sortItems();
} }
void UserListManager::processAddToListEvent(const Event_AddToList &event) void UserListManager::processAddToListEvent(const Event_AddToList &event)
{ {
const ServerInfo_User &info = event.user_info(); const auto &info = event.user_info();
bool online = allUsersList->getUsers().contains(QString::fromStdString(info.name())); const auto online = allUsersList->getUsers().contains(QString::fromStdString(info.name()));
QString list = QString::fromStdString(event.list_name()); const auto &list = QString::fromStdString(event.list_name());
UserList *userList = nullptr; UserList *userList = nullptr;
if (list == "buddy") { if (list == "buddy") {
@ -133,8 +130,8 @@ void UserListManager::processAddToListEvent(const Event_AddToList &event)
void UserListManager::processRemoveFromListEvent(const Event_RemoveFromList &event) void UserListManager::processRemoveFromListEvent(const Event_RemoveFromList &event)
{ {
QString list = QString::fromStdString(event.list_name()); const auto &list = QString::fromStdString(event.list_name());
QString user = QString::fromStdString(event.user_name()); const auto &user = QString::fromStdString(event.user_name());
UserList *userList = nullptr; UserList *userList = nullptr;
if (list == "buddy") { if (list == "buddy") {
@ -150,10 +147,10 @@ void UserListManager::processRemoveFromListEvent(const Event_RemoveFromList &eve
userList->deleteUser(user); userList->deleteUser(user);
} }
void UserListManager::addToList(const std::string &listName, const QString &userName) void UserListManager::addToList(const QString &listName, const QString &userName)
{ {
Command_AddToList cmd; Command_AddToList cmd;
cmd.set_list(listName); cmd.set_list(listName.toStdString());
cmd.set_user_name(userName.toStdString()); cmd.set_user_name(userName.toStdString());
client->sendCommand(client->prepareSessionCommand(cmd)); client->sendCommand(client->prepareSessionCommand(cmd));

View file

@ -11,11 +11,9 @@ class Event_ListRooms;
class Event_RemoveFromList; class Event_RemoveFromList;
class Event_UserJoined; class Event_UserJoined;
class Event_UserLeft; class Event_UserLeft;
class LineEditUnfocusable;
class Response; class Response;
class ServerInfo_User; class ServerInfo_User;
class TabSupervisor; class TabSupervisor;
class UserInfoBox;
class UserList; class UserList;
class UserListManager : public QWidget class UserListManager : public QWidget
@ -56,7 +54,7 @@ public slots:
void handleConnect(); void handleConnect();
void handleDisconnect(); void handleDisconnect();
void processListUsersResponse(const Response &response); void processListUsersResponse(const Response &response);
void addToList(const std::string &listName, const QString &userName); void addToList(const QString &listName, const QString &userName);
signals: signals:
void userLeft(const QString &userName); void userLeft(const QString &userName);