blob: f0706fe3253e089e012c858807100e7900f1365a [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// Client
Edric Milaret31484f12016-02-02 14:26:27 -050024#include "contactpicker.h"
25
Olivier SOLDANO223bcc82017-07-19 16:05:05 -040026// LRC
Edric Milaret029b95a2015-06-09 09:51:44 -040027#include "callmodel.h"
Edric Milaret31484f12016-02-02 14:26:27 -050028#include "contactmethod.h"
29#include "person.h"
Olivier SOLDANO09ef23a2017-08-02 17:03:18 -040030#include "account.h"
Edric Milaret029b95a2015-06-09 09:51:44 -040031
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040032#include "lrcinstance.h"
33#include "utils.h"
Olivier SOLDANO223bcc82017-07-19 16:05:05 -040034
Edric Milaret80e0b212015-10-16 10:07:43 -040035VideoOverlay::VideoOverlay(QWidget* parent) :
Edric Milaret029b95a2015-06-09 09:51:44 -040036 QWidget(parent),
Edric Milaret5cbf2b62015-07-09 11:36:53 -040037 ui(new Ui::VideoOverlay),
Edric Milaret864a2052016-01-14 15:45:03 -050038 transferDialog_(new CallUtilsDialog()),
39 qualityDialog_(new QualityDialog())
Edric Milaret029b95a2015-06-09 09:51:44 -040040{
41 ui->setupUi(this);
42
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040043 ui->bottomButtons->setMouseTracking(true);
44
Edric Milaret3aca8e32015-06-12 10:01:40 -040045 ui->chatButton->setCheckable(true);
46
Edric Milaret029b95a2015-06-09 09:51:44 -040047 setAttribute(Qt::WA_NoSystemBackground);
Edric Milaret5927d042015-06-15 12:45:29 -040048
Nicolas Jager97a21b42015-12-03 16:55:45 -050049 ui->noMicButton->setCheckable(true);
Edric Milaret5927d042015-06-15 12:45:29 -040050
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040051 ui->onHoldLabel->setVisible(false);
Nicolas Jager0a9fc602016-03-11 18:35:42 -050052
53 transferDialog_->setAttribute(Qt::WA_TranslucentBackground);
54 connect(transferDialog_, &CallUtilsDialog::isVisible, [this] (bool visible) {
55 dialogVisible_ = visible;
56 });
57
58 qualityDialog_->setAttribute(Qt::WA_TranslucentBackground);
59 connect(qualityDialog_, &QualityDialog::isVisible, [this] (bool visible) {
60 dialogVisible_ = visible;
61 });
Edric Milaret029b95a2015-06-09 09:51:44 -040062}
63
64VideoOverlay::~VideoOverlay()
65{
66 delete ui;
Edric Milaret5cbf2b62015-07-09 11:36:53 -040067 delete transferDialog_;
Edric Milaret864a2052016-01-14 15:45:03 -050068 delete qualityDialog_;
Edric Milaret029b95a2015-06-09 09:51:44 -040069}
70
71void
72VideoOverlay::setName(const QString& name)
73{
74 ui->nameLabel->setText(name);
75}
76
77void
78VideoOverlay::setTime(const QString& time)
79{
80 ui->timerLabel->setText(time);
81}
82
Olivier SOLDANO223bcc82017-07-19 16:05:05 -040083void VideoOverlay::toggleContextButtons(bool visible)
84{
85 if (! visible) {
86 ui->videoCfgBtn->hide();
Olivier SOLDANO223bcc82017-07-19 16:05:05 -040087 } else {
88 ui->videoCfgBtn->show();
Olivier SOLDANO223bcc82017-07-19 16:05:05 -040089 }
90}
91
Edric Milaret029b95a2015-06-09 09:51:44 -040092void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040093VideoOverlay::setVideoMuteVisibility(bool visible)
94{
95 ui->noVideoButton->setVisible(visible);
96}
97
98bool
99VideoOverlay::shouldShowOverlay()
100{
101 return ui->bottomButtons->underMouse() || ui->topInfoBar->underMouse();
102}
103
104void
Edric Milaret029b95a2015-06-09 09:51:44 -0400105VideoOverlay::on_hangupButton_clicked()
106{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400107 auto selectedConvUid = LRCInstance::getSelectedConvUid();
108 auto conversation = Utils::getConversationFromUid(selectedConvUid,
109 *LRCInstance::getCurrentConversationModel());
110 auto& callId = conversation->callId;
111 auto callModel = LRCInstance::getCurrentCallModel();
112 if (callModel->hasCall(callId)) {
113 callModel->hangUp(callId);
114 }
Edric Milaret3aca8e32015-06-12 10:01:40 -0400115 ui->chatButton->setChecked(false);
Edric Milaret029b95a2015-06-09 09:51:44 -0400116}
117
118void
119VideoOverlay::on_chatButton_toggled(bool checked)
120{
Edric Milaret3aca8e32015-06-12 10:01:40 -0400121 emit setChatVisibility(checked);
Edric Milaret029b95a2015-06-09 09:51:44 -0400122}
123
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400124void
Edric Milaret80e0b212015-10-16 10:07:43 -0400125VideoOverlay::on_transferButton_clicked()
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400126{
Edric Milaret80e0b212015-10-16 10:07:43 -0400127 transferDialog_->setConfMode(false);
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400128 auto pos = this->mapToGlobal(ui->transferButton->pos());
Edric Milaret80e0b212015-10-16 10:07:43 -0400129 transferDialog_->move(pos.x()
130 - transferDialog_->size().width()/2
131 + ui->transferButton->size().width()/2,
132 pos.y() - (transferDialog_->height()));
133 transferDialog_->show();
134}
135
136void
137VideoOverlay::on_addPersonButton_clicked()
138{
139 transferDialog_->setConfMode(true);
140 auto pos = this->mapToGlobal(ui->addPersonButton->pos());
141 transferDialog_->move(pos.x()
142 - transferDialog_->size().width()/2
143 + ui->addPersonButton->size().width()/2,
144 pos.y() - (transferDialog_->height()));
145 transferDialog_->show();
146}
147
148void
149VideoOverlay::on_holdButton_clicked()
150{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400151 auto selectedConvUid = LRCInstance::getSelectedConvUid();
152 auto conversation = Utils::getConversationFromUid(selectedConvUid,
153 *LRCInstance::getCurrentConversationModel());
154 auto& callId = conversation->callId;
155 auto callModel = LRCInstance::getCurrentCallModel();
156 if (callModel->hasCall(callId)) {
157 auto onHold = callModel->getCall(callId).status == lrc::api::call::Status::PAUSED;
158 ui->holdButton->setChecked(!onHold);
159 ui->onHoldLabel->setVisible(!onHold);
160 callModel->togglePause(callId);
161 }
Edric Milaret80e0b212015-10-16 10:07:43 -0400162}
163
Nicolas Jager97a21b42015-12-03 16:55:45 -0500164void
165VideoOverlay::on_noMicButton_clicked()
166{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400167 auto selectedConvUid = LRCInstance::getSelectedConvUid();
168 auto conversation = Utils::getConversationFromUid(selectedConvUid,
169 *LRCInstance::getCurrentConversationModel());
170 auto& callId = conversation->callId;
171 auto callModel = LRCInstance::getCurrentCallModel();
172 if (callModel->hasCall(callId)) {
173 ui->noMicButton->setChecked(callModel->getCall(callId).audioMuted);
174 callModel->toggleMedia(callId, lrc::api::NewCallModel::Media::AUDIO);
175 }
Nicolas Jager97a21b42015-12-03 16:55:45 -0500176}
177
178void
179VideoOverlay::on_noVideoButton_clicked()
180{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400181 auto selectedConvUid = LRCInstance::getSelectedConvUid();
182 auto conversation = Utils::getConversationFromUid(selectedConvUid,
183 *LRCInstance::getCurrentConversationModel());
184 auto& callId = conversation->callId;
185 auto callModel = LRCInstance::getCurrentCallModel();
186 if (callModel->hasCall(callId)) {
187 ui->noVideoButton->setChecked(callModel->getCall(callId).videoMuted);
188 callModel->toggleMedia(callId, lrc::api::NewCallModel::Media::VIDEO);
189 }
Nicolas Jager97a21b42015-12-03 16:55:45 -0500190}
191
192
Edric Milaret80e0b212015-10-16 10:07:43 -0400193void VideoOverlay::on_joinButton_clicked()
194{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400195 // TODO:(newlrc) conferences
196 //CallModel::instance().selectedCall()->joinToParent();
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400197}
Edric Milaret864a2052016-01-14 15:45:03 -0500198
199void
200VideoOverlay::on_qualityButton_clicked()
201{
202 auto pos = this->mapToGlobal(ui->qualityButton->pos());
203 qualityDialog_->move(pos.x()
204 - qualityDialog_->size().width()/2
205 + ui->qualityButton->size().width()/2,
206 pos.y() - (qualityDialog_->height()));
207 qualityDialog_->show();
208}
Edric Milaret31484f12016-02-02 14:26:27 -0500209
210void
Edric Milareta5fe70f2016-02-05 15:03:31 -0500211VideoOverlay::on_recButton_clicked()
212{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400213 auto selectedConvUid = LRCInstance::getSelectedConvUid();
214 auto conversation = Utils::getConversationFromUid(selectedConvUid,
215 *LRCInstance::getCurrentConversationModel());
216 auto& callId = conversation->callId;
217 auto callModel = LRCInstance::getCurrentCallModel();
218 if (callModel->hasCall(callId)) {
219 callModel->toggleAudioRecord(callId);
220 }
Edric Milareta5fe70f2016-02-05 15:03:31 -0500221}
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400222
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400223void VideoOverlay::on_videoCfgBtn_clicked()
224{
225 emit videoCfgBtnClicked();
226}