Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Edric Milaret | 4bba46d | 2015-04-29 16:33:38 -0400 | [diff] [blame] | 2 | * Copyright (C) 2015 by Savoir-Faire Linux * |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -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 "callwidget.h" |
| 20 | #include "ui_callwidget.h" |
| 21 | |
| 22 | |
| 23 | #include "imconversationmanager.h" |
| 24 | #include "instantmessagingmodel.h" |
| 25 | #include "audio/settings.h" |
| 26 | #include "personmodel.h" |
| 27 | #include "fallbackpersoncollection.h" |
| 28 | #include "accountmodel.h" |
| 29 | |
Edric Milaret | 559bda5 | 2015-04-29 17:02:31 -0400 | [diff] [blame] | 30 | #include "wizarddialog.h" |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 31 | |
| 32 | CallWidget::CallWidget(QWidget *parent) : |
| 33 | NavWidget(Main ,parent), |
| 34 | ui(new Ui::CallWidget) |
| 35 | { |
| 36 | ui->setupUi(this); |
| 37 | |
| 38 | ui->holdButton->setCheckable(true); |
| 39 | ui->muteMicButton->setCheckable(true); |
| 40 | ui->muteSpeakerButton->setCheckable(true); |
| 41 | ui->callInvite->setVisible(false); |
| 42 | |
| 43 | actualCall_ = nullptr; |
| 44 | videoRenderer_ = nullptr; |
| 45 | |
| 46 | try { |
| 47 | callModel_ = CallModel::instance(); |
| 48 | |
| 49 | connect(callModel_, SIGNAL(incomingCall(Call*)), |
| 50 | this, SLOT(callIncoming(Call*))); |
| 51 | connect(callModel_, SIGNAL(callAdded(Call*,Call*)), |
| 52 | this, SLOT(addedCall(Call*, Call*))); |
| 53 | connect(callModel_, SIGNAL(callStateChanged(Call*, Call::State)), |
| 54 | this, SLOT(callStateChanged(Call*, Call::State))); |
| 55 | |
| 56 | ui->callList->setModel(callModel_); |
| 57 | |
| 58 | CategorizedHistoryModel::instance()-> |
| 59 | addCollection<MinimalHistoryBackend>(LoadOptions::FORCE_ENABLED); |
| 60 | |
| 61 | ui->historyList->setModel(CategorizedHistoryModel::instance()); |
| 62 | ui->speakerSlider->setValue(Audio::Settings::instance()->playbackVolume()); |
| 63 | ui->micSlider->setValue(Audio::Settings::instance()->captureVolume()); |
| 64 | |
| 65 | findRingAccount(); |
| 66 | |
| 67 | } catch (...) { |
| 68 | qDebug() << "INIT ERROR"; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | CallWidget::~CallWidget() |
| 73 | { |
| 74 | delete ui; |
| 75 | } |
| 76 | |
| 77 | void |
| 78 | CallWidget::findRingAccount() { |
Edric Milaret | 559bda5 | 2015-04-29 17:02:31 -0400 | [diff] [blame] | 79 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 80 | auto a_count = AccountModel::instance()->rowCount(); |
| 81 | auto found = false; |
| 82 | for (int i = 0; i < a_count; ++i) { |
| 83 | auto idx = AccountModel::instance()->index(i, 0); |
| 84 | auto protocol = idx.data(static_cast<int>(Account::Role::Proto)); |
| 85 | if ((Account::Protocol)protocol.toUInt() == Account::Protocol::RING) { |
| 86 | auto username = idx.data(static_cast<int>(Account::Role::Username)); |
| 87 | ui->ringIdLabel->setText( |
| 88 | ui->ringIdLabel->text() + " " + username.toString()); |
| 89 | found = true; |
| 90 | return; |
| 91 | } |
| 92 | } |
| 93 | if (!found) { |
Edric Milaret | 559bda5 | 2015-04-29 17:02:31 -0400 | [diff] [blame] | 94 | WizardDialog *wizardDialog = new WizardDialog(); |
| 95 | wizardDialog->exec(); |
| 96 | delete wizardDialog; |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 97 | findRingAccount(); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | void |
| 102 | CallWidget::callIncoming(Call *call) |
| 103 | { |
| 104 | if (!call->account()->isAutoAnswer()) |
| 105 | ui->callInvite->setVisible(true); |
| 106 | actualCall_ = call; |
| 107 | } |
| 108 | |
| 109 | void |
| 110 | CallWidget::on_acceptButton_clicked() |
| 111 | { |
| 112 | if (actualCall_ != nullptr) |
| 113 | actualCall_->performAction(Call::Action::ACCEPT); |
| 114 | ui->callInvite->setVisible(false); |
| 115 | } |
| 116 | |
| 117 | void |
| 118 | CallWidget::on_refuseButton_clicked() |
| 119 | { |
| 120 | if (actualCall_ == nullptr) |
| 121 | return; |
| 122 | actualCall_->performAction(Call::Action::REFUSE); |
| 123 | actualCall_ = nullptr; |
| 124 | ui->callInvite->setVisible(false); |
| 125 | } |
| 126 | |
| 127 | void |
| 128 | CallWidget::on_holdButton_toggled(bool checked) |
| 129 | { |
| 130 | Q_UNUSED(checked) |
| 131 | if (actualCall_ == nullptr) |
| 132 | return; |
| 133 | actualCall_->performAction(Call::Action::HOLD); |
| 134 | } |
| 135 | |
| 136 | void |
| 137 | CallWidget::on_hangupButton_clicked() |
| 138 | { |
| 139 | if (actualCall_ == nullptr) |
| 140 | return; |
| 141 | actualCall_->performAction(Call::Action::REFUSE); |
| 142 | } |
| 143 | |
| 144 | void |
| 145 | CallWidget::addedCall(Call* call, Call* parent) { |
| 146 | Q_UNUSED(parent); |
| 147 | if (call->direction() == Call::Direction::OUTGOING) { |
| 148 | actualCall_ = call; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | void |
| 153 | CallWidget::callStateChanged(Call* call, Call::State previousState) { |
| 154 | Q_UNUSED(previousState) |
| 155 | ui->callList->setCurrentIndex(callModel_->getIndex(actualCall_)); |
| 156 | if (call->state() == Call::State::OVER) { |
| 157 | actualCall_ = nullptr; |
| 158 | ui->videoWidget->hide(); |
| 159 | } else { |
| 160 | ui->videoWidget->show(); |
| 161 | connect(actualCall_, SIGNAL(isOver(Call*)), |
| 162 | this, SLOT(callStateChanged(Call*,Call::State::OVER))); |
| 163 | ui->messageOutput->setModel( |
| 164 | IMConversationManager::instance()->getModel(actualCall_)); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | void |
| 169 | CallWidget::on_callList_activated(const QModelIndex &index) |
| 170 | { |
| 171 | Call *callSelected = callModel_->getCall(index); |
| 172 | if (actualCall_ != nullptr) { |
| 173 | if (callSelected == actualCall_) |
| 174 | return; |
Edric Milaret | 72c406d | 2015-04-28 13:23:54 -0400 | [diff] [blame] | 175 | ui->videoWidget->hide(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 176 | actualCall_->performAction(Call::Action::HOLD); |
| 177 | } |
| 178 | actualCall_ = callSelected; |
| 179 | actualCall_->performAction(Call::Action::HOLD); |
Edric Milaret | 72c406d | 2015-04-28 13:23:54 -0400 | [diff] [blame] | 180 | ui->videoWidget->show(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | void |
| 184 | CallWidget::on_muteSpeakerButton_toggled(bool checked) |
| 185 | { |
| 186 | Audio::Settings::instance()->mutePlayback(checked); |
| 187 | } |
| 188 | |
| 189 | void |
| 190 | CallWidget::on_muteMicButton_toggled(bool checked) |
| 191 | { |
| 192 | Audio::Settings::instance()->muteCapture(checked); |
| 193 | } |
| 194 | |
| 195 | void |
| 196 | CallWidget::on_speakerSlider_sliderMoved(int position) |
| 197 | { |
| 198 | outputVolume_ = position; |
| 199 | } |
| 200 | |
| 201 | void |
| 202 | CallWidget::on_speakerSlider_sliderReleased() |
| 203 | { |
| 204 | emit Audio::Settings::instance()->setPlaybackVolume(outputVolume_); |
| 205 | } |
| 206 | |
| 207 | void |
| 208 | CallWidget::on_micSlider_sliderMoved(int position) |
| 209 | { |
| 210 | inputVolume_ = position; |
| 211 | } |
| 212 | |
| 213 | void |
| 214 | CallWidget::on_micSlider_sliderReleased() |
| 215 | { |
| 216 | emit Audio::Settings::instance()->setCaptureVolume(inputVolume_); |
| 217 | } |
| 218 | |
| 219 | void |
| 220 | CallWidget::atExit() { |
| 221 | |
| 222 | } |