blob: c91c2a6442f9f7b8a50140e4228e326512473ce4 [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
43 connect(actionModel_,&UserActionModel::dataChanged, [=](const QModelIndex& tl, const QModelIndex& br) {
44 const int first(tl.row()),last(br.row());
45 for(int i = first; i <= last;i++) {
46 const QModelIndex& idx = actionModel_->index(i,0);
47 switch (idx.data(UserActionModel::Role::ACTION).value<UserActionModel::Action>()) {
Nicolas Jager97a21b42015-12-03 16:55:45 -050048 case UserActionModel::Action::MUTE_AUDIO:
49 ui->noMicButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>());
50 ui->noMicButton->setEnabled(idx.flags() & Qt::ItemIsEnabled);
Edric Milaret5927d042015-06-15 12:45:29 -040051 break;
52 case UserActionModel::Action::MUTE_VIDEO:
Nicolas Jager97a21b42015-12-03 16:55:45 -050053 ui->noVideoButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>());
54 ui->noVideoButton->setEnabled(idx.flags() & Qt::ItemIsEnabled);
Edric Milaret5927d042015-06-15 12:45:29 -040055 break;
Edric Milaret80e0b212015-10-16 10:07:43 -040056 case UserActionModel::Action::HOLD:
57 ui->holdButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>());
58 ui->holdButton->setEnabled(idx.flags() & Qt::ItemIsEnabled);
Edric Milaret31484f12016-02-02 14:26:27 -050059 ui->onHoldLabel->setVisible(idx.data(Qt::CheckStateRole).value<bool>());
Edric Milaret80e0b212015-10-16 10:07:43 -040060 break;
Edric Milareta5fe70f2016-02-05 15:03:31 -050061 case UserActionModel::Action::RECORD:
62 ui->recButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>());
63 ui->recButton->setEnabled(idx.flags() & Qt::ItemIsEnabled);
Edric Milaret5927d042015-06-15 12:45:29 -040064 default:
65 break;
66 }
67 }
68 });
69
Edric Milaret80e0b212015-10-16 10:07:43 -040070 connect(CallModel::instance().selectionModel(), &QItemSelectionModel::currentChanged, [=](const QModelIndex &current, const QModelIndex &previous) {
71 Q_UNUSED(previous)
72 Call* c = current.data(static_cast<int>(Call::Role::Object)).value<Call*>();
73 if (c) {
74 if (c->hasParentCall()) {
75 ui->holdButton->hide();
Edric Milaret80e0b212015-10-16 10:07:43 -040076 ui->transferButton->hide();
77 ui->addPersonButton->hide();
78 ui->chatButton->hide();
79
80 ui->joinButton->show();
81 } else {
82 ui->holdButton->show();
Edric Milaret80e0b212015-10-16 10:07:43 -040083 ui->transferButton->show();
84 ui->addPersonButton->show();
85 ui->chatButton->show();
86
87 ui->joinButton->hide();
88 }
Edric Milaret31484f12016-02-02 14:26:27 -050089 if (auto contactMethod = c->peerContactMethod())
90 ui->addToContactButton->setVisible(not contactMethod->contact()
91 || contactMethod->contact()->isPlaceHolder());
Edric Milaret80e0b212015-10-16 10:07:43 -040092 }
93 });
Edric Milaret029b95a2015-06-09 09:51:44 -040094}
95
96VideoOverlay::~VideoOverlay()
97{
98 delete ui;
Edric Milaret5cbf2b62015-07-09 11:36:53 -040099 delete transferDialog_;
Edric Milaret864a2052016-01-14 15:45:03 -0500100 delete qualityDialog_;
Edric Milaret029b95a2015-06-09 09:51:44 -0400101}
102
103void
104VideoOverlay::setName(const QString& name)
105{
106 ui->nameLabel->setText(name);
107}
108
109void
110VideoOverlay::setTime(const QString& time)
111{
112 ui->timerLabel->setText(time);
113}
114
115void
Edric Milaret029b95a2015-06-09 09:51:44 -0400116VideoOverlay::on_hangupButton_clicked()
117{
118 actionModel_->execute(UserActionModel::Action::HANGUP);
Edric Milaret3aca8e32015-06-12 10:01:40 -0400119 ui->chatButton->setChecked(false);
Edric Milaret029b95a2015-06-09 09:51:44 -0400120}
121
122void
123VideoOverlay::on_chatButton_toggled(bool checked)
124{
Edric Milaret3aca8e32015-06-12 10:01:40 -0400125 emit setChatVisibility(checked);
Edric Milaret029b95a2015-06-09 09:51:44 -0400126}
127
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400128void
Edric Milaret80e0b212015-10-16 10:07:43 -0400129VideoOverlay::on_transferButton_clicked()
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400130{
Edric Milaret80e0b212015-10-16 10:07:43 -0400131 transferDialog_->setConfMode(false);
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400132 auto pos = this->mapToGlobal(ui->transferButton->pos());
Edric Milaret80e0b212015-10-16 10:07:43 -0400133 transferDialog_->move(pos.x()
134 - transferDialog_->size().width()/2
135 + ui->transferButton->size().width()/2,
136 pos.y() - (transferDialog_->height()));
137 transferDialog_->show();
138}
139
140void
141VideoOverlay::on_addPersonButton_clicked()
142{
143 transferDialog_->setConfMode(true);
144 auto pos = this->mapToGlobal(ui->addPersonButton->pos());
145 transferDialog_->move(pos.x()
146 - transferDialog_->size().width()/2
147 + ui->addPersonButton->size().width()/2,
148 pos.y() - (transferDialog_->height()));
149 transferDialog_->show();
150}
151
152void
153VideoOverlay::on_holdButton_clicked()
154{
155 actionModel_->execute(UserActionModel::Action::HOLD);
156}
157
Nicolas Jager97a21b42015-12-03 16:55:45 -0500158void
159VideoOverlay::on_noMicButton_clicked()
160{
161 actionModel_->execute(UserActionModel::Action::MUTE_AUDIO);
162}
163
164void
165VideoOverlay::on_noVideoButton_clicked()
166{
167 actionModel_->execute(UserActionModel::Action::MUTE_VIDEO);
168}
169
170
Edric Milaret80e0b212015-10-16 10:07:43 -0400171void VideoOverlay::on_joinButton_clicked()
172{
173 CallModel::instance().selectedCall()->joinToParent();
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400174}
Edric Milaret864a2052016-01-14 15:45:03 -0500175
176void
177VideoOverlay::on_qualityButton_clicked()
178{
179 auto pos = this->mapToGlobal(ui->qualityButton->pos());
180 qualityDialog_->move(pos.x()
181 - qualityDialog_->size().width()/2
182 + ui->qualityButton->size().width()/2,
183 pos.y() - (qualityDialog_->height()));
184 qualityDialog_->show();
185}
Edric Milaret31484f12016-02-02 14:26:27 -0500186
187void
188VideoOverlay::on_addToContactButton_clicked()
189{
190 QPoint globalPos = mapToGlobal(ui->addToContactButton->pos());
191 if (auto contactMethod = CallModel::instance().selectedCall()->peerContactMethod()) {
192 ContactPicker contactPicker(contactMethod);
193 contactPicker.move(globalPos.x(),
194 globalPos.y() + ui->addToContactButton->height());
195 contactPicker.exec();
196 }
197}
Edric Milareta5fe70f2016-02-05 15:03:31 -0500198
199void
200VideoOverlay::on_recButton_clicked()
201{
202 actionModel_->execute(UserActionModel::Action::RECORD);
203}