diff --git a/src/abstractitembackend.h b/src/abstractitembackend.h index 33d6cb49b5b937f629e915a219d0739899b3f03b..517af56bbcea51750a21537fcbdb98685d902c73 100644 --- a/src/abstractitembackend.h +++ b/src/abstractitembackend.h @@ -100,6 +100,7 @@ public: virtual QList<T*> items() const = 0; private: +// QScopedPointer<AbstractItemBackendInterface> m_P; AbstractItemBackendInterface<T>* m_pParent; QVector<AbstractItemBackendInterface<T>*> m_lChildren; }; diff --git a/src/account.cpp b/src/account.cpp index f6af5e45bcd3231b91bd4e89e1a33a9ba081676d..ed8536545e3ab8d9a4379d99039d0ee65f6ccc18 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -47,21 +47,104 @@ #define TO_BOOL ?"true":"false" #define IS_TRUE == "true" -const account_function Account::stateMachineActionsOnState[6][7] = { -/* NOTHING EDIT RELOAD SAVE REMOVE MODIFY CANCEL */ -/*READY */{ &Account::nothing, &Account::edit , &Account::reload , &Account::nothing, &Account::remove , &Account::modify , &Account::nothing },/**/ -/*EDITING */{ &Account::nothing, &Account::nothing, &Account::outdate, &Account::nothing, &Account::remove , &Account::modify , &Account::cancel },/**/ -/*OUTDATED */{ &Account::nothing, &Account::nothing, &Account::nothing, &Account::nothing, &Account::remove , &Account::reloadMod, &Account::reload },/**/ -/*NEW */{ &Account::nothing, &Account::nothing, &Account::nothing, &Account::save , &Account::remove , &Account::nothing , &Account::nothing },/**/ -/*MODIFIED */{ &Account::nothing, &Account::nothing, &Account::nothing, &Account::save , &Account::remove , &Account::nothing , &Account::reload },/**/ -/*REMOVED */{ &Account::nothing, &Account::nothing, &Account::nothing, &Account::nothing, &Account::nothing, &Account::nothing , &Account::cancel } /**/ +typedef void (AccountPrivate::*account_function)(); + +class AccountPrivate : public QObject +{ +public: + Q_OBJECT + Q_DECLARE_PUBLIC(Account) + + //Constructor + AccountPrivate(Account* acc); + + //Attributes + QString m_AccountId ; + QHash<QString,QString> m_hAccountDetails; + PhoneNumber* m_pAccountNumber ; + + Account* q_ptr ; + + //Setters + void setAccountDetails (const QHash<QString,QString>& m ); + bool setAccountDetail (const QString& param, const QString& val ); + + //Getters + const QString accountDetail(const QString& param) const; + + //Helpers + inline void changeState(Account::EditState state); + + //State actions + void performAction(Account::EditAction action); + void nothing() {}; + void edit() {changeState(Account::EditState::EDITING );}; + void modify() {changeState(Account::EditState::MODIFIED);}; + void remove() {changeState(Account::EditState::REMOVED );}; + void cancel() {changeState(Account::EditState::READY );}; + void outdate() {changeState(Account::EditState::OUTDATED);}; + void reload(); + void save(); + void reloadMod() {reload();modify();}; + + CredentialModel* m_pCredentials ; + AudioCodecModel* m_pAudioCodecs ; + VideoCodecModel* m_pVideoCodecs ; + RingToneModel* m_pRingToneModel ; + KeyExchangeModel* m_pKeyExchangeModel; + SecurityValidationModel* m_pSecurityValidationModel; + Account::EditState m_CurrentState; + + // State machines + static const account_function stateMachineActionsOnState[6][7]; + + //Cached account details (as they are called too often for the hash) + mutable QString m_HostName; + mutable QString m_LastErrorMessage; + mutable int m_LastErrorCode; + mutable int m_VoiceMailCount; + mutable Certificate* m_pCaCert; + mutable Certificate* m_pTlsCert; + mutable Certificate* m_pPrivateKey; + +public Q_SLOTS: + void slotPresentChanged (bool present ); + void slotPresenceMessageChanged(const QString& ); + void slotUpdateCertificate ( ); +}; + +#define AP &AccountPrivate +const account_function AccountPrivate::stateMachineActionsOnState[6][7] = { +/* NOTHING EDIT RELOAD SAVE REMOVE MODIFY CANCEL */ +/*READY */{ AP::nothing, AP::edit , AP::reload , AP::nothing, AP::remove , AP::modify , AP::nothing },/**/ +/*EDITING */{ AP::nothing, AP::nothing, AP::outdate, AP::nothing, AP::remove , AP::modify , AP::cancel },/**/ +/*OUTDATED */{ AP::nothing, AP::nothing, AP::nothing, AP::nothing, AP::remove , AP::reloadMod, AP::reload },/**/ +/*NEW */{ AP::nothing, AP::nothing, AP::nothing, AP::save , AP::remove , AP::nothing , AP::nothing },/**/ +/*MODIFIED */{ AP::nothing, AP::nothing, AP::nothing, AP::save , AP::remove , AP::nothing , AP::reload },/**/ +/*REMOVED */{ AP::nothing, AP::nothing, AP::nothing, AP::nothing, AP::nothing, AP::nothing , AP::cancel } /**/ /* */ }; +#undef AP + +AccountPrivate::AccountPrivate(Account* acc) : QObject(acc),q_ptr(acc),m_pCredentials(nullptr),m_pAudioCodecs(nullptr), +m_pVideoCodecs(nullptr),m_LastErrorCode(-1),m_VoiceMailCount(0),m_pRingToneModel(nullptr), +m_CurrentState(Account::EditState::READY), +m_pAccountNumber(nullptr),m_pKeyExchangeModel(nullptr),m_pSecurityValidationModel(nullptr),m_pCaCert(nullptr),m_pTlsCert(nullptr), +m_pPrivateKey(nullptr) +{ + Q_Q(Account); +} + +void AccountPrivate::changeState(Account::EditState state) { + Q_Q(Account); + m_CurrentState = state; + emit q_ptr->changed(q_ptr); +} + ///Constructors -Account::Account():QObject(AccountListModel::instance()),m_pCredentials(nullptr),m_pAudioCodecs(nullptr),m_CurrentState(AccountEditState::READY), -m_pVideoCodecs(nullptr),m_LastErrorCode(-1),m_VoiceMailCount(0),m_pRingToneModel(nullptr),m_pAccountNumber(nullptr), -m_pKeyExchangeModel(nullptr),m_pSecurityValidationModel(nullptr),m_pCaCert(nullptr),m_pTlsCert(nullptr),m_pPrivateKey(nullptr) +Account::Account():QObject(AccountListModel::instance()),d_ptr(new AccountPrivate(this)) + { } @@ -70,10 +153,10 @@ Account* Account::buildExistingAccountFromId(const QString& _accountId) { // qDebug() << "Building an account from id: " << _accountId; Account* a = new Account(); - a->m_AccountId = _accountId; - a->setObjectName(_accountId); + a->d_ptr->m_AccountId = _accountId; + a->d_ptr->setObjectName(_accountId); - a->performAction(AccountEditAction::RELOAD); + a->performAction(EditAction::RELOAD); return a; } //buildExistingAccountFromId @@ -84,17 +167,17 @@ Account* Account::buildNewAccountFromAlias(const QString& alias) qDebug() << "Building an account from alias: " << alias; ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance(); Account* a = new Account(); - a->m_hAccountDetails.clear(); - a->m_hAccountDetails[Account::MapField::ENABLED] = "false"; - a->m_pAccountNumber = const_cast<PhoneNumber*>(PhoneNumber::BLANK()); + a->d_ptr->m_hAccountDetails.clear(); + a->d_ptr->m_hAccountDetails[Account::MapField::ENABLED] = "false"; + a->d_ptr->m_pAccountNumber = const_cast<PhoneNumber*>(PhoneNumber::BLANK()); MapStringString tmp = configurationManager.getAccountTemplate(); QMutableMapIterator<QString, QString> iter(tmp); while (iter.hasNext()) { iter.next(); - a->m_hAccountDetails[iter.key()] = iter.value(); + a->d_ptr->m_hAccountDetails[iter.key()] = iter.value(); } - a->setHostname(a->m_hAccountDetails[Account::MapField::HOSTNAME]); - a->setAccountDetail(Account::MapField::ALIAS,alias); + a->setHostname(a->d_ptr->m_hAccountDetails[Account::MapField::HOSTNAME]); + a->d_ptr->setAccountDetail(Account::MapField::ALIAS,alias); a->setObjectName(a->id()); return a; } @@ -103,8 +186,8 @@ Account* Account::buildNewAccountFromAlias(const QString& alias) Account::~Account() { disconnect(); - if (m_pCredentials) delete m_pCredentials ; - if (m_pAudioCodecs) delete m_pAudioCodecs ; + if (d_ptr->m_pCredentials) delete d_ptr->m_pCredentials ; + if (d_ptr->m_pAudioCodecs) delete d_ptr->m_pAudioCodecs ; } @@ -114,30 +197,19 @@ Account::~Account() * * ****************************************************************************/ -///Callback when the account state change -// void Account::accountChanged(const QString& accountId, const QString& state,int) -// { -// if ((!m_AccountId.isEmpty()) && accountId == m_AccountId) { -// if (state != "OK") //Do not polute the log -// qDebug() << "Account" << m_AccountId << "status changed to" << state; -// if (Account::updateState()) -// emit stateChanged(toHumanStateName()); -// } -// } - -void Account::slotPresentChanged(bool present) +void AccountPrivate::slotPresentChanged(bool present) { Q_UNUSED(present) - emit changed(this); + emit q_ptr->changed(q_ptr); } -void Account::slotPresenceMessageChanged(const QString& message) +void AccountPrivate::slotPresenceMessageChanged(const QString& message) { Q_UNUSED(message) - emit changed(this); + emit q_ptr->changed(q_ptr); } -void Account::slotUpdateCertificate() +void AccountPrivate::slotUpdateCertificate() { Certificate* cert = qobject_cast<Certificate*>(sender()); if (cert) { @@ -169,7 +241,7 @@ void Account::slotUpdateCertificate() ///IS this account new bool Account::isNew() const { - return (m_AccountId == nullptr) || m_AccountId.isEmpty(); + return (d_ptr->m_AccountId == nullptr) || d_ptr->m_AccountId.isEmpty(); } ///Get this account ID @@ -178,18 +250,18 @@ const QString Account::id() const if (isNew()) { qDebug() << "Error : getting AccountId of a new account."; } - if (m_AccountId.isEmpty()) { + if (d_ptr->m_AccountId.isEmpty()) { qDebug() << "Account not configured"; return QString(); //WARNING May explode } - return m_AccountId; + return d_ptr->m_AccountId; } ///Get current state const QString Account::toHumanStateName() const { - const QString s = m_hAccountDetails[Account::MapField::Registration::STATUS]; + const QString s = d_ptr->m_hAccountDetails[Account::MapField::Registration::STATUS]; static const QString registered = tr("Registered" ); static const QString notRegistered = tr("Not Registered" ); @@ -212,7 +284,7 @@ const QString Account::toHumanStateName() const if(s == Account::State::TRYING ) return trying ; if(s == Account::State::ERROR ) - return m_LastErrorMessage.isEmpty()?error:m_LastErrorMessage; + return d_ptr->m_LastErrorMessage.isEmpty()?error:d_ptr->m_LastErrorMessage; if(s == Account::State::ERROR_AUTH ) return authenticationFailed ; if(s == Account::State::ERROR_NETWORK ) @@ -233,7 +305,7 @@ const QString Account::toHumanStateName() const } ///Get an account detail -const QString Account::accountDetail(const QString& param) const +const QString AccountPrivate::accountDetail(const QString& param) const { if (!m_hAccountDetails.size()) { qDebug() << "The account details is not set"; @@ -247,7 +319,7 @@ const QString Account::accountDetail(const QString& param) const return Account::RegistrationEnabled::NO; if (param == Account::MapField::Registration::STATUS) //If an account is new, then it is unregistered return Account::State::UNREGISTERED; - if (protocol() != Account::Protocol::IAX) //IAX accounts lack some fields, be quiet + if (q_ptr->protocol() != Account::Protocol::IAX) //IAX accounts lack some fields, be quiet qDebug() << "Account parameter \"" << param << "\" not found"; return QString(); } @@ -260,13 +332,13 @@ const QString Account::accountDetail(const QString& param) const ///Get the alias const QString Account::alias() const { - return accountDetail(Account::MapField::ALIAS); + return d_ptr->accountDetail(Account::MapField::ALIAS); } ///Is this account registered bool Account::isRegistered() const { - return (accountDetail(Account::MapField::Registration::STATUS) == Account::State::REGISTERED); + return (d_ptr->accountDetail(Account::MapField::Registration::STATUS) == Account::State::REGISTERED); } ///Return the model index of this item @@ -302,54 +374,54 @@ QVariant Account::stateColor() const ///Create and return the credential model CredentialModel* Account::credentialsModel() const { - if (!m_pCredentials) + if (!d_ptr->m_pCredentials) const_cast<Account*>(this)->reloadCredentials(); - return m_pCredentials; + return d_ptr->m_pCredentials; } ///Create and return the audio codec model AudioCodecModel* Account::audioCodecModel() const { - if (!m_pAudioCodecs) + if (!d_ptr->m_pAudioCodecs) const_cast<Account*>(this)->reloadAudioCodecs(); - return m_pAudioCodecs; + return d_ptr->m_pAudioCodecs; } ///Create and return the video codec model VideoCodecModel* Account::videoCodecModel() const { - if (!m_pVideoCodecs) - const_cast<Account*>(this)->m_pVideoCodecs = new VideoCodecModel(const_cast<Account*>(this)); - return m_pVideoCodecs; + if (!d_ptr->m_pVideoCodecs) + const_cast<Account*>(this)->d_ptr->m_pVideoCodecs = new VideoCodecModel(const_cast<Account*>(this)); + return d_ptr->m_pVideoCodecs; } RingToneModel* Account::ringToneModel() const { - if (!m_pRingToneModel) - const_cast<Account*>(this)->m_pRingToneModel = new RingToneModel(const_cast<Account*>(this)); - return m_pRingToneModel; + if (!d_ptr->m_pRingToneModel) + const_cast<Account*>(this)->d_ptr->m_pRingToneModel = new RingToneModel(const_cast<Account*>(this)); + return d_ptr->m_pRingToneModel; } KeyExchangeModel* Account::keyExchangeModel() const { - if (!m_pKeyExchangeModel) { - const_cast<Account*>(this)->m_pKeyExchangeModel = new KeyExchangeModel(const_cast<Account*>(this)); + if (!d_ptr->m_pKeyExchangeModel) { + const_cast<Account*>(this)->d_ptr->m_pKeyExchangeModel = new KeyExchangeModel(const_cast<Account*>(this)); } - return m_pKeyExchangeModel; + return d_ptr->m_pKeyExchangeModel; } SecurityValidationModel* Account::securityValidationModel() const { - if (!m_pSecurityValidationModel) { - const_cast<Account*>(this)->m_pSecurityValidationModel = new SecurityValidationModel(const_cast<Account*>(this)); + if (!d_ptr->m_pSecurityValidationModel) { + const_cast<Account*>(this)->d_ptr->m_pSecurityValidationModel = new SecurityValidationModel(const_cast<Account*>(this)); } - return m_pSecurityValidationModel; + return d_ptr->m_pSecurityValidationModel; } void Account::setAlias(const QString& detail) { - bool accChanged = detail != alias(); - setAccountDetail(Account::MapField::ALIAS,detail); + const bool accChanged = detail != alias(); + d_ptr->setAccountDetail(Account::MapField::ALIAS,detail); if (accChanged) emit aliasChanged(detail); } @@ -357,37 +429,37 @@ void Account::setAlias(const QString& detail) ///Return the account hostname QString Account::hostname() const { - return m_HostName; + return d_ptr->m_HostName; } ///Return if the account is enabled bool Account::isEnabled() const { - return accountDetail(Account::MapField::ENABLED) IS_TRUE; + return d_ptr->accountDetail(Account::MapField::ENABLED) IS_TRUE; } ///Return if the account should auto answer bool Account::isAutoAnswer() const { - return accountDetail(Account::MapField::AUTOANSWER) IS_TRUE; + return d_ptr->accountDetail(Account::MapField::AUTOANSWER) IS_TRUE; } ///Return the account user name QString Account::username() const { - return accountDetail(Account::MapField::USERNAME); + return d_ptr->accountDetail(Account::MapField::USERNAME); } ///Return the account mailbox address QString Account::mailbox() const { - return accountDetail(Account::MapField::MAILBOX); + return d_ptr->accountDetail(Account::MapField::MAILBOX); } ///Return the account mailbox address QString Account::proxy() const { - return accountDetail(Account::MapField::ROUTE); + return d_ptr->accountDetail(Account::MapField::ROUTE); } @@ -398,7 +470,7 @@ QString Account::password() const if (credentialsModel()->rowCount()) return credentialsModel()->data(credentialsModel()->index(0,0),CredentialModel::Role::PASSWORD).toString(); case Account::Protocol::IAX: - return accountDetail(Account::MapField::PASSWORD); + return d_ptr->accountDetail(Account::MapField::PASSWORD); }; return ""; } @@ -406,233 +478,233 @@ QString Account::password() const /// bool Account::isDisplaySasOnce() const { - return accountDetail(Account::MapField::ZRTP::DISPLAY_SAS_ONCE) IS_TRUE; + return d_ptr->accountDetail(Account::MapField::ZRTP::DISPLAY_SAS_ONCE) IS_TRUE; } ///Return the account security fallback bool Account::isSrtpRtpFallback() const { - return accountDetail(Account::MapField::SRTP::RTP_FALLBACK) IS_TRUE; + return d_ptr->accountDetail(Account::MapField::SRTP::RTP_FALLBACK) IS_TRUE; } //Return if SRTP is enabled or not bool Account::isSrtpEnabled() const { - return accountDetail(Account::MapField::SRTP::ENABLED) IS_TRUE; + return d_ptr->accountDetail(Account::MapField::SRTP::ENABLED) IS_TRUE; } /// bool Account::isZrtpDisplaySas () const { - return accountDetail(Account::MapField::ZRTP::DISPLAY_SAS) IS_TRUE; + return d_ptr->accountDetail(Account::MapField::ZRTP::DISPLAY_SAS) IS_TRUE; } ///Return if the other side support warning bool Account::isZrtpNotSuppWarning() const { - return accountDetail(Account::MapField::ZRTP::NOT_SUPP_WARNING) IS_TRUE; + return d_ptr->accountDetail(Account::MapField::ZRTP::NOT_SUPP_WARNING) IS_TRUE; } /// bool Account::isZrtpHelloHash() const { - return accountDetail(Account::MapField::ZRTP::HELLO_HASH) IS_TRUE; + return d_ptr->accountDetail(Account::MapField::ZRTP::HELLO_HASH) IS_TRUE; } ///Return if the account is using a STUN server bool Account::isSipStunEnabled() const { - return accountDetail(Account::MapField::STUN::ENABLED) IS_TRUE; + return d_ptr->accountDetail(Account::MapField::STUN::ENABLED) IS_TRUE; } ///Return the account STUN server QString Account::sipStunServer() const { - return accountDetail(Account::MapField::STUN::SERVER); + return d_ptr->accountDetail(Account::MapField::STUN::SERVER); } ///Return when the account expire (require renewal) int Account::registrationExpire() const { - return accountDetail(Account::MapField::Registration::EXPIRE).toInt(); + return d_ptr->accountDetail(Account::MapField::Registration::EXPIRE).toInt(); } ///Return if the published address is the same as the local one bool Account::isPublishedSameAsLocal() const { - return accountDetail(Account::MapField::PUBLISHED_SAMEAS_LOCAL) IS_TRUE; + return d_ptr->accountDetail(Account::MapField::PUBLISHED_SAMEAS_LOCAL) IS_TRUE; } ///Return the account published address QString Account::publishedAddress() const { - return accountDetail(Account::MapField::PUBLISHED_ADDRESS); + return d_ptr->accountDetail(Account::MapField::PUBLISHED_ADDRESS); } ///Return the account published port int Account::publishedPort() const { - return accountDetail(Account::MapField::PUBLISHED_PORT).toUInt(); + return d_ptr->accountDetail(Account::MapField::PUBLISHED_PORT).toUInt(); } ///Return the account tls password QString Account::tlsPassword() const { - return accountDetail(Account::MapField::TLS::PASSWORD); + return d_ptr->accountDetail(Account::MapField::TLS::PASSWORD); } ///Return the account TLS port int Account::tlsListenerPort() const { - return accountDetail(Account::MapField::TLS::LISTENER_PORT).toInt(); + return d_ptr->accountDetail(Account::MapField::TLS::LISTENER_PORT).toInt(); } ///Return the account TLS certificate authority list file Certificate* Account::tlsCaListCertificate() const { - if (!m_pCaCert) { - const_cast<Account*>(this)->m_pCaCert = new Certificate(Certificate::Type::AUTHORITY,this); - connect(m_pCaCert,SIGNAL(changed()),this,SLOT(slotUpdateCertificate())); + if (!d_ptr->m_pCaCert) { + const_cast<Account*>(this)->d_ptr->m_pCaCert = new Certificate(Certificate::Type::AUTHORITY,this); + connect(d_ptr->m_pCaCert,SIGNAL(changed()),d_ptr,SLOT(slotUpdateCertificate())); } - const_cast<Account*>(this)->m_pCaCert->setPath(accountDetail(Account::MapField::TLS::CA_LIST_FILE)); - return m_pCaCert; + const_cast<Account*>(this)->d_ptr->m_pCaCert->setPath(d_ptr->accountDetail(Account::MapField::TLS::CA_LIST_FILE)); + return d_ptr->m_pCaCert; } ///Return the account TLS certificate Certificate* Account::tlsCertificate() const { - if (!m_pTlsCert) { - const_cast<Account*>(this)->m_pTlsCert = new Certificate(Certificate::Type::USER,this); - connect(m_pTlsCert,SIGNAL(changed()),this,SLOT(slotUpdateCertificate())); + if (!d_ptr->m_pTlsCert) { + const_cast<Account*>(this)->d_ptr->m_pTlsCert = new Certificate(Certificate::Type::USER,this); + connect(d_ptr->m_pTlsCert,SIGNAL(changed()),d_ptr,SLOT(slotUpdateCertificate())); } - const_cast<Account*>(this)->m_pTlsCert->setPath(accountDetail(Account::MapField::TLS::CERTIFICATE_FILE)); - return m_pTlsCert; + const_cast<Account*>(this)->d_ptr->m_pTlsCert->setPath(d_ptr->accountDetail(Account::MapField::TLS::CERTIFICATE_FILE)); + return d_ptr->m_pTlsCert; } ///Return the account private key Certificate* Account::tlsPrivateKeyCertificate() const { - if (!m_pPrivateKey) { - const_cast<Account*>(this)->m_pPrivateKey = new Certificate(Certificate::Type::PRIVATE_KEY,this); - connect(m_pPrivateKey,SIGNAL(changed()),this,SLOT(slotUpdateCertificate())); + if (!d_ptr->m_pPrivateKey) { + const_cast<Account*>(this)->d_ptr->m_pPrivateKey = new Certificate(Certificate::Type::PRIVATE_KEY,this); + connect(d_ptr->m_pPrivateKey,SIGNAL(changed()),d_ptr,SLOT(slotUpdateCertificate())); } - const_cast<Account*>(this)->m_pPrivateKey->setPath(accountDetail(Account::MapField::TLS::PRIVATE_KEY_FILE)); - return m_pPrivateKey; + const_cast<Account*>(this)->d_ptr->m_pPrivateKey->setPath(d_ptr->accountDetail(Account::MapField::TLS::PRIVATE_KEY_FILE)); + return d_ptr->m_pPrivateKey; } ///Return the account cipher QString Account::tlsCiphers() const { - return accountDetail(Account::MapField::TLS::CIPHERS); + return d_ptr->accountDetail(Account::MapField::TLS::CIPHERS); } ///Return the account TLS server name QString Account::tlsServerName() const { - return accountDetail(Account::MapField::TLS::SERVER_NAME); + return d_ptr->accountDetail(Account::MapField::TLS::SERVER_NAME); } ///Return the account negotiation timeout in seconds int Account::tlsNegotiationTimeoutSec() const { - return accountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_SEC).toInt(); + return d_ptr->accountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_SEC).toInt(); } ///Return the account negotiation timeout in milliseconds int Account::tlsNegotiationTimeoutMsec() const { - return accountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_MSEC).toInt(); + return d_ptr->accountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_MSEC).toInt(); } ///Return the account TLS verify server bool Account::isTlsVerifyServer() const { - return (accountDetail(Account::MapField::TLS::VERIFY_SERVER) IS_TRUE); + return (d_ptr->accountDetail(Account::MapField::TLS::VERIFY_SERVER) IS_TRUE); } ///Return the account TLS verify client bool Account::isTlsVerifyClient() const { - return (accountDetail(Account::MapField::TLS::VERIFY_CLIENT) IS_TRUE); + return (d_ptr->accountDetail(Account::MapField::TLS::VERIFY_CLIENT) IS_TRUE); } ///Return if it is required for the peer to have a certificate bool Account::isTlsRequireClientCertificate() const { - return (accountDetail(Account::MapField::TLS::REQUIRE_CLIENT_CERTIFICATE) IS_TRUE); + return (d_ptr->accountDetail(Account::MapField::TLS::REQUIRE_CLIENT_CERTIFICATE) IS_TRUE); } ///Return the account TLS security is enabled bool Account::isTlsEnabled() const { - return (accountDetail(Account::MapField::TLS::ENABLED) IS_TRUE); + return (d_ptr->accountDetail(Account::MapField::TLS::ENABLED) IS_TRUE); } ///Return the account the TLS encryption method TlsMethodModel::Type Account::tlsMethod() const { - const QString value = accountDetail(Account::MapField::TLS::METHOD); + const QString value = d_ptr->accountDetail(Account::MapField::TLS::METHOD); return TlsMethodModel::fromDaemonName(value); } ///Return the key exchange mechanism KeyExchangeModel::Type Account::keyExchange() const { - return KeyExchangeModel::fromDaemonName(accountDetail(Account::MapField::SRTP::KEY_EXCHANGE)); + return KeyExchangeModel::fromDaemonName(d_ptr->accountDetail(Account::MapField::SRTP::KEY_EXCHANGE)); } ///Return if the ringtone are enabled bool Account::isRingtoneEnabled() const { - return (accountDetail(Account::MapField::Ringtone::ENABLED) IS_TRUE); + return (d_ptr->accountDetail(Account::MapField::Ringtone::ENABLED) IS_TRUE); } ///Return the account ringtone path QString Account::ringtonePath() const { - return accountDetail(Account::MapField::Ringtone::PATH); + return d_ptr->accountDetail(Account::MapField::Ringtone::PATH); } ///Return the last error message received QString Account::lastErrorMessage() const { - return m_LastErrorMessage; + return d_ptr->m_LastErrorMessage; } ///Return the last error code (useful for debugging) int Account::lastErrorCode() const { - return m_LastErrorCode; + return d_ptr->m_LastErrorCode; } ///Return the account local port int Account::localPort() const { - return accountDetail(Account::MapField::LOCAL_PORT).toInt(); + return d_ptr->accountDetail(Account::MapField::LOCAL_PORT).toInt(); } ///Return the number of voicemails int Account::voiceMailCount() const { - return m_VoiceMailCount; + return d_ptr->m_VoiceMailCount; } ///Return the account local interface QString Account::localInterface() const { - return accountDetail(Account::MapField::LOCAL_INTERFACE); + return d_ptr->accountDetail(Account::MapField::LOCAL_INTERFACE); } ///Return the account registration status QString Account::registrationStatus() const { - return accountDetail(Account::MapField::Registration::STATUS); + return d_ptr->accountDetail(Account::MapField::Registration::STATUS); } ///Return the account type Account::Protocol Account::protocol() const { - const QString str = accountDetail(Account::MapField::TYPE); + const QString str = d_ptr->accountDetail(Account::MapField::TYPE); if (str.isEmpty() || str == Account::ProtocolName::SIP) return Account::Protocol::SIP; else if (str == Account::ProtocolName::IAX) @@ -644,63 +716,63 @@ Account::Protocol Account::protocol() const ///Return the DTMF type DtmfType Account::DTMFType() const { - QString type = accountDetail(Account::MapField::DTMF_TYPE); + QString type = d_ptr->accountDetail(Account::MapField::DTMF_TYPE); return (type == "overrtp" || type.isEmpty())? DtmfType::OverRtp:DtmfType::OverSip; } bool Account::presenceStatus() const { - return m_pAccountNumber->isPresent(); + return d_ptr->m_pAccountNumber->isPresent(); } QString Account::presenceMessage() const { - return m_pAccountNumber->presenceMessage(); + return d_ptr->m_pAccountNumber->presenceMessage(); } bool Account::supportPresencePublish() const { - return accountDetail(Account::MapField::Presence::SUPPORT_PUBLISH) IS_TRUE; + return d_ptr->accountDetail(Account::MapField::Presence::SUPPORT_PUBLISH) IS_TRUE; } bool Account::supportPresenceSubscribe() const { - return accountDetail(Account::MapField::Presence::SUPPORT_SUBSCRIBE) IS_TRUE; + return d_ptr->accountDetail(Account::MapField::Presence::SUPPORT_SUBSCRIBE) IS_TRUE; } bool Account::presenceEnabled() const { - return accountDetail(Account::MapField::Presence::ENABLED) IS_TRUE; + return d_ptr->accountDetail(Account::MapField::Presence::ENABLED) IS_TRUE; } bool Account::isVideoEnabled() const { - return accountDetail(Account::MapField::Video::ENABLED) IS_TRUE; + return d_ptr->accountDetail(Account::MapField::Video::ENABLED) IS_TRUE; } int Account::videoPortMax() const { - return accountDetail(Account::MapField::Video::PORT_MAX).toInt(); + return d_ptr->accountDetail(Account::MapField::Video::PORT_MAX).toInt(); } int Account::videoPortMin() const { - return accountDetail(Account::MapField::Video::PORT_MIN).toInt(); + return d_ptr->accountDetail(Account::MapField::Video::PORT_MIN).toInt(); } int Account::audioPortMin() const { - return accountDetail(Account::MapField::Audio::PORT_MIN).toInt(); + return d_ptr->accountDetail(Account::MapField::Audio::PORT_MIN).toInt(); } int Account::audioPortMax() const { - return accountDetail(Account::MapField::Audio::PORT_MAX).toInt(); + return d_ptr->accountDetail(Account::MapField::Audio::PORT_MAX).toInt(); } QString Account::userAgent() const { - return accountDetail(Account::MapField::USER_AGENT); + return d_ptr->accountDetail(Account::MapField::USER_AGENT); } QVariant Account::roleData(int role) const @@ -810,7 +882,7 @@ QVariant Account::roleData(int role) const ****************************************************************************/ ///Set account details -void Account::setAccountDetails(const QHash<QString,QString>& m) +void AccountPrivate::setAccountDetails(const QHash<QString,QString>& m) { m_hAccountDetails.clear(); m_hAccountDetails = m; @@ -818,35 +890,35 @@ void Account::setAccountDetails(const QHash<QString,QString>& m) } ///Set a specific detail -bool Account::setAccountDetail(const QString& param, const QString& val) +bool AccountPrivate::setAccountDetail(const QString& param, const QString& val) { const bool accChanged = m_hAccountDetails[param] != val; const QString buf = m_hAccountDetails[param]; if (param == Account::MapField::Registration::STATUS) { m_hAccountDetails[param] = val; if (accChanged) { - emit detailChanged(this,param,val,buf); + emit q_ptr->detailChanged(q_ptr,param,val,buf); } } else { - performAction(AccountEditAction::MODIFY); - if (m_CurrentState == AccountEditState::MODIFIED || m_CurrentState == AccountEditState::NEW) { + q_ptr->performAction(Account::EditAction::MODIFY); + if (m_CurrentState == Account::EditState::MODIFIED || m_CurrentState == Account::EditState::NEW) { m_hAccountDetails[param] = val; if (accChanged) { - emit detailChanged(this,param,val,buf); + emit q_ptr->detailChanged(q_ptr,param,val,buf); } } } - return m_CurrentState == AccountEditState::MODIFIED || m_CurrentState == AccountEditState::NEW; + return m_CurrentState == Account::EditState::MODIFIED || m_CurrentState == Account::EditState::NEW; } ///Set the account id void Account::setId(const QString& id) { - qDebug() << "Setting accountId = " << m_AccountId; + qDebug() << "Setting accountId = " << d_ptr->m_AccountId; if (! isNew()) qDebug() << "Error : setting AccountId of an existing account."; - m_AccountId = id; + d_ptr->m_AccountId = id; } ///Set the account type, SIP or IAX @@ -854,10 +926,10 @@ void Account::setProtocol(Account::Protocol proto) { switch (proto) { case Account::Protocol::SIP: - setAccountDetail(Account::MapField::TYPE ,Account::ProtocolName::SIP); + d_ptr->setAccountDetail(Account::MapField::TYPE ,Account::ProtocolName::SIP); break; case Account::Protocol::IAX: - setAccountDetail(Account::MapField::TYPE ,Account::ProtocolName::IAX); + d_ptr->setAccountDetail(Account::MapField::TYPE ,Account::ProtocolName::IAX); break; }; } @@ -865,28 +937,28 @@ void Account::setProtocol(Account::Protocol proto) ///The set account hostname, it can be an hostname or an IP address void Account::setHostname(const QString& detail) { - if (m_HostName != detail) { - m_HostName = detail; - setAccountDetail(Account::MapField::HOSTNAME, detail); + if (d_ptr->m_HostName != detail) { + d_ptr->m_HostName = detail; + d_ptr->setAccountDetail(Account::MapField::HOSTNAME, detail); } } ///Set the account username, everything is valid, some might be rejected by the PBX server void Account::setUsername(const QString& detail) { - setAccountDetail(Account::MapField::USERNAME, detail); + d_ptr->setAccountDetail(Account::MapField::USERNAME, detail); } ///Set the account mailbox, usually a number, but can be anything void Account::setMailbox(const QString& detail) { - setAccountDetail(Account::MapField::MAILBOX, detail); + d_ptr->setAccountDetail(Account::MapField::MAILBOX, detail); } ///Set the account mailbox, usually a number, but can be anything void Account::setProxy(const QString& detail) { - setAccountDetail(Account::MapField::ROUTE, detail); + d_ptr->setAccountDetail(Account::MapField::ROUTE, detail); } ///Set the main credential password @@ -902,7 +974,7 @@ void Account::setPassword(const QString& detail) } break; case Account::Protocol::IAX: - setAccountDetail(Account::MapField::PASSWORD, detail); + d_ptr->setAccountDetail(Account::MapField::PASSWORD, detail); break; }; } @@ -910,256 +982,255 @@ void Account::setPassword(const QString& detail) ///Set the TLS (encryption) password void Account::setTlsPassword(const QString& detail) { - setAccountDetail(Account::MapField::TLS::PASSWORD, detail); + d_ptr->setAccountDetail(Account::MapField::TLS::PASSWORD, detail); } ///Set the certificate authority list file void Account::setTlsCaListCertificate(Certificate* cert) { - m_pCaCert = cert; //FIXME memory leak - setAccountDetail(Account::MapField::TLS::CA_LIST_FILE, cert?cert->path().toLocalFile():QString()); + d_ptr->m_pCaCert = cert; //FIXME memory leak + d_ptr->setAccountDetail(Account::MapField::TLS::CA_LIST_FILE, cert?cert->path().toLocalFile():QString()); } ///Set the certificate void Account::setTlsCertificate(Certificate* cert) { - m_pTlsCert = cert; //FIXME memory leak - setAccountDetail(Account::MapField::TLS::CERTIFICATE_FILE, cert?cert->path().toLocalFile():QString()); + d_ptr->m_pTlsCert = cert; //FIXME memory leak + d_ptr->setAccountDetail(Account::MapField::TLS::CERTIFICATE_FILE, cert?cert->path().toLocalFile():QString()); } ///Set the private key void Account::setTlsPrivateKeyCertificate(Certificate* cert) { - m_pPrivateKey = cert; //FIXME memory leak - setAccountDetail(Account::MapField::TLS::PRIVATE_KEY_FILE, cert?cert->path().toLocalFile():QString()); + d_ptr->m_pPrivateKey = cert; //FIXME memory leak + d_ptr->setAccountDetail(Account::MapField::TLS::PRIVATE_KEY_FILE, cert?cert->path().toLocalFile():QString()); } ///Set the TLS cipher void Account::setTlsCiphers(const QString& detail) { - setAccountDetail(Account::MapField::TLS::CIPHERS, detail); + d_ptr->setAccountDetail(Account::MapField::TLS::CIPHERS, detail); } ///Set the TLS server void Account::setTlsServerName(const QString& detail) { - setAccountDetail(Account::MapField::TLS::SERVER_NAME, detail); + d_ptr->setAccountDetail(Account::MapField::TLS::SERVER_NAME, detail); } ///Set the stun server void Account::setSipStunServer(const QString& detail) { - setAccountDetail(Account::MapField::STUN::SERVER, detail); + d_ptr->setAccountDetail(Account::MapField::STUN::SERVER, detail); } ///Set the published address void Account::setPublishedAddress(const QString& detail) { - setAccountDetail(Account::MapField::PUBLISHED_ADDRESS, detail); + d_ptr->setAccountDetail(Account::MapField::PUBLISHED_ADDRESS, detail); } ///Set the local interface void Account::setLocalInterface(const QString& detail) { - setAccountDetail(Account::MapField::LOCAL_INTERFACE, detail); + d_ptr->setAccountDetail(Account::MapField::LOCAL_INTERFACE, detail); } ///Set the ringtone path, it have to be a valid absolute path void Account::setRingtonePath(const QString& detail) { - setAccountDetail(Account::MapField::Ringtone::PATH, detail); + d_ptr->setAccountDetail(Account::MapField::Ringtone::PATH, detail); } ///Set the number of voice mails void Account::setVoiceMailCount(int count) { - m_VoiceMailCount = count; + d_ptr->m_VoiceMailCount = count; } ///Set the last error message to be displayed as status instead of "Error" void Account::setLastErrorMessage(const QString& message) { - m_LastErrorMessage = message; + d_ptr->m_LastErrorMessage = message; } ///Set the last error code void Account::setLastErrorCode(int code) { - m_LastErrorCode = code; + d_ptr->m_LastErrorCode = code; } ///Set the Tls method void Account::setTlsMethod(TlsMethodModel::Type detail) { - - setAccountDetail(Account::MapField::TLS::METHOD ,TlsMethodModel::toDaemonName(detail)); + d_ptr->setAccountDetail(Account::MapField::TLS::METHOD ,TlsMethodModel::toDaemonName(detail)); } ///Set the Tls method void Account::setKeyExchange(KeyExchangeModel::Type detail) { - setAccountDetail(Account::MapField::SRTP::KEY_EXCHANGE ,KeyExchangeModel::toDaemonName(detail)); + d_ptr->setAccountDetail(Account::MapField::SRTP::KEY_EXCHANGE ,KeyExchangeModel::toDaemonName(detail)); } ///Set the account timeout, it will be renegotiated when that timeout occur void Account::setRegistrationExpire(int detail) { - setAccountDetail(Account::MapField::Registration::EXPIRE, QString::number(detail)); + d_ptr->setAccountDetail(Account::MapField::Registration::EXPIRE, QString::number(detail)); } ///Set TLS negotiation timeout in second void Account::setTlsNegotiationTimeoutSec(int detail) { - setAccountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_SEC, QString::number(detail)); + d_ptr->setAccountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_SEC, QString::number(detail)); } ///Set the TLS negotiation timeout in milliseconds void Account::setTlsNegotiationTimeoutMsec(int detail) { - setAccountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_MSEC, QString::number(detail)); + d_ptr->setAccountDetail(Account::MapField::TLS::NEGOTIATION_TIMEOUT_MSEC, QString::number(detail)); } ///Set the local port for SIP/IAX communications void Account::setLocalPort(unsigned short detail) { - setAccountDetail(Account::MapField::LOCAL_PORT, QString::number(detail)); + d_ptr->setAccountDetail(Account::MapField::LOCAL_PORT, QString::number(detail)); } ///Set the TLS listener port (0-2^16) void Account::setTlsListenerPort(unsigned short detail) { - setAccountDetail(Account::MapField::TLS::LISTENER_PORT, QString::number(detail)); + d_ptr->setAccountDetail(Account::MapField::TLS::LISTENER_PORT, QString::number(detail)); } ///Set the published port (0-2^16) void Account::setPublishedPort(unsigned short detail) { - setAccountDetail(Account::MapField::PUBLISHED_PORT, QString::number(detail)); + d_ptr->setAccountDetail(Account::MapField::PUBLISHED_PORT, QString::number(detail)); } ///Set if the account is enabled or not void Account::setEnabled(bool detail) { - setAccountDetail(Account::MapField::ENABLED, (detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::ENABLED, (detail)TO_BOOL); } ///Set if the account should auto answer void Account::setAutoAnswer(bool detail) { - setAccountDetail(Account::MapField::AUTOANSWER, (detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::AUTOANSWER, (detail)TO_BOOL); } ///Set the TLS verification server void Account::setTlsVerifyServer(bool detail) { - setAccountDetail(Account::MapField::TLS::VERIFY_SERVER, (detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::TLS::VERIFY_SERVER, (detail)TO_BOOL); } ///Set the TLS verification client void Account::setTlsVerifyClient(bool detail) { - setAccountDetail(Account::MapField::TLS::VERIFY_CLIENT, (detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::TLS::VERIFY_CLIENT, (detail)TO_BOOL); } ///Set if the peer need to be providing a certificate void Account::setTlsRequireClientCertificate(bool detail) { - setAccountDetail(Account::MapField::TLS::REQUIRE_CLIENT_CERTIFICATE ,(detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::TLS::REQUIRE_CLIENT_CERTIFICATE ,(detail)TO_BOOL); } ///Set if the security settings are enabled void Account::setTlsEnabled(bool detail) { - setAccountDetail(Account::MapField::TLS::ENABLED ,(detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::TLS::ENABLED ,(detail)TO_BOOL); } void Account::setDisplaySasOnce(bool detail) { - setAccountDetail(Account::MapField::ZRTP::DISPLAY_SAS_ONCE, (detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::ZRTP::DISPLAY_SAS_ONCE, (detail)TO_BOOL); } void Account::setSrtpRtpFallback(bool detail) { - setAccountDetail(Account::MapField::SRTP::RTP_FALLBACK, (detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::SRTP::RTP_FALLBACK, (detail)TO_BOOL); } void Account::setSrtpEnabled(bool detail) { - setAccountDetail(Account::MapField::SRTP::ENABLED, (detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::SRTP::ENABLED, (detail)TO_BOOL); } void Account::setZrtpDisplaySas(bool detail) { - setAccountDetail(Account::MapField::ZRTP::DISPLAY_SAS, (detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::ZRTP::DISPLAY_SAS, (detail)TO_BOOL); } void Account::setZrtpNotSuppWarning(bool detail) { - setAccountDetail(Account::MapField::ZRTP::NOT_SUPP_WARNING, (detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::ZRTP::NOT_SUPP_WARNING, (detail)TO_BOOL); } void Account::setZrtpHelloHash(bool detail) { - setAccountDetail(Account::MapField::ZRTP::HELLO_HASH, (detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::ZRTP::HELLO_HASH, (detail)TO_BOOL); } void Account::setSipStunEnabled(bool detail) { - setAccountDetail(Account::MapField::STUN::ENABLED, (detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::STUN::ENABLED, (detail)TO_BOOL); } void Account::setPublishedSameAsLocal(bool detail) { - setAccountDetail(Account::MapField::PUBLISHED_SAMEAS_LOCAL, (detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::PUBLISHED_SAMEAS_LOCAL, (detail)TO_BOOL); } ///Set if custom ringtone are enabled void Account::setRingtoneEnabled(bool detail) { - setAccountDetail(Account::MapField::Ringtone::ENABLED, (detail)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::Ringtone::ENABLED, (detail)TO_BOOL); } void Account::setPresenceEnabled(bool enable) { - setAccountDetail(Account::MapField::Presence::ENABLED, (enable)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::Presence::ENABLED, (enable)TO_BOOL); emit presenceEnabledChanged(enable); } ///Use video by default when available void Account::setVideoEnabled(bool enable) { - setAccountDetail(Account::MapField::Video::ENABLED, (enable)TO_BOOL); + d_ptr->setAccountDetail(Account::MapField::Video::ENABLED, (enable)TO_BOOL); } void Account::setAudioPortMax(int port ) { - setAccountDetail(Account::MapField::Audio::PORT_MAX, QString::number(port)); + d_ptr->setAccountDetail(Account::MapField::Audio::PORT_MAX, QString::number(port)); } void Account::setAudioPortMin(int port ) { - setAccountDetail(Account::MapField::Audio::PORT_MIN, QString::number(port)); + d_ptr->setAccountDetail(Account::MapField::Audio::PORT_MIN, QString::number(port)); } void Account::setVideoPortMax(int port ) { - setAccountDetail(Account::MapField::Video::PORT_MAX, QString::number(port)); + d_ptr->setAccountDetail(Account::MapField::Video::PORT_MAX, QString::number(port)); } void Account::setVideoPortMin(int port ) { - setAccountDetail(Account::MapField::Video::PORT_MIN, QString::number(port)); + d_ptr->setAccountDetail(Account::MapField::Video::PORT_MIN, QString::number(port)); } void Account::setUserAgent(const QString& agent) { - setAccountDetail(Account::MapField::USER_AGENT, agent); + d_ptr->setAccountDetail(Account::MapField::USER_AGENT, agent); } ///Set the DTMF type void Account::setDTMFType(DtmfType type) { - setAccountDetail(Account::MapField::DTMF_TYPE,(type==OverRtp)?"overrtp":"oversip"); + d_ptr->setAccountDetail(Account::MapField::DTMF_TYPE,(type==OverRtp)?"overrtp":"oversip"); } void Account::setRoleData(int role, const QVariant& value) @@ -1313,16 +1384,21 @@ void Account::setRoleData(int role, const QVariant& value) * * ****************************************************************************/ -bool Account::performAction(AccountEditAction action) +void AccountPrivate::performAction(Account::EditAction action) { - AccountEditState curState = m_CurrentState; (this->*(stateMachineActionsOnState[(int)m_CurrentState][(int)action]))();//FIXME don't use integer cast - return curState != m_CurrentState; } -Account::AccountEditState Account::state() const +bool Account::performAction(EditAction action) { - return m_CurrentState; + Account::EditState curState = d_ptr->m_CurrentState; + d_ptr->performAction(action); + return curState != d_ptr->m_CurrentState; +} + +Account::EditState Account::state() const +{ + return d_ptr->m_CurrentState; } /**Update the account @@ -1335,17 +1411,17 @@ bool Account::updateState() const MapStringString details = configurationManager.getAccountDetails(id()).value(); const QString status = details[Account::MapField::Registration::STATUS]; const QString currentStatus = registrationStatus(); - setAccountDetail(Account::MapField::Registration::STATUS, status); //Update -internal- object state + d_ptr->setAccountDetail(Account::MapField::Registration::STATUS, status); //Update -internal- object state return status == currentStatus; } return true; } ///Save the current account to the daemon -void Account::save() +void AccountPrivate::save() { ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance(); - if (isNew()) { + if (q_ptr->isNew()) { MapStringString details; QMutableHashIterator<QString,QString> iter(m_hAccountDetails); @@ -1367,10 +1443,10 @@ void Account::save() m_pAudioCodecs->setData(idx,aCodec ,AudioCodecModel::Role::ID ); m_pAudioCodecs->setData(idx, Qt::Checked ,Qt::CheckStateRole); } - saveAudioCodecs(); + q_ptr->saveAudioCodecs(); - setId(currentId); - saveCredentials(); + q_ptr->setId(currentId); + q_ptr->saveCredentials(); } //New account else { //Existing account MapStringString tmp; @@ -1380,37 +1456,37 @@ void Account::save() iter.next(); tmp[iter.key()] = iter.value(); } - configurationManager.setAccountDetails(id(), tmp); + configurationManager.setAccountDetails(q_ptr->id(), tmp); } - if (!id().isEmpty()) { - Account* acc = AccountListModel::instance()->getAccountById(id()); - qDebug() << "Adding the new account to the account list (" << id() << ")"; - if (acc != this) { - (AccountListModel::instance()->m_lAccounts) << this; + if (!q_ptr->id().isEmpty()) { + Account* acc = AccountListModel::instance()->getAccountById(q_ptr->id()); + qDebug() << "Adding the new account to the account list (" << q_ptr->id() << ")"; + if (acc != q_ptr) { + (AccountListModel::instance()->m_lAccounts) << q_ptr; } - performAction(AccountEditAction::RELOAD); - updateState(); - m_CurrentState = AccountEditState::READY; + q_ptr->performAction(Account::EditAction::RELOAD); + q_ptr->updateState(); + m_CurrentState = Account::EditState::READY; } #ifdef ENABLE_VIDEO - videoCodecModel()->save(); + q_ptr->videoCodecModel()->save(); #endif - saveAudioCodecs(); - emit changed(this); + q_ptr->saveAudioCodecs(); + emit q_ptr->changed(q_ptr); } ///sync with the daemon, this need to be done manually to prevent reloading the account while it is being edited -void Account::reload() +void AccountPrivate::reload() { - if (!isNew()) { + if (!q_ptr->isNew()) { if (m_hAccountDetails.size()) - qDebug() << "Reloading" << id() << alias(); + qDebug() << "Reloading" << q_ptr->id() << q_ptr->alias(); else - qDebug() << "Loading" << id(); + qDebug() << "Loading" << q_ptr->id(); ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance(); - QMap<QString,QString> aDetails = configurationManager.getAccountDetails(id()); + QMap<QString,QString> aDetails = configurationManager.getAccountDetails(q_ptr->id()); if (!aDetails.count()) { qDebug() << "Account not found"; @@ -1422,17 +1498,17 @@ void Account::reload() iter.next(); m_hAccountDetails[iter.key()] = iter.value(); } - setHostname(m_hAccountDetails[Account::MapField::HOSTNAME]); + q_ptr->setHostname(m_hAccountDetails[Account::MapField::HOSTNAME]); } - m_CurrentState = AccountEditState::READY; + m_CurrentState = Account::EditState::READY; - const QString currentUri = QString("%1@%2").arg(username()).arg(m_HostName); + const QString currentUri = QString("%1@%2").arg(q_ptr->username()).arg(m_HostName); if (!m_pAccountNumber || (m_pAccountNumber && m_pAccountNumber->uri() != currentUri)) { if (m_pAccountNumber) { disconnect(m_pAccountNumber,SIGNAL(presenceMessageChanged(QString)),this,SLOT(slotPresenceMessageChanged(QString))); disconnect(m_pAccountNumber,SIGNAL(presentChanged(bool)),this,SLOT(slotPresentChanged(bool))); } - m_pAccountNumber = PhoneDirectoryModel::instance()->getNumber(currentUri,this); + m_pAccountNumber = PhoneDirectoryModel::instance()->getNumber(currentUri,q_ptr); m_pAccountNumber->setType(PhoneNumber::Type::ACCOUNT); connect(m_pAccountNumber,SIGNAL(presenceMessageChanged(QString)),this,SLOT(slotPresenceMessageChanged(QString))); connect(m_pAccountNumber,SIGNAL(presentChanged(bool)),this,SLOT(slotPresentChanged(bool))); @@ -1440,50 +1516,50 @@ void Account::reload() //If the credential model is loaded, then update it if (m_pCredentials) - reloadCredentials(); - emit changed(this); + q_ptr->reloadCredentials(); + emit q_ptr->changed(q_ptr); } } ///Reload credentials from DBUS void Account::reloadCredentials() { - if (!m_pCredentials) { - m_pCredentials = new CredentialModel(this); + if (!d_ptr->m_pCredentials) { + d_ptr->m_pCredentials = new CredentialModel(this); } if (!isNew()) { - m_pCredentials->clear(); + d_ptr->m_pCredentials->clear(); ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance(); VectorMapStringString credentials = configurationManager.getCredentials(id()); for (int i=0; i < credentials.size(); i++) { - QModelIndex idx = m_pCredentials->addCredentials(); - m_pCredentials->setData(idx,credentials[i][ Account::MapField::USERNAME ],CredentialModel::Role::NAME ); - m_pCredentials->setData(idx,credentials[i][ Account::MapField::PASSWORD ],CredentialModel::Role::PASSWORD); - m_pCredentials->setData(idx,credentials[i][ Account::MapField::REALM ],CredentialModel::Role::REALM ); + QModelIndex idx = d_ptr->m_pCredentials->addCredentials(); + d_ptr->m_pCredentials->setData(idx,credentials[i][ Account::MapField::USERNAME ],CredentialModel::Role::NAME ); + d_ptr->m_pCredentials->setData(idx,credentials[i][ Account::MapField::PASSWORD ],CredentialModel::Role::PASSWORD); + d_ptr->m_pCredentials->setData(idx,credentials[i][ Account::MapField::REALM ],CredentialModel::Role::REALM ); } } } ///Save all credentials void Account::saveCredentials() { - if (m_pCredentials) { + if (d_ptr->m_pCredentials) { ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance(); VectorMapStringString toReturn; - for (int i=0; i < m_pCredentials->rowCount();i++) { - QModelIndex idx = m_pCredentials->index(i,0); + for (int i=0; i < d_ptr->m_pCredentials->rowCount();i++) { + QModelIndex idx = d_ptr->m_pCredentials->index(i,0); MapStringString credentialData; - QString user = m_pCredentials->data(idx,CredentialModel::Role::NAME).toString(); - QString realm = m_pCredentials->data(idx,CredentialModel::Role::REALM).toString(); + QString user = d_ptr->m_pCredentials->data(idx,CredentialModel::Role::NAME).toString(); + QString realm = d_ptr->m_pCredentials->data(idx,CredentialModel::Role::REALM).toString(); if (user.isEmpty()) { user = username(); - m_pCredentials->setData(idx,user,CredentialModel::Role::NAME); + d_ptr->m_pCredentials->setData(idx,user,CredentialModel::Role::NAME); } if (realm.isEmpty()) { realm = '*'; - m_pCredentials->setData(idx,realm,CredentialModel::Role::REALM); + d_ptr->m_pCredentials->setData(idx,realm,CredentialModel::Role::REALM); } credentialData[ Account::MapField::USERNAME ] = user; - credentialData[ Account::MapField::PASSWORD ] = m_pCredentials->data(idx,CredentialModel::Role::PASSWORD).toString(); + credentialData[ Account::MapField::PASSWORD ] = d_ptr->m_pCredentials->data(idx,CredentialModel::Role::PASSWORD).toString(); credentialData[ Account::MapField::REALM ] = realm; toReturn << credentialData; } @@ -1494,16 +1570,16 @@ void Account::saveCredentials() { ///Reload all audio codecs void Account::reloadAudioCodecs() { - if (!m_pAudioCodecs) { - m_pAudioCodecs = new AudioCodecModel(this); + if (!d_ptr->m_pAudioCodecs) { + d_ptr->m_pAudioCodecs = new AudioCodecModel(this); } - m_pAudioCodecs->reload(); + d_ptr->m_pAudioCodecs->reload(); } ///Save audio codecs void Account::saveAudioCodecs() { - if (m_pAudioCodecs) - m_pAudioCodecs->save(); + if (d_ptr->m_pAudioCodecs) + d_ptr->m_pAudioCodecs->save(); } /***************************************************************************** @@ -1515,7 +1591,7 @@ void Account::saveAudioCodecs() { ///Are both account the same bool Account::operator==(const Account& a)const { - return m_AccountId == a.m_AccountId; + return d_ptr->m_AccountId == a.d_ptr->m_AccountId; } /***************************************************************************** @@ -1526,3 +1602,4 @@ bool Account::operator==(const Account& a)const #undef TO_BOOL #undef IS_TRUE +#include <account.moc> diff --git a/src/account.h b/src/account.h index 0c9aca6d10db063f83abb8137a730dedcbd02b50..57ab7b2560cbb26f2255cde9e885a25339e26fdc 100644 --- a/src/account.h +++ b/src/account.h @@ -39,7 +39,9 @@ class PhoneNumber ; class SecurityValidationModel; class Certificate ; -typedef void (Account::*account_function)(); +//Private +class AccountPrivate; + ///@enum DtmfType Different method to send the DTMF (key sound) to the peer enum DtmfType { @@ -115,8 +117,8 @@ class LIB_EXPORT Account : public QObject { public: - ///@enum AccountEditState: Manage how and when an account can be reloaded or change state - enum class AccountEditState { + ///@enum EditState: Manage how and when an account can be reloaded or change state + enum class EditState { READY = 0, EDITING = 1, OUTDATED = 2, @@ -125,8 +127,8 @@ class LIB_EXPORT Account : public QObject { REMOVED = 5 }; - ///@enum AccountEditAction Actions that can be performed on the Account state - enum class AccountEditAction { + ///@enum EditAction Actions that can be performed on the Account state + enum class EditAction { NOTHING = 0, EDIT = 1, RELOAD = 2, @@ -313,14 +315,13 @@ class LIB_EXPORT Account : public QObject { *Perform an action * @return If the state changed */ - bool performAction(Account::AccountEditAction action); - Account::AccountEditState state() const; + bool performAction(Account::EditAction action); + Account::EditState state() const; //Getters bool isNew() const; const QString id() const; const QString toHumanStateName() const; - const QString accountDetail(const QString& param) const; const QString alias() const; bool isRegistered() const; QModelIndex index() ; @@ -463,53 +464,12 @@ class LIB_EXPORT Account : public QObject { public Q_SLOTS: void setEnabled(bool checked); - private Q_SLOTS: - void slotPresentChanged (bool present ); - void slotPresenceMessageChanged(const QString& ); - void slotUpdateCertificate ( ); - private: //Constructors Account(); - //Attributes - QString m_AccountId ; - QHash<QString,QString> m_hAccountDetails; - PhoneNumber* m_pAccountNumber ; - - //Setters - void setAccountDetails (const QHash<QString,QString>& m ); - bool setAccountDetail (const QString& param, const QString& val ); - - //State actions - void nothing() {}; - void edit() {m_CurrentState = AccountEditState::EDITING ;emit changed(this);}; - void modify() {m_CurrentState = AccountEditState::MODIFIED;emit changed(this);}; - void remove() {m_CurrentState = AccountEditState::REMOVED ;emit changed(this);}; - void cancel() {m_CurrentState = AccountEditState::READY ;emit changed(this);}; - void outdate() {m_CurrentState = AccountEditState::OUTDATED;emit changed(this);}; - void reload(); - void save(); - void reloadMod() {reload();modify();}; - - CredentialModel* m_pCredentials ; - AudioCodecModel* m_pAudioCodecs ; - VideoCodecModel* m_pVideoCodecs ; - RingToneModel* m_pRingToneModel ; - KeyExchangeModel* m_pKeyExchangeModel; - SecurityValidationModel* m_pSecurityValidationModel; - AccountEditState m_CurrentState; - static const account_function stateMachineActionsOnState[6][7]; - - //Cached account details (as they are called too often for the hash) - QString m_HostName; - QString m_LastErrorMessage; - int m_LastErrorCode; - int m_VoiceMailCount; - Certificate* m_pCaCert; - Certificate* m_pTlsCert; - Certificate* m_pPrivateKey; - + QScopedPointer<AccountPrivate> d_ptr; + Q_DECLARE_PRIVATE(Account) Q_SIGNALS: ///The account state (Invalid,Trying,Registered) changed diff --git a/src/accountlistmodel.cpp b/src/accountlistmodel.cpp index 871e9e9a318f9f623847f6dc0a18da06a2714160..603dc03e55d67578103e687d1cbd3186bf86ef6a 100644 --- a/src/accountlistmodel.cpp +++ b/src/accountlistmodel.cpp @@ -195,7 +195,7 @@ void AccountListModel::accountChanged(const QString& account,const QString& stat } foreach (Account* acc, m_lAccounts) { const int idx =accountIds.indexOf(acc->id()); - if (idx == -1 && (acc->state() == Account::AccountEditState::READY || acc->state() == Account::AccountEditState::REMOVED)) { + if (idx == -1 && (acc->state() == Account::EditState::READY || acc->state() == Account::EditState::REMOVED)) { m_lAccounts.remove(idx); emit dataChanged(index(idx - 1, 0), index(m_lAccounts.size()-1, 0)); emit layoutChanged(); @@ -268,9 +268,9 @@ void AccountListModel::update() for (int i = 0; i < tmp.size(); i++) { Account* current = tmp[i]; - if (!current->isNew() && (current->state() != Account::AccountEditState::NEW - && current->state() != Account::AccountEditState::MODIFIED - && current->state() != Account::AccountEditState::OUTDATED)) + if (!current->isNew() && (current->state() != Account::EditState::NEW + && current->state() != Account::EditState::MODIFIED + && current->state() != Account::EditState::OUTDATED)) removeAccount(current); } //ask for the list of accounts ids to the configurationManager @@ -304,7 +304,7 @@ void AccountListModel::updateAccounts() emit dataChanged(index(size()-1,0),index(size()-1,0)); } else { - acc->performAction(Account::AccountEditAction::RELOAD); + acc->performAction(Account::EditAction::RELOAD); } } emit accountListUpdated(); @@ -319,7 +319,7 @@ void AccountListModel::save() //create or update each account from accountList for (int i = 0; i < size(); i++) { Account* current = (*this)[i]; - current->performAction(Account::AccountEditAction::SAVE); + current->performAction(Account::EditAction::SAVE); } //remove accounts that are in the configurationManager but not in the client @@ -375,8 +375,8 @@ void AccountListModel::registerAllAccounts() ///Cancel all modifications void AccountListModel::cancel() { foreach (Account* a, getAccounts()) { - if (a->state() == Account::AccountEditState::MODIFIED || a->state() == Account::AccountEditState::OUTDATED) - a->performAction(Account::AccountEditAction::CANCEL); + if (a->state() == Account::EditState::MODIFIED || a->state() == Account::EditState::OUTDATED) + a->performAction(Account::EditAction::CANCEL); } m_lDeletedAccounts.clear(); } diff --git a/src/accountlistmodel.h b/src/accountlistmodel.h index 8490f889f187111593f2f52ea6a7050f8351c982..441ea65d94c80f9d8ea888e3c5d4ff69ca56dd44 100644 --- a/src/accountlistmodel.h +++ b/src/accountlistmodel.h @@ -45,6 +45,7 @@ public: Q_PROPERTY(bool presenceSubscribeSupported READ isPresenceSubscribeSupported ) friend class Account; + friend class AccountPrivate; //Static getter and destructor static AccountListModel* instance(); static void destroy(); @@ -107,17 +108,18 @@ private: QStringList m_lDeletedAccounts; Account* m_pIP2IP ; -public Q_SLOTS: - void update (); - void updateAccounts(); - void registerAllAccounts(); - private Q_SLOTS: void accountChanged(const QString& account,const QString& state, int code); void accountChanged(Account* a); void slotVoiceMailNotify( const QString& accountID , int count ); void slotAccountPresenceEnabledChanged(bool state); +public Q_SLOTS: + void update (); + void updateAccounts(); + void registerAllAccounts(); + + Q_SIGNALS: ///The account list changed void accountListUpdated();