File indexing completed on 2024-12-01 04:37:00

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "channelactionpopupmenu.h"
0008 #include "rocketchataccount.h"
0009 #include "room.h"
0010 #include <KLocalizedString>
0011 #include <QMenu>
0012 
0013 ChannelActionPopupMenu::ChannelActionPopupMenu(QObject *parent)
0014     : QObject(parent)
0015     , mMenu(new QMenu)
0016 {
0017     mMenu->setObjectName(QStringLiteral("mMenu"));
0018     connect(mMenu, &QMenu::aboutToShow, this, &ChannelActionPopupMenu::slotUpdateMenu);
0019     createMenu();
0020 }
0021 
0022 ChannelActionPopupMenu::~ChannelActionPopupMenu()
0023 {
0024     delete mMenu;
0025 }
0026 
0027 void ChannelActionPopupMenu::createMenu()
0028 {
0029     mPruneMessages = new QAction(i18n("Prune Messages..."), this);
0030     mMenu->addAction(mPruneMessages);
0031     connect(mPruneMessages, &QAction::triggered, this, [this]() {
0032         Q_EMIT actionRequested(RoomHeaderWidget::PruneMessages);
0033     });
0034 
0035     mPruneMessagesSeparator = mMenu->addSeparator();
0036 
0037     mShowMentions = new QAction(i18n("Show Mentions..."), this);
0038     mMenu->addAction(mShowMentions);
0039     connect(mShowMentions, &QAction::triggered, this, [this]() {
0040         Q_EMIT actionRequested(RoomHeaderWidget::ShowMentions);
0041     });
0042 
0043     mShowPinnedMessages = new QAction(i18n("Show Pinned Messages..."), this);
0044     mMenu->addAction(mShowPinnedMessages);
0045     connect(mShowPinnedMessages, &QAction::triggered, this, [this]() {
0046         Q_EMIT actionRequested(RoomHeaderWidget::ShowPinned);
0047     });
0048 
0049     mShowStarredMessages = new QAction(i18n("Show Starred Messages..."), this);
0050     mMenu->addAction(mShowStarredMessages);
0051     connect(mShowStarredMessages, &QAction::triggered, this, [this]() {
0052         Q_EMIT actionRequested(RoomHeaderWidget::ShowStarred);
0053     });
0054 
0055     mShowFileAttachments = new QAction(QIcon::fromTheme(QStringLiteral("document-send-symbolic")), i18n("Show File Attachments..."), this);
0056     mMenu->addAction(mShowFileAttachments);
0057     connect(mShowFileAttachments, &QAction::triggered, this, [this]() {
0058         Q_EMIT actionRequested(RoomHeaderWidget::ShowAttachment);
0059     });
0060 
0061     mShowDiscussions = new QAction(i18n("Show Discussions..."), this);
0062     mMenu->addAction(mShowDiscussions);
0063     connect(mShowDiscussions, &QAction::triggered, this, [this]() {
0064         Q_EMIT actionRequested(RoomHeaderWidget::ShowDiscussions);
0065     });
0066 
0067     mShowThreads = new QAction(i18n("Show Threads..."), this);
0068     mMenu->addAction(mShowThreads);
0069     connect(mShowThreads, &QAction::triggered, this, [this]() {
0070         Q_EMIT actionRequested(RoomHeaderWidget::ShowThreads);
0071     });
0072 
0073     mMenu->addSeparator();
0074 
0075     mConfigureNotification = new QAction(QIcon::fromTheme(QStringLiteral("preferences-desktop-notification")), i18n("Configure Notification..."), this);
0076     mMenu->addAction(mConfigureNotification);
0077     connect(mConfigureNotification, &QAction::triggered, this, [this]() {
0078         Q_EMIT actionRequested(RoomHeaderWidget::Notification);
0079     });
0080 
0081     mAutoTranslateSeparator = mMenu->addSeparator();
0082     mAutoTranslate = new QAction(i18n("Configure Auto-Translate..."), this);
0083     mMenu->addAction(mAutoTranslate);
0084     connect(mAutoTranslate, &QAction::triggered, this, [this]() {
0085         Q_EMIT actionRequested(RoomHeaderWidget::AutoTranslate);
0086     });
0087 
0088     mInviteUsersGenerateUrlSeparator = mMenu->addSeparator();
0089     mMenu->addAction(mInviteUsersGenerateUrlSeparator);
0090     mInviteUsersGenerateUrl = new QAction(i18n("Invite Users"), this);
0091     mMenu->addAction(mInviteUsersGenerateUrl);
0092     connect(mInviteUsersGenerateUrl, &QAction::triggered, this, [this]() {
0093         Q_EMIT actionRequested(RoomHeaderWidget::InviteUsers);
0094     });
0095 
0096     mAddUserInRoomsSeparator = mMenu->addSeparator();
0097     mAddUserInRooms = new QAction(i18n("Add Users in Channel..."), this);
0098     mMenu->addAction(mAddUserInRoomsSeparator);
0099     connect(mAddUserInRooms, &QAction::triggered, this, [this]() {
0100         Q_EMIT actionRequested(RoomHeaderWidget::AddUsersInRoom);
0101     });
0102     mMenu->addAction(mAddUserInRooms);
0103 
0104     mMenu->addSeparator();
0105     mStartVideoChat = new QAction(QIcon::fromTheme(QStringLiteral("camera-video")), i18n("Video Chat"), this);
0106     mMenu->addAction(mStartVideoChat);
0107     connect(mStartVideoChat, &QAction::triggered, this, [this]() {
0108         Q_EMIT actionRequested(RoomHeaderWidget::VideoChat);
0109     });
0110 
0111     mMenu->addSeparator();
0112     mExportMessages = new QAction(i18n("Export Messages..."), this);
0113     mMenu->addAction(mExportMessages);
0114     connect(mExportMessages, &QAction::triggered, this, [this]() {
0115         Q_EMIT actionRequested(RoomHeaderWidget::ExportMessages);
0116     });
0117 
0118     mMenu->addSeparator();
0119     mOffTheRecordMessages = new QAction(i18n("OTR"), this);
0120     mOffTheRecordMessages->setCheckable(true);
0121     mMenu->addAction(mOffTheRecordMessages);
0122     connect(mOffTheRecordMessages, &QAction::triggered, this, [this]() {
0123         Q_EMIT actionRequested(RoomHeaderWidget::OtrMessages);
0124     });
0125     mMenu->addSeparator();
0126     mEncryptMessages = new QAction(i18n("Encrypt Messages"), this);
0127     mEncryptMessages->setCheckable(true);
0128     mMenu->addAction(mEncryptMessages);
0129     connect(mEncryptMessages, &QAction::triggered, this, [this]() {
0130         Q_EMIT actionRequested(RoomHeaderWidget::EncryptMessages);
0131     });
0132 }
0133 
0134 QAction *ChannelActionPopupMenu::createSeparator()
0135 {
0136     return mMenu->addSeparator();
0137 }
0138 
0139 QMenu *ChannelActionPopupMenu::menu() const
0140 {
0141     return mMenu;
0142 }
0143 
0144 void ChannelActionPopupMenu::setRoom(Room *room)
0145 {
0146     mRoom = room;
0147 }
0148 
0149 void ChannelActionPopupMenu::setCurrentRocketChatAccount(RocketChatAccount *account)
0150 {
0151     mCurrentRocketChatAccount = account;
0152 }
0153 
0154 void ChannelActionPopupMenu::slotUpdateMenu()
0155 {
0156     mShowPinnedMessages->setVisible(mCurrentRocketChatAccount->allowMessagePinningEnabled());
0157     mShowStarredMessages->setVisible(mCurrentRocketChatAccount->allowMessageStarringEnabled());
0158     mAutoTranslate->setVisible(mCurrentRocketChatAccount->hasAutotranslateSupport());
0159     mAutoTranslateSeparator->setVisible(mCurrentRocketChatAccount->autoTranslateEnabled());
0160 
0161     bool hasPermissionInviteUserSupport = mRoom && mRoom->hasPermission(QStringLiteral("create-invite-links"));
0162     mInviteUsersGenerateUrl->setVisible(hasPermissionInviteUserSupport);
0163     mInviteUsersGenerateUrlSeparator->setVisible(hasPermissionInviteUserSupport);
0164     mStartVideoChat->setVisible(mCurrentRocketChatAccount->jitsiEnabled());
0165 
0166     mAddUserInRoomsSeparator->setVisible(mRoom && mRoom->canBeModify());
0167     mAddUserInRooms->setVisible(mRoom && mRoom->canBeModify());
0168 
0169     const bool showPruneMessage = mCurrentRocketChatAccount->hasPermission(QStringLiteral("clean-channel-history"));
0170     mPruneMessages->setVisible(showPruneMessage);
0171     mPruneMessagesSeparator->setVisible(showPruneMessage);
0172 
0173     mExportMessages->setVisible(mCurrentRocketChatAccount->hasPermission(QStringLiteral("mail-messages")));
0174 
0175     // FIXME Disable for the moment
0176     mOffTheRecordMessages->setVisible(false && mCurrentRocketChatAccount->otrEnabled() && mRoom->channelType() == Room::RoomType::Direct);
0177 
0178     // FIXME Disable for the moment
0179     // TODO
0180     mEncryptMessages->setVisible(false);
0181 }
0182 
0183 #include "moc_channelactionpopupmenu.cpp"