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 {
|
class UserlistProxy {
|
||||||
public:
|
public:
|
||||||
|
virtual const bool isOwnUserRegistered() const = 0;
|
||||||
virtual const QString getOwnUsername() const = 0;
|
virtual const QString getOwnUsername() const = 0;
|
||||||
virtual bool isUserBuddy(const QString &userName) 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
|
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);
|
gameListModel = new GamesModel(_rooms, _gameTypes, this);
|
||||||
if(showfilters)
|
if(showfilters)
|
||||||
{
|
{
|
||||||
bool ownUserIsRegistered = (bool)(tabSupervisor->getUserInfo()->user_level() & ServerInfo_User::IsRegistered);
|
gameListProxyModel = new GamesProxyModel(this, tabSupervisor->isOwnUserRegistered());
|
||||||
gameListProxyModel = new GamesProxyModel(this, ownUserIsRegistered);
|
|
||||||
gameListProxyModel->setSourceModel(gameListModel);
|
gameListProxyModel->setSourceModel(gameListModel);
|
||||||
gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||||
gameListView->setModel(gameListProxyModel);
|
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
|
const QString TabSupervisor::getOwnUsername() const
|
||||||
{
|
{
|
||||||
return QString::fromStdString(userInfo->name());
|
return QString::fromStdString(userInfo->name());
|
||||||
|
@ -619,6 +625,15 @@ bool TabSupervisor::isUserBuddy(const QString &userName) const
|
||||||
return senderIsBuddy;
|
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
|
const ServerInfo_User * TabSupervisor::getOnlineUser(const QString &userName) const
|
||||||
{
|
{
|
||||||
if (!getUserListsTab()) return nullptr;
|
if (!getUserListsTab()) return nullptr;
|
||||||
|
|
|
@ -79,8 +79,10 @@ public:
|
||||||
const QMap<int, TabRoom *> &getRoomTabs() const { return roomTabs; }
|
const QMap<int, TabRoom *> &getRoomTabs() const { return roomTabs; }
|
||||||
bool getAdminLocked() const;
|
bool getAdminLocked() const;
|
||||||
bool closeRequest();
|
bool closeRequest();
|
||||||
|
const bool isOwnUserRegistered() const;
|
||||||
const QString getOwnUsername() const;
|
const QString getOwnUsername() const;
|
||||||
bool isUserBuddy(const QString &userName) const;
|
bool isUserBuddy(const QString &userName) const;
|
||||||
|
bool isUserIgnored(const QString &userName) const;
|
||||||
const ServerInfo_User* getOnlineUser(const QString &userName) const;
|
const ServerInfo_User* getOnlineUser(const QString &userName) const;
|
||||||
signals:
|
signals:
|
||||||
void setMenu(const QList<QMenu *> &newMenuList = QList<QMenu *>());
|
void setMenu(const QList<QMenu *> &newMenuList = QList<QMenu *>());
|
||||||
|
|
|
@ -245,7 +245,7 @@ void UserContextMenu::warnUser_dialogFinished()
|
||||||
{
|
{
|
||||||
WarningDialog *dlg = static_cast<WarningDialog *>(sender());
|
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;
|
return;
|
||||||
|
|
||||||
Command_WarnUser cmd;
|
Command_WarnUser cmd;
|
||||||
|
@ -267,13 +267,13 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
|
||||||
menu->addAction(aDetails);
|
menu->addAction(aDetails);
|
||||||
menu->addAction(aShowGames);
|
menu->addAction(aShowGames);
|
||||||
menu->addAction(aChat);
|
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();
|
menu->addSeparator();
|
||||||
if (tabSupervisor->getUserListsTab()->getBuddyList()->getUsers().contains(userName))
|
if (tabSupervisor->isUserBuddy(userName))
|
||||||
menu->addAction(aRemoveFromBuddyList);
|
menu->addAction(aRemoveFromBuddyList);
|
||||||
else
|
else
|
||||||
menu->addAction(aAddToBuddyList);
|
menu->addAction(aAddToBuddyList);
|
||||||
if (tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(userName))
|
if (tabSupervisor->isUserIgnored(userName))
|
||||||
menu->addAction(aRemoveFromIgnoreList);
|
menu->addAction(aRemoveFromIgnoreList);
|
||||||
else
|
else
|
||||||
menu->addAction(aAddToIgnoreList);
|
menu->addAction(aAddToIgnoreList);
|
||||||
|
@ -298,7 +298,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
|
||||||
menu->addAction(aPromoteToMod);
|
menu->addAction(aPromoteToMod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool anotherUser = userName != QString::fromStdString(tabSupervisor->getUserInfo()->name());
|
bool anotherUser = userName != tabSupervisor->getOwnUsername();
|
||||||
aDetails->setEnabled(true);
|
aDetails->setEnabled(true);
|
||||||
aChat->setEnabled(anotherUser && online);
|
aChat->setEnabled(anotherUser && online);
|
||||||
aShowGames->setEnabled(online);
|
aShowGames->setEnabled(online);
|
||||||
|
|
Loading…
Reference in a new issue