From fe12f71b93fe377cea5a7055395fe637ae316326 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sun, 27 Jul 2014 00:26:12 +0200 Subject: [PATCH] Disable some usercontextmenu actions if the user is offline; fix #234 --- cockatrice/src/playerlistwidget.cpp | 2 +- cockatrice/src/user_context_menu.cpp | 7 ++++--- cockatrice/src/user_context_menu.h | 2 +- cockatrice/src/userlist.cpp | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cockatrice/src/playerlistwidget.cpp b/cockatrice/src/playerlistwidget.cpp index ee088203..b535c2c1 100644 --- a/cockatrice/src/playerlistwidget.cpp +++ b/cockatrice/src/playerlistwidget.cpp @@ -178,5 +178,5 @@ void PlayerListWidget::showContextMenu(const QPoint &pos, const QModelIndex &ind int playerId = index.sibling(index.row(), 4).data(Qt::UserRole + 1).toInt(); UserLevelFlags userLevel(index.sibling(index.row(), 3).data(Qt::UserRole).toInt()); - userContextMenu->showContextMenu(pos, userName, userLevel, playerId); + userContextMenu->showContextMenu(pos, userName, userLevel, true, playerId); } diff --git a/cockatrice/src/user_context_menu.cpp b/cockatrice/src/user_context_menu.cpp index eab48f47..03ccdd37 100644 --- a/cockatrice/src/user_context_menu.cpp +++ b/cockatrice/src/user_context_menu.cpp @@ -102,7 +102,7 @@ void UserContextMenu::banUser_dialogFinished() client->sendCommand(client->prepareModeratorCommand(cmd)); } -void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName, UserLevelFlags userLevel, int playerId) +void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName, UserLevelFlags userLevel, bool online, int playerId) { aUserName->setText(userName); @@ -132,8 +132,9 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName menu->addAction(aBan); } bool anotherUser = userName != QString::fromStdString(tabSupervisor->getUserInfo()->name()); - aChat->setEnabled(anotherUser); - aShowGames->setEnabled(anotherUser); + aDetails->setEnabled(online); + aChat->setEnabled(anotherUser && online); + aShowGames->setEnabled(anotherUser && online); aAddToBuddyList->setEnabled(anotherUser); aRemoveFromBuddyList->setEnabled(anotherUser); aAddToIgnoreList->setEnabled(anotherUser); diff --git a/cockatrice/src/user_context_menu.h b/cockatrice/src/user_context_menu.h index 8e6708b0..9aeadfd4 100644 --- a/cockatrice/src/user_context_menu.h +++ b/cockatrice/src/user_context_menu.h @@ -36,7 +36,7 @@ private slots: public: UserContextMenu(const TabSupervisor *_tabSupervisor, QWidget *_parent, TabGame *_game = 0); void retranslateUi(); - void showContextMenu(const QPoint &pos, const QString &userName, UserLevelFlags userLevel, int playerId = -1); + void showContextMenu(const QPoint &pos, const QString &userName, UserLevelFlags userLevel, bool online = true, int playerId = -1); }; #endif diff --git a/cockatrice/src/userlist.cpp b/cockatrice/src/userlist.cpp index 29d13781..c6174a6e 100644 --- a/cockatrice/src/userlist.cpp +++ b/cockatrice/src/userlist.cpp @@ -311,8 +311,9 @@ void UserList::userClicked(QTreeWidgetItem *item, int /*column*/) void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index) { const ServerInfo_User &userInfo = static_cast(userTree->topLevelItem(index.row()))->getUserInfo(); - - userContextMenu->showContextMenu(pos, QString::fromStdString(userInfo.name()), UserLevelFlags(userInfo.user_level())); + bool online = index.sibling(index.row(), 0).data(Qt::UserRole + 1).toBool(); + + userContextMenu->showContextMenu(pos, QString::fromStdString(userInfo.name()), UserLevelFlags(userInfo.user_level()), online); } void UserList::sortItems()