File indexing completed on 2024-12-01 04:37:01
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 "roomheaderwidget.h" 0008 #include "channelactionpopupmenu.h" 0009 #include "room.h" 0010 #include "roomheaderlabel.h" 0011 #include "teamnamelabel.h" 0012 #include <KLocalizedString> 0013 #include <QLabel> 0014 #include <QToolButton> 0015 #include <QVBoxLayout> 0016 0017 RoomHeaderWidget::RoomHeaderWidget(QWidget *parent) 0018 : QWidget(parent) 0019 , mRoomName(new QLabel(this)) 0020 , mTeamName(new TeamNameLabel(this)) 0021 , mRoomHeaderLabel(new RoomHeaderLabel(this)) 0022 , mFavoriteButton(new QToolButton(this)) 0023 , mEncryptedButton(new QToolButton(this)) 0024 , mDiscussionBackButton(new QToolButton(this)) 0025 , mListOfUsersButton(new QToolButton(this)) 0026 , mSearchMessageButton(new QToolButton(this)) 0027 , mChannelAction(new QToolButton(this)) 0028 , mChannelInfoButton(new QToolButton(this)) 0029 , mTeamChannelsButton(new QToolButton(this)) 0030 , mCallButton(new QToolButton(this)) 0031 { 0032 auto mainLayout = new QVBoxLayout(this); 0033 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0034 mainLayout->setContentsMargins({}); 0035 0036 auto headerLayout = new QHBoxLayout; 0037 headerLayout->setObjectName(QStringLiteral("headerLayout")); 0038 headerLayout->setContentsMargins({}); 0039 mainLayout->addLayout(headerLayout); 0040 0041 mFavoriteButton->setAutoRaise(true); 0042 mFavoriteButton->setObjectName(QStringLiteral("mFavoriteButton")); 0043 mFavoriteButton->setIcon(QIcon::fromTheme(QStringLiteral("favorite"))); 0044 mFavoriteButton->setCheckable(true); 0045 mFavoriteButton->setToolTip(i18n("Favorite")); 0046 #ifndef QT_NO_ACCESSIBILITY 0047 mFavoriteButton->setAccessibleName(i18n("Favorite")); 0048 #endif 0049 headerLayout->addWidget(mFavoriteButton, 0, Qt::AlignTop); 0050 connect(mFavoriteButton, &QToolButton::clicked, this, &RoomHeaderWidget::favoriteChanged); 0051 0052 mDiscussionBackButton->setAutoRaise(true); 0053 mDiscussionBackButton->setObjectName(QStringLiteral("mDiscussionBackButton")); 0054 mDiscussionBackButton->setIcon(QIcon::fromTheme(QStringLiteral("draw-arrow-back"))); 0055 mDiscussionBackButton->setCheckable(false); 0056 headerLayout->addWidget(mDiscussionBackButton, 0, Qt::AlignTop); 0057 connect(mDiscussionBackButton, &QToolButton::clicked, this, &RoomHeaderWidget::goBackToRoom); 0058 mDiscussionBackButton->setVisible(false); 0059 0060 mEncryptedButton->setAutoRaise(true); 0061 mEncryptedButton->setObjectName(QStringLiteral("mEncryptedButton")); 0062 mEncryptedButton->setIcon(QIcon::fromTheme(QStringLiteral("encrypted"))); 0063 mEncryptedButton->setToolTip(i18n("E2E Enabled")); 0064 #ifndef QT_NO_ACCESSIBILITY 0065 mEncryptedButton->setAccessibleName(i18n("Encryption")); 0066 #endif 0067 0068 mEncryptedButton->setCheckable(true); 0069 mEncryptedButton->setVisible(false); 0070 headerLayout->addWidget(mEncryptedButton, 0, Qt::AlignTop); 0071 connect(mEncryptedButton, &QToolButton::clicked, this, &RoomHeaderWidget::encryptedChanged); 0072 0073 auto infoLayout = new QVBoxLayout; 0074 infoLayout->setObjectName(QStringLiteral("infoLayout")); 0075 infoLayout->setContentsMargins({}); 0076 infoLayout->setSpacing(0); 0077 headerLayout->addLayout(infoLayout); 0078 0079 auto roomNameLayout = new QHBoxLayout; 0080 roomNameLayout->setObjectName(QStringLiteral("roomNameLayout")); 0081 roomNameLayout->setContentsMargins({}); 0082 roomNameLayout->setSpacing(0); 0083 infoLayout->addLayout(roomNameLayout); 0084 0085 mRoomName->setObjectName(QStringLiteral("mRoomName")); 0086 mRoomName->setTextInteractionFlags(Qt::TextBrowserInteraction); 0087 roomNameLayout->addWidget(mRoomName); 0088 mRoomName->setVisible(false); 0089 0090 mTeamName->setObjectName(QStringLiteral("mTeamName")); 0091 roomNameLayout->addWidget(mTeamName); 0092 mTeamName->setVisible(false); 0093 roomNameLayout->addStretch(1); 0094 0095 mRoomHeaderLabel->setObjectName(QStringLiteral("mRoomHeaderLabel")); 0096 infoLayout->addWidget(mRoomHeaderLabel); 0097 0098 auto buttonLayout = new QHBoxLayout; 0099 buttonLayout->setObjectName(QStringLiteral("buttonLayout")); 0100 buttonLayout->setContentsMargins({}); 0101 buttonLayout->setSpacing(0); 0102 headerLayout->addLayout(buttonLayout); 0103 0104 mCallButton->setAutoRaise(true); 0105 mCallButton->setObjectName(QStringLiteral("mCallButton")); 0106 mCallButton->setIcon(QIcon::fromTheme(QStringLiteral("call-start-symbolic"))); 0107 mCallButton->setToolTip(i18n("Call")); 0108 #ifndef QT_NO_ACCESSIBILITY 0109 mCallButton->setAccessibleName(i18n("Call")); 0110 #endif 0111 0112 buttonLayout->addWidget(mCallButton, 0, Qt::AlignTop); 0113 connect(mCallButton, &QToolButton::clicked, this, &RoomHeaderWidget::callRequested); 0114 0115 mChannelInfoButton->setAutoRaise(true); 0116 mChannelInfoButton->setObjectName(QStringLiteral("mChannelInfoButton")); 0117 mChannelInfoButton->setIcon(QIcon::fromTheme(QStringLiteral("documentinfo"))); 0118 mChannelInfoButton->setToolTip(i18n("Channel's Information")); 0119 #ifndef QT_NO_ACCESSIBILITY 0120 mChannelInfoButton->setAccessibleName(i18n("Channel's Information")); 0121 #endif 0122 0123 buttonLayout->addWidget(mChannelInfoButton, 0, Qt::AlignTop); 0124 connect(mChannelInfoButton, &QToolButton::clicked, this, &RoomHeaderWidget::channelInfoRequested); 0125 0126 mTeamChannelsButton->setAutoRaise(true); 0127 mTeamChannelsButton->setObjectName(QStringLiteral("mTeamChannelsButton")); 0128 mTeamChannelsButton->setIcon(QIcon::fromTheme(QStringLiteral("irc-channel-active"))); 0129 mTeamChannelsButton->setToolTip(i18n("Team Channels")); 0130 #ifndef QT_NO_ACCESSIBILITY 0131 mListOfUsersButton->setAccessibleName(i18n("Team Channels")); 0132 #endif 0133 0134 buttonLayout->addWidget(mTeamChannelsButton, 0, Qt::AlignTop); 0135 connect(mTeamChannelsButton, &QToolButton::clicked, this, &RoomHeaderWidget::teamChannelsRequested); 0136 0137 mListOfUsersButton->setAutoRaise(true); 0138 mListOfUsersButton->setObjectName(QStringLiteral("mListOfUsersButton")); 0139 mListOfUsersButton->setIcon(QIcon::fromTheme(QStringLiteral("system-users"))); 0140 mListOfUsersButton->setCheckable(true); 0141 mListOfUsersButton->setToolTip(i18n("Show List of Users")); 0142 #ifndef QT_NO_ACCESSIBILITY 0143 mListOfUsersButton->setAccessibleName(i18n("Show List of Users")); 0144 #endif 0145 0146 buttonLayout->addWidget(mListOfUsersButton, 0, Qt::AlignTop); 0147 connect(mListOfUsersButton, &QToolButton::clicked, this, &RoomHeaderWidget::listOfUsersChanged); 0148 0149 mSearchMessageButton->setAutoRaise(true); 0150 mSearchMessageButton->setObjectName(QStringLiteral("mSearchMessageButton")); 0151 mSearchMessageButton->setIcon(QIcon::fromTheme(QStringLiteral("edit-find"))); 0152 mSearchMessageButton->setCheckable(false); 0153 mSearchMessageButton->setShortcut(Qt::CTRL | Qt::Key_F); 0154 mSearchMessageButton->setToolTip(i18n("Search Messages...")); 0155 #ifndef QT_NO_ACCESSIBILITY 0156 mSearchMessageButton->setAccessibleName(i18n("Search Messages...")); 0157 #endif 0158 buttonLayout->addWidget(mSearchMessageButton, 0, Qt::AlignTop); 0159 connect(mSearchMessageButton, &QToolButton::clicked, this, &RoomHeaderWidget::searchMessageRequested); 0160 0161 mChannelAction->setAutoRaise(true); 0162 mChannelAction->setObjectName(QStringLiteral("mChannelAction")); 0163 mChannelAction->setPopupMode(QToolButton::InstantPopup); 0164 mChannelAction->setIcon(QIcon::fromTheme(QStringLiteral("application-menu"))); 0165 buttonLayout->addWidget(mChannelAction, 0, Qt::AlignTop); 0166 0167 mChannelActionPopupMenu = new ChannelActionPopupMenu(mChannelAction); 0168 mChannelActionPopupMenu->setObjectName(QStringLiteral("mChannelActionPopupMenu")); 0169 mChannelAction->setMenu(mChannelActionPopupMenu->menu()); 0170 connect(mChannelActionPopupMenu, &ChannelActionPopupMenu::actionRequested, this, &RoomHeaderWidget::actionRequested); 0171 connect(mTeamName, &TeamNameLabel::openTeam, this, &RoomHeaderWidget::openTeam); 0172 } 0173 0174 RoomHeaderWidget::~RoomHeaderWidget() = default; 0175 0176 void RoomHeaderWidget::setCallEnabled(bool b) 0177 { 0178 mCallButton->setVisible(b); 0179 } 0180 0181 void RoomHeaderWidget::setIsDirectGroup(bool state) 0182 { 0183 mChannelInfoButton->setVisible(!state); 0184 } 0185 0186 void RoomHeaderWidget::setTeamRoomInfo(const Room::TeamRoomInfo &info) 0187 { 0188 mTeamName->setTeamRoomInfo(info); 0189 mTeamName->setVisible(!info.teamName.isEmpty()); 0190 } 0191 0192 void RoomHeaderWidget::setRoomName(const QString &name) 0193 { 0194 mRoomName->setText(name); 0195 mRoomName->setVisible(!name.isEmpty()); 0196 } 0197 0198 QString RoomHeaderWidget::roomName() const 0199 { 0200 return mRoomName->text(); 0201 } 0202 0203 void RoomHeaderWidget::setRoomAnnouncement(const QString &name) 0204 { 0205 mRoomHeaderLabel->setRoomAnnouncement(name); 0206 } 0207 0208 void RoomHeaderWidget::setRoomTopic(const QString &name) 0209 { 0210 mRoomHeaderLabel->setRoomTopic(name); 0211 } 0212 0213 void RoomHeaderWidget::setFavoriteStatus(bool b) 0214 { 0215 mFavoriteButton->setChecked(b); 0216 } 0217 0218 void RoomHeaderWidget::setEncypted(bool b) 0219 { 0220 mEncryptedButton->setChecked(b); 0221 mEncryptedButton->setVisible(b); 0222 } 0223 0224 void RoomHeaderWidget::setIsMainTeam(bool isMainTeam) 0225 { 0226 mTeamChannelsButton->setVisible(isMainTeam); 0227 mChannelInfoButton->setToolTip(isMainTeam ? i18n("Team's Information") : i18n("Channel's Information")); 0228 } 0229 0230 void RoomHeaderWidget::setIsDiscussion(bool isDiscussion) 0231 { 0232 mFavoriteButton->setVisible(!isDiscussion); 0233 mDiscussionBackButton->setVisible(isDiscussion); 0234 } 0235 0236 void RoomHeaderWidget::setRoom(Room *room) 0237 { 0238 mChannelActionPopupMenu->setRoom(room); 0239 } 0240 0241 void RoomHeaderWidget::setCurrentRocketChatAccount(RocketChatAccount *account) 0242 { 0243 mChannelActionPopupMenu->setCurrentRocketChatAccount(account); 0244 } 0245 0246 #include "moc_roomheaderwidget.cpp"