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 | |
Edric Milaret | 31484f1 | 2016-02-02 14:26:27 -0500 | [diff] [blame] | 22 | #include "contactpicker.h" |
| 23 | |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 24 | #include "callmodel.h" |
Edric Milaret | 31484f1 | 2016-02-02 14:26:27 -0500 | [diff] [blame] | 25 | #include "contactmethod.h" |
| 26 | #include "person.h" |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 27 | |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 28 | VideoOverlay::VideoOverlay(QWidget* parent) : |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 29 | QWidget(parent), |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 30 | ui(new Ui::VideoOverlay), |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 31 | transferDialog_(new CallUtilsDialog()), |
| 32 | qualityDialog_(new QualityDialog()) |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 33 | { |
| 34 | ui->setupUi(this); |
| 35 | |
Edric Milaret | 3aca8e3 | 2015-06-12 10:01:40 -0400 | [diff] [blame] | 36 | ui->chatButton->setCheckable(true); |
| 37 | |
Edric Milaret | a3e4728 | 2015-10-23 15:20:30 -0400 | [diff] [blame] | 38 | actionModel_ = CallModel::instance().userActionModel(); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 39 | setAttribute(Qt::WA_NoSystemBackground); |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 40 | |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 41 | ui->noMicButton->setCheckable(true); |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 42 | |
| 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 Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 48 | case UserActionModel::Action::MUTE_AUDIO: |
| 49 | ui->noMicButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>()); |
| 50 | ui->noMicButton->setEnabled(idx.flags() & Qt::ItemIsEnabled); |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 51 | break; |
| 52 | case UserActionModel::Action::MUTE_VIDEO: |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 53 | ui->noVideoButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>()); |
| 54 | ui->noVideoButton->setEnabled(idx.flags() & Qt::ItemIsEnabled); |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 55 | break; |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 56 | case UserActionModel::Action::HOLD: |
| 57 | ui->holdButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>()); |
| 58 | ui->holdButton->setEnabled(idx.flags() & Qt::ItemIsEnabled); |
Edric Milaret | 31484f1 | 2016-02-02 14:26:27 -0500 | [diff] [blame] | 59 | ui->onHoldLabel->setVisible(idx.data(Qt::CheckStateRole).value<bool>()); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 60 | break; |
Edric Milaret | a5fe70f | 2016-02-05 15:03:31 -0500 | [diff] [blame] | 61 | case UserActionModel::Action::RECORD: |
| 62 | ui->recButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>()); |
| 63 | ui->recButton->setEnabled(idx.flags() & Qt::ItemIsEnabled); |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 64 | default: |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | }); |
| 69 | |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 70 | connect(CallModel::instance().selectionModel(), &QItemSelectionModel::currentChanged, [=](const QModelIndex ¤t, 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 Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 76 | ui->transferButton->hide(); |
| 77 | ui->addPersonButton->hide(); |
| 78 | ui->chatButton->hide(); |
| 79 | |
| 80 | ui->joinButton->show(); |
| 81 | } else { |
| 82 | ui->holdButton->show(); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 83 | ui->transferButton->show(); |
| 84 | ui->addPersonButton->show(); |
| 85 | ui->chatButton->show(); |
| 86 | |
| 87 | ui->joinButton->hide(); |
| 88 | } |
Edric Milaret | 31484f1 | 2016-02-02 14:26:27 -0500 | [diff] [blame] | 89 | if (auto contactMethod = c->peerContactMethod()) |
| 90 | ui->addToContactButton->setVisible(not contactMethod->contact() |
| 91 | || contactMethod->contact()->isPlaceHolder()); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 92 | } |
| 93 | }); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | VideoOverlay::~VideoOverlay() |
| 97 | { |
| 98 | delete ui; |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 99 | delete transferDialog_; |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 100 | delete qualityDialog_; |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void |
| 104 | VideoOverlay::setName(const QString& name) |
| 105 | { |
| 106 | ui->nameLabel->setText(name); |
| 107 | } |
| 108 | |
| 109 | void |
| 110 | VideoOverlay::setTime(const QString& time) |
| 111 | { |
| 112 | ui->timerLabel->setText(time); |
| 113 | } |
| 114 | |
| 115 | void |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 116 | VideoOverlay::on_hangupButton_clicked() |
| 117 | { |
| 118 | actionModel_->execute(UserActionModel::Action::HANGUP); |
Edric Milaret | 3aca8e3 | 2015-06-12 10:01:40 -0400 | [diff] [blame] | 119 | ui->chatButton->setChecked(false); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | void |
| 123 | VideoOverlay::on_chatButton_toggled(bool checked) |
| 124 | { |
Edric Milaret | 3aca8e3 | 2015-06-12 10:01:40 -0400 | [diff] [blame] | 125 | emit setChatVisibility(checked); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 126 | } |
| 127 | |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 128 | void |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 129 | VideoOverlay::on_transferButton_clicked() |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 130 | { |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 131 | transferDialog_->setConfMode(false); |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 132 | auto pos = this->mapToGlobal(ui->transferButton->pos()); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 133 | 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 | |
| 140 | void |
| 141 | VideoOverlay::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 | |
| 152 | void |
| 153 | VideoOverlay::on_holdButton_clicked() |
| 154 | { |
| 155 | actionModel_->execute(UserActionModel::Action::HOLD); |
| 156 | } |
| 157 | |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 158 | void |
| 159 | VideoOverlay::on_noMicButton_clicked() |
| 160 | { |
| 161 | actionModel_->execute(UserActionModel::Action::MUTE_AUDIO); |
| 162 | } |
| 163 | |
| 164 | void |
| 165 | VideoOverlay::on_noVideoButton_clicked() |
| 166 | { |
| 167 | actionModel_->execute(UserActionModel::Action::MUTE_VIDEO); |
| 168 | } |
| 169 | |
| 170 | |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 171 | void VideoOverlay::on_joinButton_clicked() |
| 172 | { |
| 173 | CallModel::instance().selectedCall()->joinToParent(); |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 174 | } |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 175 | |
| 176 | void |
| 177 | VideoOverlay::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 Milaret | 31484f1 | 2016-02-02 14:26:27 -0500 | [diff] [blame] | 186 | |
| 187 | void |
| 188 | VideoOverlay::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 Milaret | a5fe70f | 2016-02-05 15:03:31 -0500 | [diff] [blame] | 198 | |
| 199 | void |
| 200 | VideoOverlay::on_recButton_clicked() |
| 201 | { |
| 202 | actionModel_->execute(UserActionModel::Action::RECORD); |
| 203 | } |