blob: 97a6e8293b920e5b5bb498dc0a2676b18a71c1b4 [file] [log] [blame]
Edric Milaret029b95a2015-06-09 09:51:44 -04001/***************************************************************************
Anthony Léonard2fde81d2017-04-17 10:06:55 -04002 * Copyright (C) 2015-2017 by Savoir-faire Linux *
Edric Milaret029b95a2015-06-09 09:51:44 -04003 * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04004 * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> *
Edric Milaret029b95a2015-06-09 09:51:44 -04005 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 **************************************************************************/
19
20#include "videooverlay.h"
21#include "ui_videooverlay.h"
22
Olivier SOLDANO223bcc82017-07-19 16:05:05 -040023// LRC
Edric Milaret029b95a2015-06-09 09:51:44 -040024#include "callmodel.h"
Edric Milaret31484f12016-02-02 14:26:27 -050025#include "contactmethod.h"
26#include "person.h"
Olivier SOLDANO09ef23a2017-08-02 17:03:18 -040027#include "account.h"
Edric Milaret029b95a2015-06-09 09:51:44 -040028
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040029#include "lrcinstance.h"
30#include "utils.h"
Olivier SOLDANO223bcc82017-07-19 16:05:05 -040031
Edric Milaret80e0b212015-10-16 10:07:43 -040032VideoOverlay::VideoOverlay(QWidget* parent) :
Edric Milaret029b95a2015-06-09 09:51:44 -040033 QWidget(parent),
Isa Nanicca027ab2018-12-19 16:54:05 -050034 ui(new Ui::VideoOverlay),
35 oneSecondTimer_(new QTimer(this))
Edric Milaret029b95a2015-06-09 09:51:44 -040036{
37 ui->setupUi(this);
38
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040039 ui->bottomButtons->setMouseTracking(true);
40
Edric Milaret3aca8e32015-06-12 10:01:40 -040041 ui->chatButton->setCheckable(true);
42
Edric Milaret029b95a2015-06-09 09:51:44 -040043 setAttribute(Qt::WA_NoSystemBackground);
Edric Milaret5927d042015-06-15 12:45:29 -040044
Nicolas Jager97a21b42015-12-03 16:55:45 -050045 ui->noMicButton->setCheckable(true);
Edric Milaret5927d042015-06-15 12:45:29 -040046
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040047 ui->onHoldLabel->setVisible(false);
Isa Nanicca027ab2018-12-19 16:54:05 -050048
Andreas Traczyka3b984f2018-12-31 12:31:24 -050049 auto accountList = LRCInstance::accountModel().getAccountList();
50 if (!accountList.size()) {
51 QMetaObject::Connection* const connection = new QMetaObject::Connection;
52 connect(&LRCInstance::accountModel(),
53 &lrc::api::NewAccountModel::accountAdded,
54 [this, connection](const std::string& accountId) {
55 Q_UNUSED(accountId);
56 connect(LRCInstance::getCurrentCallModel(), &lrc::api::NewCallModel::callStarted,
57 [this](const std::string& tempCallId) {
58 callId = tempCallId;
59 });
60 QObject::disconnect(*connection);
61 if (connection) {
62 delete connection;
63 }
64 });
65 } else {
66 connect(LRCInstance::getCurrentCallModel(), &lrc::api::NewCallModel::callStarted,
67 [this](const std::string& tempCallId) {
68 callId = tempCallId;
69 });
70 }
Isa Nanicca027ab2018-12-19 16:54:05 -050071
72 connect(oneSecondTimer_, &QTimer::timeout, this, &VideoOverlay::setTime);
73 oneSecondTimer_->start(1000);
Edric Milaret029b95a2015-06-09 09:51:44 -040074}
75
76VideoOverlay::~VideoOverlay()
77{
78 delete ui;
79}
80
81void
82VideoOverlay::setName(const QString& name)
83{
84 ui->nameLabel->setText(name);
85}
86
87void
Isa Nanicca027ab2018-12-19 16:54:05 -050088VideoOverlay::setTime()
Edric Milaret029b95a2015-06-09 09:51:44 -040089{
Isa Nanicca027ab2018-12-19 16:54:05 -050090 if (callId.empty()) { return; }
Andreas Traczyk1c647ec2018-12-31 18:10:32 -050091 try {
92 auto callInfo = LRCInstance::getCurrentCallModel()->getCall(callId);
93 if (callInfo.status == lrc::api::call::Status::IN_PROGRESS) {
Isa Nanicca027ab2018-12-19 16:54:05 -050094
Andreas Traczyk1c647ec2018-12-31 18:10:32 -050095 int numSeconds = std::chrono::duration_cast<std::chrono::seconds>(
96 std::chrono::steady_clock::now() - callInfo.startTime).count();
Isa Nanicca027ab2018-12-19 16:54:05 -050097
Andreas Traczyk1c647ec2018-12-31 18:10:32 -050098 QString labelSec;
99 QString labelMin;
Isa Nanicca027ab2018-12-19 16:54:05 -0500100
Andreas Traczyk1c647ec2018-12-31 18:10:32 -0500101 int numMinutes = numSeconds / 60;
102 int remainder = numSeconds - numMinutes * 60;
103 if (remainder < 10) {
104 labelSec = ":0" + QString::number(remainder);
105 } else {
106 labelSec = ":" + QString::number(remainder);
107 }
Isa Nanicca027ab2018-12-19 16:54:05 -0500108
Andreas Traczyk1c647ec2018-12-31 18:10:32 -0500109 if (numMinutes < 10) {
110 labelMin = "0" + QString::number(numMinutes);
111 } else {
112 labelMin = QString::number(numMinutes);
113 }
114
115 ui->timerLabel->setText(labelMin + labelSec);
Isa Nanicca027ab2018-12-19 16:54:05 -0500116 }
Andreas Traczyk1c647ec2018-12-31 18:10:32 -0500117 } catch (...) { }
Edric Milaret029b95a2015-06-09 09:51:44 -0400118}
119
Olivier SOLDANO223bcc82017-07-19 16:05:05 -0400120void VideoOverlay::toggleContextButtons(bool visible)
121{
122 if (! visible) {
123 ui->videoCfgBtn->hide();
Olivier SOLDANO223bcc82017-07-19 16:05:05 -0400124 } else {
125 ui->videoCfgBtn->show();
Olivier SOLDANO223bcc82017-07-19 16:05:05 -0400126 }
127}
128
Edric Milaret029b95a2015-06-09 09:51:44 -0400129void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400130VideoOverlay::setVideoMuteVisibility(bool visible)
131{
132 ui->noVideoButton->setVisible(visible);
133}
134
135bool
136VideoOverlay::shouldShowOverlay()
137{
138 return ui->bottomButtons->underMouse() || ui->topInfoBar->underMouse();
139}
140
141void
Sébastien Blin93bd2062018-12-17 15:57:16 -0500142VideoOverlay::simulateShowChatview(bool checked)
143{
144 ui->chatButton->setChecked(checked);
145}
146
147bool
148VideoOverlay::getShowChatView()
149{
150 return ui->chatButton->isChecked();
151}
152
153void
Edric Milaret029b95a2015-06-09 09:51:44 -0400154VideoOverlay::on_hangupButton_clicked()
155{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400156 auto selectedConvUid = LRCInstance::getSelectedConvUid();
157 auto conversation = Utils::getConversationFromUid(selectedConvUid,
158 *LRCInstance::getCurrentConversationModel());
159 auto& callId = conversation->callId;
160 auto callModel = LRCInstance::getCurrentCallModel();
161 if (callModel->hasCall(callId)) {
162 callModel->hangUp(callId);
163 }
Edric Milaret3aca8e32015-06-12 10:01:40 -0400164 ui->chatButton->setChecked(false);
Edric Milaret029b95a2015-06-09 09:51:44 -0400165}
166
167void
168VideoOverlay::on_chatButton_toggled(bool checked)
169{
Edric Milaret3aca8e32015-06-12 10:01:40 -0400170 emit setChatVisibility(checked);
Edric Milaret029b95a2015-06-09 09:51:44 -0400171}
172
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400173void
Edric Milaret80e0b212015-10-16 10:07:43 -0400174VideoOverlay::on_holdButton_clicked()
175{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400176 auto selectedConvUid = LRCInstance::getSelectedConvUid();
177 auto conversation = Utils::getConversationFromUid(selectedConvUid,
178 *LRCInstance::getCurrentConversationModel());
179 auto& callId = conversation->callId;
180 auto callModel = LRCInstance::getCurrentCallModel();
181 if (callModel->hasCall(callId)) {
182 auto onHold = callModel->getCall(callId).status == lrc::api::call::Status::PAUSED;
183 ui->holdButton->setChecked(!onHold);
184 ui->onHoldLabel->setVisible(!onHold);
185 callModel->togglePause(callId);
186 }
Edric Milaret80e0b212015-10-16 10:07:43 -0400187}
188
Nicolas Jager97a21b42015-12-03 16:55:45 -0500189void
190VideoOverlay::on_noMicButton_clicked()
191{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400192 auto selectedConvUid = LRCInstance::getSelectedConvUid();
193 auto conversation = Utils::getConversationFromUid(selectedConvUid,
194 *LRCInstance::getCurrentConversationModel());
195 auto& callId = conversation->callId;
196 auto callModel = LRCInstance::getCurrentCallModel();
197 if (callModel->hasCall(callId)) {
198 ui->noMicButton->setChecked(callModel->getCall(callId).audioMuted);
199 callModel->toggleMedia(callId, lrc::api::NewCallModel::Media::AUDIO);
200 }
Nicolas Jager97a21b42015-12-03 16:55:45 -0500201}
202
203void
204VideoOverlay::on_noVideoButton_clicked()
205{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400206 auto selectedConvUid = LRCInstance::getSelectedConvUid();
207 auto conversation = Utils::getConversationFromUid(selectedConvUid,
208 *LRCInstance::getCurrentConversationModel());
209 auto& callId = conversation->callId;
210 auto callModel = LRCInstance::getCurrentCallModel();
211 if (callModel->hasCall(callId)) {
212 ui->noVideoButton->setChecked(callModel->getCall(callId).videoMuted);
213 callModel->toggleMedia(callId, lrc::api::NewCallModel::Media::VIDEO);
214 }
Nicolas Jager97a21b42015-12-03 16:55:45 -0500215}
216
Edric Milaret31484f12016-02-02 14:26:27 -0500217void
Edric Milareta5fe70f2016-02-05 15:03:31 -0500218VideoOverlay::on_recButton_clicked()
219{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400220 auto selectedConvUid = LRCInstance::getSelectedConvUid();
221 auto conversation = Utils::getConversationFromUid(selectedConvUid,
222 *LRCInstance::getCurrentConversationModel());
223 auto& callId = conversation->callId;
224 auto callModel = LRCInstance::getCurrentCallModel();
225 if (callModel->hasCall(callId)) {
226 callModel->toggleAudioRecord(callId);
227 }
Edric Milareta5fe70f2016-02-05 15:03:31 -0500228}
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400229
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400230void VideoOverlay::on_videoCfgBtn_clicked()
231{
232 emit videoCfgBtnClicked();
233}