1
/****************************************************************************
2
* Copyright (C) 2013-2014 by Savoir-Faire Linux *
3
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
5
* This library is free software; you can redistribute it and/or *
6
* modify it under the terms of the GNU Lesser General Public *
7
* License as published by the Free Software Foundation; either *
8
* version 2.1 of the License, or (at your option) any later version. *
10
* This library 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 GNU *
13
* Lesser General Public License for more details. *
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 "keyexchangemodel.h"
20
#include <QtCore/QCoreApplication>
24
const TypedStateMachine< TypedStateMachine< bool , KeyExchangeModel::Type > , KeyExchangeModel::Options > KeyExchangeModel::availableOptions = {{
25
/* */ /* ZRTP */ /* SDES */ /* NONE */
26
/* RTP_FALLBACK */ {{ false , true , false }},
27
/* DISPLAY_SAS */ {{ true , false , false }},
28
/* NOT_SUPP_WARNING */ {{ true , false , false }},
29
/* HELLO_HASH */ {{ true , false , false }},
30
/* DISPLAY_SAS_ONCE */ {{ true , false , false }},
34
KeyExchangeModel::KeyExchangeModel(Account* account) : QAbstractListModel(account),m_pAccount(account) {}
37
QVariant KeyExchangeModel::data( const QModelIndex& index, int role) const
39
if (!index.isValid()) return QVariant();
40
KeyExchangeModel::Type method = static_cast<KeyExchangeModel::Type>(index.row());
41
if (role == Qt::DisplayRole) {
43
case KeyExchangeModel::Type::NONE:
44
return KeyExchangeModel::Name::NONE;
46
case KeyExchangeModel::Type::ZRTP:
47
return KeyExchangeModel::Name::ZRTP;
49
case KeyExchangeModel::Type::SDES:
50
return KeyExchangeModel::Name::SDES;
52
case KeyExchangeModel::Type::COUNT:
59
int KeyExchangeModel::rowCount( const QModelIndex& parent ) const
61
return parent.isValid()?0:2;
64
Qt::ItemFlags KeyExchangeModel::flags( const QModelIndex& index ) const
66
if (!index.isValid()) return Qt::NoItemFlags;
67
return Qt::ItemIsEnabled|Qt::ItemIsSelectable;
70
bool KeyExchangeModel::setData( const QModelIndex& index, const QVariant &value, int role)
78
///Translate enum type to QModelIndex
79
QModelIndex KeyExchangeModel::toIndex(KeyExchangeModel::Type type) const
81
return index(static_cast<int>(type),0,QModelIndex());
84
///Translate enum to daemon name
85
const char* KeyExchangeModel::toDaemonName(KeyExchangeModel::Type type)
88
case KeyExchangeModel::Type::NONE:
89
return KeyExchangeModel::DaemonName::NONE;
91
case KeyExchangeModel::Type::ZRTP:
92
return KeyExchangeModel::DaemonName::ZRTP;
94
case KeyExchangeModel::Type::SDES:
95
return KeyExchangeModel::DaemonName::SDES;
97
case KeyExchangeModel::Type::COUNT:
100
return nullptr; //Cannot heppen
103
KeyExchangeModel::Type KeyExchangeModel::fromDaemonName(const QString& name)
106
return KeyExchangeModel::Type::NONE;
107
else if (name == KeyExchangeModel::DaemonName::SDES)
108
return KeyExchangeModel::Type::SDES;
109
else if (name == KeyExchangeModel::DaemonName::ZRTP)
110
return KeyExchangeModel::Type::ZRTP;
111
qDebug() << "Undefined Key exchange mechanism" << name;
112
return KeyExchangeModel::Type::NONE;
115
void KeyExchangeModel::enableSRTP(bool enable)
117
if (enable && m_pAccount->keyExchange() == KeyExchangeModel::Type::NONE) {
118
m_pAccount->setKeyExchange(KeyExchangeModel::Type::ZRTP);
121
m_pAccount->setKeyExchange(KeyExchangeModel::Type::NONE);
125
bool KeyExchangeModel::isRtpFallbackEnabled() const
127
return availableOptions[Options::RTP_FALLBACK][m_pAccount->keyExchange()];
130
bool KeyExchangeModel::isDisplaySASEnabled() const
132
return availableOptions[Options::DISPLAY_SAS][m_pAccount->keyExchange()];
135
bool KeyExchangeModel::isDisplaySasOnce() const
137
return availableOptions[Options::DISPLAY_SAS_ONCE][m_pAccount->keyExchange()];
140
bool KeyExchangeModel::areWarningSupressed() const
142
return availableOptions[Options::NOT_SUPP_WARNING][m_pAccount->keyExchange()];
145
bool KeyExchangeModel::isHelloHashEnabled() const
147
return availableOptions[Options::HELLO_HASH][m_pAccount->keyExchange()];