blob: 369f43557f4004b05934e2c4956905d28bba35ea [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
22#include "callmodel.h"
23
Edric Milaret80e0b212015-10-16 10:07:43 -040024VideoOverlay::VideoOverlay(QWidget* parent) :
Edric Milaret029b95a2015-06-09 09:51:44 -040025 QWidget(parent),
Edric Milaret5cbf2b62015-07-09 11:36:53 -040026 ui(new Ui::VideoOverlay),
Edric Milaret80e0b212015-10-16 10:07:43 -040027 transferDialog_(new CallUtilsDialog())
Edric Milaret029b95a2015-06-09 09:51:44 -040028{
29 ui->setupUi(this);
30
Edric Milaret3aca8e32015-06-12 10:01:40 -040031 ui->chatButton->setCheckable(true);
32
Edric Milareta3e47282015-10-23 15:20:30 -040033 actionModel_ = CallModel::instance().userActionModel();
Edric Milaret029b95a2015-06-09 09:51:44 -040034 setAttribute(Qt::WA_NoSystemBackground);
Edric Milaret5927d042015-06-15 12:45:29 -040035
Nicolas Jager97a21b42015-12-03 16:55:45 -050036 ui->noMicButton->setCheckable(true);
Edric Milaret5927d042015-06-15 12:45:29 -040037
38 connect(actionModel_,&UserActionModel::dataChanged, [=](const QModelIndex& tl, const QModelIndex& br) {
39 const int first(tl.row()),last(br.row());
40 for(int i = first; i <= last;i++) {
41 const QModelIndex& idx = actionModel_->index(i,0);
42 switch (idx.data(UserActionModel::Role::ACTION).value<UserActionModel::Action>()) {
Nicolas Jager97a21b42015-12-03 16:55:45 -050043 case UserActionModel::Action::MUTE_AUDIO:
44 ui->noMicButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>());
45 ui->noMicButton->setEnabled(idx.flags() & Qt::ItemIsEnabled);
Edric Milaret5927d042015-06-15 12:45:29 -040046 break;
47 case UserActionModel::Action::MUTE_VIDEO:
Nicolas Jager97a21b42015-12-03 16:55:45 -050048 ui->noVideoButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>());
49 ui->noVideoButton->setEnabled(idx.flags() & Qt::ItemIsEnabled);
Edric Milaret5927d042015-06-15 12:45:29 -040050 break;
Edric Milaret80e0b212015-10-16 10:07:43 -040051 case UserActionModel::Action::HOLD:
52 ui->holdButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>());
53 ui->holdButton->setEnabled(idx.flags() & Qt::ItemIsEnabled);
54 break;
Edric Milaret5927d042015-06-15 12:45:29 -040055 default:
56 break;
57 }
58 }
59 });
60
Edric Milaret80e0b212015-10-16 10:07:43 -040061 connect(CallModel::instance().selectionModel(), &QItemSelectionModel::currentChanged, [=](const QModelIndex &current, const QModelIndex &previous) {
62 Q_UNUSED(previous)
63 Call* c = current.data(static_cast<int>(Call::Role::Object)).value<Call*>();
64 if (c) {
65 if (c->hasParentCall()) {
66 ui->holdButton->hide();
Edric Milaret80e0b212015-10-16 10:07:43 -040067 ui->transferButton->hide();
68 ui->addPersonButton->hide();
69 ui->chatButton->hide();
70
71 ui->joinButton->show();
72 } else {
73 ui->holdButton->show();
Edric Milaret80e0b212015-10-16 10:07:43 -040074 ui->transferButton->show();
75 ui->addPersonButton->show();
76 ui->chatButton->show();
77
78 ui->joinButton->hide();
79 }
80 }
81 });
Edric Milaret029b95a2015-06-09 09:51:44 -040082}
83
84VideoOverlay::~VideoOverlay()
85{
86 delete ui;
Edric Milaret5cbf2b62015-07-09 11:36:53 -040087 delete transferDialog_;
Edric Milaret029b95a2015-06-09 09:51:44 -040088}
89
90void
91VideoOverlay::setName(const QString& name)
92{
93 ui->nameLabel->setText(name);
94}
95
96void
97VideoOverlay::setTime(const QString& time)
98{
99 ui->timerLabel->setText(time);
100}
101
102void
Edric Milaret029b95a2015-06-09 09:51:44 -0400103VideoOverlay::on_hangupButton_clicked()
104{
105 actionModel_->execute(UserActionModel::Action::HANGUP);
Edric Milaret3aca8e32015-06-12 10:01:40 -0400106 ui->chatButton->setChecked(false);
Edric Milaret029b95a2015-06-09 09:51:44 -0400107}
108
109void
110VideoOverlay::on_chatButton_toggled(bool checked)
111{
Edric Milaret3aca8e32015-06-12 10:01:40 -0400112 emit setChatVisibility(checked);
Edric Milaret029b95a2015-06-09 09:51:44 -0400113}
114
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400115void
Edric Milaret80e0b212015-10-16 10:07:43 -0400116VideoOverlay::on_transferButton_clicked()
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400117{
Edric Milaret80e0b212015-10-16 10:07:43 -0400118 transferDialog_->setConfMode(false);
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400119 auto pos = this->mapToGlobal(ui->transferButton->pos());
Edric Milaret80e0b212015-10-16 10:07:43 -0400120 transferDialog_->move(pos.x()
121 - transferDialog_->size().width()/2
122 + ui->transferButton->size().width()/2,
123 pos.y() - (transferDialog_->height()));
124 transferDialog_->show();
125}
126
127void
128VideoOverlay::on_addPersonButton_clicked()
129{
130 transferDialog_->setConfMode(true);
131 auto pos = this->mapToGlobal(ui->addPersonButton->pos());
132 transferDialog_->move(pos.x()
133 - transferDialog_->size().width()/2
134 + ui->addPersonButton->size().width()/2,
135 pos.y() - (transferDialog_->height()));
136 transferDialog_->show();
137}
138
139void
140VideoOverlay::on_holdButton_clicked()
141{
142 actionModel_->execute(UserActionModel::Action::HOLD);
143}
144
Nicolas Jager97a21b42015-12-03 16:55:45 -0500145void
146VideoOverlay::on_noMicButton_clicked()
147{
148 actionModel_->execute(UserActionModel::Action::MUTE_AUDIO);
149}
150
151void
152VideoOverlay::on_noVideoButton_clicked()
153{
154 actionModel_->execute(UserActionModel::Action::MUTE_VIDEO);
155}
156
157
Edric Milaret80e0b212015-10-16 10:07:43 -0400158void VideoOverlay::on_joinButton_clicked()
159{
160 CallModel::instance().selectedCall()->joinToParent();
Edric Milaret5cbf2b62015-07-09 11:36:53 -0400161}