Skip to content
Snippets Groups Projects
Commit b557a9ef authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

[ #25424 ] Make load time 12% faster

parent 4707ebcb
No related branches found
No related tags found
No related merge requests found
...@@ -79,10 +79,23 @@ int AbstractContactBackend::getUpdateCount() ...@@ -79,10 +79,23 @@ int AbstractContactBackend::getUpdateCount()
///Return the extension/user of an URI (<sip:12345@exemple.com>) ///Return the extension/user of an URI (<sip:12345@exemple.com>)
QString AbstractContactBackend::getUserFromPhone(QString phoneNumber) QString AbstractContactBackend::getUserFromPhone(QString phoneNumber)
{ {
if (phoneNumber.indexOf('@') != -1) { //Too slow
QString user = phoneNumber.split('@')[0]; // if (phoneNumber.indexOf('@') != -1) {
return (user.indexOf(':') != -1)?user.split(':')[1]:user; // QString user = phoneNumber.split('@')[0];
} // return (user.indexOf(':') != -1)?user.split(':')[1]:user;
// }
int start(0),stop(0);
for (int i=0;i<phoneNumber.size();i++) {
const char c = phoneNumber[i].cell(); //Because it is fast
if (c == ':')
start = i;
else if (c == '@') {
stop = i;
break;
}
}
if (stop)
return phoneNumber.mid(start,stop);
return phoneNumber; return phoneNumber;
} //getUserFromPhone } //getUserFromPhone
......
...@@ -83,7 +83,7 @@ const QString& account_state_name(const QString& s) ...@@ -83,7 +83,7 @@ const QString& account_state_name(const QString& s)
} //account_state_name } //account_state_name
///Constructors ///Constructors
Account::Account():m_pAccountId(nullptr),m_pAccountDetails(nullptr),m_pCredentials(nullptr),m_pAudioCodecs(nullptr),m_CurrentState(READY), Account::Account():m_pAccountId(nullptr),m_pCredentials(nullptr),m_pAudioCodecs(nullptr),m_CurrentState(READY),
m_pVideoCodecs(nullptr) m_pVideoCodecs(nullptr)
{ {
CallManagerInterface& callManager = CallManagerInterfaceSingleton::getInstance(); CallManagerInterface& callManager = CallManagerInterfaceSingleton::getInstance();
...@@ -108,7 +108,14 @@ Account* Account::buildNewAccountFromAlias(const QString& alias) ...@@ -108,7 +108,14 @@ Account* Account::buildNewAccountFromAlias(const QString& alias)
qDebug() << "Building an account from alias: " << alias; qDebug() << "Building an account from alias: " << alias;
ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance(); ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
Account* a = new Account(); Account* a = new Account();
a->m_pAccountDetails = new MapStringString(configurationManager.getAccountTemplate()); a->m_hAccountDetails.clear();
MapStringString tmp = configurationManager.getAccountTemplate();
QMutableMapIterator<QString, QString> iter(tmp);
while (iter.hasNext()) {
iter.next();
a->m_hAccountDetails[iter.key()] = iter.value();
}
a->setAccountHostname(a->m_hAccountDetails[ACCOUNT_HOSTNAME]);
a->setAccountDetail(ACCOUNT_ALIAS,alias); a->setAccountDetail(ACCOUNT_ALIAS,alias);
return a; return a;
} }
...@@ -119,7 +126,6 @@ Account::~Account() ...@@ -119,7 +126,6 @@ Account::~Account()
disconnect(); disconnect();
delete m_pAccountId; delete m_pAccountId;
if (m_pCredentials) delete m_pCredentials ; if (m_pCredentials) delete m_pCredentials ;
if (m_pAccountDetails) delete m_pAccountDetails;
if (m_pAudioCodecs) delete m_pAudioCodecs ; if (m_pAudioCodecs) delete m_pAudioCodecs ;
} }
...@@ -167,12 +173,6 @@ const QString Account::getAccountId() const ...@@ -167,12 +173,6 @@ const QString Account::getAccountId() const
return *m_pAccountId; return *m_pAccountId;
} }
///Get this account details
const MapStringString& Account::getAccountDetails() const
{
return *m_pAccountDetails;
}
///Get current state ///Get current state
const QString Account::getStateName(const QString& state) const const QString Account::getStateName(const QString& state) const
{ {
...@@ -182,21 +182,21 @@ const QString Account::getStateName(const QString& state) const ...@@ -182,21 +182,21 @@ const QString Account::getStateName(const QString& state) const
///Get an account detail ///Get an account detail
const QString Account::getAccountDetail(const QString& param) const const QString Account::getAccountDetail(const QString& param) const
{ {
if (!m_pAccountDetails) { if (!m_hAccountDetails.size()) {
qDebug() << "The account list is not set"; qDebug() << "The account list is not set";
return QString(); //May crash, but better than crashing now return QString(); //May crash, but better than crashing now
} }
if (m_pAccountDetails->find(param) != m_pAccountDetails->end()) { if (m_hAccountDetails.find(param) != m_hAccountDetails.end()) {
return (*m_pAccountDetails)[param]; return m_hAccountDetails[param];
} }
else if (m_pAccountDetails->count() > 0) { else if (m_hAccountDetails.count() > 0) {
if (param == "Account.enable") //If an account is invalid, at least does not try to register it if (param == "Account.enable") //If an account is invalid, at least does not try to register it
return REGISTRATION_ENABLED_FALSE; return REGISTRATION_ENABLED_FALSE;
qDebug() << "Account parameter \"" << param << "\" not found"; qDebug() << "Account parameter \"" << param << "\" not found";
return QString(); return QString();
} }
else { else {
qDebug() << "Account details not found, there is " << m_pAccountDetails->count() << " details available"; qDebug() << "Account details not found, there is " << m_hAccountDetails.count() << " details available";
return QString(); return QString();
} }
} //getAccountDetail } //getAccountDetail
...@@ -289,7 +289,7 @@ void Account::setAccountAlias(QString detail) ...@@ -289,7 +289,7 @@ void Account::setAccountAlias(QString detail)
///Return the account hostname ///Return the account hostname
QString Account::getAccountHostname() const QString Account::getAccountHostname() const
{ {
return getAccountDetail(ACCOUNT_HOSTNAME); return m_HostName;
} }
///Return if the account is enabled ///Return if the account is enabled
...@@ -529,20 +529,20 @@ DtmfType Account::getDTMFType() const ...@@ -529,20 +529,20 @@ DtmfType Account::getDTMFType() const
****************************************************************************/ ****************************************************************************/
///Set account details ///Set account details
void Account::setAccountDetails(const MapStringString& m) void Account::setAccountDetails(const QHash<QString,QString>& m)
{ {
if (m_pAccountDetails) m_hAccountDetails.clear();
delete m_pAccountDetails; m_hAccountDetails = m;
m_pAccountDetails = new MapStringString(m); m_HostName = m[ACCOUNT_HOSTNAME];
} }
///Set a specific detail ///Set a specific detail
bool Account::setAccountDetail(const QString& param, const QString& val) bool Account::setAccountDetail(const QString& param, const QString& val)
{ {
bool accChanged = (*m_pAccountDetails)[param] != val; const bool accChanged = m_hAccountDetails[param] != val;
QString buf = (*m_pAccountDetails)[param]; const QString buf = m_hAccountDetails[param];
if (param == ACCOUNT_REGISTRATION_STATUS) { if (param == ACCOUNT_REGISTRATION_STATUS) {
(*m_pAccountDetails)[param] = val; m_hAccountDetails[param] = val;
if (accChanged) { if (accChanged) {
emit detailChanged(this,param,val,buf); emit detailChanged(this,param,val,buf);
} }
...@@ -550,7 +550,7 @@ bool Account::setAccountDetail(const QString& param, const QString& val) ...@@ -550,7 +550,7 @@ bool Account::setAccountDetail(const QString& param, const QString& val)
else { else {
performAction(AccountEditAction::MODIFY); performAction(AccountEditAction::MODIFY);
if (m_CurrentState == MODIFIED || m_CurrentState == NEW) { if (m_CurrentState == MODIFIED || m_CurrentState == NEW) {
(*m_pAccountDetails)[param] = val; m_hAccountDetails[param] = val;
if (accChanged) { if (accChanged) {
emit detailChanged(this,param,val,buf); emit detailChanged(this,param,val,buf);
} }
...@@ -588,6 +588,7 @@ void Account::setAccountType(QString detail) ...@@ -588,6 +588,7 @@ void Account::setAccountType(QString detail)
///The set account hostname, it can be an hostname or an IP address ///The set account hostname, it can be an hostname or an IP address
void Account::setAccountHostname(QString detail) void Account::setAccountHostname(QString detail)
{ {
m_HostName = detail;
setAccountDetail(ACCOUNT_HOSTNAME, detail); setAccountDetail(ACCOUNT_HOSTNAME, detail);
} }
...@@ -826,9 +827,9 @@ bool Account::updateState() ...@@ -826,9 +827,9 @@ bool Account::updateState()
{ {
if(! isNew()) { if(! isNew()) {
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance(); ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
MapStringString details = configurationManager.getAccountDetails(getAccountId()).value(); const MapStringString details = configurationManager.getAccountDetails(getAccountId()).value();
QString status = details[ACCOUNT_REGISTRATION_STATUS]; const QString status = details[ACCOUNT_REGISTRATION_STATUS];
QString currentStatus = getAccountRegistrationStatus(); const QString currentStatus = getAccountRegistrationStatus();
setAccountDetail(ACCOUNT_REGISTRATION_STATUS, status); //Update -internal- object state setAccountDetail(ACCOUNT_REGISTRATION_STATUS, status); //Update -internal- object state
return status == currentStatus; return status == currentStatus;
} }
...@@ -840,8 +841,15 @@ void Account::save() ...@@ -840,8 +841,15 @@ void Account::save()
{ {
ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance(); ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
if (isNew()) { if (isNew()) {
MapStringString details = getAccountDetails(); MapStringString details;
QString currentId = configurationManager.addAccount(details); QMutableHashIterator<QString,QString> iter(m_hAccountDetails);
while (iter.hasNext()) {
iter.next();
details[iter.key()] = iter.value();
}
const QString currentId = configurationManager.addAccount(details);
//Be sure there is audio codec enabled to avoid obscure error messages for the user //Be sure there is audio codec enabled to avoid obscure error messages for the user
QVector<int> codecIdList = configurationManager.getAudioCodecList(); QVector<int> codecIdList = configurationManager.getAudioCodecList();
...@@ -860,7 +868,14 @@ void Account::save() ...@@ -860,7 +868,14 @@ void Account::save()
saveCredentials(); saveCredentials();
} }
else { else {
configurationManager.setAccountDetails(getAccountId(), getAccountDetails()); MapStringString tmp;
QMutableHashIterator<QString,QString> iter(m_hAccountDetails);
while (iter.hasNext()) {
iter.next();
tmp[iter.key()] = iter.value();
}
configurationManager.setAccountDetails(getAccountId(), tmp);
} }
//QString id = configurationManager.getAccountDetail(getAccountId()); //QString id = configurationManager.getAccountDetail(getAccountId());
...@@ -893,11 +908,13 @@ void Account::reload() ...@@ -893,11 +908,13 @@ void Account::reload()
qDebug() << "Account not found"; qDebug() << "Account not found";
} }
else { else {
if (m_pAccountDetails) { m_hAccountDetails.clear();
delete m_pAccountDetails; QMutableMapIterator<QString, QString> iter(aDetails);
m_pAccountDetails = nullptr; while (iter.hasNext()) {
iter.next();
m_hAccountDetails[iter.key()] = iter.value();
} }
m_pAccountDetails = new MapStringString(aDetails); setAccountHostname(m_hAccountDetails[ACCOUNT_HOSTNAME]);
} }
m_CurrentState = READY; m_CurrentState = READY;
reloadCredentials(); reloadCredentials();
......
...@@ -85,7 +85,6 @@ class LIB_EXPORT Account : public QObject { ...@@ -85,7 +85,6 @@ class LIB_EXPORT Account : public QObject {
//Getters //Getters
bool isNew() const; bool isNew() const;
const QString getAccountId() const; const QString getAccountId() const;
const MapStringString& getAccountDetails() const;
const QString getStateName(const QString& state) const; const QString getStateName(const QString& state) const;
const QString getAccountDetail(const QString& param) const; const QString getAccountDetail(const QString& param) const;
const QString getAlias() const; const QString getAlias() const;
...@@ -142,8 +141,6 @@ class LIB_EXPORT Account : public QObject { ...@@ -142,8 +141,6 @@ class LIB_EXPORT Account : public QObject {
//Setters //Setters
void setAccountId (const QString& id ); void setAccountId (const QString& id );
void setAccountDetails (const MapStringString& m );
bool setAccountDetail (const QString& param, const QString& val );
#ifdef ENABLE_VIDEO #ifdef ENABLE_VIDEO
void setActiveVideoCodecList(const QList<VideoCodec*>& codecs); void setActiveVideoCodecList(const QList<VideoCodec*>& codecs);
QList<VideoCodec*> getActiveVideoCodecList(); QList<VideoCodec*> getActiveVideoCodecList();
...@@ -206,7 +203,8 @@ class LIB_EXPORT Account : public QObject { ...@@ -206,7 +203,8 @@ class LIB_EXPORT Account : public QObject {
//Attributes //Attributes
QString* m_pAccountId ; QString* m_pAccountId ;
MapStringString* m_pAccountDetails; QHash<QString,QString> m_hAccountDetails;
public Q_SLOTS: public Q_SLOTS:
void setEnabled(bool checked); void setEnabled(bool checked);
...@@ -215,6 +213,10 @@ class LIB_EXPORT Account : public QObject { ...@@ -215,6 +213,10 @@ class LIB_EXPORT Account : public QObject {
void accountChanged(QString accountId,QString stateName, int state); void accountChanged(QString accountId,QString stateName, int state);
private: private:
//Setters
void setAccountDetails (const QHash<QString,QString>& m );
bool setAccountDetail (const QString& param, const QString& val );
//State actions //State actions
void nothing() {}; void nothing() {};
void edit() {m_CurrentState = EDITING ;emit changed(this);}; void edit() {m_CurrentState = EDITING ;emit changed(this);};
...@@ -232,6 +234,9 @@ class LIB_EXPORT Account : public QObject { ...@@ -232,6 +234,9 @@ class LIB_EXPORT Account : public QObject {
AccountEditState m_CurrentState; AccountEditState m_CurrentState;
static const account_function stateMachineActionsOnState[6][7]; static const account_function stateMachineActionsOnState[6][7];
//Cached account details (as they are called too often for the hash)
QString m_HostName;
Q_SIGNALS: Q_SIGNALS:
///The account state (Invalif,Trying,Registered) changed ///The account state (Invalif,Trying,Registered) changed
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "callmanager_interface_singleton.h" #include "callmanager_interface_singleton.h"
AccountList* AccountList::m_spAccountList = nullptr; AccountList* AccountList::m_spAccountList = nullptr;
QString AccountList::m_sPriorAccountId = "" ; Account* AccountList::m_spPriorAccount = nullptr ;
QVariant AccountListNoCheckProxyModel::data(const QModelIndex& idx,int role ) const QVariant AccountListNoCheckProxyModel::data(const QModelIndex& idx,int role ) const
{ {
...@@ -360,25 +360,19 @@ int AccountList::size() const ...@@ -360,25 +360,19 @@ int AccountList::size() const
///Return the current account ///Return the current account
Account* AccountList::getCurrentAccount() Account* AccountList::getCurrentAccount()
{ {
Account* priorAccount = getInstance()->getAccountById(m_sPriorAccountId); Account* priorAccount = m_spPriorAccount;
if(priorAccount && priorAccount->getAccountDetail(ACCOUNT_REGISTRATION_STATUS) == ACCOUNT_STATE_REGISTERED && priorAccount->isAccountEnabled() ) { if(priorAccount && priorAccount->getAccountRegistrationStatus() == ACCOUNT_STATE_REGISTERED && priorAccount->isAccountEnabled() ) {
return priorAccount; return priorAccount;
} }
else { else {
Account* a = getInstance()->firstRegisteredAccount(); Account* a = getInstance()->firstRegisteredAccount();
if (a) if (!a)
return getInstance()->firstRegisteredAccount(); a = getInstance()->getAccountById("IP2IP");
else getInstance()->setPriorAccount(a);
return getInstance()->getAccountById("IP2IP"); return a;
} }
} //getCurrentAccount } //getCurrentAccount
///Return the previously used account ID
QString AccountList::getPriorAccoundId()
{
return m_sPriorAccountId;
}
///Get data from the model ///Get data from the model
QVariant AccountList::data ( const QModelIndex& idx, int role) const QVariant AccountList::data ( const QModelIndex& idx, int role) const
{ {
...@@ -423,6 +417,12 @@ Account* AccountList::getAccountByModelIndex(const QModelIndex& item) const ...@@ -423,6 +417,12 @@ Account* AccountList::getAccountByModelIndex(const QModelIndex& item) const
return (*m_pAccounts)[item.row()]; return (*m_pAccounts)[item.row()];
} }
//Return the prior account
Account* AccountList::getPriorAccount()
{
return m_spPriorAccount;
}
///Return the default account (used for contact lookup) ///Return the default account (used for contact lookup)
Account* AccountList::getDefaultAccount() const Account* AccountList::getDefaultAccount() const
{ {
...@@ -488,8 +488,8 @@ void AccountList::removeAccount( QModelIndex idx ) ...@@ -488,8 +488,8 @@ void AccountList::removeAccount( QModelIndex idx )
///Set the previous account used ///Set the previous account used
void AccountList::setPriorAccount(const Account* account) { void AccountList::setPriorAccount(const Account* account) {
bool changed = (account && m_sPriorAccountId != account->getAccountId()) || (!account && !m_sPriorAccountId.isEmpty()); bool changed = (account && m_spPriorAccount != account) || (!account && m_spPriorAccount);
m_sPriorAccountId = account?account->getAccountId() : QString(); m_spPriorAccount = (Account*)(account);
if (changed) if (changed)
emit priorAccountChanged(getCurrentAccount()); emit priorAccountChanged(getCurrentAccount());
} }
......
...@@ -51,9 +51,9 @@ public: ...@@ -51,9 +51,9 @@ public:
Account* firstRegisteredAccount ( ) const; Account* firstRegisteredAccount ( ) const;
Account* getDefaultAccount ( ) const; Account* getDefaultAccount ( ) const;
static Account* getCurrentAccount ( ); static Account* getCurrentAccount ( );
static QString getPriorAccoundId ( );
Account* getAccountByModelIndex ( const QModelIndex& item ) const; Account* getAccountByModelIndex ( const QModelIndex& item ) const;
static QString getSimilarAliasIndex ( const QString& alias ); static QString getSimilarAliasIndex ( const QString& alias );
static Account* getPriorAccount ( );
//Abstract model accessors //Abstract model accessors
QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const; QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const;
...@@ -88,7 +88,7 @@ private: ...@@ -88,7 +88,7 @@ private:
//Attributes //Attributes
QVector<Account*>* m_pAccounts ; QVector<Account*>* m_pAccounts ;
static AccountList* m_spAccountList ; static AccountList* m_spAccountList ;
static QString m_sPriorAccountId; static Account* m_spPriorAccount ;
Account* m_pDefaultAccount; Account* m_pDefaultAccount;
AccountListColorVisitor* m_pColorVisitor ; AccountListColorVisitor* m_pColorVisitor ;
......
...@@ -338,8 +338,8 @@ QModelIndex HistoryModel::parent( const QModelIndex& idx) const ...@@ -338,8 +338,8 @@ QModelIndex HistoryModel::parent( const QModelIndex& idx) const
} }
HistoryTreeBackend* modelItem = static_cast<HistoryTreeBackend*>(idx.internalPointer()); HistoryTreeBackend* modelItem = static_cast<HistoryTreeBackend*>(idx.internalPointer());
if (modelItem && (long long)modelItem > 100 && modelItem->type3() == HistoryTreeBackend::Type::CALL) { if (modelItem && (long long)modelItem > 100 && modelItem->type3() == HistoryTreeBackend::Type::CALL) {
Call* call = (Call*)((HistoryTreeBackend*)(idx.internalPointer()))->getSelf(); const Call* call = (Call*)((HistoryTreeBackend*)(idx.internalPointer()))->getSelf();
QString val = category(call); const QString val = category(call);
if (m_hCategories[val]) if (m_hCategories[val])
return HistoryModel::index(m_lCategoryCounter.indexOf(m_hCategories[val]),0); return HistoryModel::index(m_lCategoryCounter.indexOf(m_hCategories[val]),0);
} }
...@@ -424,7 +424,7 @@ bool HistoryModel::dropMimeData(const QMimeData *mime, Qt::DropAction action, in ...@@ -424,7 +424,7 @@ bool HistoryModel::dropMimeData(const QMimeData *mime, Qt::DropAction action, in
return false; return false;
} }
QString HistoryModel::category(Call* call) const QString HistoryModel::category(const Call* call) const
{ {
QString cat = call->getRoleData((Call::Role)m_Role).toString(); QString cat = call->getRoleData((Call::Role)m_Role).toString();
// if (cat.size() && !m_ShowAll) // if (cat.size() && !m_ShowAll)
......
...@@ -104,7 +104,7 @@ private: ...@@ -104,7 +104,7 @@ private:
void addPriv(Call* call); void addPriv(Call* call);
//Helpers //Helpers
QString category(Call* call) const; QString category(const Call* call) const;
//Static attributes //Static attributes
static HistoryModel* m_spInstance; static HistoryModel* m_spInstance;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment