Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 1 | /*************************************************************************** |
Sébastien Blin | 68abac9 | 2019-01-02 17:41:31 -0500 | [diff] [blame] | 2 | * Copyright (C) 2019-2019 by Savoir-faire Linux * |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 3 | * Author: Isa Nanic <isa.nanic@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 | #include "direct.h" |
| 19 | #include <QFileDialog> |
| 20 | |
| 21 | #include "lrcinstance.h" |
| 22 | #include "api/newcodecmodel.h" |
| 23 | |
| 24 | #include "advancedsettingswidget.h" |
| 25 | #include "ui_advancedsettingswidget.h" |
| 26 | |
| 27 | AdvancedSettingsWidget::AdvancedSettingsWidget(QWidget* parent) |
| 28 | :QWidget(parent), |
| 29 | ui(new Ui::AdvancedSettingsWidget) |
| 30 | { |
| 31 | ui->setupUi(this); |
| 32 | |
| 33 | updateAdvancedSettings(); |
| 34 | /////////////////////////////////////////////////////////////////////////////// |
| 35 | // call settings |
Isa Nanic | 100368f | 2018-12-11 16:43:01 -0500 | [diff] [blame] | 36 | connect(ui->checkBoxUntrusted, &QAbstractButton::clicked, this, &AdvancedSettingsWidget::setCallsUntrusted); |
| 37 | connect(ui->checkBoxCustomRingtone, &QAbstractButton::clicked, this, &AdvancedSettingsWidget::setEnableRingtone); |
| 38 | connect(ui->checkBoxAutoAnswer, &QAbstractButton::clicked, this, &AdvancedSettingsWidget::setAutoAnswerCalls); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 39 | connect(ui->btnRingtone, &QPushButton::clicked, this, &AdvancedSettingsWidget::openFileCustomRingtone); |
Isa Nanic | 100368f | 2018-12-11 16:43:01 -0500 | [diff] [blame] | 40 | connect(ui->checkBoxCustomRingtone, &QAbstractButton::clicked, [this](int state) { ui->btnRingtone->setEnabled((bool)state); }); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 41 | |
| 42 | // name server |
| 43 | connect(ui->lineEditNameServer, &QLineEdit::textChanged, this, &AdvancedSettingsWidget::setNameServer); |
| 44 | |
| 45 | // openDHT config |
Isa Nanic | 100368f | 2018-12-11 16:43:01 -0500 | [diff] [blame] | 46 | connect(ui->checkBoxEnableProxy, &QAbstractButton::clicked, this, &AdvancedSettingsWidget::setEnableProxy); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 47 | |
| 48 | connect(ui->lineEditProxy, &QLineEdit::textChanged, this, &AdvancedSettingsWidget::setProxyAddress); |
| 49 | connect(ui->lineEditBootstrap, &QLineEdit::textChanged, this, &AdvancedSettingsWidget::setBootstrapAddress); |
| 50 | |
| 51 | // security |
| 52 | connect(ui->btnCACert, &QPushButton::clicked, this, &AdvancedSettingsWidget::openFileCACert); |
| 53 | connect(ui->btnUserCert, &QPushButton::clicked, this, &AdvancedSettingsWidget::openFileUserCert); |
| 54 | connect(ui->btnPrivateKey, &QPushButton::clicked, this, &AdvancedSettingsWidget::openFilePrivateKey); |
| 55 | |
| 56 | // connectivity |
Isa Nanic | 100368f | 2018-12-11 16:43:01 -0500 | [diff] [blame] | 57 | connect(ui->checkBoxUPnP, &QAbstractButton::clicked, this, &AdvancedSettingsWidget::setUseUPnP); |
| 58 | connect(ui->checkBoxTurnEnable, &QAbstractButton::clicked, this, &AdvancedSettingsWidget::setUseTURN); |
| 59 | connect(ui->checkBoxSTUNEnable, &QAbstractButton::clicked, this, &AdvancedSettingsWidget::setUseSTUN); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 60 | |
| 61 | connect(ui->lineEditTurnAddress, &QLineEdit::textChanged, this, &AdvancedSettingsWidget::setTURNAddress); |
| 62 | connect(ui->lineEditTurnUsername, &QLineEdit::textChanged, this, &AdvancedSettingsWidget::setTURNUsername); |
| 63 | connect(ui->lineEditTurnPsswd, &QLineEdit::textChanged, this, &AdvancedSettingsWidget::setTURNPsswd); |
| 64 | connect(ui->lineEditSTUNAddress, &QLineEdit::textChanged, this, &AdvancedSettingsWidget::setSTUNAddress); |
| 65 | |
| 66 | // codecs |
| 67 | connect(ui->audioListWidget, &QListWidget::itemChanged, this, &AdvancedSettingsWidget::audioCodecsStateChange); |
| 68 | connect(ui->videoListWidget, &QListWidget::itemChanged, this, &AdvancedSettingsWidget::videoCodecsStateChange); |
| 69 | |
Isa Nanic | 100368f | 2018-12-11 16:43:01 -0500 | [diff] [blame] | 70 | connect(ui->videoCheckBox, &QAbstractButton::clicked, this, &AdvancedSettingsWidget::setVideoState); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 71 | |
| 72 | // codec priority setting |
| 73 | connect(ui->audioDownPushButton, &QPushButton::clicked, this, &AdvancedSettingsWidget::decreaseAudioCodecPriority); |
| 74 | connect(ui->audioUpPushButton, &QPushButton::clicked, this, &AdvancedSettingsWidget::increaseAudioCodecPriority); |
| 75 | |
| 76 | connect(ui->videoDownPushButton, &QPushButton::clicked, this, &AdvancedSettingsWidget::decreaseVideoCodecPriority); |
| 77 | connect(ui->videoUpPushButton, &QPushButton::clicked, this, &AdvancedSettingsWidget::increaseVideoCodecPriority); |
| 78 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 79 | /////////////////////////////////////////////////////////////////////////////// |
| 80 | ui->btnRingtone->setEnabled(LRCInstance::getCurrAccConfig().Ringtone.ringtoneEnabled); |
Andreas Traczyk | 00febba | 2019-01-06 22:09:23 -0500 | [diff] [blame] | 81 | ui->btnRingtone->setText(QFileInfo(QString::fromStdString(LRCInstance::getCurrAccConfig().Ringtone.ringtonePath)).fileName()); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 82 | ui->lineEditProxy->setEnabled(LRCInstance::getCurrAccConfig().proxyEnabled); |
| 83 | ui->lineEditSTUNAddress->setEnabled(LRCInstance::getCurrAccConfig().STUN.enable); |
| 84 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | AdvancedSettingsWidget::~AdvancedSettingsWidget() |
| 88 | { |
| 89 | delete ui; |
| 90 | } |
| 91 | |
| 92 | void |
| 93 | AdvancedSettingsWidget::updateAdvancedSettings() |
| 94 | { |
| 95 | auto config = LRCInstance::getCurrAccConfig(); |
| 96 | //Call Settings |
| 97 | ui->checkBoxUntrusted->setChecked(config.allowIncoming); |
| 98 | ui->checkBoxAutoAnswer->setChecked(config.autoAnswer); |
| 99 | ui->checkBoxCustomRingtone->setChecked(config.Ringtone.ringtoneEnabled); |
| 100 | |
| 101 | // Name Server |
| 102 | ui->lineEditNameServer->setText(QString::fromStdString(config.RingNS.uri)); |
| 103 | |
| 104 | //OpenDHT Config |
| 105 | ui->checkBoxEnableProxy->setChecked(config.proxyEnabled); |
| 106 | ui->lineEditProxy->setText(QString::fromStdString(config.proxyServer)); |
| 107 | ui->lineEditBootstrap->setText(QString::fromStdString(config.hostname)); |
| 108 | |
| 109 | // Security |
Andreas Traczyk | 00febba | 2019-01-06 22:09:23 -0500 | [diff] [blame] | 110 | ui->btnCACert->setText(QFileInfo(QString::fromStdString(LRCInstance::getCurrAccConfig().TLS.certificateListFile)).fileName()); |
| 111 | ui->btnUserCert->setText(QFileInfo(QString::fromStdString(LRCInstance::getCurrAccConfig().TLS.certificateFile)).fileName()); |
| 112 | ui->btnPrivateKey->setText(QFileInfo(QString::fromStdString(LRCInstance::getCurrAccConfig().TLS.privateKeyFile)).fileName()); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 113 | |
| 114 | // Connectivity |
| 115 | ui->checkBoxUPnP->setChecked(config.upnpEnabled); |
| 116 | ui->checkBoxTurnEnable->setChecked(config.TURN.enable); |
| 117 | ui->lineEditTurnAddress->setText(QString::fromStdString(config.TURN.server)); |
| 118 | ui->lineEditTurnUsername->setText(QString::fromStdString(config.TURN.username)); |
| 119 | ui->lineEditTurnPsswd->setText(QString::fromStdString(config.TURN.password)); |
| 120 | ui->checkBoxSTUNEnable->setChecked(config.STUN.enable); |
| 121 | ui->lineEditSTUNAddress->setText(QString::fromStdString(config.STUN.server)); |
| 122 | |
| 123 | // codecs |
| 124 | ui->videoCheckBox->setChecked(config.Video.videoEnabled); |
| 125 | updateAudioCodecs(); |
| 126 | updateVideoCodecs(); |
| 127 | } |
| 128 | |
| 129 | // call settings |
| 130 | void |
| 131 | AdvancedSettingsWidget::setCallsUntrusted(bool state) |
| 132 | { |
| 133 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 134 | confProps.allowIncoming = state; |
| 135 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 136 | } |
| 137 | void |
| 138 | AdvancedSettingsWidget::setAutoAnswerCalls(bool state) |
| 139 | { |
| 140 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 141 | confProps.autoAnswer = state; |
| 142 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 143 | } |
| 144 | void |
| 145 | AdvancedSettingsWidget::setEnableRingtone(bool state) |
| 146 | { |
| 147 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 148 | confProps.Ringtone.ringtoneEnabled = state; |
| 149 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 150 | } |
| 151 | |
| 152 | void |
| 153 | AdvancedSettingsWidget::openFileCustomRingtone() |
| 154 | { |
| 155 | QString fileUrl; |
Andreas Traczyk | e83f788 | 2019-01-07 18:17:07 -0500 | [diff] [blame] | 156 | auto oldPath = QString::fromStdString(LRCInstance::getCurrAccConfig().Ringtone.ringtonePath); |
| 157 | auto openPath = oldPath.isEmpty() ? QDir::currentPath() + QString("/ringtones/") : QFileInfo(oldPath).absolutePath(); |
Andreas Traczyk | 7d5aa7c | 2019-01-08 19:11:05 -0500 | [diff] [blame^] | 158 | fileUrl = QFileDialog::getOpenFileName(this, QString("Select a new ringtone"), openPath, tr("Audio Files (*.wav, *.ogg, *.opus, *.mp3)")); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 159 | if (!fileUrl.isEmpty()) { |
| 160 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 161 | confProps.Ringtone.ringtonePath = fileUrl.toStdString(); |
| 162 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
Andreas Traczyk | 13b0272 | 2019-01-07 17:58:51 -0500 | [diff] [blame] | 163 | ui->btnRingtone->setText(QFileInfo(fileUrl).fileName()); |
Andreas Traczyk | e83f788 | 2019-01-07 18:17:07 -0500 | [diff] [blame] | 164 | } else if (oldPath.isEmpty()) { |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 165 | ui->btnRingtone->setText(tr("Add a custom ringtone")); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | // name server |
| 170 | void |
| 171 | AdvancedSettingsWidget::setNameServer(const QString& name) |
| 172 | { |
| 173 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 174 | confProps.RingNS.uri = name.toStdString(); |
| 175 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 176 | } |
| 177 | |
| 178 | // openDHT config |
| 179 | void |
| 180 | AdvancedSettingsWidget::setEnableProxy(bool state) |
| 181 | { |
| 182 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 183 | confProps.proxyEnabled = state; |
| 184 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 185 | |
| 186 | state ? ui->lineEditProxy->setEnabled(true) : ui->lineEditProxy->setEnabled(false); |
| 187 | } |
| 188 | void |
| 189 | AdvancedSettingsWidget::setProxyAddress(const QString& name) |
| 190 | { |
| 191 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 192 | confProps.proxyServer = name.toStdString(); |
| 193 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 194 | } |
| 195 | void |
| 196 | AdvancedSettingsWidget::setBootstrapAddress(const QString& name) |
| 197 | { |
| 198 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 199 | confProps.hostname = name.toStdString(); |
| 200 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 201 | } |
| 202 | |
| 203 | // security |
| 204 | |
| 205 | // connectivity |
| 206 | void |
| 207 | AdvancedSettingsWidget::setUseUPnP(bool state) |
| 208 | { |
| 209 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 210 | confProps.upnpEnabled = state; |
| 211 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 212 | } |
| 213 | void |
| 214 | AdvancedSettingsWidget::setUseTURN(bool state) |
| 215 | { |
| 216 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 217 | confProps.TURN.enable = state; |
| 218 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 219 | } |
| 220 | void |
| 221 | AdvancedSettingsWidget::setUseSTUN(bool state) |
| 222 | { |
| 223 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 224 | confProps.STUN.enable = state; |
| 225 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 226 | |
| 227 | state ? ui->lineEditSTUNAddress->setEnabled(true) : ui->lineEditSTUNAddress->setEnabled(false); |
| 228 | } |
| 229 | |
| 230 | void |
| 231 | AdvancedSettingsWidget::setTURNAddress(const QString& name) |
| 232 | { |
| 233 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 234 | confProps.TURN.server = name.toStdString(); |
| 235 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 236 | } |
| 237 | void |
| 238 | AdvancedSettingsWidget::setTURNUsername(const QString& name) |
| 239 | { |
| 240 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 241 | confProps.TURN.username = name.toStdString(); |
| 242 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 243 | } |
| 244 | void |
| 245 | AdvancedSettingsWidget::setTURNPsswd(const QString& name) |
| 246 | { |
| 247 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 248 | confProps.TURN.password = name.toStdString(); |
| 249 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 250 | } |
| 251 | void |
| 252 | AdvancedSettingsWidget::setSTUNAddress(const QString& name) |
| 253 | { |
| 254 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 255 | confProps.STUN.server = name.toStdString(); |
| 256 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 257 | } |
| 258 | |
| 259 | void |
| 260 | AdvancedSettingsWidget::openFileCACert() |
| 261 | { |
| 262 | QString fileUrl; |
| 263 | fileUrl = QFileDialog::getOpenFileName(this, QString("Select a CA certificate"), QDir::homePath() |
| 264 | + QString("/.local/share/ring/") + QString::fromStdString(LRCInstance::getCurrentAccountInfo().id)); |
| 265 | if (!fileUrl.isEmpty()) { |
| 266 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 267 | confProps.TLS.certificateListFile = fileUrl.toStdString(); |
| 268 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 269 | } |
Andreas Traczyk | 00febba | 2019-01-06 22:09:23 -0500 | [diff] [blame] | 270 | ui->btnCACert->setText(QFileInfo(QString::fromStdString(LRCInstance::getCurrAccConfig().TLS.certificateListFile)).fileName()); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | void |
| 274 | AdvancedSettingsWidget::openFileUserCert() |
| 275 | { |
| 276 | QString fileUrl; |
| 277 | fileUrl = QFileDialog::getOpenFileName(this, QString("Select a user certificate"), QDir::homePath() |
| 278 | + QString("/.local/share/ring/") + QString::fromStdString(LRCInstance::getCurrentAccountInfo().id)); |
| 279 | if (!fileUrl.isEmpty()) { |
| 280 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 281 | confProps.TLS.certificateFile = fileUrl.toStdString(); |
| 282 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 283 | } |
Andreas Traczyk | 00febba | 2019-01-06 22:09:23 -0500 | [diff] [blame] | 284 | ui->btnUserCert->setText(QFileInfo(QString::fromStdString(LRCInstance::getCurrAccConfig().TLS.certificateFile)).fileName()); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | void |
| 288 | AdvancedSettingsWidget::openFilePrivateKey() |
| 289 | { |
| 290 | QString fileUrl; |
| 291 | fileUrl = QFileDialog::getOpenFileName(this, QString("Select a private key"), QDir::homePath() |
| 292 | + QString("/.local/share/ring/") + QString::fromStdString(LRCInstance::getCurrentAccountInfo().id)); |
| 293 | if (!fileUrl.isEmpty()) { |
| 294 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 295 | confProps.TLS.privateKeyFile = fileUrl.toStdString(); |
| 296 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 297 | } |
Andreas Traczyk | 00febba | 2019-01-06 22:09:23 -0500 | [diff] [blame] | 298 | ui->btnPrivateKey->setText(QFileInfo(QString::fromStdString(LRCInstance::getCurrAccConfig().TLS.privateKeyFile)).fileName()); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | void |
| 302 | AdvancedSettingsWidget::updateAudioCodecs() |
| 303 | { |
| 304 | ui->audioListWidget->clear(); |
| 305 | |
| 306 | auto audioCodecList = LRCInstance::getCurrentAccountInfo().codecModel->getAudioCodecs(); |
| 307 | int i = 0; |
| 308 | for (auto it = audioCodecList.begin(); it != audioCodecList.end(); ++it, ++i) { |
| 309 | QListWidgetItem* audioItem = new QListWidgetItem(ui->audioListWidget); |
| 310 | audioItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); |
| 311 | Qt::CheckState state; |
| 312 | it->enabled ? state = Qt::Checked : state = Qt::Unchecked; |
| 313 | audioItem->setCheckState(state); |
| 314 | audioItem->setData(Qt::DisplayRole, QString::fromStdString(it->name) + "\n" + QString::fromStdString(it->samplerate) |
| 315 | + " Hz"); |
| 316 | |
| 317 | ui->audioListWidget->addItem(audioItem); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | void |
| 322 | AdvancedSettingsWidget::updateVideoCodecs() |
| 323 | { |
| 324 | ui->videoListWidget->clear(); |
| 325 | |
| 326 | auto videoCodecList = LRCInstance::getCurrentAccountInfo().codecModel->getVideoCodecs(); |
| 327 | int i = 0; |
| 328 | |
| 329 | for (auto it = videoCodecList.begin(); it != videoCodecList.end(); ++it, ++i) { |
| 330 | if (it->name.length()) { // [temporary fix] |
| 331 | QListWidgetItem* videoItem = new QListWidgetItem(ui->videoListWidget); |
| 332 | videoItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); |
| 333 | Qt::CheckState state; |
| 334 | it->enabled ? state = Qt::Checked : state = Qt::Unchecked; |
| 335 | videoItem->setCheckState(state); |
| 336 | videoItem->setData(Qt::DisplayRole, QString::fromStdString(it->name) + "\n"); |
| 337 | |
| 338 | ui->audioListWidget->addItem(videoItem); |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | void |
| 344 | AdvancedSettingsWidget::audioCodecsStateChange(QListWidgetItem* item) |
| 345 | { |
| 346 | auto audioCodecList = LRCInstance::getCurrentAccountInfo().codecModel->getAudioCodecs(); |
| 347 | auto it = audioCodecList.begin(); |
| 348 | |
| 349 | std::advance(it, ui->audioListWidget->row(item)); |
| 350 | |
| 351 | LRCInstance::getCurrentAccountInfo().codecModel->enable(it->id, !(it->enabled)); |
| 352 | } |
| 353 | |
| 354 | void |
| 355 | AdvancedSettingsWidget::videoCodecsStateChange(QListWidgetItem* item) |
| 356 | { |
| 357 | auto videoCodecList = LRCInstance::getCurrentAccountInfo().codecModel->getVideoCodecs(); |
| 358 | auto it = videoCodecList.begin(); |
| 359 | |
| 360 | std::advance(it, ui->videoListWidget->row(item)); |
| 361 | |
| 362 | LRCInstance::getCurrentAccountInfo().codecModel->enable(it->id, !(it->enabled)); |
| 363 | } |
| 364 | |
| 365 | void |
| 366 | AdvancedSettingsWidget::decreaseAudioCodecPriority() |
| 367 | { |
| 368 | int selectedRow = ui->audioListWidget->row(ui->audioListWidget->selectedItems().at(0)); |
| 369 | auto audioCodecList = LRCInstance::getCurrentAccountInfo().codecModel->getAudioCodecs(); |
| 370 | auto it = audioCodecList.begin(); |
| 371 | |
| 372 | advance(it, selectedRow); |
| 373 | LRCInstance::getCurrentAccountInfo().codecModel->decreasePriority(it->id, false); |
| 374 | updateAudioCodecs(); |
| 375 | } |
| 376 | |
| 377 | void |
| 378 | AdvancedSettingsWidget::increaseAudioCodecPriority() |
| 379 | { |
| 380 | int selectedRow = ui->audioListWidget->row(ui->audioListWidget->selectedItems().at(0)); |
| 381 | auto audioCodecList = LRCInstance::getCurrentAccountInfo().codecModel->getAudioCodecs(); |
| 382 | auto it = audioCodecList.begin(); |
| 383 | |
| 384 | advance(it, selectedRow); |
| 385 | LRCInstance::getCurrentAccountInfo().codecModel->increasePriority(it->id, false); |
| 386 | updateAudioCodecs(); |
| 387 | } |
| 388 | |
| 389 | void |
| 390 | AdvancedSettingsWidget::decreaseVideoCodecPriority() |
| 391 | { |
| 392 | int selectedRow = ui->videoListWidget->row(ui->videoListWidget->selectedItems().at(0)); |
| 393 | auto videoCodecList = LRCInstance::getCurrentAccountInfo().codecModel->getVideoCodecs(); |
| 394 | auto it = videoCodecList.begin(); |
| 395 | |
| 396 | advance(it, selectedRow); |
| 397 | LRCInstance::getCurrentAccountInfo().codecModel->decreasePriority(it->id, true); |
| 398 | updateVideoCodecs(); |
| 399 | } |
| 400 | |
| 401 | void |
| 402 | AdvancedSettingsWidget::increaseVideoCodecPriority() |
| 403 | { |
| 404 | int selectedRow = ui->videoListWidget->row(ui->videoListWidget->selectedItems().at(0)); |
| 405 | auto videoCodecList = LRCInstance::getCurrentAccountInfo().codecModel->getVideoCodecs(); |
| 406 | auto it = videoCodecList.begin(); |
| 407 | |
| 408 | advance(it, selectedRow); |
| 409 | LRCInstance::getCurrentAccountInfo().codecModel->increasePriority(it->id, true); |
| 410 | updateVideoCodecs(); |
| 411 | } |
| 412 | |
| 413 | void |
| 414 | AdvancedSettingsWidget::setVideoState(int state) |
| 415 | { |
| 416 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 417 | confProps.Video.videoEnabled = (bool)state; |
| 418 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 419 | } |