mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-31 07:02:22 -08:00
* 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>
178 lines
5.5 KiB
C++
178 lines
5.5 KiB
C++
#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;
|
|
}
|