Commit 3e6aefed authored by Edric Milaret's avatar Edric Milaret Committed by gerrit2

settings : add advanced and security settings

Refs #75237

Change-Id: I0438729d872a17c14f88f2eb6c67fb2af913ed17
parent aa50336a
......@@ -41,7 +41,8 @@ SOURCES += main.cpp\
windowscontactbackend.cpp \
historydelegate.cpp \
contactdelegate.cpp \
selectareadialog.cpp
selectareadialog.cpp \
accountserializationadapter.cpp
HEADERS += mainwindow.h \
callwidget.h \
......@@ -58,7 +59,8 @@ HEADERS += mainwindow.h \
windowscontactbackend.h \
historydelegate.h \
contactdelegate.h \
selectareadialog.h
selectareadialog.h \
accountserializationadapter.h
FORMS += mainwindow.ui \
callwidget.ui \
......
......@@ -20,16 +20,20 @@
#include "ui_accountdetails.h"
#include <QSortFilterProxyModel>
#include <QFileDialog>
#include <QPushButton>
#include "accountmodel.h"
#include "account.h"
#include "accountdetails.h"
#include "audio/codecmodel.h"
#include "protocolmodel.h"
#include "certificate.h"
#include "ciphermodel.h"
AccountDetails::AccountDetails(QWidget *parent) :
QWidget(parent),
ui(new Ui::AccountDetails),
codecModel_(nullptr),
currentAccount_(nullptr),
codecModelModified(false)
{
ui->setupUi(this);
......@@ -48,20 +52,16 @@ AccountDetails::AccountDetails(QWidget *parent) :
ui->videoCodecView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->videoCodecView->setShowGrid(false);
ui->hashValue->setAlignment(Qt::AlignCenter);
ui->lrcfg_username->setAlignment(Qt::AlignCenter);
connect(ui->audioCodecView, SIGNAL(cellChanged(int,int)),
this, SLOT(audio_codec_checked(int, int)));
connect(ui->videoCodecView, SIGNAL(cellChanged(int,int)),
this, SLOT(video_codec_checked(int,int)));
connect(ui->videoEnabledCheckBox, SIGNAL(toggled(bool)),
this, SLOT(setVideoEnabled(bool)));
connect(ui->autoAnswerCheckBox, SIGNAL(toggled(bool)),
this, SLOT(setAutoAnswer(bool)));
connect(ui->aliasValue, SIGNAL(editingFinished()),
this, SLOT(aliasChanged()));
connect(ui->bootstrapLineEdit, SIGNAL(editingFinished()),
this, SLOT(bootstrapChanged()));
connect(ui->lrcfg_tlsCaListCertificate, SIGNAL(clicked(bool)), this, SLOT(onCertButtonClicked()));
connect(ui->lrcfg_tlsCertificate, SIGNAL(clicked(bool)), this, SLOT(onCertButtonClicked()));
connect(ui->lrcfg_tlsPrivateKeyCertificate, SIGNAL(clicked(bool)), this, SLOT(onCertButtonClicked()));
}
AccountDetails::~AccountDetails()
......@@ -144,6 +144,10 @@ AccountDetails::reloadCodec(CodecType type)
void
AccountDetails::setAccount(Account* currentAccount) {
if (currentAccount_) {
currentAccount_->performAction(Account::EditAction::SAVE);
}
currentAccount_ = currentAccount;
if (codecModel_ && codecModelModified)
......@@ -151,75 +155,77 @@ AccountDetails::setAccount(Account* currentAccount) {
codecModel_ = currentAccount->codecModel();
//FIX ME : Reorganize this in group
ui->hashValue->hide();
ui->hashLabel->hide();
ui->aliasValue->hide();
ui->aliasLabel->hide();
ui->bootstrapLabel->hide();
ui->bootstrapLineEdit->hide();
ui->hostnameLabel->hide();
ui->hostnameEdit->hide();
ui->usernameEdit->hide();
ui->usernameLabel->hide();
ui->passwordEdit->hide();
ui->passwordLabel->hide();
ui->proxyEdit->hide();
ui->proxyLabel->hide();
ui->voicemailLabel->hide();
ui->voicemailEdit->hide();
switch (currentAccount_->protocol()) {
case Account::Protocol::SIP:
if (currentAccount_ != AccountModel::instance()->ip2ip()) {
ui->typeValueLabel->setText("SIP");
ui->aliasValue->setText(currentAccount_->alias());
ui->hostnameEdit->setText(currentAccount_->hostname());
ui->usernameEdit->setText(currentAccount_->username());
ui->passwordEdit->setText(currentAccount_->password());
ui->proxyEdit->setText(currentAccount_->proxy());
ui->voicemailEdit->setText(currentAccount_->mailbox());
ui->aliasLabel->show();
ui->aliasValue->show();
ui->hostnameLabel->show();
ui->hostnameEdit->show();
ui->usernameEdit->show();
ui->usernameLabel->show();
ui->passwordEdit->show();
ui->passwordLabel->show();
ui->proxyEdit->show();
ui->proxyLabel->show();
ui->voicemailLabel->show();
ui->voicemailEdit->show();
} else {
ui->typeValueLabel->setText("IP2IP");
}
break;
case Account::Protocol::IAX:
ui->typeValueLabel->setText("IAX");
break;
case Account::Protocol::RING:
ui->typeValueLabel->setText("RING");
ui->aliasValue->setText(currentAccount_->alias());
ui->hashValue->setText(currentAccount_->username());
ui->bootstrapLineEdit->setText(currentAccount_->hostname());
ui->hashValue->show();
ui->hashLabel->show();
ui->aliasLabel->show();
ui->aliasValue->show();
ui->bootstrapLabel->show();
ui->bootstrapLineEdit->show();
ui->typeValueLabel->setText(currentAccount_->protocolModel()->
selectionModel()->currentIndex().data().value<QString>());
ui->publishGroup->disconnect();
if (currentAccount_->isPublishedSameAsLocal())
ui->puslishedSameAsLocalRadio->setChecked(true);
else
ui->customPublishedRadio->setChecked(true);
ui->publishGroup->setId(ui->puslishedSameAsLocalRadio, 1);
ui->publishGroup->setId(ui->customPublishedRadio, 0);
ui->lrcfg_publishedAddress->setEnabled(!currentAccount_->isPublishedSameAsLocal());
ui->lrcfg_publishedPort->setEnabled(!currentAccount_->isPublishedSameAsLocal());
connect(ui->publishGroup, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked),
[=](int id) {
currentAccount_->setPublishedSameAsLocal(static_cast<bool>(id));
});
switch (currentAccount_->DTMFType()) {
case DtmfType::OverRtp:
ui->rtpRadio->setChecked(true);
break;
default:
case DtmfType::OverSip:
ui->sipRadio->setChecked(true);
break;
}
reloadCodec();
ui->dtmfGroup->disconnect();
ui->dtmfGroup->setId(ui->rtpRadio, DtmfType::OverRtp);
ui->dtmfGroup->setId(ui->sipRadio, DtmfType::OverSip);
connect(ui->dtmfGroup, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked),
[=](int id){ currentAccount_->setDTMFType(static_cast<DtmfType>(id)); });
ui->keyExchangeModelCombo->setModel(currentAccount_->keyExchangeModel());
ui->tlsProtocoCombo->setModel(currentAccount_->tlsMethodModel());
ui->videoEnabledCheckBox->setChecked(currentAccount_->isVideoEnabled());
ui->autoAnswerCheckBox->setChecked(currentAccount_->isAutoAnswer());
ui->upnpCheckBox->setChecked(currentAccount_->isUpnpEnabled());
if (currentAccount_->tlsCaListCertificate())
ui->lrcfg_tlsCaListCertificate->setText(currentAccount_->tlsCaListCertificate()->path().fileName());
if (currentAccount_->tlsCertificate())
ui->lrcfg_tlsCertificate->setText(currentAccount_->tlsCertificate()->path().fileName());
if (currentAccount_->tlsPrivateKeyCertificate())
ui->lrcfg_tlsPrivateKeyCertificate->setText(currentAccount_->tlsPrivateKeyCertificate()->path().fileName());
certMap_[ui->lrcfg_tlsCaListCertificate->objectName()] = &currentAccount_->setTlsCaListCertificate;
certMap_[ui->lrcfg_tlsCertificate->objectName()] = &currentAccount_->setTlsCertificate;
certMap_[ui->lrcfg_tlsPrivateKeyCertificate->objectName()] = &currentAccount_->setTlsPrivateKeyCertificate;
ui->srtpEnabled->disconnect();
connect(ui->srtpEnabled, &QCheckBox::toggled, [=](bool checked) {
currentAccount_->setSrtpEnabled(checked);
ui->lrcfg_srtpRtpFallback->setEnabled(checked);
ui->keyExchangeModelCombo->setEnabled(checked);
});
ui->srtpEnabled->setChecked(currentAccount_->isSrtpEnabled());
if (currentAccount_->cipherModel()->useDefault())
ui->defaultCipherRadio->setChecked(true);
else
ui->customCipherRadio->setChecked(true);
connect(ui->defaultCipherRadio, &QRadioButton::toggled, [=](bool checked) {
currentAccount_->cipherModel()->setUseDefault(checked);
});
ui->cipherListView->setModel(currentAccount_->cipherModel());
reloadCodec();
}
void
......@@ -244,26 +250,6 @@ AccountDetails::video_codec_checked(int row, int column) {
codecModelModified = true;
}
void
AccountDetails::setVideoEnabled(bool enabled) {
currentAccount_->setVideoEnabled(enabled);
}
void
AccountDetails::setAutoAnswer(bool enabled) {
currentAccount_->setAutoAnswer(enabled);
}
void
AccountDetails::aliasChanged() {
currentAccount_->setAlias(ui->aliasValue->text());
}
void
AccountDetails::bootstrapChanged() {
currentAccount_->setHostname(ui->bootstrapLineEdit->text());
}
void
AccountDetails::on_upAudioButton_clicked()
{
......@@ -322,36 +308,12 @@ AccountDetails::save() {
codecModel_->save();
}
void
AccountDetails::on_hostnameEdit_editingFinished()
{
currentAccount_->setHostname(ui->hostnameEdit->text());
}
void
AccountDetails::on_usernameEdit_editingFinished()
{
currentAccount_->setUsername(ui->usernameEdit->text());
}
void
AccountDetails::on_passwordEdit_editingFinished()
{
currentAccount_->setPassword(ui->passwordEdit->text());
}
void
AccountDetails::on_proxyEdit_editingFinished()
{
currentAccount_->setProxy(ui->proxyEdit->text());
}
void
AccountDetails::on_voicemailEdit_editingFinished()
{
currentAccount_->setMailbox(ui->voicemailEdit->text());
}
void
AccountDetails::on_tabWidget_currentChanged(int index)
{
......@@ -362,7 +324,17 @@ AccountDetails::on_tabWidget_currentChanged(int index)
}
}
void AccountDetails::on_upnpCheckBox_clicked(bool checked)
void
AccountDetails::onCertButtonClicked()
{
currentAccount_->setUpnpEnabled(checked);
QString fileName = QFileDialog::getOpenFileName(this, tr("Choose File"),
"",
tr("Files (*)"));
auto sender = QObject::sender();
(currentAccount_->*certMap_[sender->objectName()])(fileName);
static_cast<QPushButton*>(sender)->setText(fileName);
}
......@@ -20,11 +20,13 @@
#define ACCOUNTDETAILS_H
#include <QWidget>
#include <QMap>
#include <QTableWidgetItem>
#include "accountmodel.h"
#include "audio/codecmodel.h"
#include "account.h"
namespace Ui {
class AccountDetails;
......@@ -53,27 +55,21 @@ private slots:
void on_downVideoButton_clicked();
void on_audioCodecView_itemSelectionChanged();
void on_videoCodecView_itemSelectionChanged();
void on_hostnameEdit_editingFinished();
void on_usernameEdit_editingFinished();
void on_passwordEdit_editingFinished();
void on_proxyEdit_editingFinished();
void on_voicemailEdit_editingFinished();
void on_tabWidget_currentChanged(int index);
void on_upnpCheckBox_clicked(bool checked);
private slots:
void audio_codec_checked(int row, int column);
void setVideoEnabled(bool enabled);
void video_codec_checked(int row, int column);
void setAutoAnswer(bool enabled);
void aliasChanged();
void bootstrapChanged();
void onCertButtonClicked();
private:
Ui::AccountDetails *ui;
CodecModel* codecModel_;
Account* currentAccount_;
bool codecModelModified;
typedef void (Account::*ACC_PTR)(const QString&);
QMap<QString, ACC_PTR > certMap_;
};
......
This diff is collapsed.
/***************************************************************************
* Copyright (C) 2015 by Savoir-Faire Linux *
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>*
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "accountserializationadapter.h"
#include <QtWidgets/QWidget>
#include <QtWidgets/QLayout>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QSpinBox>
#include <QtWidgets/QAbstractButton>
#include <account.h>
#include <accountmodel.h>
constexpr static const char LRC_CFG[] = "lrcfg_";
constexpr static const int LRC_CFG_LEN = 6 ;
struct ConnHolder {
QMetaObject::Connection c;
~ConnHolder();
};
Q_DECLARE_METATYPE(ConnHolder*);
ConnHolder::~ConnHolder()
{
QObject::disconnect(c);
}
static void avoidDuplicate(QWidget* w)
{
if (qvariant_cast<ConnHolder*>(w->property("lrcfgConn")))
delete qvariant_cast<ConnHolder*>(w->property("lrcfgConn"));
}
/**
* This check for some supported widgets and bind the widgets and property
*/
static void setupWidget(QWidget* w, Account* a, const QHash<QByteArray, int>& roles)
{
if (w->objectName().left(LRC_CFG_LEN) == LRC_CFG) {
const QByteArray prop = w->objectName().mid(LRC_CFG_LEN, 999).toLatin1();
if (roles.contains(prop)) {
const int role = roles[prop];
if (qobject_cast<QLineEdit*>(w)) {
QLineEdit* le = qobject_cast<QLineEdit*>(w);
avoidDuplicate(le);
le->setText(a->roleData(role).toString());
ConnHolder* c = new ConnHolder {
QObject::connect(le, &QLineEdit::textChanged, [a,role](const QString& text) {
if (a->roleData(role) != text)
a->setRoleData(role, text);
})
};
le->setProperty("lrcfgConn",QVariant::fromValue(c));
}
else if (qobject_cast<QSpinBox*>(w)) {
QSpinBox* sb = qobject_cast<QSpinBox*>(w);
avoidDuplicate(sb);
sb->setValue(a->roleData(role).toInt());
ConnHolder* c = new ConnHolder {
QObject::connect(sb, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [a,role](int value) {
if (a->roleData(role).toInt() != value)
a->setRoleData(role, value);
})
};
sb->setProperty("lrcfgConn",QVariant::fromValue(c));
}
else if (qobject_cast<QAbstractButton*>(w)) {
//QCheckBox, QRadioButton, QToolButton, QPushButton
QAbstractButton* b = qobject_cast<QAbstractButton*>(w);
avoidDuplicate(b);
b->setChecked(a->roleData(role).toBool());
ConnHolder* c = new ConnHolder {
QObject::connect(b, &QAbstractButton::toggled,[a,role](bool c) {
if (a->roleData(role).toBool() != c)
a->setRoleData(role, c);
})
};
b->setProperty("lrcfgConn",QVariant::fromValue(c));
}
}
else {
qWarning() << "Unknown config properties" << w->objectName();
}
}
}
static void clearConnections(QWidget* w)
{
if (w->objectName().left(LRC_CFG_LEN) == LRC_CFG) {
avoidDuplicate(w);
}
}
static void drill(QWidget* w, Account* a, const QHash<QByteArray, int>& roles, bool clear = false)
{
for (QObject *object : w->children()) {
if (!object->isWidgetType())
continue;
QWidget* w2 = static_cast<QWidget*>(object);
if (clear)
clearConnections(w2);
else
setupWidget(w2, a, roles);
drill(w2, a, roles);
}
}
AccountSerializationAdapter::AccountSerializationAdapter(Account* a, QWidget* w) : QObject(w)
{
static QHash<QByteArray, int> reverse;
if (reverse.isEmpty()) {
const QHash<int, QByteArray> a = AccountModel::instance()->roleNames();
for (QHash<int, QByteArray>::const_iterator i = a.begin(); i != a.end(); ++i) {
reverse[i.value()] = i.key();
}
}
drill(w, a, reverse);
}
AccountSerializationAdapter::~AccountSerializationAdapter()
{
}
/***************************************************************************
* Copyright (C) 2015 by Savoir-Faire Linux *
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>*
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#ifndef ACCOUNTSERIALIZATIONADAPTER_H
#define ACCOUNTSERIALIZATIONADAPTER_H
#include "typedefs.h"
class QWidget;
class Account;
/**
* This class will automatically bridge QtDesigner .ui to the LRC Account::
* class. To use it, all relevant .ui fields need to have in their name
*
* `lrcfg_propertyName` where `propertyName` is part of the Account object
* roleName hash.
*
* Supported widgets are currently:
*
* * QLineEdit
*/
class LIB_EXPORT AccountSerializationAdapter : public QObject
{
Q_OBJECT
public:
AccountSerializationAdapter(Account* a, QWidget* w);
virtual ~AccountSerializationAdapter();
};
#endif
\ No newline at end of file
......@@ -25,6 +25,8 @@
#include "video/rate.h"
#include "video/previewmanager.h"
#include "accountserializationadapter.h"
#include "accountmodel.h"
#include "protocolmodel.h"
#include "accountdetails.h"
......@@ -136,9 +138,12 @@ ConfigurationWidget::on_rateBox_currentIndexChanged(int index)
void
ConfigurationWidget::accountSelected(QItemSelection itemSel) {
Q_UNUSED(itemSel)
accountDetails_->setAccount(accountModel_->getAccountByModelIndex(
ui->accountView->currentIndex()));
auto account = accountModel_->getAccountByModelIndex(
ui->accountView->currentIndex());
accountDetails_->setAccount(account);
AccountSerializationAdapter adapter(account, accountDetails_);
}
void
......
......@@ -42,7 +42,7 @@
<item>
<widget class="QPushButton" name="backButton">
<property name="text">
<string>Back</string>
<string>Done</string>
</property>
<property name="icon">
<iconset resource="ressources.qrc">
......
......@@ -22,5 +22,6 @@
<file>images/arrow-down.png</file>
<file>images/arrow-up.png</file>
<file>images/spinner.gif</file>
<file>images/folder-download.png</file>
</qresource>
</RCC>
......@@ -190,7 +190,7 @@ QTabWidget::pane {
}
QTabBar::tab {
min-width: 80px;
min-width: 95px;
min-height: 30px;
font-size: 20px;
color: black;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment