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

« back to all changes in this revision

Viewing changes to kde/src/lib/account.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
1
/****************************************************************************
2
 
 *   Copyright (C) 2009-2013 by Savoir-Faire Linux                          *
 
2
 *   Copyright (C) 2009-2014 by Savoir-Faire Linux                          *
3
3
 *   Author : Jérémy Quentin <jeremy.quentin@savoirfairelinux.com>          *
4
4
 *            Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
5
5
 *                                                                          *
22
22
 
23
23
//Qt
24
24
#include <QtCore/QDebug>
 
25
#include <QtCore/QObject>
25
26
#include <QtCore/QString>
26
27
 
27
28
//SFLPhone
28
29
#include "sflphone_const.h"
29
30
 
30
31
//SFLPhone lib
31
 
#include "configurationmanager_interface_singleton.h"
32
 
#include "callmanager_interface_singleton.h"
33
 
#include "video_interface_singleton.h"
34
 
#include "accountlist.h"
 
32
#include "dbus/configurationmanager.h"
 
33
#include "dbus/callmanager.h"
 
34
#include "dbus/videomanager.h"
 
35
#include "visitors/accountlistcolorvisitor.h"
 
36
#include "accountlistmodel.h"
35
37
#include "credentialmodel.h"
36
38
#include "audiocodecmodel.h"
37
39
#include "videocodecmodel.h"
 
40
#include "ringtonemodel.h"
 
41
#include "phonenumber.h"
 
42
#include "phonedirectorymodel.h"
 
43
#include "presencestatusmodel.h"
 
44
#define TO_BOOL ?"true":"false"
 
45
#define IS_TRUE == "true"
38
46
 
39
47
const account_function Account::stateMachineActionsOnState[6][7] = {
40
48
/*                 NOTHING              EDIT              RELOAD              SAVE               REMOVE             MODIFY             CANCEL            */
47
55
/*                                                                                                                                                       */
48
56
};
49
57
 
50
 
///Match state name to user readable string
51
 
const QString& account_state_name(const QString& s)
52
 
{
53
 
   static const QString registered             = "Registered"               ;
54
 
   static const QString notRegistered          = "Not Registered"           ;
55
 
   static const QString trying                 = "Trying..."                ;
56
 
   static const QString error                  = "Error"                    ;
57
 
   static const QString authenticationFailed   = "Authentication Failed"    ;
58
 
   static const QString networkUnreachable     = "Network unreachable"      ;
59
 
   static const QString hostUnreachable        = "Host unreachable"         ;
60
 
   static const QString stunConfigurationError = "Stun configuration error" ;
61
 
   static const QString stunServerInvalid      = "Stun server invalid"      ;
62
 
   static const QString invalid                = "Invalid"                  ;
63
 
   
64
 
   if(s == QString(ACCOUNT_STATE_REGISTERED)       )
65
 
      return registered             ;
66
 
   if(s == QString(ACCOUNT_STATE_UNREGISTERED)     )
67
 
      return notRegistered          ;
68
 
   if(s == QString(ACCOUNT_STATE_TRYING)           )
69
 
      return trying                 ;
70
 
   if(s == QString(ACCOUNT_STATE_ERROR)            )
71
 
      return error                  ;
72
 
   if(s == QString(ACCOUNT_STATE_ERROR_AUTH)       )
73
 
      return authenticationFailed   ;
74
 
   if(s == QString(ACCOUNT_STATE_ERROR_NETWORK)    )
75
 
      return networkUnreachable     ;
76
 
   if(s == QString(ACCOUNT_STATE_ERROR_HOST)       )
77
 
      return hostUnreachable        ;
78
 
   if(s == QString(ACCOUNT_STATE_ERROR_CONF_STUN)  )
79
 
      return stunConfigurationError ;
80
 
   if(s == QString(ACCOUNT_STATE_ERROR_EXIST_STUN) )
81
 
      return stunServerInvalid      ;
82
 
   return invalid                   ;
83
 
} //account_state_name
84
 
 
85
58
///Constructors
86
 
Account::Account():m_pAccountId(nullptr),m_pAccountDetails(nullptr),m_pCredentials(nullptr),m_pAudioCodecs(nullptr),m_CurrentState(READY),
87
 
m_pVideoCodecs(nullptr)
 
59
Account::Account():QObject(AccountListModel::instance()),m_pCredentials(nullptr),m_pAudioCodecs(nullptr),m_CurrentState(AccountEditState::READY),
 
60
m_pVideoCodecs(nullptr),m_LastErrorCode(-1),m_VoiceMailCount(0),m_pRingToneModel(nullptr),m_pAccountNumber(nullptr),
 
61
m_pKeyExchangeModel(nullptr)
88
62
{
89
 
   CallManagerInterface& callManager = CallManagerInterfaceSingleton::getInstance();
90
 
   connect(&callManager,SIGNAL(registrationStateChanged(QString,QString,int)),this,SLOT(accountChanged(QString,QString,int)));
91
63
}
92
64
 
93
65
///Build an account from it'id
94
66
Account* Account::buildExistingAccountFromId(const QString& _accountId)
95
67
{
96
 
   qDebug() << "Building an account from id: " << _accountId;
 
68
//    qDebug() << "Building an account from id: " << _accountId;
97
69
   Account* a = new Account();
98
 
   a->m_pAccountId = new QString(_accountId);
 
70
   a->m_AccountId = _accountId;
 
71
   a->setObjectName(_accountId);
99
72
 
100
73
   a->performAction(AccountEditAction::RELOAD);
101
74
 
106
79
Account* Account::buildNewAccountFromAlias(const QString& alias)
107
80
{
108
81
   qDebug() << "Building an account from alias: " << alias;
109
 
   ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
110
 
   Account* a           = new Account();
111
 
   a->m_pAccountDetails = new MapStringString(configurationManager.getAccountTemplate());
112
 
   a->setAccountDetail(ACCOUNT_ALIAS,alias);
 
82
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
83
   Account* a = new Account();
 
84
   a->m_hAccountDetails.clear();
 
85
   a->m_hAccountDetails[Account::MapField::ENABLED] = "false";
 
86
   a->m_pAccountNumber = const_cast<PhoneNumber*>(PhoneNumber::BLANK());
 
87
   MapStringString tmp = configurationManager.getAccountTemplate();
 
88
   QMutableMapIterator<QString, QString> iter(tmp);
 
89
   while (iter.hasNext()) {
 
90
      iter.next();
 
91
      a->m_hAccountDetails[iter.key()] = iter.value();
 
92
   }
 
93
   a->setHostname(a->m_hAccountDetails[Account::MapField::HOSTNAME]);
 
94
   a->setAccountDetail(Account::MapField::ALIAS,alias);
 
95
   a->setObjectName(a->id());
113
96
   return a;
114
97
}
115
98
 
117
100
Account::~Account()
118
101
{
119
102
   disconnect();
120
 
   delete m_pAccountId;
121
 
   if (m_pCredentials)    delete m_pCredentials   ;
122
 
   if (m_pAccountDetails) delete m_pAccountDetails;
123
 
   if (m_pAudioCodecs)    delete m_pAudioCodecs   ;
 
103
   if (m_pCredentials) delete m_pCredentials ;
 
104
   if (m_pAudioCodecs) delete m_pAudioCodecs ;
124
105
}
125
106
 
126
107
 
131
112
 ****************************************************************************/
132
113
 
133
114
///Callback when the account state change
134
 
void Account::accountChanged(QString accountId,QString state,int)
135
 
{
136
 
   if (m_pAccountId && accountId == *m_pAccountId) {
137
 
      qDebug() << "Account" << m_pAccountId << "status changed";
138
 
      if (Account::updateState())
139
 
         emit stateChanged(getStateName(state));
140
 
   }
141
 
}
142
 
 
 
115
// void Account::accountChanged(const QString& accountId, const QString& state,int)
 
116
// {
 
117
//    if ((!m_AccountId.isEmpty()) && accountId == m_AccountId) {
 
118
//       if (state != "OK") //Do not polute the log
 
119
//          qDebug() << "Account" << m_AccountId << "status changed to" << state;
 
120
//       if (Account::updateState())
 
121
//          emit stateChanged(toHumanStateName());
 
122
//    }
 
123
// }
 
124
 
 
125
void Account::slotPresentChanged(bool present)
 
126
{
 
127
   Q_UNUSED(present)
 
128
   emit changed(this);
 
129
}
 
130
 
 
131
void Account::slotPresenceMessageChanged(const QString& message)
 
132
{
 
133
   Q_UNUSED(message)
 
134
   emit changed(this);
 
135
}
143
136
 
144
137
/*****************************************************************************
145
138
 *                                                                           *
150
143
///IS this account new
151
144
bool Account::isNew() const
152
145
{
153
 
   return (m_pAccountId == nullptr);
 
146
   return (m_AccountId == nullptr) || m_AccountId.isEmpty();
154
147
}
155
148
 
156
149
///Get this account ID
157
 
const QString Account::getAccountId() const
 
150
const QString Account::id() const
158
151
{
159
152
   if (isNew()) {
160
153
      qDebug() << "Error : getting AccountId of a new account.";
161
154
   }
162
 
   if (!m_pAccountId) {
 
155
   if (m_AccountId.isEmpty()) {
163
156
      qDebug() << "Account not configured";
164
 
      return EMPTY_STRING; //WARNING May explode
 
157
      return QString(); //WARNING May explode
165
158
   }
166
 
   
167
 
   return *m_pAccountId;
168
 
}
169
159
 
170
 
///Get this account details
171
 
const MapStringString& Account::getAccountDetails() const
172
 
{
173
 
   return *m_pAccountDetails;
 
160
   return m_AccountId;
174
161
}
175
162
 
176
163
///Get current state
177
 
const QString Account::getStateName(const QString& state) const
 
164
const QString Account::toHumanStateName() const
178
165
{
179
 
   return (const QString&)account_state_name(state);
 
166
   const QString s = m_hAccountDetails[Account::MapField::Registration::STATUS];
 
167
 
 
168
   static const QString registered             = tr("Registered"               );
 
169
   static const QString notRegistered          = tr("Not Registered"           );
 
170
   static const QString trying                 = tr("Trying..."                );
 
171
   static const QString error                  = tr("Error"                    );
 
172
   static const QString authenticationFailed   = tr("Authentication Failed"    );
 
173
   static const QString networkUnreachable     = tr("Network unreachable"      );
 
174
   static const QString hostUnreachable        = tr("Host unreachable"         );
 
175
   static const QString stunConfigurationError = tr("Stun configuration error" );
 
176
   static const QString stunServerInvalid      = tr("Stun server invalid"      );
 
177
   static const QString serviceUnavailable     = tr("Service unavailable"      );
 
178
   static const QString notAcceptable          = tr("Unacceptable"             );
 
179
   static const QString invalid                = tr("Invalid"                  );
 
180
   static const QString requestTimeout         = tr("Request Timeout"          );
 
181
 
 
182
   if(s == Account::State::REGISTERED       )
 
183
      return registered             ;
 
184
   if(s == Account::State::UNREGISTERED     )
 
185
      return notRegistered          ;
 
186
   if(s == Account::State::TRYING           )
 
187
      return trying                 ;
 
188
   if(s == Account::State::ERROR            )
 
189
      return m_LastErrorMessage.isEmpty()?error:m_LastErrorMessage;
 
190
   if(s == Account::State::ERROR_AUTH       )
 
191
      return authenticationFailed   ;
 
192
   if(s == Account::State::ERROR_NETWORK    )
 
193
      return networkUnreachable     ;
 
194
   if(s == Account::State::ERROR_HOST       )
 
195
      return hostUnreachable        ;
 
196
   if(s == Account::State::ERROR_CONF_STUN  )
 
197
      return stunConfigurationError ;
 
198
   if(s == Account::State::ERROR_EXIST_STUN )
 
199
      return stunServerInvalid      ;
 
200
   if(s == Account::State::ERROR_SERVICE_UNAVAILABLE )
 
201
      return serviceUnavailable     ;
 
202
   if(s == Account::State::ERROR_NOT_ACCEPTABLE      )
 
203
      return notAcceptable          ;
 
204
   if(s == Account::State::REQUEST_TIMEOUT           )
 
205
      return requestTimeout         ;
 
206
   return invalid                   ;
180
207
}
181
208
 
182
209
///Get an account detail
183
 
const QString Account::getAccountDetail(const QString& param) const
 
210
const QString Account::accountDetail(const QString& param) const
184
211
{
185
 
   if (!m_pAccountDetails) {
186
 
      qDebug() << "The account list is not set";
187
 
      return EMPTY_STRING; //May crash, but better than crashing now
188
 
   }
189
 
   if (m_pAccountDetails->find(param) != m_pAccountDetails->end()) {
190
 
      return (*m_pAccountDetails)[param];
191
 
   }
192
 
   else if (m_pAccountDetails->count() > 0) {
193
 
      if (param == "Account.enable") //If an account is invalid, at least does not try to register it
 
212
   if (!m_hAccountDetails.size()) {
 
213
      qDebug() << "The account details is not set";
 
214
      return QString(); //May crash, but better than crashing now
 
215
   }
 
216
   if (m_hAccountDetails.find(param) != m_hAccountDetails.end()) {
 
217
      return m_hAccountDetails[param];
 
218
   }
 
219
   else if (m_hAccountDetails.count() > 0) {
 
220
      if (param == Account::MapField::ENABLED) //If an account is invalid, at least does not try to register it
194
221
         return REGISTRATION_ENABLED_FALSE;
195
 
      qDebug() << "Account parameter \"" << param << "\" not found";
196
 
      return EMPTY_STRING;
 
222
      if (param == Account::MapField::Registration::STATUS) //If an account is new, then it is unregistered
 
223
         return Account::State::UNREGISTERED;
 
224
      if (protocol() != Account::Protocol::IAX) //IAX accounts lack some fields, be quiet
 
225
         qDebug() << "Account parameter \"" << param << "\" not found";
 
226
      return QString();
197
227
   }
198
228
   else {
199
 
      qDebug() << "Account details not found, there is " << m_pAccountDetails->count() << " details available";
200
 
      return EMPTY_STRING;
 
229
      qDebug() << "Account details not found, there is " << m_hAccountDetails.count() << " details available";
 
230
      return QString();
201
231
   }
202
 
} //getAccountDetail
 
232
} //accountDetail
203
233
 
204
234
///Get the alias
205
 
const QString Account::getAlias() const
206
 
{
207
 
   return getAccountDetail(ACCOUNT_ALIAS);
208
 
}
209
 
 
210
 
///Is this account enabled
211
 
bool Account::isEnabled() const
212
 
{
213
 
   //getAccountRegistrationStatus() != ACCOUNT_STATE_UNREGISTERED should not happen, but it does, it is not managed because both client trying to 
214
 
   //set the state would fight to the daeth to set the enabled boolean
215
 
   return (getAccountDetail(ACCOUNT_ENABLED) == REGISTRATION_ENABLED_TRUE);
 
235
const QString Account::alias() const
 
236
{
 
237
   return accountDetail(Account::MapField::ALIAS);
216
238
}
217
239
 
218
240
///Is this account registered
219
241
bool Account::isRegistered() const
220
242
{
221
 
   return (getAccountDetail(ACCOUNT_REGISTRATION_STATUS) == ACCOUNT_STATE_REGISTERED);
 
243
   return (accountDetail(Account::MapField::Registration::STATUS) == Account::State::REGISTERED);
222
244
}
223
245
 
224
246
///Return the model index of this item
225
 
QModelIndex Account::getIndex()
 
247
QModelIndex Account::index()
226
248
{
227
 
   for (int i=0;i < AccountList::getInstance()->m_pAccounts->size();i++) {
228
 
      if (this == (*AccountList::getInstance()->m_pAccounts)[i]) {
229
 
         return AccountList::getInstance()->index(i,0);
 
249
   for (int i=0;i < AccountListModel::instance()->m_lAccounts.size();i++) {
 
250
      if (this == (AccountListModel::instance()->m_lAccounts)[i]) {
 
251
         return AccountListModel::instance()->index(i,0);
230
252
      }
231
253
   }
232
254
   return QModelIndex();
233
255
}
234
256
 
235
257
///Return status color name
236
 
QString Account::getStateColorName() const
 
258
QString Account::stateColorName() const
237
259
{
238
 
   if(getAccountRegistrationStatus() == ACCOUNT_STATE_UNREGISTERED)
 
260
   if(registrationStatus() == Account::State::UNREGISTERED)
239
261
      return "black";
240
 
   if(getAccountRegistrationStatus() == ACCOUNT_STATE_REGISTERED || getAccountRegistrationStatus() == ACCOUNT_STATE_READY)
 
262
   if(registrationStatus() == Account::State::REGISTERED || registrationStatus() == Account::State::READY)
241
263
      return "darkGreen";
242
264
   return "red";
243
265
}
244
266
 
245
267
///Return status Qt color, QColor is not part of QtCore, use using the global variant
246
 
Qt::GlobalColor Account::getStateColor() const
 
268
QVariant Account::stateColor() const
247
269
{
248
 
   if(getAccountRegistrationStatus() == ACCOUNT_STATE_UNREGISTERED)
249
 
      return Qt::darkGray  ;
250
 
   if(getAccountRegistrationStatus() == ACCOUNT_STATE_REGISTERED || getAccountRegistrationStatus() == ACCOUNT_STATE_READY)
251
 
      return Qt::darkGreen ;
252
 
   if(getAccountRegistrationStatus() == ACCOUNT_STATE_TRYING)
253
 
      return Qt::darkYellow;
254
 
   return Qt::darkRed;
 
270
   if (AccountListModel::instance()->colorVisitor()) {
 
271
      return AccountListModel::instance()->colorVisitor()->getColor(this);
 
272
   }
 
273
   return QVariant();
255
274
}
256
275
 
257
276
///Create and return the credential model
258
 
CredentialModel* Account::getCredentialsModel()
 
277
CredentialModel* Account::credentialsModel() const
259
278
{
260
279
   if (!m_pCredentials)
261
 
      reloadCredentials();
 
280
      const_cast<Account*>(this)->reloadCredentials();
262
281
   return m_pCredentials;
263
282
}
264
283
 
265
284
///Create and return the audio codec model
266
 
AudioCodecModel* Account::getAudioCodecModel()
 
285
AudioCodecModel* Account::audioCodecModel() const
267
286
{
268
287
   if (!m_pAudioCodecs)
269
 
      reloadAudioCodecs();
 
288
      const_cast<Account*>(this)->reloadAudioCodecs();
270
289
   return m_pAudioCodecs;
271
290
}
272
291
 
273
292
///Create and return the video codec model
274
 
VideoCodecModel* Account::getVideoCodecModel()
 
293
VideoCodecModel* Account::videoCodecModel() const
275
294
{
276
295
   if (!m_pVideoCodecs)
277
 
      m_pVideoCodecs = new VideoCodecModel(this);
 
296
      const_cast<Account*>(this)->m_pVideoCodecs = new VideoCodecModel(const_cast<Account*>(this));
278
297
   return m_pVideoCodecs;
279
298
}
280
299
 
281
 
void Account::setAccountAlias(QString detail)
282
 
{
283
 
   bool changed = detail != getAccountAlias();
284
 
   setAccountDetail(ACCOUNT_ALIAS,detail);
285
 
   if (changed)
 
300
RingToneModel* Account::ringToneModel() const
 
301
{
 
302
   if (!m_pRingToneModel)
 
303
      const_cast<Account*>(this)->m_pRingToneModel = new RingToneModel(const_cast<Account*>(this));
 
304
   return m_pRingToneModel;
 
305
}
 
306
 
 
307
KeyExchangeModel* Account::keyExchangeModel() const
 
308
{
 
309
   if (!m_pKeyExchangeModel) {
 
310
      const_cast<Account*>(this)->m_pKeyExchangeModel = new KeyExchangeModel(const_cast<Account*>(this));
 
311
   }
 
312
   return m_pKeyExchangeModel;
 
313
}
 
314
 
 
315
void Account::setAlias(const QString& detail)
 
316
{
 
317
   bool accChanged = detail != alias();
 
318
   setAccountDetail(Account::MapField::ALIAS,detail);
 
319
   if (accChanged)
286
320
      emit aliasChanged(detail);
287
321
}
288
322
 
289
323
///Return the account hostname
290
 
QString Account::getAccountHostname              () const
 
324
QString Account::hostname() const
291
325
{
292
 
   return getAccountDetail(ACCOUNT_HOSTNAME);
 
326
   return m_HostName;
293
327
}
294
328
 
295
329
///Return if the account is enabled
296
 
bool Account::isAccountEnabled() const 
 
330
bool Account::isEnabled() const
297
331
{
298
 
   return (getAccountDetail(ACCOUNT_ENABLED)  == "true")?1:0;
 
332
   return accountDetail(Account::MapField::ENABLED) IS_TRUE;
299
333
}
300
334
 
301
335
///Return if the account should auto answer
302
336
bool Account::isAutoAnswer() const
303
337
{
304
 
   return (getAccountDetail(ACCOUNT_AUTOANSWER)  == "true")?1:0;
 
338
   return accountDetail(Account::MapField::AUTOANSWER) IS_TRUE;
305
339
}
306
340
 
307
341
///Return the account user name
308
 
QString Account::getAccountUsername() const
309
 
{
310
 
   return getAccountDetail(ACCOUNT_USERNAME);
311
 
}
312
 
 
313
 
///Return the account mailbox address
314
 
QString Account::getAccountMailbox() const 
315
 
{
316
 
   return getAccountDetail(ACCOUNT_MAILBOX);
317
 
}
318
 
 
319
 
///Return the account mailbox address
320
 
QString Account::getAccountProxy() const
321
 
{
322
 
   return getAccountDetail(ACCOUNT_ROUTE);
 
342
QString Account::username() const
 
343
{
 
344
   return accountDetail(Account::MapField::USERNAME);
 
345
}
 
346
 
 
347
///Return the account mailbox address
 
348
QString Account::mailbox() const
 
349
{
 
350
   return accountDetail(Account::MapField::MAILBOX);
 
351
}
 
352
 
 
353
///Return the account mailbox address
 
354
QString Account::proxy() const
 
355
{
 
356
   return accountDetail(Account::MapField::ROUTE);
 
357
}
 
358
 
 
359
 
 
360
QString Account::password() const
 
361
{
 
362
   switch (protocol()) {
 
363
      case Account::Protocol::SIP:
 
364
         if (credentialsModel()->rowCount())
 
365
            return credentialsModel()->data(credentialsModel()->index(0,0),CredentialModel::Role::PASSWORD).toString();
 
366
      case Account::Protocol::IAX:
 
367
         return accountDetail(Account::MapField::PASSWORD);
 
368
   };
 
369
   return "";
323
370
}
324
371
 
325
372
///
326
 
bool Account::isAccountDisplaySasOnce() const
 
373
bool Account::isDisplaySasOnce() const
327
374
328
 
   return (getAccountDetail(ACCOUNT_DISPLAY_SAS_ONCE)  == "true")?1:0 ;
 
375
   return accountDetail(Account::MapField::ZRTP::DISPLAY_SAS_ONCE) IS_TRUE;
329
376
}
330
377
 
331
378
///Return the account security fallback
332
 
bool Account::isAccountSrtpRtpFallback() const
333
 
{
334
 
   return (getAccountDetail(ACCOUNT_SRTP_RTP_FALLBACK)  == "true")?1:0 ;
 
379
bool Account::isSrtpRtpFallback() const
 
380
{
 
381
   return accountDetail(Account::MapField::SRTP::RTP_FALLBACK) IS_TRUE;
 
382
}
 
383
 
 
384
//Return if SRTP is enabled or not
 
385
bool Account::isSrtpEnabled() const
 
386
{
 
387
   return accountDetail(Account::MapField::SRTP::ENABLED) IS_TRUE;
335
388
}
336
389
 
337
390
///
338
 
bool Account::isAccountZrtpDisplaySas         () const
 
391
bool Account::isZrtpDisplaySas         () const
339
392
{
340
 
   return (getAccountDetail(ACCOUNT_ZRTP_DISPLAY_SAS)  == "true")?1:0 ;
 
393
   return accountDetail(Account::MapField::ZRTP::DISPLAY_SAS) IS_TRUE;
341
394
}
342
395
 
343
396
///Return if the other side support warning
344
 
bool Account::isAccountZrtpNotSuppWarning() const
 
397
bool Account::isZrtpNotSuppWarning() const
345
398
{
346
 
   return (getAccountDetail(ACCOUNT_ZRTP_NOT_SUPP_WARNING) == "true")?1:0 ;
 
399
   return accountDetail(Account::MapField::ZRTP::NOT_SUPP_WARNING) IS_TRUE;
347
400
}
348
401
 
349
402
///
350
 
bool Account::isAccountZrtpHelloHash() const
 
403
bool Account::isZrtpHelloHash() const
351
404
{
352
 
   return (getAccountDetail(ACCOUNT_ZRTP_HELLO_HASH)  == "true")?1:0 ;
 
405
   return accountDetail(Account::MapField::ZRTP::HELLO_HASH) IS_TRUE;
353
406
}
354
407
 
355
408
///Return if the account is using a STUN server
356
 
bool Account::isAccountSipStunEnabled() const
 
409
bool Account::isSipStunEnabled() const
357
410
{
358
 
   return (getAccountDetail(ACCOUNT_SIP_STUN_ENABLED)  == "true")?1:0 ;
 
411
   return accountDetail(Account::MapField::STUN::ENABLED) IS_TRUE;
359
412
}
360
413
 
361
414
///Return the account STUN server
362
 
QString Account::getAccountSipStunServer() const
 
415
QString Account::sipStunServer() const
363
416
{
364
 
   return getAccountDetail(ACCOUNT_SIP_STUN_SERVER);
 
417
   return accountDetail(Account::MapField::STUN::SERVER);
365
418
}
366
419
 
367
420
///Return when the account expire (require renewal)
368
 
int Account::getAccountRegistrationExpire() const
 
421
int Account::registrationExpire() const
369
422
{
370
 
   return getAccountDetail(ACCOUNT_REGISTRATION_EXPIRE).toInt();
 
423
   return accountDetail(Account::MapField::Registration::EXPIRE).toInt();
371
424
}
372
425
 
373
426
///Return if the published address is the same as the local one
374
427
bool Account::isPublishedSameAsLocal() const
375
428
{
376
 
   return (getAccountDetail(PUBLISHED_SAMEAS_LOCAL)  == "true")?1:0 ;
 
429
   return accountDetail(Account::MapField::PUBLISHED_SAMEAS_LOCAL) IS_TRUE;
377
430
}
378
431
 
379
432
///Return the account published address
380
 
QString Account::getPublishedAddress() const
 
433
QString Account::publishedAddress() const
381
434
{
382
 
   return getAccountDetail(PUBLISHED_ADDRESS);
 
435
   return accountDetail(Account::MapField::PUBLISHED_ADDRESS);
383
436
}
384
437
 
385
438
///Return the account published port
386
 
int Account::getPublishedPort() const
 
439
int Account::publishedPort() const
387
440
{
388
 
   return getAccountDetail(PUBLISHED_PORT).toUInt();
 
441
   return accountDetail(Account::MapField::PUBLISHED_PORT).toUInt();
389
442
}
390
443
 
391
444
///Return the account tls password
392
 
QString Account::getTlsPassword() const
 
445
QString Account::tlsPassword() const
393
446
{
394
 
   return getAccountDetail(TLS_PASSWORD);
 
447
   return accountDetail(Account::MapField::TLS::PASSWORD);
395
448
}
396
449
 
397
450
///Return the account TLS port
398
 
int Account::getTlsListenerPort() const
 
451
int Account::tlsListenerPort() const
399
452
{
400
 
   return getAccountDetail(TLS_LISTENER_PORT).toInt();
 
453
   return accountDetail(Account::MapField::TLS::LISTENER_PORT).toInt();
401
454
}
402
455
 
403
456
///Return the account TLS certificate authority list file
404
 
QString Account::getTlsCaListFile() const
 
457
QString Account::tlsCaListFile() const
405
458
{
406
 
   return getAccountDetail(TLS_CA_LIST_FILE);
 
459
   return accountDetail(Account::MapField::TLS::CA_LIST_FILE);
407
460
}
408
461
 
409
462
///Return the account TLS certificate
410
 
QString Account::getTlsCertificateFile() const
 
463
QString Account::tlsCertificateFile() const
411
464
{
412
 
   return getAccountDetail(TLS_CERTIFICATE_FILE);
 
465
   return accountDetail(Account::MapField::TLS::CERTIFICATE_FILE);
413
466
}
414
467
 
415
468
///Return the account private key
416
 
QString Account::getTlsPrivateKeyFile() const
 
469
QString Account::tlsPrivateKeyFile() const
417
470
{
418
 
   return getAccountDetail(TLS_PRIVATE_KEY_FILE);
 
471
   return accountDetail(Account::MapField::TLS::PRIVATE_KEY_FILE);
419
472
}
420
473
 
421
474
///Return the account cipher
422
 
QString Account::getTlsCiphers() const
 
475
QString Account::tlsCiphers() const
423
476
{
424
 
   return getAccountDetail(TLS_CIPHERS);
 
477
   return accountDetail(Account::MapField::TLS::CIPHERS);
425
478
}
426
479
 
427
480
///Return the account TLS server name
428
 
QString Account::getTlsServerName() const
 
481
QString Account::tlsServerName() const
429
482
{
430
 
   return getAccountDetail(TLS_SERVER_NAME);
 
483
   return accountDetail(Account::MapField::TLS::SERVER_NAME);
431
484
}
432
485
 
433
486
///Return the account negotiation timeout in seconds
434
 
int Account::getTlsNegotiationTimeoutSec() const
 
487
int Account::tlsNegotiationTimeoutSec() const
435
488
{
436
 
   return getAccountDetail(TLS_NEGOTIATION_TIMEOUT_SEC).toInt();
 
489
   return accountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_SEC).toInt();
437
490
}
438
491
 
439
492
///Return the account negotiation timeout in milliseconds
440
 
int Account::getTlsNegotiationTimeoutMsec() const
 
493
int Account::tlsNegotiationTimeoutMsec() const
441
494
{
442
 
   return getAccountDetail(TLS_NEGOTIATION_TIMEOUT_MSEC).toInt();
 
495
   return accountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_MSEC).toInt();
443
496
}
444
497
 
445
498
///Return the account TLS verify server
446
499
bool Account::isTlsVerifyServer() const
447
500
{
448
 
   return (getAccountDetail(TLS_VERIFY_SERVER)  == "true")?1:0;
 
501
   return (accountDetail(Account::MapField::TLS::VERIFY_SERVER) IS_TRUE);
449
502
}
450
503
 
451
504
///Return the account TLS verify client
452
505
bool Account::isTlsVerifyClient() const
453
506
{
454
 
   return (getAccountDetail(TLS_VERIFY_CLIENT)  == "true")?1:0;
 
507
   return (accountDetail(Account::MapField::TLS::VERIFY_CLIENT) IS_TRUE);
455
508
}
456
509
 
457
510
///Return if it is required for the peer to have a certificate
458
511
bool Account::isTlsRequireClientCertificate() const
459
512
{
460
 
   return (getAccountDetail(TLS_REQUIRE_CLIENT_CERTIFICATE)  == "true")?1:0;
 
513
   return (accountDetail(Account::MapField::TLS::REQUIRE_CLIENT_CERTIFICATE) IS_TRUE);
461
514
}
462
515
 
463
516
///Return the account TLS security is enabled
464
517
bool Account::isTlsEnable() const
465
518
466
 
   return (getAccountDetail(TLS_ENABLE)  == "true")?1:0;
 
519
   return (accountDetail(Account::MapField::TLS::ENABLE) IS_TRUE);
467
520
}
468
521
 
469
522
///Return the account the TLS encryption method
470
 
int Account::getTlsMethod() const
 
523
TlsMethodModel::Type Account::tlsMethod() const
471
524
{
472
 
   return getAccountDetail(TLS_METHOD).toInt();
 
525
   const QString value = accountDetail(Account::MapField::TLS::METHOD);
 
526
   return TlsMethodModel::fromDaemonName(value);
473
527
}
474
528
 
475
 
///Return the account alias
476
 
QString Account::getAccountAlias() const
 
529
///Return the key exchange mechanism
 
530
KeyExchangeModel::Type Account::keyExchange() const
477
531
{
478
 
   return getAccountDetail(ACCOUNT_ALIAS);
 
532
   return KeyExchangeModel::fromDaemonName(accountDetail(Account::MapField::SRTP::KEY_EXCHANGE));
479
533
}
480
534
 
481
535
///Return if the ringtone are enabled
482
536
bool Account::isRingtoneEnabled() const
483
537
{
484
 
   return (getAccountDetail(CONFIG_RINGTONE_ENABLED)  == "true")?1:0;
 
538
   return (accountDetail(Account::MapField::Ringtone::ENABLED) IS_TRUE);
485
539
}
486
540
 
487
541
///Return the account ringtone path
488
 
QString Account::getRingtonePath() const
489
 
{
490
 
   return getAccountDetail(CONFIG_RINGTONE_PATH);
 
542
QString Account::ringtonePath() const
 
543
{
 
544
   return accountDetail(Account::MapField::Ringtone::PATH);
 
545
}
 
546
 
 
547
///Return the last error message received
 
548
QString Account::lastErrorMessage() const
 
549
{
 
550
   return m_LastErrorMessage;
 
551
}
 
552
 
 
553
///Return the last error code (useful for debugging)
 
554
int Account::lastErrorCode() const
 
555
{
 
556
   return m_LastErrorCode;
491
557
}
492
558
 
493
559
///Return the account local port
494
 
int Account::getLocalPort() const
495
 
{
496
 
   return getAccountDetail(LOCAL_PORT).toInt();
 
560
int Account::localPort() const
 
561
{
 
562
   return accountDetail(Account::MapField::LOCAL_PORT).toInt();
 
563
}
 
564
 
 
565
///Return the number of voicemails
 
566
int Account::voiceMailCount() const
 
567
{
 
568
   return m_VoiceMailCount;
497
569
}
498
570
 
499
571
///Return the account local interface
500
 
QString Account::getLocalInterface() const
 
572
QString Account::localInterface() const
501
573
{
502
 
   return getAccountDetail(LOCAL_INTERFACE);
 
574
   return accountDetail(Account::MapField::LOCAL_INTERFACE);
503
575
}
504
576
 
505
577
///Return the account registration status
506
 
QString Account::getAccountRegistrationStatus() const
 
578
QString Account::registrationStatus() const
507
579
{
508
 
   return getAccountDetail(ACCOUNT_REGISTRATION_STATUS);
 
580
   return accountDetail(Account::MapField::Registration::STATUS);
509
581
}
510
582
 
511
583
///Return the account type
512
 
QString Account::getAccountType() const
 
584
Account::Protocol Account::protocol() const
513
585
{
514
 
   return getAccountDetail(ACCOUNT_TYPE);
 
586
   const QString str = accountDetail(Account::MapField::TYPE);
 
587
   if (str.isEmpty() || str == Account::ProtocolName::SIP)
 
588
      return Account::Protocol::SIP;
 
589
   else if (str == Account::ProtocolName::IAX)
 
590
      return Account::Protocol::IAX;
 
591
   qDebug() << "Warning: unhandled protocol name" << str << ", defaulting to SIP";
 
592
   return Account::Protocol::SIP;
515
593
}
516
594
 
517
595
///Return the DTMF type
518
 
DtmfType Account::getDTMFType() const
 
596
DtmfType Account::DTMFType() const
519
597
{
520
 
   QString type = getAccountDetail(ACCOUNT_DTMF_TYPE);
 
598
   QString type = accountDetail(Account::MapField::DTMF_TYPE);
521
599
   return (type == "overrtp" || type.isEmpty())? DtmfType::OverRtp:DtmfType::OverSip;
522
600
}
523
601
 
 
602
bool Account::presenceStatus() const
 
603
{
 
604
   return m_pAccountNumber->isPresent();
 
605
}
 
606
 
 
607
QString Account::presenceMessage() const
 
608
{
 
609
   return m_pAccountNumber->presenceMessage();
 
610
}
 
611
 
 
612
bool Account::supportPresencePublish() const
 
613
{
 
614
   return accountDetail(Account::MapField::Presence::SUPPORT_PUBLISH) IS_TRUE;
 
615
}
 
616
 
 
617
bool Account::supportPresenceSubscribe() const
 
618
{
 
619
   return accountDetail(Account::MapField::Presence::SUPPORT_SUBSCRIBE) IS_TRUE;
 
620
}
 
621
 
 
622
bool Account::presenceEnabled() const
 
623
{
 
624
   return accountDetail(Account::MapField::Presence::ENABLE) IS_TRUE;
 
625
}
 
626
 
 
627
QVariant Account::roleData(int role) const
 
628
{
 
629
   switch(role) {
 
630
      case Account::Role::Alias:
 
631
         return alias();
 
632
      case Account::Role::Proto:
 
633
         return static_cast<int>(protocol());
 
634
      case Account::Role::Hostname:
 
635
         return hostname();
 
636
      case Account::Role::Username:
 
637
         return username();
 
638
      case Account::Role::Mailbox:
 
639
         return mailbox();
 
640
      case Account::Role::Proxy:
 
641
         return proxy();
 
642
//       case Password:
 
643
//          return accountPassword();
 
644
      case Account::Role::TlsPassword:
 
645
         return tlsPassword();
 
646
      case Account::Role::TlsCaListFile:
 
647
         return tlsCaListFile();
 
648
      case Account::Role::TlsCertificateFile:
 
649
         return tlsCertificateFile();
 
650
      case Account::Role::TlsPrivateKeyFile:
 
651
         return tlsPrivateKeyFile();
 
652
      case Account::Role::TlsCiphers:
 
653
         return tlsCiphers();
 
654
      case Account::Role::TlsServerName:
 
655
         return tlsServerName();
 
656
      case Account::Role::SipStunServer:
 
657
         return sipStunServer();
 
658
      case Account::Role::PublishedAddress:
 
659
         return publishedAddress();
 
660
      case Account::Role::LocalInterface:
 
661
         return localInterface();
 
662
      case Account::Role::RingtonePath:
 
663
         return ringtonePath();
 
664
      case Account::Role::TlsMethod:
 
665
         return static_cast<int>(tlsMethod());
 
666
      case Account::Role::RegistrationExpire:
 
667
         return registrationExpire();
 
668
      case Account::Role::TlsNegotiationTimeoutSec:
 
669
         return tlsNegotiationTimeoutSec();
 
670
      case Account::Role::TlsNegotiationTimeoutMsec:
 
671
         return tlsNegotiationTimeoutMsec();
 
672
      case Account::Role::LocalPort:
 
673
         return localPort();
 
674
      case Account::Role::TlsListenerPort:
 
675
         return tlsListenerPort();
 
676
      case Account::Role::PublishedPort:
 
677
         return publishedPort();
 
678
      case Account::Role::Enabled:
 
679
         return isEnabled();
 
680
      case Account::Role::AutoAnswer:
 
681
         return isAutoAnswer();
 
682
      case Account::Role::TlsVerifyServer:
 
683
         return isTlsVerifyServer();
 
684
      case Account::Role::TlsVerifyClient:
 
685
         return isTlsVerifyClient();
 
686
      case Account::Role::TlsRequireClientCertificate:
 
687
         return isTlsRequireClientCertificate();
 
688
      case Account::Role::TlsEnable:
 
689
         return isTlsEnable();
 
690
      case Account::Role::DisplaySasOnce:
 
691
         return isDisplaySasOnce();
 
692
      case Account::Role::SrtpRtpFallback:
 
693
         return isSrtpRtpFallback();
 
694
      case Account::Role::ZrtpDisplaySas:
 
695
         return isZrtpDisplaySas();
 
696
      case Account::Role::ZrtpNotSuppWarning:
 
697
         return isZrtpNotSuppWarning();
 
698
      case Account::Role::ZrtpHelloHash:
 
699
         return isZrtpHelloHash();
 
700
      case Account::Role::SipStunEnabled:
 
701
         return isSipStunEnabled();
 
702
      case Account::Role::PublishedSameAsLocal:
 
703
         return isPublishedSameAsLocal();
 
704
      case Account::Role::RingtoneEnabled:
 
705
         return isRingtoneEnabled();
 
706
      case Account::Role::dTMFType:
 
707
         return DTMFType();
 
708
      case Account::Role::Id:
 
709
         return id();
 
710
      case Account::Role::Object: {
 
711
         QVariant var;
 
712
         var.setValue(const_cast<Account*>(this));
 
713
         return var;
 
714
      }
 
715
      case Account::Role::TypeName:
 
716
         return static_cast<int>(protocol());
 
717
      case Account::Role::PresenceStatus:
 
718
         return PresenceStatusModel::instance()->currentStatus();
 
719
      case Account::Role::PresenceMessage:
 
720
         return PresenceStatusModel::instance()->currentMessage();
 
721
      default:
 
722
         return QVariant();
 
723
   }
 
724
}
 
725
 
524
726
 
525
727
/*****************************************************************************
526
728
 *                                                                           *
529
731
 ****************************************************************************/
530
732
 
531
733
///Set account details
532
 
void Account::setAccountDetails(const MapStringString& m)
 
734
void Account::setAccountDetails(const QHash<QString,QString>& m)
533
735
{
534
 
   if (m_pAccountDetails)
535
 
      delete m_pAccountDetails;
536
 
   *m_pAccountDetails = m;
 
736
   m_hAccountDetails.clear();
 
737
   m_hAccountDetails = m;
 
738
   m_HostName = m[Account::MapField::HOSTNAME];
537
739
}
538
740
 
539
741
///Set a specific detail
540
742
bool Account::setAccountDetail(const QString& param, const QString& val)
541
743
{
542
 
   bool changed = (*m_pAccountDetails)[param] != val;
543
 
   QString buf = (*m_pAccountDetails)[param];
544
 
   if (param == ACCOUNT_REGISTRATION_STATUS) {
545
 
      (*m_pAccountDetails)[param] = val;
546
 
      if (changed) {
 
744
   const bool accChanged = m_hAccountDetails[param] != val;
 
745
   const QString buf = m_hAccountDetails[param];
 
746
   if (param == Account::MapField::Registration::STATUS) {
 
747
      m_hAccountDetails[param] = val;
 
748
      if (accChanged) {
547
749
         emit detailChanged(this,param,val,buf);
548
750
      }
549
751
   }
550
752
   else {
551
753
      performAction(AccountEditAction::MODIFY);
552
 
      if (m_CurrentState == MODIFIED || m_CurrentState == NEW) {
553
 
         (*m_pAccountDetails)[param] = val;
554
 
         if (changed) {
 
754
      if (m_CurrentState == AccountEditState::MODIFIED || m_CurrentState == AccountEditState::NEW) {
 
755
         m_hAccountDetails[param] = val;
 
756
         if (accChanged) {
555
757
            emit detailChanged(this,param,val,buf);
556
758
         }
557
759
      }
558
760
   }
559
 
   return m_CurrentState == MODIFIED || m_CurrentState == NEW;
 
761
   return m_CurrentState == AccountEditState::MODIFIED || m_CurrentState == AccountEditState::NEW;
560
762
}
561
763
 
562
764
///Set the account id
563
 
void Account::setAccountId(const QString& id)
 
765
void Account::setId(const QString& id)
564
766
{
565
 
   qDebug() << "Setting accountId = " << m_pAccountId;
 
767
   qDebug() << "Setting accountId = " << m_AccountId;
566
768
   if (! isNew())
567
769
      qDebug() << "Error : setting AccountId of an existing account.";
568
 
   m_pAccountId = new QString(id);
569
 
}
570
 
 
571
 
///Set account enabled
572
 
void Account::setEnabled(bool checked)
573
 
{
574
 
   setAccountEnabled(checked);
575
 
}
576
 
 
577
 
 
578
 
#ifdef ENABLE_VIDEO
579
 
void Account::setActiveVideoCodecList(const QList<VideoCodec*>& codecs);
580
 
QList<VideoCodec*> getActiveVideoCodecList();
581
 
#endif
 
770
   m_AccountId = id;
 
771
}
 
772
 
582
773
///Set the account type, SIP or IAX
583
 
void Account::setAccountType(QString detail)
 
774
void Account::setProtocol(Account::Protocol proto)
584
775
{
585
 
   setAccountDetail(ACCOUNT_TYPE ,detail);
 
776
   switch (proto) {
 
777
      case Account::Protocol::SIP:
 
778
         setAccountDetail(Account::MapField::TYPE ,Account::ProtocolName::SIP);
 
779
         break;
 
780
      case Account::Protocol::IAX:
 
781
         setAccountDetail(Account::MapField::TYPE ,Account::ProtocolName::IAX);
 
782
         break;
 
783
   };
586
784
}
587
785
 
588
786
///The set account hostname, it can be an hostname or an IP address
589
 
void Account::setAccountHostname(QString detail)
 
787
void Account::setHostname(const QString& detail)
590
788
{
591
 
   setAccountDetail(ACCOUNT_HOSTNAME               ,detail);
 
789
   if (m_HostName != detail) {
 
790
      m_HostName = detail;
 
791
      setAccountDetail(Account::MapField::HOSTNAME, detail);
 
792
   }
592
793
}
593
794
 
594
795
///Set the account username, everything is valid, some might be rejected by the PBX server
595
 
void Account::setAccountUsername(QString detail)
596
 
{
597
 
   setAccountDetail(ACCOUNT_USERNAME               ,detail);
598
 
}
599
 
 
600
 
///Set the account mailbox, usually a number, but can be anything
601
 
void Account::setAccountMailbox(QString detail)
602
 
{
603
 
   setAccountDetail(ACCOUNT_MAILBOX                ,detail);
604
 
}
605
 
 
606
 
///Set the account mailbox, usually a number, but can be anything
607
 
void Account::setAccountProxy(QString detail)
608
 
{
609
 
   setAccountDetail(ACCOUNT_ROUTE                  ,detail);
 
796
void Account::setUsername(const QString& detail)
 
797
{
 
798
   setAccountDetail(Account::MapField::USERNAME, detail);
 
799
}
 
800
 
 
801
///Set the account mailbox, usually a number, but can be anything
 
802
void Account::setMailbox(const QString& detail)
 
803
{
 
804
   setAccountDetail(Account::MapField::MAILBOX, detail);
 
805
}
 
806
 
 
807
///Set the account mailbox, usually a number, but can be anything
 
808
void Account::setProxy(const QString& detail)
 
809
{
 
810
   setAccountDetail(Account::MapField::ROUTE, detail);
610
811
}
611
812
 
612
813
///Set the main credential password
613
 
void Account::setAccountPassword(QString detail)
 
814
void Account::setPassword(const QString& detail)
614
815
{
615
 
   setAccountDetail(ACCOUNT_PASSWORD               ,detail);
 
816
   switch (protocol()) {
 
817
      case Account::Protocol::SIP:
 
818
         if (credentialsModel()->rowCount())
 
819
            credentialsModel()->setData(credentialsModel()->index(0,0),detail,CredentialModel::Role::PASSWORD);
 
820
         else {
 
821
            const QModelIndex idx = credentialsModel()->addCredentials();
 
822
            credentialsModel()->setData(idx,detail,CredentialModel::Role::PASSWORD);
 
823
         }
 
824
         break;
 
825
      case Account::Protocol::IAX:
 
826
         setAccountDetail(Account::MapField::PASSWORD, detail);
 
827
         break;
 
828
   };
616
829
}
617
830
 
618
831
///Set the TLS (encryption) password
619
 
void Account::setTlsPassword(QString detail)
 
832
void Account::setTlsPassword(const QString& detail)
620
833
{
621
 
   setAccountDetail(TLS_PASSWORD                   ,detail);
 
834
   setAccountDetail(Account::MapField::TLS::PASSWORD, detail);
622
835
}
623
836
 
624
837
///Set the certificate authority list file
625
 
void Account::setTlsCaListFile(QString detail)
 
838
void Account::setTlsCaListFile(const QString& detail)
626
839
{
627
 
   setAccountDetail(TLS_CA_LIST_FILE               ,detail);
 
840
   setAccountDetail(Account::MapField::TLS::CA_LIST_FILE, detail);
628
841
}
629
842
 
630
843
///Set the certificate
631
 
void Account::setTlsCertificateFile(QString detail)
 
844
void Account::setTlsCertificateFile(const QString& detail)
632
845
{
633
 
   setAccountDetail(TLS_CERTIFICATE_FILE           ,detail);
 
846
   setAccountDetail(Account::MapField::TLS::CERTIFICATE_FILE, detail);
634
847
}
635
848
 
636
849
///Set the private key
637
 
void Account::setTlsPrivateKeyFile(QString detail)
 
850
void Account::setTlsPrivateKeyFile(const QString& detail)
638
851
{
639
 
   setAccountDetail(TLS_PRIVATE_KEY_FILE           ,detail);
 
852
   setAccountDetail(Account::MapField::TLS::PRIVATE_KEY_FILE, detail);
640
853
}
641
854
 
642
855
///Set the TLS cipher
643
 
void Account::setTlsCiphers(QString detail)
 
856
void Account::setTlsCiphers(const QString& detail)
644
857
{
645
 
   setAccountDetail(TLS_CIPHERS                    ,detail);
 
858
   setAccountDetail(Account::MapField::TLS::CIPHERS, detail);
646
859
}
647
860
 
648
861
///Set the TLS server
649
 
void Account::setTlsServerName(QString detail)
 
862
void Account::setTlsServerName(const QString& detail)
650
863
{
651
 
   setAccountDetail(TLS_SERVER_NAME                ,detail);
 
864
   setAccountDetail(Account::MapField::TLS::SERVER_NAME, detail);
652
865
}
653
866
 
654
867
///Set the stun server
655
 
void Account::setAccountSipStunServer(QString detail)
 
868
void Account::setSipStunServer(const QString& detail)
656
869
{
657
 
   setAccountDetail(ACCOUNT_SIP_STUN_SERVER        ,detail);
 
870
   setAccountDetail(Account::MapField::STUN::SERVER, detail);
658
871
}
659
872
 
660
873
///Set the published address
661
 
void Account::setPublishedAddress(QString detail)
 
874
void Account::setPublishedAddress(const QString& detail)
662
875
{
663
 
   setAccountDetail(PUBLISHED_ADDRESS              ,detail);
 
876
   setAccountDetail(Account::MapField::PUBLISHED_ADDRESS, detail);
664
877
}
665
878
 
666
879
///Set the local interface
667
 
void Account::setLocalInterface(QString detail)
 
880
void Account::setLocalInterface(const QString& detail)
668
881
{
669
 
   setAccountDetail(LOCAL_INTERFACE                ,detail);
 
882
   setAccountDetail(Account::MapField::LOCAL_INTERFACE, detail);
670
883
}
671
884
 
672
885
///Set the ringtone path, it have to be a valid absolute path
673
 
void Account::setRingtonePath(QString detail)
674
 
{
675
 
   setAccountDetail(CONFIG_RINGTONE_PATH           ,detail);
676
 
}
677
 
 
678
 
///Set the Tls method
679
 
void Account::setTlsMethod(int detail)
680
 
{
681
 
   setAccountDetail(TLS_METHOD ,QString::number(detail));
 
886
void Account::setRingtonePath(const QString& detail)
 
887
{
 
888
   setAccountDetail(Account::MapField::Ringtone::PATH, detail);
 
889
}
 
890
 
 
891
///Set the number of voice mails
 
892
void Account::setVoiceMailCount(int count)
 
893
{
 
894
   m_VoiceMailCount = count;
 
895
}
 
896
 
 
897
///Set the last error message to be displayed as status instead of "Error"
 
898
void Account::setLastErrorMessage(const QString& message)
 
899
{
 
900
   m_LastErrorMessage = message;
 
901
}
 
902
 
 
903
///Set the last error code
 
904
void Account::setLastErrorCode(int code)
 
905
{
 
906
   m_LastErrorCode = code;
 
907
}
 
908
 
 
909
///Set the Tls method
 
910
void Account::setTlsMethod(TlsMethodModel::Type detail)
 
911
{
 
912
   
 
913
   setAccountDetail(Account::MapField::TLS::METHOD ,TlsMethodModel::toDaemonName(detail));
 
914
}
 
915
 
 
916
///Set the Tls method
 
917
void Account::setKeyExchange(KeyExchangeModel::Type detail)
 
918
{
 
919
   setAccountDetail(Account::MapField::SRTP::KEY_EXCHANGE ,KeyExchangeModel::toDaemonName(detail));
682
920
}
683
921
 
684
922
///Set the account timeout, it will be renegotiated when that timeout occur
685
 
void Account::setAccountRegistrationExpire(int detail)
 
923
void Account::setRegistrationExpire(int detail)
686
924
{
687
 
   setAccountDetail(ACCOUNT_REGISTRATION_EXPIRE    ,QString::number(detail));
 
925
   setAccountDetail(Account::MapField::Registration::EXPIRE, QString::number(detail));
688
926
}
689
927
 
690
928
///Set TLS negotiation timeout in second
691
929
void Account::setTlsNegotiationTimeoutSec(int detail)
692
930
{
693
 
   setAccountDetail(TLS_NEGOTIATION_TIMEOUT_SEC    ,QString::number(detail));
 
931
   setAccountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_SEC, QString::number(detail));
694
932
}
695
933
 
696
934
///Set the TLS negotiation timeout in milliseconds
697
935
void Account::setTlsNegotiationTimeoutMsec(int detail)
698
936
{
699
 
   setAccountDetail(TLS_NEGOTIATION_TIMEOUT_MSEC   ,QString::number(detail));
 
937
   setAccountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_MSEC, QString::number(detail));
700
938
}
701
939
 
702
940
///Set the local port for SIP/IAX communications
703
941
void Account::setLocalPort(unsigned short detail)
704
942
{
705
 
   setAccountDetail(LOCAL_PORT              ,QString::number(detail));
 
943
   setAccountDetail(Account::MapField::LOCAL_PORT, QString::number(detail));
706
944
}
707
945
 
708
946
///Set the TLS listener port (0-2^16)
709
947
void Account::setTlsListenerPort(unsigned short detail)
710
948
{
711
 
   setAccountDetail(TLS_LISTENER_PORT       ,QString::number(detail));
 
949
   setAccountDetail(Account::MapField::TLS::LISTENER_PORT, QString::number(detail));
712
950
}
713
951
 
714
952
///Set the published port (0-2^16)
715
953
void Account::setPublishedPort(unsigned short detail)
716
954
{
717
 
   setAccountDetail(PUBLISHED_PORT          ,QString::number(detail));
 
955
   setAccountDetail(Account::MapField::PUBLISHED_PORT, QString::number(detail));
718
956
}
719
957
 
720
958
///Set if the account is enabled or not
721
 
void Account::setAccountEnabled(bool detail)
 
959
void Account::setEnabled(bool detail)
722
960
{
723
 
   setAccountDetail(ACCOUNT_ENABLED                ,detail?"true":"false");
 
961
   setAccountDetail(Account::MapField::ENABLED, (detail)TO_BOOL);
724
962
}
725
963
 
726
964
///Set if the account should auto answer
727
965
void Account::setAutoAnswer(bool detail)
728
966
{
729
 
   setAccountDetail(ACCOUNT_AUTOANSWER             ,detail?"true":"false");
 
967
   setAccountDetail(Account::MapField::AUTOANSWER, (detail)TO_BOOL);
730
968
}
731
969
 
732
970
///Set the TLS verification server
733
971
void Account::setTlsVerifyServer(bool detail)
734
972
{
735
 
   setAccountDetail(TLS_VERIFY_SERVER              ,detail?"true":"false");
 
973
   setAccountDetail(Account::MapField::TLS::VERIFY_SERVER, (detail)TO_BOOL);
736
974
}
737
975
 
738
976
///Set the TLS verification client
739
977
void Account::setTlsVerifyClient(bool detail)
740
978
{
741
 
   setAccountDetail(TLS_VERIFY_CLIENT              ,detail?"true":"false");
 
979
   setAccountDetail(Account::MapField::TLS::VERIFY_CLIENT, (detail)TO_BOOL);
742
980
}
743
981
 
744
982
///Set if the peer need to be providing a certificate
745
983
void Account::setTlsRequireClientCertificate(bool detail)
746
984
{
747
 
   setAccountDetail(TLS_REQUIRE_CLIENT_CERTIFICATE ,detail?"true":"false");
 
985
   setAccountDetail(Account::MapField::TLS::REQUIRE_CLIENT_CERTIFICATE ,(detail)TO_BOOL);
748
986
}
749
987
 
750
988
///Set if the security settings are enabled
751
989
void Account::setTlsEnable(bool detail)
752
990
{
753
 
   setAccountDetail(TLS_ENABLE ,detail?"true":"false");
754
 
}
755
 
 
756
 
void Account::setAccountDisplaySasOnce(bool detail)
757
 
{
758
 
   setAccountDetail(ACCOUNT_DISPLAY_SAS_ONCE       ,detail?"true":"false");
759
 
}
760
 
 
761
 
void Account::setAccountSrtpRtpFallback(bool detail)
762
 
{
763
 
   setAccountDetail(ACCOUNT_SRTP_RTP_FALLBACK      ,detail?"true":"false");
764
 
}
765
 
 
766
 
void Account::setAccountZrtpDisplaySas(bool detail)
767
 
{
768
 
   setAccountDetail(ACCOUNT_ZRTP_DISPLAY_SAS       ,detail?"true":"false");
769
 
}
770
 
 
771
 
void Account::setAccountZrtpNotSuppWarning(bool detail)
772
 
{
773
 
   setAccountDetail(ACCOUNT_ZRTP_NOT_SUPP_WARNING  ,detail?"true":"false");
774
 
}
775
 
 
776
 
void Account::setAccountZrtpHelloHash(bool detail)
777
 
{
778
 
   setAccountDetail(ACCOUNT_ZRTP_HELLO_HASH        ,detail?"true":"false");
779
 
}
780
 
 
781
 
void Account::setAccountSipStunEnabled(bool detail)
782
 
{
783
 
   setAccountDetail(ACCOUNT_SIP_STUN_ENABLED       ,detail?"true":"false");
 
991
   setAccountDetail(Account::MapField::TLS::ENABLE ,(detail)TO_BOOL);
 
992
}
 
993
 
 
994
void Account::setDisplaySasOnce(bool detail)
 
995
{
 
996
   setAccountDetail(Account::MapField::ZRTP::DISPLAY_SAS_ONCE, (detail)TO_BOOL);
 
997
}
 
998
 
 
999
void Account::setSrtpRtpFallback(bool detail)
 
1000
{
 
1001
   setAccountDetail(Account::MapField::SRTP::RTP_FALLBACK, (detail)TO_BOOL);
 
1002
}
 
1003
 
 
1004
void Account::setSrtpEnabled(bool detail)
 
1005
{
 
1006
   setAccountDetail(Account::MapField::SRTP::ENABLED, (detail)TO_BOOL);
 
1007
}
 
1008
 
 
1009
void Account::setZrtpDisplaySas(bool detail)
 
1010
{
 
1011
   setAccountDetail(Account::MapField::ZRTP::DISPLAY_SAS, (detail)TO_BOOL);
 
1012
}
 
1013
 
 
1014
void Account::setZrtpNotSuppWarning(bool detail)
 
1015
{
 
1016
   setAccountDetail(Account::MapField::ZRTP::NOT_SUPP_WARNING, (detail)TO_BOOL);
 
1017
}
 
1018
 
 
1019
void Account::setZrtpHelloHash(bool detail)
 
1020
{
 
1021
   setAccountDetail(Account::MapField::ZRTP::HELLO_HASH, (detail)TO_BOOL);
 
1022
}
 
1023
 
 
1024
void Account::setSipStunEnabled(bool detail)
 
1025
{
 
1026
   setAccountDetail(Account::MapField::STUN::ENABLED, (detail)TO_BOOL);
784
1027
}
785
1028
 
786
1029
void Account::setPublishedSameAsLocal(bool detail)
787
1030
{
788
 
   setAccountDetail(PUBLISHED_SAMEAS_LOCAL         ,detail?"true":"false");
 
1031
   setAccountDetail(Account::MapField::PUBLISHED_SAMEAS_LOCAL, (detail)TO_BOOL);
789
1032
}
790
1033
 
791
1034
///Set if custom ringtone are enabled
792
1035
void Account::setRingtoneEnabled(bool detail)
793
1036
{
794
 
   setAccountDetail(CONFIG_RINGTONE_ENABLED        ,detail?"true":"false");
 
1037
   setAccountDetail(Account::MapField::Ringtone::ENABLED, (detail)TO_BOOL);
 
1038
}
 
1039
 
 
1040
void Account::setPresenceEnabled(bool enable)
 
1041
{
 
1042
   setAccountDetail(Account::MapField::Presence::ENABLE, (enable)TO_BOOL);
795
1043
}
796
1044
 
797
1045
///Set the DTMF type
798
1046
void Account::setDTMFType(DtmfType type)
799
1047
{
800
 
   setAccountDetail(ACCOUNT_DTMF_TYPE,(type==OverRtp)?"overrtp":"oversip");
 
1048
   setAccountDetail(Account::MapField::DTMF_TYPE,(type==OverRtp)?"overrtp":"oversip");
 
1049
}
 
1050
 
 
1051
void Account::setRoleData(int role, const QVariant& value)
 
1052
{
 
1053
   switch(role) {
 
1054
      case Account::Role::Alias:
 
1055
         setAlias(value.toString());
 
1056
      case Account::Role::Proto: {
 
1057
         const int proto = value.toInt();
 
1058
         setProtocol((proto>=0&&proto<=1)?static_cast<Account::Protocol>(proto):Account::Protocol::SIP);
 
1059
      }
 
1060
      case Account::Role::Hostname:
 
1061
         setHostname(value.toString());
 
1062
      case Account::Role::Username:
 
1063
         setUsername(value.toString());
 
1064
      case Account::Role::Mailbox:
 
1065
         setMailbox(value.toString());
 
1066
      case Account::Role::Proxy:
 
1067
         setProxy(value.toString());
 
1068
//       case Password:
 
1069
//          accountPassword();
 
1070
      case Account::Role::TlsPassword:
 
1071
         setTlsPassword(value.toString());
 
1072
      case Account::Role::TlsCaListFile:
 
1073
         setTlsCaListFile(value.toString());
 
1074
      case Account::Role::TlsCertificateFile:
 
1075
         setTlsCertificateFile(value.toString());
 
1076
      case Account::Role::TlsPrivateKeyFile:
 
1077
         setTlsPrivateKeyFile(value.toString());
 
1078
      case Account::Role::TlsCiphers:
 
1079
         setTlsCiphers(value.toString());
 
1080
      case Account::Role::TlsServerName:
 
1081
         setTlsServerName(value.toString());
 
1082
      case Account::Role::SipStunServer:
 
1083
         setSipStunServer(value.toString());
 
1084
      case Account::Role::PublishedAddress:
 
1085
         setPublishedAddress(value.toString());
 
1086
      case Account::Role::LocalInterface:
 
1087
         setLocalInterface(value.toString());
 
1088
      case Account::Role::RingtonePath:
 
1089
         setRingtonePath(value.toString());
 
1090
      case Account::Role::TlsMethod: {
 
1091
         const int method = value.toInt();
 
1092
         setTlsMethod(method<=TlsMethodModel::instance()->rowCount()?static_cast<TlsMethodModel::Type>(method):TlsMethodModel::Type::DEFAULT);
 
1093
      }
 
1094
      case Account::Role::KeyExchange: {
 
1095
         const int method = value.toInt();
 
1096
         setKeyExchange(method<=keyExchangeModel()->rowCount()?static_cast<KeyExchangeModel::Type>(method):KeyExchangeModel::Type::NONE);
 
1097
      }
 
1098
      case Account::Role::RegistrationExpire:
 
1099
         setRegistrationExpire(value.toInt());
 
1100
      case Account::Role::TlsNegotiationTimeoutSec:
 
1101
         setTlsNegotiationTimeoutSec(value.toInt());
 
1102
      case Account::Role::TlsNegotiationTimeoutMsec:
 
1103
         setTlsNegotiationTimeoutMsec(value.toInt());
 
1104
      case Account::Role::LocalPort:
 
1105
         setLocalPort(value.toInt());
 
1106
      case Account::Role::TlsListenerPort:
 
1107
         setTlsListenerPort(value.toInt());
 
1108
      case Account::Role::PublishedPort:
 
1109
         setPublishedPort(value.toInt());
 
1110
      case Account::Role::Enabled:
 
1111
         setEnabled(value.toBool());
 
1112
      case Account::Role::AutoAnswer:
 
1113
         setAutoAnswer(value.toBool());
 
1114
      case Account::Role::TlsVerifyServer:
 
1115
         setTlsVerifyServer(value.toBool());
 
1116
      case Account::Role::TlsVerifyClient:
 
1117
         setTlsVerifyClient(value.toBool());
 
1118
      case Account::Role::TlsRequireClientCertificate:
 
1119
         setTlsRequireClientCertificate(value.toBool());
 
1120
      case Account::Role::TlsEnable:
 
1121
         setTlsEnable(value.toBool());
 
1122
      case Account::Role::DisplaySasOnce:
 
1123
         setDisplaySasOnce(value.toBool());
 
1124
      case Account::Role::SrtpRtpFallback:
 
1125
         setSrtpRtpFallback(value.toBool());
 
1126
      case Account::Role::ZrtpDisplaySas:
 
1127
         setZrtpDisplaySas(value.toBool());
 
1128
      case Account::Role::ZrtpNotSuppWarning:
 
1129
         setZrtpNotSuppWarning(value.toBool());
 
1130
      case Account::Role::ZrtpHelloHash:
 
1131
         setZrtpHelloHash(value.toBool());
 
1132
      case Account::Role::SipStunEnabled:
 
1133
         setSipStunEnabled(value.toBool());
 
1134
      case Account::Role::PublishedSameAsLocal:
 
1135
         setPublishedSameAsLocal(value.toBool());
 
1136
      case Account::Role::RingtoneEnabled:
 
1137
         setRingtoneEnabled(value.toBool());
 
1138
      case Account::Role::dTMFType:
 
1139
         setDTMFType((DtmfType)value.toInt());
 
1140
      case Account::Role::Id:
 
1141
         setId(value.toString());
 
1142
   }
801
1143
}
802
1144
 
803
1145
 
810
1152
bool Account::performAction(AccountEditAction action)
811
1153
{
812
1154
   AccountEditState curState = m_CurrentState;
813
 
   (this->*(stateMachineActionsOnState[m_CurrentState][action]))();
 
1155
   (this->*(stateMachineActionsOnState[(int)m_CurrentState][(int)action]))();//FIXME don't use integer cast
814
1156
   return curState != m_CurrentState;
815
1157
}
816
1158
 
817
 
AccountEditState Account::currentState() const
 
1159
Account::AccountEditState Account::state() const
818
1160
{
819
1161
   return m_CurrentState;
820
 
};
 
1162
}
821
1163
 
822
1164
/**Update the account
823
1165
 * @return if the state changed
825
1167
bool Account::updateState()
826
1168
{
827
1169
   if(! isNew()) {
828
 
      ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
829
 
      MapStringString details       = configurationManager.getAccountDetails(getAccountId()).value();
830
 
      QString         status        = details[ACCOUNT_REGISTRATION_STATUS];
831
 
      QString         currentStatus = getAccountRegistrationStatus();
832
 
      setAccountDetail(ACCOUNT_REGISTRATION_STATUS, status); //Update -internal- object state
 
1170
      ConfigurationManagerInterface & configurationManager = DBus::ConfigurationManager::instance();
 
1171
      const MapStringString details       = configurationManager.getAccountDetails(id()).value();
 
1172
      const QString         status        = details[Account::MapField::Registration::STATUS];
 
1173
      const QString         currentStatus = registrationStatus();
 
1174
      setAccountDetail(Account::MapField::Registration::STATUS, status); //Update -internal- object state
833
1175
      return status == currentStatus;
834
1176
   }
835
1177
   return true;
838
1180
///Save the current account to the daemon
839
1181
void Account::save()
840
1182
{
841
 
   ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
 
1183
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
842
1184
   if (isNew()) {
843
 
      MapStringString details = getAccountDetails();
844
 
      QString currentId = configurationManager.addAccount(details);
 
1185
      MapStringString details;
 
1186
      QMutableHashIterator<QString,QString> iter(m_hAccountDetails);
 
1187
 
 
1188
      while (iter.hasNext()) {
 
1189
         iter.next();
 
1190
         details[iter.key()] = iter.value();
 
1191
      }
 
1192
 
 
1193
      const QString currentId = configurationManager.addAccount(details);
845
1194
 
846
1195
      //Be sure there is audio codec enabled to avoid obscure error messages for the user
847
 
      QVector<int> codecIdList = configurationManager.getAudioCodecList();
 
1196
      const QVector<int> codecIdList = configurationManager.getAudioCodecList();
848
1197
      foreach (const int aCodec, codecIdList) {
849
 
         QStringList codec = configurationManager.getAudioCodecDetails(aCodec);
850
 
         QModelIndex idx = m_pAudioCodecs->addAudioCodec();
851
 
         m_pAudioCodecs->setData(idx,codec[0],AudioCodecModel::NAME_ROLE       );
852
 
         m_pAudioCodecs->setData(idx,codec[1],AudioCodecModel::SAMPLERATE_ROLE );
853
 
         m_pAudioCodecs->setData(idx,codec[2],AudioCodecModel::BITRATE_ROLE    );
854
 
         m_pAudioCodecs->setData(idx,aCodec  ,AudioCodecModel::ID_ROLE         );
 
1198
         const QStringList codec = configurationManager.getAudioCodecDetails(aCodec);
 
1199
         const QModelIndex idx = m_pAudioCodecs->addAudioCodec();
 
1200
         m_pAudioCodecs->setData(idx,codec[0],AudioCodecModel::Role::NAME       );
 
1201
         m_pAudioCodecs->setData(idx,codec[1],AudioCodecModel::Role::SAMPLERATE );
 
1202
         m_pAudioCodecs->setData(idx,codec[2],AudioCodecModel::Role::BITRATE    );
 
1203
         m_pAudioCodecs->setData(idx,aCodec  ,AudioCodecModel::Role::ID         );
855
1204
         m_pAudioCodecs->setData(idx, Qt::Checked ,Qt::CheckStateRole);
856
1205
      }
857
1206
      saveAudioCodecs();
858
1207
 
859
 
      setAccountId(currentId);
 
1208
      setId(currentId);
860
1209
      saveCredentials();
861
 
   }
862
 
   else {
863
 
      configurationManager.setAccountDetails(getAccountId(), getAccountDetails());
864
 
   }
865
 
 
866
 
   //QString id = configurationManager.getAccountDetail(getAccountId());
867
 
   if (!getAccountId().isEmpty()) {
868
 
      Account* acc =  AccountList::getInstance()->getAccountById(getAccountId());
869
 
      qDebug() << "Adding the new account to the account list (" << getAccountId() << ")";
 
1210
   } //New account
 
1211
   else { //Existing account
 
1212
      MapStringString tmp;
 
1213
      QMutableHashIterator<QString,QString> iter(m_hAccountDetails);
 
1214
 
 
1215
      while (iter.hasNext()) {
 
1216
         iter.next();
 
1217
         tmp[iter.key()] = iter.value();
 
1218
      }
 
1219
      configurationManager.setAccountDetails(id(), tmp);
 
1220
   }
 
1221
 
 
1222
   if (!id().isEmpty()) {
 
1223
      Account* acc =  AccountListModel::instance()->getAccountById(id());
 
1224
      qDebug() << "Adding the new account to the account list (" << id() << ")";
870
1225
      if (acc != this) {
871
 
         (*AccountList::getInstance()->m_pAccounts) << this;
 
1226
         (AccountListModel::instance()->m_lAccounts) << this;
872
1227
      }
873
1228
 
874
1229
      performAction(AccountEditAction::RELOAD);
875
1230
      updateState();
876
 
      m_CurrentState = READY;
 
1231
      m_CurrentState = AccountEditState::READY;
877
1232
   }
878
1233
   #ifdef ENABLE_VIDEO
879
 
   m_pVideoCodecs->save();
 
1234
   videoCodecModel()->save();
880
1235
   #endif
881
1236
   saveAudioCodecs();
882
1237
   emit changed(this);
885
1240
///sync with the daemon, this need to be done manually to prevent reloading the account while it is being edited
886
1241
void Account::reload()
887
1242
{
888
 
   qDebug() << "Reloading" << getAccountId();
889
 
   ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
890
 
   QMap<QString,QString> aDetails = configurationManager.getAccountDetails(getAccountId());
891
 
 
892
 
   if (!aDetails.count()) {
893
 
      qDebug() << "Account not found";
894
 
   }
895
 
   else {
896
 
      if (m_pAccountDetails) {
897
 
         delete m_pAccountDetails;
898
 
         m_pAccountDetails = nullptr;
899
 
      }
900
 
      m_pAccountDetails = new MapStringString(aDetails);
901
 
   }
902
 
   m_CurrentState = READY;
903
 
   reloadCredentials();
904
 
   emit changed(this);
 
1243
   if (!isNew()) {
 
1244
      if (m_hAccountDetails.size())
 
1245
         qDebug() << "Reloading" << id() << alias();
 
1246
      else
 
1247
         qDebug() << "Loading" << id();
 
1248
      ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
1249
      QMap<QString,QString> aDetails = configurationManager.getAccountDetails(id());
 
1250
 
 
1251
      if (!aDetails.count()) {
 
1252
         qDebug() << "Account not found";
 
1253
      }
 
1254
      else {
 
1255
         m_hAccountDetails.clear();
 
1256
         QMutableMapIterator<QString, QString> iter(aDetails);
 
1257
         while (iter.hasNext()) {
 
1258
            iter.next();
 
1259
            m_hAccountDetails[iter.key()] = iter.value();
 
1260
         }
 
1261
         setHostname(m_hAccountDetails[Account::MapField::HOSTNAME]);
 
1262
      }
 
1263
      m_CurrentState = AccountEditState::READY;
 
1264
 
 
1265
      const QString currentUri = QString("%1@%2").arg(username()).arg(m_HostName);
 
1266
      if (!m_pAccountNumber || (m_pAccountNumber && m_pAccountNumber->uri() != currentUri)) {
 
1267
         if (m_pAccountNumber) {
 
1268
            disconnect(m_pAccountNumber,SIGNAL(presenceMessageChanged(QString)),this,SLOT(slotPresenceMessageChanged(QString)));
 
1269
            disconnect(m_pAccountNumber,SIGNAL(presentChanged(bool)),this,SLOT(slotPresentChanged(bool)));
 
1270
         }
 
1271
         m_pAccountNumber = PhoneDirectoryModel::instance()->getNumber(currentUri,this);
 
1272
         m_pAccountNumber->setType(PhoneNumber::Type::ACCOUNT);
 
1273
         connect(m_pAccountNumber,SIGNAL(presenceMessageChanged(QString)),this,SLOT(slotPresenceMessageChanged(QString)));
 
1274
         connect(m_pAccountNumber,SIGNAL(presentChanged(bool)),this,SLOT(slotPresentChanged(bool)));
 
1275
      }
 
1276
 
 
1277
      //If the credential model is loaded, then update it
 
1278
      if (m_pCredentials)
 
1279
         reloadCredentials();
 
1280
      emit changed(this);
 
1281
   }
905
1282
}
906
1283
 
907
1284
///Reload credentials from DBUS
912
1289
   }
913
1290
   if (!isNew()) {
914
1291
      m_pCredentials->clear();
915
 
      ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
916
 
      VectorMapStringString credentials = configurationManager.getCredentials(getAccountId());
 
1292
      ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
1293
      VectorMapStringString credentials = configurationManager.getCredentials(id());
917
1294
      for (int i=0; i < credentials.size(); i++) {
918
1295
         QModelIndex idx = m_pCredentials->addCredentials();
919
 
         m_pCredentials->setData(idx,credentials[i][ CONFIG_ACCOUNT_USERNAME  ],CredentialModel::NAME_ROLE    );
920
 
         m_pCredentials->setData(idx,credentials[i][ CONFIG_ACCOUNT_PASSWORD  ],CredentialModel::PASSWORD_ROLE);
921
 
         m_pCredentials->setData(idx,credentials[i][ CONFIG_ACCOUNT_REALM     ],CredentialModel::REALM_ROLE   );
 
1296
         m_pCredentials->setData(idx,credentials[i][ Account::MapField::USERNAME ],CredentialModel::Role::NAME    );
 
1297
         m_pCredentials->setData(idx,credentials[i][ Account::MapField::PASSWORD ],CredentialModel::Role::PASSWORD);
 
1298
         m_pCredentials->setData(idx,credentials[i][ Account::MapField::REALM    ],CredentialModel::Role::REALM   );
922
1299
      }
923
1300
   }
924
1301
}
926
1303
///Save all credentials
927
1304
void Account::saveCredentials() {
928
1305
   if (m_pCredentials) {
929
 
      ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
 
1306
      ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
930
1307
      VectorMapStringString toReturn;
931
1308
      for (int i=0; i < m_pCredentials->rowCount();i++) {
932
1309
         QModelIndex idx = m_pCredentials->index(i,0);
933
1310
         MapStringString credentialData;
934
 
         QString username = m_pCredentials->data(idx,CredentialModel::NAME_ROLE ).toString();
935
 
         QString realm = m_pCredentials->data(idx,CredentialModel::REALM_ROLE    ).toString();
936
 
         if (username.isEmpty()) {
937
 
            username = getAccountUsername();
938
 
            m_pCredentials->setData(idx,username,CredentialModel::NAME_ROLE );
 
1311
         QString user = m_pCredentials->data(idx,CredentialModel::Role::NAME).toString();
 
1312
         QString realm = m_pCredentials->data(idx,CredentialModel::Role::REALM).toString();
 
1313
         if (user.isEmpty()) {
 
1314
            user = username();
 
1315
            m_pCredentials->setData(idx,user,CredentialModel::Role::NAME);
939
1316
         }
940
1317
         if (realm.isEmpty()) {
941
1318
            realm = '*';
942
 
            m_pCredentials->setData(idx,realm,CredentialModel::REALM_ROLE    );
 
1319
            m_pCredentials->setData(idx,realm,CredentialModel::Role::REALM);
943
1320
         }
944
 
         credentialData[ CONFIG_ACCOUNT_USERNAME] = username;
945
 
         credentialData[ CONFIG_ACCOUNT_PASSWORD] = m_pCredentials->data(idx,CredentialModel::PASSWORD_ROLE ).toString();
946
 
         credentialData[ CONFIG_ACCOUNT_REALM   ] = realm;
 
1321
         credentialData[ Account::MapField::USERNAME ] = user;
 
1322
         credentialData[ Account::MapField::PASSWORD ] = m_pCredentials->data(idx,CredentialModel::Role::PASSWORD).toString();
 
1323
         credentialData[ Account::MapField::REALM    ] = realm;
947
1324
         toReturn << credentialData;
948
1325
      }
949
 
      configurationManager.setCredentials(getAccountId(),toReturn);
 
1326
      configurationManager.setCredentials(id(),toReturn);
950
1327
   }
951
1328
}
952
1329
 
956
1333
   if (!m_pAudioCodecs) {
957
1334
      m_pAudioCodecs = new AudioCodecModel(this);
958
1335
   }
959
 
   m_pAudioCodecs->clear();
960
 
   ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
961
 
   QVector<int> codecIdList = configurationManager.getAudioCodecList();
962
 
   if (!isNew()) {
963
 
      QVector<int> activeCodecList = configurationManager.getActiveAudioCodecList(getAccountId());
964
 
      QStringList tmpNameList;
965
 
 
966
 
      foreach (const int aCodec, activeCodecList) {
967
 
         QStringList codec = configurationManager.getAudioCodecDetails(aCodec);
968
 
         QModelIndex idx = m_pAudioCodecs->addAudioCodec();
969
 
         m_pAudioCodecs->setData(idx,codec[0]     ,AudioCodecModel::NAME_ROLE       );
970
 
         m_pAudioCodecs->setData(idx,codec[1]     ,AudioCodecModel::SAMPLERATE_ROLE );
971
 
         m_pAudioCodecs->setData(idx,codec[2]     ,AudioCodecModel::BITRATE_ROLE    );
972
 
         m_pAudioCodecs->setData(idx,aCodec       ,AudioCodecModel::ID_ROLE         );
973
 
         m_pAudioCodecs->setData(idx, Qt::Checked ,Qt::CheckStateRole               );
974
 
         if (codecIdList.indexOf(aCodec)!=-1)
975
 
            codecIdList.remove(codecIdList.indexOf(aCodec));
976
 
      }
977
 
   }
978
 
 
979
 
   foreach (const int aCodec, codecIdList) {
980
 
      QStringList codec = configurationManager.getAudioCodecDetails(aCodec);
981
 
      QModelIndex idx = m_pAudioCodecs->addAudioCodec();
982
 
      m_pAudioCodecs->setData(idx,codec[0],AudioCodecModel::NAME_ROLE       );
983
 
      m_pAudioCodecs->setData(idx,codec[1],AudioCodecModel::SAMPLERATE_ROLE );
984
 
      m_pAudioCodecs->setData(idx,codec[2],AudioCodecModel::BITRATE_ROLE    );
985
 
      m_pAudioCodecs->setData(idx,aCodec  ,AudioCodecModel::ID_ROLE         );
986
 
      
987
 
      m_pAudioCodecs->setData(idx, Qt::Unchecked ,Qt::CheckStateRole);
988
 
   }
 
1336
   m_pAudioCodecs->reload();
989
1337
}
990
1338
 
991
1339
///Save audio codecs
992
1340
void Account::saveAudioCodecs() {
993
 
   if (m_pAudioCodecs) {
994
 
      QStringList _codecList;
995
 
      for (int i=0; i < m_pAudioCodecs->rowCount();i++) {
996
 
         QModelIndex idx = m_pAudioCodecs->index(i,0);
997
 
         if (m_pAudioCodecs->data(idx,Qt::CheckStateRole) == Qt::Checked) {
998
 
            _codecList << m_pAudioCodecs->data(idx,AudioCodecModel::ID_ROLE).toString();
999
 
         }
1000
 
      }
1001
 
 
1002
 
      ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
1003
 
      configurationManager.setActiveAudioCodecList(_codecList, getAccountId());
1004
 
   }
 
1341
   if (m_pAudioCodecs)
 
1342
      m_pAudioCodecs->save();
1005
1343
}
1006
1344
 
1007
1345
/*****************************************************************************
1013
1351
///Are both account the same
1014
1352
bool Account::operator==(const Account& a)const
1015
1353
{
1016
 
   return *m_pAccountId == *a.m_pAccountId;
 
1354
   return m_AccountId == a.m_AccountId;
1017
1355
}
1018
1356
 
1019
1357
/*****************************************************************************
1021
1359
 *                                   Video                                   *
1022
1360
 *                                                                           *
1023
1361
 ****************************************************************************/
1024
 
#ifdef ENABLE_VIDEO
1025
 
///Save active video codecs
1026
 
void Account::setActiveVideoCodecList(const QList<VideoCodec*>& codecs)
1027
 
{
1028
 
   QStringList codecs2;
1029
 
   VideoInterface& interface = VideoInterfaceSingleton::getInstance();
1030
 
   foreach(VideoCodec* codec,codecs) {
1031
 
      codecs2 << codecs->getName();
1032
 
   }
1033
 
   interface.setActiveCodecList(codecs2,m_pAccountId);
1034
 
}
1035
 
 
1036
 
///Return the list of active video dodecs
1037
 
QList<VideoCodec*> Account::getActiveVideoCodecList()
1038
 
{
1039
 
   QList<VideoCodec*> codecs;
1040
 
   VideoInterface& interface = VideoInterfaceSingleton::getInstance();
1041
 
   const QStringList activeCodecList = interface.getActiveCodecList(m_pAccountId);
1042
 
   foreach (const QString& codec, activeCodecList) {
1043
 
      codecs << VideoCodec::getCodec(codec);
1044
 
   }
1045
 
}
1046
 
 
1047
 
#endif
 
1362
 
 
1363
#undef TO_BOOL
 
1364
#undef IS_TRUE