Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Nicolas Jager | 74fe46f | 2016-02-29 14:55:09 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 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 "accountdetails.h" |
| 20 | #include "ui_accountdetails.h" |
| 21 | |
| 22 | #include <QSortFilterProxyModel> |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 23 | #include <QFileDialog> |
| 24 | #include <QPushButton> |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 25 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 26 | #include "accountdetails.h" |
Edric Milaret | e82782e | 2016-03-21 12:14:17 -0400 | [diff] [blame] | 27 | #include "codecmodel.h" |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 28 | #include "protocolmodel.h" |
| 29 | #include "certificate.h" |
| 30 | #include "ciphermodel.h" |
Edric Milaret | b1b00ce | 2016-02-03 14:10:05 -0500 | [diff] [blame] | 31 | #include "ringtonemodel.h" |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 32 | |
| 33 | AccountDetails::AccountDetails(QWidget *parent) : |
| 34 | QWidget(parent), |
| 35 | ui(new Ui::AccountDetails), |
| 36 | codecModel_(nullptr), |
Edric Milaret | 2d03da4 | 2015-07-15 15:36:43 -0400 | [diff] [blame] | 37 | currentAccount_(nullptr) |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 38 | { |
| 39 | ui->setupUi(this); |
| 40 | |
Edric Milaret | c9d3e41 | 2015-08-11 15:43:04 -0400 | [diff] [blame] | 41 | setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
| 42 | |
Nicolas Jager | 584a80e | 2016-03-18 16:10:00 -0400 | [diff] [blame^] | 43 | connect(ui->lrcfg_tlsCaListCertificate, &RingButton::clicked, this, &AccountDetails::onCertButtonClicked); |
| 44 | connect(ui->lrcfg_tlsCertificate, &RingButton::clicked, this, &AccountDetails::onCertButtonClicked); |
| 45 | connect(ui->lrcfg_tlsPrivateKeyCertificate, &RingButton::clicked, this, &AccountDetails::onCertButtonClicked); |
Edric Milaret | dda49b6 | 2016-02-05 14:27:38 -0500 | [diff] [blame] | 46 | |
| 47 | connect(&RingtoneModel::instance(), |
| 48 | &RingtoneModel::dataChanged, |
| 49 | [=](const QModelIndex& topLeft, const QModelIndex& bottomRight) { |
| 50 | Q_UNUSED(topLeft) |
| 51 | Q_UNUSED(bottomRight) |
| 52 | if (not currentAccount_) |
| 53 | return; |
| 54 | if (RingtoneModel::instance().isPlaying()) |
| 55 | ui->playButton->setText(tr("Pause")); |
| 56 | else |
| 57 | ui->playButton->setText(tr("Play")); |
| 58 | |
| 59 | }); |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 60 | |
| 61 | connect(ui->lrcfg_tlsEnabled, &QCheckBox::stateChanged, [=] (int state) { |
| 62 | if(state == Qt::Checked) { |
| 63 | ui->negoEncry_1->setVisible(currentAccount_->protocol() != Account::Protocol::RING); |
| 64 | ui->negoEncry_2->setVisible(true); |
| 65 | ui->defaultCipherCheckBox->setVisible(currentAccount_->protocol() != Account::Protocol::RING); |
| 66 | ui->cipherListView->setVisible(!ui->defaultCipherCheckBox->isChecked() |
| 67 | && currentAccount_->protocol() != Account::Protocol::RING); |
| 68 | } else { |
| 69 | ui->negoEncry_1->setVisible(false); |
| 70 | ui->negoEncry_2->setVisible(false); |
| 71 | ui->defaultCipherCheckBox->setVisible(false); |
| 72 | ui->cipherListView->setVisible(false); |
| 73 | } |
| 74 | }); |
| 75 | |
| 76 | connect(ui->defaultCipherCheckBox, &QCheckBox::stateChanged, [=] (int state) { |
| 77 | if (state == Qt::Checked) { |
| 78 | ui->cipherListView->setVisible(false); |
| 79 | currentAccount_->cipherModel()->setUseDefault(true); |
| 80 | } else { |
| 81 | ui->cipherListView->setVisible(true); |
| 82 | currentAccount_->cipherModel()->setUseDefault(false); |
| 83 | } |
| 84 | }); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | AccountDetails::~AccountDetails() |
| 88 | { |
| 89 | delete ui; |
| 90 | } |
| 91 | |
| 92 | void |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 93 | AccountDetails::setAccount(Account* currentAccount) { |
| 94 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 95 | if (currentAccount_) { |
Edric Milaret | dda49b6 | 2016-02-05 14:27:38 -0500 | [diff] [blame] | 96 | stopRingtone(); |
| 97 | save(); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 100 | currentAccount_ = currentAccount; |
| 101 | |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 102 | ui->lrcfg_username->setReadOnly(currentAccount_->protocol() == Account::Protocol::RING); |
| 103 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 104 | codecModel_ = currentAccount->codecModel(); |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 105 | ui->audioCodecView->setModel(codecModel_->audioCodecs()); |
| 106 | ui->videoCodecView->setModel(codecModel_->videoCodecs()); |
| 107 | connect(ui->audioCodecView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), |
| 108 | this, SLOT(audioCodecSelectionChanged(QItemSelection,QItemSelection))); |
| 109 | connect(ui->videoCodecView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), |
| 110 | this, SLOT(videoCodecSelectionChanged(QItemSelection,QItemSelection))); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 111 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 112 | ui->typeValueLabel->setText(currentAccount_->protocolModel()-> |
| 113 | selectionModel()->currentIndex().data().value<QString>()); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 114 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 115 | ui->publishGroup->disconnect(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 116 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 117 | if (currentAccount_->isPublishedSameAsLocal()) |
| 118 | ui->puslishedSameAsLocalRadio->setChecked(true); |
| 119 | else |
| 120 | ui->customPublishedRadio->setChecked(true); |
| 121 | |
| 122 | ui->publishGroup->setId(ui->puslishedSameAsLocalRadio, 1); |
| 123 | ui->publishGroup->setId(ui->customPublishedRadio, 0); |
| 124 | ui->lrcfg_publishedAddress->setEnabled(!currentAccount_->isPublishedSameAsLocal()); |
| 125 | ui->lrcfg_publishedPort->setEnabled(!currentAccount_->isPublishedSameAsLocal()); |
| 126 | |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 127 | connect(ui->publishGroup, |
| 128 | static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), |
| 129 | [=](int id) { |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 130 | currentAccount_->setPublishedSameAsLocal(static_cast<bool>(id)); |
| 131 | }); |
| 132 | |
| 133 | switch (currentAccount_->DTMFType()) { |
| 134 | case DtmfType::OverRtp: |
| 135 | ui->rtpRadio->setChecked(true); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 136 | break; |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 137 | case DtmfType::OverSip: |
| 138 | ui->sipRadio->setChecked(true); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 139 | break; |
| 140 | } |
| 141 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 142 | ui->dtmfGroup->disconnect(); |
| 143 | ui->dtmfGroup->setId(ui->rtpRadio, DtmfType::OverRtp); |
| 144 | ui->dtmfGroup->setId(ui->sipRadio, DtmfType::OverSip); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 145 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 146 | connect(ui->dtmfGroup, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 147 | [=](int id){ currentAccount_->setDTMFType(static_cast<DtmfType>(id)); }); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 148 | |
| 149 | if (currentAccount_->tlsCaListCertificate()) |
Edric Milaret | 4f0b02c | 2015-08-14 11:40:58 -0400 | [diff] [blame] | 150 | ui->lrcfg_tlsCaListCertificate->setText(currentAccount_->tlsCaListCertificate()->path()); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 151 | if (currentAccount_->tlsCertificate()) |
Edric Milaret | 4f0b02c | 2015-08-14 11:40:58 -0400 | [diff] [blame] | 152 | ui->lrcfg_tlsCertificate->setText(currentAccount_->tlsCertificate()->path()); |
| 153 | if (not currentAccount_->tlsPrivateKey().isEmpty()) |
| 154 | ui->lrcfg_tlsPrivateKeyCertificate->setText(currentAccount_->tlsPrivateKey()); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 155 | |
Edric Milaret | 3658736 | 2016-02-04 12:30:52 -0500 | [diff] [blame] | 156 | #ifdef Q_OS_WIN |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 157 | certMap_[ui->lrcfg_tlsCaListCertificate->objectName()] = ¤tAccount_->setTlsCaListCertificate; |
| 158 | certMap_[ui->lrcfg_tlsCertificate->objectName()] = ¤tAccount_->setTlsCertificate; |
Edric Milaret | 4f0b02c | 2015-08-14 11:40:58 -0400 | [diff] [blame] | 159 | certMap_[ui->lrcfg_tlsPrivateKeyCertificate->objectName()] = ¤tAccount_->setTlsPrivateKey; |
Edric Milaret | b37aa1f | 2015-07-09 16:39:04 -0400 | [diff] [blame] | 160 | #endif |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 161 | |
| 162 | ui->srtpEnabled->disconnect(); |
| 163 | connect(ui->srtpEnabled, &QCheckBox::toggled, [=](bool checked) { |
| 164 | currentAccount_->setSrtpEnabled(checked); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 165 | }); |
| 166 | |
| 167 | ui->srtpEnabled->setChecked(currentAccount_->isSrtpEnabled()); |
| 168 | |
| 169 | if (currentAccount_->cipherModel()->useDefault()) |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 170 | ui->defaultCipherCheckBox->setChecked(true); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 171 | else |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 172 | ui->defaultCipherCheckBox->setChecked(false); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 173 | |
| 174 | ui->cipherListView->setModel(currentAccount_->cipherModel()); |
Edric Milaret | b1b00ce | 2016-02-03 14:10:05 -0500 | [diff] [blame] | 175 | |
| 176 | disconnect(ui->ringtonesBox); |
| 177 | ui->ringtonesBox->setModel(&RingtoneModel::instance()); |
| 178 | ui->ringtonesBox->setCurrentIndex(RingtoneModel::instance().selectionModel(currentAccount_)->currentIndex().row()); |
| 179 | connect(ui->ringtonesBox, SIGNAL(currentIndexChanged(int)), this, SLOT(ringtonesBoxCurrentIndexChanged(int))); |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 180 | |
| 181 | auto accountProtocol = currentAccount_->protocol(); |
| 182 | if (accountProtocol == Account::Protocol::RING) { |
| 183 | ui->medStreaEncry->setVisible(false); |
| 184 | ui->lrcfg_tlsEnabled->setVisible(false); |
| 185 | } else if (accountProtocol == Account::Protocol::SIP) { |
| 186 | ui->medStreaEncry->setVisible(true); |
| 187 | ui->lrcfg_tlsEnabled->setVisible(true); |
| 188 | } |
| 189 | |
| 190 | if (ui->lrcfg_tlsEnabled->checkState() == Qt::Checked) { |
| 191 | ui->negoEncry_1->setVisible(true); |
| 192 | ui->negoEncry_2->setVisible(true); |
| 193 | ui->defaultCipherCheckBox->setVisible(currentAccount_->protocol() != Account::Protocol::RING); |
| 194 | } else { |
| 195 | ui->negoEncry_1->setVisible(false); |
| 196 | ui->negoEncry_2->setVisible(false); |
| 197 | ui->defaultCipherCheckBox->setVisible(false); |
| 198 | ui->cipherListView->setVisible(false); |
| 199 | } |
| 200 | |
| 201 | if (ui->defaultCipherCheckBox->checkState() == Qt::Checked) |
| 202 | ui->cipherListView->setVisible(false); |
| 203 | else |
| 204 | ui->cipherListView->setVisible(true); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | void |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 208 | AccountDetails::on_upAudioButton_clicked() { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 209 | codecModel_->moveUp(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 213 | AccountDetails::on_downAudioButton_clicked() { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 214 | codecModel_->moveDown(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | void |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 218 | AccountDetails::on_upVideoButton_clicked() { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 219 | codecModel_->moveUp(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | void |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 223 | AccountDetails::on_downVideoButton_clicked() { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 224 | codecModel_->moveDown(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | void |
| 228 | AccountDetails::save() { |
Edric Milaret | 2d03da4 | 2015-07-15 15:36:43 -0400 | [diff] [blame] | 229 | codecModel_->performAction(CodecModel::EditAction::SAVE); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | void |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 233 | AccountDetails::onCertButtonClicked() { |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 234 | QString fileName = QFileDialog::getOpenFileName(this, tr("Choose File"), |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 235 | "", |
| 236 | tr("Files (*)")); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 237 | |
| 238 | auto sender = QObject::sender(); |
| 239 | |
| 240 | (currentAccount_->*certMap_[sender->objectName()])(fileName); |
Edric Milaret | 9f6b519 | 2016-02-02 15:14:27 -0500 | [diff] [blame] | 241 | if (not fileName.isEmpty()) |
| 242 | static_cast<QPushButton*>(sender)->setText(fileName); |
Edric Milaret | e653879 | 2015-05-08 11:51:01 -0400 | [diff] [blame] | 243 | } |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 244 | |
| 245 | void |
| 246 | AccountDetails::audioCodecSelectionChanged(const QItemSelection& selected, |
| 247 | const QItemSelection& deselected) { |
| 248 | Q_UNUSED(deselected) |
| 249 | if (not codecModel_ || selected.empty()) |
| 250 | return; |
| 251 | auto idx = codecModel_->audioCodecs()->mapToSource(selected.indexes().at(0)); |
| 252 | codecModel_->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect); |
| 253 | } |
| 254 | |
| 255 | void |
| 256 | AccountDetails::videoCodecSelectionChanged(const QItemSelection& selected, |
| 257 | const QItemSelection& deselected) { |
| 258 | Q_UNUSED(deselected) |
| 259 | if (not codecModel_ || selected.empty()) |
| 260 | return; |
| 261 | auto idx = codecModel_->videoCodecs()->mapToSource(selected.indexes().at(0)); |
| 262 | codecModel_->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect); |
| 263 | } |
Edric Milaret | b1b00ce | 2016-02-03 14:10:05 -0500 | [diff] [blame] | 264 | |
| 265 | void |
| 266 | AccountDetails::ringtonesBoxCurrentIndexChanged(int index) |
| 267 | { |
| 268 | RingtoneModel::instance().selectionModel(currentAccount_)->setCurrentIndex( |
| 269 | RingtoneModel::instance().index(index, 0), QItemSelectionModel::ClearAndSelect); |
| 270 | } |
| 271 | |
| 272 | void |
| 273 | AccountDetails::on_playButton_clicked() |
| 274 | { |
| 275 | RingtoneModel::instance().play(RingtoneModel::instance().index( |
| 276 | ui->ringtonesBox->currentIndex(), 0)); |
| 277 | } |
Edric Milaret | dda49b6 | 2016-02-05 14:27:38 -0500 | [diff] [blame] | 278 | |
| 279 | void |
| 280 | AccountDetails::stopRingtone() { |
| 281 | if (not currentAccount_) |
| 282 | return; |
| 283 | auto idx = RingtoneModel::instance().selectionModel(currentAccount_)->currentIndex(); |
| 284 | if (RingtoneModel::instance().isPlaying()) |
| 285 | RingtoneModel::instance().play(idx); |
| 286 | } |
Nicolas Jager | 74fe46f | 2016-02-29 14:55:09 -0500 | [diff] [blame] | 287 | |
| 288 | QPushButton* |
| 289 | AccountDetails::getDeleteAccountButton() |
| 290 | { |
| 291 | return ui->deleteAccountButton; |
| 292 | } |
| 293 | |