blob: 5052d49874a0291a18f4f1a1d783d0bc811dfdc9 [file] [log] [blame]
Edric Milaret029b95a2015-06-09 09:51:44 -04001/***************************************************************************
Edric Milaretbab169d2016-01-07 15:13:33 -05002 * Copyright (C) 2015-2016 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
Edric Milaret31484f12016-02-02 14:26:27 -050022#include "contactpicker.h"
23
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"
Edric Milaret029b95a2015-06-09 09:51:44 -040027
Edric Milaret80e0b212015-10-16 10:07:43 -040028VideoOverlay::VideoOverlay(QWidget* parent) :
Edric Milaret029b95a2015-06-09 09:51:44 -040029 QWidget(parent),
Edric Milaret5cbf2b62015-07-09 11:36:53 -040030 ui(new Ui::VideoOverlay),
Edric Milaret864a2052016-01-14 15:45:03 -050031 transferDialog_(new CallUtilsDialog()),
32 qualityDialog_(new QualityDialog())
Edric Milaret029b95a2015-06-09 09:51:44 -040033{
34 ui->setupUi(this);
35
Edric Milaret3aca8e32015-06-12 10:01:40 -040036 ui->chatButton->setCheckable(true);
37
Edric Milareta3e47282015-10-23 15:20:30 -040038 actionModel_ = CallModel::instance().userActionModel();
Edric Milaret029b95a2015-06-09 09:51:44 -040039 setAttribute(Qt::WA_NoSystemBackground);
Edric Milaret5927d042015-06-15 12:45:29 -040040
Nicolas Jager97a21b42015-12-03 16:55:45 -050041 ui->noMicButton->setCheckable(true);
Edric Milaret5927d042015-06-15 12:45:29 -040042
Edric Milaret864a2052016-01-14 15:45:03 -050043 QPixmap pixmap(":/images/video-conf/ic_high_quality_white.svg");
44 QIcon qualityIcon(pixmap);
45 ui->qualityButton->setIcon(qualityIcon);
46 ui->qualityButton->setIconSize(pixmap.rect().size());
47
Edric Milaret5927d042015-06-15 12:45:29 -040048 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 }
Edric Milaret31484f12016-02-02 14:26:27 -050094 if (auto contactMethod = c->peerContactMethod())
95 ui->addToContactButton->setVisible(not contactMethod->contact()
96 || contactMethod->contact()->isPlaceHolder());
Edric Milaret80e0b212015-10-16 10:07:43 -040097 }
98 });
Edric Milaret029b95a2015-06-09 09:51:44 -040099}
100
101VideoOverlay::~VideoOverlay()
102{
103 delete ui;
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400104 delete transferDialog_;
Edric Milaret864a2052016-01-14 15:45:03 -0500105 delete qualityDialog_;
Edric Milaret029b95a2015-06-09 09:51:44 -0400106}
107
108void
109VideoOverlay::setName(const QString& name)
110{
111 ui->nameLabel->setText(name);
112}
113
114void
115VideoOverlay::setTime(const QString& time)
116{
117 ui->timerLabel->setText(time);
118}
119
120void
Edric Milaret029b95a2015-06-09 09:51:44 -0400121VideoOverlay::on_hangupButton_clicked()
122{
123 actionModel_->execute(UserActionModel::Action::HANGUP);
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_transferButton_clicked()
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400135{
Edric Milaret80e0b212015-10-16 10:07:43 -0400136 transferDialog_->setConfMode(false);
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400137 auto pos = this->mapToGlobal(ui->transferButton->pos());
Edric Milaret80e0b212015-10-16 10:07:43 -0400138 transferDialog_->move(pos.x()
139 - transferDialog_->size().width()/2
140 + ui->transferButton->size().width()/2,
141 pos.y() - (transferDialog_->height()));
142 transferDialog_->show();
143}
144
145void
146VideoOverlay::on_addPersonButton_clicked()
147{
148 transferDialog_->setConfMode(true);
149 auto pos = this->mapToGlobal(ui->addPersonButton->pos());
150 transferDialog_->move(pos.x()
151 - transferDialog_->size().width()/2
152 + ui->addPersonButton->size().width()/2,
153 pos.y() - (transferDialog_->height()));
154 transferDialog_->show();
155}
156
157void
158VideoOverlay::on_holdButton_clicked()
159{
160 actionModel_->execute(UserActionModel::Action::HOLD);
161}
162
Nicolas Jager97a21b42015-12-03 16:55:45 -0500163void
164VideoOverlay::on_noMicButton_clicked()
165{
166 actionModel_->execute(UserActionModel::Action::MUTE_AUDIO);
167}
168
169void
170VideoOverlay::on_noVideoButton_clicked()
171{
172 actionModel_->execute(UserActionModel::Action::MUTE_VIDEO);
173}
174
175
Edric Milaret80e0b212015-10-16 10:07:43 -0400176void VideoOverlay::on_joinButton_clicked()
177{
178 CallModel::instance().selectedCall()->joinToParent();
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400179}
Edric Milaret864a2052016-01-14 15:45:03 -0500180
181void
182VideoOverlay::on_qualityButton_clicked()
183{
184 auto pos = this->mapToGlobal(ui->qualityButton->pos());
185 qualityDialog_->move(pos.x()
186 - qualityDialog_->size().width()/2
187 + ui->qualityButton->size().width()/2,
188 pos.y() - (qualityDialog_->height()));
189 qualityDialog_->show();
190}
Edric Milaret31484f12016-02-02 14:26:27 -0500191
192void
193VideoOverlay::on_addToContactButton_clicked()
194{
195 QPoint globalPos = mapToGlobal(ui->addToContactButton->pos());
196 if (auto contactMethod = CallModel::instance().selectedCall()->peerContactMethod()) {
197 ContactPicker contactPicker(contactMethod);
198 contactPicker.move(globalPos.x(),
199 globalPos.y() + ui->addToContactButton->height());
200 contactPicker.exec();
201 }
202}
Edric Milareta5fe70f2016-02-05 15:03:31 -0500203
204void
205VideoOverlay::on_recButton_clicked()
206{
207 actionModel_->execute(UserActionModel::Action::RECORD);
208}