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 | |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 61 | connect(ui->defaultCipherCheckBox, &QCheckBox::stateChanged, [=] (int state) { |
| 62 | if (state == Qt::Checked) { |
| 63 | ui->cipherListView->setVisible(false); |
| 64 | currentAccount_->cipherModel()->setUseDefault(true); |
| 65 | } else { |
| 66 | ui->cipherListView->setVisible(true); |
| 67 | currentAccount_->cipherModel()->setUseDefault(false); |
| 68 | } |
| 69 | }); |
Edric Milaret | 1343831 | 2016-03-18 13:27:46 -0400 | [diff] [blame] | 70 | |
| 71 | connect(ui->lrcfg_alias, &QLineEdit::textEdited, [=](const QString& newAlias) { |
| 72 | if (currentAccount_ && currentAccount_->protocol() == Account::Protocol::RING) |
| 73 | currentAccount_->setDisplayName(newAlias); |
| 74 | }); |
Anthony Léonard | 5107a69 | 2016-11-04 13:20:37 -0400 | [diff] [blame] | 75 | |
| 76 | connect(ui->lrcfg_nameServiceURL, &QLineEdit::textEdited, [=](const QString& newNSURL) { |
| 77 | if (currentAccount_ && currentAccount_->protocol() == Account::Protocol::RING) |
| 78 | currentAccount_->setNameServiceURL(newNSURL); |
| 79 | }); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | AccountDetails::~AccountDetails() |
| 83 | { |
| 84 | delete ui; |
| 85 | } |
| 86 | |
| 87 | void |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 88 | AccountDetails::setAccount(Account* currentAccount) { |
| 89 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 90 | if (currentAccount_) { |
Edric Milaret | dda49b6 | 2016-02-05 14:27:38 -0500 | [diff] [blame] | 91 | stopRingtone(); |
| 92 | save(); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 93 | } |
| 94 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 95 | currentAccount_ = currentAccount; |
| 96 | |
Edric Milaret | ce0ea47 | 2016-04-12 10:16:56 -0400 | [diff] [blame] | 97 | if (currentAccount_ == nullptr) |
| 98 | return; |
| 99 | |
Anthony Léonard | aa90e1a | 2016-10-12 11:24:17 -0400 | [diff] [blame] | 100 | if (currentAccount_->protocol() == Account::Protocol::RING) { |
Anthony Léonard | 4433876 | 2016-11-15 11:22:27 -0500 | [diff] [blame] | 101 | ui->usernameLabel->setText(tr("RingID")); |
| 102 | ui->lrcfg_username->setReadOnly(true); |
Anthony Léonard | aa90e1a | 2016-10-12 11:24:17 -0400 | [diff] [blame] | 103 | if (currentAccount_->registeredName().isEmpty() ){ // If our user isn't registered on the blockhain |
| 104 | ui->lrcfg_registeredName->clear(); |
| 105 | ui->lrcfg_registeredName->setReadOnly(false); |
| 106 | ui->registerButton->setText(tr("Register on blockchain")); |
| 107 | ui->registerButton->show(); |
| 108 | ui->registerButton->setEnabled(true); |
| 109 | } else { |
| 110 | ui->lrcfg_registeredName->setText(currentAccount_->registeredName()); |
| 111 | ui->lrcfg_registeredName->setReadOnly(true); |
| 112 | ui->registerButton->hide(); |
| 113 | } |
Anthony Léonard | 4433876 | 2016-11-15 11:22:27 -0500 | [diff] [blame] | 114 | } else { // If currentAccount_ is of type SIP |
| 115 | ui->usernameLabel->setText(tr("Username")); |
| 116 | ui->lrcfg_username->setReadOnly(false); |
Anthony Léonard | aa90e1a | 2016-10-12 11:24:17 -0400 | [diff] [blame] | 117 | } |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 118 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 119 | codecModel_ = currentAccount->codecModel(); |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 120 | ui->audioCodecView->setModel(codecModel_->audioCodecs()); |
| 121 | ui->videoCodecView->setModel(codecModel_->videoCodecs()); |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 122 | |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 123 | connect(ui->audioCodecView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), |
| 124 | this, SLOT(audioCodecSelectionChanged(QItemSelection,QItemSelection))); |
| 125 | connect(ui->videoCodecView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), |
| 126 | this, SLOT(videoCodecSelectionChanged(QItemSelection,QItemSelection))); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 127 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 128 | ui->typeValueLabel->setText(currentAccount_->protocolModel()-> |
| 129 | selectionModel()->currentIndex().data().value<QString>()); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 130 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 131 | ui->publishGroup->disconnect(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 132 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 133 | if (currentAccount_->isPublishedSameAsLocal()) |
| 134 | ui->puslishedSameAsLocalRadio->setChecked(true); |
| 135 | else |
| 136 | ui->customPublishedRadio->setChecked(true); |
| 137 | |
| 138 | ui->publishGroup->setId(ui->puslishedSameAsLocalRadio, 1); |
| 139 | ui->publishGroup->setId(ui->customPublishedRadio, 0); |
| 140 | ui->lrcfg_publishedAddress->setEnabled(!currentAccount_->isPublishedSameAsLocal()); |
| 141 | ui->lrcfg_publishedPort->setEnabled(!currentAccount_->isPublishedSameAsLocal()); |
| 142 | |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 143 | connect(ui->publishGroup, |
| 144 | static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), |
| 145 | [=](int id) { |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 146 | currentAccount_->setPublishedSameAsLocal(static_cast<bool>(id)); |
| 147 | }); |
| 148 | |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 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 | |
Olivier SOLDANO | ee35181 | 2017-07-07 08:34:41 -0400 | [diff] [blame^] | 162 | ui->srtpEnabledChkBox->disconnect(); |
| 163 | connect(ui->srtpEnabledChkBox, &QCheckBox::toggled, [=](bool checked) { |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 164 | currentAccount_->setSrtpEnabled(checked); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 165 | }); |
| 166 | |
Olivier SOLDANO | ee35181 | 2017-07-07 08:34:41 -0400 | [diff] [blame^] | 167 | ui->srtpEnabledChkBox->setChecked(currentAccount_->isSrtpEnabled()); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 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) { |
Olivier SOLDANO | ee35181 | 2017-07-07 08:34:41 -0400 | [diff] [blame^] | 183 | ui->srtpEnabledChkBox->hide(); |
Anthony Léonard | 5107a69 | 2016-11-04 13:20:37 -0400 | [diff] [blame] | 184 | ui->nameServiceURLLabel->show(); |
| 185 | ui->lrcfg_nameServiceURL->show(); |
| 186 | ui->lrcfg_nameServiceURL->setText(currentAccount_->nameServiceURL()); |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 187 | } else if (accountProtocol == Account::Protocol::SIP) { |
Olivier SOLDANO | ee35181 | 2017-07-07 08:34:41 -0400 | [diff] [blame^] | 188 | ui->srtpEnabledChkBox->show(); |
Anthony Léonard | 5107a69 | 2016-11-04 13:20:37 -0400 | [diff] [blame] | 189 | ui->nameServiceURLLabel->hide(); |
| 190 | ui->lrcfg_nameServiceURL->hide(); |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 191 | } |
| 192 | |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 193 | if (ui->defaultCipherCheckBox->checkState() == Qt::Checked) |
| 194 | ui->cipherListView->setVisible(false); |
| 195 | else |
| 196 | ui->cipherListView->setVisible(true); |
Edric Milaret | 5746784 | 2016-08-30 13:06:11 -0400 | [diff] [blame] | 197 | |
| 198 | ui->tableView->setModel((QAbstractItemModel*)currentAccount_->ringDeviceModel()); |
Olivier SOLDANO | 5d4a1ff | 2017-05-08 13:12:47 -0400 | [diff] [blame] | 199 | ui->bannedContactsWidget->setAccount(currentAccount_); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 203 | AccountDetails::on_upAudioButton_clicked() { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 204 | codecModel_->moveUp(); |
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_downAudioButton_clicked() { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 209 | codecModel_->moveDown(); |
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_upVideoButton_clicked() { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 214 | codecModel_->moveUp(); |
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_downVideoButton_clicked() { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 219 | codecModel_->moveDown(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | void |
| 223 | AccountDetails::save() { |
Edric Milaret | 2d03da4 | 2015-07-15 15:36:43 -0400 | [diff] [blame] | 224 | codecModel_->performAction(CodecModel::EditAction::SAVE); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | void |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 228 | AccountDetails::onCertButtonClicked() { |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 229 | QString fileName = QFileDialog::getOpenFileName(this, tr("Choose File"), |
Nicolas Jager | e638405 | 2016-03-10 13:13:24 -0500 | [diff] [blame] | 230 | "", |
| 231 | tr("Files (*)")); |
Edric Milaret | 3e6aefe | 2015-06-05 16:07:26 -0400 | [diff] [blame] | 232 | |
| 233 | auto sender = QObject::sender(); |
| 234 | |
| 235 | (currentAccount_->*certMap_[sender->objectName()])(fileName); |
Edric Milaret | 9f6b519 | 2016-02-02 15:14:27 -0500 | [diff] [blame] | 236 | if (not fileName.isEmpty()) |
| 237 | static_cast<QPushButton*>(sender)->setText(fileName); |
Edric Milaret | e653879 | 2015-05-08 11:51:01 -0400 | [diff] [blame] | 238 | } |
Edric Milaret | e531385 | 2015-11-09 13:06:00 -0500 | [diff] [blame] | 239 | |
| 240 | void |
| 241 | AccountDetails::audioCodecSelectionChanged(const QItemSelection& selected, |
| 242 | const QItemSelection& deselected) { |
| 243 | Q_UNUSED(deselected) |
| 244 | if (not codecModel_ || selected.empty()) |
| 245 | return; |
| 246 | auto idx = codecModel_->audioCodecs()->mapToSource(selected.indexes().at(0)); |
| 247 | codecModel_->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect); |
| 248 | } |
| 249 | |
| 250 | void |
| 251 | AccountDetails::videoCodecSelectionChanged(const QItemSelection& selected, |
| 252 | const QItemSelection& deselected) { |
| 253 | Q_UNUSED(deselected) |
| 254 | if (not codecModel_ || selected.empty()) |
| 255 | return; |
| 256 | auto idx = codecModel_->videoCodecs()->mapToSource(selected.indexes().at(0)); |
| 257 | codecModel_->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect); |
| 258 | } |
Edric Milaret | b1b00ce | 2016-02-03 14:10:05 -0500 | [diff] [blame] | 259 | |
| 260 | void |
| 261 | AccountDetails::ringtonesBoxCurrentIndexChanged(int index) |
| 262 | { |
| 263 | RingtoneModel::instance().selectionModel(currentAccount_)->setCurrentIndex( |
| 264 | RingtoneModel::instance().index(index, 0), QItemSelectionModel::ClearAndSelect); |
| 265 | } |
| 266 | |
| 267 | void |
| 268 | AccountDetails::on_playButton_clicked() |
| 269 | { |
| 270 | RingtoneModel::instance().play(RingtoneModel::instance().index( |
| 271 | ui->ringtonesBox->currentIndex(), 0)); |
| 272 | } |
Edric Milaret | dda49b6 | 2016-02-05 14:27:38 -0500 | [diff] [blame] | 273 | |
| 274 | void |
| 275 | AccountDetails::stopRingtone() { |
| 276 | if (not currentAccount_) |
| 277 | return; |
| 278 | auto idx = RingtoneModel::instance().selectionModel(currentAccount_)->currentIndex(); |
| 279 | if (RingtoneModel::instance().isPlaying()) |
| 280 | RingtoneModel::instance().play(idx); |
| 281 | } |
Nicolas Jager | 74fe46f | 2016-02-29 14:55:09 -0500 | [diff] [blame] | 282 | |
Edric Milaret | 5746784 | 2016-08-30 13:06:11 -0400 | [diff] [blame] | 283 | void |
| 284 | AccountDetails::on_addDeviceButton_clicked() |
| 285 | { |
| 286 | ui->devicesStackedWidget->setCurrentIndex(1); |
| 287 | } |
| 288 | |
| 289 | void |
| 290 | AccountDetails::on_cancelButton_clicked() |
| 291 | { |
| 292 | ui->devicesStackedWidget->setCurrentIndex(0); |
| 293 | } |
| 294 | |
| 295 | void |
| 296 | AccountDetails::on_exportOnRingButton_clicked() |
| 297 | { |
| 298 | if (ui->passwordArchiveEdit->text().isEmpty()) |
| 299 | return; |
| 300 | |
| 301 | connect(currentAccount_, SIGNAL(exportOnRingEnded(Account::ExportOnRingStatus,QString)), this, SLOT(exportOnRingEnded(Account::ExportOnRingStatus,QString))); |
| 302 | currentAccount_->exportOnRing(ui->passwordArchiveEdit->text()); |
| 303 | ui->devicesStackedWidget->setCurrentIndex(2); |
| 304 | ui->pinLabel->setText(tr("Please wait while your PIN is generated.")); |
| 305 | } |
| 306 | |
| 307 | void |
| 308 | AccountDetails::exportOnRingEnded(Account::ExportOnRingStatus state, const QString& pin) { |
| 309 | |
| 310 | ui->devicesStackedWidget->setCurrentIndex(2); |
| 311 | |
| 312 | ui->pinLabel->clear(); |
| 313 | |
| 314 | switch (state) { |
| 315 | case Account::ExportOnRingStatus::SUCCESS: |
| 316 | { |
| 317 | ui->pinLabel->setText(pin); |
Anthony Léonard | 3937499 | 2016-10-21 13:39:55 -0400 | [diff] [blame] | 318 | ui->pinLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); |
Edric Milaret | 5746784 | 2016-08-30 13:06:11 -0400 | [diff] [blame] | 319 | break; |
| 320 | } |
| 321 | case Account::ExportOnRingStatus::NETWORK_ERROR: |
| 322 | { |
| 323 | ui->pinLabel->setText(tr("Network Error. Please try again later.")); |
| 324 | break; |
| 325 | } |
| 326 | case Account::ExportOnRingStatus::WRONG_PASSWORD: |
| 327 | ui->pinLabel->setText(tr("Wrong password.")); |
| 328 | break; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | void |
| 333 | AccountDetails::on_exportEndedOkButton_clicked() |
| 334 | { |
| 335 | ui->devicesStackedWidget->setCurrentIndex(0); |
| 336 | } |
| 337 | |
| 338 | void |
| 339 | AccountDetails::on_cancelAddButton_clicked() |
| 340 | { |
| 341 | ui->devicesStackedWidget->setCurrentIndex(0); |
| 342 | } |
Anthony Léonard | 59db8ce | 2016-10-19 10:54:11 -0400 | [diff] [blame] | 343 | |
| 344 | void AccountDetails::on_devicesStackedWidget_currentChanged(int pageNum) |
| 345 | { |
| 346 | // We clear the password textEdit each time we leave its page |
| 347 | if (pageNum != ui->devicesStackedWidget->indexOf(ui->passwordAskingPage)) |
| 348 | ui->passwordArchiveEdit->clear(); |
| 349 | } |
Anthony Léonard | aa90e1a | 2016-10-12 11:24:17 -0400 | [diff] [blame] | 350 | |
| 351 | void AccountDetails::on_registerButton_clicked() |
| 352 | { |
| 353 | ui->registerButton->setEnabled(false); |
| 354 | ui->registerButton->setText(tr("Registering... It may take some time")); |
| 355 | bool regSuccess = currentAccount_->registerName(ui->lrcfg_password->text(), ui->lrcfg_registeredName->text()); |
| 356 | if (!regSuccess) { |
| 357 | QMessageBox::warning(this, "Username not registered", "Username registration failed, try again later."); |
| 358 | ui->registerButton->setEnabled(true); |
| 359 | ui->registerButton->setText(tr("Register on blockchain")); |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | connect(currentAccount_, SIGNAL(nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString)), |
| 364 | this, SLOT(handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString))); |
| 365 | } |
| 366 | |
| 367 | |
| 368 | void AccountDetails::handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus status, const QString& name) |
| 369 | { |
| 370 | disconnect(currentAccount_, SIGNAL(nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString)), |
| 371 | this, SLOT(handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString))); |
| 372 | switch(status) { |
| 373 | case NameDirectory::RegisterNameStatus::ALREADY_TAKEN: |
| 374 | QMessageBox::warning(this, "Username not registered", "This username is already taken, try another one."); |
| 375 | ui->registerButton->setEnabled(true); |
| 376 | ui->registerButton->setText(tr("Register on blockchain")); |
| 377 | break; |
| 378 | case NameDirectory::RegisterNameStatus::INVALID_NAME: |
| 379 | QMessageBox::warning(this, "Username not registered", "This username is invalid, try another one."); |
| 380 | ui->registerButton->setEnabled(true); |
| 381 | ui->registerButton->setText(tr("Register on blockchain")); |
| 382 | break; |
| 383 | case NameDirectory::RegisterNameStatus::WRONG_PASSWORD: |
| 384 | QMessageBox::warning(this, "Username not registered", "Wrong password, try again."); |
| 385 | ui->registerButton->setEnabled(true); |
| 386 | ui->registerButton->setText(tr("Register on blockchain")); |
| 387 | break; |
| 388 | case NameDirectory::RegisterNameStatus::NETWORK_ERROR: |
| 389 | QMessageBox::warning(this, "Username not registered", "Network error. Try again later."); |
| 390 | ui->registerButton->setEnabled(true); |
| 391 | ui->registerButton->setText(tr("Register on blockchain")); |
| 392 | break; |
| 393 | case NameDirectory::RegisterNameStatus::SUCCESS: |
| 394 | ui->lrcfg_registeredName->setReadOnly(true); |
| 395 | ui->registerButton->hide(); |
| 396 | QMessageBox::information(this, "Username registered", name + " is registered, you can now share this name."); |
| 397 | break; |
| 398 | } |
| 399 | |
| 400 | } |