Skip to content
Snippets Groups Projects
Commit fecd9efe authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

[ #37237 ] Improve security configuration dialog usability

parent 5f38b539
No related branches found
No related tags found
No related merge requests found
......@@ -57,7 +57,8 @@ const account_function Account::stateMachineActionsOnState[6][7] = {
///Constructors
Account::Account():QObject(AccountListModel::instance()),m_pCredentials(nullptr),m_pAudioCodecs(nullptr),m_CurrentState(AccountEditState::READY),
m_pVideoCodecs(nullptr),m_LastErrorCode(-1),m_VoiceMailCount(0),m_pRingToneModel(nullptr),m_pAccountNumber(nullptr)
m_pVideoCodecs(nullptr),m_LastErrorCode(-1),m_VoiceMailCount(0),m_pRingToneModel(nullptr),m_pAccountNumber(nullptr),
m_pKeyExchangeModel(nullptr)
{
}
......@@ -303,6 +304,14 @@ RingToneModel* Account::ringToneModel() const
return m_pRingToneModel;
}
KeyExchangeModel* Account::keyExchangeModel() const
{
if (!m_pKeyExchangeModel) {
const_cast<Account*>(this)->m_pKeyExchangeModel = new KeyExchangeModel(const_cast<Account*>(this));
}
return m_pKeyExchangeModel;
}
void Account::setAlias(const QString& detail)
{
bool accChanged = detail != alias();
......@@ -1073,7 +1082,7 @@ void Account::setRoleData(int role, const QVariant& value)
}
case Account::Role::KeyExchange: {
const int method = value.toInt();
setKeyExchange(method<=KeyExchangeModel::instance()->rowCount()?static_cast<KeyExchangeModel::Type>(method):KeyExchangeModel::Type::NONE);
setKeyExchange(method<=keyExchangeModel()->rowCount()?static_cast<KeyExchangeModel::Type>(method):KeyExchangeModel::Type::NONE);
}
case Account::Role::RegistrationExpire:
setRegistrationExpire(value.toInt());
......
......@@ -305,6 +305,7 @@ class LIB_EXPORT Account : public QObject {
Q_INVOKABLE AudioCodecModel* audioCodecModel () const;
Q_INVOKABLE VideoCodecModel* videoCodecModel () const;
Q_INVOKABLE RingToneModel* ringToneModel () const;
Q_INVOKABLE KeyExchangeModel* keyExchangeModel() const;
//Getters
QString hostname () const;
......@@ -453,6 +454,7 @@ class LIB_EXPORT Account : public QObject {
AudioCodecModel* m_pAudioCodecs ;
VideoCodecModel* m_pVideoCodecs ;
RingToneModel* m_pRingToneModel ;
KeyExchangeModel* m_pKeyExchangeModel;
AccountEditState m_CurrentState;
static const account_function stateMachineActionsOnState[6][7];
......
......@@ -19,9 +19,19 @@
#include <QtCore/QCoreApplication>
KeyExchangeModel* KeyExchangeModel::m_spInstance = nullptr;
#include "account.h"
KeyExchangeModel::KeyExchangeModel() : QAbstractListModel(QCoreApplication::instance()) {}
const TypedStateMachine< TypedStateMachine< bool , KeyExchangeModel::Type > , KeyExchangeModel::Options > KeyExchangeModel::availableOptions = {{
/* */ /* ZRTP */ /* SDES */ /* NONE */
/* RTP_FALLBACK */ {{ false , true , false }},
/* DISPLAY_SAS */ {{ true , false , false }},
/* NOT_SUPP_WARNING */ {{ true , false , false }},
/* HELLO_HASH */ {{ true , false , false }},
/* DISPLAY_SAS_ONCE */ {{ true , false , false }},
}};
KeyExchangeModel::KeyExchangeModel(Account* account) : QAbstractListModel(account),m_pAccount(account) {}
//Model functions
QVariant KeyExchangeModel::data( const QModelIndex& index, int role) const
......@@ -39,6 +49,8 @@ QVariant KeyExchangeModel::data( const QModelIndex& index, int role) const
case KeyExchangeModel::Type::SDES:
return KeyExchangeModel::Name::SDES;
break;
case KeyExchangeModel::Type::COUNT:
break;
};
}
return QVariant();
......@@ -46,7 +58,7 @@ QVariant KeyExchangeModel::data( const QModelIndex& index, int role) const
int KeyExchangeModel::rowCount( const QModelIndex& parent ) const
{
return parent.isValid()?0:3;
return parent.isValid()?0:2;
}
Qt::ItemFlags KeyExchangeModel::flags( const QModelIndex& index ) const
......@@ -63,13 +75,6 @@ bool KeyExchangeModel::setData( const QModelIndex& index, const QVariant &value,
return false;
}
KeyExchangeModel* KeyExchangeModel::instance()
{
if (!m_spInstance)
m_spInstance = new KeyExchangeModel();
return m_spInstance;
}
///Translate enum type to QModelIndex
QModelIndex KeyExchangeModel::toIndex(KeyExchangeModel::Type type) const
{
......@@ -89,6 +94,8 @@ const char* KeyExchangeModel::toDaemonName(KeyExchangeModel::Type type)
case KeyExchangeModel::Type::SDES:
return KeyExchangeModel::DaemonName::SDES;
break;
case KeyExchangeModel::Type::COUNT:
break;
};
return nullptr; //Cannot heppen
}
......@@ -104,3 +111,38 @@ KeyExchangeModel::Type KeyExchangeModel::fromDaemonName(const QString& name)
qDebug() << "Undefined Key exchange mechanism" << name;
return KeyExchangeModel::Type::NONE;
}
void KeyExchangeModel::enableSRTP(bool enable)
{
if (enable && m_pAccount->keyExchange() == KeyExchangeModel::Type::NONE) {
m_pAccount->setKeyExchange(KeyExchangeModel::Type::ZRTP);
}
else if (!enable) {
m_pAccount->setKeyExchange(KeyExchangeModel::Type::NONE);
}
}
bool KeyExchangeModel::isRtpFallbackEnabled() const
{
return availableOptions[Options::RTP_FALLBACK][m_pAccount->keyExchange()];
}
bool KeyExchangeModel::isDisplaySASEnabled() const
{
return availableOptions[Options::DISPLAY_SAS][m_pAccount->keyExchange()];
}
bool KeyExchangeModel::isDisplaySasOnce() const
{
return availableOptions[Options::DISPLAY_SAS_ONCE][m_pAccount->keyExchange()];
}
bool KeyExchangeModel::areWarningSupressed() const
{
return availableOptions[Options::NOT_SUPP_WARNING][m_pAccount->keyExchange()];
}
bool KeyExchangeModel::isHelloHashEnabled() const
{
return availableOptions[Options::HELLO_HASH][m_pAccount->keyExchange()];
}
......@@ -21,19 +21,33 @@
#include "typedefs.h"
#include <QtCore/QAbstractListModel>
class Account;
///Static model for handling encryption types
class LIB_EXPORT KeyExchangeModel : public QAbstractListModel {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
Q_OBJECT
#pragma GCC diagnostic pop
friend class Account;
public:
///@enum Type Every supported encryption types
enum class Type {
NONE = 0,
ZRTP = 1,
SDES = 2,
ZRTP = 0,
SDES = 1,
NONE = 2,
COUNT,
};
///@enum Options Every Key exchange options
enum class Options {
RTP_FALLBACK = 0,
DISPLAY_SAS = 1,
NOT_SUPP_WARNING = 2,
HELLO_HASH = 3,
DISPLAY_SAS_ONCE = 4,
COUNT,
};
class Name {
......@@ -51,7 +65,7 @@ public:
};
//Private constructor, can only be called by 'Account'
explicit KeyExchangeModel();
explicit KeyExchangeModel(Account* account);
//Model functions
QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const;
......@@ -64,11 +78,23 @@ public:
static const char* toDaemonName (KeyExchangeModel::Type type) ;
static KeyExchangeModel::Type fromDaemonName(const QString& name ) ;
//Singleton
static KeyExchangeModel* instance();
bool isRtpFallbackEnabled() const;
bool isDisplaySASEnabled () const;
bool isDisplaySasOnce () const;
bool areWarningSupressed () const;
bool isHelloHashEnabled () const;
private:
static KeyExchangeModel* m_spInstance;
KeyExchangeModel::Type m_CurrentMethod;
Account* m_pAccount;
static const TypedStateMachine< TypedStateMachine< bool , KeyExchangeModel::Type > , KeyExchangeModel::Options > availableOptions;
public Q_SLOTS:
void enableSRTP(bool enable);
Q_SIGNALS:
void srtpEnabled(bool);
};
Q_DECLARE_METATYPE(KeyExchangeModel*)
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment