style: Add braces to all control flow statements (#6887)

* style: Add braces to all control flow statements

  Standardize code style by adding explicit braces to all single-statement
  control flow blocks (if, else, for, while) across the entire codebase.

  Also documents the InsertBraces clang-format option (requires v15+) for
  future automated enforcement.

* InsertBraces-check-enabled
This commit is contained in:
DawnFire42 2026-05-16 13:19:53 -04:00 committed by GitHub
parent 7153f7d4c1
commit aadee34238
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
173 changed files with 2725 additions and 1461 deletions

View file

@ -144,10 +144,11 @@ void AbstractTabDeckEditor::addCardHelper(const ExactCard &card, const QString &
*/
void AbstractTabDeckEditor::actAddCard(const ExactCard &card)
{
if (QApplication::keyboardModifiers() & Qt::ControlModifier)
if (QApplication::keyboardModifiers() & Qt::ControlModifier) {
actAddCardToSideboard(card);
else
} else {
addCardHelper(card, DECK_ZONE_MAIN);
}
deckMenu->setSaveStatus(true);
}
@ -201,8 +202,9 @@ void AbstractTabDeckEditor::setDeck(const LoadedDeck &_deck)
void AbstractTabDeckEditor::actNewDeck()
{
auto deckOpenLocation = confirmOpen(false);
if (deckOpenLocation == CANCELLED)
if (deckOpenLocation == CANCELLED) {
return;
}
if (deckOpenLocation == NEW_TAB) {
emit openDeckEditor(LoadedDeck());
@ -227,22 +229,25 @@ void AbstractTabDeckEditor::cleanDeckAndResetModified()
AbstractTabDeckEditor::DeckOpenLocation AbstractTabDeckEditor::confirmOpen(const bool openInSameTabIfBlank)
{
if (SettingsCache::instance().getOpenDeckInNewTab()) {
if (openInSameTabIfBlank && deckStateManager->isBlankNewDeck())
if (openInSameTabIfBlank && deckStateManager->isBlankNewDeck()) {
return SAME_TAB;
else
} else {
return NEW_TAB;
}
}
if (!deckStateManager->isModified())
if (!deckStateManager->isModified()) {
return SAME_TAB;
}
tabSupervisor->setCurrentWidget(this);
QMessageBox *msgBox = createSaveConfirmationWindow();
QPushButton *newTabButton = msgBox->addButton(tr("Open in new tab"), QMessageBox::ApplyRole);
int ret = msgBox->exec();
if (msgBox->clickedButton() == newTabButton)
if (msgBox->clickedButton() == newTabButton) {
return NEW_TAB;
}
switch (ret) {
case QMessageBox::Save:
@ -275,12 +280,14 @@ QMessageBox *AbstractTabDeckEditor::createSaveConfirmationWindow()
void AbstractTabDeckEditor::actLoadDeck()
{
auto deckOpenLocation = confirmOpen();
if (deckOpenLocation == CANCELLED)
if (deckOpenLocation == CANCELLED) {
return;
}
DlgLoadDeck dialog(this);
if (!dialog.exec())
if (!dialog.exec()) {
return;
}
QString fileName = dialog.selectedFiles().at(0);
openDeckFromFile(fileName, deckOpenLocation);
@ -293,8 +300,9 @@ void AbstractTabDeckEditor::actLoadDeck()
void AbstractTabDeckEditor::actOpenRecent(const QString &fileName)
{
auto deckOpenLocation = confirmOpen();
if (deckOpenLocation == CANCELLED)
if (deckOpenLocation == CANCELLED) {
return;
}
openDeckFromFile(fileName, deckOpenLocation);
}
@ -347,8 +355,9 @@ bool AbstractTabDeckEditor::actSaveDeck()
return true;
}
if (loadedDeck.lastLoadInfo.fileName.isEmpty())
if (loadedDeck.lastLoadInfo.fileName.isEmpty()) {
return actSaveDeckAs();
}
if (DeckLoader::saveToFile(loadedDeck)) {
deckStateManager->setModified(false);
@ -376,8 +385,9 @@ bool AbstractTabDeckEditor::actSaveDeckAs()
dialog.setNameFilters(DeckLoader::FILE_NAME_FILTERS);
dialog.selectFile(deckList.getName().trimmed());
if (!dialog.exec())
if (!dialog.exec()) {
return false;
}
QString fileName = dialog.selectedFiles().at(0);
DeckFileFormat::Format fmt = DeckFileFormat::getFormatFromName(fileName);
@ -403,10 +413,11 @@ bool AbstractTabDeckEditor::actSaveDeckAs()
*/
void AbstractTabDeckEditor::saveDeckRemoteFinished(const Response &response)
{
if (response.response_code() != Response::RespOk)
if (response.response_code() != Response::RespOk) {
QMessageBox::critical(this, tr("Error"), tr("The deck could not be saved."));
else
} else {
deckStateManager->setModified(false);
}
}
/**
@ -416,12 +427,14 @@ void AbstractTabDeckEditor::saveDeckRemoteFinished(const Response &response)
void AbstractTabDeckEditor::actLoadDeckFromClipboard()
{
auto deckOpenLocation = confirmOpen();
if (deckOpenLocation == CANCELLED)
if (deckOpenLocation == CANCELLED) {
return;
}
DlgLoadDeckFromClipboard dlg(this);
if (!dlg.exec())
if (!dlg.exec()) {
return;
}
if (deckOpenLocation == NEW_TAB) {
emit openDeckEditor({.deckList = dlg.getDeckList()});
@ -441,8 +454,9 @@ void AbstractTabDeckEditor::editDeckInClipboard(bool annotated)
{
LoadedDeck loadedDeck = deckStateManager->toLoadedDeck();
DlgEditDeckInClipboard dlg(loadedDeck.deckList, annotated, this);
if (!dlg.exec())
if (!dlg.exec()) {
return;
}
setDeck({dlg.getDeckList(), loadedDeck.lastLoadInfo});
deckStateManager->setModified(true);
@ -500,12 +514,14 @@ void AbstractTabDeckEditor::actPrintDeck()
void AbstractTabDeckEditor::actLoadDeckFromWebsite()
{
auto deckOpenLocation = confirmOpen();
if (deckOpenLocation == CANCELLED)
if (deckOpenLocation == CANCELLED) {
return;
}
DlgLoadDeckFromWebsite dlg(this);
if (!dlg.exec())
if (!dlg.exec()) {
return;
}
if (deckOpenLocation == NEW_TAB) {
emit openDeckEditor({.deckList = dlg.getDeck()});
@ -588,10 +604,11 @@ bool AbstractTabDeckEditor::confirmClose()
if (deckStateManager->isModified()) {
tabSupervisor->setCurrentWidget(this);
int ret = createSaveConfirmationWindow()->exec();
if (ret == QMessageBox::Save)
if (ret == QMessageBox::Save) {
return actSaveDeck();
else if (ret == QMessageBox::Cancel)
} else if (ret == QMessageBox::Cancel) {
return false;
}
}
return true;
}
@ -599,7 +616,8 @@ bool AbstractTabDeckEditor::confirmClose()
/** @brief Handles close requests from outside (tab manager). */
bool AbstractTabDeckEditor::closeRequest()
{
if (!confirmClose())
if (!confirmClose()) {
return false;
}
return close();
}

View file

@ -98,55 +98,79 @@ inline static DeckFormat apiNameToFormat(const QString &name)
{
const QString n = name.trimmed();
if (n.compare("Standard", Qt::CaseInsensitive) == 0)
if (n.compare("Standard", Qt::CaseInsensitive) == 0) {
return DeckFormat::Standard;
if (n.compare("Modern", Qt::CaseInsensitive) == 0)
}
if (n.compare("Modern", Qt::CaseInsensitive) == 0) {
return DeckFormat::Modern;
if (n.compare("Commander", Qt::CaseInsensitive) == 0)
}
if (n.compare("Commander", Qt::CaseInsensitive) == 0) {
return DeckFormat::Commander;
if (n.compare("Legacy", Qt::CaseInsensitive) == 0)
}
if (n.compare("Legacy", Qt::CaseInsensitive) == 0) {
return DeckFormat::Legacy;
if (n.compare("Vintage", Qt::CaseInsensitive) == 0)
}
if (n.compare("Vintage", Qt::CaseInsensitive) == 0) {
return DeckFormat::Vintage;
if (n.compare("Pauper", Qt::CaseInsensitive) == 0)
}
if (n.compare("Pauper", Qt::CaseInsensitive) == 0) {
return DeckFormat::Pauper;
if (n.compare("Custom", Qt::CaseInsensitive) == 0)
}
if (n.compare("Custom", Qt::CaseInsensitive) == 0) {
return DeckFormat::Custom;
if (n.compare("Frontier", Qt::CaseInsensitive) == 0)
}
if (n.compare("Frontier", Qt::CaseInsensitive) == 0) {
return DeckFormat::Frontier;
if (n.compare("Future Std", Qt::CaseInsensitive) == 0)
}
if (n.compare("Future Std", Qt::CaseInsensitive) == 0) {
return DeckFormat::FutureStandard;
if (n.compare("Penny Dreadful", Qt::CaseInsensitive) == 0)
}
if (n.compare("Penny Dreadful", Qt::CaseInsensitive) == 0) {
return DeckFormat::PennyDreadful;
if (n.compare("1v1 Commander", Qt::CaseInsensitive) == 0)
}
if (n.compare("1v1 Commander", Qt::CaseInsensitive) == 0) {
return DeckFormat::Commander1v1;
if (n.compare("Dual Commander", Qt::CaseInsensitive) == 0)
}
if (n.compare("Dual Commander", Qt::CaseInsensitive) == 0) {
return DeckFormat::DualCommander;
if (n.compare("Brawl", Qt::CaseInsensitive) == 0)
}
if (n.compare("Brawl", Qt::CaseInsensitive) == 0) {
return DeckFormat::Brawl;
}
if (n.compare("Alchemy", Qt::CaseInsensitive) == 0)
if (n.compare("Alchemy", Qt::CaseInsensitive) == 0) {
return DeckFormat::Alchemy;
if (n.compare("Historic", Qt::CaseInsensitive) == 0)
}
if (n.compare("Historic", Qt::CaseInsensitive) == 0) {
return DeckFormat::Historic;
if (n.compare("Gladiator", Qt::CaseInsensitive) == 0)
}
if (n.compare("Gladiator", Qt::CaseInsensitive) == 0) {
return DeckFormat::Gladiator;
if (n.compare("Oathbreaker", Qt::CaseInsensitive) == 0)
}
if (n.compare("Oathbreaker", Qt::CaseInsensitive) == 0) {
return DeckFormat::Oathbreaker;
if (n.compare("Old School", Qt::CaseInsensitive) == 0)
}
if (n.compare("Old School", Qt::CaseInsensitive) == 0) {
return DeckFormat::OldSchool;
if (n.compare("Pauper Commander", Qt::CaseInsensitive) == 0)
}
if (n.compare("Pauper Commander", Qt::CaseInsensitive) == 0) {
return DeckFormat::PauperCommander;
if (n.compare("Pioneer", Qt::CaseInsensitive) == 0)
}
if (n.compare("Pioneer", Qt::CaseInsensitive) == 0) {
return DeckFormat::Pioneer;
if (n.compare("PreDH", Qt::CaseInsensitive) == 0)
}
if (n.compare("PreDH", Qt::CaseInsensitive) == 0) {
return DeckFormat::PreDH;
if (n.compare("Premodern", Qt::CaseInsensitive) == 0)
}
if (n.compare("Premodern", Qt::CaseInsensitive) == 0) {
return DeckFormat::Premodern;
if (n.compare("Standard Brawl", Qt::CaseInsensitive) == 0)
}
if (n.compare("Standard Brawl", Qt::CaseInsensitive) == 0) {
return DeckFormat::StandardBrawl;
if (n.compare("Timeless", Qt::CaseInsensitive) == 0)
}
if (n.compare("Timeless", Qt::CaseInsensitive) == 0) {
return DeckFormat::Timeless;
}
return DeckFormat::Unknown;
}

View file

@ -20,21 +20,27 @@ static QString timeAgo(const QString &timestamp)
{
QDateTime dt = QDateTime::fromString(timestamp, Qt::ISODate);
if (!dt.isValid())
if (!dt.isValid()) {
return timestamp; // fallback if parsing fails
}
qint64 secs = dt.secsTo(QDateTime::currentDateTimeUtc());
if (secs < 60)
if (secs < 60) {
return QString("%1 seconds ago").arg(secs);
if (secs < 3600)
}
if (secs < 3600) {
return QString("%1 minutes ago").arg(secs / 60);
if (secs < 86400)
}
if (secs < 86400) {
return QString("%1 hours ago").arg(secs / 3600);
if (secs < 30 * 86400)
}
if (secs < 30 * 86400) {
return QString("%1 days ago").arg(secs / 86400);
if (secs < 365 * 86400)
}
if (secs < 365 * 86400) {
return QString("%1 months ago").arg(secs / (30 * 86400));
}
return QString("%1 years ago").arg(secs / (365 * 86400));
}

View file

@ -93,10 +93,11 @@ void TabArchidekt::initializeUi()
colorLayout->addWidget(manaSymbol);
connect(manaSymbol, &ManaSymbolWidget::colorToggled, this, [this](QChar c, bool active) {
if (active)
if (active) {
activeColors.insert(c);
else
} else {
activeColors.remove(c);
}
doSearch();
});
}
@ -298,16 +299,18 @@ void TabArchidekt::setupFilterWidgets()
searchModel->updateSearchResults(text);
QString pattern = ".*" + QRegularExpression::escape(text) + ".*";
proxyModel->setFilterRegularExpression(QRegularExpression(pattern, QRegularExpression::CaseInsensitiveOption));
if (!text.isEmpty())
if (!text.isEmpty()) {
completer->complete();
}
});
connect(commandersField, &QLineEdit::textChanged, this, [=](const QString &text) {
searchModel->updateSearchResults(text);
QString pattern = ".*" + QRegularExpression::escape(text) + ".*";
proxyModel->setFilterRegularExpression(QRegularExpression(pattern, QRegularExpression::CaseInsensitiveOption));
if (!text.isEmpty())
if (!text.isEmpty()) {
completer->complete();
}
});
// Assemble secondary toolbar
@ -492,12 +495,13 @@ QString TabArchidekt::buildSearchUrl()
QString logic = "GTE";
QString selected = minDeckSizeLogicCombo->currentText();
if (selected == "")
if (selected == "") {
logic = "GTE";
else if (selected == "")
} else if (selected == "") {
logic = "LTE";
else
} else {
logic = "";
}
if (!logic.isEmpty()) {
query.addQueryItem("sizeLogic", logic);

View file

@ -81,8 +81,9 @@ void TabDeckEditor::createMenus()
QString TabDeckEditor::getTabText() const
{
QString result = tr("Deck: %1").arg(deckStateManager->getSimpleDeckName());
if (deckStateManager->isModified())
if (deckStateManager->isModified()) {
result.prepend("* ");
}
return result;
}
@ -137,9 +138,9 @@ void TabDeckEditor::loadLayout()
LayoutsSettings &layouts = SettingsCache::instance().layouts();
auto layoutState = layouts.getDeckEditorLayoutState();
if (layoutState.isNull())
if (layoutState.isNull()) {
restartLayout();
else {
} else {
restoreState(layoutState);
restoreGeometry(layouts.getDeckEditorGeometry());
}

View file

@ -181,8 +181,9 @@ void TabDeckStorage::retranslateUi()
QString TabDeckStorage::getTargetPath() const
{
RemoteDeckList_TreeModel::Node *curRight = serverDirView->getCurrentItem();
if (curRight == nullptr)
if (curRight == nullptr) {
return {};
}
auto *dir = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight);
if (dir == nullptr) {
dir = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight->getParent());
@ -237,13 +238,15 @@ void TabDeckStorage::actOpenLocalDeck()
{
QModelIndexList curLefts = localDirView->selectionModel()->selectedRows();
for (const auto &curLeft : curLefts) {
if (localDirModel->isDir(curLeft))
if (localDirModel->isDir(curLeft)) {
continue;
}
QString filePath = localDirModel->filePath(curLeft);
std::optional<LoadedDeck> deckOpt = DeckLoader::loadFromFile(filePath, DeckFileFormat::Cockatrice, true);
if (!deckOpt)
if (!deckOpt) {
continue;
}
emit openDeckEditor(deckOpt.value());
}
@ -320,10 +323,12 @@ void TabDeckStorage::uploadDeck(const QString &filePath, const QString &targetPa
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)
if (!ok) {
return;
if (deckName.isEmpty())
}
if (deckName.isEmpty()) {
deckName = tr("Unnamed deck");
}
deck.setName(deckName);
} else {
deck.setName(deck.getName().left(MAX_NAME_LENGTH));
@ -372,8 +377,9 @@ void TabDeckStorage::actNewLocalFolder()
bool ok;
QString folderName =
QInputDialog::getText(this, tr("New folder"), tr("Name of new folder:"), QLineEdit::Normal, "", &ok);
if (!ok || folderName.isEmpty())
if (!ok || folderName.isEmpty()) {
return;
}
localDirModel->mkdir(dirIndex, folderName);
}
@ -387,8 +393,9 @@ void TabDeckStorage::actDeleteLocalDeck()
}
if (QMessageBox::warning(this, tr("Delete local file"), tr("Are you sure you want to delete the selected files?"),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
return;
}
for (const auto &curLeft : curLefts) {
if (curLeft.isValid()) {
@ -414,8 +421,9 @@ void TabDeckStorage::actOpenRemoteDeck()
{
for (const auto &curRight : serverDirView->getCurrentSelection()) {
RemoteDeckList_TreeModel::FileNode *node = dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(curRight);
if (!node)
if (!node) {
continue;
}
Command_DeckDownload cmd;
cmd.set_deck_id(node->getId());
@ -428,15 +436,17 @@ void TabDeckStorage::actOpenRemoteDeck()
void TabDeckStorage::openRemoteDeckFinished(const Response &r, const CommandContainer &commandContainer)
{
if (r.response_code() != Response::RespOk)
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);
std::optional<LoadedDeck> deckOpt = DeckLoader::loadFromRemote(QString::fromStdString(resp.deck()), cmd.deck_id());
if (!deckOpt)
if (!deckOpt) {
return;
}
emit openDeckEditor(deckOpt.value());
}
@ -488,8 +498,9 @@ void TabDeckStorage::downloadFinished(const Response &r,
const CommandContainer & /*commandContainer*/,
const QVariant &extraData)
{
if (r.response_code() != Response::RespOk)
if (r.response_code() != Response::RespOk) {
return;
}
const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext);
QString filePath = extraData.toString();
@ -504,12 +515,14 @@ 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
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())
if (folderName.isEmpty()) {
return;
}
// '/' isn't a valid filename character on *nix so we're choosing to replace it with a different arbitrary
// character.
@ -527,8 +540,9 @@ void TabDeckStorage::actNewFolder()
void TabDeckStorage::newFolderFinished(const Response &response, const CommandContainer &commandContainer)
{
if (response.response_code() != Response::RespOk)
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()),
@ -562,8 +576,9 @@ void TabDeckStorage::deleteRemoteDeck(const RemoteDeckList_TreeModel::Node *curR
PendingCommand *pend;
if (const auto *dir = dynamic_cast<const RemoteDeckList_TreeModel::DirectoryNode *>(curRight)) {
QString targetPath = dir->getPath();
if (targetPath.isEmpty())
if (targetPath.isEmpty()) {
return;
}
if (targetPath.length() > MAX_NAME_LENGTH) {
qCritical() << "target path to delete is too long" << targetPath;
return;
@ -585,22 +600,26 @@ void TabDeckStorage::deleteRemoteDeck(const RemoteDeckList_TreeModel::Node *curR
void TabDeckStorage::deleteDeckFinished(const Response &response, const CommandContainer &commandContainer)
{
if (response.response_code() != Response::RespOk)
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)
if (toDelete) {
serverDirView->removeNode(toDelete);
}
}
void TabDeckStorage::deleteFolderFinished(const Response &response, const CommandContainer &commandContainer)
{
if (response.response_code() != Response::RespOk)
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)
if (toDelete) {
serverDirView->removeNode(toDelete);
}
}

View file

@ -125,8 +125,9 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor,
refreshShortcuts();
// append game to rooms game list for others to see
for (int i = game->getGameMetaInfo()->gameTypesSize() - 1; i >= 0; i--)
for (int i = game->getGameMetaInfo()->gameTypesSize() - 1; i >= 0; i--) {
gameTypes.append(game->getGameMetaInfo()->findRoomGameType(i));
}
QTimer::singleShot(0, this, &TabGame::loadLayout);
}
@ -282,12 +283,14 @@ void TabGame::retranslateUi()
updatePlayerListDockTitle();
cardInfoDock->setWindowTitle(tr("Card Info") + (cardInfoDock->isWindow() ? tabText : QString()));
messageLayoutDock->setWindowTitle(tr("Messages") + (messageLayoutDock->isWindow() ? tabText : QString()));
if (replayDock)
if (replayDock) {
replayDock->setWindowTitle(tr("Replay Timeline") + (replayDock->isWindow() ? tabText : QString()));
}
if (phasesMenu) {
for (int i = 0; i < phaseActions.size(); ++i)
for (int i = 0; i < phaseActions.size(); ++i) {
phaseActions[i]->setText(phasesToolbar->getLongPhaseName(i));
}
phasesMenu->setTitle(tr("&Phases"));
}
@ -313,8 +316,9 @@ void TabGame::retranslateUi()
if (aRotateViewCCW) {
aRotateViewCCW->setText(tr("Rotate View Co&unterclockwise"));
}
if (aGameInfo)
if (aGameInfo) {
aGameInfo->setText(tr("Game &information"));
}
if (aConcede) {
if (game->getPlayerManager()->isMainPlayerConceded()) {
aConcede->setText(tr("Un&concede"));
@ -361,11 +365,13 @@ void TabGame::retranslateUi()
QMapIterator<int, Player *> i(game->getPlayerManager()->getPlayers());
while (i.hasNext())
while (i.hasNext()) {
i.next().value()->getGraphicsItem()->retranslateUi();
}
QMapIterator<int, TabbedDeckViewContainer *> j(deckViewContainers);
while (j.hasNext())
while (j.hasNext()) {
j.next().value()->playerDeckView->retranslateUi();
}
scene->retranslateUi();
}
@ -484,18 +490,21 @@ void TabGame::actGameInfo()
void TabGame::actConcede()
{
Player *player = game->getPlayerManager()->getActiveLocalPlayer(game->getGameState()->getActivePlayer());
if (player == nullptr)
if (player == nullptr) {
return;
}
if (!player->getConceded()) {
if (QMessageBox::question(this, tr("Concede"), tr("Are you sure you want to concede this game?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) {
return;
}
emit game->getPlayerManager()->activeLocalPlayerConceded();
} else {
if (QMessageBox::question(this, tr("Unconcede"),
tr("You have already conceded. Do you want to return to this game?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) {
return;
}
emit game->getPlayerManager()->activeLocalPlayerUnconceded();
}
}
@ -511,20 +520,23 @@ bool TabGame::leaveGame()
if (!game->getPlayerManager()->isSpectator()) {
tabSupervisor->setCurrentWidget(this);
if (QMessageBox::question(this, tr("Leave game"), tr("Are you sure you want to leave this game?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) {
return false;
}
}
if (!replayDock)
if (!replayDock) {
emit gameLeft();
}
}
return true;
}
void TabGame::actSay()
{
if (completer->popup()->isVisible())
if (completer->popup()->isVisible()) {
return;
}
if (sayEdit->text().startsWith("/card ")) {
cardInfoFrameWidget->setCard(sayEdit->text().mid(6));
@ -569,8 +581,9 @@ void TabGame::actPhaseAction()
void TabGame::actNextPhase()
{
int phase = game->getGameState()->getCurrentPhase();
if (++phase >= phasesToolbar->phaseCount())
if (++phase >= phasesToolbar->phaseCount()) {
phase = 0;
}
emit phaseChanged(phase);
}
@ -596,8 +609,9 @@ void TabGame::actRemoveLocalArrows()
QMapIterator<int, Player *> playerIterator(game->getPlayerManager()->getPlayers());
while (playerIterator.hasNext()) {
Player *player = playerIterator.next().value();
if (!player->getPlayerInfo()->getLocal())
if (!player->getPlayerInfo()->getLocal()) {
continue;
}
QMapIterator<int, ArrowItem *> arrowIterator(player->getArrows());
while (arrowIterator.hasNext()) {
ArrowItem *a = arrowIterator.next().value();
@ -807,8 +821,9 @@ void TabGame::startGame(bool _resuming)
if (!_resuming) {
QMapIterator<int, Player *> playerIterator(game->getPlayerManager()->getPlayers());
while (playerIterator.hasNext())
while (playerIterator.hasNext()) {
playerIterator.next().value()->setGameStarted();
}
}
playerListWidget->setGameStarted(true, game->getGameState()->isResuming());
@ -851,8 +866,9 @@ void TabGame::closeGame()
Player *TabGame::setActivePlayer(int id)
{
Player *player = game->getPlayerManager()->getPlayer(id);
if (!player)
if (!player) {
return nullptr;
}
playerListWidget->setActivePlayer(id);
QMapIterator<int, Player *> i(game->getPlayerManager()->getPlayers());
@ -894,26 +910,31 @@ QString TabGame::getTabText() const
QString gameTypeInfo;
if (!gameTypes.empty()) {
gameTypeInfo = gameTypes.at(0);
if (gameTypes.size() > 1)
if (gameTypes.size() > 1) {
gameTypeInfo.append("...");
}
}
QString gameDesc(game->getGameMetaInfo()->description());
QString gameId(QString::number(game->getGameMetaInfo()->gameId()));
QString tabText;
if (replayDock)
if (replayDock) {
tabText.append(tr("Replay") + " ");
if (!gameTypeInfo.isEmpty())
tabText.append(gameTypeInfo + " ");
if (!gameDesc.isEmpty()) {
if (gameDesc.length() >= 15)
tabText.append("| " + gameDesc.left(15) + "... ");
else
tabText.append("| " + gameDesc + " ");
}
if (!tabText.isEmpty())
if (!gameTypeInfo.isEmpty()) {
tabText.append(gameTypeInfo + " ");
}
if (!gameDesc.isEmpty()) {
if (gameDesc.length() >= 15) {
tabText.append("| " + gameDesc.left(15) + "... ");
} else {
tabText.append("| " + gameDesc + " ");
}
}
if (!tabText.isEmpty()) {
tabText.append("| ");
}
tabText.append("#" + gameId);
return tabText;
@ -1127,9 +1148,10 @@ void TabGame::actResetLayout()
void TabGame::createPlayAreaWidget(bool bReplay)
{
phasesToolbar = new PhasesToolbar;
if (!bReplay)
if (!bReplay) {
connect(phasesToolbar, &PhasesToolbar::sendGameCommand, game->getGameEventHandler(),
qOverload<const ::google::protobuf::Message &, int>(&GameEventHandler::sendGameCommand));
}
scene = new GameScene(phasesToolbar, this);
connect(game->getPlayerManager(), &PlayerManager::playerConceded, scene, &GameScene::rearrange);
connect(game->getPlayerManager(), &PlayerManager::playerCountChanged, scene, &GameScene::rearrange);

View file

@ -83,18 +83,22 @@ void TabLog::getClicked()
privateChat->setChecked(true);
}
if (maximumResults->value() == 0)
if (maximumResults->value() == 0) {
maximumResults->setValue(1000);
}
int dateRange = 0;
if (lastHour->isChecked())
if (lastHour->isChecked()) {
dateRange = 1;
}
if (today->isChecked())
if (today->isChecked()) {
dateRange = 24;
}
if (pastDays->isChecked())
if (pastDays->isChecked()) {
dateRange = pastXDays->value() * 24;
}
Command_ViewLogHistory cmd;
cmd.set_user_name(findUsername->text().toStdString());

View file

@ -72,8 +72,9 @@ void TabMessage::retranslateUi()
void TabMessage::tabActivated()
{
if (!sayEdit->hasFocus())
if (!sayEdit->hasFocus()) {
sayEdit->setFocus();
}
}
QString TabMessage::getUserName() const
@ -94,8 +95,9 @@ void TabMessage::closeEvent(QCloseEvent *event)
void TabMessage::sendMessage()
{
if (sayEdit->text().isEmpty() || !userOnline)
if (sayEdit->text().isEmpty() || !userOnline) {
return;
}
Command_Message cmd;
cmd.set_user_name(otherUserInfo->name());
@ -110,9 +112,10 @@ void TabMessage::sendMessage()
void TabMessage::messageSent(const Response &response)
{
if (response.response_code() == Response::RespInIgnoreList)
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::processUserMessageEvent(const Event_UserMessage &event)
@ -120,12 +123,15 @@ void TabMessage::processUserMessageEvent(const Event_UserMessage &event)
auto userInfo = event.sender_name() == otherUserInfo->name() ? otherUserInfo : ownUserInfo;
chatView->appendMessage(QString::fromStdString(event.message()), {}, *userInfo, true);
if (tabSupervisor->currentIndex() != tabSupervisor->indexOf(this))
if (tabSupervisor->currentIndex() != tabSupervisor->indexOf(this)) {
soundEngine->playSound("private_message");
if (SettingsCache::instance().getShowMessagePopup() && shouldShowSystemPopup(event))
}
if (SettingsCache::instance().getShowMessagePopup() && shouldShowSystemPopup(event)) {
showSystemPopup(event);
if (QString::fromStdString(event.sender_name()).toLower().simplified() == "servatrice")
}
if (QString::fromStdString(event.sender_name()).toLower().simplified() == "servatrice") {
sayEdit->setDisabled(true);
}
emit userEvent();
}

View file

@ -256,13 +256,15 @@ void TabReplays::actOpenLocalReplay()
{
QModelIndexList curLefts = localDirView->selectionModel()->selectedRows();
for (const auto &curLeft : curLefts) {
if (localDirModel->isDir(curLeft))
if (localDirModel->isDir(curLeft)) {
continue;
}
QString filePath = localDirModel->filePath(curLeft);
QFile f(filePath);
if (!f.open(QIODevice::ReadOnly))
if (!f.open(QIODevice::ReadOnly)) {
continue;
}
QByteArray _data = f.readAll();
f.close();
@ -319,8 +321,9 @@ void TabReplays::actNewLocalFolder()
bool ok;
QString folderName =
QInputDialog::getText(this, tr("New folder"), tr("Name of new folder:"), QLineEdit::Normal, "", &ok);
if (!ok || folderName.isEmpty())
if (!ok || folderName.isEmpty()) {
return;
}
localDirModel->mkdir(dirIndex, folderName);
}
@ -378,8 +381,9 @@ void TabReplays::actOpenRemoteReplay()
void TabReplays::openRemoteReplayFinished(const Response &r)
{
if (r.response_code() != Response::RespOk)
if (r.response_code() != Response::RespOk) {
return;
}
const Response_ReplayDownload &resp = r.GetExtension(Response_ReplayDownload::ext);
GameReplay *replay = new GameReplay;
@ -438,8 +442,9 @@ void TabReplays::downloadFinished(const Response &r,
const CommandContainer & /* commandContainer */,
const QVariant &extraData)
{
if (r.response_code() != Response::RespOk)
if (r.response_code() != Response::RespOk) {
return;
}
const Response_ReplayDownload &resp = r.GetExtension(Response_ReplayDownload::ext);
QString filePath = extraData.toString();
@ -475,8 +480,9 @@ void TabReplays::actKeepRemoteReplay()
void TabReplays::keepRemoteReplayFinished(const Response &r, const CommandContainer &commandContainer)
{
if (r.response_code() != Response::RespOk)
if (r.response_code() != Response::RespOk) {
return;
}
const Command_ReplayModifyMatch &cmd =
commandContainer.session_command(0).GetExtension(Command_ReplayModifyMatch::ext);
@ -513,8 +519,9 @@ void TabReplays::actDeleteRemoteReplay()
void TabReplays::deleteRemoteReplayFinished(const Response &r, const CommandContainer &commandContainer)
{
if (r.response_code() != Response::RespOk)
if (r.response_code() != Response::RespOk) {
return;
}
const Command_ReplayDeleteMatch &cmd =
commandContainer.session_command(0).GetExtension(Command_ReplayDeleteMatch::ext);

View file

@ -41,9 +41,10 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor,
ownUser(_ownUser), userListProxy(_tabSupervisor->getUserListManager())
{
const int gameTypeListSize = info.gametype_list_size();
for (int i = 0; i < gameTypeListSize; ++i)
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);
@ -117,8 +118,9 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor,
userList->sortItems();
const int gameListSize = info.game_list_size();
for (int i = 0; i < gameListSize; ++i)
for (int i = 0; i < gameListSize; ++i) {
gameSelector->processGameInfo(info.game_list(i));
}
completer = new QCompleter(autocompleteUserList, sayEdit);
completer->setCaseSensitivity(Qt::CaseInsensitive);
@ -182,8 +184,9 @@ void TabRoom::closeEvent(QCloseEvent *event)
void TabRoom::tabActivated()
{
if (!sayEdit->hasFocus())
if (!sayEdit->hasFocus()) {
sayEdit->setFocus();
}
}
QString TabRoom::sanitizeHtml(QString dirty) const
@ -211,8 +214,9 @@ void TabRoom::sendMessage()
void TabRoom::sayFinished(const Response &response)
{
if (response.response_code() == Response::RespChatFlood)
if (response.response_code() == Response::RespChatFlood) {
chatView->appendMessage(tr("You are flooding the chat. Please wait a couple of seconds."));
}
}
void TabRoom::actClearChat()
@ -258,8 +262,9 @@ void TabRoom::processRoomEvent(const RoomEvent &event)
void TabRoom::processListGamesEvent(const Event_ListGames &event)
{
const int gameListSize = event.game_list_size();
for (int i = 0; i < gameListSize; ++i)
for (int i = 0; i < gameListSize; ++i) {
gameSelector->processGameInfo(event.game_list(i));
}
}
void TabRoom::processJoinRoomEvent(const Event_JoinRoom &event)
@ -284,26 +289,30 @@ void TabRoom::processRoomSayEvent(const Event_RoomSay &event)
QString senderName = QString::fromStdString(event.name());
QString message = QString::fromStdString(event.message());
if (userListProxy->isUserIgnored(senderName))
if (userListProxy->isUserIgnored(senderName)) {
return;
}
UserListTWI *twi = userList->getUsers().value(senderName);
ServerInfo_User userInfo = {};
if (twi) {
userInfo = twi->getUserInfo();
if (SettingsCache::instance().getIgnoreUnregisteredUsers() &&
!UserLevelFlags(userInfo.user_level()).testFlag(ServerInfo_User::IsRegistered))
!UserLevelFlags(userInfo.user_level()).testFlag(ServerInfo_User::IsRegistered)) {
return;
}
}
if (event.message_type() == Event_RoomSay::ChatHistory && !SettingsCache::instance().getRoomHistory())
if (event.message_type() == Event_RoomSay::ChatHistory && !SettingsCache::instance().getRoomHistory()) {
return;
}
if (event.message_type() == Event_RoomSay::ChatHistory)
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(), userInfo, true);
emit userEvent(false);

View file

@ -69,27 +69,35 @@ void RoomSelector::processListRoomsEvent(const Event_ListRooms &event)
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())
if (room.has_name()) {
twi->setData(0, Qt::DisplayRole, QString::fromStdString(room.name()));
if (room.has_description())
}
if (room.has_description()) {
twi->setData(1, Qt::DisplayRole, QString::fromStdString(room.description()));
if (room.has_permissionlevel())
}
if (room.has_permissionlevel()) {
twi->setData(2, Qt::DisplayRole, getRoomPermissionDisplay(room));
if (room.has_player_count())
}
if (room.has_player_count()) {
twi->setData(3, Qt::DisplayRole, room.player_count());
if (room.has_game_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())
if (room.has_name()) {
twi->setData(0, Qt::DisplayRole, QString::fromStdString(room.name()));
if (room.has_description())
}
if (room.has_description()) {
twi->setData(1, Qt::DisplayRole, QString::fromStdString(room.description()));
if (room.has_permissionlevel())
}
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);
@ -97,9 +105,11 @@ void RoomSelector::processListRoomsEvent(const Event_ListRooms &event)
twi->setTextAlignment(4, Qt::AlignRight);
roomList->addTopLevelItem(twi);
if (room.has_auto_join())
if (room.auto_join())
if (room.has_auto_join()) {
if (room.auto_join()) {
emit joinRoomRequest(room.room_id(), false);
}
}
}
}
@ -113,10 +123,12 @@ QString RoomSelector::getRoomPermissionDisplay(const ServerInfo_Room &room)
*/
QString roomPermissionDisplay = QString::fromStdString(room.privilegelevel()).toLower();
if (QString::fromStdString(room.permissionlevel()).toLower() != "none")
if (QString::fromStdString(room.permissionlevel()).toLower() != "none") {
roomPermissionDisplay = QString::fromStdString(room.permissionlevel()).toLower();
if (roomPermissionDisplay == "") // catch all for misconfigured .ini room definitions
}
if (roomPermissionDisplay == "") { // catch all for misconfigured .ini room definitions
roomPermissionDisplay = "none";
}
return roomPermissionDisplay;
}
@ -124,8 +136,9 @@ QString RoomSelector::getRoomPermissionDisplay(const ServerInfo_Room &room)
void RoomSelector::joinClicked()
{
QTreeWidgetItem *twi = roomList->currentItem();
if (!twi)
if (!twi) {
return;
}
int id = twi->data(0, Qt::UserRole).toInt();
@ -185,8 +198,9 @@ void TabServer::joinRoom(int id, bool setCurrent)
return;
}
if (setCurrent)
if (setCurrent) {
tabSupervisor->setCurrentWidget((QWidget *)room);
}
}
void TabServer::joinRoomFinished(const Response &r,

View file

@ -86,18 +86,22 @@ void CloseButton::paintEvent(QPaintEvent * /*event*/)
QStyleOption opt;
opt.initFrom(this);
opt.state |= QStyle::State_AutoRaise;
if (isEnabled() && underMouse() && !isChecked() && !isDown())
if (isEnabled() && underMouse() && !isChecked() && !isDown()) {
opt.state |= QStyle::State_Raised;
if (isChecked())
}
if (isChecked()) {
opt.state |= QStyle::State_On;
if (isDown())
}
if (isDown()) {
opt.state |= QStyle::State_Sunken;
}
if (const auto *tb = qobject_cast<const QTabBar *>(parent())) {
int index = tb->currentIndex();
auto position = (QTabBar::ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, nullptr, tb);
if (tb->tabButton(index, position) == this)
if (tb->tabButton(index, position) == this) {
opt.state |= QStyle::State_Selected;
}
}
style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, &p, this);
@ -228,20 +232,25 @@ void TabSupervisor::retranslateUi()
tabs.append(tabAccount);
tabs.append(tabLog);
QMapIterator<int, TabRoom *> roomIterator(roomTabs);
while (roomIterator.hasNext())
while (roomIterator.hasNext()) {
tabs.append(roomIterator.next().value());
}
QMapIterator<int, TabGame *> gameIterator(gameTabs);
while (gameIterator.hasNext())
while (gameIterator.hasNext()) {
tabs.append(gameIterator.next().value());
}
QListIterator<TabGame *> replayIterator(replayTabs);
while (replayIterator.hasNext())
while (replayIterator.hasNext()) {
tabs.append(replayIterator.next());
}
QListIterator<AbstractTabDeckEditor *> deckEditorIterator(deckEditorTabs);
while (deckEditorIterator.hasNext())
while (deckEditorIterator.hasNext()) {
tabs.append(deckEditorIterator.next());
}
QMapIterator<QString, TabMessage *> messageIterator(messageTabs);
while (messageIterator.hasNext())
while (messageIterator.hasNext()) {
tabs.append(messageIterator.next().value());
}
for (auto &tab : tabs) {
if (tab) {
@ -448,9 +457,10 @@ void TabSupervisor::startLocal(const QList<AbstractClient *> &_clients)
isLocalGame = true;
userInfo = new ServerInfo_User;
localClients = _clients;
for (int i = 0; i < localClients.size(); ++i)
for (int i = 0; i < localClients.size(); ++i) {
connect(localClients[i], &AbstractClient::gameEventContainerReceived, this,
&TabSupervisor::processGameEventContainer);
}
connect(localClients.first(), &AbstractClient::gameJoinedEventReceived, this, &TabSupervisor::localGameJoined);
}
@ -459,8 +469,9 @@ void TabSupervisor::startLocal(const QList<AbstractClient *> &_clients)
*/
void TabSupervisor::stop()
{
if ((!client) && localClients.isEmpty())
if ((!client) && localClients.isEmpty()) {
return;
}
resetTabsMenu();
@ -694,10 +705,12 @@ void TabSupervisor::openTabLog()
void TabSupervisor::updatePingTime(int value, int max)
{
if (!tabServer)
if (!tabServer) {
return;
if (tabServer->getContentsChanged())
}
if (tabServer->getContentsChanged()) {
return;
}
setTabIcon(indexOf(tabServer), QIcon(PingPixmapGenerator::generatePixmap(15, value, max)));
}
@ -706,12 +719,14 @@ void TabSupervisor::gameJoined(const Event_GameJoined &event)
{
QMap<int, QString> roomGameTypes;
TabRoom *room = roomTabs.value(event.game_info().room_id());
if (room)
if (room) {
roomGameTypes = room->getGameTypes();
else
for (int i = 0; i < event.game_types_size(); ++i)
} 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()));
}
}
auto *tab = new TabGame(this, QList<AbstractClient *>() << client, event, roomGameTypes);
connect(tab, &TabGame::gameClosing, this, &TabSupervisor::gameLeft);
@ -740,14 +755,16 @@ void TabSupervisor::localGameJoined(const Event_GameJoined &event)
void TabSupervisor::gameLeft(TabGame *tab)
{
if (tab == currentWidget())
if (tab == currentWidget()) {
emit setMenu();
}
gameTabs.remove(tab->getGame()->getGameMetaInfo()->gameId());
removeTab(indexOf(tab));
if (!localClients.isEmpty())
if (!localClients.isEmpty()) {
stop();
}
}
void TabSupervisor::addRoomTab(const ServerInfo_Room &info, bool setCurrent)
@ -758,14 +775,16 @@ void TabSupervisor::addRoomTab(const ServerInfo_Room &info, bool setCurrent)
connect(tab, &TabRoom::openMessageDialog, this, &TabSupervisor::addMessageTab);
myAddTab(tab);
roomTabs.insert(info.room_id(), tab);
if (setCurrent)
if (setCurrent) {
setCurrentWidget(tab);
}
}
void TabSupervisor::roomLeft(TabRoom *tab)
{
if (tab == currentWidget())
if (tab == currentWidget()) {
emit setMenu();
}
roomTabs.remove(tab->getRoomId());
removeTab(indexOf(tab));
@ -793,16 +812,18 @@ void TabSupervisor::openReplay(GameReplay *replay)
void TabSupervisor::replayLeft(TabGame *tab)
{
if (tab == currentWidget())
if (tab == currentWidget()) {
emit setMenu();
}
replayTabs.removeOne(tab);
}
TabMessage *TabSupervisor::addMessageTab(const QString &receiverName, bool focus)
{
if (receiverName == QString::fromStdString(userInfo->name()))
if (receiverName == QString::fromStdString(userInfo->name())) {
return nullptr;
}
ServerInfo_User otherUser;
if (auto user = userListManager->getOnlineUser(receiverName)) {
@ -814,8 +835,9 @@ TabMessage *TabSupervisor::addMessageTab(const QString &receiverName, bool focus
TabMessage *tab;
tab = messageTabs.value(QString::fromStdString(otherUser.name()));
if (tab) {
if (focus)
if (focus) {
setCurrentWidget(tab);
}
return tab;
}
@ -824,8 +846,9 @@ TabMessage *TabSupervisor::addMessageTab(const QString &receiverName, bool focus
connect(tab, &TabMessage::maximizeClient, this, &TabSupervisor::maximizeMainWindow);
myAddTab(tab);
messageTabs.insert(receiverName, tab);
if (focus)
if (focus) {
setCurrentWidget(tab);
}
return tab;
}
@ -836,8 +859,9 @@ void TabSupervisor::maximizeMainWindow()
void TabSupervisor::talkLeft(TabMessage *tab)
{
if (tab == currentWidget())
if (tab == currentWidget()) {
emit setMenu();
}
messageTabs.remove(tab->getUserName());
removeTab(indexOf(tab));
@ -934,8 +958,9 @@ TabEdhRec *TabSupervisor::addEdhrecTab(const CardInfoPtr &cardToQuery, bool isCo
void TabSupervisor::deckEditorClosed(AbstractTabDeckEditor *tab)
{
if (tab == currentWidget())
if (tab == currentWidget()) {
emit setMenu();
}
deckEditorTabs.removeOne(tab);
removeTab(indexOf(tab));
@ -948,8 +973,9 @@ void TabSupervisor::tabUserEvent(bool globalEvent)
tab->setContentsChanged(true);
setTabIcon(indexOf(tab), QPixmap("theme:icons/tab_changed"));
}
if (globalEvent && SettingsCache::instance().getNotificationsEnabled())
if (globalEvent && SettingsCache::instance().getNotificationsEnabled()) {
QApplication::alert(this);
}
}
void TabSupervisor::updateTabText(Tab *tab, const QString &newTabText)
@ -962,39 +988,44 @@ void TabSupervisor::updateTabText(Tab *tab, const QString &newTabText)
void TabSupervisor::processRoomEvent(const RoomEvent &event)
{
TabRoom *tab = roomTabs.value(event.room_id(), 0);
if (tab)
if (tab) {
tab->processRoomEvent(event);
}
}
void TabSupervisor::processGameEventContainer(const GameEventContainer &cont)
{
TabGame *tab = gameTabs.value(cont.game_id());
if (tab)
if (tab) {
tab->getGame()->getGameEventHandler()->processGameEventContainer(cont, qobject_cast<AbstractClient *>(sender()),
{});
else
} else {
qCInfo(TabSupervisorLog) << "gameEvent: invalid gameId" << cont.game_id();
}
}
void TabSupervisor::processUserMessageEvent(const Event_UserMessage &event)
{
QString senderName = QString::fromStdString(event.sender_name());
TabMessage *tab = messageTabs.value(senderName);
if (!tab)
if (!tab) {
tab = messageTabs.value(QString::fromStdString(event.receiver_name()));
}
if (!tab) {
const ServerInfo_User *onlineUserInfo = userListManager->getOnlineUser(senderName);
if (onlineUserInfo) {
auto userLevel = UserLevelFlags(onlineUserInfo->user_level());
if (SettingsCache::instance().getIgnoreUnregisteredUserMessages() &&
!userLevel.testFlag(ServerInfo_User::IsRegistered))
!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)
if (!tab) {
return;
}
tab->processUserMessageEvent(event);
}
@ -1012,8 +1043,9 @@ void TabSupervisor::actShowPopup(const QString &message)
void TabSupervisor::processUserLeft(const QString &userName)
{
TabMessage *tab = messageTabs.value(userName);
if (tab)
if (tab) {
tab->processUserLeft();
}
}
void TabSupervisor::processUserJoined(const ServerInfo_User &userInfoJoined)
@ -1037,8 +1069,9 @@ void TabSupervisor::processUserJoined(const ServerInfo_User &userInfoJoined)
}
TabMessage *tab = messageTabs.value(userName);
if (tab)
if (tab) {
tab->processUserJoined(userInfoJoined);
}
}
void TabSupervisor::updateCurrent(int index)
@ -1051,8 +1084,9 @@ void TabSupervisor::updateCurrent(int index)
}
emit setMenu(static_cast<Tab *>(widget(index))->getTabMenus());
tab->tabActivated();
} else
} else {
emit setMenu();
}
}
/**
@ -1062,8 +1096,9 @@ void TabSupervisor::updateCurrent(int index)
*/
bool TabSupervisor::getAdminLocked() const
{
if (!tabAdmin)
if (!tabAdmin) {
return true;
}
return tabAdmin->getLocked();
}
@ -1087,12 +1122,13 @@ void TabSupervisor::processNotifyUserEvent(const Event_NotifyUser &event)
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())
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: {

View file

@ -116,8 +116,9 @@ void TabDeckEditorVisual::createMenus()
QString TabDeckEditorVisual::getTabText() const
{
QString result = tr("Visual Deck: %1").arg(deckStateManager->getSimpleDeckName());
if (deckStateManager->isModified())
if (deckStateManager->isModified()) {
result.prepend("* ");
}
return result;
}