blob: 654c6f404b566418e224bfbb1c057c02ac4615e3 [file] [log] [blame]
Isa Nanic6e4a39a2018-12-04 14:26:02 -05001/***************************************************************************
Sébastien Blin68abac92019-01-02 17:41:31 -05002 * Copyright (C) 2019-2019 by Savoir-faire Linux *
Isa Nanic6e4a39a2018-12-04 14:26:02 -05003 * 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
27AdvancedSettingsWidget::AdvancedSettingsWidget(QWidget* parent)
28 :QWidget(parent),
29 ui(new Ui::AdvancedSettingsWidget)
30{
31 ui->setupUi(this);
32
33 updateAdvancedSettings();
34///////////////////////////////////////////////////////////////////////////////
35 // call settings
Isa Nanic100368f2018-12-11 16:43:01 -050036 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 Nanic6e4a39a2018-12-04 14:26:02 -050039 connect(ui->btnRingtone, &QPushButton::clicked, this, &AdvancedSettingsWidget::openFileCustomRingtone);
Isa Nanic100368f2018-12-11 16:43:01 -050040 connect(ui->checkBoxCustomRingtone, &QAbstractButton::clicked, [this](int state) { ui->btnRingtone->setEnabled((bool)state); });
Isa Nanic6e4a39a2018-12-04 14:26:02 -050041
42 // name server
43 connect(ui->lineEditNameServer, &QLineEdit::textChanged, this, &AdvancedSettingsWidget::setNameServer);
44
45 // openDHT config
Isa Nanic100368f2018-12-11 16:43:01 -050046 connect(ui->checkBoxEnableProxy, &QAbstractButton::clicked, this, &AdvancedSettingsWidget::setEnableProxy);
Isa Nanic6e4a39a2018-12-04 14:26:02 -050047
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 Nanic100368f2018-12-11 16:43:01 -050057 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 Nanic6e4a39a2018-12-04 14:26:02 -050060
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 Nanic100368f2018-12-11 16:43:01 -050070 connect(ui->videoCheckBox, &QAbstractButton::clicked, this, &AdvancedSettingsWidget::setVideoState);
Isa Nanic6e4a39a2018-12-04 14:26:02 -050071
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 Nanic6e4a39a2018-12-04 14:26:02 -050079///////////////////////////////////////////////////////////////////////////////
80 ui->btnRingtone->setEnabled(LRCInstance::getCurrAccConfig().Ringtone.ringtoneEnabled);
Andreas Traczyk00febba2019-01-06 22:09:23 -050081 ui->btnRingtone->setText(QFileInfo(QString::fromStdString(LRCInstance::getCurrAccConfig().Ringtone.ringtonePath)).fileName());
Isa Nanic6e4a39a2018-12-04 14:26:02 -050082 ui->lineEditProxy->setEnabled(LRCInstance::getCurrAccConfig().proxyEnabled);
83 ui->lineEditSTUNAddress->setEnabled(LRCInstance::getCurrAccConfig().STUN.enable);
84
Isa Nanic6e4a39a2018-12-04 14:26:02 -050085}
86
87AdvancedSettingsWidget::~AdvancedSettingsWidget()
88{
89 delete ui;
90}
91
92void
93AdvancedSettingsWidget::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 Traczyk00febba2019-01-06 22:09:23 -0500110 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 Nanic6e4a39a2018-12-04 14:26:02 -0500113
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
130void
131AdvancedSettingsWidget::setCallsUntrusted(bool state)
132{
133 auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
134 confProps.allowIncoming = state;
135 LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
136}
137void
138AdvancedSettingsWidget::setAutoAnswerCalls(bool state)
139{
140 auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
141 confProps.autoAnswer = state;
142 LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
143}
144void
145AdvancedSettingsWidget::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
152void
153AdvancedSettingsWidget::openFileCustomRingtone()
154{
155 QString fileUrl;
Andreas Traczyke83f7882019-01-07 18:17:07 -0500156 auto oldPath = QString::fromStdString(LRCInstance::getCurrAccConfig().Ringtone.ringtonePath);
157 auto openPath = oldPath.isEmpty() ? QDir::currentPath() + QString("/ringtones/") : QFileInfo(oldPath).absolutePath();
Andreas Traczyk7d5aa7c2019-01-08 19:11:05 -0500158 fileUrl = QFileDialog::getOpenFileName(this, QString("Select a new ringtone"), openPath, tr("Audio Files (*.wav, *.ogg, *.opus, *.mp3)"));
Isa Nanic6e4a39a2018-12-04 14:26:02 -0500159 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 Traczyk13b02722019-01-07 17:58:51 -0500163 ui->btnRingtone->setText(QFileInfo(fileUrl).fileName());
Andreas Traczyke83f7882019-01-07 18:17:07 -0500164 } else if (oldPath.isEmpty()) {
Isa Nanic6e4a39a2018-12-04 14:26:02 -0500165 ui->btnRingtone->setText(tr("Add a custom ringtone"));
166 }
167}
168
169// name server
170void
171AdvancedSettingsWidget::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
179void
180AdvancedSettingsWidget::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}
188void
189AdvancedSettingsWidget::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}
195void
196AdvancedSettingsWidget::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
206void
207AdvancedSettingsWidget::setUseUPnP(bool state)
208{
209 auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
210 confProps.upnpEnabled = state;
211 LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
212}
213void
214AdvancedSettingsWidget::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}
220void
221AdvancedSettingsWidget::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
230void
231AdvancedSettingsWidget::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}
237void
238AdvancedSettingsWidget::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}
244void
245AdvancedSettingsWidget::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}
251void
252AdvancedSettingsWidget::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
259void
260AdvancedSettingsWidget::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 Traczyk00febba2019-01-06 22:09:23 -0500270 ui->btnCACert->setText(QFileInfo(QString::fromStdString(LRCInstance::getCurrAccConfig().TLS.certificateListFile)).fileName());
Isa Nanic6e4a39a2018-12-04 14:26:02 -0500271}
272
273void
274AdvancedSettingsWidget::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 Traczyk00febba2019-01-06 22:09:23 -0500284 ui->btnUserCert->setText(QFileInfo(QString::fromStdString(LRCInstance::getCurrAccConfig().TLS.certificateFile)).fileName());
Isa Nanic6e4a39a2018-12-04 14:26:02 -0500285}
286
287void
288AdvancedSettingsWidget::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 Traczyk00febba2019-01-06 22:09:23 -0500298 ui->btnPrivateKey->setText(QFileInfo(QString::fromStdString(LRCInstance::getCurrAccConfig().TLS.privateKeyFile)).fileName());
Isa Nanic6e4a39a2018-12-04 14:26:02 -0500299}
300
301void
302AdvancedSettingsWidget::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
321void
322AdvancedSettingsWidget::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
343void
344AdvancedSettingsWidget::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
354void
355AdvancedSettingsWidget::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
365void
366AdvancedSettingsWidget::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
377void
378AdvancedSettingsWidget::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
389void
390AdvancedSettingsWidget::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
401void
402AdvancedSettingsWidget::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
413void
414AdvancedSettingsWidget::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}