diff --git a/cockatrice/src/client/tabs/tab_account.cpp b/cockatrice/src/client/tabs/tab_account.cpp index 30574c58e..54058e779 100644 --- a/cockatrice/src/client/tabs/tab_account.cpp +++ b/cockatrice/src/client/tabs/tab_account.cpp @@ -21,8 +21,8 @@ TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_client, - const ServerInfo_User &userInfo, - UserListManager *_userListManager) + UserListManager *_userListManager, + const ServerInfo_User &userInfo) : Tab(_tabSupervisor), client(_client), userListManager(_userListManager) { userInfoBox = new UserInfoBox(client, true); @@ -88,8 +88,7 @@ void TabUserLists::addToBuddyList() if (userName.length() < 1) return; - std::string listName = "buddy"; - userListManager->addToList(listName, userName); + userListManager->addToList("buddy", userName); addBuddyEdit->clear(); } @@ -99,8 +98,7 @@ void TabUserLists::addToIgnoreList() if (userName.length() < 1) return; - std::string listName = "ignore"; - userListManager->addToList(listName, userName); + userListManager->addToList("ignore", userName); addIgnoreEdit->clear(); } diff --git a/cockatrice/src/client/tabs/tab_account.h b/cockatrice/src/client/tabs/tab_account.h index 2060f3d1e..47d150b8f 100644 --- a/cockatrice/src/client/tabs/tab_account.h +++ b/cockatrice/src/client/tabs/tab_account.h @@ -36,8 +36,8 @@ private: public: TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_client, - const ServerInfo_User &userInfo, - UserListManager *_userListManager); + UserListManager *_userListManager, + const ServerInfo_User &userInfo); void retranslateUi() override; QString getTabText() const override { diff --git a/cockatrice/src/client/tabs/tab_supervisor.cpp b/cockatrice/src/client/tabs/tab_supervisor.cpp index d7f7f5c6f..45e222fd0 100644 --- a/cockatrice/src/client/tabs/tab_supervisor.cpp +++ b/cockatrice/src/client/tabs/tab_supervisor.cpp @@ -431,7 +431,7 @@ void TabSupervisor::actTabServer(bool checked) void TabSupervisor::actTabUserLists(bool checked) { 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(userListManager, &UserListManager::userJoined, this, &TabSupervisor::processUserJoined); connect(userListManager, &UserListManager::userLeft, this, &TabSupervisor::processUserLeft); diff --git a/cockatrice/src/client/user_list_manager.cpp b/cockatrice/src/client/user_list_manager.cpp index 590439cb1..5a47d3d03 100644 --- a/cockatrice/src/client/user_list_manager.cpp +++ b/cockatrice/src/client/user_list_manager.cpp @@ -14,12 +14,11 @@ #include "trice_limits.h" 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::userLeftEventReceived, this, &UserListManager::processUserLeftEvent); connect(client, &AbstractClient::buddyListReceived, this, &UserListManager::buddyListReceived); @@ -30,17 +29,15 @@ UserListManager::UserListManager(TabSupervisor *_tabSupervisor, AbstractClient * void UserListManager::handleConnect() { - } void UserListManager::handleDisconnect() { - } 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(); for (int i = 0; i < userListSize; ++i) { @@ -58,8 +55,8 @@ void UserListManager::processListUsersResponse(const Response &response) void UserListManager::processUserJoinedEvent(const Event_UserJoined &event) { - const ServerInfo_User &info = event.user_info(); - const QString userName = QString::fromStdString(info.name()); + const auto &info = event.user_info(); + const auto &userName = QString::fromStdString(info.name()); allUsersList->processUserInfo(info, true); ignoreList->setUserOnline(userName, true); @@ -78,7 +75,7 @@ void UserListManager::processUserJoinedEvent(const Event_UserJoined &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)) { soundEngine->playSound("buddy_leave"); @@ -96,25 +93,25 @@ void UserListManager::processUserLeftEvent(const Event_UserLeft &event) void UserListManager::buddyListReceived(const QList &_buddyList) { - for (int i = 0; i < _buddyList.size(); ++i) { - buddyList->processUserInfo(_buddyList[i], false); + for (const auto &buddyUser : _buddyList) { + buddyList->processUserInfo(buddyUser, false); } buddyList->sortItems(); } void UserListManager::ignoreListReceived(const QList &_ignoreList) { - for (int i = 0; i < _ignoreList.size(); ++i) { - ignoreList->processUserInfo(_ignoreList[i], false); + for (const auto &ignoredUser : _ignoreList) { + ignoreList->processUserInfo(ignoredUser, false); } ignoreList->sortItems(); } void UserListManager::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()); + const auto &info = event.user_info(); + const auto online = allUsersList->getUsers().contains(QString::fromStdString(info.name())); + const auto &list = QString::fromStdString(event.list_name()); UserList *userList = nullptr; if (list == "buddy") { @@ -133,8 +130,8 @@ void UserListManager::processAddToListEvent(const Event_AddToList &event) void UserListManager::processRemoveFromListEvent(const Event_RemoveFromList &event) { - QString list = QString::fromStdString(event.list_name()); - QString user = QString::fromStdString(event.user_name()); + const auto &list = QString::fromStdString(event.list_name()); + const auto &user = QString::fromStdString(event.user_name()); UserList *userList = nullptr; if (list == "buddy") { @@ -150,10 +147,10 @@ void UserListManager::processRemoveFromListEvent(const Event_RemoveFromList &eve 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; - cmd.set_list(listName); + cmd.set_list(listName.toStdString()); cmd.set_user_name(userName.toStdString()); client->sendCommand(client->prepareSessionCommand(cmd)); diff --git a/cockatrice/src/client/user_list_manager.h b/cockatrice/src/client/user_list_manager.h index 987dd61fa..117a61c58 100644 --- a/cockatrice/src/client/user_list_manager.h +++ b/cockatrice/src/client/user_list_manager.h @@ -11,11 +11,9 @@ class Event_ListRooms; class Event_RemoveFromList; class Event_UserJoined; class Event_UserLeft; -class LineEditUnfocusable; class Response; class ServerInfo_User; class TabSupervisor; -class UserInfoBox; class UserList; class UserListManager : public QWidget @@ -56,7 +54,7 @@ public slots: void handleConnect(); void handleDisconnect(); void processListUsersResponse(const Response &response); - void addToList(const std::string &listName, const QString &userName); + void addToList(const QString &listName, const QString &userName); signals: void userLeft(const QString &userName);