mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-23 07:03:54 -07:00
more buddy list & ignore list code
This commit is contained in:
parent
7a7b686e67
commit
9e34c9c985
22 changed files with 278 additions and 174 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include <QWidget>
|
||||
|
||||
class QMenu;
|
||||
class TabSupervisor;
|
||||
|
||||
class Tab : public QWidget {
|
||||
Q_OBJECT
|
||||
|
|
@ -11,11 +12,12 @@ signals:
|
|||
void userEvent();
|
||||
protected:
|
||||
QMenu *tabMenu;
|
||||
TabSupervisor *tabSupervisor;
|
||||
private:
|
||||
bool contentsChanged;
|
||||
public:
|
||||
Tab(QWidget *parent = 0)
|
||||
: QWidget(parent), tabMenu(0), contentsChanged(false) { }
|
||||
Tab(TabSupervisor *_tabSupervisor, QWidget *parent = 0)
|
||||
: QWidget(parent), tabMenu(0), tabSupervisor(_tabSupervisor), contentsChanged(false) { }
|
||||
QMenu *getTabMenu() const { return tabMenu; }
|
||||
bool getContentsChanged() const { return contentsChanged; }
|
||||
void setContentsChanged(bool _contentsChanged) { contentsChanged = _contentsChanged; }
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
#include "abstractclient.h"
|
||||
#include "protocol_items.h"
|
||||
|
||||
TabAdmin::TabAdmin(AbstractClient *_client, QWidget *parent)
|
||||
: Tab(parent), client(_client)
|
||||
TabAdmin::TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent)
|
||||
: Tab(_tabSupervisor, parent), client(_client)
|
||||
{
|
||||
updateServerMessageButton = new QPushButton;
|
||||
connect(updateServerMessageButton, SIGNAL(clicked()), this, SLOT(actUpdateServerMessage()));
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ private slots:
|
|||
void actUnlock();
|
||||
void actLock();
|
||||
public:
|
||||
TabAdmin(AbstractClient *_client, QWidget *parent = 0);
|
||||
TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
QString getTabText() const { return tr("Administration"); }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
#include "window_deckeditor.h"
|
||||
#include "settingscache.h"
|
||||
|
||||
TabDeckStorage::TabDeckStorage(AbstractClient *_client)
|
||||
: Tab(), client(_client)
|
||||
TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client)
|
||||
: Tab(_tabSupervisor), client(_client)
|
||||
{
|
||||
localDirModel = new QFileSystemModel(this);
|
||||
localDirModel->setRootPath(settingsCache->getDeckPath());
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ private slots:
|
|||
void actDelete();
|
||||
void deleteFinished(ResponseCode resp);
|
||||
public:
|
||||
TabDeckStorage(AbstractClient *_client);
|
||||
TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client);
|
||||
void retranslateUi();
|
||||
QString getTabText() const { return tr("Deck storage"); }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -159,8 +159,8 @@ void DeckViewContainer::setDeck(DeckList *deck)
|
|||
readyStartButton->setEnabled(true);
|
||||
}
|
||||
|
||||
TabGame::TabGame(QList<AbstractClient *> &_clients, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming)
|
||||
: Tab(), clients(_clients), gameId(_gameId), gameDescription(_gameDescription), localPlayerId(_localPlayerId), spectator(_spectator), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), started(false), resuming(_resuming), currentPhase(-1), infoPopup(0)
|
||||
TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming)
|
||||
: Tab(_tabSupervisor), clients(_clients), gameId(_gameId), gameDescription(_gameDescription), localPlayerId(_localPlayerId), spectator(_spectator), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), started(false), resuming(_resuming), currentPhase(-1), infoPopup(0)
|
||||
{
|
||||
phasesToolbar = new PhasesToolbar;
|
||||
phasesToolbar->hide();
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ private slots:
|
|||
void actNextPhase();
|
||||
void actNextTurn();
|
||||
public:
|
||||
TabGame(QList<AbstractClient *> &_clients, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming);
|
||||
TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming);
|
||||
~TabGame();
|
||||
void retranslateUi();
|
||||
const QMap<int, Player *> &getPlayers() const { return players; }
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
#include "protocol_items.h"
|
||||
#include "chatview.h"
|
||||
|
||||
TabMessage::TabMessage(AbstractClient *_client, const QString &_ownName, const QString &_userName)
|
||||
: Tab(), client(_client), userName(_userName), userOnline(true)
|
||||
TabMessage::TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, const QString &_userName)
|
||||
: Tab(_tabSupervisor), client(_client), userName(_userName), userOnline(true)
|
||||
{
|
||||
chatView = new ChatView(_ownName);
|
||||
sayEdit = new QLineEdit;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ private slots:
|
|||
void sendMessage();
|
||||
void actLeave();
|
||||
public:
|
||||
TabMessage(AbstractClient *_client, const QString &_ownName, const QString &_userName);
|
||||
TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, const QString &_userName);
|
||||
~TabMessage();
|
||||
void retranslateUi();
|
||||
QString getUserName() const { return userName; }
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <QInputDialog>
|
||||
#include <QLabel>
|
||||
#include "dlg_creategame.h"
|
||||
#include "tab_supervisor.h"
|
||||
#include "tab_room.h"
|
||||
#include "userlist.h"
|
||||
#include "abstractclient.h"
|
||||
|
|
@ -122,15 +123,15 @@ void GameSelector::processGameInfo(ServerInfo_Game *info)
|
|||
gameListModel->updateGameList(info);
|
||||
}
|
||||
|
||||
TabRoom::TabRoom(AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info)
|
||||
: Tab(), client(_client), roomId(info->getRoomId()), roomName(info->getName()), ownName(_ownName)
|
||||
TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info)
|
||||
: Tab(_tabSupervisor), client(_client), roomId(info->getRoomId()), roomName(info->getName()), ownName(_ownName)
|
||||
{
|
||||
const QList<ServerInfo_GameType *> gameTypeList = info->getGameTypeList();
|
||||
for (int i = 0; i < gameTypeList.size(); ++i)
|
||||
gameTypes.insert(gameTypeList[i]->getGameTypeId(), gameTypeList[i]->getDescription());
|
||||
|
||||
gameSelector = new GameSelector(client, this);
|
||||
userList = new UserList(client, false);
|
||||
userList = new UserList(tabSupervisor->getUserListsTab(), client, UserList::RoomList);
|
||||
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
|
||||
|
||||
chatView = new ChatView(ownName);
|
||||
|
|
@ -169,7 +170,7 @@ TabRoom::TabRoom(AbstractClient *_client, const QString &_ownName, ServerInfo_Ro
|
|||
|
||||
const QList<ServerInfo_User *> users = info->getUserList();
|
||||
for (int i = 0; i < users.size(); ++i)
|
||||
userList->processUserInfo(users[i]);
|
||||
userList->processUserInfo(users[i], true);
|
||||
userList->sortItems();
|
||||
|
||||
const QList<ServerInfo_Game *> games = info->getGameList();
|
||||
|
|
@ -233,7 +234,7 @@ void TabRoom::processListGamesEvent(Event_ListGames *event)
|
|||
|
||||
void TabRoom::processJoinRoomEvent(Event_JoinRoom *event)
|
||||
{
|
||||
userList->processUserInfo(event->getUserInfo());
|
||||
userList->processUserInfo(event->getUserInfo(), true);
|
||||
userList->sortItems();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ private slots:
|
|||
void processLeaveRoomEvent(Event_LeaveRoom *event);
|
||||
void processSayEvent(Event_RoomSay *event);
|
||||
public:
|
||||
TabRoom(AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info);
|
||||
TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info);
|
||||
~TabRoom();
|
||||
void retranslateUi();
|
||||
void processRoomEvent(RoomEvent *event);
|
||||
|
|
|
|||
|
|
@ -117,47 +117,27 @@ void RoomSelector::joinFinished(ProtocolResponse *r)
|
|||
emit roomJoined(resp->getRoomInfo(), static_cast<Command *>(sender())->getExtraData().toBool());
|
||||
}
|
||||
|
||||
TabServer::TabServer(AbstractClient *_client, ServerInfo_User *userInfo, QWidget *parent)
|
||||
: Tab(parent), client(_client)
|
||||
TabServer::TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent)
|
||||
: Tab(_tabSupervisor, parent), client(_client)
|
||||
{
|
||||
roomSelector = new RoomSelector(client);
|
||||
serverInfoBox = new QTextBrowser;
|
||||
serverInfoBox->setOpenExternalLinks(true);
|
||||
userInfoBox = new UserInfoBox(_client, false);
|
||||
userInfoBox->updateInfo(userInfo);
|
||||
userList = new UserList(client, true);
|
||||
|
||||
connect(roomSelector, SIGNAL(roomJoined(ServerInfo_Room *, bool)), this, SIGNAL(roomJoined(ServerInfo_Room *, bool)));
|
||||
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
|
||||
|
||||
connect(client, SIGNAL(userJoinedEventReceived(Event_UserJoined *)), this, SLOT(processUserJoinedEvent(Event_UserJoined *)));
|
||||
connect(client, SIGNAL(userLeftEventReceived(Event_UserLeft *)), this, SLOT(processUserLeftEvent(Event_UserLeft *)));
|
||||
connect(client, SIGNAL(serverMessageEventReceived(Event_ServerMessage *)), this, SLOT(processServerMessageEvent(Event_ServerMessage *)));
|
||||
|
||||
Command_ListUsers *cmd = new Command_ListUsers;
|
||||
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(processListUsersResponse(ProtocolResponse *)));
|
||||
client->sendCommand(cmd);
|
||||
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(roomSelector);
|
||||
vbox->addWidget(serverInfoBox);
|
||||
|
||||
QVBoxLayout *vbox2 = new QVBoxLayout;
|
||||
vbox2->addWidget(userInfoBox);
|
||||
vbox2->addWidget(userList);
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
mainLayout->addLayout(vbox, 3);
|
||||
mainLayout->addLayout(vbox2, 1);
|
||||
|
||||
setLayout(mainLayout);
|
||||
setLayout(vbox);
|
||||
}
|
||||
|
||||
void TabServer::retranslateUi()
|
||||
{
|
||||
roomSelector->retranslateUi();
|
||||
userInfoBox->retranslateUi();
|
||||
userList->retranslateUi();
|
||||
}
|
||||
|
||||
void TabServer::processServerMessageEvent(Event_ServerMessage *event)
|
||||
|
|
@ -165,30 +145,3 @@ void TabServer::processServerMessageEvent(Event_ServerMessage *event)
|
|||
serverInfoBox->setHtml(event->getMessage());
|
||||
emit userEvent();
|
||||
}
|
||||
|
||||
void TabServer::processListUsersResponse(ProtocolResponse *response)
|
||||
{
|
||||
Response_ListUsers *resp = qobject_cast<Response_ListUsers *>(response);
|
||||
if (!resp)
|
||||
return;
|
||||
|
||||
const QList<ServerInfo_User *> &respList = resp->getUserList();
|
||||
for (int i = 0; i < respList.size(); ++i)
|
||||
userList->processUserInfo(respList[i]);
|
||||
|
||||
userList->sortItems();
|
||||
}
|
||||
|
||||
void TabServer::processUserJoinedEvent(Event_UserJoined *event)
|
||||
{
|
||||
userList->processUserInfo(event->getUserInfo());
|
||||
userList->sortItems();
|
||||
|
||||
emit userJoined(event->getUserInfo()->getName());
|
||||
}
|
||||
|
||||
void TabServer::processUserLeftEvent(Event_UserLeft *event)
|
||||
{
|
||||
if (userList->deleteUser(event->getUserName()))
|
||||
emit userLeft(event->getUserName());
|
||||
}
|
||||
|
|
@ -11,14 +11,10 @@ class QTextEdit;
|
|||
class QLabel;
|
||||
class UserList;
|
||||
class QPushButton;
|
||||
class UserInfoBox;
|
||||
|
||||
class Event_ListRooms;
|
||||
class Event_ServerMessage;
|
||||
class Event_UserJoined;
|
||||
class Event_UserLeft;
|
||||
class ProtocolResponse;
|
||||
class ServerInfo_User;
|
||||
class ServerInfo_Room;
|
||||
|
||||
class RoomSelector : public QGroupBox {
|
||||
|
|
@ -44,22 +40,14 @@ class TabServer : public Tab {
|
|||
Q_OBJECT
|
||||
signals:
|
||||
void roomJoined(ServerInfo_Room *info, bool setCurrent);
|
||||
void openMessageDialog(const QString &userName, bool focus);
|
||||
void userLeft(const QString &userName);
|
||||
void userJoined(const QString &userName);
|
||||
private slots:
|
||||
void processListUsersResponse(ProtocolResponse *response);
|
||||
void processUserJoinedEvent(Event_UserJoined *event);
|
||||
void processUserLeftEvent(Event_UserLeft *event);
|
||||
void processServerMessageEvent(Event_ServerMessage *event);
|
||||
private:
|
||||
AbstractClient *client;
|
||||
RoomSelector *roomSelector;
|
||||
QTextBrowser *serverInfoBox;
|
||||
UserList *userList;
|
||||
UserInfoBox *userInfoBox;
|
||||
public:
|
||||
TabServer(AbstractClient *_client, ServerInfo_User *userInfo, QWidget *parent = 0);
|
||||
TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
QString getTabText() const { return tr("Server"); }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "tab_deck_storage.h"
|
||||
#include "tab_admin.h"
|
||||
#include "tab_message.h"
|
||||
#include "tab_userlists.h"
|
||||
#include "protocol_items.h"
|
||||
#include "pixmapgenerator.h"
|
||||
#include <QDebug>
|
||||
|
|
@ -63,22 +64,26 @@ void TabSupervisor::start(AbstractClient *_client, ServerInfo_User *userInfo)
|
|||
connect(client, SIGNAL(messageEventReceived(Event_Message *)), this, SLOT(processMessageEvent(Event_Message *)));
|
||||
connect(client, SIGNAL(maxPingTime(int, int)), this, SLOT(updatePingTime(int, int)));
|
||||
|
||||
tabServer = new TabServer(client, userInfo);
|
||||
tabServer = new TabServer(this, client);
|
||||
connect(tabServer, SIGNAL(roomJoined(ServerInfo_Room *, bool)), this, SLOT(addRoomTab(ServerInfo_Room *, bool)));
|
||||
connect(tabServer, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool)));
|
||||
connect(tabServer, SIGNAL(userJoined(const QString &)), this, SLOT(processUserJoined(const QString &)));
|
||||
connect(tabServer, SIGNAL(userLeft(const QString &)), this, SLOT(processUserLeft(const QString &)));
|
||||
myAddTab(tabServer);
|
||||
|
||||
tabUserLists = new TabUserLists(this, client, userInfo);
|
||||
connect(tabUserLists, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool)));
|
||||
connect(tabUserLists, SIGNAL(userJoined(const QString &)), this, SLOT(processUserJoined(const QString &)));
|
||||
connect(tabUserLists, SIGNAL(userLeft(const QString &)), this, SLOT(processUserLeft(const QString &)));
|
||||
myAddTab(tabUserLists);
|
||||
|
||||
updatePingTime(0, -1);
|
||||
|
||||
if (userInfo->getUserLevel() & ServerInfo_User::IsRegistered) {
|
||||
tabDeckStorage = new TabDeckStorage(client);
|
||||
tabDeckStorage = new TabDeckStorage(this, client);
|
||||
myAddTab(tabDeckStorage);
|
||||
} else
|
||||
tabDeckStorage = 0;
|
||||
|
||||
if (userInfo->getUserLevel() & ServerInfo_User::IsAdmin) {
|
||||
tabAdmin = new TabAdmin(client);
|
||||
tabAdmin = new TabAdmin(this, client);
|
||||
myAddTab(tabAdmin);
|
||||
} else
|
||||
tabAdmin = 0;
|
||||
|
|
@ -148,7 +153,7 @@ void TabSupervisor::updatePingTime(int value, int max)
|
|||
|
||||
void TabSupervisor::gameJoined(Event_GameJoined *event)
|
||||
{
|
||||
TabGame *tab = new TabGame(QList<AbstractClient *>() << client, event->getGameId(), event->getGameDescription(), event->getPlayerId(), event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming());
|
||||
TabGame *tab = new TabGame(this, QList<AbstractClient *>() << client, event->getGameId(), event->getGameDescription(), event->getPlayerId(), event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming());
|
||||
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
|
||||
myAddTab(tab);
|
||||
gameTabs.insert(event->getGameId(), tab);
|
||||
|
|
@ -157,7 +162,7 @@ void TabSupervisor::gameJoined(Event_GameJoined *event)
|
|||
|
||||
void TabSupervisor::localGameJoined(Event_GameJoined *event)
|
||||
{
|
||||
TabGame *tab = new TabGame(localClients, event->getGameId(), event->getGameDescription(), event->getPlayerId(), event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming());
|
||||
TabGame *tab = new TabGame(this, localClients, event->getGameId(), event->getGameDescription(), event->getPlayerId(), event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming());
|
||||
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
|
||||
myAddTab(tab);
|
||||
gameTabs.insert(event->getGameId(), tab);
|
||||
|
|
@ -182,7 +187,7 @@ void TabSupervisor::gameLeft(TabGame *tab)
|
|||
|
||||
void TabSupervisor::addRoomTab(ServerInfo_Room *info, bool setCurrent)
|
||||
{
|
||||
TabRoom *tab = new TabRoom(client, userName, info);
|
||||
TabRoom *tab = new TabRoom(this, client, userName, info);
|
||||
connect(tab, SIGNAL(roomClosing(TabRoom *)), this, SLOT(roomLeft(TabRoom *)));
|
||||
connect(tab, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool)));
|
||||
myAddTab(tab);
|
||||
|
|
@ -204,7 +209,7 @@ TabMessage *TabSupervisor::addMessageTab(const QString &receiverName, bool focus
|
|||
if (receiverName == userName)
|
||||
return 0;
|
||||
|
||||
TabMessage *tab = new TabMessage(client, userName, receiverName);
|
||||
TabMessage *tab = new TabMessage(this, client, userName, receiverName);
|
||||
connect(tab, SIGNAL(talkClosing(TabMessage *)), this, SLOT(talkLeft(TabMessage *)));
|
||||
myAddTab(tab);
|
||||
messageTabs.insert(receiverName, tab);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ class TabGame;
|
|||
class TabDeckStorage;
|
||||
class TabAdmin;
|
||||
class TabMessage;
|
||||
class TabUserLists;
|
||||
class RoomEvent;
|
||||
class GameEventContainer;
|
||||
class Event_GameJoined;
|
||||
|
|
@ -28,6 +29,7 @@ private:
|
|||
AbstractClient *client;
|
||||
QList<AbstractClient *> localClients;
|
||||
TabServer *tabServer;
|
||||
TabUserLists *tabUserLists;
|
||||
TabDeckStorage *tabDeckStorage;
|
||||
TabAdmin *tabAdmin;
|
||||
QMap<int, TabRoom *> roomTabs;
|
||||
|
|
@ -42,6 +44,7 @@ public:
|
|||
void startLocal(const QList<AbstractClient *> &_clients);
|
||||
void stop();
|
||||
int getGameCount() const { return gameTabs.size(); }
|
||||
TabUserLists *getUserListsTab() const { return tabUserLists; }
|
||||
signals:
|
||||
void setMenu(QMenu *menu);
|
||||
void localGameEnded();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "userlist.h"
|
||||
#include "tab_userlists.h"
|
||||
#include "abstractclient.h"
|
||||
#include "pixmapgenerator.h"
|
||||
#include "userinfobox.h"
|
||||
|
|
@ -31,15 +32,20 @@ UserListTWI::UserListTWI()
|
|||
|
||||
bool UserListTWI::operator<(const QTreeWidgetItem &other) const
|
||||
{
|
||||
// Equal user level => sort by name
|
||||
if (data(0, Qt::UserRole) == other.data(0, Qt::UserRole))
|
||||
return data(2, Qt::UserRole).toString().toLower() < other.data(2, Qt::UserRole).toString().toLower();
|
||||
// Else sort by user level
|
||||
return data(0, Qt::UserRole).toInt() > other.data(0, Qt::UserRole).toInt();
|
||||
// Sort by online/offline
|
||||
if (data(0, Qt::UserRole + 1) != other.data(0, Qt::UserRole + 1))
|
||||
return data(0, Qt::UserRole + 1).toBool();
|
||||
|
||||
// Sort by user level
|
||||
if (data(0, Qt::UserRole) != other.data(0, Qt::UserRole))
|
||||
return data(0, Qt::UserRole).toInt() > other.data(0, Qt::UserRole).toInt();
|
||||
|
||||
// Sort by name
|
||||
return data(2, Qt::UserRole).toString().toLower() < other.data(2, Qt::UserRole).toString().toLower();
|
||||
}
|
||||
|
||||
UserList::UserList(AbstractClient *_client, bool _global, QWidget *parent)
|
||||
: QGroupBox(parent), client(_client), global(_global)
|
||||
UserList::UserList(TabUserLists *_tabUserLists, AbstractClient *_client, UserListType _type, QWidget *parent)
|
||||
: QGroupBox(parent), tabUserLists(_tabUserLists), client(_client), type(_type), onlineCount(0)
|
||||
{
|
||||
itemDelegate = new UserListItemDelegate(this);
|
||||
|
||||
|
|
@ -62,11 +68,16 @@ UserList::UserList(AbstractClient *_client, bool _global, QWidget *parent)
|
|||
|
||||
void UserList::retranslateUi()
|
||||
{
|
||||
titleStr = global ? tr("Users online: %1") : tr("Users in this room: %1");
|
||||
switch (type) {
|
||||
case AllUsersList: titleStr = tr("Users online: %1"); break;
|
||||
case RoomList: titleStr = tr("Users in this room: %1"); break;
|
||||
case BuddyList: titleStr = tr("Buddies online: %1 / %2"); break;
|
||||
case IgnoreList: titleStr = tr("Ignored users online: %1 / %2"); break;
|
||||
}
|
||||
updateCount();
|
||||
}
|
||||
|
||||
void UserList::processUserInfo(ServerInfo_User *user)
|
||||
void UserList::processUserInfo(ServerInfo_User *user, bool online)
|
||||
{
|
||||
QTreeWidgetItem *item = 0;
|
||||
for (int i = 0; i < userTree->topLevelItemCount(); ++i) {
|
||||
|
|
@ -86,6 +97,12 @@ void UserList::processUserInfo(ServerInfo_User *user)
|
|||
item->setIcon(1, QIcon(CountryPixmapGenerator::generatePixmap(12, user->getCountry())));
|
||||
item->setData(2, Qt::UserRole, user->getName());
|
||||
item->setData(2, Qt::DisplayRole, user->getName());
|
||||
|
||||
item->setData(0, Qt::UserRole + 1, online);
|
||||
if (online)
|
||||
item->setData(2, Qt::ForegroundRole, QBrush());
|
||||
else
|
||||
item->setData(2, Qt::ForegroundRole, QBrush(Qt::gray));
|
||||
}
|
||||
|
||||
bool UserList::deleteUser(const QString &userName)
|
||||
|
|
@ -100,9 +117,37 @@ bool UserList::deleteUser(const QString &userName)
|
|||
return false;
|
||||
}
|
||||
|
||||
void UserList::setUserOnline(QTreeWidgetItem *item, bool online)
|
||||
{
|
||||
item->setData(0, Qt::UserRole + 1, online);
|
||||
|
||||
if (online) {
|
||||
item->setData(2, Qt::ForegroundRole, QBrush());
|
||||
++onlineCount;
|
||||
} else {
|
||||
item->setData(2, Qt::ForegroundRole, QBrush(Qt::gray));
|
||||
--onlineCount;
|
||||
}
|
||||
updateCount();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UserList::updateCount()
|
||||
{
|
||||
setTitle(titleStr.arg(userTree->topLevelItemCount()));
|
||||
QString str = titleStr;
|
||||
if ((type == BuddyList) || (type == IgnoreList))
|
||||
str = str.arg(onlineCount);
|
||||
setTitle(str.arg(userTree->topLevelItemCount()));
|
||||
}
|
||||
|
||||
void UserList::userClicked(QTreeWidgetItem *item, int /*column*/)
|
||||
|
|
@ -118,12 +163,25 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
|||
aUserName->setEnabled(false);
|
||||
QAction *aDetails = new QAction(tr("User &details"), this);
|
||||
QAction *aChat = new QAction(tr("Direct &chat"), this);
|
||||
QAction *aAddToBuddyList = new QAction(tr("Add to &buddy list"), this);
|
||||
QAction *aRemoveFromBuddyList = new QAction(tr("Remove from &buddy list"), this);
|
||||
QAction *aAddToIgnoreList = new QAction(tr("Remove from &ignore list"), this);
|
||||
QAction *aRemoveFromIgnoreList = new QAction(tr("Remove from &ignore list"), this);
|
||||
|
||||
QMenu *menu = new QMenu(this);
|
||||
menu->addAction(aUserName);
|
||||
menu->addSeparator();
|
||||
menu->addAction(aDetails);
|
||||
menu->addAction(aChat);
|
||||
menu->addSeparator();
|
||||
if (tabUserLists->getBuddyList()->userInList(userName))
|
||||
menu->addAction(aRemoveFromBuddyList);
|
||||
else
|
||||
menu->addAction(aAddToBuddyList);
|
||||
if (tabUserLists->getIgnoreList()->userInList(userName))
|
||||
menu->addAction(aRemoveFromIgnoreList);
|
||||
else
|
||||
menu->addAction(aAddToIgnoreList);
|
||||
|
||||
QAction *actionClicked = menu->exec(pos);
|
||||
if (actionClicked == aDetails) {
|
||||
|
|
@ -132,6 +190,14 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
|||
infoWidget->updateInfo(userName);
|
||||
} else if (actionClicked == aChat)
|
||||
emit openMessageDialog(userName, true);
|
||||
else if (actionClicked == aAddToBuddyList)
|
||||
emit addBuddy(userName);
|
||||
else if (actionClicked == aRemoveFromBuddyList)
|
||||
emit removeBuddy(userName);
|
||||
else if (actionClicked == aAddToIgnoreList)
|
||||
emit addIgnore(userName);
|
||||
else if (actionClicked == aRemoveFromIgnoreList)
|
||||
emit removeIgnore(userName);
|
||||
|
||||
delete menu;
|
||||
delete aUserName;
|
||||
|
|
@ -139,6 +205,14 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
|||
delete aChat;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
class QTreeWidget;
|
||||
class ServerInfo_User;
|
||||
class AbstractClient;
|
||||
class TabUserLists;
|
||||
|
||||
class UserListItemDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
|
|
@ -23,22 +24,33 @@ public:
|
|||
|
||||
class UserList : public QGroupBox {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum UserListType { AllUsersList, RoomList, BuddyList, IgnoreList };
|
||||
private:
|
||||
TabUserLists *tabUserLists;
|
||||
AbstractClient *client;
|
||||
UserListType type;
|
||||
QTreeWidget *userTree;
|
||||
UserListItemDelegate *itemDelegate;
|
||||
bool global;
|
||||
int onlineCount;
|
||||
QString titleStr;
|
||||
void updateCount();
|
||||
void setUserOnline(QTreeWidgetItem *user, bool online);
|
||||
private slots:
|
||||
void userClicked(QTreeWidgetItem *item, int column);
|
||||
signals:
|
||||
void openMessageDialog(const QString &userName, bool focus);
|
||||
void addBuddy(const QString &userName);
|
||||
void removeBuddy(const QString &userName);
|
||||
void addIgnore(const QString &userName);
|
||||
void removeIgnore(const QString &userName);
|
||||
public:
|
||||
UserList(AbstractClient *_client, bool _global, QWidget *parent = 0);
|
||||
UserList(TabUserLists *_tabUserLists, AbstractClient *_client, UserListType _type, QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
void processUserInfo(ServerInfo_User *user);
|
||||
void processUserInfo(ServerInfo_User *user, bool online);
|
||||
bool deleteUser(const QString &userName);
|
||||
void setUserOnline(const QString &userName, bool online);
|
||||
bool userInList(const QString &userName) const;
|
||||
void showContextMenu(const QPoint &pos, const QModelIndex &index);
|
||||
void sortItems();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue