Compare commits

...

3 commits

Author SHA1 Message Date
ebbit1q
6be9cec6e2
do not save a const reference to the user data in the info dialog (#6974)
Some checks are pending
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 15 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker Image / amd64 & arm64 (push) Waiting to run
* do not save a const reference to the user data in the info dialog

* cmake format
2026-06-09 23:35:00 -07:00
kongwu
6d0a423dcf
[Messages] Add option to ignore private messages from non-buddy users (#6966)
* [Messages] Add option to ignore private messages from non-buddy users

* [Messages] Exclude Moderator/Admin from non-buddy ignore filter

Moderator and Admin messages should not be filtered out when the
'Ignore private messages from non-buddies' setting is enabled, to
ensure that important warnings from server staff reach users.
2026-06-09 20:49:29 -07:00
kongwu
f72c82d0f9
[DeckEditor] Replace mainboard/sideboard with tokensboard for tokens (#6971)
* [DeckEditor] Replace mainboard/sideboard with tokensboard for token cards (#6546)

* [PrintingSelector] Replace std::tuple with ZoneCounts struct for readability (#6546)
2026-06-09 20:46:43 -07:00
21 changed files with 174 additions and 66 deletions

View file

@ -388,6 +388,7 @@ SettingsCache::SettingsCache()
ignoreUnregisteredUsers = settings->value("chat/ignore_unregistered", false).toBool();
ignoreUnregisteredUserMessages = settings->value("chat/ignore_unregistered_messages", false).toBool();
ignoreNonBuddyUserMessages = settings->value("chat/ignore_nonbuddy_messages", false).toBool();
scaleCards = settings->value("cards/scaleCards", true).toBool();
verticalCardOverlapPercent = settings->value("cards/verticalCardOverlapPercent", 33).toInt();
@ -1117,6 +1118,12 @@ void SettingsCache::setIgnoreUnregisteredUserMessages(QT_STATE_CHANGED_T _ignore
settings->setValue("chat/ignore_unregistered_messages", ignoreUnregisteredUserMessages);
}
void SettingsCache::setIgnoreNonBuddyUserMessages(QT_STATE_CHANGED_T _ignoreNonBuddyUserMessages)
{
ignoreNonBuddyUserMessages = static_cast<bool>(_ignoreNonBuddyUserMessages);
settings->setValue("chat/ignore_nonbuddy_messages", ignoreNonBuddyUserMessages);
}
void SettingsCache::setPixmapCacheSize(const int _pixmapCacheSize)
{
pixmapCacheSize = _pixmapCacheSize;

View file

@ -183,6 +183,7 @@ signals:
void soundThemeChanged();
void ignoreUnregisteredUsersChanged();
void ignoreUnregisteredUserMessagesChanged();
void ignoreNonBuddyUserMessagesChanged();
void pixmapCacheSizeChanged(int newSizeInMBs);
void networkCacheSizeChanged(int newSizeInMBs);
void redirectCacheTtlChanged(int newTtl);
@ -294,6 +295,7 @@ private:
QString soundThemeName;
bool ignoreUnregisteredUsers;
bool ignoreUnregisteredUserMessages;
bool ignoreNonBuddyUserMessages;
QString picUrl;
QString picUrlFallback;
QString clientID;
@ -788,6 +790,10 @@ public:
{
return ignoreUnregisteredUserMessages;
}
[[nodiscard]] bool getIgnoreNonBuddyUserMessages() const
{
return ignoreNonBuddyUserMessages;
}
[[nodiscard]] int getPixmapCacheSize() const
{
return pixmapCacheSize;
@ -1111,6 +1117,7 @@ public slots:
void setSoundThemeName(const QString &_soundThemeName);
void setIgnoreUnregisteredUsers(QT_STATE_CHANGED_T _ignoreUnregisteredUsers);
void setIgnoreUnregisteredUserMessages(QT_STATE_CHANGED_T _ignoreUnregisteredUserMessages);
void setIgnoreNonBuddyUserMessages(QT_STATE_CHANGED_T _ignoreNonBuddyUserMessages);
void setPixmapCacheSize(const int _pixmapCacheSize);
void setCardImageCacheMethod(CardPictureLoaderCacheMethod::CacheMethod _cardImageCachingMethod);
void setNetworkCacheSizeInMB(const int _networkCacheSize);

View file

@ -255,6 +255,10 @@ bool DeckStateManager::swapCardAtIndex(const QModelIndex &idx)
}
QString zoneName = gparent.siblingAtColumn(DeckListModelColumns::CARD_NAME).data(Qt::EditRole).toString();
// tokens have no swap target
if (zoneName == DECK_ZONE_TOKENS) {
return false;
}
QString otherZoneName = zoneName == DECK_ZONE_MAIN ? DECK_ZONE_SIDE : DECK_ZONE_MAIN;
QString reason = tr("Moved to %1 1 × \"%2\" (%3)") //

View file

@ -8,7 +8,7 @@
* @brief Constructor for the AllZonesCardAmountWidget class.
*
* Initializes the widget with its layout and sets up the connections and necessary
* UI elements for managing card counts in both the mainboard and sideboard zones.
* UI elements for managing card counts in all the mainboard, tokensboard and sideboard zones.
*
* @param parent The parent widget.
* @param deckStateManager Pointer to the DeckStateManager
@ -31,13 +31,28 @@ AllZonesCardAmountWidget::AllZonesCardAmountWidget(QWidget *parent,
buttonBoxMainboard = new CardAmountWidget(this, deckStateManager, cardSizeSlider, rootCard, DECK_ZONE_MAIN);
zoneLabelSideboard = new ShadowBackgroundLabel(this, tr("Sideboard"));
buttonBoxSideboard = new CardAmountWidget(this, deckStateManager, cardSizeSlider, rootCard, DECK_ZONE_SIDE);
zoneLabelTokensboard = new ShadowBackgroundLabel(this, tr("Tokens"));
buttonBoxTokensboard = new CardAmountWidget(this, deckStateManager, cardSizeSlider, rootCard, DECK_ZONE_TOKENS);
layout->addWidget(zoneLabelMainboard, 0, Qt::AlignHCenter | Qt::AlignBottom);
layout->addWidget(buttonBoxMainboard, 0, Qt::AlignHCenter | Qt::AlignTop);
layout->addSpacing(25);
layout->addSpacing(12);
layout->addWidget(zoneLabelTokensboard, 0, Qt::AlignHCenter | Qt::AlignBottom);
layout->addWidget(buttonBoxTokensboard, 0, Qt::AlignHCenter | Qt::AlignTop);
layout->addSpacing(13);
layout->addWidget(zoneLabelSideboard, 0, Qt::AlignHCenter | Qt::AlignBottom);
layout->addWidget(buttonBoxSideboard, 0, Qt::AlignHCenter | Qt::AlignTop);
// Show Tokens buttons for token cards, Mainboard/Sideboard for non-token cards
bool isToken = rootCard.getInfo().getIsToken();
zoneLabelMainboard->setVisible(!isToken);
buttonBoxMainboard->setVisible(!isToken);
zoneLabelTokensboard->setVisible(isToken);
buttonBoxTokensboard->setVisible(isToken);
zoneLabelSideboard->setVisible(!isToken);
buttonBoxSideboard->setVisible(!isToken);
connect(cardSizeSlider, &QSlider::valueChanged, this, &AllZonesCardAmountWidget::adjustFontSize);
QTimer::singleShot(10, this, [this]() { adjustFontSize(this->cardSizeSlider->value()); });
@ -67,15 +82,17 @@ void AllZonesCardAmountWidget::adjustFontSize(int scalePercentage)
zoneLabelFont.setPointSize(newFontSize);
zoneLabelMainboard->setFont(zoneLabelFont);
zoneLabelSideboard->setFont(zoneLabelFont);
zoneLabelTokensboard->setFont(zoneLabelFont);
// Repaint the widget (if necessary)
repaint();
}
void AllZonesCardAmountWidget::setAmounts(int mainboardAmount, int sideboardAmount)
void AllZonesCardAmountWidget::setAmounts(int mainboardAmount, int sideboardAmount, int tokensboardAmount)
{
buttonBoxMainboard->setAmount(mainboardAmount);
buttonBoxSideboard->setAmount(sideboardAmount);
buttonBoxTokensboard->setAmount(tokensboardAmount);
}
/**
@ -99,11 +116,21 @@ int AllZonesCardAmountWidget::getSideboardAmount()
}
/**
* @brief Checks if the amount is at least one in either the mainboard or sideboard.
* @brief Gets the card count in the tokensboard zone.
*
* @return The number of cards in the tokensboard.
*/
int AllZonesCardAmountWidget::getTokensboardAmount()
{
return buttonBoxTokensboard->getAmount();
}
/**
* @brief Checks if the amount is at least one in either the mainboard or sideboard or tokensboard.
*/
bool AllZonesCardAmountWidget::isNonZero()
{
return getMainboardAmount() > 0 || getSideboardAmount() > 0;
return getMainboardAmount() > 0 || getSideboardAmount() > 0 || getTokensboardAmount() > 0;
}
/**

View file

@ -23,6 +23,7 @@ public:
const ExactCard &rootCard);
int getMainboardAmount();
int getSideboardAmount();
int getTokensboardAmount();
bool isNonZero();
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
@ -33,7 +34,7 @@ public:
public slots:
void adjustFontSize(int scalePercentage);
void setAmounts(int mainboardAmount, int sideboardAmount);
void setAmounts(int mainboardAmount, int sideboardAmount, int tokensboardAmount);
private:
QVBoxLayout *layout;
@ -42,6 +43,8 @@ private:
CardAmountWidget *buttonBoxMainboard;
QLabel *zoneLabelSideboard;
CardAmountWidget *buttonBoxSideboard;
QLabel *zoneLabelTokensboard;
CardAmountWidget *buttonBoxTokensboard;
};
#endif // ALL_ZONES_CARD_AMOUNT_WIDGET_H

View file

@ -11,7 +11,7 @@
* @param parent The parent widget.
* @param cardSizeSlider Pointer to the QSlider for adjusting font size.
* @param rootCard The root card to manage within the widget.
* @param zoneName The zone name (e.g., DECK_ZONE_MAIN or DECK_ZONE_SIDE).
* @param zoneName The zone name (e.g., DECK_ZONE_MAIN , DECK_ZONE_SIDE, or DECK_ZONE_TOKENS).
*/
CardAmountWidget::CardAmountWidget(QWidget *parent,
DeckStateManager *deckStateManager,
@ -36,13 +36,16 @@ CardAmountWidget::CardAmountWidget(QWidget *parent,
incrementButton->setFixedSize(parentWidget()->size().width() / 3, parentWidget()->size().height() / 9);
decrementButton->setFixedSize(parentWidget()->size().width() / 3, parentWidget()->size().height() / 9);
// Set up connections based on the zone (Mainboard or Sideboard)
// Set up connections based on the zone (Mainboard, Sideboard, or Tokensboard)
if (zoneName == DECK_ZONE_MAIN) {
connect(incrementButton, &QPushButton::clicked, this, &CardAmountWidget::addPrintingMainboard);
connect(decrementButton, &QPushButton::clicked, this, &CardAmountWidget::removePrintingMainboard);
} else if (zoneName == DECK_ZONE_SIDE) {
connect(incrementButton, &QPushButton::clicked, this, &CardAmountWidget::addPrintingSideboard);
connect(decrementButton, &QPushButton::clicked, this, &CardAmountWidget::removePrintingSideboard);
} else if (zoneName == DECK_ZONE_TOKENS) {
connect(incrementButton, &QPushButton::clicked, this, &CardAmountWidget::addPrintingTokensboard);
connect(decrementButton, &QPushButton::clicked, this, &CardAmountWidget::removePrintingTokensboard);
}
cardCountInZone = new QLabel(QString::number(amount), this);
@ -137,6 +140,19 @@ void CardAmountWidget::updateCardCount()
layout->activate();
}
static QString zoneLogName(const QString &zone)
{
if (zone == DECK_ZONE_MAIN) {
return "mainboard";
} else if (zone == DECK_ZONE_SIDE) {
return "sideboard";
} else if (zone == DECK_ZONE_TOKENS) {
return "tokens";
} else {
return "unknown";
}
}
static QModelIndex addAndReplacePrintings(DeckListModel *model,
const QModelIndex &existing,
const ExactCard &rootCard,
@ -161,9 +177,9 @@ static QModelIndex addAndReplacePrintings(DeckListModel *model,
}
/**
* @brief Adds a printing of the card to the specified zone (Mainboard or Sideboard).
* @brief Adds a printing of the card to the specified zone (Mainboard, Sideboard, or Tokensboard).
*
* @param zone The zone to add the card to (DECK_ZONE_MAIN or DECK_ZONE_SIDE).
* @param zone The zone to add the card to (DECK_ZONE_MAIN, DECK_ZONE_SIDE, or DECK_ZONE_TOKENS).
*/
void CardAmountWidget::addPrinting(const QString &zone)
{
@ -183,12 +199,13 @@ void CardAmountWidget::addPrinting(const QString &zone)
}
}
QString zoneName = zoneLogName(zone);
QString reason = QString("Added %1 copies of '%2 (%3) %4' to %5 [ProviderID: %6]%7")
.arg(1 + extraCopies)
.arg(rootCard.getName())
.arg(rootCard.getPrinting().getSet()->getShortName())
.arg(rootCard.getPrinting().getProperty("num"))
.arg(zone == DECK_ZONE_MAIN ? "mainboard" : "sideboard")
.arg(zoneName)
.arg(rootCard.getPrinting().getUuid())
.arg(replacingProviderless ? " (replaced providerless printings)" : "");
@ -218,6 +235,14 @@ void CardAmountWidget::addPrintingSideboard()
addPrinting(DECK_ZONE_SIDE);
}
/**
* @brief Adds a printing to the tokens zone.
*/
void CardAmountWidget::addPrintingTokensboard()
{
addPrinting(DECK_ZONE_TOKENS);
}
/**
* @brief Removes a printing from the mainboard zone.
*/
@ -234,18 +259,27 @@ void CardAmountWidget::removePrintingSideboard()
decrementCardHelper(DECK_ZONE_SIDE);
}
/**
* @brief Removes a printing from the tokens zone.
*/
void CardAmountWidget::removePrintingTokensboard()
{
decrementCardHelper(DECK_ZONE_TOKENS);
}
/**
* @brief Helper function to decrement the card count for a given zone.
*
* @param zone The zone from which to remove the card (DECK_ZONE_MAIN or DECK_ZONE_SIDE).
* @param zone The zone from which to remove the card (DECK_ZONE_MAIN, DECK_ZONE_SIDE, or DECK_ZONE_TOKENS).
*/
void CardAmountWidget::decrementCardHelper(const QString &zone)
{
QString zoneName = zoneLogName(zone);
QString reason = QString("Removed 1 copy of '%1 (%2) %3' from %4 [ProviderID: %5]")
.arg(rootCard.getName())
.arg(rootCard.getPrinting().getSet()->getShortName())
.arg(rootCard.getPrinting().getProperty("num"))
.arg(zone == DECK_ZONE_MAIN ? "mainboard" : "sideboard")
.arg(zoneName)
.arg(rootCard.getPrinting().getUuid());
deckStateManager->modifyDeck(reason, [this, &zone](auto model) {

View file

@ -60,8 +60,10 @@ private:
private slots:
void addPrintingMainboard();
void addPrintingSideboard();
void addPrintingTokensboard();
void removePrintingMainboard();
void removePrintingSideboard();
void removePrintingTokensboard();
void adjustFontSize(int scalePercentage);
};

View file

@ -105,23 +105,30 @@ void PrintingSelector::printingsInDeckChanged()
}
/**
* @return A map of uuid to amounts (main, side).
* @return A map of uuid to amounts (main, side, tokens).
*/
static QMap<QString, QPair<int, int>> tallyUuidCounts(const DeckListModel *model, const QString &cardName)
static QMap<QString, ZoneCounts> tallyUuidCounts(const DeckListModel *model, const QString &cardName)
{
QMap<QString, QPair<int, int>> map;
QMap<QString, ZoneCounts> map;
auto mainNodes = model->getCardNodesForZone(DECK_ZONE_MAIN);
for (auto &node : mainNodes) {
if (node->getName() == cardName) {
map[node->getCardProviderId()].first += node->getNumber();
map[node->getCardProviderId()].mainboard += node->getNumber();
}
}
auto sideNodes = model->getCardNodesForZone(DECK_ZONE_SIDE);
for (auto &node : sideNodes) {
if (node->getName() == cardName) {
map[node->getCardProviderId()].second += node->getNumber();
map[node->getCardProviderId()].sideboard += node->getNumber();
}
}
auto tokensNodes = model->getCardNodesForZone(DECK_ZONE_TOKENS);
for (auto &node : tokensNodes) {
if (node->getName() == cardName) {
map[node->getCardProviderId()].tokensboard += node->getNumber();
}
}

View file

@ -22,6 +22,13 @@
#define BATCH_SIZE 10
struct ZoneCounts
{
int mainboard = 0;
int sideboard = 0;
int tokensboard = 0;
};
class DeckStateManager;
class PrintingSelectorCardSearchWidget;
class PrintingSelectorCardSelectionWidget;
@ -59,9 +66,9 @@ signals:
/**
* The amounts of the printings in the deck has changed
* @param uuidToAmounts Map of uuids to the amounts (maindeck, sideboard) in the deck
* @param uuidToAmounts Map of uuids to the amounts (maindeck, sideboard, tokensboard) in the deck
*/
void cardAmountsChanged(const QMap<QString, QPair<int, int>> &uuidToAmounts);
void cardAmountsChanged(const QMap<QString, ZoneCounts> &uuidToAmounts);
private:
QVBoxLayout *layout;

View file

@ -67,10 +67,10 @@ void PrintingSelectorCardDisplayWidget::clampSetNameToPicture()
update();
}
void PrintingSelectorCardDisplayWidget::updateCardAmounts(const QMap<QString, QPair<int, int>> &uuidToAmounts)
void PrintingSelectorCardDisplayWidget::updateCardAmounts(const QMap<QString, ZoneCounts> &uuidToAmounts)
{
auto [main, side] = uuidToAmounts.value(rootCard.getPrinting().getUuid());
overlayWidget->updateCardAmounts(main, side);
auto counts = uuidToAmounts.value(rootCard.getPrinting().getUuid());
overlayWidget->updateCardAmounts(counts.mainboard, counts.sideboard, counts.tokensboard);
}
void PrintingSelectorCardDisplayWidget::resizeEvent(QResizeEvent *event)

View file

@ -27,7 +27,7 @@ public:
public slots:
void clampSetNameToPicture();
void updateCardAmounts(const QMap<QString, QPair<int, int>> &uuidToAmounts);
void updateCardAmounts(const QMap<QString, ZoneCounts> &uuidToAmounts);
void resizeEvent(QResizeEvent *event) override;

View file

@ -116,9 +116,11 @@ void PrintingSelectorCardOverlayWidget::enterEvent(QEvent *event)
updateVisibility();
}
void PrintingSelectorCardOverlayWidget::updateCardAmounts(int mainboardAmount, int sideboardAmount)
void PrintingSelectorCardOverlayWidget::updateCardAmounts(int mainboardAmount,
int sideboardAmount,
int tokensboardAmount)
{
allZonesCardAmountWidget->setAmounts(mainboardAmount, sideboardAmount);
allZonesCardAmountWidget->setAmounts(mainboardAmount, sideboardAmount, tokensboardAmount);
updateVisibility();
}
@ -173,8 +175,8 @@ void PrintingSelectorCardOverlayWidget::updatePinBadgeVisibility()
/**
* @brief Handles the mouse leave event when the cursor leaves the overlay widget area.
*
* When the cursor leaves the widget, the card amount widget is hidden if both the mainboard and sideboard
* amounts are zero.
* When the cursor leaves the widget, the card amount widget is hidden if all of the mainboard, sideboard, and
* tokensboard amounts are zero.
*
* @param event The event triggered when the mouse leaves the widget.
*/

View file

@ -39,7 +39,7 @@ signals:
void cardPreferenceChanged();
public slots:
void updateCardAmounts(int mainboardAmount, int sideboardAmount);
void updateCardAmounts(int mainboardAmount, int sideboardAmount, int tokensboardAmount);
private slots:
void updateVisibility();

View file

@ -85,24 +85,15 @@ void UserInfoBox::retranslateUi()
avatarButton.setText(tr("Change avatar"));
}
/**
* Creates the default profile pic that is used when the user doesn't have a custom pic
*/
static QPixmap createDefaultAvatar(int height, const ServerInfo_User &user)
{
return UserLevelPixmapGenerator::generatePixmap(height, UserLevelFlags(user.user_level()), user.pawn_colors(),
false, QString::fromStdString(user.privlevel()));
}
void UserInfoBox::updateInfo(const ServerInfo_User &user)
{
currentUserInfo = &user;
const UserLevelFlags userLevel(user.user_level());
userLevel = UserLevelFlags(user.user_level());
pawnColors = user.pawn_colors();
privLevel = QString::fromStdString(user.privlevel());
const std::string &bmp = user.avatar_bmp();
if (!avatarPixmap.loadFromData((const uchar *)bmp.data(), static_cast<uint>(bmp.size()))) {
avatarPixmap = createDefaultAvatar(64, user);
avatarPixmap = UserLevelPixmapGenerator::generatePixmap(64, userLevel, pawnColors, false, privLevel);
hasAvatar = false;
} else {
hasAvatar = true;
@ -120,8 +111,7 @@ void UserInfoBox::updateInfo(const ServerInfo_User &user)
countryLabel3.setText("");
}
userLevelIcon.setPixmap(UserLevelPixmapGenerator::generatePixmap(15, userLevel, user.pawn_colors(), false,
QString::fromStdString(user.privlevel())));
userLevelIcon.setPixmap(UserLevelPixmapGenerator::generatePixmap(15, userLevel, pawnColors, false, privLevel));
QString userLevelText;
if (userLevel.testFlag(ServerInfo_User::IsAdmin)) {
userLevelText = tr("Administrator");
@ -373,7 +363,7 @@ void UserInfoBox::processAvatarResponse(const Response &r)
break;
case Response::RespInternalError:
default:
QMessageBox::critical(this, tr("Error"), tr("An error occured while trying to updater your avatar."));
QMessageBox::critical(this, tr("Error"), tr("An error occured while trying to update your avatar."));
break;
}
}
@ -385,7 +375,7 @@ void UserInfoBox::resizeEvent(QResizeEvent *event)
resizedPixmap = avatarPixmap.scaled(avatarPic.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
} else {
int height = qMin(avatarPic.size().width(), avatarPic.size().height());
resizedPixmap = createDefaultAvatar(height, *currentUserInfo);
resizedPixmap = UserLevelPixmapGenerator::generatePixmap(height, userLevel, pawnColors, false, privLevel);
}
avatarPic.setPixmap(resizedPixmap);

View file

@ -11,8 +11,9 @@
#include <QLabel>
#include <QPushButton>
#include <QWidget>
#include <libcockatrice/network/server/remote/user_level.h>
#include <libcockatrice/utility/days_years_between.h>
class ServerInfo_User;
class AbstractClient;
class Response;
@ -27,20 +28,15 @@ private:
QPushButton editButton, passwordButton, avatarButton;
QPixmap avatarPixmap;
bool hasAvatar;
const ServerInfo_User *currentUserInfo;
UserLevelFlags userLevel;
ServerInfo_User::PawnColorsOverride pawnColors;
QString privLevel;
static QString getAgeString(int ageSeconds);
public:
UserInfoBox(AbstractClient *_client, bool editable, QWidget *parent = nullptr, Qt::WindowFlags flags = {});
void retranslateUi();
inline static QPair<int, int> getDaysAndYearsBetween(const QDate &then, const QDate &now)
{
int years = now.addDays(1 - then.dayOfYear()).year() - then.year(); // there is no yearsTo
int days = then.addYears(years).daysTo(now);
return {days, years};
}
private slots:
void processResponse(const Response &r);
void processEditResponse(const Response &r);

View file

@ -22,10 +22,14 @@ MessagesSettingsPage::MessagesSettingsPage()
ignoreUnregUsersMainChat.setChecked(SettingsCache::instance().getIgnoreUnregisteredUsers());
ignoreUnregUserMessages.setChecked(SettingsCache::instance().getIgnoreUnregisteredUserMessages());
ignoreNonBuddyUserMessages.setChecked(SettingsCache::instance().getIgnoreNonBuddyUserMessages());
connect(&ignoreUnregUsersMainChat, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
&SettingsCache::setIgnoreUnregisteredUsers);
connect(&ignoreUnregUserMessages, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
&SettingsCache::setIgnoreUnregisteredUserMessages);
connect(&ignoreNonBuddyUserMessages, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
&SettingsCache::setIgnoreNonBuddyUserMessages);
invertMentionForeground.setChecked(SettingsCache::instance().getChatMentionForeground());
connect(&invertMentionForeground, &QCheckBox::QT_STATE_CHANGED, this, &MessagesSettingsPage::updateTextColor);
@ -62,9 +66,10 @@ MessagesSettingsPage::MessagesSettingsPage()
chatGrid->addWidget(&ignoreUnregUsersMainChat, 2, 0);
chatGrid->addWidget(&hexLabel, 1, 2);
chatGrid->addWidget(&ignoreUnregUserMessages, 3, 0);
chatGrid->addWidget(&messagePopups, 4, 0);
chatGrid->addWidget(&mentionPopups, 5, 0);
chatGrid->addWidget(&roomHistory, 6, 0);
chatGrid->addWidget(&ignoreNonBuddyUserMessages, 4, 0);
chatGrid->addWidget(&messagePopups, 5, 0);
chatGrid->addWidget(&mentionPopups, 6, 0);
chatGrid->addWidget(&roomHistory, 7, 0);
chatGroupBox = new QGroupBox;
chatGroupBox->setLayout(chatGrid);
@ -237,6 +242,7 @@ void MessagesSettingsPage::retranslateUi()
QString("<a href='%1'>%2</a>").arg(WIKI_CUSTOM_SHORTCUTS).arg(tr("How to use in-game message macros")));
ignoreUnregUsersMainChat.setText(tr("Ignore chat room messages sent by unregistered users"));
ignoreUnregUserMessages.setText(tr("Ignore private messages sent by unregistered users"));
ignoreNonBuddyUserMessages.setText(tr("Ignore private messages sent by non-buddy users"));
invertMentionForeground.setText(tr("Invert text color"));
invertHighlightForeground.setText(tr("Invert text color"));
messagePopups.setText(tr("Enable desktop notifications for private messages"));

View file

@ -36,6 +36,7 @@ private:
QCheckBox invertHighlightForeground;
QCheckBox ignoreUnregUsersMainChat;
QCheckBox ignoreUnregUserMessages;
QCheckBox ignoreNonBuddyUserMessages;
QCheckBox messagePopups;
QCheckBox mentionPopups;
QCheckBox roomHistory;

View file

@ -1019,6 +1019,12 @@ void TabSupervisor::processUserMessageEvent(const Event_UserMessage &event)
!userLevel.testFlag(ServerInfo_User::IsRegistered)) {
// Flags are additive, so reg/mod/admin are all IsRegistered
return;
} else if (SettingsCache::instance().getIgnoreNonBuddyUserMessages() &&
!userListManager->isUserBuddy(senderName) && !userLevel.testFlag(ServerInfo_User::IsModerator) &&
!userLevel.testFlag(ServerInfo_User::IsAdmin)) {
// Ignore private messages from non-buddies
// Moderator/Admin messages are exempt to ensure warnings reach users
return;
}
}
tab = addMessageTab(QString::fromStdString(event.sender_name()), false);

View file

@ -0,0 +1,8 @@
#include <QDateTime>
inline static QPair<int, int> getDaysAndYearsBetween(const QDate &then, const QDate &now)
{
int years = now.addDays(1 - then.dayOfYear()).year() - then.year(); // there is no yearsTo
int days = then.addYears(years).daysTo(now);
return {days, years};
}

View file

@ -59,7 +59,9 @@ endif()
include_directories(${GTEST_INCLUDE_DIRS})
target_link_libraries(dummy_test Threads::Threads ${GTEST_BOTH_LIBRARIES})
target_link_libraries(expression_test libcockatrice_utility Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
target_link_libraries(test_age_formatting Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
target_link_libraries(
test_age_formatting libcockatrice_utility Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES}
)
target_link_libraries(
password_hash_test libcockatrice_utility Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES}
)

View file

@ -1,6 +1,5 @@
#include "../cockatrice/src/interface/widgets/server/user/user_info_box.h"
#include "gtest/gtest.h"
#include <libcockatrice/utility/days_years_between.h>
namespace
{
@ -8,31 +7,31 @@ using dayyear = QPair<int, int>;
TEST(AgeFormatting, Zero)
{
auto got = UserInfoBox::getDaysAndYearsBetween(QDate(2000, 1, 1), QDate(2000, 1, 1));
auto got = getDaysAndYearsBetween(QDate(2000, 1, 1), QDate(2000, 1, 1));
ASSERT_EQ(got, dayyear(0, 0)) << "these are the same day";
}
TEST(AgeFormatting, LeapDay)
{
auto got = UserInfoBox::getDaysAndYearsBetween(QDate(2000, 2, 28), QDate(2000, 3, 1));
auto got = getDaysAndYearsBetween(QDate(2000, 2, 28), QDate(2000, 3, 1));
ASSERT_EQ(got, dayyear(2, 0)) << "there is a leap day in between these days";
}
TEST(AgeFormatting, LeapYear)
{
auto got = UserInfoBox::getDaysAndYearsBetween(QDate(2000, 1, 1), QDate(2001, 1, 1));
auto got = getDaysAndYearsBetween(QDate(2000, 1, 1), QDate(2001, 1, 1));
ASSERT_EQ(got, dayyear(0, 1)) << "there is a leap day in between these dates, but that's fine";
}
TEST(AgeFormatting, LeapDayWithYear)
{
auto got = UserInfoBox::getDaysAndYearsBetween(QDate(2000, 2, 28), QDate(2001, 3, 1));
auto got = getDaysAndYearsBetween(QDate(2000, 2, 28), QDate(2001, 3, 1));
ASSERT_EQ(got, dayyear(1, 1)) << "there is a leap day in between these days but not in the last year";
}
TEST(AgeFormatting, LeapDayThisYear)
{
auto got = UserInfoBox::getDaysAndYearsBetween(QDate(2003, 2, 28), QDate(2004, 3, 1));
auto got = getDaysAndYearsBetween(QDate(2003, 2, 28), QDate(2004, 3, 1));
ASSERT_EQ(got, dayyear(2, 1)) << "there is a leap day in between these days this year";
}
} // namespace