File indexing completed on 2024-12-08 04:34:11

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "conferenceinfowidget.h"
0008 #include "common/flowlayout.h"
0009 #include "connection.h"
0010 #include "rocketchataccount.h"
0011 #include "ruqolawidgets_debug.h"
0012 #include "video-conference/videoconferenceinfojob.h"
0013 #include "videoconference/videoconferenceinfo.h"
0014 #include <KLocalizedString>
0015 #include <QFormLayout>
0016 #include <QIcon>
0017 #include <QLabel>
0018 #include <QScreen>
0019 
0020 ConferenceInfoWidget::ConferenceInfoWidget(RocketChatAccount *account, QWidget *parent)
0021     : QWidget{parent}
0022     , mFormLayout(new QFormLayout(this))
0023     , mRocketChatAccount(account)
0024 {
0025     mFormLayout->setContentsMargins({});
0026     mFormLayout->setObjectName(QStringLiteral("mFormLayout"));
0027 }
0028 
0029 ConferenceInfoWidget::~ConferenceInfoWidget() = default;
0030 
0031 void ConferenceInfoWidget::initializeInfo()
0032 {
0033     auto conferenceInfoJob = new RocketChatRestApi::VideoConferenceInfoJob(this);
0034     conferenceInfoJob->setCallId(mConferenceId);
0035     mRocketChatAccount->restApi()->initializeRestApiJob(conferenceInfoJob);
0036     connect(conferenceInfoJob, &RocketChatRestApi::VideoConferenceInfoJob::videoConferenceInfoDone, this, [this](const QJsonObject &obj) {
0037         VideoConferenceInfo info;
0038         info.parse(obj);
0039         auto meetingUrlLabel = new QLabel(this);
0040         meetingUrlLabel->setText(QStringLiteral("<a href=\"%1\">%1</a>").arg(info.url()));
0041         meetingUrlLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
0042         meetingUrlLabel->setOpenExternalLinks(true);
0043 
0044         mFormLayout->addRow(i18n("Meeting URL:"), meetingUrlLabel);
0045         mFormLayout->addRow(i18n("Provider:"), new QLabel(info.providerName(), this));
0046 
0047         const QString statusInformation = info.statusInformation();
0048         if (!statusInformation.isEmpty()) {
0049             mFormLayout->addRow(i18n("Status:"), new QLabel(statusInformation, this));
0050         }
0051         const auto users = info.users();
0052         if (!users.isEmpty()) {
0053             auto avatarLayout = new FlowLayout;
0054             mFormLayout->addItem(avatarLayout);
0055             for (const auto &user : users) {
0056                 auto avatarLabel = new QLabel(this);
0057                 mFormLayout->addWidget(avatarLabel);
0058                 Utils::AvatarInfo info;
0059                 info.avatarType = Utils::AvatarType::User;
0060                 info.identifier = user.userName();
0061                 const QUrl iconUrlStr = QUrl(mRocketChatAccount->avatarUrl(info));
0062                 if (!iconUrlStr.isEmpty()) {
0063                     const QSize pixmapAvatarSize = QSize(80, 80) * screen()->devicePixelRatio();
0064                     avatarLabel->setPixmap(QIcon(iconUrlStr.toLocalFile()).pixmap(pixmapAvatarSize));
0065                 }
0066                 avatarLabel->setToolTip(user.userName());
0067             }
0068         }
0069     });
0070     if (!conferenceInfoJob->start()) {
0071         qCWarning(RUQOLAWIDGETS_LOG) << "Impossible to start VideoConferenceInfoJob job";
0072     }
0073 }
0074 
0075 QString ConferenceInfoWidget::conferenceId() const
0076 {
0077     return mConferenceId;
0078 }
0079 
0080 void ConferenceInfoWidget::setConferenceId(const QString &newConferenceId)
0081 {
0082     mConferenceId = newConferenceId;
0083 }
0084 
0085 #include "moc_conferenceinfowidget.cpp"