Reduce TabSupervisor direct usage in UserContextMenu
This commit is contained in:
parent
c5aa75d4d1
commit
a3f4012d1a
5 changed files with 25 additions and 7 deletions
|
@ -9,8 +9,10 @@ class ServerInfo_User;
|
|||
*/
|
||||
class UserlistProxy {
|
||||
public:
|
||||
virtual const bool isOwnUserRegistered() const = 0;
|
||||
virtual const QString getOwnUsername() const = 0;
|
||||
virtual bool isUserBuddy(const QString &userName) const = 0;
|
||||
virtual bool isUserIgnored(const QString &userName) const = 0;
|
||||
virtual const ServerInfo_User* getOnlineUser(const QString &userName) const = 0; // Can return nullptr
|
||||
};
|
||||
|
||||
|
|
|
@ -25,8 +25,7 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup
|
|||
gameListModel = new GamesModel(_rooms, _gameTypes, this);
|
||||
if(showfilters)
|
||||
{
|
||||
bool ownUserIsRegistered = (bool)(tabSupervisor->getUserInfo()->user_level() & ServerInfo_User::IsRegistered);
|
||||
gameListProxyModel = new GamesProxyModel(this, ownUserIsRegistered);
|
||||
gameListProxyModel = new GamesProxyModel(this, tabSupervisor->isOwnUserRegistered());
|
||||
gameListProxyModel->setSourceModel(gameListModel);
|
||||
gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
gameListView->setModel(gameListProxyModel);
|
||||
|
|
|
@ -605,6 +605,12 @@ void TabSupervisor::processNotifyUserEvent(const Event_NotifyUser &event)
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
const bool TabSupervisor::isOwnUserRegistered() const
|
||||
{
|
||||
return (bool) getUserInfo()->user_level() & ServerInfo_User::IsRegistered;
|
||||
}
|
||||
|
||||
const QString TabSupervisor::getOwnUsername() const
|
||||
{
|
||||
return QString::fromStdString(userInfo->name());
|
||||
|
@ -619,6 +625,15 @@ bool TabSupervisor::isUserBuddy(const QString &userName) const
|
|||
return senderIsBuddy;
|
||||
}
|
||||
|
||||
bool TabSupervisor::isUserIgnored(const QString &userName) const
|
||||
{
|
||||
if (!getUserListsTab()) return false;
|
||||
if (!getUserListsTab()->getIgnoreList()) return false;
|
||||
QMap<QString, UserListTWI *> buddyList = getUserListsTab()->getIgnoreList()->getUsers();
|
||||
bool senderIsBuddy = buddyList.contains(userName);
|
||||
return senderIsBuddy;
|
||||
}
|
||||
|
||||
const ServerInfo_User * TabSupervisor::getOnlineUser(const QString &userName) const
|
||||
{
|
||||
if (!getUserListsTab()) return nullptr;
|
||||
|
|
|
@ -79,8 +79,10 @@ public:
|
|||
const QMap<int, TabRoom *> &getRoomTabs() const { return roomTabs; }
|
||||
bool getAdminLocked() const;
|
||||
bool closeRequest();
|
||||
const bool isOwnUserRegistered() const;
|
||||
const QString getOwnUsername() const;
|
||||
bool isUserBuddy(const QString &userName) const;
|
||||
bool isUserIgnored(const QString &userName) const;
|
||||
const ServerInfo_User* getOnlineUser(const QString &userName) const;
|
||||
signals:
|
||||
void setMenu(const QList<QMenu *> &newMenuList = QList<QMenu *>());
|
||||
|
|
|
@ -245,7 +245,7 @@ void UserContextMenu::warnUser_dialogFinished()
|
|||
{
|
||||
WarningDialog *dlg = static_cast<WarningDialog *>(sender());
|
||||
|
||||
if (dlg->getName().isEmpty() || QString::fromStdString(tabSupervisor->getUserInfo()->name()).simplified().isEmpty())
|
||||
if (dlg->getName().isEmpty() || tabSupervisor->getOwnUsername().simplified().isEmpty())
|
||||
return;
|
||||
|
||||
Command_WarnUser cmd;
|
||||
|
@ -267,13 +267,13 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
|
|||
menu->addAction(aDetails);
|
||||
menu->addAction(aShowGames);
|
||||
menu->addAction(aChat);
|
||||
if (userLevel.testFlag(ServerInfo_User::IsRegistered) && (tabSupervisor->getUserInfo()->user_level() & ServerInfo_User::IsRegistered)) {
|
||||
if (userLevel.testFlag(ServerInfo_User::IsRegistered) && tabSupervisor->isOwnUserRegistered()) {
|
||||
menu->addSeparator();
|
||||
if (tabSupervisor->getUserListsTab()->getBuddyList()->getUsers().contains(userName))
|
||||
if (tabSupervisor->isUserBuddy(userName))
|
||||
menu->addAction(aRemoveFromBuddyList);
|
||||
else
|
||||
menu->addAction(aAddToBuddyList);
|
||||
if (tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(userName))
|
||||
if (tabSupervisor->isUserIgnored(userName))
|
||||
menu->addAction(aRemoveFromIgnoreList);
|
||||
else
|
||||
menu->addAction(aAddToIgnoreList);
|
||||
|
@ -298,7 +298,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
|
|||
menu->addAction(aPromoteToMod);
|
||||
}
|
||||
}
|
||||
bool anotherUser = userName != QString::fromStdString(tabSupervisor->getUserInfo()->name());
|
||||
bool anotherUser = userName != tabSupervisor->getOwnUsername();
|
||||
aDetails->setEnabled(true);
|
||||
aChat->setEnabled(anotherUser && online);
|
||||
aShowGames->setEnabled(online);
|
||||
|
|
Loading…
Reference in a new issue