diff --git a/cockatrice/src/interface/widgets/server/chat_view/chat_view.cpp b/cockatrice/src/interface/widgets/server/chat_view/chat_view.cpp index e62195c2f..869df4cf3 100644 --- a/cockatrice/src/interface/widgets/server/chat_view/chat_view.cpp +++ b/cockatrice/src/interface/widgets/server/chat_view/chat_view.cpp @@ -14,8 +14,6 @@ #include #include #include -#include -#include #include #include #include @@ -51,7 +49,7 @@ ChatView::ChatView(TabSupervisor *_tabSupervisor, AbstractGame *_game, bool _sho viewport()->setCursor(Qt::IBeamCursor); setReadOnly(true); - setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard); + setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse); setOpenLinks(false); connect(this, &ChatView::anchorClicked, this, &ChatView::openLink); @@ -221,46 +219,6 @@ void ChatView::appendUrlTag(QTextCursor &cursor, QString url) cursor.setCharFormat(oldFormat); } -void ChatView::appendGameLinkTag(QTextCursor &cursor, const QString &url) -{ - const QUrl gameUrl(url); - const QUrlQuery query(gameUrl); - const QString hostname = query.queryItemValue("hostname"); - // FullyDecoded undoes every %XX escape, so a description that itself - // contains "%" cannot end up displayed as "%25" in the label. - const QString description = query.queryItemValue("game", QUrl::FullyDecoded); - const int gameId = query.queryItemValue("gameid").toInt(); - - QString label; - if (gameId > 0 && !hostname.isEmpty()) { - // Links built before the description was embedded stay readable: the - // id + server fallback below is identical to the old anchor text. - if (!description.isEmpty()) { - // Multi-arg .arg() replaces all placeholders in a single pass, so a - // description containing "%…" cannot corrupt later placeholders. - label = tr("Join game \"%1\" (#%2) on %3").arg(description, QString::number(gameId), hostname); - } else { - label = tr("Join game #%1 on %2").arg(QString::number(gameId), hostname); - } - } else { - label = tr("Join game"); - } - - QTextCharFormat oldFormat = cursor.charFormat(); - QTextCharFormat gameLinkFormat = oldFormat; - gameLinkFormat.setForeground(linkColor); - gameLinkFormat.setFontWeight(QFont::Bold); - gameLinkFormat.setAnchor(true); - gameLinkFormat.setAnchorHref(url); - QColor background = palette().highlight().color(); - background.setAlpha(40); - gameLinkFormat.setBackground(background); - - cursor.setCharFormat(gameLinkFormat); - cursor.insertText(label); - cursor.setCharFormat(oldFormat); -} - void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType, const ServerInfo_User &userInfo, @@ -545,17 +503,6 @@ void ChatView::checkWord(QTextCursor &cursor, QString &message) } } - if (fullWordUpToSpaceOrEnd.startsWith("cockatrice://", Qt::CaseInsensitive)) { - // Only links to a game (cockatrice://joingame) become invite buttons; - // any other cockatrice:// scheme falls through to plain text below. - const QUrl gameLink(fullWordUpToSpaceOrEnd); - if (gameLink.host().compare("joingame", Qt::CaseInsensitive) == 0) { - appendGameLinkTag(cursor, fullWordUpToSpaceOrEnd); - cursor.insertText(rest, defaultFormat); - return; - } - } - // check word mentions for (const QString &word : highlightedWords) { if (fullWordUpToSpaceOrEnd.compare(word, Qt::CaseInsensitive) == 0) { @@ -777,11 +724,6 @@ void ChatView::mouseReleaseEvent(QMouseEvent *event) void ChatView::openLink(const QUrl &link) { - if (link.scheme() == "cockatrice") { - emit cockatriceLinkActivated(link.toString(QUrl::FullyEncoded)); - return; - } - if ((link.scheme() == "card") || (link.scheme() == "user")) { return; } diff --git a/cockatrice/src/interface/widgets/server/chat_view/chat_view.h b/cockatrice/src/interface/widgets/server/chat_view/chat_view.h index c58efa2c6..646aa6a80 100644 --- a/cockatrice/src/interface/widgets/server/chat_view/chat_view.h +++ b/cockatrice/src/interface/widgets/server/chat_view/chat_view.h @@ -71,7 +71,6 @@ private: void scrollToBottom(); void appendCardTag(QTextCursor &cursor, const QString &cardName); void appendUrlTag(QTextCursor &cursor, QString url); - void appendGameLinkTag(QTextCursor &cursor, const QString &url); static QColor getCustomMentionColor(); static QColor getCustomHighlightColor(); void showSystemPopup(const QString &userName); @@ -122,7 +121,6 @@ signals: void addMentionTag(QString mentionTag); void messageClickedSignal(); void showMentionPopup(const QString &userName); - void cockatriceLinkActivated(const QString &url); }; #endif diff --git a/cockatrice/src/interface/widgets/server/user/user_list_widget.cpp b/cockatrice/src/interface/widgets/server/user/user_list_widget.cpp index be52b9871..7a82b0c76 100644 --- a/cockatrice/src/interface/widgets/server/user/user_list_widget.cpp +++ b/cockatrice/src/interface/widgets/server/user/user_list_widget.cpp @@ -336,12 +336,11 @@ constexpr int UserInfo = Qt::UserRole + 2; // rows (UserListTWI, which uses QTreeWidgetItem::Type) by this item type. constexpr int SectionItemType = QTreeWidgetItem::UserType + 1; -UserListItemDelegate::UserListItemDelegate(UserListWidget *owner, - QTreeWidget *tree, +UserListItemDelegate::UserListItemDelegate(QTreeWidget *tree, const QMap *avatarCache, const QMap *cardArtCache, const QMap *cardArtParamsMap) - : QStyledItemDelegate(tree), tree(tree), owner(owner), avatarCache(avatarCache), cardArtCache(cardArtCache), + : QStyledItemDelegate(tree), tree(tree), avatarCache(avatarCache), cardArtCache(cardArtCache), cardArtParamsMap(cardArtParamsMap) { } @@ -354,7 +353,7 @@ bool UserListItemDelegate::editorEvent(QEvent *event, if ((event->type() == QEvent::MouseButtonPress) && index.isValid()) { QMouseEvent *const mouseEvent = static_cast(event); if (mouseEvent->button() == Qt::RightButton) { - owner->showContextMenu(mouseEvent->globalPosition().toPoint(), index); + static_cast(parent())->showContextMenu(mouseEvent->globalPosition().toPoint(), index); return true; } } @@ -594,8 +593,8 @@ UserListWidget::UserListWidget(TabSupervisor *_tabSupervisor, userTree->setHeaderHidden(true); userTree->setRootIsDecorated(false); userTree->setIconSize(QSize(20, 18)); - itemDelegate = new UserListItemDelegate(this, userTree, &avatarProvider->cache(), &cardArtProvider->cache(), - &cardArtParamsMap); + itemDelegate = + new UserListItemDelegate(userTree, &avatarProvider->cache(), &cardArtProvider->cache(), &cardArtParamsMap); userTree->setItemDelegate(itemDelegate); userTree->setAlternatingRowColors(true); userTree->hideColumn(1); @@ -1639,27 +1638,15 @@ void UserListWidget::updateSectionDivider(Section section) return; } int visible = 0; - int online = 0; for (int i = 0; i < divider->childCount(); ++i) { - QTreeWidgetItem *child = divider->child(i); - if (!child->isHidden()) { + if (!divider->child(i)->isHidden()) { ++visible; - if (child->data(0, UserListRoles::Online).toBool()) { - ++online; - } } } // The tree draws no branches (rows are flush), so the divider carries its // own collapse arrow glyph. const QString arrow = divider->isExpanded() ? QStringLiteral("\u25BE") : QStringLiteral("\u25B8"); - if (section == Section::Buddy) { - // The buddy divider reports how many of the shown buddies are online, - // mirroring the "Buddies online: %1 / %2" title of the non-sectioned - // buddy list. - divider->setText(0, tr("%1 %2 (%3/%4)").arg(arrow, sectionTitle(section)).arg(online).arg(visible)); - } else { - divider->setText(0, tr("%1 %2 (%3)").arg(arrow, sectionTitle(section)).arg(visible)); - } + divider->setText(0, tr("%1 %2 (%3)").arg(arrow, sectionTitle(section)).arg(visible)); } void UserListWidget::handleSectionExpansion(QTreeWidgetItem *item, bool expanded) diff --git a/cockatrice/src/interface/widgets/server/user/user_list_widget.h b/cockatrice/src/interface/widgets/server/user/user_list_widget.h index e048c7fb7..298a5f8d8 100644 --- a/cockatrice/src/interface/widgets/server/user/user_list_widget.h +++ b/cockatrice/src/interface/widgets/server/user/user_list_widget.h @@ -37,7 +37,6 @@ class QPlainTextEdit; class Response; class CommandContainer; class UserContextMenu; -class UserListWidget; class QShowEvent; class BanDialog : public QDialog @@ -106,14 +105,12 @@ public: class UserListItemDelegate : public QStyledItemDelegate { QTreeWidget *tree; - UserListWidget *owner; const QMap *avatarCache; const QMap *cardArtCache; const QMap *cardArtParamsMap; public: - explicit UserListItemDelegate(UserListWidget *owner, - QTreeWidget *tree, + explicit UserListItemDelegate(QTreeWidget *tree, const QMap *avatarCache, const QMap *cardArtCache, const QMap *cardArtParamsMap); diff --git a/cockatrice/src/interface/widgets/tabs/tab.h b/cockatrice/src/interface/widgets/tabs/tab.h index bddf325e2..6ea1f5077 100644 --- a/cockatrice/src/interface/widgets/tabs/tab.h +++ b/cockatrice/src/interface/widgets/tabs/tab.h @@ -20,7 +20,6 @@ class Tab : public QMainWindow signals: void userEvent(bool globalEvent = true); void tabTextChanged(Tab *tab, const QString &newTabText); - void cockatriceLinkActivated(const QString &url); protected: TabSupervisor *tabSupervisor; diff --git a/cockatrice/src/interface/widgets/tabs/tab_game.cpp b/cockatrice/src/interface/widgets/tabs/tab_game.cpp index 513b7c926..3f165c1d5 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_game.cpp +++ b/cockatrice/src/interface/widgets/tabs/tab_game.cpp @@ -1292,7 +1292,6 @@ void TabGame::createMessageDock(bool bReplay) qOverload(&CardInfoFrameWidget::setCard)); connect(messageLog, &MessageLogWidget::showCardInfoPopup, this, &TabGame::showCardInfoPopup); connect(messageLog, &MessageLogWidget::deleteCardInfoPopup, this, &TabGame::deleteCardInfoPopup); - connect(messageLog, &MessageLogWidget::cockatriceLinkActivated, this, &TabGame::cockatriceLinkActivated); if (!bReplay) { connect(messageLog, &MessageLogWidget::openMessageDialog, this, &TabGame::openMessageDialog); diff --git a/cockatrice/src/interface/widgets/tabs/tab_message.cpp b/cockatrice/src/interface/widgets/tabs/tab_message.cpp index 9eccea7a2..9e9dbce1c 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_message.cpp +++ b/cockatrice/src/interface/widgets/tabs/tab_message.cpp @@ -23,16 +23,14 @@ TabMessage::TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User &_ownUserInfo, - const ServerInfo_User &_otherUserInfo, - bool _userOnline) + const ServerInfo_User &_otherUserInfo) : Tab(_tabSupervisor), client(_client), ownUserInfo(new ServerInfo_User(_ownUserInfo)), - otherUserInfo(new ServerInfo_User(_otherUserInfo)), userOnline(_userOnline) + otherUserInfo(new ServerInfo_User(_otherUserInfo)), userOnline(true) { chatView = new ChatView(tabSupervisor, 0, true); connect(chatView, &ChatView::showCardInfoPopup, this, &TabMessage::showCardInfoPopup); connect(chatView, &ChatView::deleteCardInfoPopup, this, &TabMessage::deleteCardInfoPopup); connect(chatView, &ChatView::addMentionTag, this, &TabMessage::addMentionTag); - connect(chatView, &ChatView::cockatriceLinkActivated, this, &TabMessage::cockatriceLinkActivated); sayEdit = new LineEditUnfocusable; sayEdit->setMaxLength(MAX_TEXT_LENGTH); connect(sayEdit, &LineEditUnfocusable::returnPressed, this, &TabMessage::sendMessage); @@ -98,14 +96,7 @@ void TabMessage::closeEvent(QCloseEvent *event) void TabMessage::sendMessage() { - if (sayEdit->text().isEmpty()) { - return; - } - - if (!userOnline) { - // Keep the draft: the user may be back momentarily, and the typed text - // should not be lost to a transient offline spell. - notifyUserOffline(); + if (sayEdit->text().isEmpty() || !userOnline) { return; } @@ -114,27 +105,17 @@ void TabMessage::sendMessage() cmd.set_message(sayEdit->text().toStdString()); PendingCommand *pend = client->prepareSessionCommand(cmd); - pend->setExtraData(sayEdit->text()); connect(pend, &PendingCommand::finished, this, &TabMessage::messageSent); client->sendCommand(pend); sayEdit->clear(); } -void TabMessage::messageSent(const Response &response, - const CommandContainer & /*commandContainer*/, - const QVariant &extraData) +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.")); - } else if (response.response_code() == Response::RespNameNotFound) { - // The recipient went offline before the command reached the server: restore the draft. - userOnline = false; - if (sayEdit->text().isEmpty()) { - sayEdit->setText(extraData.toString()); - } - notifyUserOffline(); } } @@ -194,8 +175,3 @@ void TabMessage::processUserJoined(const ServerInfo_User &_userInfo) userOnline = true; *otherUserInfo = _userInfo; } - -void TabMessage::notifyUserOffline() -{ - chatView->appendMessage(tr("Message not sent — %1 is offline.").arg(QString::fromStdString(otherUserInfo->name()))); -} diff --git a/cockatrice/src/interface/widgets/tabs/tab_message.h b/cockatrice/src/interface/widgets/tabs/tab_message.h index f7d15b4f6..0472bb061 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_message.h +++ b/cockatrice/src/interface/widgets/tabs/tab_message.h @@ -19,7 +19,6 @@ class LineEditUnfocusable; class Event_UserMessage; class Response; class ServerInfo_User; -class CommandContainer; class TabMessage : public Tab { @@ -40,7 +39,7 @@ signals: void maximizeClient(); private slots: void sendMessage(); - void messageSent(const Response &response, const CommandContainer &commandContainer, const QVariant &extraData); + void messageSent(const Response &response); void addMentionTag(QString mentionTag); void messageClicked(); @@ -51,8 +50,7 @@ public: TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User &_ownUserInfo, - const ServerInfo_User &_otherUserInfo, - bool _userOnline); + const ServerInfo_User &_otherUserInfo); ~TabMessage() override; void retranslateUi() override; void tabActivated() override; @@ -67,7 +65,6 @@ public: private: bool shouldShowSystemPopup(const Event_UserMessage &event); void showSystemPopup(const Event_UserMessage &event); - void notifyUserOffline(); }; #endif diff --git a/cockatrice/src/interface/widgets/tabs/tab_room.cpp b/cockatrice/src/interface/widgets/tabs/tab_room.cpp index 508d5a048..9b09ba7bb 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_room.cpp +++ b/cockatrice/src/interface/widgets/tabs/tab_room.cpp @@ -70,7 +70,6 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, connect(chatView, &ChatView::showMentionPopup, this, &TabRoom::actShowMentionPopup); connect(chatView, &ChatView::messageClickedSignal, this, &TabRoom::focusTab); connect(chatView, &ChatView::openMessageDialog, this, &TabRoom::openMessageDialog); - connect(chatView, &ChatView::cockatriceLinkActivated, this, &TabRoom::cockatriceLinkActivated); connect(chatView, &ChatView::showCardInfoPopup, this, &TabRoom::showCardInfoPopup); connect(chatView, &ChatView::deleteCardInfoPopup, this, &TabRoom::deleteCardInfoPopup); connect(chatView, &ChatView::addMentionTag, this, &TabRoom::addMentionTag); diff --git a/cockatrice/src/interface/widgets/tabs/tab_supervisor.cpp b/cockatrice/src/interface/widgets/tabs/tab_supervisor.cpp index 1ab812c54..4100e124a 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_supervisor.cpp +++ b/cockatrice/src/interface/widgets/tabs/tab_supervisor.cpp @@ -406,7 +406,6 @@ int TabSupervisor::myAddTab(Tab *tab, QAction *manager) { connect(tab, &TabGame::userEvent, this, &TabSupervisor::tabUserEvent); connect(tab, &TabGame::tabTextChanged, this, &TabSupervisor::updateTabText); - connect(tab, &TabGame::cockatriceLinkActivated, this, &TabSupervisor::cockatriceLinkActivated); QString tabText = tab->getTabText(); int idx = addTab(tab, sanitizeTabName(tabText)); @@ -852,7 +851,6 @@ void TabSupervisor::addRoomTab(const ServerInfo_Room &info, bool setCurrent) connect(tab, &TabRoom::maximizeClient, this, &TabSupervisor::maximizeMainWindow); connect(tab, &TabRoom::roomClosing, this, &TabSupervisor::roomLeft); connect(tab, &TabRoom::openMessageDialog, this, &TabSupervisor::addMessageTab); - connect(tab, &TabRoom::cockatriceLinkActivated, this, &TabSupervisor::cockatriceLinkActivated); myAddTab(tab); roomTabs.insert(info.room_id(), tab); if (setCurrent) { @@ -906,10 +904,8 @@ TabMessage *TabSupervisor::addMessageTab(const QString &receiverName, bool focus } ServerInfo_User otherUser; - bool userOnline = false; if (auto user = userListManager->getOnlineUser(receiverName)) { otherUser = ServerInfo_User(*user); - userOnline = true; } else { otherUser.set_name(receiverName.toStdString()); } @@ -923,10 +919,9 @@ TabMessage *TabSupervisor::addMessageTab(const QString &receiverName, bool focus return tab; } - tab = new TabMessage(this, client, *userInfo, otherUser, userOnline); + tab = new TabMessage(this, client, *userInfo, otherUser); connect(tab, &TabMessage::talkClosing, this, &TabSupervisor::talkLeft); connect(tab, &TabMessage::maximizeClient, this, &TabSupervisor::maximizeMainWindow); - connect(tab, &TabMessage::cockatriceLinkActivated, this, &TabSupervisor::cockatriceLinkActivated); myAddTab(tab); messageTabs.insert(receiverName, tab); if (focus) { diff --git a/cockatrice/src/interface/widgets/tabs/tab_supervisor.h b/cockatrice/src/interface/widgets/tabs/tab_supervisor.h index 5ac3eb365..0c3542cf3 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_supervisor.h +++ b/cockatrice/src/interface/widgets/tabs/tab_supervisor.h @@ -169,7 +169,6 @@ signals: void localGameEnded(); void adminLockChanged(bool lock); void showWindowIfHidden(); - void cockatriceLinkActivated(const QString &url); public slots: void openDeckInNewTab(const LoadedDeck &deckToOpen); diff --git a/cockatrice/src/interface/window_main.cpp b/cockatrice/src/interface/window_main.cpp index 199a2d952..c083dccf8 100644 --- a/cockatrice/src/interface/window_main.cpp +++ b/cockatrice/src/interface/window_main.cpp @@ -40,7 +40,6 @@ #include "intents/intent_connect_to_server.h" #include "intents/intent_login.h" #include "intents/intent_open_server_room_by_name.h" -#include "intents/url_parser.h" #include "logger.h" #include "version_string.h" #include "widgets/dialogs/dlg_connect.h" @@ -498,7 +497,6 @@ MainWindow::MainWindow(QWidget *parent) pixmapCacheSizeChanged(SettingsCache::instance().cacheStorage().getPixmapCacheSize()); connectionController = new ConnectionController(this, this); - urlParser = new IntentUrlParser(this, this); createActions(); createMenus(); @@ -510,7 +508,6 @@ MainWindow::MainWindow(QWidget *parent) connect(tabSupervisor, &TabSupervisor::setMenu, this, &MainWindow::updateTabMenu); connect(tabSupervisor, &TabSupervisor::localGameEnded, this, &MainWindow::localGameEnded); connect(tabSupervisor, &TabSupervisor::showWindowIfHidden, this, &MainWindow::showWindowIfHidden); - connect(tabSupervisor, &TabSupervisor::cockatriceLinkActivated, this, &MainWindow::handleCockatriceLink); connect(connectionController, &ConnectionController::tabSupervisorStartRequested, tabSupervisor, &TabSupervisor::start); connect(connectionController, &ConnectionController::tabSupervisorStopRequested, tabSupervisor, @@ -864,11 +861,6 @@ void MainWindow::showWindowIfHidden() show(); } -void MainWindow::handleCockatriceLink(const QString &url) -{ - urlParser->handle(url); -} - void MainWindow::cardDatabaseLoadingFailed() { if (askedForDbUpdater) { diff --git a/cockatrice/src/interface/window_main.h b/cockatrice/src/interface/window_main.h index fc0791832..73b7c42c5 100644 --- a/cockatrice/src/interface/window_main.h +++ b/cockatrice/src/interface/window_main.h @@ -56,7 +56,6 @@ class TabSupervisor; class WndSets; class DlgTipOfTheDay; struct ContextConnectToServer; -class IntentUrlParser; class MainWindow : public QMainWindow { @@ -85,7 +84,6 @@ private slots: void actOpenSettingsFolder(); void actShow(); void showWindowIfHidden(); - void handleCockatriceLink(const QString &url); void cardUpdateError(QProcess::ProcessError err); void cardUpdateFinished(int exitCode, QProcess::ExitStatus exitStatus); @@ -141,7 +139,6 @@ private: *aOpenSettingsFolder; TabSupervisor *tabSupervisor; - IntentUrlParser *urlParser; WndSets *wndSets; ConnectionController *connectionController; LocalServer *localServer;