File indexing completed on 2024-05-12 05:02:13

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 "videoconferencenotificationjob.h"
0008 #include "rocketchataccount.h"
0009 #include "ruqola_videoconference_core_debug.h"
0010 #include <KLocalizedString>
0011 #include <KNotification>
0012 
0013 VideoConferenceNotificationJob::VideoConferenceNotificationJob(QObject *parent)
0014     : QObject{parent}
0015 {
0016 }
0017 
0018 VideoConferenceNotificationJob::~VideoConferenceNotificationJob() = default;
0019 
0020 void VideoConferenceNotificationJob::start()
0021 {
0022     if (!canStart()) {
0023         qCWarning(RUQOLA_VIDEO_CONFERENCE_LOG) << "Impossible to start VideoConferenceNotificationJob";
0024         deleteLater();
0025         return;
0026     }
0027     switch (mVideoConference.action()) {
0028     case VideoConference::IncomingCall:
0029         inComingCall();
0030         return;
0031     case VideoConference::Unknown:
0032     case VideoConference::Canceled:
0033     case VideoConference::Confirmed:
0034     case VideoConference::Accepted:
0035     case VideoConference::Rejected:
0036         break;
0037     }
0038     deleteLater();
0039 }
0040 
0041 QString VideoConferenceNotificationJob::generateText() const
0042 {
0043     const QString str = mRocketChatAccount->accountName() + QLatin1Char('\n');
0044     // Add user name!
0045     return str;
0046 }
0047 
0048 void VideoConferenceNotificationJob::inComingCall()
0049 {
0050     auto notification = new KNotification(QStringLiteral("VideoConference-Incoming"), KNotification::CloseOnTimeout);
0051     notification->setTitle(i18n("InComing Call"));
0052     // notification->setIconName(QStringLiteral("network-connect"));
0053     notification->setText(generateText());
0054 
0055     auto acceptAction = notification->addAction(i18n("Accept"));
0056     connect(acceptAction, &KNotificationAction::activated, this, [this] {
0057         Q_EMIT acceptVideoConference();
0058         deleteLater();
0059     });
0060 
0061     auto rejectAction = notification->addAction(i18n("Reject"));
0062     connect(rejectAction, &KNotificationAction::activated, this, [this] {
0063         Q_EMIT rejectVideoConference();
0064         deleteLater();
0065     });
0066 
0067     connect(notification, &KNotification::closed, this, &VideoConferenceNotificationJob::deleteLater);
0068     notification->sendEvent();
0069 }
0070 
0071 bool VideoConferenceNotificationJob::canStart() const
0072 {
0073     return mVideoConference.isValid();
0074 }
0075 
0076 void VideoConferenceNotificationJob::setRocketChatAccount(RocketChatAccount *account)
0077 {
0078     mRocketChatAccount = account;
0079 }
0080 
0081 VideoConference VideoConferenceNotificationJob::videoConference() const
0082 {
0083     return mVideoConference;
0084 }
0085 
0086 void VideoConferenceNotificationJob::setVideoConference(const VideoConference &newVideoConference)
0087 {
0088     mVideoConference = newVideoConference;
0089 }
0090 
0091 #include "moc_videoconferencenotificationjob.cpp"