mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 02:53:56 -07:00
added option to ignore unregistered users in chat; switched UserList data storage to QMap to speed up lookups; issue #28 fixed
This commit is contained in:
parent
ff632911f2
commit
cdda3f15a0
10 changed files with 191 additions and 43 deletions
|
|
@ -183,11 +183,11 @@ void PlayerListWidget::showContextMenu(const QPoint &pos, const QModelIndex &ind
|
|||
menu->addAction(aChat);
|
||||
if ((userLevel & ServerInfo_User::IsRegistered) && (tabSupervisor->getUserLevel() & ServerInfo_User::IsRegistered)) {
|
||||
menu->addSeparator();
|
||||
if (tabSupervisor->getUserListsTab()->getBuddyList()->userInList(userName))
|
||||
if (tabSupervisor->getUserListsTab()->getBuddyList()->getUsers().contains(userName))
|
||||
menu->addAction(aRemoveFromBuddyList);
|
||||
else
|
||||
menu->addAction(aAddToBuddyList);
|
||||
if (tabSupervisor->getUserListsTab()->getIgnoreList()->userInList(userName))
|
||||
if (tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(userName))
|
||||
menu->addAction(aRemoveFromIgnoreList);
|
||||
else
|
||||
menu->addAction(aAddToIgnoreList);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ SettingsCache::SettingsCache()
|
|||
soundPath = settings->value("sound/path").toString();
|
||||
|
||||
priceTagFeature = settings->value("deckeditor/pricetags", false).toBool();
|
||||
|
||||
ignoreUnregisteredUsers = settings->value("chat/ignore_unregistered", false).toBool();
|
||||
}
|
||||
|
||||
void SettingsCache::setCustomTranslationFile(const QString &_customTranslationFile)
|
||||
|
|
@ -202,3 +204,10 @@ void SettingsCache::setPriceTagFeature(int _priceTagFeature)
|
|||
priceTagFeature = _priceTagFeature;
|
||||
settings->setValue("deckeditor/pricetags", priceTagFeature);
|
||||
}
|
||||
|
||||
void SettingsCache::setIgnoreUnregisteredUsers(bool _ignoreUnregisteredUsers)
|
||||
{
|
||||
ignoreUnregisteredUsers = _ignoreUnregisteredUsers;
|
||||
settings->setValue("chat/ignore_unregistered", ignoreUnregisteredUsers);
|
||||
emit ignoreUnregisteredUsersChanged();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ signals:
|
|||
void invertVerticalCoordinateChanged();
|
||||
void minPlayersForMultiColumnLayoutChanged();
|
||||
void soundPathChanged();
|
||||
void ignoreUnregisteredUsersChanged();
|
||||
private:
|
||||
QSettings *settings;
|
||||
|
||||
|
|
@ -42,6 +43,7 @@ private:
|
|||
bool soundEnabled;
|
||||
QString soundPath;
|
||||
bool priceTagFeature;
|
||||
bool ignoreUnregisteredUsers;
|
||||
public:
|
||||
SettingsCache();
|
||||
QString getCustomTranslationFile() const { return customTranslationFile; }
|
||||
|
|
@ -69,6 +71,7 @@ public:
|
|||
bool getSoundEnabled() const { return soundEnabled; }
|
||||
QString getSoundPath() const { return soundPath; }
|
||||
bool getPriceTagFeature() const { return priceTagFeature; }
|
||||
bool getIgnoreUnregisteredUsers() const { return ignoreUnregisteredUsers; }
|
||||
public slots:
|
||||
void setCustomTranslationFile(const QString &_customTranslationFile);
|
||||
void setLang(const QString &_lang);
|
||||
|
|
@ -95,6 +98,7 @@ public slots:
|
|||
void setSoundEnabled(int _soundEnabled);
|
||||
void setSoundPath(const QString &_soundPath);
|
||||
void setPriceTagFeature(int _priceTagFeature);
|
||||
void setIgnoreUnregisteredUsers(bool _ignoreUnregisteredUsers);
|
||||
};
|
||||
|
||||
extern SettingsCache *settingsCache;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <QMessageBox>
|
||||
#include <QCheckBox>
|
||||
#include <QLabel>
|
||||
#include <QToolButton>
|
||||
#include <QSplitter>
|
||||
#include "tab_supervisor.h"
|
||||
#include "tab_room.h"
|
||||
|
|
@ -15,6 +16,7 @@
|
|||
#include "abstractclient.h"
|
||||
#include "chatview.h"
|
||||
#include "gameselector.h"
|
||||
#include "settingscache.h"
|
||||
|
||||
#include "get_pb_extension.h"
|
||||
#include "pb/room_commands.pb.h"
|
||||
|
|
@ -46,9 +48,20 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerI
|
|||
sayLabel->setBuddy(sayEdit);
|
||||
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(sendMessage()));
|
||||
|
||||
QMenu *chatSettingsMenu = new QMenu(this);
|
||||
aIgnoreUnregisteredUsers = chatSettingsMenu->addAction(QString());
|
||||
aIgnoreUnregisteredUsers->setCheckable(true);
|
||||
connect(aIgnoreUnregisteredUsers, SIGNAL(triggered()), this, SLOT(actIgnoreUnregisteredUsers()));
|
||||
connect(settingsCache, SIGNAL(ignoreUnregisteredUsersChanged()), this, SLOT(ignoreUnregisteredUsersChanged()));
|
||||
QToolButton *chatSettingsButton = new QToolButton;
|
||||
chatSettingsButton->setIcon(QIcon(":/resources/icon_settings.svg"));
|
||||
chatSettingsButton->setMenu(chatSettingsMenu);
|
||||
chatSettingsButton->setPopupMode(QToolButton::InstantPopup);
|
||||
|
||||
QHBoxLayout *sayHbox = new QHBoxLayout;
|
||||
sayHbox->addWidget(sayLabel);
|
||||
sayHbox->addWidget(sayEdit);
|
||||
sayHbox->addWidget(chatSettingsButton);
|
||||
|
||||
QVBoxLayout *chatVbox = new QVBoxLayout;
|
||||
chatVbox->addWidget(chatView);
|
||||
|
|
@ -96,6 +109,7 @@ void TabRoom::retranslateUi()
|
|||
chatGroupBox->setTitle(tr("Chat"));
|
||||
tabMenu->setTitle(tr("&Room"));
|
||||
aLeaveRoom->setText(tr("&Leave room"));
|
||||
aIgnoreUnregisteredUsers->setText(tr("&Ignore unregistered users in chat"));
|
||||
}
|
||||
|
||||
void TabRoom::closeRequest()
|
||||
|
|
@ -137,6 +151,16 @@ void TabRoom::actLeaveRoom()
|
|||
deleteLater();
|
||||
}
|
||||
|
||||
void TabRoom::actIgnoreUnregisteredUsers()
|
||||
{
|
||||
settingsCache->setIgnoreUnregisteredUsers(!settingsCache->getIgnoreUnregisteredUsers());
|
||||
}
|
||||
|
||||
void TabRoom::ignoreUnregisteredUsersChanged()
|
||||
{
|
||||
aIgnoreUnregisteredUsers->setChecked(settingsCache->getIgnoreUnregisteredUsers());
|
||||
}
|
||||
|
||||
void TabRoom::processRoomEvent(const RoomEvent &event)
|
||||
{
|
||||
switch (static_cast<RoomEvent::RoomEventType>(getPbExtension(event))) {
|
||||
|
|
@ -168,8 +192,24 @@ void TabRoom::processLeaveRoomEvent(const Event_LeaveRoom &event)
|
|||
|
||||
void TabRoom::processRoomSayEvent(const Event_RoomSay &event)
|
||||
{
|
||||
if (!tabSupervisor->getUserListsTab()->getIgnoreList()->userInList(QString::fromStdString(event.name())))
|
||||
chatView->appendMessage(QString::fromStdString(event.name()), QString::fromStdString(event.message()));
|
||||
QString senderName = QString::fromStdString(event.name());
|
||||
if (tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(senderName))
|
||||
return;
|
||||
UserListTWI *twi = userList->getUsers().value(senderName);
|
||||
QColor senderColor;
|
||||
if (twi && (senderName != QString::fromStdString(ownUser->name()))) {
|
||||
ServerInfo_User::UserLevelFlags userLevel = static_cast<ServerInfo_User::UserLevelFlags>(twi->getUserLevel());
|
||||
if (userLevel & ServerInfo_User::IsModerator)
|
||||
senderColor = Qt::darkMagenta;
|
||||
else if (userLevel & ServerInfo_User::IsRegistered)
|
||||
senderColor = Qt::darkGreen;
|
||||
else {
|
||||
if (settingsCache->getIgnoreUnregisteredUsers())
|
||||
return;
|
||||
senderColor = QColor(0, 0, 254);
|
||||
}
|
||||
}
|
||||
chatView->appendMessage(QString::fromStdString(event.name()), QString::fromStdString(event.message()), senderColor);
|
||||
emit userEvent(false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,14 +42,17 @@ private:
|
|||
QGroupBox *chatGroupBox;
|
||||
|
||||
QAction *aLeaveRoom;
|
||||
QAction *aIgnoreUnregisteredUsers;
|
||||
QString sanitizeHtml(QString dirty) const;
|
||||
signals:
|
||||
void roomClosing(TabRoom *tab);
|
||||
void openMessageDialog(const QString &userName, bool focus);
|
||||
private slots:
|
||||
void sendMessage();
|
||||
void actLeaveRoom();
|
||||
void sayFinished(const Response &response);
|
||||
void actLeaveRoom();
|
||||
void actIgnoreUnregisteredUsers();
|
||||
void ignoreUnregisteredUsersChanged();
|
||||
|
||||
void processListGamesEvent(const Event_ListGames &event);
|
||||
void processJoinRoomEvent(const Event_JoinRoom &event);
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ void TabUserLists::ignoreListReceived(const QList<ServerInfo_User> &_ignoreList)
|
|||
void TabUserLists::processAddToListEvent(const Event_AddToList &event)
|
||||
{
|
||||
const ServerInfo_User &info = event.user_info();
|
||||
bool online = allUsersList->userInList(QString::fromStdString(info.name()));
|
||||
bool online = allUsersList->getUsers().contains(QString::fromStdString(info.name()));
|
||||
QString list = QString::fromStdString(event.list_name());
|
||||
UserList *userList = 0;
|
||||
if (list == "buddy")
|
||||
|
|
|
|||
|
|
@ -174,6 +174,16 @@ UserListTWI::UserListTWI()
|
|||
{
|
||||
}
|
||||
|
||||
QString UserListTWI::getUserName() const
|
||||
{
|
||||
return data(2, Qt::UserRole).toString();
|
||||
}
|
||||
|
||||
int UserListTWI::getUserLevel() const
|
||||
{
|
||||
return data(0, Qt::UserRole).toInt();
|
||||
}
|
||||
|
||||
bool UserListTWI::operator<(const QTreeWidgetItem &other) const
|
||||
{
|
||||
// Sort by online/offline
|
||||
|
|
@ -224,16 +234,11 @@ void UserList::retranslateUi()
|
|||
|
||||
void UserList::processUserInfo(const ServerInfo_User &user, bool online)
|
||||
{
|
||||
QTreeWidgetItem *item = 0;
|
||||
for (int i = 0; i < userTree->topLevelItemCount(); ++i) {
|
||||
QTreeWidgetItem *temp = userTree->topLevelItem(i);
|
||||
if (temp->data(2, Qt::UserRole) == QString::fromStdString(user.name())) {
|
||||
item = temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const QString userName = QString::fromStdString(user.name());
|
||||
UserListTWI *item = users.value(userName);
|
||||
if (!item) {
|
||||
item = new UserListTWI;
|
||||
users.insert(userName, item);
|
||||
userTree->addTopLevelItem(item);
|
||||
if (online)
|
||||
++onlineCount;
|
||||
|
|
@ -254,15 +259,16 @@ void UserList::processUserInfo(const ServerInfo_User &user, bool online)
|
|||
|
||||
bool UserList::deleteUser(const QString &userName)
|
||||
{
|
||||
for (int i = 0; i < userTree->topLevelItemCount(); ++i)
|
||||
if (userTree->topLevelItem(i)->data(2, Qt::UserRole) == userName) {
|
||||
QTreeWidgetItem *item = userTree->takeTopLevelItem(i);
|
||||
if (item->data(0, Qt::UserRole + 1).toBool())
|
||||
--onlineCount;
|
||||
delete item;
|
||||
updateCount();
|
||||
return true;
|
||||
}
|
||||
UserListTWI *twi = users.value(userName);
|
||||
if (twi) {
|
||||
users.remove(userName);
|
||||
userTree->takeTopLevelItem(userTree->indexOfTopLevelItem(twi));
|
||||
if (twi->data(0, Qt::UserRole + 1).toBool())
|
||||
--onlineCount;
|
||||
delete twi;
|
||||
updateCount();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -283,13 +289,9 @@ void UserList::setUserOnline(QTreeWidgetItem *item, bool online)
|
|||
|
||||
void UserList::setUserOnline(const QString &userName, bool online)
|
||||
{
|
||||
for (int i = 0; i < userTree->topLevelItemCount(); ++i) {
|
||||
QTreeWidgetItem *item = userTree->topLevelItem(i);
|
||||
if (item->data(2, Qt::UserRole) == userName) {
|
||||
setUserOnline(item, online);
|
||||
break;
|
||||
}
|
||||
}
|
||||
UserListTWI *twi = users.value(userName);
|
||||
if (twi)
|
||||
setUserOnline(twi, online);
|
||||
}
|
||||
|
||||
void UserList::updateCount()
|
||||
|
|
@ -361,8 +363,9 @@ void UserList::banUser_dialogFinished()
|
|||
|
||||
void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
||||
{
|
||||
const QString &userName = index.sibling(index.row(), 2).data(Qt::UserRole).toString();
|
||||
ServerInfo_User::UserLevelFlags userLevel = static_cast<ServerInfo_User::UserLevelFlags>(index.sibling(index.row(), 0).data(Qt::UserRole).toInt());
|
||||
UserListTWI *twi = static_cast<UserListTWI *>(userTree->topLevelItem(index.row()));
|
||||
const QString &userName = twi->getUserName();
|
||||
ServerInfo_User::UserLevelFlags userLevel = static_cast<ServerInfo_User::UserLevelFlags>(twi->getUserLevel());
|
||||
|
||||
QAction *aUserName = new QAction(userName, this);
|
||||
aUserName->setEnabled(false);
|
||||
|
|
@ -383,11 +386,11 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
|||
menu->addAction(aChat);
|
||||
if ((userLevel & ServerInfo_User::IsRegistered) && (tabSupervisor->getUserLevel() & ServerInfo_User::IsRegistered)) {
|
||||
menu->addSeparator();
|
||||
if (tabSupervisor->getUserListsTab()->getBuddyList()->userInList(userName))
|
||||
if (tabSupervisor->getUserListsTab()->getBuddyList()->getUsers().contains(userName))
|
||||
menu->addAction(aRemoveFromBuddyList);
|
||||
else
|
||||
menu->addAction(aAddToBuddyList);
|
||||
if (tabSupervisor->getUserListsTab()->getIgnoreList()->userInList(userName))
|
||||
if (tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(userName))
|
||||
menu->addAction(aRemoveFromIgnoreList);
|
||||
else
|
||||
menu->addAction(aAddToIgnoreList);
|
||||
|
|
@ -465,14 +468,6 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
|||
delete aBan;
|
||||
}
|
||||
|
||||
bool UserList::userInList(const QString &userName) const
|
||||
{
|
||||
for (int i = 0; i < userTree->topLevelItemCount(); ++i)
|
||||
if (userTree->topLevelItem(i)->data(2, Qt::UserRole) == userName)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void UserList::sortItems()
|
||||
{
|
||||
userTree->sortItems(1, Qt::AscendingOrder);
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ public:
|
|||
class UserListTWI : public QTreeWidgetItem {
|
||||
public:
|
||||
UserListTWI();
|
||||
QString getUserName() const;
|
||||
int getUserLevel() const;
|
||||
bool operator<(const QTreeWidgetItem &other) const;
|
||||
};
|
||||
|
||||
|
|
@ -56,6 +58,7 @@ class UserList : public QGroupBox {
|
|||
public:
|
||||
enum UserListType { AllUsersList, RoomList, BuddyList, IgnoreList };
|
||||
private:
|
||||
QMap<QString, UserListTWI *> users;
|
||||
TabSupervisor *tabSupervisor;
|
||||
AbstractClient *client;
|
||||
UserListType type;
|
||||
|
|
@ -82,7 +85,7 @@ public:
|
|||
void processUserInfo(const ServerInfo_User &user, bool online);
|
||||
bool deleteUser(const QString &userName);
|
||||
void setUserOnline(const QString &userName, bool online);
|
||||
bool userInList(const QString &userName) const;
|
||||
const QMap<QString, UserListTWI *> &getUsers() const { return users; }
|
||||
void showContextMenu(const QPoint &pos, const QModelIndex &index);
|
||||
void sortItems();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue