Commit fc9e8b68 authored by Ronan Abhamon's avatar Ronan Abhamon

fix(src/components/calls/CallsListModel): handle getData exception and code refactoring

parent 69f114e5
......@@ -67,12 +67,12 @@ public:
CallModel (std::shared_ptr<linphone::Call> linphoneCall);
~CallModel ();
std::shared_ptr<linphone::Call> getLinphoneCall () const {
return mLinphoneCall;
std::shared_ptr<linphone::Call> getCall () const {
return mCall;
}
static void setRecordFile (std::shared_ptr<linphone::CallParams> &callParams);
void updateStats (const std::shared_ptr<const linphone::CallStats> &stats);
void updateStats (const std::shared_ptr<const linphone::CallStats> &callStats);
Q_INVOKABLE void accept ();
Q_INVOKABLE void acceptWithVideo ();
......@@ -103,7 +103,7 @@ private:
CallStatus getStatus () const;
bool isOutgoing () const {
return mLinphoneCall->getDir() == linphone::CallDirOutgoing;
return mCall->getDir() == linphone::CallDirOutgoing;
}
int getDuration () const;
......@@ -126,7 +126,7 @@ private:
QVariantList getAudioStats () const;
QVariantList getVideoStats () const;
void updateStats (const std::shared_ptr<const linphone::CallStats> &callStats, QVariantList &stats);
void updateStats (const std::shared_ptr<const linphone::CallStats> &callStats, QVariantList &statsList);
QString iceStateToString (linphone::IceState state) const;
......@@ -137,7 +137,7 @@ private:
QVariantList mAudioStats;
QVariantList mVideoStats;
std::shared_ptr<linphone::Call> mLinphoneCall;
std::shared_ptr<linphone::Call> mCall;
};
#endif // CALL_MODEL_H_
......@@ -36,13 +36,13 @@ using namespace std;
// =============================================================================
inline QList<CallModel *>::iterator findCall (
inline QList<CallModel *>::iterator findCallModel (
QList<CallModel *> &list,
const shared_ptr<linphone::Call> &linphoneCall
const shared_ptr<linphone::Call> &call
) {
return find_if(
list.begin(), list.end(), [linphoneCall](CallModel *call) {
return linphoneCall == call->getLinphoneCall();
list.begin(), list.end(), [call](CallModel *callModel) {
return call == callModel->getCall();
}
);
}
......@@ -53,21 +53,21 @@ CallsListModel::CallsListModel (QObject *parent) : QAbstractListModel(parent) {
mCoreHandlers = CoreManager::getInstance()->getHandlers();
QObject::connect(
&(*mCoreHandlers), &CoreHandlers::callStateChanged,
this, [this](const shared_ptr<linphone::Call> &linphoneCall, linphone::CallState state) {
this, [this](const shared_ptr<linphone::Call> &call, linphone::CallState state) {
switch (state) {
case linphone::CallStateIncomingReceived:
case linphone::CallStateOutgoingInit:
addCall(linphoneCall);
addCall(call);
break;
case linphone::CallStateEnd:
case linphone::CallStateError:
removeCall(linphoneCall);
removeCall(call);
break;
case linphone::CallStateStreamsRunning: {
int index = static_cast<int>(distance(mList.begin(), findCall(mList, linphoneCall)));
emit callRunning(index, &linphoneCall->getData<CallModel>("call-model"));
int index = static_cast<int>(distance(mList.begin(), findCallModel(mList, call)));
emit callRunning(index, &call->getData<CallModel>("call-model"));
}
break;
......@@ -100,8 +100,8 @@ QVariant CallsListModel::data (const QModelIndex &index, int role) const {
return QVariant();
}
CallModel *CallsListModel::getCall (const shared_ptr<linphone::Call> &linphoneCall) const {
auto it = findCall(*(const_cast<QList<CallModel *> *>(&mList)), linphoneCall);
CallModel *CallsListModel::getCallModel (const shared_ptr<linphone::Call> &call) const {
auto it = findCallModel(*(const_cast<QList<CallModel *> *>(&mList)), call);
return it != mList.end() ? *it : nullptr;
}
......@@ -170,33 +170,42 @@ bool CallsListModel::removeRows (int row, int count, const QModelIndex &parent)
// -----------------------------------------------------------------------------
void CallsListModel::addCall (const shared_ptr<linphone::Call> &linphoneCall) {
if (linphoneCall->getDir() == linphone::CallDirOutgoing)
void CallsListModel::addCall (const shared_ptr<linphone::Call> &call) {
if (call->getDir() == linphone::CallDirOutgoing)
App::smartShowWindow(App::getInstance()->getCallsWindow());
CallModel *call = new CallModel(linphoneCall);
CallModel *callModel = new CallModel(call);
qInfo() << QStringLiteral("Add call:") << call;
qInfo() << QStringLiteral("Add call:") << callModel;
App::getInstance()->getEngine()->setObjectOwnership(call, QQmlEngine::CppOwnership);
App::getInstance()->getEngine()->setObjectOwnership(callModel, QQmlEngine::CppOwnership);
int row = mList.count();
beginInsertRows(QModelIndex(), row, row);
mList << call;
mList << callModel;
endInsertRows();
}
void CallsListModel::removeCall (const shared_ptr<linphone::Call> &linphoneCall) {
QTimer::singleShot(
DELAY_BEFORE_REMOVE_CALL, this, [this, linphoneCall]() {
CallModel *call = &linphoneCall->getData<CallModel>("call-model");
void CallsListModel::removeCall (const shared_ptr<linphone::Call> &call) {
CallModel *callModel;
try {
callModel = &call->getData<CallModel>("call-model");
} catch (const out_of_range &) {
// Can be a bug. Or the call model not exists because the linphone call state
// `CallStateIncomingReceived`/`CallStateOutgoingInit` was not notified.
qWarning() << QStringLiteral("Unable to found call in:") << callModel;
return;
}
qInfo() << QStringLiteral("Removing call:") << call;
QTimer::singleShot(
DELAY_BEFORE_REMOVE_CALL, this, [this, callModel]() {
qInfo() << QStringLiteral("Removing call:") << callModel;
int index = mList.indexOf(call);
int index = mList.indexOf(callModel);
if (index == -1 || !removeRow(index))
qWarning() << QStringLiteral("Unable to remove call:") << call;
qWarning() << QStringLiteral("Unable to remove call:") << callModel;
if (mList.empty())
App::getInstance()->getCallsWindow()->close();
......
......@@ -43,7 +43,7 @@ public:
QHash<int, QByteArray> roleNames () const override;
QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
CallModel *getCall (const std::shared_ptr<linphone::Call> &linphoneCall) const;
CallModel *getCallModel (const std::shared_ptr<linphone::Call> &call) const;
Q_INVOKABLE void launchAudioCall (const QString &sipUri) const;
Q_INVOKABLE void launchVideoCall (const QString &sipUri) const;
......@@ -53,14 +53,14 @@ public:
Q_INVOKABLE void terminateAllCalls () const;
signals:
void callRunning (int index, CallModel *call);
void callRunning (int index, CallModel *callModel);
private:
bool removeRow (int row, const QModelIndex &parent = QModelIndex());
bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
void addCall (const std::shared_ptr<linphone::Call> &linphoneCall);
void removeCall (const std::shared_ptr<linphone::Call> &linphoneCall);
void addCall (const std::shared_ptr<linphone::Call> &call);
void removeCall (const std::shared_ptr<linphone::Call> &call);
QList<CallModel *> mList;
......
......@@ -57,8 +57,8 @@ CameraRenderer::~CameraRenderer () {
if (mIsPreview)
coreManager->getCore()->setNativePreviewWindowId(nullptr);
else if (mLinphoneCall)
mLinphoneCall->setNativeVideoWindowId(nullptr);
else if (mCall)
mCall->setNativeVideoWindowId(nullptr);
coreManager->unlockVideoRender();
......@@ -104,8 +104,8 @@ void CameraRenderer::render () {
if (mIsPreview)
coreManager->getCore()->previewOglRender();
else if (mLinphoneCall)
mLinphoneCall->oglRender();
else if (mCall)
mCall->oglRender();
msFunctions->bind(nullptr);
coreManager->unlockVideoRender();
......@@ -124,8 +124,8 @@ void CameraRenderer::synchronize (QQuickFramebufferObject *item) {
Camera *camera = qobject_cast<Camera *>(item);
{
CallModel *model = camera->getCall();
mLinphoneCall = model ? model->getLinphoneCall() : nullptr;
CallModel *model = camera->getCallModel();
mCall = model ? model->getCall() : nullptr;
}
mIsPreview = camera->mIsPreview;
......@@ -144,8 +144,8 @@ void CameraRenderer::updateWindowId () {
if (mIsPreview)
CoreManager::getInstance()->getCore()->setNativePreviewWindowId(mContextInfo);
else if (mLinphoneCall)
mLinphoneCall->setNativeVideoWindowId(mContextInfo);
else if (mCall)
mCall->setNativeVideoWindowId(mContextInfo);
}
// -----------------------------------------------------------------------------
......@@ -172,16 +172,16 @@ QQuickFramebufferObject::Renderer *Camera::createRenderer () const {
// -----------------------------------------------------------------------------
CallModel *Camera::getCall () const {
return mCall;
CallModel *Camera::getCallModel () const {
return mCallModel;
}
void Camera::setCall (CallModel *call) {
if (mCall != call) {
mCall = call;
void Camera::setCallModel (CallModel *callModel) {
if (mCallModel != callModel) {
mCallModel = callModel;
update();
emit callChanged(mCall);
emit callChanged(mCallModel);
}
}
......
......@@ -57,7 +57,7 @@ private:
bool mUpdateContextInfo = false;
bool mIsPreview = false;
std::shared_ptr<linphone::Call> mLinphoneCall;
std::shared_ptr<linphone::Call> mCall;
QQuickWindow *mWindow;
};
......@@ -69,7 +69,7 @@ class Camera : public QQuickFramebufferObject {
Q_OBJECT;
Q_PROPERTY(CallModel * call READ getCall WRITE setCall NOTIFY callChanged);
Q_PROPERTY(CallModel * call READ getCallModel WRITE setCallModel NOTIFY callChanged);
Q_PROPERTY(bool isPreview READ getIsPreview WRITE setIsPreview NOTIFY isPreviewChanged);
public:
......@@ -79,18 +79,18 @@ public:
QQuickFramebufferObject::Renderer *createRenderer () const override;
signals:
void callChanged (CallModel *call);
void callChanged (CallModel *callModel);
void isPreviewChanged (bool isPreview);
private:
CallModel *getCall () const;
void setCall (CallModel *call);
CallModel *getCallModel () const;
void setCallModel (CallModel *callModel);
bool getIsPreview () const;
void setIsPreview (bool status);
bool mIsPreview = false;
CallModel *mCall = nullptr;
CallModel *mCallModel = nullptr;
QTimer *mRefreshTimer;
};
......
......@@ -524,6 +524,7 @@ void ChatModel::insertCall (const shared_ptr<linphone::CallLog> &callLog) {
case linphone::CallStatusAborted:
case linphone::CallStatusEarlyAborted:
return; // Ignore aborted calls.
case linphone::CallStatusSuccess:
case linphone::CallStatusMissed:
case linphone::CallStatusDeclined:
......
......@@ -29,6 +29,8 @@
// =============================================================================
class VcardModel : public QObject {
friend class ContactModel;
Q_OBJECT;
Q_PROPERTY(QString username READ getUsername WRITE setUsername NOTIFY vcardUpdated);
......@@ -39,8 +41,6 @@ class VcardModel : public QObject {
Q_PROPERTY(QVariantList emails READ getEmails NOTIFY vcardUpdated);
Q_PROPERTY(QVariantList urls READ getUrls NOTIFY vcardUpdated);
friend class ContactModel;
public:
VcardModel (std::shared_ptr<linphone::Vcard> vcard) : mVcard(vcard) {}
......
......@@ -256,17 +256,17 @@ void Notifier::notifyReceivedCall (const shared_ptr<linphone::Call> &call) {
if (!notification)
return;
CallModel *model = CoreManager::getInstance()->getCallsListModel()->getCall(call);
CallModel *callModel = CoreManager::getInstance()->getCallsListModel()->getCallModel(call);
QObject::connect(
model, &CallModel::statusChanged, notification, [this, notification](CallModel::CallStatus status) {
callModel, &CallModel::statusChanged, notification, [this, notification](CallModel::CallStatus status) {
if (status == CallModel::CallStatusEnded || status == CallModel::CallStatusConnected)
deleteNotification(QVariant::fromValue(notification));
}
);
QVariantMap map;
map["call"].setValue(model);
map["call"].setValue(callModel);
::setProperty(*notification, NOTIFICATION_PROPERTY_DATA, map);
showNotification(notification, NOTIFICATION_TIMEOUT_RECEIVED_CALL);
......
......@@ -24,6 +24,7 @@ function handleCreation () {
contactEdit._edition = true
} else {
contactEdit._vcard = contact.vcard
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment