Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Anthony Léonard | 2fde81d | 2017-04-17 10:06:55 -0400 | [diff] [blame^] | 2 | * Copyright (C) 2015-2017 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> |
Anthony Léonard | aa90e1a | 2016-10-12 11:24:17 -0400 | [diff] [blame] | 25 | #include <QMessageBox> |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 26 | |
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 | 1343831 | 2016-03-18 13:27:46 -0400 | [diff] [blame] | 85 | |
| 86 | connect(ui->lrcfg_alias, &QLineEdit::textEdited, [=](const QString& newAlias) { |
| 87 | if (currentAccount_ && currentAccount_->protocol() == Account::Protocol::RING) |
| 88 | currentAccount_->setDisplayName(newAlias); |
| 89 | }); |
Anthony Léonard | 5107a69 | 2016-11-04 13:20:37 -0400 | [diff] [blame] | 90 | |
| 91 | connect(ui->lrcfg_nameServiceURL, &QLineEdit::textEdited, [=](const QString& newNSURL) { |
| 92 | if (currentAccount_ && currentAccount_->protocol() == Account::Protocol::RING) |
| 93 | currentAccount_->setNameServiceURL(newNSURL); |
| 94 | }); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | AccountDetails::~AccountDetails() |
| 98 | { |
| 99 | delete ui; |
| 100 | } |
| 101 | |
| 102 | void |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 103 | AccountDetails::setAccount(Account* currentAccount) { |
| 104 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 105 | if (currentAccount_) { |
Edric Milaret | dda49b6 | 2016-02-05 14:27:38 -0500 | [diff] [blame] | 106 | stopRingtone(); |
| 107 | save(); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 108 | } |
| 109 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 110 | currentAccount_ = currentAccount; |
| 111 | |
Edric Milaret | ce0ea47 | 2016-04-12 10:16:56 -0400 | [diff] [blame] | 112 | if (currentAccount_ == nullptr) |
| 113 | return; |
| 114 | |
Anthony Léonard | aa90e1a | 2016-10-12 11:24:17 -0400 | [diff] [blame] | 115 | if (currentAccount_->protocol() == Account::Protocol::RING) { |
Anthony Léonard | 4433876 | 2016-11-15 11:22:27 -0500 | [diff] [blame] | 116 | ui->usernameLabel->setText(tr("RingID")); |
| 117 | ui->lrcfg_username->setReadOnly(true); |
Anthony Léonard | aa90e1a | 2016-10-12 11:24:17 -0400 | [diff] [blame] | 118 | if (currentAccount_->registeredName().isEmpty() ){ // If our user isn't registered on the blockhain |
| 119 | ui->lrcfg_registeredName->clear(); |
| 120 | ui->lrcfg_registeredName->setReadOnly(false); |
| 121 | ui->registerButton->setText(tr("Register on blockchain")); |
| 122 | ui->registerButton->show(); |
| 123 | ui->registerButton->setEnabled(true); |
| 124 | } else { |
| 125 | ui->lrcfg_registeredName->setText(currentAccount_->registeredName()); |
| 126 | ui->lrcfg_registeredName->setReadOnly(true); |
| 127 | ui->registerButton->hide(); |
| 128 | } |
Anthony Léonard | 4433876 | 2016-11-15 11:22:27 -0500 | [diff] [blame] | 129 | } else { // If currentAccount_ is of type SIP |
| 130 | ui->usernameLabel->setText(tr("Username")); |
| 131 | ui->lrcfg_username->setReadOnly(false); |
Anthony Léonard | aa90e1a | 2016-10-12 11:24:17 -0400 | [diff] [blame] | 132 | } |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 133 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 134 | codecModel_ = currentAccount->codecModel(); |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 135 | ui->audioCodecView->setModel(codecModel_->audioCodecs()); |
| 136 | ui->videoCodecView->setModel(codecModel_->videoCodecs()); |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 137 | |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 138 | connect(ui->audioCodecView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), |
| 139 | this, SLOT(audioCodecSelectionChanged(QItemSelection,QItemSelection))); |
| 140 | connect(ui->videoCodecView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), |
| 141 | this, SLOT(videoCodecSelectionChanged(QItemSelection,QItemSelection))); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 142 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 143 | ui->typeValueLabel->setText(currentAccount_->protocolModel()-> |
| 144 | selectionModel()->currentIndex().data().value<QString>()); |
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 | ui->publishGroup->disconnect(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 147 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 148 | if (currentAccount_->isPublishedSameAsLocal()) |
| 149 | ui->puslishedSameAsLocalRadio->setChecked(true); |
| 150 | else |
| 151 | ui->customPublishedRadio->setChecked(true); |
| 152 | |
| 153 | ui->publishGroup->setId(ui->puslishedSameAsLocalRadio, 1); |
| 154 | ui->publishGroup->setId(ui->customPublishedRadio, 0); |
| 155 | ui->lrcfg_publishedAddress->setEnabled(!currentAccount_->isPublishedSameAsLocal()); |
| 156 | ui->lrcfg_publishedPort->setEnabled(!currentAccount_->isPublishedSameAsLocal()); |
| 157 | |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 158 | connect(ui->publishGroup, |
| 159 | static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), |
| 160 | [=](int id) { |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 161 | currentAccount_->setPublishedSameAsLocal(static_cast<bool>(id)); |
| 162 | }); |
| 163 | |
| 164 | switch (currentAccount_->DTMFType()) { |
| 165 | case DtmfType::OverRtp: |
| 166 | ui->rtpRadio->setChecked(true); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 167 | break; |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 168 | case DtmfType::OverSip: |
| 169 | ui->sipRadio->setChecked(true); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 170 | break; |
| 171 | } |
| 172 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 173 | ui->dtmfGroup->disconnect(); |
| 174 | ui->dtmfGroup->setId(ui->rtpRadio, DtmfType::OverRtp); |
| 175 | ui->dtmfGroup->setId(ui->sipRadio, DtmfType::OverSip); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 176 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 177 | connect(ui->dtmfGroup, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 178 | [=](int id){ currentAccount_->setDTMFType(static_cast<DtmfType>(id)); }); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 179 | |
| 180 | if (currentAccount_->tlsCaListCertificate()) |
Edric Milaret | 4f0b02c | 2015-08-14 11:40:58 -0400 | [diff] [blame] | 181 | ui->lrcfg_tlsCaListCertificate->setText(currentAccount_->tlsCaListCertificate()->path()); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 182 | if (currentAccount_->tlsCertificate()) |
Edric Milaret | 4f0b02c | 2015-08-14 11:40:58 -0400 | [diff] [blame] | 183 | ui->lrcfg_tlsCertificate->setText(currentAccount_->tlsCertificate()->path()); |
| 184 | if (not currentAccount_->tlsPrivateKey().isEmpty()) |
| 185 | ui->lrcfg_tlsPrivateKeyCertificate->setText(currentAccount_->tlsPrivateKey()); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 186 | |
Edric Milaret | 3658736 | 2016-02-04 12:30:52 -0500 | [diff] [blame] | 187 | #ifdef Q_OS_WIN |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 188 | certMap_[ui->lrcfg_tlsCaListCertificate->objectName()] = ¤tAccount_->setTlsCaListCertificate; |
| 189 | certMap_[ui->lrcfg_tlsCertificate->objectName()] = ¤tAccount_->setTlsCertificate; |
Edric Milaret | 4f0b02c | 2015-08-14 11:40:58 -0400 | [diff] [blame] | 190 | certMap_[ui->lrcfg_tlsPrivateKeyCertificate->objectName()] = ¤tAccount_->setTlsPrivateKey; |
Edric Milaret | b37aa1f | 2015-07-09 16:39:04 -0400 | [diff] [blame] | 191 | #endif |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 192 | |
| 193 | ui->srtpEnabled->disconnect(); |
| 194 | connect(ui->srtpEnabled, &QCheckBox::toggled, [=](bool checked) { |
| 195 | currentAccount_->setSrtpEnabled(checked); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 196 | }); |
| 197 | |
| 198 | ui->srtpEnabled->setChecked(currentAccount_->isSrtpEnabled()); |
| 199 | |
| 200 | if (currentAccount_->cipherModel()->useDefault()) |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 201 | ui->defaultCipherCheckBox->setChecked(true); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 202 | else |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 203 | ui->defaultCipherCheckBox->setChecked(false); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 204 | |
| 205 | ui->cipherListView->setModel(currentAccount_->cipherModel()); |
Edric Milaret | b1b00ce | 2016-02-03 14:10:05 -0500 | [diff] [blame] | 206 | |
| 207 | disconnect(ui->ringtonesBox); |
| 208 | ui->ringtonesBox->setModel(&RingtoneModel::instance()); |
| 209 | ui->ringtonesBox->setCurrentIndex(RingtoneModel::instance().selectionModel(currentAccount_)->currentIndex().row()); |
| 210 | connect(ui->ringtonesBox, SIGNAL(currentIndexChanged(int)), this, SLOT(ringtonesBoxCurrentIndexChanged(int))); |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 211 | |
| 212 | auto accountProtocol = currentAccount_->protocol(); |
| 213 | if (accountProtocol == Account::Protocol::RING) { |
| 214 | ui->medStreaEncry->setVisible(false); |
| 215 | ui->lrcfg_tlsEnabled->setVisible(false); |
Anthony Léonard | 5107a69 | 2016-11-04 13:20:37 -0400 | [diff] [blame] | 216 | |
| 217 | ui->nameServiceURLLabel->show(); |
| 218 | ui->lrcfg_nameServiceURL->show(); |
| 219 | ui->lrcfg_nameServiceURL->setText(currentAccount_->nameServiceURL()); |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 220 | } else if (accountProtocol == Account::Protocol::SIP) { |
| 221 | ui->medStreaEncry->setVisible(true); |
| 222 | ui->lrcfg_tlsEnabled->setVisible(true); |
Anthony Léonard | 5107a69 | 2016-11-04 13:20:37 -0400 | [diff] [blame] | 223 | |
| 224 | ui->nameServiceURLLabel->hide(); |
| 225 | ui->lrcfg_nameServiceURL->hide(); |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | if (ui->lrcfg_tlsEnabled->checkState() == Qt::Checked) { |
| 229 | ui->negoEncry_1->setVisible(true); |
| 230 | ui->negoEncry_2->setVisible(true); |
| 231 | ui->defaultCipherCheckBox->setVisible(currentAccount_->protocol() != Account::Protocol::RING); |
| 232 | } else { |
| 233 | ui->negoEncry_1->setVisible(false); |
| 234 | ui->negoEncry_2->setVisible(false); |
| 235 | ui->defaultCipherCheckBox->setVisible(false); |
| 236 | ui->cipherListView->setVisible(false); |
| 237 | } |
| 238 | |
| 239 | if (ui->defaultCipherCheckBox->checkState() == Qt::Checked) |
| 240 | ui->cipherListView->setVisible(false); |
| 241 | else |
| 242 | ui->cipherListView->setVisible(true); |
Edric Milaret | 5746784 | 2016-08-30 13:06:11 -0400 | [diff] [blame] | 243 | |
| 244 | ui->tableView->setModel((QAbstractItemModel*)currentAccount_->ringDeviceModel()); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | void |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 248 | AccountDetails::on_upAudioButton_clicked() { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 249 | codecModel_->moveUp(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | void |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 253 | AccountDetails::on_downAudioButton_clicked() { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 254 | codecModel_->moveDown(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | void |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 258 | AccountDetails::on_upVideoButton_clicked() { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 259 | codecModel_->moveUp(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | void |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 263 | AccountDetails::on_downVideoButton_clicked() { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 264 | codecModel_->moveDown(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | void |
| 268 | AccountDetails::save() { |
Edric Milaret | 2d03da4 | 2015-07-15 15:36:43 -0400 | [diff] [blame] | 269 | codecModel_->performAction(CodecModel::EditAction::SAVE); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | void |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 273 | AccountDetails::onCertButtonClicked() { |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 274 | QString fileName = QFileDialog::getOpenFileName(this, tr("Choose File"), |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 275 | "", |
| 276 | tr("Files (*)")); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 277 | |
| 278 | auto sender = QObject::sender(); |
| 279 | |
| 280 | (currentAccount_->*certMap_[sender->objectName()])(fileName); |
Edric Milaret | 9f6b519 | 2016-02-02 15:14:27 -0500 | [diff] [blame] | 281 | if (not fileName.isEmpty()) |
| 282 | static_cast<QPushButton*>(sender)->setText(fileName); |
Edric Milaret | e653879 | 2015-05-08 11:51:01 -0400 | [diff] [blame] | 283 | } |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 284 | |
| 285 | void |
| 286 | AccountDetails::audioCodecSelectionChanged(const QItemSelection& selected, |
| 287 | const QItemSelection& deselected) { |
| 288 | Q_UNUSED(deselected) |
| 289 | if (not codecModel_ || selected.empty()) |
| 290 | return; |
| 291 | auto idx = codecModel_->audioCodecs()->mapToSource(selected.indexes().at(0)); |
| 292 | codecModel_->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect); |
| 293 | } |
| 294 | |
| 295 | void |
| 296 | AccountDetails::videoCodecSelectionChanged(const QItemSelection& selected, |
| 297 | const QItemSelection& deselected) { |
| 298 | Q_UNUSED(deselected) |
| 299 | if (not codecModel_ || selected.empty()) |
| 300 | return; |
| 301 | auto idx = codecModel_->videoCodecs()->mapToSource(selected.indexes().at(0)); |
| 302 | codecModel_->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect); |
| 303 | } |
Edric Milaret | b1b00ce | 2016-02-03 14:10:05 -0500 | [diff] [blame] | 304 | |
| 305 | void |
| 306 | AccountDetails::ringtonesBoxCurrentIndexChanged(int index) |
| 307 | { |
| 308 | RingtoneModel::instance().selectionModel(currentAccount_)->setCurrentIndex( |
| 309 | RingtoneModel::instance().index(index, 0), QItemSelectionModel::ClearAndSelect); |
| 310 | } |
| 311 | |
| 312 | void |
| 313 | AccountDetails::on_playButton_clicked() |
| 314 | { |
| 315 | RingtoneModel::instance().play(RingtoneModel::instance().index( |
| 316 | ui->ringtonesBox->currentIndex(), 0)); |
| 317 | } |
Edric Milaret | dda49b6 | 2016-02-05 14:27:38 -0500 | [diff] [blame] | 318 | |
| 319 | void |
| 320 | AccountDetails::stopRingtone() { |
| 321 | if (not currentAccount_) |
| 322 | return; |
| 323 | auto idx = RingtoneModel::instance().selectionModel(currentAccount_)->currentIndex(); |
| 324 | if (RingtoneModel::instance().isPlaying()) |
| 325 | RingtoneModel::instance().play(idx); |
| 326 | } |
Nicolas Jager | 74fe46f | 2016-02-29 14:55:09 -0500 | [diff] [blame] | 327 | |
| 328 | QPushButton* |
| 329 | AccountDetails::getDeleteAccountButton() |
| 330 | { |
| 331 | return ui->deleteAccountButton; |
| 332 | } |
Edric Milaret | 5746784 | 2016-08-30 13:06:11 -0400 | [diff] [blame] | 333 | |
| 334 | void |
| 335 | AccountDetails::on_addDeviceButton_clicked() |
| 336 | { |
| 337 | ui->devicesStackedWidget->setCurrentIndex(1); |
| 338 | } |
| 339 | |
| 340 | void |
| 341 | AccountDetails::on_cancelButton_clicked() |
| 342 | { |
| 343 | ui->devicesStackedWidget->setCurrentIndex(0); |
| 344 | } |
| 345 | |
| 346 | void |
| 347 | AccountDetails::on_exportOnRingButton_clicked() |
| 348 | { |
| 349 | if (ui->passwordArchiveEdit->text().isEmpty()) |
| 350 | return; |
| 351 | |
| 352 | connect(currentAccount_, SIGNAL(exportOnRingEnded(Account::ExportOnRingStatus,QString)), this, SLOT(exportOnRingEnded(Account::ExportOnRingStatus,QString))); |
| 353 | currentAccount_->exportOnRing(ui->passwordArchiveEdit->text()); |
| 354 | ui->devicesStackedWidget->setCurrentIndex(2); |
| 355 | ui->pinLabel->setText(tr("Please wait while your PIN is generated.")); |
| 356 | } |
| 357 | |
| 358 | void |
| 359 | AccountDetails::exportOnRingEnded(Account::ExportOnRingStatus state, const QString& pin) { |
| 360 | |
| 361 | ui->devicesStackedWidget->setCurrentIndex(2); |
| 362 | |
| 363 | ui->pinLabel->clear(); |
| 364 | |
| 365 | switch (state) { |
| 366 | case Account::ExportOnRingStatus::SUCCESS: |
| 367 | { |
| 368 | ui->pinLabel->setText(pin); |
Anthony Léonard | 3937499 | 2016-10-21 13:39:55 -0400 | [diff] [blame] | 369 | ui->pinLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); |
Edric Milaret | 5746784 | 2016-08-30 13:06:11 -0400 | [diff] [blame] | 370 | break; |
| 371 | } |
| 372 | case Account::ExportOnRingStatus::NETWORK_ERROR: |
| 373 | { |
| 374 | ui->pinLabel->setText(tr("Network Error. Please try again later.")); |
| 375 | break; |
| 376 | } |
| 377 | case Account::ExportOnRingStatus::WRONG_PASSWORD: |
| 378 | ui->pinLabel->setText(tr("Wrong password.")); |
| 379 | break; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | void |
| 384 | AccountDetails::on_exportEndedOkButton_clicked() |
| 385 | { |
| 386 | ui->devicesStackedWidget->setCurrentIndex(0); |
| 387 | } |
| 388 | |
| 389 | void |
| 390 | AccountDetails::on_cancelAddButton_clicked() |
| 391 | { |
| 392 | ui->devicesStackedWidget->setCurrentIndex(0); |
| 393 | } |
Anthony Léonard | 59db8ce | 2016-10-19 10:54:11 -0400 | [diff] [blame] | 394 | |
| 395 | void AccountDetails::on_devicesStackedWidget_currentChanged(int pageNum) |
| 396 | { |
| 397 | // We clear the password textEdit each time we leave its page |
| 398 | if (pageNum != ui->devicesStackedWidget->indexOf(ui->passwordAskingPage)) |
| 399 | ui->passwordArchiveEdit->clear(); |
| 400 | } |
Anthony Léonard | aa90e1a | 2016-10-12 11:24:17 -0400 | [diff] [blame] | 401 | |
| 402 | void AccountDetails::on_registerButton_clicked() |
| 403 | { |
| 404 | ui->registerButton->setEnabled(false); |
| 405 | ui->registerButton->setText(tr("Registering... It may take some time")); |
| 406 | bool regSuccess = currentAccount_->registerName(ui->lrcfg_password->text(), ui->lrcfg_registeredName->text()); |
| 407 | if (!regSuccess) { |
| 408 | QMessageBox::warning(this, "Username not registered", "Username registration failed, try again later."); |
| 409 | ui->registerButton->setEnabled(true); |
| 410 | ui->registerButton->setText(tr("Register on blockchain")); |
| 411 | return; |
| 412 | } |
| 413 | |
| 414 | connect(currentAccount_, SIGNAL(nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString)), |
| 415 | this, SLOT(handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString))); |
| 416 | } |
| 417 | |
| 418 | |
| 419 | void AccountDetails::handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus status, const QString& name) |
| 420 | { |
| 421 | disconnect(currentAccount_, SIGNAL(nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString)), |
| 422 | this, SLOT(handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString))); |
| 423 | switch(status) { |
| 424 | case NameDirectory::RegisterNameStatus::ALREADY_TAKEN: |
| 425 | QMessageBox::warning(this, "Username not registered", "This username is already taken, try another one."); |
| 426 | ui->registerButton->setEnabled(true); |
| 427 | ui->registerButton->setText(tr("Register on blockchain")); |
| 428 | break; |
| 429 | case NameDirectory::RegisterNameStatus::INVALID_NAME: |
| 430 | QMessageBox::warning(this, "Username not registered", "This username is invalid, try another one."); |
| 431 | ui->registerButton->setEnabled(true); |
| 432 | ui->registerButton->setText(tr("Register on blockchain")); |
| 433 | break; |
| 434 | case NameDirectory::RegisterNameStatus::WRONG_PASSWORD: |
| 435 | QMessageBox::warning(this, "Username not registered", "Wrong password, try again."); |
| 436 | ui->registerButton->setEnabled(true); |
| 437 | ui->registerButton->setText(tr("Register on blockchain")); |
| 438 | break; |
| 439 | case NameDirectory::RegisterNameStatus::NETWORK_ERROR: |
| 440 | QMessageBox::warning(this, "Username not registered", "Network error. Try again later."); |
| 441 | ui->registerButton->setEnabled(true); |
| 442 | ui->registerButton->setText(tr("Register on blockchain")); |
| 443 | break; |
| 444 | case NameDirectory::RegisterNameStatus::SUCCESS: |
| 445 | ui->lrcfg_registeredName->setReadOnly(true); |
| 446 | ui->registerButton->hide(); |
| 447 | QMessageBox::information(this, "Username registered", name + " is registered, you can now share this name."); |
| 448 | break; |
| 449 | } |
| 450 | |
| 451 | } |