~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to kde/src/lib/keyexchangemodel.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 *   Copyright (C) 2013-2014 by Savoir-Faire Linux                          *
 
3
 *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
 
4
 *                                                                          *
 
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.     *
 
9
 *                                                                          *
 
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.                        *
 
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 "keyexchangemodel.h"
 
19
 
 
20
#include <QtCore/QCoreApplication>
 
21
 
 
22
#include "account.h"
 
23
 
 
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   }},
 
31
}};
 
32
 
 
33
 
 
34
KeyExchangeModel::KeyExchangeModel(Account* account) : QAbstractListModel(account),m_pAccount(account) {}
 
35
 
 
36
//Model functions
 
37
QVariant KeyExchangeModel::data( const QModelIndex& index, int role) const
 
38
{
 
39
   if (!index.isValid()) return QVariant();
 
40
   KeyExchangeModel::Type method = static_cast<KeyExchangeModel::Type>(index.row());
 
41
   if (role == Qt::DisplayRole) {
 
42
      switch (method) {
 
43
         case KeyExchangeModel::Type::NONE:
 
44
            return KeyExchangeModel::Name::NONE;
 
45
            break;
 
46
         case KeyExchangeModel::Type::ZRTP:
 
47
            return KeyExchangeModel::Name::ZRTP;
 
48
            break;
 
49
         case KeyExchangeModel::Type::SDES:
 
50
            return KeyExchangeModel::Name::SDES;
 
51
            break;
 
52
         case KeyExchangeModel::Type::COUNT:
 
53
            break;
 
54
      };
 
55
   }
 
56
   return QVariant();
 
57
}
 
58
 
 
59
int KeyExchangeModel::rowCount( const QModelIndex& parent ) const
 
60
{
 
61
   return parent.isValid()?0:2;
 
62
}
 
63
 
 
64
Qt::ItemFlags KeyExchangeModel::flags( const QModelIndex& index ) const
 
65
{
 
66
   if (!index.isValid()) return Qt::NoItemFlags;
 
67
   return Qt::ItemIsEnabled|Qt::ItemIsSelectable;
 
68
}
 
69
 
 
70
bool KeyExchangeModel::setData( const QModelIndex& index, const QVariant &value, int role)
 
71
{
 
72
   Q_UNUSED(index)
 
73
   Q_UNUSED(value)
 
74
   Q_UNUSED(role )
 
75
   return false;
 
76
}
 
77
 
 
78
///Translate enum type to QModelIndex
 
79
QModelIndex KeyExchangeModel::toIndex(KeyExchangeModel::Type type) const
 
80
{
 
81
   return index(static_cast<int>(type),0,QModelIndex());
 
82
}
 
83
 
 
84
///Translate enum to daemon name
 
85
const char* KeyExchangeModel::toDaemonName(KeyExchangeModel::Type type)
 
86
{
 
87
   switch (type) {
 
88
      case KeyExchangeModel::Type::NONE:
 
89
         return KeyExchangeModel::DaemonName::NONE;
 
90
         break;
 
91
      case KeyExchangeModel::Type::ZRTP:
 
92
         return KeyExchangeModel::DaemonName::ZRTP;
 
93
         break;
 
94
      case KeyExchangeModel::Type::SDES:
 
95
         return KeyExchangeModel::DaemonName::SDES;
 
96
         break;
 
97
      case KeyExchangeModel::Type::COUNT:
 
98
         break;
 
99
   };
 
100
   return nullptr; //Cannot heppen
 
101
}
 
102
 
 
103
KeyExchangeModel::Type KeyExchangeModel::fromDaemonName(const QString& name)
 
104
{
 
105
   if (name.isEmpty())
 
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;
 
113
}
 
114
 
 
115
void KeyExchangeModel::enableSRTP(bool enable)
 
116
{
 
117
   if (enable && m_pAccount->keyExchange() == KeyExchangeModel::Type::NONE) {
 
118
      m_pAccount->setKeyExchange(KeyExchangeModel::Type::ZRTP);
 
119
   }
 
120
   else if (!enable) {
 
121
      m_pAccount->setKeyExchange(KeyExchangeModel::Type::NONE);
 
122
   }
 
123
}
 
124
 
 
125
bool KeyExchangeModel::isRtpFallbackEnabled() const
 
126
{
 
127
   return availableOptions[Options::RTP_FALLBACK][m_pAccount->keyExchange()];
 
128
}
 
129
 
 
130
bool KeyExchangeModel::isDisplaySASEnabled() const
 
131
{
 
132
   return availableOptions[Options::DISPLAY_SAS][m_pAccount->keyExchange()];
 
133
}
 
134
 
 
135
bool KeyExchangeModel::isDisplaySasOnce() const
 
136
{
 
137
   return availableOptions[Options::DISPLAY_SAS_ONCE][m_pAccount->keyExchange()];
 
138
}
 
139
 
 
140
bool KeyExchangeModel::areWarningSupressed() const
 
141
{
 
142
   return availableOptions[Options::NOT_SUPP_WARNING][m_pAccount->keyExchange()];
 
143
}
 
144
 
 
145
bool KeyExchangeModel::isHelloHashEnabled() const
 
146
{
 
147
   return availableOptions[Options::HELLO_HASH][m_pAccount->keyExchange()];
 
148
}