Major Directory Refactoring (#5118)

* refactored cardzone.cpp, added doc and changed if to switch case

* started moving every files into different folders

* remove undercase to match with other files naming convention

* refactored dialog files

* ran format.sh

* refactored client/tabs folder

* refactored client/tabs folder

* refactored client/tabs folder

* refactored client folder

* refactored carddbparser

* refactored dialogs

* Create sonar-project.properties

temporary file for lint

* Create build.yml

temporary file for lint

* removed all files from root directory

* removed all files from root directory

* added current branch to workflow

* fixed most broken import

* fixed issues while renaming files

* fixed oracle importer

* fixed dbconverter

* updated translations

* made sub-folders for client

* removed linter

* removed linter folder

* fixed oracle import

* revert card_zone documentation

* renamed db parser files name and deck_view imports

* fixed dlg file issue

* ran format file and fixed test file

* fixed carddb test files

* moved player folder in game

* updated translations and format files

* fixed peglib import

* format cmake files

* removing vcpkg to try to add it back later

* tried fixing vcpkg file

* renamed filter to filters and moved database parser to cards folder

* reverted translation files

* reverted oracle translated

* Update cockatrice/src/dialogs/dlg_register.cpp

Co-authored-by: tooomm <tooomm@users.noreply.github.com>

* Update cockatrice/src/client/ui/window_main.cpp

Co-authored-by: tooomm <tooomm@users.noreply.github.com>

* removed empty line at file start

* removed useless include from tab_supervisor.cpp

* refactored cardzone.cpp, added doc and changed if to switch case

* started moving every files into different folders

* remove undercase to match with other files naming convention

* refactored dialog files

* ran format.sh

* refactored client/tabs folder

* refactored client folder

* refactored carddbparser

* refactored dialogs

* removed all files from root directory

* Create sonar-project.properties

temporary file for lint

* Create build.yml

temporary file for lint

* added current branch to workflow

* fixed most broken import

* fixed issues while renaming files

* fixed oracle importer

* fixed dbconverter

* updated translations

* made sub-folders for client

* removed linter

* removed linter folder

* fixed oracle import

* revert card_zone documentation

* renamed db parser files name and deck_view imports

* fixed dlg file issue

* ran format file and fixed test file

* fixed carddb test files

* moved player folder in game

* updated translations and format files

* fixed peglib import

* reverted translation files

* format cmake files

* removing vcpkg to try to add it back later

* tried fixing vcpkg file

* pre-updating of cockatrice changes

* removed empty line at file start

* reverted oracle translated

* Update cockatrice/src/dialogs/dlg_register.cpp

Co-authored-by: tooomm <tooomm@users.noreply.github.com>

* Update cockatrice/src/client/ui/window_main.cpp

Co-authored-by: tooomm <tooomm@users.noreply.github.com>

* removed useless include from tab_supervisor.cpp

---------

Co-authored-by: tooomm <tooomm@users.noreply.github.com>
This commit is contained in:
LunaticCat 2024-10-20 16:11:35 +02:00 committed by GitHub
parent d1e0f9dfc5
commit fa999880ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
261 changed files with 735 additions and 729 deletions

View file

@ -0,0 +1,41 @@
#include "tab.h"
#include "../../game/cards/card_info_widget.h"
#include <QApplication>
#include <QDebug>
#include <QScreen>
Tab::Tab(TabSupervisor *_tabSupervisor, QWidget *parent)
: QMainWindow(parent), tabSupervisor(_tabSupervisor), contentsChanged(false), infoPopup(0)
{
setAttribute(Qt::WA_DeleteOnClose);
}
void Tab::showCardInfoPopup(const QPoint &pos, const QString &cardName)
{
if (infoPopup) {
infoPopup->deleteLater();
}
currentCardName = cardName;
infoPopup = new CardInfoWidget(
cardName, 0, Qt::Widget | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
infoPopup->setAttribute(Qt::WA_TransparentForMouseEvents);
auto screenRect = qApp->primaryScreen()->geometry();
infoPopup->move(qMax(screenRect.left(), qMin(pos.x() - infoPopup->width() / 2,
screenRect.left() + screenRect.width() - infoPopup->width())),
qMax(screenRect.top(), qMin(pos.y() - infoPopup->height() / 2,
screenRect.top() + screenRect.height() - infoPopup->height())));
infoPopup->show();
}
void Tab::deleteCardInfoPopup(const QString &cardName)
{
if (infoPopup) {
if ((currentCardName == cardName) || (cardName == "_")) {
infoPopup->deleteLater();
infoPopup = 0;
}
}
}

View file

@ -0,0 +1,61 @@
#ifndef TAB_H
#define TAB_H
#include <QMainWindow>
class QMenu;
class TabSupervisor;
class CardInfoWidget;
class Tab : public QMainWindow
{
Q_OBJECT
signals:
void userEvent(bool globalEvent = true);
void tabTextChanged(Tab *tab, const QString &newTabText);
protected:
TabSupervisor *tabSupervisor;
void addTabMenu(QMenu *menu)
{
tabMenus.append(menu);
}
protected slots:
void showCardInfoPopup(const QPoint &pos, const QString &cardName);
void deleteCardInfoPopup(const QString &cardName);
private:
QString currentCardName;
bool contentsChanged;
CardInfoWidget *infoPopup;
QList<QMenu *> tabMenus;
public:
Tab(TabSupervisor *_tabSupervisor, QWidget *parent = nullptr);
const QList<QMenu *> &getTabMenus() const
{
return tabMenus;
}
TabSupervisor *getTabSupervisor() const
{
return tabSupervisor;
}
bool getContentsChanged() const
{
return contentsChanged;
}
void setContentsChanged(bool _contentsChanged)
{
contentsChanged = _contentsChanged;
}
virtual QString getTabText() const = 0;
virtual void retranslateUi() = 0;
virtual void closeRequest()
{
}
virtual void tabActivated()
{
}
};
#endif

View file

@ -0,0 +1,238 @@
#include "tab_account.h"
#include "../../deck/custom_line_edit.h"
#include "../../server/pending_command.h"
#include "../../server/user/user_info_box.h"
#include "../../server/user/user_list.h"
#include "../game_logic/abstract_client.h"
#include "../sound_engine.h"
#include "pb/event_add_to_list.pb.h"
#include "pb/event_remove_from_list.pb.h"
#include "pb/event_user_joined.pb.h"
#include "pb/event_user_left.pb.h"
#include "pb/response_list_users.pb.h"
#include "pb/session_commands.pb.h"
#include "trice_limits.h"
#include <QHBoxLayout>
#include <QPushButton>
#include <QVBoxLayout>
TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor,
AbstractClient *_client,
const ServerInfo_User &userInfo,
QWidget *parent)
: Tab(_tabSupervisor, parent), client(_client)
{
allUsersList = new UserList(_tabSupervisor, client, UserList::AllUsersList);
buddyList = new UserList(_tabSupervisor, client, UserList::BuddyList);
ignoreList = new UserList(_tabSupervisor, client, UserList::IgnoreList);
userInfoBox = new UserInfoBox(client, true);
userInfoBox->updateInfo(userInfo);
connect(allUsersList, SIGNAL(openMessageDialog(const QString &, bool)), this,
SIGNAL(openMessageDialog(const QString &, bool)));
connect(buddyList, SIGNAL(openMessageDialog(const QString &, bool)), this,
SIGNAL(openMessageDialog(const QString &, bool)));
connect(ignoreList, SIGNAL(openMessageDialog(const QString &, bool)), this,
SIGNAL(openMessageDialog(const QString &, bool)));
connect(client, SIGNAL(userJoinedEventReceived(const Event_UserJoined &)), this,
SLOT(processUserJoinedEvent(const Event_UserJoined &)));
connect(client, SIGNAL(userLeftEventReceived(const Event_UserLeft &)), this,
SLOT(processUserLeftEvent(const Event_UserLeft &)));
connect(client, SIGNAL(buddyListReceived(const QList<ServerInfo_User> &)), this,
SLOT(buddyListReceived(const QList<ServerInfo_User> &)));
connect(client, SIGNAL(ignoreListReceived(const QList<ServerInfo_User> &)), this,
SLOT(ignoreListReceived(const QList<ServerInfo_User> &)));
connect(client, SIGNAL(addToListEventReceived(const Event_AddToList &)), this,
SLOT(processAddToListEvent(const Event_AddToList &)));
connect(client, SIGNAL(removeFromListEventReceived(const Event_RemoveFromList &)), this,
SLOT(processRemoveFromListEvent(const Event_RemoveFromList &)));
PendingCommand *pend = client->prepareSessionCommand(Command_ListUsers());
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(processListUsersResponse(const Response &)));
client->sendCommand(pend);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(userInfoBox);
vbox->addWidget(allUsersList);
QHBoxLayout *addToBuddyList = new QHBoxLayout;
addBuddyEdit = new LineEditUnfocusable;
addBuddyEdit->setMaxLength(MAX_NAME_LENGTH);
addBuddyEdit->setPlaceholderText(tr("Add to Buddy List"));
connect(addBuddyEdit, SIGNAL(returnPressed()), this, SLOT(addToBuddyList()));
QPushButton *addBuddyButton = new QPushButton("Add");
connect(addBuddyButton, SIGNAL(clicked()), this, SLOT(addToBuddyList()));
addToBuddyList->addWidget(addBuddyEdit);
addToBuddyList->addWidget(addBuddyButton);
QHBoxLayout *addToIgnoreList = new QHBoxLayout;
addIgnoreEdit = new LineEditUnfocusable;
addIgnoreEdit->setMaxLength(MAX_NAME_LENGTH);
addIgnoreEdit->setPlaceholderText(tr("Add to Ignore List"));
connect(addIgnoreEdit, SIGNAL(returnPressed()), this, SLOT(addToIgnoreList()));
QPushButton *addIgnoreButton = new QPushButton("Add");
connect(addIgnoreButton, SIGNAL(clicked()), this, SLOT(addToIgnoreList()));
addToIgnoreList->addWidget(addIgnoreEdit);
addToIgnoreList->addWidget(addIgnoreButton);
QVBoxLayout *buddyPanel = new QVBoxLayout;
buddyPanel->addWidget(buddyList);
buddyPanel->addLayout(addToBuddyList);
QVBoxLayout *ignorePanel = new QVBoxLayout;
ignorePanel->addWidget(ignoreList);
ignorePanel->addLayout(addToIgnoreList);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(buddyPanel);
mainLayout->addLayout(ignorePanel);
mainLayout->addLayout(vbox);
retranslateUi();
QWidget *mainWidget = new QWidget(this);
mainWidget->setLayout(mainLayout);
setCentralWidget(mainWidget);
}
void TabUserLists::addToBuddyList()
{
QString userName = addBuddyEdit->text();
if (userName.length() < 1)
return;
std::string listName = "buddy";
addToList(listName, userName);
addBuddyEdit->clear();
}
void TabUserLists::addToIgnoreList()
{
QString userName = addIgnoreEdit->text();
if (userName.length() < 1)
return;
std::string listName = "ignore";
addToList(listName, userName);
addIgnoreEdit->clear();
}
void TabUserLists::addToList(const std::string &listName, const QString &userName)
{
Command_AddToList cmd;
cmd.set_list(listName);
cmd.set_user_name(userName.toStdString());
client->sendCommand(client->prepareSessionCommand(cmd));
}
void TabUserLists::retranslateUi()
{
allUsersList->retranslateUi();
buddyList->retranslateUi();
ignoreList->retranslateUi();
userInfoBox->retranslateUi();
}
void TabUserLists::processListUsersResponse(const Response &response)
{
const Response_ListUsers &resp = response.GetExtension(Response_ListUsers::ext);
const int userListSize = resp.user_list_size();
for (int i = 0; i < userListSize; ++i) {
const ServerInfo_User &info = resp.user_list(i);
const QString userName = QString::fromStdString(info.name());
allUsersList->processUserInfo(info, true);
ignoreList->setUserOnline(userName, true);
buddyList->setUserOnline(userName, true);
}
allUsersList->sortItems();
ignoreList->sortItems();
buddyList->sortItems();
}
void TabUserLists::processUserJoinedEvent(const Event_UserJoined &event)
{
const ServerInfo_User &info = event.user_info();
const QString userName = QString::fromStdString(info.name());
allUsersList->processUserInfo(info, true);
ignoreList->setUserOnline(userName, true);
buddyList->setUserOnline(userName, true);
allUsersList->sortItems();
ignoreList->sortItems();
buddyList->sortItems();
if (buddyList->getUsers().keys().contains(userName))
soundEngine->playSound("buddy_join");
emit userJoined(info);
}
void TabUserLists::processUserLeftEvent(const Event_UserLeft &event)
{
QString userName = QString::fromStdString(event.name());
if (buddyList->getUsers().keys().contains(userName))
soundEngine->playSound("buddy_leave");
if (allUsersList->deleteUser(userName)) {
ignoreList->setUserOnline(userName, false);
buddyList->setUserOnline(userName, false);
ignoreList->sortItems();
buddyList->sortItems();
emit userLeft(userName);
}
}
void TabUserLists::buddyListReceived(const QList<ServerInfo_User> &_buddyList)
{
for (int i = 0; i < _buddyList.size(); ++i)
buddyList->processUserInfo(_buddyList[i], false);
buddyList->sortItems();
}
void TabUserLists::ignoreListReceived(const QList<ServerInfo_User> &_ignoreList)
{
for (int i = 0; i < _ignoreList.size(); ++i)
ignoreList->processUserInfo(_ignoreList[i], false);
ignoreList->sortItems();
}
void TabUserLists::processAddToListEvent(const Event_AddToList &event)
{
const ServerInfo_User &info = event.user_info();
bool online = allUsersList->getUsers().contains(QString::fromStdString(info.name()));
QString list = QString::fromStdString(event.list_name());
UserList *userList = 0;
if (list == "buddy")
userList = buddyList;
else if (list == "ignore")
userList = ignoreList;
if (!userList)
return;
userList->processUserInfo(info, online);
userList->sortItems();
}
void TabUserLists::processRemoveFromListEvent(const Event_RemoveFromList &event)
{
QString list = QString::fromStdString(event.list_name());
QString user = QString::fromStdString(event.user_name());
UserList *userList = 0;
if (list == "buddy")
userList = buddyList;
else if (list == "ignore")
userList = ignoreList;
if (!userList)
return;
userList->deleteUser(user);
}

View file

@ -0,0 +1,72 @@
#ifndef TAB_ACCOUNT_H
#define TAB_ACCOUNT_H
#include "pb/serverinfo_user.pb.h"
#include "tab.h"
class AbstractClient;
class UserList;
class UserInfoBox;
class LineEditUnfocusable;
class Event_ListRooms;
class Event_UserJoined;
class Event_UserLeft;
class Response;
class ServerInfo_User;
class Event_AddToList;
class Event_RemoveFromList;
class TabUserLists : public Tab
{
Q_OBJECT
signals:
void openMessageDialog(const QString &userName, bool focus);
void userLeft(const QString &userName);
void userJoined(const ServerInfo_User &userInfo);
private slots:
void processListUsersResponse(const Response &response);
void processUserJoinedEvent(const Event_UserJoined &event);
void processUserLeftEvent(const Event_UserLeft &event);
void buddyListReceived(const QList<ServerInfo_User> &_buddyList);
void ignoreListReceived(const QList<ServerInfo_User> &_ignoreList);
void processAddToListEvent(const Event_AddToList &event);
void processRemoveFromListEvent(const Event_RemoveFromList &event);
void addToIgnoreList();
void addToBuddyList();
private:
AbstractClient *client;
UserList *allUsersList;
UserList *buddyList;
UserList *ignoreList;
UserInfoBox *userInfoBox;
LineEditUnfocusable *addBuddyEdit;
LineEditUnfocusable *addIgnoreEdit;
void addToList(const std::string &listName, const QString &userName);
public:
TabUserLists(TabSupervisor *_tabSupervisor,
AbstractClient *_client,
const ServerInfo_User &userInfo,
QWidget *parent = nullptr);
void retranslateUi();
QString getTabText() const
{
return tr("Account");
}
const UserList *getAllUsersList() const
{
return allUsersList;
}
const UserList *getBuddyList() const
{
return buddyList;
}
const UserList *getIgnoreList() const
{
return ignoreList;
}
};
#endif

View file

@ -0,0 +1,148 @@
#include "tab_admin.h"
#include "../game_logic/abstract_client.h"
#include "pb/admin_commands.pb.h"
#include "trice_limits.h"
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>
#include <QSpinBox>
#include <QVBoxLayout>
ShutdownDialog::ShutdownDialog(QWidget *parent) : QDialog(parent)
{
QLabel *reasonLabel = new QLabel(tr("&Reason for shutdown:"));
reasonEdit = new QLineEdit;
reasonEdit->setMaxLength(MAX_TEXT_LENGTH);
reasonLabel->setBuddy(reasonEdit);
QLabel *minutesLabel = new QLabel(tr("&Time until shutdown (minutes):"));
minutesEdit = new QSpinBox;
minutesLabel->setBuddy(minutesEdit);
minutesEdit->setMinimum(0);
minutesEdit->setValue(5);
minutesEdit->setMaximum(999);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(reasonLabel, 0, 0);
mainLayout->addWidget(reasonEdit, 0, 1);
mainLayout->addWidget(minutesLabel, 1, 0);
mainLayout->addWidget(minutesEdit, 1, 1);
mainLayout->addWidget(buttonBox, 2, 0, 1, 2);
setLayout(mainLayout);
setWindowTitle(tr("Shut down server"));
}
QString ShutdownDialog::getReason() const
{
return reasonEdit->text();
}
int ShutdownDialog::getMinutes() const
{
return minutesEdit->value();
}
TabAdmin::TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, bool _fullAdmin, QWidget *parent)
: Tab(_tabSupervisor, parent), locked(true), client(_client), fullAdmin(_fullAdmin)
{
updateServerMessageButton = new QPushButton;
connect(updateServerMessageButton, SIGNAL(clicked()), this, SLOT(actUpdateServerMessage()));
shutdownServerButton = new QPushButton;
connect(shutdownServerButton, SIGNAL(clicked()), this, SLOT(actShutdownServer()));
reloadConfigButton = new QPushButton;
connect(reloadConfigButton, SIGNAL(clicked()), this, SLOT(actReloadConfig()));
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(updateServerMessageButton);
vbox->addWidget(shutdownServerButton);
vbox->addWidget(reloadConfigButton);
vbox->addStretch();
adminGroupBox = new QGroupBox;
adminGroupBox->setLayout(vbox);
adminGroupBox->setEnabled(false);
unlockButton = new QPushButton;
connect(unlockButton, SIGNAL(clicked()), this, SLOT(actUnlock()));
lockButton = new QPushButton;
lockButton->setEnabled(false);
connect(lockButton, SIGNAL(clicked()), this, SLOT(actLock()));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(adminGroupBox);
mainLayout->addWidget(unlockButton);
mainLayout->addWidget(lockButton);
retranslateUi();
QWidget *mainWidget = new QWidget(this);
mainWidget->setLayout(mainLayout);
setCentralWidget(mainWidget);
actUnlock();
}
void TabAdmin::retranslateUi()
{
updateServerMessageButton->setText(tr("Update server &message"));
shutdownServerButton->setText(tr("&Shut down server"));
reloadConfigButton->setText(tr("&Reload configuration"));
adminGroupBox->setTitle(tr("Server administration functions"));
unlockButton->setText(tr("&Unlock functions"));
lockButton->setText(tr("&Lock functions"));
}
void TabAdmin::actUpdateServerMessage()
{
client->sendCommand(client->prepareAdminCommand(Command_UpdateServerMessage()));
}
void TabAdmin::actShutdownServer()
{
ShutdownDialog dlg;
if (dlg.exec()) {
Command_ShutdownServer cmd;
cmd.set_reason(dlg.getReason().toStdString());
cmd.set_minutes(dlg.getMinutes());
client->sendCommand(client->prepareAdminCommand(cmd));
}
}
void TabAdmin::actReloadConfig()
{
Command_ReloadConfig cmd;
client->sendCommand(client->prepareAdminCommand(cmd));
}
void TabAdmin::actUnlock()
{
if (fullAdmin)
adminGroupBox->setEnabled(true);
lockButton->setEnabled(true);
unlockButton->setEnabled(false);
locked = false;
emit adminLockChanged(false);
}
void TabAdmin::actLock()
{
if (fullAdmin)
adminGroupBox->setEnabled(false);
lockButton->setEnabled(false);
unlockButton->setEnabled(true);
locked = true;
emit adminLockChanged(true);
}

View file

@ -0,0 +1,61 @@
#ifndef TAB_ADMIN_H
#define TAB_ADMIN_H
#include "tab.h"
#include <QDialog>
class AbstractClient;
class QGroupBox;
class QPushButton;
class QSpinBox;
class QLineEdit;
class ShutdownDialog : public QDialog
{
Q_OBJECT
private:
QLineEdit *reasonEdit;
QSpinBox *minutesEdit;
public:
ShutdownDialog(QWidget *parent = nullptr);
QString getReason() const;
int getMinutes() const;
};
class TabAdmin : public Tab
{
Q_OBJECT
private:
bool locked;
AbstractClient *client;
bool fullAdmin;
QPushButton *updateServerMessageButton, *shutdownServerButton, *reloadConfigButton;
QGroupBox *adminGroupBox;
QPushButton *unlockButton, *lockButton;
signals:
void adminLockChanged(bool lock);
private slots:
void actUpdateServerMessage();
void actShutdownServer();
void actReloadConfig();
void actUnlock();
void actLock();
public:
TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, bool _fullAdmin, QWidget *parent = nullptr);
void retranslateUi();
QString getTabText() const
{
return tr("Administration");
}
bool getLocked() const
{
return locked;
}
};
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,170 @@
#ifndef WINDOW_DECKEDITOR_H
#define WINDOW_DECKEDITOR_H
#include "../../deck/custom_line_edit.h"
#include "../../game/cards/card_database.h"
#include "../game_logic/key_signals.h"
#include "tab.h"
#include <QAbstractItemModel>
#include <QDir>
class CardDatabaseModel;
class CardDatabaseDisplayModel;
class DeckListModel;
class QTreeView;
class CardFrame;
class QTextEdit;
class QLabel;
class DeckLoader;
class Response;
class FilterTreeModel;
class FilterBuilder;
class QGroupBox;
class QHBoxLayout;
class QVBoxLayout;
class QPushButton;
class QDockWidget;
class SearchLineEdit : public LineEditUnfocusable
{
private:
QTreeView *treeView;
protected:
void keyPressEvent(QKeyEvent *event) override;
public:
SearchLineEdit() : LineEditUnfocusable(), treeView(nullptr)
{
}
void setTreeView(QTreeView *_treeView)
{
treeView = _treeView;
}
};
class TabDeckEditor : public Tab
{
Q_OBJECT
private slots:
void updateName(const QString &name);
void updateComments();
void updateHash();
void updateCardInfoLeft(const QModelIndex &current, const QModelIndex &previous);
void updateCardInfoRight(const QModelIndex &current, const QModelIndex &previous);
void updateSearch(const QString &search);
void databaseCustomMenu(QPoint point);
void actNewDeck();
void actLoadDeck();
bool actSaveDeck();
bool actSaveDeckAs();
void actLoadDeckFromClipboard();
void actSaveDeckToClipboard();
void actSaveDeckToClipboardRaw();
void actPrintDeck();
void actExportDeckDecklist();
void actAnalyzeDeckDeckstats();
void actAnalyzeDeckTappedout();
void actClearFilterAll();
void actClearFilterOne();
void actSwapCard();
void actAddCard();
void actAddCardToSideboard();
void actRemoveCard();
void actIncrement();
void actDecrement();
void actDecrementCard();
void actDecrementCardFromSideboard();
void copyDatabaseCellContents();
void saveDeckRemoteFinished(const Response &r);
void filterViewCustomContextMenu(const QPoint &point);
void filterRemove(QAction *action);
void loadLayout();
void restartLayout();
void freeDocksSize();
void refreshShortcuts();
bool eventFilter(QObject *o, QEvent *e) override;
void dockVisibleTriggered();
void dockFloatingTriggered();
void dockTopLevelChanged(bool topLevel);
void saveDbHeaderState();
void setSaveStatus(bool newStatus);
void showSearchSyntaxHelp();
private:
CardInfoPtr currentCardInfo() const;
void addCardHelper(QString zoneName);
void offsetCountAtIndex(const QModelIndex &idx, int offset);
void decrementCardHelper(QString zoneName);
void recursiveExpand(const QModelIndex &index);
CardDatabaseModel *databaseModel;
CardDatabaseDisplayModel *databaseDisplayModel;
DeckListModel *deckModel;
QTreeView *databaseView;
QTreeView *deckView;
KeySignals deckViewKeySignals;
CardFrame *cardInfo;
SearchLineEdit *searchEdit;
KeySignals searchKeySignals;
QLabel *nameLabel;
LineEditUnfocusable *nameEdit;
QLabel *commentsLabel;
QTextEdit *commentsEdit;
QLabel *hashLabel1;
LineEditUnfocusable *hashLabel;
FilterTreeModel *filterModel;
QTreeView *filterView;
KeySignals filterViewKeySignals;
QWidget *filterBox;
QMenu *deckMenu, *viewMenu, *cardInfoDockMenu, *deckDockMenu, *filterDockMenu, *analyzeDeckMenu,
*saveDeckToClipboardMenu;
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard,
*aSaveDeckToClipboardRaw, *aPrintDeck, *aExportDeckDecklist, *aAnalyzeDeckDeckstats, *aAnalyzeDeckTappedout,
*aClose;
QAction *aClearFilterAll, *aClearFilterOne;
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;
QAction *aResetLayout;
QAction *aCardInfoDockVisible, *aCardInfoDockFloating, *aDeckDockVisible, *aDeckDockFloating, *aFilterDockVisible,
*aFilterDockFloating;
bool modified;
QVBoxLayout *centralFrame;
QHBoxLayout *searchLayout;
QDockWidget *cardInfoDock;
QDockWidget *deckDock;
QDockWidget *filterDock;
QWidget *centralWidget;
public:
explicit TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent = nullptr);
~TabDeckEditor() override;
void retranslateUi() override;
QString getTabText() const override;
void setDeck(DeckLoader *_deckLoader);
void setModified(bool _windowModified);
bool confirmClose();
void createDeckDock();
void createCardInfoDock();
void createFiltersDock();
void createMenus();
void createCentralFrame();
public slots:
void closeRequest() override;
signals:
void deckEditorClosing(TabDeckEditor *tab);
};
#endif

View file

@ -0,0 +1,414 @@
#include "tab_deck_storage.h"
#include "../../deck/deck_loader.h"
#include "../../server/pending_command.h"
#include "../../server/remote/remote_decklist_tree_widget.h"
#include "../../settings/cache_settings.h"
#include "../game_logic/abstract_client.h"
#include "../get_text_with_max.h"
#include "decklist.h"
#include "pb/command_deck_del.pb.h"
#include "pb/command_deck_del_dir.pb.h"
#include "pb/command_deck_download.pb.h"
#include "pb/command_deck_new_dir.pb.h"
#include "pb/command_deck_upload.pb.h"
#include "pb/response.pb.h"
#include "pb/response_deck_download.pb.h"
#include "pb/response_deck_upload.pb.h"
#include <QAction>
#include <QApplication>
#include <QDebug>
#include <QFileSystemModel>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QInputDialog>
#include <QMessageBox>
#include <QToolBar>
#include <QTreeView>
#include <QVBoxLayout>
TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client)
: Tab(_tabSupervisor), client(_client)
{
localDirModel = new QFileSystemModel(this);
localDirModel->setRootPath(SettingsCache::instance().getDeckPath());
localDirModel->sort(0, Qt::AscendingOrder);
localDirView = new QTreeView;
localDirView->setModel(localDirModel);
localDirView->setColumnHidden(1, true);
localDirView->setRootIndex(localDirModel->index(localDirModel->rootPath(), 0));
localDirView->setSortingEnabled(true);
localDirView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
localDirView->header()->setSortIndicator(0, Qt::AscendingOrder);
leftToolBar = new QToolBar;
leftToolBar->setOrientation(Qt::Horizontal);
leftToolBar->setIconSize(QSize(32, 32));
QHBoxLayout *leftToolBarLayout = new QHBoxLayout;
leftToolBarLayout->addStretch();
leftToolBarLayout->addWidget(leftToolBar);
leftToolBarLayout->addStretch();
QVBoxLayout *leftVbox = new QVBoxLayout;
leftVbox->addWidget(localDirView);
leftVbox->addLayout(leftToolBarLayout);
leftGroupBox = new QGroupBox;
leftGroupBox->setLayout(leftVbox);
rightToolBar = new QToolBar;
rightToolBar->setOrientation(Qt::Horizontal);
rightToolBar->setIconSize(QSize(32, 32));
QHBoxLayout *rightToolBarLayout = new QHBoxLayout;
rightToolBarLayout->addStretch();
rightToolBarLayout->addWidget(rightToolBar);
rightToolBarLayout->addStretch();
serverDirView = new RemoteDeckList_TreeWidget(client);
QVBoxLayout *rightVbox = new QVBoxLayout;
rightVbox->addWidget(serverDirView);
rightVbox->addLayout(rightToolBarLayout);
rightGroupBox = new QGroupBox;
rightGroupBox->setLayout(rightVbox);
QHBoxLayout *hbox = new QHBoxLayout;
hbox->addWidget(leftGroupBox);
hbox->addWidget(rightGroupBox);
aOpenLocalDeck = new QAction(this);
aOpenLocalDeck->setIcon(QPixmap("theme:icons/pencil"));
connect(aOpenLocalDeck, SIGNAL(triggered()), this, SLOT(actOpenLocalDeck()));
aUpload = new QAction(this);
aUpload->setIcon(QPixmap("theme:icons/arrow_right_green"));
connect(aUpload, SIGNAL(triggered()), this, SLOT(actUpload()));
aDeleteLocalDeck = new QAction(this);
aDeleteLocalDeck->setIcon(QPixmap("theme:icons/remove_row"));
connect(aDeleteLocalDeck, SIGNAL(triggered()), this, SLOT(actDeleteLocalDeck()));
aOpenRemoteDeck = new QAction(this);
aOpenRemoteDeck->setIcon(QPixmap("theme:icons/pencil"));
connect(aOpenRemoteDeck, SIGNAL(triggered()), this, SLOT(actOpenRemoteDeck()));
aDownload = new QAction(this);
aDownload->setIcon(QPixmap("theme:icons/arrow_left_green"));
connect(aDownload, SIGNAL(triggered()), this, SLOT(actDownload()));
aNewFolder = new QAction(this);
aNewFolder->setIcon(qApp->style()->standardIcon(QStyle::SP_FileDialogNewFolder));
connect(aNewFolder, SIGNAL(triggered()), this, SLOT(actNewFolder()));
aDeleteRemoteDeck = new QAction(this);
aDeleteRemoteDeck->setIcon(QPixmap("theme:icons/remove_row"));
connect(aDeleteRemoteDeck, SIGNAL(triggered()), this, SLOT(actDeleteRemoteDeck()));
leftToolBar->addAction(aOpenLocalDeck);
leftToolBar->addAction(aUpload);
leftToolBar->addAction(aDeleteLocalDeck);
rightToolBar->addAction(aOpenRemoteDeck);
rightToolBar->addAction(aDownload);
rightToolBar->addAction(aNewFolder);
rightToolBar->addAction(aDeleteRemoteDeck);
retranslateUi();
QWidget *mainWidget = new QWidget(this);
mainWidget->setLayout(hbox);
setCentralWidget(mainWidget);
}
void TabDeckStorage::retranslateUi()
{
leftGroupBox->setTitle(tr("Local file system"));
rightGroupBox->setTitle(tr("Server deck storage"));
aOpenLocalDeck->setText(tr("Open in deck editor"));
aUpload->setText(tr("Upload deck"));
aOpenRemoteDeck->setText(tr("Open in deck editor"));
aDownload->setText(tr("Download deck"));
aNewFolder->setText(tr("New folder"));
aDeleteLocalDeck->setText(tr("Delete"));
aDeleteRemoteDeck->setText(tr("Delete"));
}
QString TabDeckStorage::getTargetPath() const
{
RemoteDeckList_TreeModel::Node *curRight = serverDirView->getCurrentItem();
if (curRight == nullptr)
return {};
auto *dir = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight);
if (dir == nullptr) {
dir = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight->getParent());
if (dir != nullptr) {
return dir->getPath();
} else {
return {};
}
} else {
return dir->getPath();
}
}
void TabDeckStorage::actOpenLocalDeck()
{
QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
if (localDirModel->isDir(curLeft))
return;
QString filePath = localDirModel->filePath(curLeft);
DeckLoader deckLoader;
if (!deckLoader.loadFromFile(filePath, DeckLoader::CockatriceFormat))
return;
emit openDeckEditor(&deckLoader);
}
void TabDeckStorage::actUpload()
{
QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
if (localDirModel->isDir(curLeft))
return;
QString targetPath = getTargetPath();
if (targetPath.length() > MAX_NAME_LENGTH) {
qCritical() << "target path to upload to is too long" << targetPath;
return;
}
QString filePath = localDirModel->filePath(curLeft);
QFile deckFile(filePath);
QFileInfo deckFileInfo(deckFile);
QString deckString;
DeckLoader deck;
bool error = !deck.loadFromFile(filePath, DeckLoader::CockatriceFormat);
if (!error) {
deckString = deck.writeToString_Native();
error = deckString.length() > MAX_FILE_LENGTH;
}
if (error) {
QMessageBox::critical(this, tr("Error"), tr("Invalid deck file"));
return;
}
if (deck.getName().isEmpty()) {
bool ok;
QString deckName =
getTextWithMax(this, tr("Enter deck name"), tr("This decklist does not have a name.\nPlease enter a name:"),
QLineEdit::Normal, deckFileInfo.completeBaseName(), &ok);
if (!ok)
return;
if (deckName.isEmpty())
deckName = tr("Unnamed deck");
deck.setName(deckName);
} else {
deck.setName(deck.getName().left(MAX_NAME_LENGTH));
}
Command_DeckUpload cmd;
cmd.set_path(targetPath.toStdString());
cmd.set_deck_list(deckString.toStdString());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(uploadFinished(Response, CommandContainer)));
client->sendCommand(pend);
}
void TabDeckStorage::uploadFinished(const Response &r, const CommandContainer &commandContainer)
{
if (r.response_code() != Response::RespOk) {
qCritical() << "failed to upload deck:" << r.response_code();
QMessageBox::critical(this, tr("Error"), tr("Failed to upload deck to server"));
return;
}
const Response_DeckUpload &resp = r.GetExtension(Response_DeckUpload::ext);
const Command_DeckUpload &cmd = commandContainer.session_command(0).GetExtension(Command_DeckUpload::ext);
serverDirView->addFileToTree(resp.new_file(), serverDirView->getNodeByPath(QString::fromStdString(cmd.path())));
}
void TabDeckStorage::actDeleteLocalDeck()
{
QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
if (localDirModel->isDir(curLeft))
return;
if (QMessageBox::warning(this, tr("Delete local file"),
tr("Are you sure you want to delete \"%1\"?").arg(localDirModel->fileName(curLeft)),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
return;
localDirModel->remove(curLeft);
}
void TabDeckStorage::actOpenRemoteDeck()
{
RemoteDeckList_TreeModel::FileNode *curRight =
dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(serverDirView->getCurrentItem());
if (!curRight)
return;
Command_DeckDownload cmd;
cmd.set_deck_id(curRight->getId());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(openRemoteDeckFinished(Response, CommandContainer)));
client->sendCommand(pend);
}
void TabDeckStorage::openRemoteDeckFinished(const Response &r, const CommandContainer &commandContainer)
{
if (r.response_code() != Response::RespOk)
return;
const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext);
const Command_DeckDownload &cmd = commandContainer.session_command(0).GetExtension(Command_DeckDownload::ext);
DeckLoader loader;
if (!loader.loadFromRemote(QString::fromStdString(resp.deck()), cmd.deck_id()))
return;
emit openDeckEditor(&loader);
}
void TabDeckStorage::actDownload()
{
QString filePath;
QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
if (!curLeft.isValid())
filePath = localDirModel->rootPath();
else {
while (!localDirModel->isDir(curLeft))
curLeft = curLeft.parent();
filePath = localDirModel->filePath(curLeft);
}
RemoteDeckList_TreeModel::FileNode *curRight =
dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(serverDirView->getCurrentItem());
if (!curRight)
return;
filePath += QString("/deck_%1.cod").arg(curRight->getId());
Command_DeckDownload cmd;
cmd.set_deck_id(curRight->getId());
PendingCommand *pend = client->prepareSessionCommand(cmd);
pend->setExtraData(filePath);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(downloadFinished(Response, CommandContainer, QVariant)));
client->sendCommand(pend);
}
void TabDeckStorage::downloadFinished(const Response &r,
const CommandContainer & /*commandContainer*/,
const QVariant &extraData)
{
if (r.response_code() != Response::RespOk)
return;
const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext);
QString filePath = extraData.toString();
DeckLoader deck(QString::fromStdString(resp.deck()));
deck.saveToFile(filePath, DeckLoader::CockatriceFormat);
}
void TabDeckStorage::actNewFolder()
{
QString targetPath = getTargetPath();
int max_length = MAX_NAME_LENGTH - targetPath.length() - 1; // generated length would be path + / + name
if (max_length < 1) // can't create path that's short enough
return;
QString folderName = getTextWithMax(this, tr("New folder"), tr("Name of new folder:"), max_length);
if (folderName.isEmpty())
return;
// '/' isn't a valid filename character on *nix so we're choosing to replace it with a different arbitrary
// character.
std::string folder = folderName.toStdString();
std::replace(folder.begin(), folder.end(), '/', '-');
Command_DeckNewDir cmd;
cmd.set_path(targetPath.toStdString());
cmd.set_dir_name(folder);
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(newFolderFinished(Response, CommandContainer)));
client->sendCommand(pend);
}
void TabDeckStorage::newFolderFinished(const Response &response, const CommandContainer &commandContainer)
{
if (response.response_code() != Response::RespOk)
return;
const Command_DeckNewDir &cmd = commandContainer.session_command(0).GetExtension(Command_DeckNewDir::ext);
serverDirView->addFolderToTree(QString::fromStdString(cmd.dir_name()),
serverDirView->getNodeByPath(QString::fromStdString(cmd.path())));
}
void TabDeckStorage::actDeleteRemoteDeck()
{
PendingCommand *pend;
RemoteDeckList_TreeModel::Node *curRight = serverDirView->getCurrentItem();
if (!curRight)
return;
RemoteDeckList_TreeModel::DirectoryNode *dir = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight);
if (dir) {
QString targetPath = dir->getPath();
if (targetPath.isEmpty())
return;
if (targetPath.length() > MAX_NAME_LENGTH) {
qCritical() << "target path to delete is too long" << targetPath;
return;
}
if (QMessageBox::warning(this, tr("Delete remote folder"),
tr("Are you sure you want to delete \"%1\"?").arg(targetPath),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
return;
Command_DeckDelDir cmd;
cmd.set_path(targetPath.toStdString());
pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(deleteFolderFinished(Response, CommandContainer)));
} else {
RemoteDeckList_TreeModel::FileNode *deckNode = dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(curRight);
if (QMessageBox::warning(this, tr("Delete remote deck"),
tr("Are you sure you want to delete \"%1\"?").arg(deckNode->getName()),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
return;
Command_DeckDel cmd;
cmd.set_deck_id(deckNode->getId());
pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(deleteDeckFinished(Response, CommandContainer)));
}
client->sendCommand(pend);
}
void TabDeckStorage::deleteDeckFinished(const Response &response, const CommandContainer &commandContainer)
{
if (response.response_code() != Response::RespOk)
return;
const Command_DeckDel &cmd = commandContainer.session_command(0).GetExtension(Command_DeckDel::ext);
RemoteDeckList_TreeModel::Node *toDelete = serverDirView->getNodeById(cmd.deck_id());
if (toDelete)
serverDirView->removeNode(toDelete);
}
void TabDeckStorage::deleteFolderFinished(const Response &response, const CommandContainer &commandContainer)
{
if (response.response_code() != Response::RespOk)
return;
const Command_DeckDelDir &cmd = commandContainer.session_command(0).GetExtension(Command_DeckDelDir::ext);
RemoteDeckList_TreeModel::Node *toDelete = serverDirView->getNodeByPath(QString::fromStdString(cmd.path()));
if (toDelete)
serverDirView->removeNode(toDelete);
}

View file

@ -0,0 +1,63 @@
#ifndef TAB_DECK_STORAGE_H
#define TAB_DECK_STORAGE_H
#include "tab.h"
class AbstractClient;
class QTreeView;
class QFileSystemModel;
class QToolBar;
class QTreeWidget;
class QTreeWidgetItem;
class QGroupBox;
class RemoteDeckList_TreeWidget;
class CommandContainer;
class Response;
class DeckLoader;
class TabDeckStorage : public Tab
{
Q_OBJECT
private:
AbstractClient *client;
QTreeView *localDirView;
QFileSystemModel *localDirModel;
QToolBar *leftToolBar, *rightToolBar;
RemoteDeckList_TreeWidget *serverDirView;
QGroupBox *leftGroupBox, *rightGroupBox;
QAction *aOpenLocalDeck, *aUpload, *aDeleteLocalDeck, *aOpenRemoteDeck, *aDownload, *aNewFolder, *aDeleteRemoteDeck;
QString getTargetPath() const;
private slots:
void actOpenLocalDeck();
void actUpload();
void uploadFinished(const Response &r, const CommandContainer &commandContainer);
void actDeleteLocalDeck();
void actOpenRemoteDeck();
void openRemoteDeckFinished(const Response &r, const CommandContainer &commandContainer);
void actDownload();
void downloadFinished(const Response &r, const CommandContainer &commandContainer, const QVariant &extraData);
void actNewFolder();
void newFolderFinished(const Response &response, const CommandContainer &commandContainer);
void actDeleteRemoteDeck();
void deleteFolderFinished(const Response &response, const CommandContainer &commandContainer);
void deleteDeckFinished(const Response &response, const CommandContainer &commandContainer);
public:
TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client);
void retranslateUi();
QString getTabText() const
{
return tr("Deck storage");
}
signals:
void openDeckEditor(const DeckLoader *deckLoader);
};
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,315 @@
#ifndef TAB_GAME_H
#define TAB_GAME_H
#include "../../client/tearoff_menu.h"
#include "pb/event_leave.pb.h"
#include "pb/serverinfo_game.pb.h"
#include "tab.h"
#include <QCompleter>
#include <QMap>
#include <QPushButton>
class AbstractClient;
class CardDatabase;
class GameView;
class DeckView;
class GameScene;
class CardFrame;
class MessageLogWidget;
class QTimer;
class QSplitter;
class QLabel;
class QPushButton;
class QToolButton;
class QMenu;
class ZoneViewLayout;
class ZoneViewWidget;
class PhasesToolbar;
class PlayerListWidget;
class ReplayTimelineWidget;
class Response;
class GameEventContainer;
class GameEventContext;
class GameCommand;
class CommandContainer;
class Event_GameJoined;
class Event_GameStateChanged;
class Event_PlayerPropertiesChanged;
class Event_Join;
class Event_Leave;
class Event_GameHostChanged;
class Event_GameClosed;
class Event_GameStart;
class Event_SetActivePlayer;
class Event_SetActivePhase;
class Event_Ping;
class Event_GameSay;
class Event_Kicked;
class Event_ReverseTurn;
class Player;
class CardZone;
class AbstractCardItem;
class CardItem;
class TabGame;
class DeckLoader;
class QVBoxLayout;
class QHBoxLayout;
class GameReplay;
class ServerInfo_User;
class PendingCommand;
class LineEditCompleter;
class QDockWidget;
class QStackedWidget;
class ToggleButton : public QPushButton
{
Q_OBJECT
private:
bool state;
signals:
void stateChanged();
public:
ToggleButton(QWidget *parent = nullptr);
bool getState() const
{
return state;
}
void setState(bool _state);
protected:
void paintEvent(QPaintEvent *event);
};
class DeckViewContainer : public QWidget
{
Q_OBJECT
private:
QPushButton *loadLocalButton, *loadRemoteButton;
ToggleButton *readyStartButton, *sideboardLockButton;
DeckView *deckView;
TabGame *parentGame;
int playerId;
private slots:
void loadLocalDeck();
void loadRemoteDeck();
void readyStart();
void deckSelectFinished(const Response &r);
void sideboardPlanChanged();
void sideboardLockButtonClicked();
void updateSideboardLockButtonText();
void refreshShortcuts();
signals:
void newCardAdded(AbstractCardItem *card);
void notIdle();
public:
DeckViewContainer(int _playerId, TabGame *parent);
void retranslateUi();
void setButtonsVisible(bool _visible);
void setReadyStart(bool ready);
void setSideboardLocked(bool locked);
void setDeck(const DeckLoader &deck);
};
class TabGame : public Tab
{
Q_OBJECT
private:
QTimer *gameTimer;
int secondsElapsed;
QList<AbstractClient *> clients;
ServerInfo_Game gameInfo;
QMap<int, QString> roomGameTypes;
int hostId;
int localPlayerId;
const bool isLocalGame;
bool spectator;
bool judge;
QMap<int, Player *> players;
QMap<int, ServerInfo_User> spectators;
bool gameStateKnown;
bool resuming;
QStringList phasesList;
int currentPhase;
int activePlayer;
CardItem *activeCard;
bool gameClosed;
QStringList gameTypes;
QCompleter *completer;
QStringList autocompleteUserList;
QStackedWidget *mainWidget;
// Replay related members
GameReplay *replay;
int currentReplayStep;
QList<int> replayTimeline;
ReplayTimelineWidget *timelineWidget;
QToolButton *replayPlayButton, *replayFastForwardButton;
CardFrame *cardInfo;
PlayerListWidget *playerListWidget;
QLabel *timeElapsedLabel;
MessageLogWidget *messageLog;
QLabel *sayLabel;
LineEditCompleter *sayEdit;
PhasesToolbar *phasesToolbar;
GameScene *scene;
GameView *gameView;
QMap<int, DeckViewContainer *> deckViewContainers;
QVBoxLayout *cardVInfoLayout, *messageLogLayout, *gamePlayAreaVBox, *deckViewContainerLayout;
QHBoxLayout *cardHInfoLayout, *sayHLayout, *mainHLayout, *replayControlLayout;
QWidget *cardBoxLayoutWidget, *messageLogLayoutWidget, *gamePlayAreaWidget, *deckViewContainerWidget,
*replayControlWidget;
QDockWidget *cardInfoDock, *messageLayoutDock, *playerListDock, *replayDock;
QAction *playersSeparator;
QMenu *gameMenu, *viewMenu, *cardInfoDockMenu, *messageLayoutDockMenu, *playerListDockMenu, *replayDockMenu;
TearOffMenu *phasesMenu;
QAction *aGameInfo, *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextPhaseAction, *aNextTurn,
*aReverseTurn, *aRemoveLocalArrows, *aRotateViewCW, *aRotateViewCCW, *aResetLayout, *aResetReplayLayout;
QAction *aCardInfoDockVisible, *aCardInfoDockFloating, *aMessageLayoutDockVisible, *aMessageLayoutDockFloating,
*aPlayerListDockVisible, *aPlayerListDockFloating, *aReplayDockVisible, *aReplayDockFloating;
QAction *aFocusChat;
QList<QAction *> phaseActions;
Player *addPlayer(int playerId, const ServerInfo_User &info);
void startGame(bool resuming);
void stopGame();
void closeGame();
void eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext &context);
void eventSpectatorLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context);
void eventGameStateChanged(const Event_GameStateChanged &event, int eventPlayerId, const GameEventContext &context);
void eventPlayerPropertiesChanged(const Event_PlayerPropertiesChanged &event,
int eventPlayerId,
const GameEventContext &context);
void eventJoin(const Event_Join &event, int eventPlayerId, const GameEventContext &context);
void eventLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context);
void eventKicked(const Event_Kicked &event, int eventPlayerId, const GameEventContext &context);
void eventGameHostChanged(const Event_GameHostChanged &event, int eventPlayerId, const GameEventContext &context);
void eventGameClosed(const Event_GameClosed &event, int eventPlayerId, const GameEventContext &context);
Player *setActivePlayer(int id);
void eventSetActivePlayer(const Event_SetActivePlayer &event, int eventPlayerId, const GameEventContext &context);
void setActivePhase(int phase);
void eventSetActivePhase(const Event_SetActivePhase &event, int eventPlayerId, const GameEventContext &context);
void eventPing(const Event_Ping &event, int eventPlayerId, const GameEventContext &context);
void eventReverseTurn(const Event_ReverseTurn &event, int eventPlayerId, const GameEventContext & /*context*/);
void emitUserEvent();
void createMenuItems();
void createReplayMenuItems();
void createViewMenuItems();
void createCardInfoDock(bool bReplay = false);
void createPlayerListDock(bool bReplay = false);
void createMessageDock(bool bReplay = false);
void createPlayAreaWidget(bool bReplay = false);
void createDeckViewContainerWidget(bool bReplay = false);
void createReplayDock();
QString getLeaveReason(Event_Leave::LeaveReason reason);
signals:
void gameClosing(TabGame *tab);
void playerAdded(Player *player);
void playerRemoved(Player *player);
void containerProcessingStarted(const GameEventContext &context);
void containerProcessingDone();
void openMessageDialog(const QString &userName, bool focus);
void openDeckEditor(const DeckLoader *deck);
void notIdle();
private slots:
void replayNextEvent();
void replayFinished();
void replayPlayButtonToggled(bool checked);
void replayFastForwardButtonToggled(bool checked);
void incrementGameTime();
void adminLockChanged(bool lock);
void newCardAdded(AbstractCardItem *card);
void updateCardMenu(AbstractCardItem *card);
void actGameInfo();
void actConcede();
void actLeaveGame();
void actRemoveLocalArrows();
void actRotateViewCW();
void actRotateViewCCW();
void actSay();
void actPhaseAction();
void actNextPhase();
void actNextPhaseAction();
void actNextTurn();
void actReverseTurn();
void addMentionTag(const QString &value);
void linkCardToChat(const QString &cardName);
void commandFinished(const Response &response);
void refreshShortcuts();
void loadLayout();
void actCompleterChanged();
void actResetLayout();
void freeDocksSize();
bool eventFilter(QObject *o, QEvent *e) override;
void dockVisibleTriggered();
void dockFloatingTriggered();
void dockTopLevelChanged(bool topLevel);
public:
TabGame(TabSupervisor *_tabSupervisor,
QList<AbstractClient *> &_clients,
const Event_GameJoined &event,
const QMap<int, QString> &_roomGameTypes);
TabGame(TabSupervisor *_tabSupervisor, GameReplay *replay);
~TabGame() override;
void retranslateUi() override;
void updatePlayerListDockTitle();
void closeRequest() override;
const QMap<int, Player *> &getPlayers() const
{
return players;
}
CardItem *getCard(int playerId, const QString &zoneName, int cardId) const;
bool isHost() const
{
return hostId == localPlayerId;
}
bool getIsLocalGame() const
{
return isLocalGame;
}
int getGameId() const
{
return gameInfo.game_id();
}
QString getTabText() const override;
bool getSpectator() const
{
return spectator;
}
bool getSpectatorsSeeEverything() const
{
return gameInfo.spectators_omniscient();
}
bool isSpectator();
Player *getActiveLocalPlayer() const;
AbstractClient *getClientForPlayer(int playerId) const;
void setActiveCard(CardItem *card);
CardItem *getActiveCard() const
{
return activeCard;
}
void processGameEventContainer(const GameEventContainer &cont, AbstractClient *client);
PendingCommand *prepareGameCommand(const ::google::protobuf::Message &cmd);
PendingCommand *prepareGameCommand(const QList<const ::google::protobuf::Message *> &cmdList);
public slots:
void sendGameCommand(PendingCommand *pend, int playerId = -1);
void sendGameCommand(const ::google::protobuf::Message &command, int playerId = -1);
void viewCardInfo(const QString &cardName);
};
#endif

View file

@ -0,0 +1,350 @@
#include "tab_logs.h"
#include "../../deck/custom_line_edit.h"
#include "../../dialogs/dlg_manage_sets.h"
#include "../../server/pending_command.h"
#include "../game_logic/abstract_client.h"
#include "pb/moderator_commands.pb.h"
#include "pb/response_viewlog_history.pb.h"
#include "trice_limits.h"
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
#include <QRadioButton>
#include <QSpinBox>
#include <QTabWidget>
#include <QtGui>
#include <QtWidgets>
TabLog::TabLog(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent)
: Tab(_tabSupervisor, parent), client(_client)
{
roomTable = new QTableWidget();
roomTable->setColumnCount(6);
roomTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
roomTable->setHorizontalHeaderLabels(
QString(tr("Time;SenderName;SenderIP;Message;TargetID;TargetName")).split(";"));
gameTable = new QTableWidget();
gameTable->setColumnCount(6);
gameTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
gameTable->setHorizontalHeaderLabels(
QString(tr("Time;SenderName;SenderIP;Message;TargetID;TargetName")).split(";"));
chatTable = new QTableWidget();
chatTable->setColumnCount(6);
chatTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chatTable->setHorizontalHeaderLabels(
QString(tr("Time;SenderName;SenderIP;Message;TargetID;TargetName")).split(";"));
QTabWidget *tabManager = new QTabWidget();
tabManager->addTab(roomTable, tr("Room Logs"));
tabManager->addTab(gameTable, tr("Game Logs"));
tabManager->addTab(chatTable, tr("Chat Logs"));
setCentralWidget(tabManager);
createDock();
restartLayout();
clearClicked();
retranslateUi();
}
TabLog::~TabLog()
{
}
void TabLog::retranslateUi()
{
}
void TabLog::getClicked()
{
if (findUsername->text().isEmpty() && findIPAddress->text().isEmpty() && findGameName->text().isEmpty() &&
findGameID->text().isEmpty() && findMessage->text().isEmpty()) {
QMessageBox::critical(this, tr("Error"), tr("You must select at least one filter."));
return;
}
if (!lastHour->isChecked() && !today->isChecked() && !pastDays->isChecked()) {
pastDays->setChecked(true);
pastXDays->setValue(20);
}
if (pastDays->isChecked() && pastXDays->value() == 0) {
QMessageBox::critical(this, tr("Error"), tr("You have to select a valid number of days to locate."));
return;
}
if (!mainRoom->isChecked() && !gameRoom->isChecked() && !privateChat->isChecked()) {
mainRoom->setChecked(true);
gameRoom->setChecked(true);
privateChat->setChecked(true);
}
if (maximumResults->value() == 0)
maximumResults->setValue(1000);
int dateRange = 0;
if (lastHour->isChecked())
dateRange = 1;
if (today->isChecked())
dateRange = 24;
if (pastDays->isChecked())
dateRange = pastXDays->value() * 24;
Command_ViewLogHistory cmd;
cmd.set_user_name(findUsername->text().toStdString());
cmd.set_ip_address(findIPAddress->text().toStdString());
cmd.set_game_name(findGameName->text().toStdString());
cmd.set_game_id(findGameID->text().toStdString());
cmd.set_message(findMessage->text().toStdString());
if (mainRoom->isChecked()) {
cmd.add_log_location("room");
};
if (gameRoom->isChecked()) {
cmd.add_log_location("game");
};
if (privateChat->isChecked()) {
cmd.add_log_location("chat");
};
cmd.set_date_range(dateRange);
cmd.set_maximum_results(maximumResults->value());
PendingCommand *pend = client->prepareModeratorCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(viewLogHistory_processResponse(Response)));
client->sendCommand(pend);
}
void TabLog::clearClicked()
{
findUsername->clear();
findIPAddress->clear();
findGameName->clear();
findGameID->clear();
findMessage->clear();
pastXDays->clear();
maximumResults->clear();
mainRoom->setChecked(false);
gameRoom->setChecked(false);
privateChat->setChecked(false);
pastDays->setAutoExclusive(false);
pastDays->setChecked(false);
today->setAutoExclusive(false);
today->setChecked(false);
lastHour->setAutoExclusive(false);
lastHour->setChecked(false);
pastDays->setAutoExclusive(true);
today->setAutoExclusive(true);
lastHour->setAutoExclusive(true);
}
void TabLog::createDock()
{
labelFindUserName = new QLabel(tr("Username: "));
findUsername = new LineEditUnfocusable("");
findUsername->setMaxLength(MAX_NAME_LENGTH);
findUsername->setAlignment(Qt::AlignCenter);
labelFindIPAddress = new QLabel(tr("IP Address: "));
findIPAddress = new LineEditUnfocusable("");
findIPAddress->setMaxLength(MAX_NAME_LENGTH);
findIPAddress->setAlignment(Qt::AlignCenter);
labelFindGameName = new QLabel(tr("Game Name: "));
findGameName = new LineEditUnfocusable("");
findGameName->setMaxLength(MAX_NAME_LENGTH);
findGameName->setAlignment(Qt::AlignCenter);
labelFindGameID = new QLabel(tr("GameID: "));
findGameID = new LineEditUnfocusable("");
findGameID->setMaxLength(MAX_NAME_LENGTH);
findGameID->setAlignment(Qt::AlignCenter);
labelMessage = new QLabel(tr("Message: "));
findMessage = new LineEditUnfocusable("");
findMessage->setMaxLength(MAX_TEXT_LENGTH);
findMessage->setAlignment(Qt::AlignCenter);
mainRoom = new QCheckBox(tr("Main Room"));
gameRoom = new QCheckBox(tr("Game Room"));
privateChat = new QCheckBox(tr("Private Chat"));
pastDays = new QRadioButton(tr("Past X Days: "));
today = new QRadioButton(tr("Today"));
lastHour = new QRadioButton(tr("Last Hour"));
pastXDays = new QSpinBox;
pastXDays->setMaximum(20);
labelMaximum = new QLabel(tr("Maximum Results: "));
maximumResults = new QSpinBox;
maximumResults->setMaximum(1000);
labelDescription = new QLabel(tr(
"At least one filter is required.\nThe more information you put in, the more specific your results will be."));
getButton = new QPushButton(tr("Get User Logs"));
getButton->setAutoDefault(true);
connect(getButton, SIGNAL(clicked()), this, SLOT(getClicked()));
clearButton = new QPushButton(tr("Clear Filters"));
clearButton->setAutoDefault(true);
connect(clearButton, SIGNAL(clicked()), this, SLOT(clearClicked()));
criteriaGrid = new QGridLayout;
criteriaGrid->addWidget(labelFindUserName, 0, 0);
criteriaGrid->addWidget(findUsername, 0, 1);
criteriaGrid->addWidget(labelFindIPAddress, 1, 0);
criteriaGrid->addWidget(findIPAddress, 1, 1);
criteriaGrid->addWidget(labelFindGameName, 2, 0);
criteriaGrid->addWidget(findGameName, 2, 1);
criteriaGrid->addWidget(labelFindGameID, 3, 0);
criteriaGrid->addWidget(findGameID, 3, 1);
criteriaGrid->addWidget(labelMessage, 4, 0);
criteriaGrid->addWidget(findMessage, 4, 1);
criteriaGroupBox = new QGroupBox(tr("Filters"));
criteriaGroupBox->setLayout(criteriaGrid);
criteriaGroupBox->setMaximumSize(500, 300);
criteriaGroupBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
locationGrid = new QGridLayout;
locationGrid->addWidget(mainRoom, 0, 0);
locationGrid->addWidget(gameRoom, 0, 1);
locationGrid->addWidget(privateChat, 0, 2);
locationGroupBox = new QGroupBox(tr("Log Locations"));
locationGroupBox->setLayout(locationGrid);
rangeGrid = new QGridLayout;
rangeGrid->addWidget(pastDays, 0, 0);
rangeGrid->addWidget(pastXDays, 0, 1);
rangeGrid->addWidget(today, 0, 2);
rangeGrid->addWidget(lastHour, 0, 3);
rangeGroupBox = new QGroupBox(tr("Date Range"));
rangeGroupBox->setLayout(rangeGrid);
maxResultsGrid = new QGridLayout;
maxResultsGrid->addWidget(labelMaximum, 0, 0);
maxResultsGrid->addWidget(maximumResults, 0, 1);
maxResultsGroupBox = new QGroupBox(tr("Maximum Results"));
maxResultsGroupBox->setLayout(maxResultsGrid);
descriptionGrid = new QGridLayout;
descriptionGrid->addWidget(labelDescription, 0, 0);
descriptionGroupBox = new QGroupBox(tr(""));
descriptionGroupBox->setLayout(descriptionGrid);
buttonGrid = new QGridLayout;
buttonGrid->addWidget(getButton, 0, 0);
buttonGrid->addWidget(clearButton, 0, 1);
buttonGroupBox = new QGroupBox(tr(""));
buttonGroupBox->setLayout(buttonGrid);
mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(criteriaGroupBox);
mainLayout->addWidget(locationGroupBox);
mainLayout->addWidget(rangeGroupBox);
mainLayout->addWidget(maxResultsGroupBox);
mainLayout->addWidget(descriptionGroupBox);
mainLayout->addWidget(buttonGroupBox);
mainLayout->setAlignment(Qt::AlignCenter);
searchDockContents = new QWidget(this);
searchDockContents->setLayout(mainLayout);
searchDock = new QDockWidget(this);
searchDock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
searchDock->setWidget(searchDockContents);
}
void TabLog::viewLogHistory_processResponse(const Response &resp)
{
const Response_ViewLogHistory &response = resp.GetExtension(Response_ViewLogHistory::ext);
if (resp.response_code() != Response::RespOk) {
QMessageBox::critical(static_cast<QWidget *>(parent()), tr("Message History"),
tr("Failed to collect message history information."));
return;
}
if (response.log_message_size() == 0) {
QMessageBox::information(static_cast<QWidget *>(parent()), tr("Message History"),
tr("There are no messages for the selected filters."));
return;
}
int roomCounter = 0, gameCounter = 0, chatCounter = 0;
roomTable->setRowCount(roomCounter);
gameTable->setRowCount(gameCounter);
chatTable->setRowCount(chatCounter);
for (int i = 0; i < response.log_message_size(); ++i) {
ServerInfo_ChatMessage message = response.log_message(i);
if (QString::fromStdString(message.target_type()) == "room") {
roomTable->insertRow(roomCounter);
roomTable->setItem(roomCounter, 0, new QTableWidgetItem(QString::fromStdString(message.time())));
roomTable->setItem(roomCounter, 1, new QTableWidgetItem(QString::fromStdString(message.sender_name())));
roomTable->setItem(roomCounter, 2, new QTableWidgetItem(QString::fromStdString(message.sender_ip())));
roomTable->setItem(roomCounter, 3, new QTableWidgetItem(QString::fromStdString(message.message())));
roomTable->setItem(roomCounter, 4, new QTableWidgetItem(QString::fromStdString(message.target_id())));
roomTable->setItem(roomCounter, 5, new QTableWidgetItem(QString::fromStdString(message.target_name())));
++roomCounter;
}
if (QString::fromStdString(message.target_type()) == "game") {
gameTable->insertRow(gameCounter);
gameTable->setItem(gameCounter, 0, new QTableWidgetItem(QString::fromStdString(message.time())));
gameTable->setItem(gameCounter, 1, new QTableWidgetItem(QString::fromStdString(message.sender_name())));
gameTable->setItem(gameCounter, 2, new QTableWidgetItem(QString::fromStdString(message.sender_ip())));
gameTable->setItem(gameCounter, 3, new QTableWidgetItem(QString::fromStdString(message.message())));
gameTable->setItem(gameCounter, 4, new QTableWidgetItem(QString::fromStdString(message.target_id())));
gameTable->setItem(gameCounter, 5, new QTableWidgetItem(QString::fromStdString(message.target_name())));
++gameCounter;
}
if (QString::fromStdString(message.target_type()) == "chat") {
chatTable->insertRow(chatCounter);
chatTable->setItem(chatCounter, 0, new QTableWidgetItem(QString::fromStdString(message.time())));
chatTable->setItem(chatCounter, 1, new QTableWidgetItem(QString::fromStdString(message.sender_name())));
chatTable->setItem(chatCounter, 2, new QTableWidgetItem(QString::fromStdString(message.sender_ip())));
chatTable->setItem(chatCounter, 3, new QTableWidgetItem(QString::fromStdString(message.message())));
chatTable->setItem(chatCounter, 4, new QTableWidgetItem(QString::fromStdString(message.target_id())));
chatTable->setItem(chatCounter, 5, new QTableWidgetItem(QString::fromStdString(message.target_name())));
++chatCounter;
}
}
if (roomCounter) {
roomTable->show();
roomTable->resizeColumnsToContents();
} else {
roomTable->hide();
}
if (gameCounter) {
gameTable->resizeColumnsToContents();
gameTable->show();
} else {
gameTable->hide();
}
if (chatCounter) {
chatTable->resizeColumnsToContents();
chatTable->show();
} else {
chatTable->hide();
}
}
void TabLog::restartLayout()
{
searchDock->setFloating(false);
addDockWidget(Qt::LeftDockWidgetArea, searchDock);
searchDock->setVisible(true);
}

View file

@ -0,0 +1,65 @@
#ifndef TAB_LOG_H
#define TAB_LOG_H
#include "tab.h"
#include <QDialog>
class AbstractClient;
class LineEditUnfocusable;
class QGroupBox;
class QPushButton;
class QSpinBox;
class QCheckBox;
class QRadioButton;
class QLabel;
class QDockWidget;
class QWidget;
class QGridLayout;
class QVBoxLayout;
class QTableWidget;
class CommandContainer;
class Response;
class AbstractClient;
class TabLog : public Tab
{
Q_OBJECT
private:
AbstractClient *client;
QLabel *labelFindUserName, *labelFindIPAddress, *labelFindGameName, *labelFindGameID, *labelMessage, *labelMaximum,
*labelDescription;
LineEditUnfocusable *findUsername, *findIPAddress, *findGameName, *findGameID, *findMessage;
QCheckBox *mainRoom, *gameRoom, *privateChat;
QRadioButton *pastDays, *today, *lastHour;
QSpinBox *maximumResults, *pastXDays;
QDockWidget *searchDock;
QWidget *searchDockContents;
QPushButton *getButton, *clearButton;
QGridLayout *criteriaGrid, *locationGrid, *rangeGrid, *maxResultsGrid, *descriptionGrid, *buttonGrid;
QGroupBox *criteriaGroupBox, *locationGroupBox, *rangeGroupBox, *maxResultsGroupBox, *descriptionGroupBox,
*buttonGroupBox;
QVBoxLayout *mainLayout;
QTableWidget *roomTable, *gameTable, *chatTable;
void createDock();
signals:
private slots:
void getClicked();
void clearClicked();
void viewLogHistory_processResponse(const Response &resp);
void restartLayout();
public:
TabLog(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent = nullptr);
~TabLog();
void retranslateUi();
QString getTabText() const
{
return tr("Logs");
}
};
#endif

View file

@ -0,0 +1,177 @@
#include "tab_message.h"
#include "../../deck/custom_line_edit.h"
#include "../../main.h"
#include "../../server/chat_view/chat_view.h"
#include "../../server/pending_command.h"
#include "../../settings/cache_settings.h"
#include "../game_logic/abstract_client.h"
#include "../sound_engine.h"
#include "pb/event_user_message.pb.h"
#include "pb/serverinfo_user.pb.h"
#include "pb/session_commands.pb.h"
#include "trice_limits.h"
#include <QApplication>
#include <QDebug>
#include <QMenu>
#include <QSystemTrayIcon>
#include <QVBoxLayout>
TabMessage::TabMessage(TabSupervisor *_tabSupervisor,
AbstractClient *_client,
const ServerInfo_User &_ownUserInfo,
const ServerInfo_User &_otherUserInfo)
: Tab(_tabSupervisor), client(_client), ownUserInfo(new ServerInfo_User(_ownUserInfo)),
otherUserInfo(new ServerInfo_User(_otherUserInfo)), userOnline(true)
{
chatView = new ChatView(tabSupervisor, tabSupervisor, 0, true);
connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
connect(chatView, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
connect(chatView, SIGNAL(addMentionTag(QString)), this, SLOT(addMentionTag(QString)));
sayEdit = new LineEditUnfocusable;
sayEdit->setMaxLength(MAX_TEXT_LENGTH);
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(sendMessage()));
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(chatView);
vbox->addWidget(sayEdit);
aLeave = new QAction(this);
connect(aLeave, SIGNAL(triggered()), this, SLOT(actLeave()));
messageMenu = new QMenu(this);
messageMenu->addAction(aLeave);
addTabMenu(messageMenu);
retranslateUi();
QWidget *mainWidget = new QWidget(this);
mainWidget->setLayout(vbox);
setCentralWidget(mainWidget);
}
TabMessage::~TabMessage()
{
emit talkClosing(this);
delete ownUserInfo;
delete otherUserInfo;
}
void TabMessage::addMentionTag(QString mentionTag)
{
sayEdit->insert(mentionTag + " ");
sayEdit->setFocus();
}
void TabMessage::retranslateUi()
{
messageMenu->setTitle(tr("Private &chat"));
aLeave->setText(tr("&Leave"));
}
void TabMessage::tabActivated()
{
if (!sayEdit->hasFocus())
sayEdit->setFocus();
}
QString TabMessage::getUserName() const
{
return QString::fromStdString(otherUserInfo->name());
}
QString TabMessage::getTabText() const
{
return tr("%1 - Private chat").arg(QString::fromStdString(otherUserInfo->name()));
}
void TabMessage::closeRequest()
{
actLeave();
}
void TabMessage::sendMessage()
{
if (sayEdit->text().isEmpty() || !userOnline)
return;
Command_Message cmd;
cmd.set_user_name(otherUserInfo->name());
cmd.set_message(sayEdit->text().toStdString());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(messageSent(const Response &)));
client->sendCommand(pend);
sayEdit->clear();
}
void TabMessage::messageSent(const Response &response)
{
if (response.response_code() == Response::RespInIgnoreList)
chatView->appendMessage(tr(
"This user is ignoring you, they cannot see your messages in main chat and you cannot join their games."));
}
void TabMessage::actLeave()
{
deleteLater();
}
void TabMessage::processUserMessageEvent(const Event_UserMessage &event)
{
auto userInfo = event.sender_name() == otherUserInfo->name() ? otherUserInfo : ownUserInfo;
const UserLevelFlags userLevel(userInfo->user_level());
const QString userPriv = QString::fromStdString(userInfo->privlevel());
chatView->appendMessage(QString::fromStdString(event.message()), {}, QString::fromStdString(event.sender_name()),
userLevel, userPriv, true);
if (tabSupervisor->currentIndex() != tabSupervisor->indexOf(this))
soundEngine->playSound("private_message");
if (SettingsCache::instance().getShowMessagePopup() && shouldShowSystemPopup(event))
showSystemPopup(event);
if (QString::fromStdString(event.sender_name()).toLower().simplified() == "servatrice")
sayEdit->setDisabled(true);
emit userEvent();
}
bool TabMessage::shouldShowSystemPopup(const Event_UserMessage &event)
{
return (QApplication::activeWindow() == 0 || QApplication::focusWidget() == 0 ||
(event.sender_name() == otherUserInfo->name() &&
tabSupervisor->currentIndex() != tabSupervisor->indexOf(this)));
}
void TabMessage::showSystemPopup(const Event_UserMessage &event)
{
if (trayIcon) {
disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0);
trayIcon->showMessage(tr("Private message from") + " " + otherUserInfo->name().c_str(),
event.message().c_str());
connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));
} else {
qDebug() << "Error: trayIcon is NULL. TabMessage::showSystemPopup failed";
}
}
void TabMessage::messageClicked()
{
tabSupervisor->setCurrentIndex(tabSupervisor->indexOf(this));
activateWindow();
emit maximizeClient();
}
void TabMessage::processUserLeft()
{
chatView->appendMessage(tr("%1 has left the server.").arg(QString::fromStdString(otherUserInfo->name())));
userOnline = false;
}
void TabMessage::processUserJoined(const ServerInfo_User &_userInfo)
{
chatView->appendMessage(tr("%1 has joined the server.").arg(QString::fromStdString(otherUserInfo->name())));
userOnline = true;
*otherUserInfo = _userInfo;
}

View file

@ -0,0 +1,59 @@
#ifndef TAB_MESSAGE_H
#define TAB_MESSAGE_H
#include "tab.h"
class AbstractClient;
class ChatView;
class LineEditUnfocusable;
class Event_UserMessage;
class Response;
class ServerInfo_User;
class TabMessage : public Tab
{
Q_OBJECT
private:
AbstractClient *client;
QMenu *messageMenu;
ServerInfo_User *ownUserInfo;
ServerInfo_User *otherUserInfo;
bool userOnline;
ChatView *chatView;
LineEditUnfocusable *sayEdit;
QAction *aLeave;
signals:
void talkClosing(TabMessage *tab);
void maximizeClient();
private slots:
void sendMessage();
void actLeave();
void messageSent(const Response &response);
void addMentionTag(QString mentionTag);
void messageClicked();
public:
TabMessage(TabSupervisor *_tabSupervisor,
AbstractClient *_client,
const ServerInfo_User &_ownUserInfo,
const ServerInfo_User &_otherUserInfo);
~TabMessage();
void retranslateUi();
void closeRequest();
void tabActivated();
QString getUserName() const;
QString getTabText() const;
void processUserMessageEvent(const Event_UserMessage &event);
void processUserLeft();
void processUserJoined(const ServerInfo_User &_userInfo);
private:
bool shouldShowSystemPopup(const Event_UserMessage &event);
void showSystemPopup(const Event_UserMessage &event);
};
#endif

View file

@ -0,0 +1,298 @@
#include "tab_replays.h"
#include "../../server/pending_command.h"
#include "../../server/remote/remote_replay_list_tree_widget.h"
#include "../../settings/cache_settings.h"
#include "../game_logic/abstract_client.h"
#include "pb/command_replay_delete_match.pb.h"
#include "pb/command_replay_download.pb.h"
#include "pb/command_replay_modify_match.pb.h"
#include "pb/event_replay_added.pb.h"
#include "pb/game_replay.pb.h"
#include "pb/response.pb.h"
#include "pb/response_replay_download.pb.h"
#include "tab_game.h"
#include <QAction>
#include <QApplication>
#include <QFileSystemModel>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QInputDialog>
#include <QMessageBox>
#include <QToolBar>
#include <QTreeView>
#include <QVBoxLayout>
TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client) : Tab(_tabSupervisor), client(_client)
{
localDirModel = new QFileSystemModel(this);
localDirModel->setRootPath(SettingsCache::instance().getReplaysPath());
localDirModel->sort(0, Qt::AscendingOrder);
localDirView = new QTreeView;
localDirView->setModel(localDirModel);
localDirView->setColumnHidden(1, true);
localDirView->setRootIndex(localDirModel->index(localDirModel->rootPath(), 0));
localDirView->setSortingEnabled(true);
localDirView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
localDirView->header()->setSortIndicator(0, Qt::AscendingOrder);
leftToolBar = new QToolBar;
leftToolBar->setOrientation(Qt::Horizontal);
leftToolBar->setIconSize(QSize(32, 32));
QHBoxLayout *leftToolBarLayout = new QHBoxLayout;
leftToolBarLayout->addStretch();
leftToolBarLayout->addWidget(leftToolBar);
leftToolBarLayout->addStretch();
QVBoxLayout *leftVbox = new QVBoxLayout;
leftVbox->addWidget(localDirView);
leftVbox->addLayout(leftToolBarLayout);
leftGroupBox = new QGroupBox;
leftGroupBox->setLayout(leftVbox);
rightToolBar = new QToolBar;
rightToolBar->setOrientation(Qt::Horizontal);
rightToolBar->setIconSize(QSize(32, 32));
QHBoxLayout *rightToolBarLayout = new QHBoxLayout;
rightToolBarLayout->addStretch();
rightToolBarLayout->addWidget(rightToolBar);
rightToolBarLayout->addStretch();
serverDirView = new RemoteReplayList_TreeWidget(client);
QVBoxLayout *rightVbox = new QVBoxLayout;
rightVbox->addWidget(serverDirView);
rightVbox->addLayout(rightToolBarLayout);
rightGroupBox = new QGroupBox;
rightGroupBox->setLayout(rightVbox);
QHBoxLayout *hbox = new QHBoxLayout;
hbox->addWidget(leftGroupBox);
hbox->addWidget(rightGroupBox);
aOpenLocalReplay = new QAction(this);
aOpenLocalReplay->setIcon(QPixmap("theme:icons/view"));
connect(aOpenLocalReplay, SIGNAL(triggered()), this, SLOT(actOpenLocalReplay()));
connect(localDirView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actOpenLocalReplay()));
aDeleteLocalReplay = new QAction(this);
aDeleteLocalReplay->setIcon(QPixmap("theme:icons/remove_row"));
connect(aDeleteLocalReplay, SIGNAL(triggered()), this, SLOT(actDeleteLocalReplay()));
aOpenRemoteReplay = new QAction(this);
aOpenRemoteReplay->setIcon(QPixmap("theme:icons/view"));
connect(aOpenRemoteReplay, SIGNAL(triggered()), this, SLOT(actOpenRemoteReplay()));
connect(serverDirView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actOpenRemoteReplay()));
aDownload = new QAction(this);
aDownload->setIcon(QPixmap("theme:icons/arrow_left_green"));
connect(aDownload, SIGNAL(triggered()), this, SLOT(actDownload()));
aKeep = new QAction(this);
aKeep->setIcon(QPixmap("theme:icons/lock"));
connect(aKeep, SIGNAL(triggered()), this, SLOT(actKeepRemoteReplay()));
aDeleteRemoteReplay = new QAction(this);
aDeleteRemoteReplay->setIcon(QPixmap("theme:icons/remove_row"));
connect(aDeleteRemoteReplay, SIGNAL(triggered()), this, SLOT(actDeleteRemoteReplay()));
leftToolBar->addAction(aOpenLocalReplay);
leftToolBar->addAction(aDeleteLocalReplay);
rightToolBar->addAction(aOpenRemoteReplay);
rightToolBar->addAction(aDownload);
rightToolBar->addAction(aKeep);
rightToolBar->addAction(aDeleteRemoteReplay);
retranslateUi();
QWidget *mainWidget = new QWidget(this);
mainWidget->setLayout(hbox);
setCentralWidget(mainWidget);
connect(client, SIGNAL(replayAddedEventReceived(const Event_ReplayAdded &)), this,
SLOT(replayAddedEventReceived(const Event_ReplayAdded &)));
}
void TabReplays::retranslateUi()
{
leftGroupBox->setTitle(tr("Local file system"));
rightGroupBox->setTitle(tr("Server replay storage"));
aOpenLocalReplay->setText(tr("Watch replay"));
aDeleteLocalReplay->setText(tr("Delete"));
aOpenRemoteReplay->setText(tr("Watch replay"));
aDownload->setText(tr("Download replay"));
aKeep->setText(tr("Toggle expiration lock"));
aDeleteRemoteReplay->setText(tr("Delete"));
}
void TabReplays::actOpenLocalReplay()
{
QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
if (localDirModel->isDir(curLeft))
return;
QString filePath = localDirModel->filePath(curLeft);
QFile f(filePath);
if (!f.open(QIODevice::ReadOnly))
return;
QByteArray _data = f.readAll();
f.close();
GameReplay *replay = new GameReplay;
replay->ParseFromArray(_data.data(), _data.size());
emit openReplay(replay);
}
void TabReplays::actDeleteLocalReplay()
{
QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
if (!curLeft.isValid())
return;
if (QMessageBox::warning(this, tr("Delete local file"),
tr("Are you sure you want to delete \"%1\"?").arg(localDirModel->fileName(curLeft)),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
return;
localDirModel->remove(curLeft);
}
void TabReplays::actOpenRemoteReplay()
{
ServerInfo_Replay const *curRight = serverDirView->getCurrentReplay();
if (!curRight)
return;
Command_ReplayDownload cmd;
cmd.set_replay_id(curRight->replay_id());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(openRemoteReplayFinished(const Response &)));
client->sendCommand(pend);
}
void TabReplays::openRemoteReplayFinished(const Response &r)
{
if (r.response_code() != Response::RespOk)
return;
const Response_ReplayDownload &resp = r.GetExtension(Response_ReplayDownload::ext);
GameReplay *replay = new GameReplay;
replay->ParseFromString(resp.replay_data());
emit openReplay(replay);
}
void TabReplays::actDownload()
{
QString filePath;
QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
if (!curLeft.isValid())
filePath = localDirModel->rootPath();
else {
while (!localDirModel->isDir(curLeft))
curLeft = curLeft.parent();
filePath = localDirModel->filePath(curLeft);
}
ServerInfo_Replay const *curRight = serverDirView->getCurrentReplay();
if (!curRight) {
QMessageBox::information(this, tr("Downloading Replays"),
tr("Folder download is not yet supported. Please download replays individually."));
return;
}
filePath += QString("/replay_%1.cor").arg(curRight->replay_id());
Command_ReplayDownload cmd;
cmd.set_replay_id(curRight->replay_id());
PendingCommand *pend = client->prepareSessionCommand(cmd);
pend->setExtraData(filePath);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(downloadFinished(Response, CommandContainer, QVariant)));
client->sendCommand(pend);
}
void TabReplays::downloadFinished(const Response &r,
const CommandContainer & /* commandContainer */,
const QVariant &extraData)
{
if (r.response_code() != Response::RespOk)
return;
const Response_ReplayDownload &resp = r.GetExtension(Response_ReplayDownload::ext);
QString filePath = extraData.toString();
const std::string &_data = resp.replay_data();
QFile f(filePath);
f.open(QIODevice::WriteOnly);
f.write((const char *)_data.data(), _data.size());
f.close();
}
void TabReplays::actKeepRemoteReplay()
{
ServerInfo_ReplayMatch const *curRight = serverDirView->getCurrentReplayMatch();
if (!curRight)
return;
Command_ReplayModifyMatch cmd;
cmd.set_game_id(curRight->game_id());
cmd.set_do_not_hide(!curRight->do_not_hide());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(keepRemoteReplayFinished(Response, CommandContainer)));
client->sendCommand(pend);
}
void TabReplays::keepRemoteReplayFinished(const Response &r, const CommandContainer &commandContainer)
{
if (r.response_code() != Response::RespOk)
return;
const Command_ReplayModifyMatch &cmd =
commandContainer.session_command(0).GetExtension(Command_ReplayModifyMatch::ext);
ServerInfo_ReplayMatch temp;
temp.set_do_not_hide(cmd.do_not_hide());
serverDirView->updateMatchInfo(cmd.game_id(), temp);
}
void TabReplays::actDeleteRemoteReplay()
{
ServerInfo_ReplayMatch const *curRight = serverDirView->getCurrentReplayMatch();
if (!curRight)
return;
if (QMessageBox::warning(this, tr("Delete remote replay"),
tr("Are you sure you want to delete the replay of game %1?").arg(curRight->game_id()),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
return;
Command_ReplayDeleteMatch cmd;
cmd.set_game_id(curRight->game_id());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(deleteRemoteReplayFinished(Response, CommandContainer)));
client->sendCommand(pend);
}
void TabReplays::deleteRemoteReplayFinished(const Response &r, const CommandContainer &commandContainer)
{
if (r.response_code() != Response::RespOk)
return;
const Command_ReplayDeleteMatch &cmd =
commandContainer.session_command(0).GetExtension(Command_ReplayDeleteMatch::ext);
serverDirView->removeMatchInfo(cmd.game_id());
}
void TabReplays::replayAddedEventReceived(const Event_ReplayAdded &event)
{
serverDirView->addMatchInfo(event.match_info());
}

View file

@ -0,0 +1,59 @@
#ifndef TAB_REPLAYS_H
#define TAB_REPLAYS_H
#include "tab.h"
class Response;
class AbstractClient;
class QTreeView;
class QFileSystemModel;
class QToolBar;
class QGroupBox;
class RemoteReplayList_TreeWidget;
class GameReplay;
class Event_ReplayAdded;
class CommandContainer;
class TabReplays : public Tab
{
Q_OBJECT
private:
AbstractClient *client;
QTreeView *localDirView;
QFileSystemModel *localDirModel;
QToolBar *leftToolBar, *rightToolBar;
RemoteReplayList_TreeWidget *serverDirView;
QGroupBox *leftGroupBox, *rightGroupBox;
QAction *aOpenLocalReplay, *aDeleteLocalReplay, *aOpenRemoteReplay, *aDownload, *aKeep, *aDeleteRemoteReplay;
private slots:
void actOpenLocalReplay();
void actDeleteLocalReplay();
void actOpenRemoteReplay();
void openRemoteReplayFinished(const Response &r);
void actDownload();
void downloadFinished(const Response &r, const CommandContainer &commandContainer, const QVariant &extraData);
void actKeepRemoteReplay();
void keepRemoteReplayFinished(const Response &r, const CommandContainer &commandContainer);
void actDeleteRemoteReplay();
void deleteRemoteReplayFinished(const Response &r, const CommandContainer &commandContainer);
void replayAddedEventReceived(const Event_ReplayAdded &event);
signals:
void openReplay(GameReplay *replay);
public:
TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client);
void retranslateUi();
QString getTabText() const
{
return tr("Game replays");
}
};
#endif

View file

@ -0,0 +1,347 @@
#include "tab_room.h"
#include "../../client/game_logic/abstract_client.h"
#include "../../dialogs/dlg_settings.h"
#include "../../game/game_selector.h"
#include "../../main.h"
#include "../../server/chat_view/chat_view.h"
#include "../../server/pending_command.h"
#include "../../server/user/user_list.h"
#include "../../settings/cache_settings.h"
#include "get_pb_extension.h"
#include "pb/event_join_room.pb.h"
#include "pb/event_leave_room.pb.h"
#include "pb/event_list_games.pb.h"
#include "pb/event_remove_messages.pb.h"
#include "pb/event_room_say.pb.h"
#include "pb/room_commands.pb.h"
#include "pb/serverinfo_room.pb.h"
#include "tab_account.h"
#include "tab_supervisor.h"
#include "trice_limits.h"
#include <QApplication>
#include <QCompleter>
#include <QLabel>
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QSplitter>
#include <QSystemTrayIcon>
#include <QToolButton>
#include <QVBoxLayout>
#include <QtCore/qdatetime.h>
TabRoom::TabRoom(TabSupervisor *_tabSupervisor,
AbstractClient *_client,
ServerInfo_User *_ownUser,
const ServerInfo_Room &info)
: Tab(_tabSupervisor), client(_client), roomId(info.room_id()), roomName(QString::fromStdString(info.name())),
ownUser(_ownUser)
{
const int gameTypeListSize = info.gametype_list_size();
for (int i = 0; i < gameTypeListSize; ++i)
gameTypes.insert(info.gametype_list(i).game_type_id(),
QString::fromStdString(info.gametype_list(i).description()));
QMap<int, GameTypeMap> tempMap;
tempMap.insert(info.room_id(), gameTypes);
gameSelector = new GameSelector(client, tabSupervisor, this, QMap<int, QString>(), tempMap, true, true);
userList = new UserList(tabSupervisor, client, UserList::RoomList);
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this,
SIGNAL(openMessageDialog(const QString &, bool)));
chatView = new ChatView(tabSupervisor, tabSupervisor, nullptr, true, this);
connect(chatView, SIGNAL(showMentionPopup(const QString &)), this, SLOT(actShowMentionPopup(const QString &)));
connect(chatView, SIGNAL(messageClickedSignal()), this, SLOT(focusTab()));
connect(chatView, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
connect(chatView, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
connect(chatView, SIGNAL(addMentionTag(QString)), this, SLOT(addMentionTag(QString)));
connect(&SettingsCache::instance(), SIGNAL(chatMentionCompleterChanged()), this, SLOT(actCompleterChanged()));
sayLabel = new QLabel;
sayEdit = new LineEditCompleter;
sayEdit->setMaxLength(MAX_TEXT_LENGTH);
sayLabel->setBuddy(sayEdit);
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(sendMessage()));
QMenu *chatSettingsMenu = new QMenu(this);
aClearChat = chatSettingsMenu->addAction(QString());
connect(aClearChat, SIGNAL(triggered()), this, SLOT(actClearChat()));
chatSettingsMenu->addSeparator();
aOpenChatSettings = chatSettingsMenu->addAction(QString());
connect(aOpenChatSettings, SIGNAL(triggered()), this, SLOT(actOpenChatSettings()));
QToolButton *chatSettingsButton = new QToolButton;
chatSettingsButton->setIcon(QPixmap("theme:icons/settings"));
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);
chatVbox->addLayout(sayHbox);
chatGroupBox = new QGroupBox;
chatGroupBox->setLayout(chatVbox);
QSplitter *splitter = new QSplitter(Qt::Vertical);
splitter->addWidget(gameSelector);
splitter->addWidget(chatGroupBox);
QHBoxLayout *hbox = new QHBoxLayout;
hbox->addWidget(splitter, 3);
hbox->addWidget(userList, 1);
aLeaveRoom = new QAction(this);
connect(aLeaveRoom, SIGNAL(triggered()), this, SLOT(actLeaveRoom()));
roomMenu = new QMenu(this);
roomMenu->addAction(aLeaveRoom);
addTabMenu(roomMenu);
const int userListSize = info.user_list_size();
for (int i = 0; i < userListSize; ++i) {
userList->processUserInfo(info.user_list(i), true);
autocompleteUserList.append("@" + QString::fromStdString(info.user_list(i).name()));
}
userList->sortItems();
const int gameListSize = info.game_list_size();
for (int i = 0; i < gameListSize; ++i)
gameSelector->processGameInfo(info.game_list(i));
completer = new QCompleter(autocompleteUserList, sayEdit);
completer->setCaseSensitivity(Qt::CaseInsensitive);
completer->setMaxVisibleItems(5);
completer->setFilterMode(Qt::MatchStartsWith);
sayEdit->setCompleter(completer);
actCompleterChanged();
connect(&SettingsCache::instance().shortcuts(), SIGNAL(shortCutChanged()), this, SLOT(refreshShortcuts()));
refreshShortcuts();
retranslateUi();
QWidget *mainWidget = new QWidget(this);
mainWidget->setLayout(hbox);
setCentralWidget(mainWidget);
}
TabRoom::~TabRoom()
{
emit roomClosing(this);
}
void TabRoom::retranslateUi()
{
gameSelector->retranslateUi();
chatView->retranslateUi();
userList->retranslateUi();
sayLabel->setText(tr("&Say:"));
chatGroupBox->setTitle(tr("Chat"));
roomMenu->setTitle(tr("&Room"));
aLeaveRoom->setText(tr("&Leave room"));
aClearChat->setText(tr("&Clear chat"));
aOpenChatSettings->setText(tr("Chat Settings..."));
}
void TabRoom::focusTab()
{
activateWindow();
tabSupervisor->setCurrentIndex(tabSupervisor->indexOf(this));
emit maximizeClient();
}
void TabRoom::actShowMentionPopup(const QString &sender)
{
this->actShowPopup(sender + tr(" mentioned you."));
}
void TabRoom::actShowPopup(const QString &message)
{
if (trayIcon && (tabSupervisor->currentIndex() != tabSupervisor->indexOf(this) ||
QApplication::activeWindow() == nullptr || QApplication::focusWidget() == nullptr)) {
disconnect(trayIcon, SIGNAL(messageClicked()), nullptr, nullptr);
trayIcon->showMessage(message, tr("Click to view"));
connect(trayIcon, SIGNAL(messageClicked()), chatView, SLOT(actMessageClicked()));
}
}
void TabRoom::closeRequest()
{
actLeaveRoom();
}
void TabRoom::tabActivated()
{
if (!sayEdit->hasFocus())
sayEdit->setFocus();
}
QString TabRoom::sanitizeHtml(QString dirty) const
{
return dirty.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
}
void TabRoom::sendMessage()
{
if (sayEdit->text().isEmpty()) {
return;
} else if (completer->popup()->isVisible()) {
completer->popup()->hide();
return;
} else {
Command_RoomSay cmd;
cmd.set_message(sayEdit->text().toStdString());
PendingCommand *pend = prepareRoomCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(sayFinished(const Response &)));
sendRoomCommand(pend);
sayEdit->clear();
}
}
void TabRoom::sayFinished(const Response &response)
{
if (response.response_code() == Response::RespChatFlood)
chatView->appendMessage(tr("You are flooding the chat. Please wait a couple of seconds."));
}
void TabRoom::actLeaveRoom()
{
sendRoomCommand(prepareRoomCommand(Command_LeaveRoom()));
deleteLater();
}
void TabRoom::actClearChat()
{
chatView->clearChat();
}
void TabRoom::actOpenChatSettings()
{
DlgSettings settings(this);
settings.setTab(4);
settings.exec();
}
void TabRoom::actCompleterChanged()
{
SettingsCache::instance().getChatMentionCompleter() ? completer->setCompletionRole(2)
: completer->setCompletionRole(1);
}
void TabRoom::processRoomEvent(const RoomEvent &event)
{
switch (static_cast<RoomEvent::RoomEventType>(getPbExtension(event))) {
case RoomEvent::LIST_GAMES:
processListGamesEvent(event.GetExtension(Event_ListGames::ext));
break;
case RoomEvent::JOIN_ROOM:
processJoinRoomEvent(event.GetExtension(Event_JoinRoom::ext));
break;
case RoomEvent::LEAVE_ROOM:
processLeaveRoomEvent(event.GetExtension(Event_LeaveRoom::ext));
break;
case RoomEvent::ROOM_SAY:
processRoomSayEvent(event.GetExtension(Event_RoomSay::ext));
break;
case RoomEvent::REMOVE_MESSAGES:
processRemoveMessagesEvent(event.GetExtension(Event_RemoveMessages::ext));
break;
default:;
}
}
void TabRoom::processListGamesEvent(const Event_ListGames &event)
{
const int gameListSize = event.game_list_size();
for (int i = 0; i < gameListSize; ++i)
gameSelector->processGameInfo(event.game_list(i));
}
void TabRoom::processJoinRoomEvent(const Event_JoinRoom &event)
{
userList->processUserInfo(event.user_info(), true);
userList->sortItems();
if (!autocompleteUserList.contains("@" + QString::fromStdString(event.user_info().name()))) {
autocompleteUserList << "@" + QString::fromStdString(event.user_info().name());
sayEdit->setCompletionList(autocompleteUserList);
}
}
void TabRoom::processLeaveRoomEvent(const Event_LeaveRoom &event)
{
userList->deleteUser(QString::fromStdString(event.name()));
autocompleteUserList.removeOne("@" + QString::fromStdString(event.name()));
sayEdit->setCompletionList(autocompleteUserList);
}
void TabRoom::processRoomSayEvent(const Event_RoomSay &event)
{
QString senderName = QString::fromStdString(event.name());
QString message = QString::fromStdString(event.message());
if (tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(senderName))
return;
UserListTWI *twi = userList->getUsers().value(senderName);
UserLevelFlags userLevel;
QString userPrivLevel;
if (twi) {
userLevel = UserLevelFlags(twi->getUserInfo().user_level());
userPrivLevel = QString::fromStdString(twi->getUserInfo().privlevel());
if (SettingsCache::instance().getIgnoreUnregisteredUsers() &&
!userLevel.testFlag(ServerInfo_User::IsRegistered))
return;
}
if (event.message_type() == Event_RoomSay::ChatHistory && !SettingsCache::instance().getRoomHistory())
return;
if (event.message_type() == Event_RoomSay::ChatHistory)
message =
"[" +
QString(QDateTime::fromMSecsSinceEpoch(event.time_of()).toLocalTime().toString("d MMM yyyy HH:mm:ss")) +
"] " + message;
chatView->appendMessage(message, event.message_type(), senderName, userLevel, userPrivLevel, true);
emit userEvent(false);
}
void TabRoom::processRemoveMessagesEvent(const Event_RemoveMessages &event)
{
QString userName = QString::fromStdString(event.name());
int amount = event.amount();
chatView->redactMessages(userName, amount);
}
void TabRoom::refreshShortcuts()
{
aClearChat->setShortcuts(SettingsCache::instance().shortcuts().getShortcut("tab_room/aClearChat"));
}
void TabRoom::addMentionTag(QString mentionTag)
{
sayEdit->insert(mentionTag + " ");
sayEdit->setFocus();
}
PendingCommand *TabRoom::prepareRoomCommand(const ::google::protobuf::Message &cmd)
{
return client->prepareRoomCommand(cmd, roomId);
}
void TabRoom::sendRoomCommand(PendingCommand *pend)
{
client->sendCommand(pend);
}

View file

@ -0,0 +1,124 @@
#ifndef TAB_ROOM_H
#define TAB_ROOM_H
#include "../ui/line_edit_completer.h"
#include "tab.h"
#include <QFocusEvent>
#include <QGroupBox>
#include <QKeyEvent>
#include <QMap>
namespace google
{
namespace protobuf
{
class Message;
}
} // namespace google
class AbstractClient;
class UserList;
class QLabel;
class ChatView;
class QPushButton;
class QTextTable;
class QCompleter;
class RoomEvent;
class ServerInfo_Room;
class ServerInfo_Game;
class Event_ListGames;
class Event_JoinRoom;
class Event_LeaveRoom;
class Event_RoomSay;
class Event_RemoveMessages;
class GameSelector;
class Response;
class PendingCommand;
class ServerInfo_User;
class LineEditCompleter;
class TabRoom : public Tab
{
Q_OBJECT
private:
AbstractClient *client;
int roomId;
QString roomName;
ServerInfo_User *ownUser;
QMap<int, QString> gameTypes;
GameSelector *gameSelector;
UserList *userList;
ChatView *chatView;
QLabel *sayLabel;
LineEditCompleter *sayEdit;
QGroupBox *chatGroupBox;
QMenu *roomMenu;
QAction *aLeaveRoom;
QAction *aOpenChatSettings;
QAction *aClearChat;
QString sanitizeHtml(QString dirty) const;
QStringList autocompleteUserList;
QCompleter *completer;
signals:
void roomClosing(TabRoom *tab);
void openMessageDialog(const QString &userName, bool focus);
void maximizeClient();
void notIdle();
private slots:
void sendMessage();
void sayFinished(const Response &response);
void actLeaveRoom();
void actClearChat();
void actOpenChatSettings();
void addMentionTag(QString mentionTag);
void focusTab();
void actShowMentionPopup(const QString &sender);
void actShowPopup(const QString &message);
void actCompleterChanged();
void processListGamesEvent(const Event_ListGames &event);
void processJoinRoomEvent(const Event_JoinRoom &event);
void processLeaveRoomEvent(const Event_LeaveRoom &event);
void processRoomSayEvent(const Event_RoomSay &event);
void processRemoveMessagesEvent(const Event_RemoveMessages &event);
void refreshShortcuts();
public:
TabRoom(TabSupervisor *_tabSupervisor,
AbstractClient *_client,
ServerInfo_User *_ownUser,
const ServerInfo_Room &info);
~TabRoom();
void retranslateUi();
void closeRequest();
void tabActivated();
void processRoomEvent(const RoomEvent &event);
int getRoomId() const
{
return roomId;
}
const QMap<int, QString> &getGameTypes() const
{
return gameTypes;
}
QString getChannelName() const
{
return roomName;
}
QString getTabText() const
{
return roomName;
}
const ServerInfo_User *getUserInfo() const
{
return ownUser;
}
PendingCommand *prepareRoomCommand(const ::google::protobuf::Message &cmd);
void sendRoomCommand(PendingCommand *pend);
};
#endif

View file

@ -0,0 +1,231 @@
#include "tab_server.h"
#include "../../client/game_logic/abstract_client.h"
#include "../../server/pending_command.h"
#include "../../server/user/user_list.h"
#include "pb/event_list_rooms.pb.h"
#include "pb/event_server_message.pb.h"
#include "pb/response_join_room.pb.h"
#include "pb/session_commands.pb.h"
#include "tab_supervisor.h"
#include <QCheckBox>
#include <QDebug>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QInputDialog>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
#include <QTextEdit>
#include <QTreeView>
#include <QVBoxLayout>
RoomSelector::RoomSelector(AbstractClient *_client, QWidget *parent) : QGroupBox(parent), client(_client)
{
roomList = new QTreeWidget;
roomList->setRootIsDecorated(false);
roomList->setColumnCount(5);
roomList->header()->setStretchLastSection(false);
roomList->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
roomList->header()->setSectionResizeMode(1, QHeaderView::Stretch);
roomList->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
roomList->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
joinButton = new QPushButton;
connect(joinButton, SIGNAL(clicked()), this, SLOT(joinClicked()));
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
buttonLayout->addWidget(joinButton);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(roomList);
vbox->addLayout(buttonLayout);
retranslateUi();
setLayout(vbox);
connect(client, SIGNAL(listRoomsEventReceived(const Event_ListRooms &)), this,
SLOT(processListRoomsEvent(const Event_ListRooms &)));
connect(roomList, SIGNAL(activated(const QModelIndex &)), this, SLOT(joinClicked()));
client->sendCommand(client->prepareSessionCommand(Command_ListRooms()));
}
void RoomSelector::retranslateUi()
{
setTitle(tr("Rooms"));
joinButton->setText(tr("Joi&n"));
QTreeWidgetItem *header = roomList->headerItem();
header->setText(0, tr("Room"));
header->setText(1, tr("Description"));
header->setText(2, tr("Permissions"));
header->setText(3, tr("Players"));
header->setText(4, tr("Games"));
header->setTextAlignment(2, Qt::AlignRight);
header->setTextAlignment(3, Qt::AlignRight);
header->setTextAlignment(4, Qt::AlignRight);
}
void RoomSelector::processListRoomsEvent(const Event_ListRooms &event)
{
const int roomListSize = event.room_list_size();
for (int i = 0; i < roomListSize; ++i) {
const ServerInfo_Room &room = event.room_list(i);
for (int j = 0; j < roomList->topLevelItemCount(); ++j) {
QTreeWidgetItem *twi = roomList->topLevelItem(j);
if (twi->data(0, Qt::UserRole).toInt() == room.room_id()) {
if (room.has_name())
twi->setData(0, Qt::DisplayRole, QString::fromStdString(room.name()));
if (room.has_description())
twi->setData(1, Qt::DisplayRole, QString::fromStdString(room.description()));
if (room.has_permissionlevel())
twi->setData(2, Qt::DisplayRole, getRoomPermissionDisplay(room));
if (room.has_player_count())
twi->setData(3, Qt::DisplayRole, room.player_count());
if (room.has_game_count())
twi->setData(4, Qt::DisplayRole, room.game_count());
return;
}
}
QTreeWidgetItem *twi = new QTreeWidgetItem;
twi->setData(0, Qt::UserRole, room.room_id());
if (room.has_name())
twi->setData(0, Qt::DisplayRole, QString::fromStdString(room.name()));
if (room.has_description())
twi->setData(1, Qt::DisplayRole, QString::fromStdString(room.description()));
if (room.has_permissionlevel())
twi->setData(2, Qt::DisplayRole, getRoomPermissionDisplay(room));
twi->setData(3, Qt::DisplayRole, room.player_count());
twi->setData(4, Qt::DisplayRole, room.game_count());
twi->setTextAlignment(2, Qt::AlignRight);
twi->setTextAlignment(3, Qt::AlignRight);
twi->setTextAlignment(4, Qt::AlignRight);
roomList->addTopLevelItem(twi);
if (room.has_auto_join())
if (room.auto_join())
emit joinRoomRequest(room.room_id(), false);
}
}
QString RoomSelector::getRoomPermissionDisplay(const ServerInfo_Room &room)
{
/*
* A server room can have a permission level and a privilege level. How ever we want to display only the necessary
* information on the server tab needed to inform users of required permissions to enter a room. If the room has a
* privilege level the server tab will display the privilege level in the "permissions" column in the row however if
* the room contains a permissions level for the room the permissions level defined for the room will be displayed.
*/
QString roomPermissionDisplay = QString::fromStdString(room.privilegelevel()).toLower();
if (QString::fromStdString(room.permissionlevel()).toLower() != "none")
roomPermissionDisplay = QString::fromStdString(room.permissionlevel()).toLower();
if (roomPermissionDisplay == "") // catch all for misconfigured .ini room definitions
roomPermissionDisplay = "none";
return roomPermissionDisplay;
}
void RoomSelector::joinClicked()
{
QTreeWidgetItem *twi = roomList->currentItem();
if (!twi)
return;
int id = twi->data(0, Qt::UserRole).toInt();
emit joinRoomRequest(id, true);
}
TabServer::TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent)
: Tab(_tabSupervisor, parent), client(_client)
{
roomSelector = new RoomSelector(client);
serverInfoBox = new QTextBrowser;
serverInfoBox->setOpenExternalLinks(true);
connect(roomSelector, SIGNAL(joinRoomRequest(int, bool)), this, SLOT(joinRoom(int, bool)));
connect(client, SIGNAL(serverMessageEventReceived(const Event_ServerMessage &)), this,
SLOT(processServerMessageEvent(const Event_ServerMessage &)));
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(roomSelector);
vbox->addWidget(serverInfoBox);
retranslateUi();
QWidget *mainWidget = new QWidget(this);
mainWidget->setLayout(vbox);
setCentralWidget(mainWidget);
}
void TabServer::retranslateUi()
{
roomSelector->retranslateUi();
}
void TabServer::processServerMessageEvent(const Event_ServerMessage &event)
{
serverInfoBox->setHtml(QString::fromStdString(event.message()));
if (shouldEmitUpdate) {
// prevent the initial server message from taking attention from ping icon
emit userEvent();
} else {
shouldEmitUpdate = true;
}
}
void TabServer::joinRoom(int id, bool setCurrent)
{
TabRoom *room = tabSupervisor->getRoomTabs().value(id);
if (!room) {
Command_JoinRoom cmd;
cmd.set_room_id(id);
PendingCommand *pend = client->prepareSessionCommand(cmd);
pend->setExtraData(setCurrent);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(joinRoomFinished(Response, CommandContainer, QVariant)));
client->sendCommand(pend);
return;
}
if (setCurrent)
tabSupervisor->setCurrentWidget((QWidget *)room);
}
void TabServer::joinRoomFinished(const Response &r,
const CommandContainer & /*commandContainer*/,
const QVariant &extraData)
{
switch (r.response_code()) {
case Response::RespOk:
break;
case Response::RespNameNotFound:
QMessageBox::critical(this, tr("Error"),
tr("Failed to join the server room: it doesn't exist on the server."));
return;
case Response::RespContextError:
QMessageBox::critical(
this, tr("Error"),
tr("The server thinks you are in the server room but your client is unable to display it. "
"Try restarting your client."));
return;
case Response::RespUserLevelTooLow:
QMessageBox::critical(this, tr("Error"),
tr("You do not have the required permission to join this server room."));
return;
default:
QMessageBox::critical(
this, tr("Error"),
tr("Failed to join the server room due to an unknown error: %1.").arg(r.response_code()));
return;
}
const Response_JoinRoom &resp = r.GetExtension(Response_JoinRoom::ext);
emit roomJoined(resp.room_info(), extraData.toBool());
}

View file

@ -0,0 +1,66 @@
#ifndef TAB_SERVER_H
#define TAB_SERVER_H
#include "tab.h"
#include <QGroupBox>
#include <QTextBrowser>
#include <QTreeWidget>
class AbstractClient;
class QTextEdit;
class QLabel;
class UserList;
class QPushButton;
class Event_ListRooms;
class Event_ServerMessage;
class Response;
class ServerInfo_Room;
class CommandContainer;
class RoomSelector : public QGroupBox
{
Q_OBJECT
private:
QTreeWidget *roomList;
QPushButton *joinButton;
AbstractClient *client;
QString getRoomPermissionDisplay(const ServerInfo_Room &room);
private slots:
void processListRoomsEvent(const Event_ListRooms &event);
void joinClicked();
signals:
void joinRoomRequest(int, bool setCurrent);
public:
RoomSelector(AbstractClient *_client, QWidget *parent = nullptr);
void retranslateUi();
};
class TabServer : public Tab
{
Q_OBJECT
signals:
void roomJoined(const ServerInfo_Room &info, bool setCurrent);
private slots:
void processServerMessageEvent(const Event_ServerMessage &event);
void joinRoom(int id, bool setCurrent);
void joinRoomFinished(const Response &resp, const CommandContainer &commandContainer, const QVariant &extraData);
private:
AbstractClient *client;
RoomSelector *roomSelector;
QTextBrowser *serverInfoBox;
bool shouldEmitUpdate = false;
public:
TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent = nullptr);
void retranslateUi();
QString getTabText() const
{
return tr("Server");
}
};
#endif

View file

@ -0,0 +1,750 @@
#include "tab_supervisor.h"
#include "../../client/game_logic/abstract_client.h"
#include "../../main.h"
#include "../../server/user/user_list.h"
#include "../../settings/cache_settings.h"
#include "../ui/pixel_map_generator.h"
#include "pb/event_game_joined.pb.h"
#include "pb/event_notify_user.pb.h"
#include "pb/event_user_message.pb.h"
#include "pb/game_event_container.pb.h"
#include "pb/moderator_commands.pb.h"
#include "pb/room_commands.pb.h"
#include "pb/room_event.pb.h"
#include "pb/serverinfo_room.pb.h"
#include "pb/serverinfo_user.pb.h"
#include "tab_account.h"
#include "tab_admin.h"
#include "tab_deck_editor.h"
#include "tab_deck_storage.h"
#include "tab_game.h"
#include "tab_logs.h"
#include "tab_message.h"
#include "tab_replays.h"
#include "tab_room.h"
#include "tab_server.h"
#include <QApplication>
#include <QDebug>
#include <QMessageBox>
#include <QPainter>
#include <QSystemTrayIcon>
QRect MacOSTabFixStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
{
if (element != SE_TabBarTabText) {
return QProxyStyle::subElementRect(element, option, widget);
}
// Skip over QProxyStyle handling subElementRect,
// This fixes an issue with Qt 5.10 on OSX where the labels for tabs with a button and an icon
// get cut-off too early
return QCommonStyle::subElementRect(element, option, widget);
}
CloseButton::CloseButton(QWidget *parent) : QAbstractButton(parent)
{
setFocusPolicy(Qt::NoFocus);
setCursor(Qt::ArrowCursor);
resize(sizeHint());
}
QSize CloseButton::sizeHint() const
{
ensurePolished();
int width = style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, this);
int height = style()->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, 0, this);
return QSize(width, height);
}
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
void CloseButton::enterEvent(QEnterEvent *event)
#else
void CloseButton::enterEvent(QEvent *event)
#endif
{
update();
QAbstractButton::enterEvent(event);
}
void CloseButton::leaveEvent(QEvent *event)
{
update();
QAbstractButton::leaveEvent(event);
}
void CloseButton::paintEvent(QPaintEvent * /*event*/)
{
QPainter p(this);
QStyleOption opt;
opt.initFrom(this);
opt.state |= QStyle::State_AutoRaise;
if (isEnabled() && underMouse() && !isChecked() && !isDown())
opt.state |= QStyle::State_Raised;
if (isChecked())
opt.state |= QStyle::State_On;
if (isDown())
opt.state |= QStyle::State_Sunken;
if (const QTabBar *tb = qobject_cast<const QTabBar *>(parent())) {
int index = tb->currentIndex();
QTabBar::ButtonPosition position =
(QTabBar::ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, tb);
if (tb->tabButton(index, position) == this)
opt.state |= QStyle::State_Selected;
}
style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, &p, this);
}
TabSupervisor::TabSupervisor(AbstractClient *_client, QWidget *parent)
: QTabWidget(parent), userInfo(0), client(_client), tabServer(0), tabUserLists(0), tabDeckStorage(0), tabReplays(0),
tabAdmin(0), tabLog(0)
{
setElideMode(Qt::ElideRight);
setMovable(true);
setIconSize(QSize(15, 15));
#if defined(Q_OS_MAC)
// This is necessary to fix an issue on macOS with qt5.10,
// where tabs with icons and buttons get drawn incorrectly
tabBar()->setStyle(new MacOSTabFixStyle);
#endif
connect(this, SIGNAL(currentChanged(int)), this, SLOT(updateCurrent(int)));
connect(client, SIGNAL(roomEventReceived(const RoomEvent &)), this, SLOT(processRoomEvent(const RoomEvent &)));
connect(client, SIGNAL(gameEventContainerReceived(const GameEventContainer &)), this,
SLOT(processGameEventContainer(const GameEventContainer &)));
connect(client, SIGNAL(gameJoinedEventReceived(const Event_GameJoined &)), this,
SLOT(gameJoined(const Event_GameJoined &)));
connect(client, SIGNAL(userMessageEventReceived(const Event_UserMessage &)), this,
SLOT(processUserMessageEvent(const Event_UserMessage &)));
connect(client, SIGNAL(maxPingTime(int, int)), this, SLOT(updatePingTime(int, int)));
connect(client, SIGNAL(notifyUserEventReceived(const Event_NotifyUser &)), this,
SLOT(processNotifyUserEvent(const Event_NotifyUser &)));
retranslateUi();
}
TabSupervisor::~TabSupervisor()
{
stop();
}
void TabSupervisor::retranslateUi()
{
QList<Tab *> tabs;
tabs.append(tabServer);
tabs.append(tabReplays);
tabs.append(tabDeckStorage);
tabs.append(tabAdmin);
tabs.append(tabUserLists);
tabs.append(tabLog);
QMapIterator<int, TabRoom *> roomIterator(roomTabs);
while (roomIterator.hasNext())
tabs.append(roomIterator.next().value());
QMapIterator<int, TabGame *> gameIterator(gameTabs);
while (gameIterator.hasNext())
tabs.append(gameIterator.next().value());
QListIterator<TabGame *> replayIterator(replayTabs);
while (replayIterator.hasNext())
tabs.append(replayIterator.next());
QListIterator<TabDeckEditor *> deckEditorIterator(deckEditorTabs);
while (deckEditorIterator.hasNext())
tabs.append(deckEditorIterator.next());
QMapIterator<QString, TabMessage *> messageIterator(messageTabs);
while (messageIterator.hasNext())
tabs.append(messageIterator.next().value());
for (int i = 0; i < tabs.size(); ++i)
if (tabs[i]) {
int idx = indexOf(tabs[i]);
QString tabText = tabs[i]->getTabText();
setTabText(idx, sanitizeTabName(tabText));
setTabToolTip(idx, sanitizeHtml(tabText));
tabs[i]->retranslateUi();
}
}
bool TabSupervisor::closeRequest()
{
if (getGameCount()) {
if (QMessageBox::question(this, tr("Are you sure?"),
tr("There are still open games. Are you sure you want to quit?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) {
return false;
}
}
foreach (TabDeckEditor *tab, deckEditorTabs) {
if (!tab->confirmClose())
return false;
}
return true;
}
AbstractClient *TabSupervisor::getClient() const
{
return localClients.isEmpty() ? client : localClients.first();
}
QString TabSupervisor::sanitizeTabName(QString dirty) const
{
return dirty.replace("&", "&&");
}
QString TabSupervisor::sanitizeHtml(QString dirty) const
{
return dirty.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;");
}
int TabSupervisor::myAddTab(Tab *tab)
{
connect(tab, SIGNAL(userEvent(bool)), this, SLOT(tabUserEvent(bool)));
connect(tab, SIGNAL(tabTextChanged(Tab *, QString)), this, SLOT(updateTabText(Tab *, QString)));
QString tabText = tab->getTabText();
int idx = addTab(tab, sanitizeTabName(tabText));
setTabToolTip(idx, sanitizeHtml(tabText));
return idx;
}
void TabSupervisor::start(const ServerInfo_User &_userInfo)
{
isLocalGame = false;
userInfo = new ServerInfo_User(_userInfo);
tabServer = new TabServer(this, client);
connect(tabServer, SIGNAL(roomJoined(const ServerInfo_Room &, bool)), this,
SLOT(addRoomTab(const ServerInfo_Room &, bool)));
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(ServerInfo_User)), this, SLOT(processUserJoined(ServerInfo_User)));
connect(tabUserLists, SIGNAL(userLeft(const QString &)), this, SLOT(processUserLeft(const QString &)));
myAddTab(tabUserLists);
updatePingTime(0, -1);
if (userInfo->user_level() & ServerInfo_User::IsRegistered) {
tabDeckStorage = new TabDeckStorage(this, client);
connect(tabDeckStorage, SIGNAL(openDeckEditor(const DeckLoader *)), this,
SLOT(addDeckEditorTab(const DeckLoader *)));
myAddTab(tabDeckStorage);
tabReplays = new TabReplays(this, client);
connect(tabReplays, SIGNAL(openReplay(GameReplay *)), this, SLOT(openReplay(GameReplay *)));
myAddTab(tabReplays);
} else {
tabDeckStorage = 0;
tabReplays = 0;
}
if (userInfo->user_level() & ServerInfo_User::IsModerator) {
tabAdmin = new TabAdmin(this, client, (userInfo->user_level() & ServerInfo_User::IsAdmin));
connect(tabAdmin, SIGNAL(adminLockChanged(bool)), this, SIGNAL(adminLockChanged(bool)));
myAddTab(tabAdmin);
tabLog = new TabLog(this, client);
myAddTab(tabLog);
} else {
tabAdmin = 0;
tabLog = 0;
}
retranslateUi();
}
void TabSupervisor::startLocal(const QList<AbstractClient *> &_clients)
{
tabUserLists = 0;
tabDeckStorage = 0;
tabReplays = 0;
tabAdmin = 0;
tabLog = 0;
isLocalGame = true;
userInfo = new ServerInfo_User;
localClients = _clients;
for (int i = 0; i < localClients.size(); ++i)
connect(localClients[i], SIGNAL(gameEventContainerReceived(const GameEventContainer &)), this,
SLOT(processGameEventContainer(const GameEventContainer &)));
connect(localClients.first(), SIGNAL(gameJoinedEventReceived(const Event_GameJoined &)), this,
SLOT(localGameJoined(const Event_GameJoined &)));
}
void TabSupervisor::stop()
{
if ((!client) && localClients.isEmpty())
return;
if (!localClients.isEmpty()) {
for (int i = 0; i < localClients.size(); ++i)
localClients[i]->deleteLater();
localClients.clear();
emit localGameEnded();
} else {
if (tabUserLists)
tabUserLists->deleteLater();
if (tabServer)
tabServer->deleteLater();
if (tabDeckStorage)
tabDeckStorage->deleteLater();
if (tabReplays)
tabReplays->deleteLater();
if (tabAdmin)
tabAdmin->deleteLater();
if (tabLog)
tabLog->deleteLater();
}
tabUserLists = 0;
tabServer = 0;
tabDeckStorage = 0;
tabReplays = 0;
tabAdmin = 0;
tabLog = 0;
QMapIterator<int, TabRoom *> roomIterator(roomTabs);
while (roomIterator.hasNext())
roomIterator.next().value()->deleteLater();
roomTabs.clear();
QMapIterator<int, TabGame *> gameIterator(gameTabs);
while (gameIterator.hasNext())
gameIterator.next().value()->deleteLater();
gameTabs.clear();
QListIterator<TabGame *> replayIterator(replayTabs);
while (replayIterator.hasNext())
replayIterator.next()->deleteLater();
replayTabs.clear();
delete userInfo;
userInfo = 0;
}
void TabSupervisor::updatePingTime(int value, int max)
{
if (!tabServer)
return;
if (tabServer->getContentsChanged())
return;
setTabIcon(indexOf(tabServer), QIcon(PingPixmapGenerator::generatePixmap(15, value, max)));
}
void TabSupervisor::closeButtonPressed()
{
Tab *tab = static_cast<Tab *>(static_cast<CloseButton *>(sender())->property("tab").value<QObject *>());
tab->closeRequest();
}
void TabSupervisor::addCloseButtonToTab(Tab *tab, int tabIndex)
{
QTabBar::ButtonPosition closeSide =
(QTabBar::ButtonPosition)tabBar()->style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, tabBar());
CloseButton *closeButton = new CloseButton;
connect(closeButton, SIGNAL(clicked()), this, SLOT(closeButtonPressed()));
closeButton->setProperty("tab", QVariant::fromValue((QObject *)tab));
tabBar()->setTabButton(tabIndex, closeSide, closeButton);
}
void TabSupervisor::gameJoined(const Event_GameJoined &event)
{
QMap<int, QString> roomGameTypes;
TabRoom *room = roomTabs.value(event.game_info().room_id());
if (room)
roomGameTypes = room->getGameTypes();
else
for (int i = 0; i < event.game_types_size(); ++i)
roomGameTypes.insert(event.game_types(i).game_type_id(),
QString::fromStdString(event.game_types(i).description()));
TabGame *tab = new TabGame(this, QList<AbstractClient *>() << client, event, roomGameTypes);
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
connect(tab, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool)));
connect(tab, SIGNAL(openDeckEditor(const DeckLoader *)), this, SLOT(addDeckEditorTab(const DeckLoader *)));
int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex);
gameTabs.insert(event.game_info().game_id(), tab);
setCurrentWidget(tab);
}
void TabSupervisor::localGameJoined(const Event_GameJoined &event)
{
TabGame *tab = new TabGame(this, localClients, event, QMap<int, QString>());
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
connect(tab, SIGNAL(openDeckEditor(const DeckLoader *)), this, SLOT(addDeckEditorTab(const DeckLoader *)));
int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex);
gameTabs.insert(event.game_info().game_id(), tab);
setCurrentWidget(tab);
for (int i = 1; i < localClients.size(); ++i) {
Command_JoinGame cmd;
cmd.set_game_id(event.game_info().game_id());
localClients[i]->sendCommand(localClients[i]->prepareRoomCommand(cmd, 0));
}
}
void TabSupervisor::gameLeft(TabGame *tab)
{
if (tab == currentWidget())
emit setMenu();
gameTabs.remove(tab->getGameId());
removeTab(indexOf(tab));
if (!localClients.isEmpty())
stop();
}
void TabSupervisor::addRoomTab(const ServerInfo_Room &info, bool setCurrent)
{
TabRoom *tab = new TabRoom(this, client, userInfo, info);
connect(tab, SIGNAL(maximizeClient()), this, SLOT(maximizeMainWindow()));
connect(tab, SIGNAL(roomClosing(TabRoom *)), this, SLOT(roomLeft(TabRoom *)));
connect(tab, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool)));
int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex);
roomTabs.insert(info.room_id(), tab);
if (setCurrent)
setCurrentWidget(tab);
}
void TabSupervisor::roomLeft(TabRoom *tab)
{
if (tab == currentWidget())
emit setMenu();
roomTabs.remove(tab->getRoomId());
removeTab(indexOf(tab));
}
void TabSupervisor::openReplay(GameReplay *replay)
{
TabGame *replayTab = new TabGame(this, replay);
connect(replayTab, SIGNAL(gameClosing(TabGame *)), this, SLOT(replayLeft(TabGame *)));
int tabIndex = myAddTab(replayTab);
addCloseButtonToTab(replayTab, tabIndex);
replayTabs.append(replayTab);
setCurrentWidget(replayTab);
}
void TabSupervisor::replayLeft(TabGame *tab)
{
if (tab == currentWidget())
emit setMenu();
replayTabs.removeOne(tab);
}
TabMessage *TabSupervisor::addMessageTab(const QString &receiverName, bool focus)
{
if (receiverName == QString::fromStdString(userInfo->name()))
return nullptr;
ServerInfo_User otherUser;
UserListTWI *twi = tabUserLists->getAllUsersList()->getUsers().value(receiverName);
if (twi)
otherUser = twi->getUserInfo();
else
otherUser.set_name(receiverName.toStdString());
TabMessage *tab;
tab = messageTabs.value(QString::fromStdString(otherUser.name()));
if (tab) {
if (focus)
setCurrentWidget(tab);
return tab;
}
tab = new TabMessage(this, client, *userInfo, otherUser);
connect(tab, SIGNAL(talkClosing(TabMessage *)), this, SLOT(talkLeft(TabMessage *)));
connect(tab, SIGNAL(maximizeClient()), this, SLOT(maximizeMainWindow()));
int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex);
messageTabs.insert(receiverName, tab);
if (focus)
setCurrentWidget(tab);
return tab;
}
void TabSupervisor::maximizeMainWindow()
{
emit showWindowIfHidden();
}
void TabSupervisor::talkLeft(TabMessage *tab)
{
if (tab == currentWidget())
emit setMenu();
messageTabs.remove(tab->getUserName());
removeTab(indexOf(tab));
}
TabDeckEditor *TabSupervisor::addDeckEditorTab(const DeckLoader *deckToOpen)
{
TabDeckEditor *tab = new TabDeckEditor(this);
if (deckToOpen)
tab->setDeck(new DeckLoader(*deckToOpen));
connect(tab, SIGNAL(deckEditorClosing(TabDeckEditor *)), this, SLOT(deckEditorClosed(TabDeckEditor *)));
int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex);
deckEditorTabs.append(tab);
setCurrentWidget(tab);
return tab;
}
void TabSupervisor::deckEditorClosed(TabDeckEditor *tab)
{
if (tab == currentWidget())
emit setMenu();
deckEditorTabs.removeOne(tab);
removeTab(indexOf(tab));
}
void TabSupervisor::tabUserEvent(bool globalEvent)
{
Tab *tab = static_cast<Tab *>(sender());
if (tab != currentWidget()) {
tab->setContentsChanged(true);
setTabIcon(indexOf(tab), QPixmap("theme:icons/tab_changed"));
}
if (globalEvent && SettingsCache::instance().getNotificationsEnabled())
QApplication::alert(this);
}
void TabSupervisor::updateTabText(Tab *tab, const QString &newTabText)
{
int idx = indexOf(tab);
setTabText(idx, sanitizeTabName(newTabText));
setTabToolTip(idx, sanitizeHtml(newTabText));
}
void TabSupervisor::processRoomEvent(const RoomEvent &event)
{
TabRoom *tab = roomTabs.value(event.room_id(), 0);
if (tab)
tab->processRoomEvent(event);
}
void TabSupervisor::processGameEventContainer(const GameEventContainer &cont)
{
TabGame *tab = gameTabs.value(cont.game_id());
if (tab)
tab->processGameEventContainer(cont, qobject_cast<AbstractClient *>(sender()));
else
qDebug() << "gameEvent: invalid gameId";
}
void TabSupervisor::processUserMessageEvent(const Event_UserMessage &event)
{
QString senderName = QString::fromStdString(event.sender_name());
TabMessage *tab = messageTabs.value(senderName);
if (!tab)
tab = messageTabs.value(QString::fromStdString(event.receiver_name()));
if (!tab) {
UserListTWI *twi = tabUserLists->getAllUsersList()->getUsers().value(senderName);
if (twi) {
UserLevelFlags userLevel = UserLevelFlags(twi->getUserInfo().user_level());
if (SettingsCache::instance().getIgnoreUnregisteredUserMessages() &&
!userLevel.testFlag(ServerInfo_User::IsRegistered))
// Flags are additive, so reg/mod/admin are all IsRegistered
return;
}
tab = addMessageTab(QString::fromStdString(event.sender_name()), false);
}
if (!tab)
return;
tab->processUserMessageEvent(event);
}
void TabSupervisor::actShowPopup(const QString &message)
{
qDebug() << "ACT SHOW POPUP";
if (trayIcon && (QApplication::activeWindow() == nullptr || QApplication::focusWidget() == nullptr)) {
qDebug() << "LAUNCHING POPUP";
// disconnect(trayIcon, SIGNAL(messageClicked()), nullptr, nullptr);
trayIcon->showMessage(message, tr("Click to view"));
// connect(trayIcon, SIGNAL(messageClicked()), chatView, SLOT(actMessageClicked()));
}
}
void TabSupervisor::processUserLeft(const QString &userName)
{
TabMessage *tab = messageTabs.value(userName);
if (tab)
tab->processUserLeft();
}
void TabSupervisor::processUserJoined(const ServerInfo_User &userInfoJoined)
{
QString userName = QString::fromStdString(userInfoJoined.name());
if (isUserBuddy(userName)) {
Tab *tab = static_cast<Tab *>(getUserListsTab());
if (tab != currentWidget()) {
tab->setContentsChanged(true);
QPixmap avatarPixmap =
UserLevelPixmapGenerator::generatePixmap(13, (UserLevelFlags)userInfoJoined.user_level(), true,
QString::fromStdString(userInfoJoined.privlevel()));
setTabIcon(indexOf(tab), QPixmap(avatarPixmap));
}
if (SettingsCache::instance().getBuddyConnectNotificationsEnabled()) {
QApplication::alert(this);
this->actShowPopup(tr("Your buddy %1 has signed on!").arg(userName));
}
}
TabMessage *tab = messageTabs.value(userName);
if (tab)
tab->processUserJoined(userInfoJoined);
}
void TabSupervisor::updateCurrent(int index)
{
if (index != -1) {
Tab *tab = static_cast<Tab *>(widget(index));
if (tab->getContentsChanged()) {
setTabIcon(index, QIcon());
tab->setContentsChanged(false);
}
emit setMenu(static_cast<Tab *>(widget(index))->getTabMenus());
tab->tabActivated();
} else
emit setMenu();
}
/**
* Determine if a user is a moderator/administrator
* By seeing if they have the admin tab open & unlocked
* @return if the admin tab is open & unlocked
*/
bool TabSupervisor::getAdminLocked() const
{
if (!tabAdmin)
return true;
return tabAdmin->getLocked();
}
void TabSupervisor::processNotifyUserEvent(const Event_NotifyUser &event)
{
switch ((Event_NotifyUser::NotificationType)event.type()) {
case Event_NotifyUser::UNKNOWN:
QMessageBox::information(
this, tr("Unknown Event"),
tr("The server has sent you a message that your client does not understand.\nThis message might mean "
"there is a new version of Cockatrice available or this server is running a custom or pre-release "
"version.\n\nTo update your client, go to Help -> Check for Updates."));
break;
case Event_NotifyUser::IDLEWARNING:
QMessageBox::information(this, tr("Idle Timeout"), tr("You are about to be logged out due to inactivity."));
break;
case Event_NotifyUser::PROMOTED:
QMessageBox::information(
this, tr("Promotion"),
tr("You have been promoted. Please log out and back in for changes to take effect."));
break;
case Event_NotifyUser::WARNING: {
if (!QString::fromStdString(event.warning_reason()).simplified().isEmpty())
QMessageBox::warning(this, tr("Warned"),
tr("You have received a warning due to %1.\nPlease refrain from engaging in this "
"activity or further actions may be taken against you. If you have any "
"questions, please private message a moderator.")
.arg(QString::fromStdString(event.warning_reason()).simplified()));
break;
}
case Event_NotifyUser::CUSTOM: {
if (!QString::fromStdString(event.custom_title()).simplified().isEmpty() &&
!QString::fromStdString(event.custom_content()).simplified().isEmpty()) {
QMessageBox msgBox;
msgBox.setParent(this);
msgBox.setWindowFlags(Qt::Dialog);
msgBox.setIcon(QMessageBox::Information);
msgBox.setWindowTitle(QString::fromStdString(event.custom_title()).simplified());
msgBox.setText(tr("You have received the following message from the server.\n(custom messages like "
"these could be untranslated)"));
msgBox.setDetailedText(QString::fromStdString(event.custom_content()).simplified());
msgBox.setMinimumWidth(200);
msgBox.exec();
}
break;
}
default:;
}
}
bool TabSupervisor::isOwnUserRegistered() const
{
return userInfo != nullptr && (userInfo->user_level() & ServerInfo_User::IsRegistered) != 0;
}
QString TabSupervisor::getOwnUsername() const
{
return userInfo != nullptr ? QString::fromStdString(userInfo->name()) : QString();
}
bool TabSupervisor::isUserBuddy(const QString &userName) const
{
if (!getUserListsTab())
return false;
if (!getUserListsTab()->getBuddyList())
return false;
QMap<QString, UserListTWI *> buddyList = getUserListsTab()->getBuddyList()->getUsers();
bool senderIsBuddy = buddyList.contains(userName);
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;
if (!getUserListsTab()->getAllUsersList())
return nullptr;
QMap<QString, UserListTWI *> userList = getUserListsTab()->getAllUsersList()->getUsers();
const QString &userNameToMatchLower = userName.toLower();
QMap<QString, UserListTWI *>::iterator i;
for (i = userList.begin(); i != userList.end(); ++i)
if (i.key().toLower() == userNameToMatchLower) {
const ServerInfo_User &_userInfo = i.value()->getUserInfo();
return &_userInfo;
}
return nullptr;
};
bool TabSupervisor::switchToGameTabIfAlreadyExists(const int gameId)
{
bool isGameTabExists = false;
if (gameTabs.contains(gameId)) {
isGameTabExists = true;
TabGame *tabGame = gameTabs[gameId];
const int gameTabIndex = indexOf(tabGame);
setCurrentIndex(gameTabIndex);
}
return isGameTabExists;
}

View file

@ -0,0 +1,158 @@
#ifndef TAB_SUPERVISOR_H
#define TAB_SUPERVISOR_H
#include "../../deck/deck_loader.h"
#include "../../server/chat_view/user_list_proxy.h"
#include <QAbstractButton>
#include <QCommonStyle>
#include <QMap>
#include <QProxyStyle>
#include <QTabWidget>
class QMenu;
class AbstractClient;
class Tab;
class TabServer;
class TabRoom;
class TabGame;
class TabDeckStorage;
class TabReplays;
class TabAdmin;
class TabMessage;
class TabUserLists;
class TabDeckEditor;
class TabLog;
class RoomEvent;
class GameEventContainer;
class Event_GameJoined;
class Event_UserMessage;
class Event_NotifyUser;
class ServerInfo_Room;
class ServerInfo_User;
class GameReplay;
class DeckList;
class MacOSTabFixStyle : public QProxyStyle
{
Q_OBJECT
public:
QRect subElementRect(SubElement, const QStyleOption *, const QWidget *) const;
};
class CloseButton : public QAbstractButton
{
Q_OBJECT
public:
CloseButton(QWidget *parent = nullptr);
QSize sizeHint() const;
inline QSize minimumSizeHint() const
{
return sizeHint();
}
protected:
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
void enterEvent(QEnterEvent *event);
#else
void enterEvent(QEvent *event);
#endif
void leaveEvent(QEvent *event);
void paintEvent(QPaintEvent *event);
};
class TabSupervisor : public QTabWidget, public UserlistProxy
{
Q_OBJECT
private:
ServerInfo_User *userInfo;
AbstractClient *client;
QList<AbstractClient *> localClients;
TabServer *tabServer;
TabUserLists *tabUserLists;
TabDeckStorage *tabDeckStorage;
TabReplays *tabReplays;
TabAdmin *tabAdmin;
TabLog *tabLog;
QMap<int, TabRoom *> roomTabs;
QMap<int, TabGame *> gameTabs;
QList<TabGame *> replayTabs;
QMap<QString, TabMessage *> messageTabs;
QList<TabDeckEditor *> deckEditorTabs;
int myAddTab(Tab *tab);
void addCloseButtonToTab(Tab *tab, int tabIndex);
QString sanitizeTabName(QString dirty) const;
QString sanitizeHtml(QString dirty) const;
bool isLocalGame;
public:
TabSupervisor(AbstractClient *_client, QWidget *parent = nullptr);
~TabSupervisor();
void retranslateUi();
void start(const ServerInfo_User &userInfo);
void startLocal(const QList<AbstractClient *> &_clients);
void stop();
bool getIsLocalGame() const
{
return isLocalGame;
}
int getGameCount() const
{
return gameTabs.size();
}
TabUserLists *getUserListsTab() const
{
return tabUserLists;
}
ServerInfo_User *getUserInfo() const
{
return userInfo;
}
AbstractClient *getClient() const;
const QMap<int, TabRoom *> &getRoomTabs() const
{
return roomTabs;
}
bool getAdminLocked() const;
bool closeRequest();
bool isOwnUserRegistered() const;
QString getOwnUsername() const;
bool isUserBuddy(const QString &userName) const;
bool isUserIgnored(const QString &userName) const;
const ServerInfo_User *getOnlineUser(const QString &userName) const;
bool switchToGameTabIfAlreadyExists(const int gameId);
void actShowPopup(const QString &message);
signals:
void setMenu(const QList<QMenu *> &newMenuList = QList<QMenu *>());
void localGameEnded();
void adminLockChanged(bool lock);
void showWindowIfHidden();
public slots:
TabDeckEditor *addDeckEditorTab(const DeckLoader *deckToOpen);
void openReplay(GameReplay *replay);
void maximizeMainWindow();
private slots:
void closeButtonPressed();
void updateCurrent(int index);
void updatePingTime(int value, int max);
void gameJoined(const Event_GameJoined &event);
void localGameJoined(const Event_GameJoined &event);
void gameLeft(TabGame *tab);
void addRoomTab(const ServerInfo_Room &info, bool setCurrent);
void roomLeft(TabRoom *tab);
TabMessage *addMessageTab(const QString &userName, bool focus);
void replayLeft(TabGame *tab);
void processUserLeft(const QString &userName);
void processUserJoined(const ServerInfo_User &userInfo);
void talkLeft(TabMessage *tab);
void deckEditorClosed(TabDeckEditor *tab);
void tabUserEvent(bool globalEvent);
void updateTabText(Tab *tab, const QString &newTabText);
void processRoomEvent(const RoomEvent &event);
void processGameEventContainer(const GameEventContainer &cont);
void processUserMessageEvent(const Event_UserMessage &event);
void processNotifyUserEvent(const Event_NotifyUser &event);
};
#endif