Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Edric Milaret | bab169d | 2016-01-07 15:13:33 -0500 | [diff] [blame^] | 2 | * Copyright (C) 2015-2016 by Savoir-faire Linux * |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 3 | * 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 Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 24 | VideoOverlay::VideoOverlay(QWidget* parent) : |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 25 | QWidget(parent), |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 26 | ui(new Ui::VideoOverlay), |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 27 | transferDialog_(new CallUtilsDialog()) |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 28 | { |
| 29 | ui->setupUi(this); |
| 30 | |
Edric Milaret | 3aca8e3 | 2015-06-12 10:01:40 -0400 | [diff] [blame] | 31 | ui->chatButton->setCheckable(true); |
| 32 | |
Edric Milaret | a3e4728 | 2015-10-23 15:20:30 -0400 | [diff] [blame] | 33 | actionModel_ = CallModel::instance().userActionModel(); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 34 | setAttribute(Qt::WA_NoSystemBackground); |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 35 | |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 36 | ui->noMicButton->setCheckable(true); |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 37 | |
| 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 Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 43 | case UserActionModel::Action::MUTE_AUDIO: |
| 44 | ui->noMicButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>()); |
| 45 | ui->noMicButton->setEnabled(idx.flags() & Qt::ItemIsEnabled); |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 46 | break; |
| 47 | case UserActionModel::Action::MUTE_VIDEO: |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 48 | ui->noVideoButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>()); |
| 49 | ui->noVideoButton->setEnabled(idx.flags() & Qt::ItemIsEnabled); |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 50 | break; |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 51 | 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 Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 55 | default: |
| 56 | break; |
| 57 | } |
| 58 | } |
| 59 | }); |
| 60 | |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 61 | connect(CallModel::instance().selectionModel(), &QItemSelectionModel::currentChanged, [=](const QModelIndex ¤t, 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 Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 67 | ui->transferButton->hide(); |
| 68 | ui->addPersonButton->hide(); |
| 69 | ui->chatButton->hide(); |
| 70 | |
| 71 | ui->joinButton->show(); |
| 72 | } else { |
| 73 | ui->holdButton->show(); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 74 | ui->transferButton->show(); |
| 75 | ui->addPersonButton->show(); |
| 76 | ui->chatButton->show(); |
| 77 | |
| 78 | ui->joinButton->hide(); |
| 79 | } |
| 80 | } |
| 81 | }); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | VideoOverlay::~VideoOverlay() |
| 85 | { |
| 86 | delete ui; |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 87 | delete transferDialog_; |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void |
| 91 | VideoOverlay::setName(const QString& name) |
| 92 | { |
| 93 | ui->nameLabel->setText(name); |
| 94 | } |
| 95 | |
| 96 | void |
| 97 | VideoOverlay::setTime(const QString& time) |
| 98 | { |
| 99 | ui->timerLabel->setText(time); |
| 100 | } |
| 101 | |
| 102 | void |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 103 | VideoOverlay::on_hangupButton_clicked() |
| 104 | { |
| 105 | actionModel_->execute(UserActionModel::Action::HANGUP); |
Edric Milaret | 3aca8e3 | 2015-06-12 10:01:40 -0400 | [diff] [blame] | 106 | ui->chatButton->setChecked(false); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | void |
| 110 | VideoOverlay::on_chatButton_toggled(bool checked) |
| 111 | { |
Edric Milaret | 3aca8e3 | 2015-06-12 10:01:40 -0400 | [diff] [blame] | 112 | emit setChatVisibility(checked); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 113 | } |
| 114 | |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 115 | void |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 116 | VideoOverlay::on_transferButton_clicked() |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 117 | { |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 118 | transferDialog_->setConfMode(false); |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 119 | auto pos = this->mapToGlobal(ui->transferButton->pos()); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 120 | 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 | |
| 127 | void |
| 128 | VideoOverlay::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 | |
| 139 | void |
| 140 | VideoOverlay::on_holdButton_clicked() |
| 141 | { |
| 142 | actionModel_->execute(UserActionModel::Action::HOLD); |
| 143 | } |
| 144 | |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 145 | void |
| 146 | VideoOverlay::on_noMicButton_clicked() |
| 147 | { |
| 148 | actionModel_->execute(UserActionModel::Action::MUTE_AUDIO); |
| 149 | } |
| 150 | |
| 151 | void |
| 152 | VideoOverlay::on_noVideoButton_clicked() |
| 153 | { |
| 154 | actionModel_->execute(UserActionModel::Action::MUTE_VIDEO); |
| 155 | } |
| 156 | |
| 157 | |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 158 | void VideoOverlay::on_joinButton_clicked() |
| 159 | { |
| 160 | CallModel::instance().selectedCall()->joinToParent(); |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 161 | } |