From 938556051418fb27c5fab403e02f98740665b72b Mon Sep 17 00:00:00 2001 From: Alexandre Lision <alexandre.lision@savoirfairelinux.com> Date: Wed, 16 Sep 2015 11:15:02 -0400 Subject: [PATCH] call: use peerContactMethod when available When creating an outgoing call from a Person or an History entry, we already have the peerContactMethod to call, we should be able to use it directly. Issue: #75334 Change-Id: I19e81c7c9708d5531d9023503da0fc67ffd1a1e7 --- src/call.cpp | 57 +++++++++++++++++++++++++++++++++++++--------------- src/call.h | 3 ++- src/uri.cpp | 36 +++++++++++++++++++-------------- src/uri.h | 6 +++++- 4 files changed, 69 insertions(+), 33 deletions(-) diff --git a/src/call.cpp b/src/call.cpp index 139ace45..5d2191e7 100644 --- a/src/call.cpp +++ b/src/call.cpp @@ -1079,6 +1079,17 @@ void Call::setDialNumber(const ContactMethod* number) setDialNumber(number->uri()); } +void Call::setPeerContactMethod(ContactMethod* cm) +{ + //Change the peerContactMethod only when creating a Call + if (!cm || lifeCycleState() != Call::LifeCycleState::CREATION) { + qDebug() << "Trying to change the contact method on a non-dialing call"; + return; + } + d_ptr->m_pPeerContactMethod = cm; + setDialNumber(cm->uri()); +} + ///Set the recording path void CallPrivate::setRecordingPath(const QString& path) { @@ -1583,24 +1594,33 @@ void CallPrivate::hold() void CallPrivate::call() { Q_ASSERT_IS_IN_PROGRESS; + auto peerCM = q_ptr->peerContactMethod(); // Calls to empty URI should not be allowed, dring will go crazy - if (!m_pDialNumber || m_pDialNumber->uri().isEmpty()) { + if (peerCM->uri().isEmpty()) { qDebug() << "Trying to call an empty URI"; - changeCurrentState(Call::State::FAILURE); + changeCurrentState(Call::State::ABORTED); if (!m_pDialNumber) emit q_ptr->dialNumberChanged(QString()); else m_pDialNumber.reset(); - q_ptr->setPeerName(tr("Failure")); + q_ptr->setPeerName(tr("Aborted")); emit q_ptr->changed(); return; } - // Trying to find a valid account + // Try to set the account from the associated ContactMethod + if (auto tryingAcc = peerCM->account()) { + // make sure account exist in the model and that it's READY + if (AccountModel::instance()->getById(tryingAcc->id()) && + (tryingAcc->registrationState() == Account::RegistrationState::READY)) + m_Account = tryingAcc; + } + + // Otherwise set default account if (!m_Account) { qDebug() << "Account is not set, taking the first registered."; - m_Account = AvailableAccountModel::currentDefaultAccount(m_pDialNumber.get()); + m_Account = AvailableAccountModel::currentDefaultAccount(peerCM); if (!m_Account) { qDebug() << "Trying to call " << (m_pTransferNumber ? static_cast<QString>(m_pTransferNumber->uri()) : "ERROR") @@ -1608,42 +1628,47 @@ void CallPrivate::call() throw tr("No account registered!"); } } - qDebug() << "account = " << m_Account << " " << m_Account->alias(); // Normal case - qDebug() << "Calling " << q_ptr->peerContactMethod()->uri() << " with account " << m_Account + qDebug() << "Calling " << peerCM->uri() << " with account " << m_Account << ", CallId: " << q_ptr << ", ConfId: " << q_ptr; m_Direction = Call::Direction::OUTGOING; // Warning: m_pDialNumber can become nullptr when linking directly - const auto& uri = m_pDialNumber->uri(); - m_pPeerContactMethod = PhoneDirectoryModel::instance()->getNumber(uri, q_ptr->account()); + URI uri {peerCM->uri()}; + if (!m_pPeerContactMethod) + m_pPeerContactMethod = PhoneDirectoryModel::instance()->getNumber(uri, q_ptr->account()); + + // m_pDialNumber is now discarded + m_pDialNumber.reset(); + + //Refresh peerCM + peerCM = q_ptr->peerContactMethod(); + m_DringId = DBus::CallManager::instance().placeCall(m_Account->id(), uri); // This can happen when the daemon cannot allocate memory if (m_DringId.isEmpty()) { changeCurrentState(Call::State::FAILURE); - qWarning() << "Creating the call to " << m_pDialNumber->uri() << " failed"; - m_DringId = "FAILED"; // TODO once the ABORTED state is implemented, use it + qWarning() << "Creating the call to " << peerCM->uri() << " failed"; + m_DringId = "FAILED"; return; } setObjectName("Call:"+m_DringId); if (PersonModel::instance()->hasCollections()) { - if (auto contact = m_pPeerContactMethod->contact()) + if (auto contact = peerCM->contact()) m_PeerName = contact->formattedName(); } setStartTimeStamp(); CallModel::instance()->registerCall(q_ptr); - connect(m_pPeerContactMethod, SIGNAL(presentChanged(bool)), this, SLOT(updated())); - m_pPeerContactMethod->addCall(q_ptr); + connect(peerCM, SIGNAL(presentChanged(bool)), this, SLOT(updated())); + peerCM->addCall(q_ptr); - // m_pDialNumber is now deprecated by m_pPeerContactMethod emit q_ptr->dialNumberChanged(QString()); - m_pDialNumber.reset(); } ///Transfer the call diff --git a/src/call.h b/src/call.h index dba5b7b4..a391e078 100644 --- a/src/call.h +++ b/src/call.h @@ -269,7 +269,7 @@ public: Q_PROPERTY( Certificate* certificate READ certificate ) //Read/write properties - Q_PROPERTY( ContactMethod* peerContactMethod READ peerContactMethod ) + Q_PROPERTY( ContactMethod* peerContactMethod READ peerContactMethod WRITE setPeerContactMethod) Q_PROPERTY( QString peerName READ peerName WRITE setPeerName ) Q_PROPERTY( QString transferNumber READ transferNumber WRITE setTransferNumber ) Q_PROPERTY( QString dialNumber READ dialNumber WRITE setDialNumber NOTIFY dialNumberChanged(QString)) @@ -324,6 +324,7 @@ public: void setTransferNumber ( const QString& number ); void setDialNumber ( const QString& number ); void setDialNumber ( const ContactMethod* number ); + void setPeerContactMethod( ContactMethod* cm ); void setPeerName ( const QString& name ); void setAccount ( Account* account ); diff --git a/src/uri.cpp b/src/uri.cpp index 0f1cadd6..11d7cf96 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -99,13 +99,33 @@ m_IsHNParsed(false),m_Port(-1),m_Transport(URI::Transport::NOT_SET) { } +///Default constructor +URI::URI() : QString(), d_ptr(new URIPrivate(this)) +{ + +} + ///Constructor -URI::URI(const QString& other):QString(), d_ptr(new URIPrivate(this)) +URI::URI(const QString& other) : URI() { d_ptr->m_Stripped = URIPrivate::strip(other,d_ptr->m_HeaderType); (*static_cast<QString*>(this)) = d_ptr->m_Stripped ; } +///Copy constructor +URI::URI(const URI& o) : URI() +{ + d_ptr->commonCopyConstructor(o); +} + +///Destructor +URI::~URI() +{ + (*static_cast<QString*>(this)) = QString(); + d_ptr->m_Stripped = QString(); +// delete d_ptr; +} + void URIPrivate::commonCopyConstructor(const URI& o) { //TODO see if a copy on write kind of algo could be used for this @@ -125,20 +145,6 @@ void URIPrivate::commonCopyConstructor(const URI& o) (*static_cast<QString*>(q_ptr)) = o.d_ptr->m_Stripped; } -///Copy constructor -URI::URI(const URI& o):QString(), d_ptr(new URIPrivate(this)) -{ - d_ptr->commonCopyConstructor(o); -} - -///Destructor -URI::~URI() -{ - (*static_cast<QString*>(this)) = QString(); - d_ptr->m_Stripped = QString(); -// delete d_ptr; -} - /// Copy operator, make sure the cache is also copied URI& URI::operator=(const URI& o) { diff --git a/src/uri.h b/src/uri.h index 050893dd..ff061e26 100644 --- a/src/uri.h +++ b/src/uri.h @@ -81,12 +81,16 @@ class LIB_EXPORT URI : public QString friend class URIPrivate; public: + ///Default constructor + URI(); + /** * Default copy constructor * @param other an URI string */ - URI(const QString& other); URI(const URI& other); + + URI(const QString& other); virtual ~URI(); ///@enum SchemeType The very first part of the URI followed by a ':' -- GitLab