blob: 572fbcb987bde51316803cb963e9d16025f1e66b [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>*
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
19#include "videooverlay.h"
20#include "ui_videooverlay.h"
21
Olivier SOLDANO223bcc82017-07-19 16:05:05 -040022// Client
Edric Milaret31484f12016-02-02 14:26:27 -050023#include "contactpicker.h"
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
Olivier SOLDANO223bcc82017-07-19 16:05:05 -040031
32
Edric Milaret80e0b212015-10-16 10:07:43 -040033VideoOverlay::VideoOverlay(QWidget* parent) :
Edric Milaret029b95a2015-06-09 09:51:44 -040034 QWidget(parent),
Edric Milaret5cbf2b62015-07-09 11:36:53 -040035 ui(new Ui::VideoOverlay),
Edric Milaret864a2052016-01-14 15:45:03 -050036 transferDialog_(new CallUtilsDialog()),
37 qualityDialog_(new QualityDialog())
Edric Milaret029b95a2015-06-09 09:51:44 -040038{
39 ui->setupUi(this);
40
Edric Milaret3aca8e32015-06-12 10:01:40 -040041 ui->chatButton->setCheckable(true);
42
Edric Milareta3e47282015-10-23 15:20:30 -040043 actionModel_ = CallModel::instance().userActionModel();
Edric Milaret029b95a2015-06-09 09:51:44 -040044 setAttribute(Qt::WA_NoSystemBackground);
Edric Milaret5927d042015-06-15 12:45:29 -040045
Nicolas Jager97a21b42015-12-03 16:55:45 -050046 ui->noMicButton->setCheckable(true);
Edric Milaret5927d042015-06-15 12:45:29 -040047
48 connect(actionModel_,&UserActionModel::dataChanged, [=](const QModelIndex& tl, const QModelIndex& br) {
49 const int first(tl.row()),last(br.row());
50 for(int i = first; i <= last;i++) {
51 const QModelIndex& idx = actionModel_->index(i,0);
52 switch (idx.data(UserActionModel::Role::ACTION).value<UserActionModel::Action>()) {
Nicolas Jager97a21b42015-12-03 16:55:45 -050053 case UserActionModel::Action::MUTE_AUDIO:
54 ui->noMicButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>());
55 ui->noMicButton->setEnabled(idx.flags() & Qt::ItemIsEnabled);
Edric Milaret5927d042015-06-15 12:45:29 -040056 break;
57 case UserActionModel::Action::MUTE_VIDEO:
Nicolas Jager97a21b42015-12-03 16:55:45 -050058 ui->noVideoButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>());
59 ui->noVideoButton->setEnabled(idx.flags() & Qt::ItemIsEnabled);
Edric Milaret5927d042015-06-15 12:45:29 -040060 break;
Edric Milaret80e0b212015-10-16 10:07:43 -040061 case UserActionModel::Action::HOLD:
62 ui->holdButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>());
63 ui->holdButton->setEnabled(idx.flags() & Qt::ItemIsEnabled);
Edric Milaret31484f12016-02-02 14:26:27 -050064 ui->onHoldLabel->setVisible(idx.data(Qt::CheckStateRole).value<bool>());
Edric Milaret80e0b212015-10-16 10:07:43 -040065 break;
Edric Milareta5fe70f2016-02-05 15:03:31 -050066 case UserActionModel::Action::RECORD:
67 ui->recButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>());
68 ui->recButton->setEnabled(idx.flags() & Qt::ItemIsEnabled);
Edric Milaret5927d042015-06-15 12:45:29 -040069 default:
70 break;
71 }
72 }
73 });
74
Edric Milaret80e0b212015-10-16 10:07:43 -040075 connect(CallModel::instance().selectionModel(), &QItemSelectionModel::currentChanged, [=](const QModelIndex &current, const QModelIndex &previous) {
76 Q_UNUSED(previous)
77 Call* c = current.data(static_cast<int>(Call::Role::Object)).value<Call*>();
78 if (c) {
79 if (c->hasParentCall()) {
80 ui->holdButton->hide();
Edric Milaret80e0b212015-10-16 10:07:43 -040081 ui->transferButton->hide();
82 ui->addPersonButton->hide();
83 ui->chatButton->hide();
84
85 ui->joinButton->show();
86 } else {
87 ui->holdButton->show();
Edric Milaret80e0b212015-10-16 10:07:43 -040088 ui->transferButton->show();
89 ui->addPersonButton->show();
90 ui->chatButton->show();
91
92 ui->joinButton->hide();
93 }
Olivier SOLDANO09ef23a2017-08-02 17:03:18 -040094
Anthony Léonard9cc075b2017-10-23 10:59:40 -040095 if (auto* contactMethod = c->peerContactMethod())
Edric Milaret31484f12016-02-02 14:26:27 -050096 ui->addToContactButton->setVisible(not contactMethod->contact()
97 || contactMethod->contact()->isPlaceHolder());
Olivier SOLDANO09ef23a2017-08-02 17:03:18 -040098
Anthony Léonard9cc075b2017-10-23 10:59:40 -040099 if (auto* acc = c->account())
100 ui->transferButton->setVisible(acc->isIp2ip());
101 else
102 ui->transferButton->setVisible(false); // Hide transferButton as fallback so it is not displayed for Ring calls
Edric Milaret80e0b212015-10-16 10:07:43 -0400103 }
104 });
Nicolas Jager0a9fc602016-03-11 18:35:42 -0500105
106 transferDialog_->setAttribute(Qt::WA_TranslucentBackground);
107 connect(transferDialog_, &CallUtilsDialog::isVisible, [this] (bool visible) {
108 dialogVisible_ = visible;
109 });
110
111 qualityDialog_->setAttribute(Qt::WA_TranslucentBackground);
112 connect(qualityDialog_, &QualityDialog::isVisible, [this] (bool visible) {
113 dialogVisible_ = visible;
114 });
Edric Milaret029b95a2015-06-09 09:51:44 -0400115}
116
117VideoOverlay::~VideoOverlay()
118{
119 delete ui;
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400120 delete transferDialog_;
Edric Milaret864a2052016-01-14 15:45:03 -0500121 delete qualityDialog_;
Edric Milaret029b95a2015-06-09 09:51:44 -0400122}
123
124void
125VideoOverlay::setName(const QString& name)
126{
127 ui->nameLabel->setText(name);
128}
129
130void
131VideoOverlay::setTime(const QString& time)
132{
133 ui->timerLabel->setText(time);
134}
135
Olivier SOLDANO223bcc82017-07-19 16:05:05 -0400136void VideoOverlay::toggleContextButtons(bool visible)
137{
138 if (! visible) {
139 ui->videoCfgBtn->hide();
Olivier SOLDANO223bcc82017-07-19 16:05:05 -0400140 } else {
141 ui->videoCfgBtn->show();
Olivier SOLDANO223bcc82017-07-19 16:05:05 -0400142 }
143}
144
Edric Milaret029b95a2015-06-09 09:51:44 -0400145void
Edric Milaret029b95a2015-06-09 09:51:44 -0400146VideoOverlay::on_hangupButton_clicked()
147{
148 actionModel_->execute(UserActionModel::Action::HANGUP);
Edric Milaret3aca8e32015-06-12 10:01:40 -0400149 ui->chatButton->setChecked(false);
Edric Milaret029b95a2015-06-09 09:51:44 -0400150}
151
152void
153VideoOverlay::on_chatButton_toggled(bool checked)
154{
Edric Milaret3aca8e32015-06-12 10:01:40 -0400155 emit setChatVisibility(checked);
Edric Milaret029b95a2015-06-09 09:51:44 -0400156}
157
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400158void
Edric Milaret80e0b212015-10-16 10:07:43 -0400159VideoOverlay::on_transferButton_clicked()
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400160{
Edric Milaret80e0b212015-10-16 10:07:43 -0400161 transferDialog_->setConfMode(false);
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400162 auto pos = this->mapToGlobal(ui->transferButton->pos());
Edric Milaret80e0b212015-10-16 10:07:43 -0400163 transferDialog_->move(pos.x()
164 - transferDialog_->size().width()/2
165 + ui->transferButton->size().width()/2,
166 pos.y() - (transferDialog_->height()));
167 transferDialog_->show();
168}
169
170void
171VideoOverlay::on_addPersonButton_clicked()
172{
173 transferDialog_->setConfMode(true);
174 auto pos = this->mapToGlobal(ui->addPersonButton->pos());
175 transferDialog_->move(pos.x()
176 - transferDialog_->size().width()/2
177 + ui->addPersonButton->size().width()/2,
178 pos.y() - (transferDialog_->height()));
179 transferDialog_->show();
180}
181
182void
183VideoOverlay::on_holdButton_clicked()
184{
185 actionModel_->execute(UserActionModel::Action::HOLD);
186}
187
Nicolas Jager97a21b42015-12-03 16:55:45 -0500188void
189VideoOverlay::on_noMicButton_clicked()
190{
191 actionModel_->execute(UserActionModel::Action::MUTE_AUDIO);
192}
193
194void
195VideoOverlay::on_noVideoButton_clicked()
196{
197 actionModel_->execute(UserActionModel::Action::MUTE_VIDEO);
198}
199
200
Edric Milaret80e0b212015-10-16 10:07:43 -0400201void VideoOverlay::on_joinButton_clicked()
202{
203 CallModel::instance().selectedCall()->joinToParent();
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400204}
Edric Milaret864a2052016-01-14 15:45:03 -0500205
206void
207VideoOverlay::on_qualityButton_clicked()
208{
209 auto pos = this->mapToGlobal(ui->qualityButton->pos());
210 qualityDialog_->move(pos.x()
211 - qualityDialog_->size().width()/2
212 + ui->qualityButton->size().width()/2,
213 pos.y() - (qualityDialog_->height()));
214 qualityDialog_->show();
215}
Edric Milaret31484f12016-02-02 14:26:27 -0500216
217void
218VideoOverlay::on_addToContactButton_clicked()
219{
220 QPoint globalPos = mapToGlobal(ui->addToContactButton->pos());
221 if (auto contactMethod = CallModel::instance().selectedCall()->peerContactMethod()) {
222 ContactPicker contactPicker(contactMethod);
223 contactPicker.move(globalPos.x(),
224 globalPos.y() + ui->addToContactButton->height());
225 contactPicker.exec();
226 }
227}
Edric Milareta5fe70f2016-02-05 15:03:31 -0500228
229void
230VideoOverlay::on_recButton_clicked()
231{
232 actionModel_->execute(UserActionModel::Action::RECORD);
233}
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400234
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400235void VideoOverlay::on_videoCfgBtn_clicked()
236{
237 emit videoCfgBtnClicked();
238}