From 8e414578c66284b20d38094174759a9115e4fe3d Mon Sep 17 00:00:00 2001 From: Dexter Gaon-Shatford Date: Sun, 4 Aug 2024 16:41:01 -0400 Subject: [PATCH] FEAT(client): Add "View Description" context action to channels Previously, channel descriptions could only be viewed as a pop-up which does not allow text selection/copying and doesn't allow you to scroll through descriptions to large to fit on your screen. User comments already support this use case via the "View Comment" context menu action on users which opens their comment in a separate window. This commit adds a "View Description" context menu action to channels which works the same way as the "View Comment" action. --- src/mumble/MainWindow.cpp | 30 ++++++++++++++++++++++++++++++ src/mumble/MainWindow.h | 1 + src/mumble/MainWindow.ui | 8 ++++++++ src/mumble/UserModel.cpp | 4 ++++ 4 files changed, 43 insertions(+) diff --git a/src/mumble/MainWindow.cpp b/src/mumble/MainWindow.cpp index f32428a4f40..81c4f289d13 100644 --- a/src/mumble/MainWindow.cpp +++ b/src/mumble/MainWindow.cpp @@ -2258,6 +2258,7 @@ void MainWindow::qmChannel_aboutToShow() { qmChannel->addAction(qaChannelUnlinkAll); qmChannel->addSeparator(); qmChannel->addAction(qaChannelCopyURL); + qmChannel->addAction(qaChannelDescriptionView); qmChannel->addAction(qaChannelSendMessage); // hiding the root is nonsense @@ -2310,6 +2311,7 @@ void MainWindow::qmChannel_aboutToShow() { if (c) { qaChannelHide->setChecked(c->m_filterMode == ChannelFilterMode::HIDE); qaChannelPin->setChecked(c->m_filterMode == ChannelFilterMode::PIN); + qaChannelDescriptionView->setEnabled(!c->qbaDescHash.isEmpty()); } qaChannelAdd->setEnabled(add); @@ -2531,6 +2533,34 @@ void MainWindow::on_qaChannelCopyURL_triggered() { QClipboard::Clipboard); } +void MainWindow::on_qaChannelDescriptionView_triggered() { + Channel *c = getContextMenuChannel(); + // This has to be done here because UserModel could've set it. + cContextChannel.clear(); + + if (!c) + return; + + if (!c->qbaDescHash.isEmpty() && c->qsDesc.isEmpty()) { + c->qsDesc = QString::fromUtf8(Global::get().db->blob(c->qbaDescHash)); + if (c->qsDesc.isEmpty()) { + pmModel->iChannelDescription = ~static_cast< int >(c->iId); + MumbleProto::RequestBlob mprb; + mprb.add_channel_description(c->iId); + Global::get().sh->sendMessage(mprb); + return; + } + } + + pmModel->seenComment(pmModel->index(c)); + + ::TextMessage *texm = new ::TextMessage(this, tr("View description of channel %1").arg(c->qsName)); + + texm->rteMessage->setText(c->qsDesc, true); + texm->setAttribute(Qt::WA_DeleteOnClose, true); + texm->show(); +} + /** * This function updates the UI according to the permission of the user in the current channel. * If possible the permissions are fetched from a cache. Otherwise they are requested by the server diff --git a/src/mumble/MainWindow.h b/src/mumble/MainWindow.h index e54eab71169..a85aa33eb1d 100644 --- a/src/mumble/MainWindow.h +++ b/src/mumble/MainWindow.h @@ -271,6 +271,7 @@ public slots: void on_qaChannelHide_triggered(); void on_qaChannelPin_triggered(); void on_qaChannelCopyURL_triggered(); + void on_qaChannelDescriptionView_triggered(); void on_qaAudioReset_triggered(); void on_qaAudioMute_triggered(); void on_qaAudioDeaf_triggered(); diff --git a/src/mumble/MainWindow.ui b/src/mumble/MainWindow.ui index da034615394..bf84cbc535e 100644 --- a/src/mumble/MainWindow.ui +++ b/src/mumble/MainWindow.ui @@ -919,6 +919,14 @@ the channel's context menu. &Pin When Filtering + + + Vie&w Description + + + View description in editor + + Vie&w Comment diff --git a/src/mumble/UserModel.cpp b/src/mumble/UserModel.cpp index 49d2fab1244..6dc5b86dbab 100644 --- a/src/mumble/UserModel.cpp +++ b/src/mumble/UserModel.cpp @@ -1271,6 +1271,10 @@ void UserModel::setComment(Channel *c, const QString &comment) { QToolTip::showText(QCursor::pos(), data(index(c, 0), Qt::ToolTipRole).toString(), Global::get().mw->qtvUsers); } + } else if (c->iId == static_cast< unsigned int >(~iChannelDescription)) { + iChannelDescription = -1; + Global::get().mw->cContextChannel = c; + QTimer::singleShot(0, Global::get().mw, SLOT(on_qaChannelDescriptionView_triggered())); } else { item->bCommentSeen = Global::get().db->seenComment(item->hash(), c->qbaDescHash); newstate = item->bCommentSeen ? 2 : 1;