blob: 9622ddee2c002148ae5d66d6b746c45c2a05c7b2 [file] [log] [blame]
Edric Milaret627500d2015-03-27 16:41:40 -04001/***************************************************************************
Nicolas Jager74fe46f2016-02-29 14:55:09 -05002 * Copyright (C) 2015-2016 by Savoir-faire Linux *
Edric Milaret627500d2015-03-27 16:41:40 -04003 * 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 Milaret3e6aefe2015-06-05 16:07:26 -040023#include <QFileDialog>
24#include <QPushButton>
Edric Milaret627500d2015-03-27 16:41:40 -040025
Edric Milaret627500d2015-03-27 16:41:40 -040026#include "accountdetails.h"
Edric Milarete82782e2016-03-21 12:14:17 -040027#include "codecmodel.h"
Edric Milaret3e6aefe2015-06-05 16:07:26 -040028#include "protocolmodel.h"
29#include "certificate.h"
30#include "ciphermodel.h"
Edric Milaretb1b00ce2016-02-03 14:10:05 -050031#include "ringtonemodel.h"
Edric Milaret627500d2015-03-27 16:41:40 -040032
33AccountDetails::AccountDetails(QWidget *parent) :
34 QWidget(parent),
35 ui(new Ui::AccountDetails),
36 codecModel_(nullptr),
Edric Milaret2d03da42015-07-15 15:36:43 -040037 currentAccount_(nullptr)
Edric Milaret627500d2015-03-27 16:41:40 -040038{
39 ui->setupUi(this);
40
Edric Milaretc9d3e412015-08-11 15:43:04 -040041 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
42
Nicolas Jager584a80e2016-03-18 16:10:00 -040043 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 Milaretdda49b62016-02-05 14:27:38 -050046
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 Jagere6384052016-03-10 13:13:24 -050060
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 Milaret627500d2015-03-27 16:41:40 -040085}
86
87AccountDetails::~AccountDetails()
88{
89 delete ui;
90}
91
92void
Edric Milaret627500d2015-03-27 16:41:40 -040093AccountDetails::setAccount(Account* currentAccount) {
94
Edric Milaret3e6aefe2015-06-05 16:07:26 -040095 if (currentAccount_) {
Edric Milaretdda49b62016-02-05 14:27:38 -050096 stopRingtone();
97 save();
Edric Milaret3e6aefe2015-06-05 16:07:26 -040098 }
99
Edric Milaret627500d2015-03-27 16:41:40 -0400100 currentAccount_ = currentAccount;
101
Edric Milareted0b2802015-10-01 15:10:02 -0400102 ui->lrcfg_username->setReadOnly(currentAccount_->protocol() == Account::Protocol::RING);
103
Edric Milaret627500d2015-03-27 16:41:40 -0400104 codecModel_ = currentAccount->codecModel();
Edric Milarete5313852015-11-09 13:06:00 -0500105 ui->audioCodecView->setModel(codecModel_->audioCodecs());
106 ui->videoCodecView->setModel(codecModel_->videoCodecs());
107 connect(ui->audioCodecView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
108 this, SLOT(audioCodecSelectionChanged(QItemSelection,QItemSelection)));
109 connect(ui->videoCodecView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
110 this, SLOT(videoCodecSelectionChanged(QItemSelection,QItemSelection)));
Edric Milaret627500d2015-03-27 16:41:40 -0400111
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400112 ui->typeValueLabel->setText(currentAccount_->protocolModel()->
113 selectionModel()->currentIndex().data().value<QString>());
Edric Milaret627500d2015-03-27 16:41:40 -0400114
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400115 ui->publishGroup->disconnect();
Edric Milaret627500d2015-03-27 16:41:40 -0400116
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400117 if (currentAccount_->isPublishedSameAsLocal())
118 ui->puslishedSameAsLocalRadio->setChecked(true);
119 else
120 ui->customPublishedRadio->setChecked(true);
121
122 ui->publishGroup->setId(ui->puslishedSameAsLocalRadio, 1);
123 ui->publishGroup->setId(ui->customPublishedRadio, 0);
124 ui->lrcfg_publishedAddress->setEnabled(!currentAccount_->isPublishedSameAsLocal());
125 ui->lrcfg_publishedPort->setEnabled(!currentAccount_->isPublishedSameAsLocal());
126
Nicolas Jagere6384052016-03-10 13:13:24 -0500127 connect(ui->publishGroup,
128 static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked),
129 [=](int id) {
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400130 currentAccount_->setPublishedSameAsLocal(static_cast<bool>(id));
131 });
132
133 switch (currentAccount_->DTMFType()) {
134 case DtmfType::OverRtp:
135 ui->rtpRadio->setChecked(true);
Edric Milaret627500d2015-03-27 16:41:40 -0400136 break;
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400137 case DtmfType::OverSip:
138 ui->sipRadio->setChecked(true);
Edric Milaret627500d2015-03-27 16:41:40 -0400139 break;
140 }
141
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400142 ui->dtmfGroup->disconnect();
143 ui->dtmfGroup->setId(ui->rtpRadio, DtmfType::OverRtp);
144 ui->dtmfGroup->setId(ui->sipRadio, DtmfType::OverSip);
Edric Milaret627500d2015-03-27 16:41:40 -0400145
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400146 connect(ui->dtmfGroup, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked),
Nicolas Jagere6384052016-03-10 13:13:24 -0500147 [=](int id){ currentAccount_->setDTMFType(static_cast<DtmfType>(id)); });
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400148
149 if (currentAccount_->tlsCaListCertificate())
Edric Milaret4f0b02c2015-08-14 11:40:58 -0400150 ui->lrcfg_tlsCaListCertificate->setText(currentAccount_->tlsCaListCertificate()->path());
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400151 if (currentAccount_->tlsCertificate())
Edric Milaret4f0b02c2015-08-14 11:40:58 -0400152 ui->lrcfg_tlsCertificate->setText(currentAccount_->tlsCertificate()->path());
153 if (not currentAccount_->tlsPrivateKey().isEmpty())
154 ui->lrcfg_tlsPrivateKeyCertificate->setText(currentAccount_->tlsPrivateKey());
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400155
Edric Milaret36587362016-02-04 12:30:52 -0500156#ifdef Q_OS_WIN
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400157 certMap_[ui->lrcfg_tlsCaListCertificate->objectName()] = &currentAccount_->setTlsCaListCertificate;
158 certMap_[ui->lrcfg_tlsCertificate->objectName()] = &currentAccount_->setTlsCertificate;
Edric Milaret4f0b02c2015-08-14 11:40:58 -0400159 certMap_[ui->lrcfg_tlsPrivateKeyCertificate->objectName()] = &currentAccount_->setTlsPrivateKey;
Edric Milaretb37aa1f2015-07-09 16:39:04 -0400160#endif
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400161
162 ui->srtpEnabled->disconnect();
163 connect(ui->srtpEnabled, &QCheckBox::toggled, [=](bool checked) {
164 currentAccount_->setSrtpEnabled(checked);
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400165 });
166
167 ui->srtpEnabled->setChecked(currentAccount_->isSrtpEnabled());
168
169 if (currentAccount_->cipherModel()->useDefault())
Nicolas Jagere6384052016-03-10 13:13:24 -0500170 ui->defaultCipherCheckBox->setChecked(true);
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400171 else
Nicolas Jagere6384052016-03-10 13:13:24 -0500172 ui->defaultCipherCheckBox->setChecked(false);
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400173
174 ui->cipherListView->setModel(currentAccount_->cipherModel());
Edric Milaretb1b00ce2016-02-03 14:10:05 -0500175
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 Jagere6384052016-03-10 13:13:24 -0500180
181 auto accountProtocol = currentAccount_->protocol();
182 if (accountProtocol == Account::Protocol::RING) {
183 ui->medStreaEncry->setVisible(false);
184 ui->lrcfg_tlsEnabled->setVisible(false);
185 } else if (accountProtocol == Account::Protocol::SIP) {
186 ui->medStreaEncry->setVisible(true);
187 ui->lrcfg_tlsEnabled->setVisible(true);
188 }
189
190 if (ui->lrcfg_tlsEnabled->checkState() == Qt::Checked) {
191 ui->negoEncry_1->setVisible(true);
192 ui->negoEncry_2->setVisible(true);
193 ui->defaultCipherCheckBox->setVisible(currentAccount_->protocol() != Account::Protocol::RING);
194 } else {
195 ui->negoEncry_1->setVisible(false);
196 ui->negoEncry_2->setVisible(false);
197 ui->defaultCipherCheckBox->setVisible(false);
198 ui->cipherListView->setVisible(false);
199 }
200
201 if (ui->defaultCipherCheckBox->checkState() == Qt::Checked)
202 ui->cipherListView->setVisible(false);
203 else
204 ui->cipherListView->setVisible(true);
Edric Milaret627500d2015-03-27 16:41:40 -0400205}
206
207void
Edric Milarete5313852015-11-09 13:06:00 -0500208AccountDetails::on_upAudioButton_clicked() {
Edric Milaret627500d2015-03-27 16:41:40 -0400209 codecModel_->moveUp();
Edric Milaret627500d2015-03-27 16:41:40 -0400210}
211
212void
Edric Milarete5313852015-11-09 13:06:00 -0500213AccountDetails::on_downAudioButton_clicked() {
Edric Milaret627500d2015-03-27 16:41:40 -0400214 codecModel_->moveDown();
Edric Milaret627500d2015-03-27 16:41:40 -0400215}
216
217void
Edric Milarete5313852015-11-09 13:06:00 -0500218AccountDetails::on_upVideoButton_clicked() {
Edric Milaret627500d2015-03-27 16:41:40 -0400219 codecModel_->moveUp();
Edric Milaret627500d2015-03-27 16:41:40 -0400220}
221
222void
Edric Milarete5313852015-11-09 13:06:00 -0500223AccountDetails::on_downVideoButton_clicked() {
Edric Milaret627500d2015-03-27 16:41:40 -0400224 codecModel_->moveDown();
Edric Milaret627500d2015-03-27 16:41:40 -0400225}
226
227void
228AccountDetails::save() {
Edric Milaret2d03da42015-07-15 15:36:43 -0400229 codecModel_->performAction(CodecModel::EditAction::SAVE);
Edric Milaret627500d2015-03-27 16:41:40 -0400230}
231
232void
Edric Milarete5313852015-11-09 13:06:00 -0500233AccountDetails::onCertButtonClicked() {
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400234 QString fileName = QFileDialog::getOpenFileName(this, tr("Choose File"),
Nicolas Jagere6384052016-03-10 13:13:24 -0500235 "",
236 tr("Files (*)"));
Edric Milaret3e6aefe2015-06-05 16:07:26 -0400237
238 auto sender = QObject::sender();
239
240 (currentAccount_->*certMap_[sender->objectName()])(fileName);
Edric Milaret9f6b5192016-02-02 15:14:27 -0500241 if (not fileName.isEmpty())
242 static_cast<QPushButton*>(sender)->setText(fileName);
Edric Milarete6538792015-05-08 11:51:01 -0400243}
Edric Milarete5313852015-11-09 13:06:00 -0500244
245void
246AccountDetails::audioCodecSelectionChanged(const QItemSelection& selected,
247 const QItemSelection& deselected) {
248 Q_UNUSED(deselected)
249 if (not codecModel_ || selected.empty())
250 return;
251 auto idx = codecModel_->audioCodecs()->mapToSource(selected.indexes().at(0));
252 codecModel_->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
253}
254
255void
256AccountDetails::videoCodecSelectionChanged(const QItemSelection& selected,
257 const QItemSelection& deselected) {
258 Q_UNUSED(deselected)
259 if (not codecModel_ || selected.empty())
260 return;
261 auto idx = codecModel_->videoCodecs()->mapToSource(selected.indexes().at(0));
262 codecModel_->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
263}
Edric Milaretb1b00ce2016-02-03 14:10:05 -0500264
265void
266AccountDetails::ringtonesBoxCurrentIndexChanged(int index)
267{
268 RingtoneModel::instance().selectionModel(currentAccount_)->setCurrentIndex(
269 RingtoneModel::instance().index(index, 0), QItemSelectionModel::ClearAndSelect);
270}
271
272void
273AccountDetails::on_playButton_clicked()
274{
275 RingtoneModel::instance().play(RingtoneModel::instance().index(
276 ui->ringtonesBox->currentIndex(), 0));
277}
Edric Milaretdda49b62016-02-05 14:27:38 -0500278
279void
280AccountDetails::stopRingtone() {
281 if (not currentAccount_)
282 return;
283 auto idx = RingtoneModel::instance().selectionModel(currentAccount_)->currentIndex();
284 if (RingtoneModel::instance().isPlaying())
285 RingtoneModel::instance().play(idx);
286}
Nicolas Jager74fe46f2016-02-29 14:55:09 -0500287
288QPushButton*
289AccountDetails::getDeleteAccountButton()
290{
291 return ui->deleteAccountButton;
292}
293