150
143
///IS this account new
151
144
bool Account::isNew() const
153
return (m_pAccountId == nullptr);
146
return (m_AccountId == nullptr) || m_AccountId.isEmpty();
156
149
///Get this account ID
157
const QString Account::getAccountId() const
150
const QString Account::id() const
160
153
qDebug() << "Error : getting AccountId of a new account.";
155
if (m_AccountId.isEmpty()) {
163
156
qDebug() << "Account not configured";
164
return EMPTY_STRING; //WARNING May explode
157
return QString(); //WARNING May explode
167
return *m_pAccountId;
170
///Get this account details
171
const MapStringString& Account::getAccountDetails() const
173
return *m_pAccountDetails;
176
163
///Get current state
177
const QString Account::getStateName(const QString& state) const
164
const QString Account::toHumanStateName() const
179
return (const QString&)account_state_name(state);
166
const QString s = m_hAccountDetails[Account::MapField::Registration::STATUS];
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" );
182
if(s == Account::State::REGISTERED )
184
if(s == Account::State::UNREGISTERED )
185
return notRegistered ;
186
if(s == Account::State::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 ;
182
209
///Get an account detail
183
const QString Account::getAccountDetail(const QString& param) const
210
const QString Account::accountDetail(const QString& param) const
185
if (!m_pAccountDetails) {
186
qDebug() << "The account list is not set";
187
return EMPTY_STRING; //May crash, but better than crashing now
189
if (m_pAccountDetails->find(param) != m_pAccountDetails->end()) {
190
return (*m_pAccountDetails)[param];
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
216
if (m_hAccountDetails.find(param) != m_hAccountDetails.end()) {
217
return m_hAccountDetails[param];
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";
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";
199
qDebug() << "Account details not found, there is " << m_pAccountDetails->count() << " details available";
229
qDebug() << "Account details not found, there is " << m_hAccountDetails.count() << " details available";
205
const QString Account::getAlias() const
207
return getAccountDetail(ACCOUNT_ALIAS);
210
///Is this account enabled
211
bool Account::isEnabled() const
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
237
return accountDetail(Account::MapField::ALIAS);
218
240
///Is this account registered
219
241
bool Account::isRegistered() const
221
return (getAccountDetail(ACCOUNT_REGISTRATION_STATUS) == ACCOUNT_STATE_REGISTERED);
243
return (accountDetail(Account::MapField::Registration::STATUS) == Account::State::REGISTERED);
224
246
///Return the model index of this item
225
QModelIndex Account::getIndex()
247
QModelIndex Account::index()
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);
232
254
return QModelIndex();
235
257
///Return status color name
236
QString Account::getStateColorName() const
258
QString Account::stateColorName() const
238
if(getAccountRegistrationStatus() == ACCOUNT_STATE_UNREGISTERED)
260
if(registrationStatus() == Account::State::UNREGISTERED)
240
if(getAccountRegistrationStatus() == ACCOUNT_STATE_REGISTERED || getAccountRegistrationStatus() == ACCOUNT_STATE_READY)
262
if(registrationStatus() == Account::State::REGISTERED || registrationStatus() == Account::State::READY)
241
263
return "darkGreen";
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
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;
270
if (AccountListModel::instance()->colorVisitor()) {
271
return AccountListModel::instance()->colorVisitor()->getColor(this);
257
276
///Create and return the credential model
258
CredentialModel* Account::getCredentialsModel()
277
CredentialModel* Account::credentialsModel() const
260
279
if (!m_pCredentials)
280
const_cast<Account*>(this)->reloadCredentials();
262
281
return m_pCredentials;
265
284
///Create and return the audio codec model
266
AudioCodecModel* Account::getAudioCodecModel()
285
AudioCodecModel* Account::audioCodecModel() const
268
287
if (!m_pAudioCodecs)
288
const_cast<Account*>(this)->reloadAudioCodecs();
270
289
return m_pAudioCodecs;
273
292
///Create and return the video codec model
274
VideoCodecModel* Account::getVideoCodecModel()
293
VideoCodecModel* Account::videoCodecModel() const
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;
281
void Account::setAccountAlias(QString detail)
283
bool changed = detail != getAccountAlias();
284
setAccountDetail(ACCOUNT_ALIAS,detail);
300
RingToneModel* Account::ringToneModel() const
302
if (!m_pRingToneModel)
303
const_cast<Account*>(this)->m_pRingToneModel = new RingToneModel(const_cast<Account*>(this));
304
return m_pRingToneModel;
307
KeyExchangeModel* Account::keyExchangeModel() const
309
if (!m_pKeyExchangeModel) {
310
const_cast<Account*>(this)->m_pKeyExchangeModel = new KeyExchangeModel(const_cast<Account*>(this));
312
return m_pKeyExchangeModel;
315
void Account::setAlias(const QString& detail)
317
bool accChanged = detail != alias();
318
setAccountDetail(Account::MapField::ALIAS,detail);
286
320
emit aliasChanged(detail);
289
323
///Return the account hostname
290
QString Account::getAccountHostname () const
324
QString Account::hostname() const
292
return getAccountDetail(ACCOUNT_HOSTNAME);
295
329
///Return if the account is enabled
296
bool Account::isAccountEnabled() const
330
bool Account::isEnabled() const
298
return (getAccountDetail(ACCOUNT_ENABLED) == "true")?1:0;
332
return accountDetail(Account::MapField::ENABLED) IS_TRUE;
301
335
///Return if the account should auto answer
302
336
bool Account::isAutoAnswer() const
304
return (getAccountDetail(ACCOUNT_AUTOANSWER) == "true")?1:0;
338
return accountDetail(Account::MapField::AUTOANSWER) IS_TRUE;
307
341
///Return the account user name
308
QString Account::getAccountUsername() const
310
return getAccountDetail(ACCOUNT_USERNAME);
313
///Return the account mailbox address
314
QString Account::getAccountMailbox() const
316
return getAccountDetail(ACCOUNT_MAILBOX);
319
///Return the account mailbox address
320
QString Account::getAccountProxy() const
322
return getAccountDetail(ACCOUNT_ROUTE);
342
QString Account::username() const
344
return accountDetail(Account::MapField::USERNAME);
347
///Return the account mailbox address
348
QString Account::mailbox() const
350
return accountDetail(Account::MapField::MAILBOX);
353
///Return the account mailbox address
354
QString Account::proxy() const
356
return accountDetail(Account::MapField::ROUTE);
360
QString Account::password() const
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);
326
bool Account::isAccountDisplaySasOnce() const
373
bool Account::isDisplaySasOnce() const
328
return (getAccountDetail(ACCOUNT_DISPLAY_SAS_ONCE) == "true")?1:0 ;
375
return accountDetail(Account::MapField::ZRTP::DISPLAY_SAS_ONCE) IS_TRUE;
331
378
///Return the account security fallback
332
bool Account::isAccountSrtpRtpFallback() const
334
return (getAccountDetail(ACCOUNT_SRTP_RTP_FALLBACK) == "true")?1:0 ;
379
bool Account::isSrtpRtpFallback() const
381
return accountDetail(Account::MapField::SRTP::RTP_FALLBACK) IS_TRUE;
384
//Return if SRTP is enabled or not
385
bool Account::isSrtpEnabled() const
387
return accountDetail(Account::MapField::SRTP::ENABLED) IS_TRUE;
338
bool Account::isAccountZrtpDisplaySas () const
391
bool Account::isZrtpDisplaySas () const
340
return (getAccountDetail(ACCOUNT_ZRTP_DISPLAY_SAS) == "true")?1:0 ;
393
return accountDetail(Account::MapField::ZRTP::DISPLAY_SAS) IS_TRUE;
343
396
///Return if the other side support warning
344
bool Account::isAccountZrtpNotSuppWarning() const
397
bool Account::isZrtpNotSuppWarning() const
346
return (getAccountDetail(ACCOUNT_ZRTP_NOT_SUPP_WARNING) == "true")?1:0 ;
399
return accountDetail(Account::MapField::ZRTP::NOT_SUPP_WARNING) IS_TRUE;
350
bool Account::isAccountZrtpHelloHash() const
403
bool Account::isZrtpHelloHash() const
352
return (getAccountDetail(ACCOUNT_ZRTP_HELLO_HASH) == "true")?1:0 ;
405
return accountDetail(Account::MapField::ZRTP::HELLO_HASH) IS_TRUE;
355
408
///Return if the account is using a STUN server
356
bool Account::isAccountSipStunEnabled() const
409
bool Account::isSipStunEnabled() const
358
return (getAccountDetail(ACCOUNT_SIP_STUN_ENABLED) == "true")?1:0 ;
411
return accountDetail(Account::MapField::STUN::ENABLED) IS_TRUE;
361
414
///Return the account STUN server
362
QString Account::getAccountSipStunServer() const
415
QString Account::sipStunServer() const
364
return getAccountDetail(ACCOUNT_SIP_STUN_SERVER);
417
return accountDetail(Account::MapField::STUN::SERVER);
367
420
///Return when the account expire (require renewal)
368
int Account::getAccountRegistrationExpire() const
421
int Account::registrationExpire() const
370
return getAccountDetail(ACCOUNT_REGISTRATION_EXPIRE).toInt();
423
return accountDetail(Account::MapField::Registration::EXPIRE).toInt();
373
426
///Return if the published address is the same as the local one
374
427
bool Account::isPublishedSameAsLocal() const
376
return (getAccountDetail(PUBLISHED_SAMEAS_LOCAL) == "true")?1:0 ;
429
return accountDetail(Account::MapField::PUBLISHED_SAMEAS_LOCAL) IS_TRUE;
379
432
///Return the account published address
380
QString Account::getPublishedAddress() const
433
QString Account::publishedAddress() const
382
return getAccountDetail(PUBLISHED_ADDRESS);
435
return accountDetail(Account::MapField::PUBLISHED_ADDRESS);
385
438
///Return the account published port
386
int Account::getPublishedPort() const
439
int Account::publishedPort() const
388
return getAccountDetail(PUBLISHED_PORT).toUInt();
441
return accountDetail(Account::MapField::PUBLISHED_PORT).toUInt();
391
444
///Return the account tls password
392
QString Account::getTlsPassword() const
445
QString Account::tlsPassword() const
394
return getAccountDetail(TLS_PASSWORD);
447
return accountDetail(Account::MapField::TLS::PASSWORD);
397
450
///Return the account TLS port
398
int Account::getTlsListenerPort() const
451
int Account::tlsListenerPort() const
400
return getAccountDetail(TLS_LISTENER_PORT).toInt();
453
return accountDetail(Account::MapField::TLS::LISTENER_PORT).toInt();
403
456
///Return the account TLS certificate authority list file
404
QString Account::getTlsCaListFile() const
457
QString Account::tlsCaListFile() const
406
return getAccountDetail(TLS_CA_LIST_FILE);
459
return accountDetail(Account::MapField::TLS::CA_LIST_FILE);
409
462
///Return the account TLS certificate
410
QString Account::getTlsCertificateFile() const
463
QString Account::tlsCertificateFile() const
412
return getAccountDetail(TLS_CERTIFICATE_FILE);
465
return accountDetail(Account::MapField::TLS::CERTIFICATE_FILE);
415
468
///Return the account private key
416
QString Account::getTlsPrivateKeyFile() const
469
QString Account::tlsPrivateKeyFile() const
418
return getAccountDetail(TLS_PRIVATE_KEY_FILE);
471
return accountDetail(Account::MapField::TLS::PRIVATE_KEY_FILE);
421
474
///Return the account cipher
422
QString Account::getTlsCiphers() const
475
QString Account::tlsCiphers() const
424
return getAccountDetail(TLS_CIPHERS);
477
return accountDetail(Account::MapField::TLS::CIPHERS);
427
480
///Return the account TLS server name
428
QString Account::getTlsServerName() const
481
QString Account::tlsServerName() const
430
return getAccountDetail(TLS_SERVER_NAME);
483
return accountDetail(Account::MapField::TLS::SERVER_NAME);
433
486
///Return the account negotiation timeout in seconds
434
int Account::getTlsNegotiationTimeoutSec() const
487
int Account::tlsNegotiationTimeoutSec() const
436
return getAccountDetail(TLS_NEGOTIATION_TIMEOUT_SEC).toInt();
489
return accountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_SEC).toInt();
439
492
///Return the account negotiation timeout in milliseconds
440
int Account::getTlsNegotiationTimeoutMsec() const
493
int Account::tlsNegotiationTimeoutMsec() const
442
return getAccountDetail(TLS_NEGOTIATION_TIMEOUT_MSEC).toInt();
495
return accountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_MSEC).toInt();
445
498
///Return the account TLS verify server
446
499
bool Account::isTlsVerifyServer() const
448
return (getAccountDetail(TLS_VERIFY_SERVER) == "true")?1:0;
501
return (accountDetail(Account::MapField::TLS::VERIFY_SERVER) IS_TRUE);
451
504
///Return the account TLS verify client
452
505
bool Account::isTlsVerifyClient() const
454
return (getAccountDetail(TLS_VERIFY_CLIENT) == "true")?1:0;
507
return (accountDetail(Account::MapField::TLS::VERIFY_CLIENT) IS_TRUE);
457
510
///Return if it is required for the peer to have a certificate
458
511
bool Account::isTlsRequireClientCertificate() const
460
return (getAccountDetail(TLS_REQUIRE_CLIENT_CERTIFICATE) == "true")?1:0;
513
return (accountDetail(Account::MapField::TLS::REQUIRE_CLIENT_CERTIFICATE) IS_TRUE);
463
516
///Return the account TLS security is enabled
464
517
bool Account::isTlsEnable() const
466
return (getAccountDetail(TLS_ENABLE) == "true")?1:0;
519
return (accountDetail(Account::MapField::TLS::ENABLE) IS_TRUE);
469
522
///Return the account the TLS encryption method
470
int Account::getTlsMethod() const
523
TlsMethodModel::Type Account::tlsMethod() const
472
return getAccountDetail(TLS_METHOD).toInt();
525
const QString value = accountDetail(Account::MapField::TLS::METHOD);
526
return TlsMethodModel::fromDaemonName(value);
475
///Return the account alias
476
QString Account::getAccountAlias() const
529
///Return the key exchange mechanism
530
KeyExchangeModel::Type Account::keyExchange() const
478
return getAccountDetail(ACCOUNT_ALIAS);
532
return KeyExchangeModel::fromDaemonName(accountDetail(Account::MapField::SRTP::KEY_EXCHANGE));
481
535
///Return if the ringtone are enabled
482
536
bool Account::isRingtoneEnabled() const
484
return (getAccountDetail(CONFIG_RINGTONE_ENABLED) == "true")?1:0;
538
return (accountDetail(Account::MapField::Ringtone::ENABLED) IS_TRUE);
487
541
///Return the account ringtone path
488
QString Account::getRingtonePath() const
490
return getAccountDetail(CONFIG_RINGTONE_PATH);
542
QString Account::ringtonePath() const
544
return accountDetail(Account::MapField::Ringtone::PATH);
547
///Return the last error message received
548
QString Account::lastErrorMessage() const
550
return m_LastErrorMessage;
553
///Return the last error code (useful for debugging)
554
int Account::lastErrorCode() const
556
return m_LastErrorCode;
493
559
///Return the account local port
494
int Account::getLocalPort() const
496
return getAccountDetail(LOCAL_PORT).toInt();
560
int Account::localPort() const
562
return accountDetail(Account::MapField::LOCAL_PORT).toInt();
565
///Return the number of voicemails
566
int Account::voiceMailCount() const
568
return m_VoiceMailCount;
499
571
///Return the account local interface
500
QString Account::getLocalInterface() const
572
QString Account::localInterface() const
502
return getAccountDetail(LOCAL_INTERFACE);
574
return accountDetail(Account::MapField::LOCAL_INTERFACE);
505
577
///Return the account registration status
506
QString Account::getAccountRegistrationStatus() const
578
QString Account::registrationStatus() const
508
return getAccountDetail(ACCOUNT_REGISTRATION_STATUS);
580
return accountDetail(Account::MapField::Registration::STATUS);
511
583
///Return the account type
512
QString Account::getAccountType() const
584
Account::Protocol Account::protocol() const
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;
517
595
///Return the DTMF type
518
DtmfType Account::getDTMFType() const
596
DtmfType Account::DTMFType() const
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;
602
bool Account::presenceStatus() const
604
return m_pAccountNumber->isPresent();
607
QString Account::presenceMessage() const
609
return m_pAccountNumber->presenceMessage();
612
bool Account::supportPresencePublish() const
614
return accountDetail(Account::MapField::Presence::SUPPORT_PUBLISH) IS_TRUE;
617
bool Account::supportPresenceSubscribe() const
619
return accountDetail(Account::MapField::Presence::SUPPORT_SUBSCRIBE) IS_TRUE;
622
bool Account::presenceEnabled() const
624
return accountDetail(Account::MapField::Presence::ENABLE) IS_TRUE;
627
QVariant Account::roleData(int role) const
630
case Account::Role::Alias:
632
case Account::Role::Proto:
633
return static_cast<int>(protocol());
634
case Account::Role::Hostname:
636
case Account::Role::Username:
638
case Account::Role::Mailbox:
640
case Account::Role::Proxy:
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:
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:
674
case Account::Role::TlsListenerPort:
675
return tlsListenerPort();
676
case Account::Role::PublishedPort:
677
return publishedPort();
678
case Account::Role::Enabled:
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:
708
case Account::Role::Id:
710
case Account::Role::Object: {
712
var.setValue(const_cast<Account*>(this));
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();
525
727
/*****************************************************************************
529
731
****************************************************************************/
531
733
///Set account details
532
void Account::setAccountDetails(const MapStringString& m)
734
void Account::setAccountDetails(const QHash<QString,QString>& m)
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];
539
741
///Set a specific detail
540
742
bool Account::setAccountDetail(const QString& param, const QString& val)
542
bool changed = (*m_pAccountDetails)[param] != val;
543
QString buf = (*m_pAccountDetails)[param];
544
if (param == ACCOUNT_REGISTRATION_STATUS) {
545
(*m_pAccountDetails)[param] = val;
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;
547
749
emit detailChanged(this,param,val,buf);
551
753
performAction(AccountEditAction::MODIFY);
552
if (m_CurrentState == MODIFIED || m_CurrentState == NEW) {
553
(*m_pAccountDetails)[param] = val;
754
if (m_CurrentState == AccountEditState::MODIFIED || m_CurrentState == AccountEditState::NEW) {
755
m_hAccountDetails[param] = val;
555
757
emit detailChanged(this,param,val,buf);
559
return m_CurrentState == MODIFIED || m_CurrentState == NEW;
761
return m_CurrentState == AccountEditState::MODIFIED || m_CurrentState == AccountEditState::NEW;
562
764
///Set the account id
563
void Account::setAccountId(const QString& id)
765
void Account::setId(const QString& id)
565
qDebug() << "Setting accountId = " << m_pAccountId;
767
qDebug() << "Setting accountId = " << m_AccountId;
567
769
qDebug() << "Error : setting AccountId of an existing account.";
568
m_pAccountId = new QString(id);
571
///Set account enabled
572
void Account::setEnabled(bool checked)
574
setAccountEnabled(checked);
579
void Account::setActiveVideoCodecList(const QList<VideoCodec*>& codecs);
580
QList<VideoCodec*> getActiveVideoCodecList();
582
773
///Set the account type, SIP or IAX
583
void Account::setAccountType(QString detail)
774
void Account::setProtocol(Account::Protocol proto)
585
setAccountDetail(ACCOUNT_TYPE ,detail);
777
case Account::Protocol::SIP:
778
setAccountDetail(Account::MapField::TYPE ,Account::ProtocolName::SIP);
780
case Account::Protocol::IAX:
781
setAccountDetail(Account::MapField::TYPE ,Account::ProtocolName::IAX);
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)
591
setAccountDetail(ACCOUNT_HOSTNAME ,detail);
789
if (m_HostName != detail) {
791
setAccountDetail(Account::MapField::HOSTNAME, detail);
594
795
///Set the account username, everything is valid, some might be rejected by the PBX server
595
void Account::setAccountUsername(QString detail)
597
setAccountDetail(ACCOUNT_USERNAME ,detail);
600
///Set the account mailbox, usually a number, but can be anything
601
void Account::setAccountMailbox(QString detail)
603
setAccountDetail(ACCOUNT_MAILBOX ,detail);
606
///Set the account mailbox, usually a number, but can be anything
607
void Account::setAccountProxy(QString detail)
609
setAccountDetail(ACCOUNT_ROUTE ,detail);
796
void Account::setUsername(const QString& detail)
798
setAccountDetail(Account::MapField::USERNAME, detail);
801
///Set the account mailbox, usually a number, but can be anything
802
void Account::setMailbox(const QString& detail)
804
setAccountDetail(Account::MapField::MAILBOX, detail);
807
///Set the account mailbox, usually a number, but can be anything
808
void Account::setProxy(const QString& detail)
810
setAccountDetail(Account::MapField::ROUTE, detail);
612
813
///Set the main credential password
613
void Account::setAccountPassword(QString detail)
814
void Account::setPassword(const QString& detail)
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);
821
const QModelIndex idx = credentialsModel()->addCredentials();
822
credentialsModel()->setData(idx,detail,CredentialModel::Role::PASSWORD);
825
case Account::Protocol::IAX:
826
setAccountDetail(Account::MapField::PASSWORD, detail);
618
831
///Set the TLS (encryption) password
619
void Account::setTlsPassword(QString detail)
832
void Account::setTlsPassword(const QString& detail)
621
setAccountDetail(TLS_PASSWORD ,detail);
834
setAccountDetail(Account::MapField::TLS::PASSWORD, detail);
624
837
///Set the certificate authority list file
625
void Account::setTlsCaListFile(QString detail)
838
void Account::setTlsCaListFile(const QString& detail)
627
setAccountDetail(TLS_CA_LIST_FILE ,detail);
840
setAccountDetail(Account::MapField::TLS::CA_LIST_FILE, detail);
630
843
///Set the certificate
631
void Account::setTlsCertificateFile(QString detail)
844
void Account::setTlsCertificateFile(const QString& detail)
633
setAccountDetail(TLS_CERTIFICATE_FILE ,detail);
846
setAccountDetail(Account::MapField::TLS::CERTIFICATE_FILE, detail);
636
849
///Set the private key
637
void Account::setTlsPrivateKeyFile(QString detail)
850
void Account::setTlsPrivateKeyFile(const QString& detail)
639
setAccountDetail(TLS_PRIVATE_KEY_FILE ,detail);
852
setAccountDetail(Account::MapField::TLS::PRIVATE_KEY_FILE, detail);
642
855
///Set the TLS cipher
643
void Account::setTlsCiphers(QString detail)
856
void Account::setTlsCiphers(const QString& detail)
645
setAccountDetail(TLS_CIPHERS ,detail);
858
setAccountDetail(Account::MapField::TLS::CIPHERS, detail);
648
861
///Set the TLS server
649
void Account::setTlsServerName(QString detail)
862
void Account::setTlsServerName(const QString& detail)
651
setAccountDetail(TLS_SERVER_NAME ,detail);
864
setAccountDetail(Account::MapField::TLS::SERVER_NAME, detail);
654
867
///Set the stun server
655
void Account::setAccountSipStunServer(QString detail)
868
void Account::setSipStunServer(const QString& detail)
657
setAccountDetail(ACCOUNT_SIP_STUN_SERVER ,detail);
870
setAccountDetail(Account::MapField::STUN::SERVER, detail);
660
873
///Set the published address
661
void Account::setPublishedAddress(QString detail)
874
void Account::setPublishedAddress(const QString& detail)
663
setAccountDetail(PUBLISHED_ADDRESS ,detail);
876
setAccountDetail(Account::MapField::PUBLISHED_ADDRESS, detail);
666
879
///Set the local interface
667
void Account::setLocalInterface(QString detail)
880
void Account::setLocalInterface(const QString& detail)
669
setAccountDetail(LOCAL_INTERFACE ,detail);
882
setAccountDetail(Account::MapField::LOCAL_INTERFACE, detail);
672
885
///Set the ringtone path, it have to be a valid absolute path
673
void Account::setRingtonePath(QString detail)
675
setAccountDetail(CONFIG_RINGTONE_PATH ,detail);
678
///Set the Tls method
679
void Account::setTlsMethod(int detail)
681
setAccountDetail(TLS_METHOD ,QString::number(detail));
886
void Account::setRingtonePath(const QString& detail)
888
setAccountDetail(Account::MapField::Ringtone::PATH, detail);
891
///Set the number of voice mails
892
void Account::setVoiceMailCount(int count)
894
m_VoiceMailCount = count;
897
///Set the last error message to be displayed as status instead of "Error"
898
void Account::setLastErrorMessage(const QString& message)
900
m_LastErrorMessage = message;
903
///Set the last error code
904
void Account::setLastErrorCode(int code)
906
m_LastErrorCode = code;
909
///Set the Tls method
910
void Account::setTlsMethod(TlsMethodModel::Type detail)
913
setAccountDetail(Account::MapField::TLS::METHOD ,TlsMethodModel::toDaemonName(detail));
916
///Set the Tls method
917
void Account::setKeyExchange(KeyExchangeModel::Type detail)
919
setAccountDetail(Account::MapField::SRTP::KEY_EXCHANGE ,KeyExchangeModel::toDaemonName(detail));
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)
687
setAccountDetail(ACCOUNT_REGISTRATION_EXPIRE ,QString::number(detail));
925
setAccountDetail(Account::MapField::Registration::EXPIRE, QString::number(detail));
690
928
///Set TLS negotiation timeout in second
691
929
void Account::setTlsNegotiationTimeoutSec(int detail)
693
setAccountDetail(TLS_NEGOTIATION_TIMEOUT_SEC ,QString::number(detail));
931
setAccountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_SEC, QString::number(detail));
696
934
///Set the TLS negotiation timeout in milliseconds
697
935
void Account::setTlsNegotiationTimeoutMsec(int detail)
699
setAccountDetail(TLS_NEGOTIATION_TIMEOUT_MSEC ,QString::number(detail));
937
setAccountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_MSEC, QString::number(detail));
702
940
///Set the local port for SIP/IAX communications
703
941
void Account::setLocalPort(unsigned short detail)
705
setAccountDetail(LOCAL_PORT ,QString::number(detail));
943
setAccountDetail(Account::MapField::LOCAL_PORT, QString::number(detail));
708
946
///Set the TLS listener port (0-2^16)
709
947
void Account::setTlsListenerPort(unsigned short detail)
711
setAccountDetail(TLS_LISTENER_PORT ,QString::number(detail));
949
setAccountDetail(Account::MapField::TLS::LISTENER_PORT, QString::number(detail));
714
952
///Set the published port (0-2^16)
715
953
void Account::setPublishedPort(unsigned short detail)
717
setAccountDetail(PUBLISHED_PORT ,QString::number(detail));
955
setAccountDetail(Account::MapField::PUBLISHED_PORT, QString::number(detail));
720
958
///Set if the account is enabled or not
721
void Account::setAccountEnabled(bool detail)
959
void Account::setEnabled(bool detail)
723
setAccountDetail(ACCOUNT_ENABLED ,detail?"true":"false");
961
setAccountDetail(Account::MapField::ENABLED, (detail)TO_BOOL);
726
964
///Set if the account should auto answer
727
965
void Account::setAutoAnswer(bool detail)
729
setAccountDetail(ACCOUNT_AUTOANSWER ,detail?"true":"false");
967
setAccountDetail(Account::MapField::AUTOANSWER, (detail)TO_BOOL);
732
970
///Set the TLS verification server
733
971
void Account::setTlsVerifyServer(bool detail)
735
setAccountDetail(TLS_VERIFY_SERVER ,detail?"true":"false");
973
setAccountDetail(Account::MapField::TLS::VERIFY_SERVER, (detail)TO_BOOL);
738
976
///Set the TLS verification client
739
977
void Account::setTlsVerifyClient(bool detail)
741
setAccountDetail(TLS_VERIFY_CLIENT ,detail?"true":"false");
979
setAccountDetail(Account::MapField::TLS::VERIFY_CLIENT, (detail)TO_BOOL);
744
982
///Set if the peer need to be providing a certificate
745
983
void Account::setTlsRequireClientCertificate(bool detail)
747
setAccountDetail(TLS_REQUIRE_CLIENT_CERTIFICATE ,detail?"true":"false");
985
setAccountDetail(Account::MapField::TLS::REQUIRE_CLIENT_CERTIFICATE ,(detail)TO_BOOL);
750
988
///Set if the security settings are enabled
751
989
void Account::setTlsEnable(bool detail)
753
setAccountDetail(TLS_ENABLE ,detail?"true":"false");
756
void Account::setAccountDisplaySasOnce(bool detail)
758
setAccountDetail(ACCOUNT_DISPLAY_SAS_ONCE ,detail?"true":"false");
761
void Account::setAccountSrtpRtpFallback(bool detail)
763
setAccountDetail(ACCOUNT_SRTP_RTP_FALLBACK ,detail?"true":"false");
766
void Account::setAccountZrtpDisplaySas(bool detail)
768
setAccountDetail(ACCOUNT_ZRTP_DISPLAY_SAS ,detail?"true":"false");
771
void Account::setAccountZrtpNotSuppWarning(bool detail)
773
setAccountDetail(ACCOUNT_ZRTP_NOT_SUPP_WARNING ,detail?"true":"false");
776
void Account::setAccountZrtpHelloHash(bool detail)
778
setAccountDetail(ACCOUNT_ZRTP_HELLO_HASH ,detail?"true":"false");
781
void Account::setAccountSipStunEnabled(bool detail)
783
setAccountDetail(ACCOUNT_SIP_STUN_ENABLED ,detail?"true":"false");
991
setAccountDetail(Account::MapField::TLS::ENABLE ,(detail)TO_BOOL);
994
void Account::setDisplaySasOnce(bool detail)
996
setAccountDetail(Account::MapField::ZRTP::DISPLAY_SAS_ONCE, (detail)TO_BOOL);
999
void Account::setSrtpRtpFallback(bool detail)
1001
setAccountDetail(Account::MapField::SRTP::RTP_FALLBACK, (detail)TO_BOOL);
1004
void Account::setSrtpEnabled(bool detail)
1006
setAccountDetail(Account::MapField::SRTP::ENABLED, (detail)TO_BOOL);
1009
void Account::setZrtpDisplaySas(bool detail)
1011
setAccountDetail(Account::MapField::ZRTP::DISPLAY_SAS, (detail)TO_BOOL);
1014
void Account::setZrtpNotSuppWarning(bool detail)
1016
setAccountDetail(Account::MapField::ZRTP::NOT_SUPP_WARNING, (detail)TO_BOOL);
1019
void Account::setZrtpHelloHash(bool detail)
1021
setAccountDetail(Account::MapField::ZRTP::HELLO_HASH, (detail)TO_BOOL);
1024
void Account::setSipStunEnabled(bool detail)
1026
setAccountDetail(Account::MapField::STUN::ENABLED, (detail)TO_BOOL);
786
1029
void Account::setPublishedSameAsLocal(bool detail)
788
setAccountDetail(PUBLISHED_SAMEAS_LOCAL ,detail?"true":"false");
1031
setAccountDetail(Account::MapField::PUBLISHED_SAMEAS_LOCAL, (detail)TO_BOOL);
791
1034
///Set if custom ringtone are enabled
792
1035
void Account::setRingtoneEnabled(bool detail)
794
setAccountDetail(CONFIG_RINGTONE_ENABLED ,detail?"true":"false");
1037
setAccountDetail(Account::MapField::Ringtone::ENABLED, (detail)TO_BOOL);
1040
void Account::setPresenceEnabled(bool enable)
1042
setAccountDetail(Account::MapField::Presence::ENABLE, (enable)TO_BOOL);
797
1045
///Set the DTMF type
798
1046
void Account::setDTMFType(DtmfType type)
800
setAccountDetail(ACCOUNT_DTMF_TYPE,(type==OverRtp)?"overrtp":"oversip");
1048
setAccountDetail(Account::MapField::DTMF_TYPE,(type==OverRtp)?"overrtp":"oversip");
1051
void Account::setRoleData(int role, const QVariant& value)
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);
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());
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);
1094
case Account::Role::KeyExchange: {
1095
const int method = value.toInt();
1096
setKeyExchange(method<=keyExchangeModel()->rowCount()?static_cast<KeyExchangeModel::Type>(method):KeyExchangeModel::Type::NONE);
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());