blob: a8e1e1bfeb99b77026212f22e3db36ee06e95c00 [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
Andreas Traczyka493d5b2019-01-09 20:14:29 -050023#include <QTime>
24
Olivier SOLDANO223bcc82017-07-19 16:05:05 -040025// LRC
Edric Milaret029b95a2015-06-09 09:51:44 -040026#include "callmodel.h"
Edric Milaret31484f12016-02-02 14:26:27 -050027#include "contactmethod.h"
28#include "person.h"
Olivier SOLDANO09ef23a2017-08-02 17:03:18 -040029#include "account.h"
Edric Milaret029b95a2015-06-09 09:51:44 -040030
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040031#include "lrcinstance.h"
32#include "utils.h"
Olivier SOLDANO223bcc82017-07-19 16:05:05 -040033
Edric Milaret80e0b212015-10-16 10:07:43 -040034VideoOverlay::VideoOverlay(QWidget* parent) :
Edric Milaret029b95a2015-06-09 09:51:44 -040035 QWidget(parent),
Isa Nanicca027ab2018-12-19 16:54:05 -050036 ui(new Ui::VideoOverlay),
37 oneSecondTimer_(new QTimer(this))
Edric Milaret029b95a2015-06-09 09:51:44 -040038{
39 ui->setupUi(this);
40
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040041 ui->bottomButtons->setMouseTracking(true);
42
Edric Milaret3aca8e32015-06-12 10:01:40 -040043 ui->chatButton->setCheckable(true);
44
Edric Milaret029b95a2015-06-09 09:51:44 -040045 setAttribute(Qt::WA_NoSystemBackground);
Edric Milaret5927d042015-06-15 12:45:29 -040046
Nicolas Jager97a21b42015-12-03 16:55:45 -050047 ui->noMicButton->setCheckable(true);
Edric Milaret5927d042015-06-15 12:45:29 -040048
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040049 ui->onHoldLabel->setVisible(false);
Edric Milaret029b95a2015-06-09 09:51:44 -040050}
51
52VideoOverlay::~VideoOverlay()
53{
54 delete ui;
55}
56
57void
Andreas Traczyka493d5b2019-01-09 20:14:29 -050058VideoOverlay::callStarted(const std::string& callId)
59{
60 ui->timerLabel->setText("00:00");
61 callId_ = callId;
62 connect(oneSecondTimer_, &QTimer::timeout, this, &VideoOverlay::setTime);
63 oneSecondTimer_->start(1000);
64}
65
66void
Edric Milaret029b95a2015-06-09 09:51:44 -040067VideoOverlay::setName(const QString& name)
68{
69 ui->nameLabel->setText(name);
70}
71
72void
Isa Nanicca027ab2018-12-19 16:54:05 -050073VideoOverlay::setTime()
Edric Milaret029b95a2015-06-09 09:51:44 -040074{
Andreas Traczyka493d5b2019-01-09 20:14:29 -050075 if (callId_.empty()) {
76 return;
77 }
Andreas Traczyk1c647ec2018-12-31 18:10:32 -050078 try {
Andreas Traczyka493d5b2019-01-09 20:14:29 -050079 auto callInfo = LRCInstance::getCurrentCallModel()->getCall(callId_);
Andreas Traczyk1c647ec2018-12-31 18:10:32 -050080 if (callInfo.status == lrc::api::call::Status::IN_PROGRESS) {
Andreas Traczyk1c647ec2018-12-31 18:10:32 -050081 int numSeconds = std::chrono::duration_cast<std::chrono::seconds>(
82 std::chrono::steady_clock::now() - callInfo.startTime).count();
Andreas Traczyka493d5b2019-01-09 20:14:29 -050083 QTime t(0, 0, numSeconds);
84 ui->timerLabel->setText(t.toString(numSeconds > 3600 ? "hh:mm:ss" : "mm:ss"));
Isa Nanicca027ab2018-12-19 16:54:05 -050085 }
Andreas Traczyk1c647ec2018-12-31 18:10:32 -050086 } catch (...) { }
Edric Milaret029b95a2015-06-09 09:51:44 -040087}
88
89void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040090VideoOverlay::setVideoMuteVisibility(bool visible)
91{
92 ui->noVideoButton->setVisible(visible);
93}
94
95bool
96VideoOverlay::shouldShowOverlay()
97{
98 return ui->bottomButtons->underMouse() || ui->topInfoBar->underMouse();
99}
100
101void
Sébastien Blin93bd2062018-12-17 15:57:16 -0500102VideoOverlay::simulateShowChatview(bool checked)
103{
104 ui->chatButton->setChecked(checked);
105}
106
107bool
108VideoOverlay::getShowChatView()
109{
110 return ui->chatButton->isChecked();
111}
112
113void
Edric Milaret029b95a2015-06-09 09:51:44 -0400114VideoOverlay::on_hangupButton_clicked()
115{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400116 auto selectedConvUid = LRCInstance::getSelectedConvUid();
117 auto conversation = Utils::getConversationFromUid(selectedConvUid,
118 *LRCInstance::getCurrentConversationModel());
119 auto& callId = conversation->callId;
120 auto callModel = LRCInstance::getCurrentCallModel();
121 if (callModel->hasCall(callId)) {
122 callModel->hangUp(callId);
123 }
Edric Milaret3aca8e32015-06-12 10:01:40 -0400124 ui->chatButton->setChecked(false);
Edric Milaret029b95a2015-06-09 09:51:44 -0400125}
126
127void
128VideoOverlay::on_chatButton_toggled(bool checked)
129{
Edric Milaret3aca8e32015-06-12 10:01:40 -0400130 emit setChatVisibility(checked);
Edric Milaret029b95a2015-06-09 09:51:44 -0400131}
132
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400133void
Edric Milaret80e0b212015-10-16 10:07:43 -0400134VideoOverlay::on_holdButton_clicked()
135{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400136 auto selectedConvUid = LRCInstance::getSelectedConvUid();
137 auto conversation = Utils::getConversationFromUid(selectedConvUid,
138 *LRCInstance::getCurrentConversationModel());
139 auto& callId = conversation->callId;
140 auto callModel = LRCInstance::getCurrentCallModel();
141 if (callModel->hasCall(callId)) {
142 auto onHold = callModel->getCall(callId).status == lrc::api::call::Status::PAUSED;
143 ui->holdButton->setChecked(!onHold);
144 ui->onHoldLabel->setVisible(!onHold);
145 callModel->togglePause(callId);
146 }
Edric Milaret80e0b212015-10-16 10:07:43 -0400147}
148
Nicolas Jager97a21b42015-12-03 16:55:45 -0500149void
150VideoOverlay::on_noMicButton_clicked()
151{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400152 auto selectedConvUid = LRCInstance::getSelectedConvUid();
153 auto conversation = Utils::getConversationFromUid(selectedConvUid,
154 *LRCInstance::getCurrentConversationModel());
155 auto& callId = conversation->callId;
156 auto callModel = LRCInstance::getCurrentCallModel();
157 if (callModel->hasCall(callId)) {
158 ui->noMicButton->setChecked(callModel->getCall(callId).audioMuted);
159 callModel->toggleMedia(callId, lrc::api::NewCallModel::Media::AUDIO);
160 }
Nicolas Jager97a21b42015-12-03 16:55:45 -0500161}
162
163void
164VideoOverlay::on_noVideoButton_clicked()
165{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400166 auto selectedConvUid = LRCInstance::getSelectedConvUid();
167 auto conversation = Utils::getConversationFromUid(selectedConvUid,
168 *LRCInstance::getCurrentConversationModel());
169 auto& callId = conversation->callId;
170 auto callModel = LRCInstance::getCurrentCallModel();
171 if (callModel->hasCall(callId)) {
172 ui->noVideoButton->setChecked(callModel->getCall(callId).videoMuted);
173 callModel->toggleMedia(callId, lrc::api::NewCallModel::Media::VIDEO);
174 }
Nicolas Jager97a21b42015-12-03 16:55:45 -0500175}
176
Edric Milaret31484f12016-02-02 14:26:27 -0500177void
Edric Milareta5fe70f2016-02-05 15:03:31 -0500178VideoOverlay::on_recButton_clicked()
179{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400180 auto selectedConvUid = LRCInstance::getSelectedConvUid();
181 auto conversation = Utils::getConversationFromUid(selectedConvUid,
182 *LRCInstance::getCurrentConversationModel());
183 auto& callId = conversation->callId;
184 auto callModel = LRCInstance::getCurrentCallModel();
185 if (callModel->hasCall(callId)) {
186 callModel->toggleAudioRecord(callId);
187 }
Edric Milareta5fe70f2016-02-05 15:03:31 -0500188}
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400189
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400190void VideoOverlay::on_videoCfgBtn_clicked()
191{
192 emit videoCfgBtnClicked();
193}