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 #include "roomcounterinfowidget.h" 0007 #include <KLocalizedString> 0008 RoomCounterInfoWidget::RoomCounterInfoWidget(QWidget *parent) 0009 : KMessageWidget(parent) 0010 { 0011 setVisible(false); 0012 setCloseButtonVisible(false); 0013 setMessageType(Information); 0014 setPosition(KMessageWidget::Header); 0015 connect(this, &KMessageWidget::linkActivated, this, &RoomCounterInfoWidget::slotLinkActivated); 0016 } 0017 0018 RoomCounterInfoWidget::~RoomCounterInfoWidget() = default; 0019 0020 ChannelCounterInfo RoomCounterInfoWidget::channelCounterInfo() const 0021 { 0022 return mChannelCounterInfo; 0023 } 0024 0025 void RoomCounterInfoWidget::setChannelCounterInfo(const ChannelCounterInfo &channelCounterInfo) 0026 { 0027 if (mChannelCounterInfo != channelCounterInfo) { 0028 mChannelCounterInfo = channelCounterInfo; 0029 updateInfo(); 0030 } 0031 } 0032 0033 void RoomCounterInfoWidget::updateInfo() 0034 { 0035 if (mChannelCounterInfo.isValid() && mChannelCounterInfo.unreadMessages() > 0) { 0036 setText(i18np("%4 %1 new message since %2. %3", 0037 "%4 %1 new messages since %2. %3", 0038 mChannelCounterInfo.unreadMessages(), 0039 mChannelCounterInfo.unreadFrom().toString(), 0040 QStringLiteral(" <a href=\"markAsRead\">%1</a>").arg(i18n("(Mark As Read)")), 0041 QStringLiteral("<a href=\"gotofirstunreadmessage\">%1</a>").arg(i18n("(Jump to first Unread)")))); 0042 setVisible(true); // FIXME: AnimateShow create some pb. Need to investigate it 0043 } else { 0044 setVisible(false); 0045 } 0046 } 0047 0048 void RoomCounterInfoWidget::slotLinkActivated(const QString &contents) 0049 { 0050 if (contents == QLatin1String("markAsRead")) { 0051 Q_EMIT markAsRead(); 0052 } else if (contents == QLatin1String("gotofirstunreadmessage")) { 0053 Q_EMIT jumpToUnreadMessage(mChannelCounterInfo.unreadMessages()); 0054 setVisible(false); 0055 } 0056 } 0057 0058 #include "moc_roomcounterinfowidget.cpp"