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 UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName, UserLevelFlags userLevel, bool online, int playerId) { aUserName->setText(userName); QMenu *menu = new QMenu(static_cast<QWidget *>(parent())); menu->addAction(aUserName); menu->addSeparator(); menu->addAction(aDetails); menu->addAction(aShowGames); menu->addAction(aChat); if (userLevel.testFlag(ServerInfo_User::IsRegistered) && (tabSupervisor->getUserInfo()->user_level() & ServerInfo_User::IsRegistered)) { menu->addSeparator(); if (tabSupervisor->getUserListsTab()->getBuddyList()->getUsers().contains(userName)) menu->addAction(aRemoveFromBuddyList); else menu->addAction(aAddToBuddyList); if (tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(userName)) menu->addAction(aRemoveFromIgnoreList); else menu->addAction(aAddToIgnoreList); } if (game && (game->isHost() || !tabSupervisor->getAdminLocked())) { menu->addSeparator(); menu->addAction(aKick); } if (!tabSupervisor->getAdminLocked()) { menu->addSeparator(); menu->addAction(aBan); } bool anotherUser = userName != QString::fromStdString(tabSupervisor->getUserInfo()->name()); aDetails->setEnabled(online); aChat->setEnabled(anotherUser && online); aShowGames->setEnabled(anotherUser); aAddToBuddyList->setEnabled(anotherUser); aRemoveFromBuddyList->setEnabled(anotherUser); aAddToIgnoreList->setEnabled(anotherUser); aRemoveFromIgnoreList->setEnabled(anotherUser); aKick->setEnabled(anotherUser); aBan->setEnabled(anotherUser); QAction *actionClicked = menu->exec(pos); if (actionClicked == aDetails) { UserInfoBox *infoWidget = new UserInfoBox(client, false, static_cast<QWidget *>(parent()), Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint); infoWidget->setAttribute(Qt::WA_DeleteOnClose); infoWidget->updateInfo(userName); } else if (actionClicked == aChat) emit openMessageDialog(userName, true); else if (actionClicked == aShowGames) { Command_GetGamesOfUser cmd; cmd.set_user_name(userName.toStdString()); PendingCommand *pend = client->prepareSessionCommand(cmd); connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(gamesOfUserReceived(Response, CommandContainer))); client->sendCommand(pend); } else if (actionClicked == aAddToBuddyList) { Command_AddToList cmd; cmd.set_list("buddy"); cmd.set_user_name(userName.toStdString()); client->sendCommand(client->prepareSessionCommand(cmd)); } else if (actionClicked == aRemoveFromBuddyList) { Command_RemoveFromList cmd; cmd.set_list("buddy"); cmd.set_user_name(userName.toStdString()); client->sendCommand(client->prepareSessionCommand(cmd)); } else if (actionClicked == aAddToIgnoreList) { Command_AddToList cmd; cmd.set_list("ignore"); cmd.set_user_name(userName.toStdString()); client->sendCommand(client->prepareSessionCommand(cmd)); } else if (actionClicked == aRemoveFromIgnoreList) { Command_RemoveFromList cmd; cmd.set_list("ignore"); cmd.set_user_name(userName.toStdString()); client->sendCommand(client->prepareSessionCommand(cmd)); } else if (actionClicked == aKick) { Command_KickFromGame cmd; cmd.set_player_id(playerId); game->sendGameCommand(cmd); } else if (actionClicked == aBan) { Command_GetUserInfo cmd; cmd.set_user_name(userName.toStdString()); PendingCommand *pend = client->prepareSessionCommand(cmd); connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(banUser_processUserInfoResponse(Response))); client->sendCommand(pend); } delete menu; }