Commit fc9e8b68 authored by Ronan Abhamon's avatar Ronan Abhamon

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

parent 69f114e5
...@@ -36,10 +36,10 @@ using namespace std; ...@@ -36,10 +36,10 @@ using namespace std;
// ============================================================================= // =============================================================================
CallModel::CallModel (shared_ptr<linphone::Call> linphoneCall) { CallModel::CallModel (shared_ptr<linphone::Call> call) {
Q_ASSERT(linphoneCall != nullptr); Q_ASSERT(call != nullptr);
mLinphoneCall = linphoneCall; mCall = call;
mLinphoneCall->setData("call-model", *this); mCall->setData("call-model", *this);
// Deal with auto-answer. // Deal with auto-answer.
{ {
...@@ -59,7 +59,7 @@ CallModel::CallModel (shared_ptr<linphone::Call> linphoneCall) { ...@@ -59,7 +59,7 @@ CallModel::CallModel (shared_ptr<linphone::Call> linphoneCall) {
QObject::connect( QObject::connect(
&(*CoreManager::getInstance()->getHandlers()), &CoreHandlers::callStateChanged, &(*CoreManager::getInstance()->getHandlers()), &CoreHandlers::callStateChanged,
this, [this](const shared_ptr<linphone::Call> &call, linphone::CallState state) { this, [this](const shared_ptr<linphone::Call> &call, linphone::CallState state) {
if (call != mLinphoneCall) if (call != mCall)
return; return;
switch (state) { switch (state) {
...@@ -90,10 +90,10 @@ CallModel::CallModel (shared_ptr<linphone::Call> linphoneCall) { ...@@ -90,10 +90,10 @@ CallModel::CallModel (shared_ptr<linphone::Call> linphoneCall) {
case linphone::CallStateUpdatedByRemote: case linphone::CallStateUpdatedByRemote:
if ( if (
!mLinphoneCall->getCurrentParams()->videoEnabled() && !mCall->getCurrentParams()->videoEnabled() &&
mLinphoneCall->getRemoteParams()->videoEnabled() mCall->getRemoteParams()->videoEnabled()
) { ) {
mLinphoneCall->deferUpdate(); mCall->deferUpdate();
emit videoRequested(); emit videoRequested();
} }
...@@ -109,7 +109,7 @@ CallModel::CallModel (shared_ptr<linphone::Call> linphoneCall) { ...@@ -109,7 +109,7 @@ CallModel::CallModel (shared_ptr<linphone::Call> linphoneCall) {
} }
CallModel::~CallModel () { CallModel::~CallModel () {
mLinphoneCall->unsetData("call-model"); mCall->unsetData("call-model");
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -123,13 +123,13 @@ void CallModel::setRecordFile (shared_ptr<linphone::CallParams> &callParams) { ...@@ -123,13 +123,13 @@ void CallModel::setRecordFile (shared_ptr<linphone::CallParams> &callParams) {
); );
} }
void CallModel::updateStats (const shared_ptr<const linphone::CallStats> &stats) { void CallModel::updateStats (const shared_ptr<const linphone::CallStats> &callStats) {
switch (stats->getType()) { switch (callStats->getType()) {
case linphone::StreamTypeAudio: case linphone::StreamTypeAudio:
updateStats(stats, mAudioStats); updateStats(callStats, mAudioStats);
break; break;
case linphone::StreamTypeVideo: case linphone::StreamTypeVideo:
updateStats(stats, mVideoStats); updateStats(callStats, mVideoStats);
break; break;
default: default:
break; break;
...@@ -144,31 +144,31 @@ void CallModel::accept () { ...@@ -144,31 +144,31 @@ void CallModel::accept () {
stopAutoAnswerTimer(); stopAutoAnswerTimer();
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore(); shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
shared_ptr<linphone::CallParams> params = core->createCallParams(mLinphoneCall); shared_ptr<linphone::CallParams> params = core->createCallParams(mCall);
params->enableVideo(false); params->enableVideo(false);
setRecordFile(params); setRecordFile(params);
App::smartShowWindow(App::getInstance()->getCallsWindow()); App::smartShowWindow(App::getInstance()->getCallsWindow());
mLinphoneCall->acceptWithParams(params); mCall->acceptWithParams(params);
} }
void CallModel::acceptWithVideo () { void CallModel::acceptWithVideo () {
stopAutoAnswerTimer(); stopAutoAnswerTimer();
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore(); shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
shared_ptr<linphone::CallParams> params = core->createCallParams(mLinphoneCall); shared_ptr<linphone::CallParams> params = core->createCallParams(mCall);
params->enableVideo(true); params->enableVideo(true);
setRecordFile(params); setRecordFile(params);
App::smartShowWindow(App::getInstance()->getCallsWindow()); App::smartShowWindow(App::getInstance()->getCallsWindow());
mLinphoneCall->acceptWithParams(params); mCall->acceptWithParams(params);
} }
void CallModel::terminate () { void CallModel::terminate () {
CoreManager *core = CoreManager::getInstance(); CoreManager *core = CoreManager::getInstance();
core->lockVideoRender(); core->lockVideoRender();
mLinphoneCall->terminate(); mCall->terminate();
core->unlockVideoRender(); core->unlockVideoRender();
} }
...@@ -178,14 +178,14 @@ void CallModel::transfer () { ...@@ -178,14 +178,14 @@ void CallModel::transfer () {
void CallModel::acceptVideoRequest () { void CallModel::acceptVideoRequest () {
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore(); shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
shared_ptr<linphone::CallParams> params = core->createCallParams(mLinphoneCall); shared_ptr<linphone::CallParams> params = core->createCallParams(mCall);
params->enableVideo(true); params->enableVideo(true);
mLinphoneCall->acceptUpdate(params); mCall->acceptUpdate(params);
} }
void CallModel::rejectVideoRequest () { void CallModel::rejectVideoRequest () {
mLinphoneCall->acceptUpdate(mLinphoneCall->getCurrentParams()); mCall->acceptUpdate(mCall->getCurrentParams());
} }
void CallModel::takeSnapshot () { void CallModel::takeSnapshot () {
...@@ -199,9 +199,9 @@ void CallModel::takeSnapshot () { ...@@ -199,9 +199,9 @@ void CallModel::takeSnapshot () {
oldName = newName; oldName = newName;
qInfo() << "Take snapshot of call:" << &mLinphoneCall; qInfo() << "Take snapshot of call:" << &mCall;
mLinphoneCall->takeVideoSnapshot( mCall->takeVideoSnapshot(
::Utils::qStringToLinphoneString( ::Utils::qStringToLinphoneString(
CoreManager::getInstance()->getSettingsModel()->getSavedScreenshotsFolder() + newName CoreManager::getInstance()->getSettingsModel()->getSavedScreenshotsFolder() + newName
) )
...@@ -212,9 +212,9 @@ void CallModel::startRecording () { ...@@ -212,9 +212,9 @@ void CallModel::startRecording () {
if (mRecording) if (mRecording)
return; return;
qInfo() << "Start recording call:" << &mLinphoneCall; qInfo() << "Start recording call:" << &mCall;
mLinphoneCall->startRecording(); mCall->startRecording();
mRecording = true; mRecording = true;
emit recordingChanged(true); emit recordingChanged(true);
...@@ -222,10 +222,10 @@ void CallModel::startRecording () { ...@@ -222,10 +222,10 @@ void CallModel::startRecording () {
void CallModel::stopRecording () { void CallModel::stopRecording () {
if (mRecording) { if (mRecording) {
qInfo() << "Stop recording call:" << &mLinphoneCall; qInfo() << "Stop recording call:" << &mCall;
mRecording = false; mRecording = false;
mLinphoneCall->stopRecording(); mCall->stopRecording();
emit recordingChanged(false); emit recordingChanged(false);
} }
...@@ -242,11 +242,11 @@ void CallModel::stopAutoAnswerTimer () const { ...@@ -242,11 +242,11 @@ void CallModel::stopAutoAnswerTimer () const {
} }
QString CallModel::getSipAddress () const { QString CallModel::getSipAddress () const {
return ::Utils::linphoneStringToQString(mLinphoneCall->getRemoteAddress()->asStringUriOnly()); return ::Utils::linphoneStringToQString(mCall->getRemoteAddress()->asStringUriOnly());
} }
CallModel::CallStatus CallModel::getStatus () const { CallModel::CallStatus CallModel::getStatus () const {
switch (mLinphoneCall->getState()) { switch (mCall->getState()) {
case linphone::CallStateConnected: case linphone::CallStateConnected:
case linphone::CallStateStreamsRunning: case linphone::CallStateStreamsRunning:
return CallStatusConnected; return CallStatusConnected;
...@@ -279,17 +279,17 @@ CallModel::CallStatus CallModel::getStatus () const { ...@@ -279,17 +279,17 @@ CallModel::CallStatus CallModel::getStatus () const {
break; break;
} }
return mLinphoneCall->getDir() == linphone::CallDirIncoming ? CallStatusIncoming : CallStatusOutgoing; return mCall->getDir() == linphone::CallDirIncoming ? CallStatusIncoming : CallStatusOutgoing;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
int CallModel::getDuration () const { int CallModel::getDuration () const {
return mLinphoneCall->getDuration(); return mCall->getDuration();
} }
float CallModel::getQuality () const { float CallModel::getQuality () const {
return mLinphoneCall->getCurrentQuality(); return mCall->getCurrentQuality();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -307,11 +307,11 @@ inline float computeVu (float volume) { ...@@ -307,11 +307,11 @@ inline float computeVu (float volume) {
} }
float CallModel::getMicroVu () const { float CallModel::getMicroVu () const {
return computeVu(mLinphoneCall->getRecordVolume()); return computeVu(mCall->getRecordVolume());
} }
float CallModel::getSpeakerVu () const { float CallModel::getSpeakerVu () const {
return computeVu(mLinphoneCall->getPlayVolume()); return computeVu(mCall->getPlayVolume());
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -336,7 +336,7 @@ bool CallModel::getPausedByUser () const { ...@@ -336,7 +336,7 @@ bool CallModel::getPausedByUser () const {
} }
void CallModel::setPausedByUser (bool status) { void CallModel::setPausedByUser (bool status) {
switch (mLinphoneCall->getState()) { switch (mCall->getState()) {
case linphone::CallStateConnected: case linphone::CallStateConnected:
case linphone::CallStateStreamsRunning: case linphone::CallStateStreamsRunning:
case linphone::CallStatePaused: case linphone::CallStatePaused:
...@@ -347,24 +347,24 @@ void CallModel::setPausedByUser (bool status) { ...@@ -347,24 +347,24 @@ void CallModel::setPausedByUser (bool status) {
if (status) { if (status) {
if (!mPausedByUser) if (!mPausedByUser)
mLinphoneCall->pause(); mCall->pause();
return; return;
} }
if (mPausedByUser) if (mPausedByUser)
mLinphoneCall->resume(); mCall->resume();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool CallModel::getVideoEnabled () const { bool CallModel::getVideoEnabled () const {
shared_ptr<const linphone::CallParams> params = mLinphoneCall->getCurrentParams(); shared_ptr<const linphone::CallParams> params = mCall->getCurrentParams();
return params && params->videoEnabled() && getStatus() == CallStatusConnected; return params && params->videoEnabled() && getStatus() == CallStatusConnected;
} }
void CallModel::setVideoEnabled (bool status) { void CallModel::setVideoEnabled (bool status) {
switch (mLinphoneCall->getState()) { switch (mCall->getState()) {
case linphone::CallStateConnected: case linphone::CallStateConnected:
case linphone::CallStateStreamsRunning: case linphone::CallStateStreamsRunning:
break; break;
...@@ -375,16 +375,16 @@ void CallModel::setVideoEnabled (bool status) { ...@@ -375,16 +375,16 @@ void CallModel::setVideoEnabled (bool status) {
return; return;
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore(); shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
shared_ptr<linphone::CallParams> params = core->createCallParams(mLinphoneCall); shared_ptr<linphone::CallParams> params = core->createCallParams(mCall);
params->enableVideo(status); params->enableVideo(status);
mLinphoneCall->update(params); mCall->update(params);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool CallModel::getUpdating () const { bool CallModel::getUpdating () const {
switch (mLinphoneCall->getState()) { switch (mCall->getState()) {
case linphone::CallStateConnected: case linphone::CallStateConnected:
case linphone::CallStateStreamsRunning: case linphone::CallStateStreamsRunning:
case linphone::CallStatePaused: case linphone::CallStatePaused:
...@@ -406,7 +406,7 @@ bool CallModel::getRecording () const { ...@@ -406,7 +406,7 @@ bool CallModel::getRecording () const {
void CallModel::sendDtmf (const QString &dtmf) { void CallModel::sendDtmf (const QString &dtmf) {
qInfo() << QStringLiteral("Send dtmf: `%1`.").arg(dtmf); qInfo() << QStringLiteral("Send dtmf: `%1`.").arg(dtmf);
mLinphoneCall->sendDtmf(dtmf.constData()[0].toLatin1()); mCall->sendDtmf(dtmf.constData()[0].toLatin1());
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -426,9 +426,9 @@ inline QVariantMap createStat (const QString &key, const QString &value) { ...@@ -426,9 +426,9 @@ inline QVariantMap createStat (const QString &key, const QString &value) {
return m; return m;
} }
void CallModel::updateStats (const shared_ptr<const linphone::CallStats> &callStats, QVariantList &stats) { void CallModel::updateStats (const shared_ptr<const linphone::CallStats> &callStats, QVariantList &statsList) {
QString family; QString family;
shared_ptr<const linphone::CallParams> params = mLinphoneCall->getCurrentParams(); shared_ptr<const linphone::CallParams> params = mCall->getCurrentParams();
shared_ptr<const linphone::PayloadType> payloadType; shared_ptr<const linphone::PayloadType> payloadType;
switch (callStats->getType()) { switch (callStats->getType()) {
...@@ -454,21 +454,21 @@ void CallModel::updateStats (const shared_ptr<const linphone::CallStats> &callSt ...@@ -454,21 +454,21 @@ void CallModel::updateStats (const shared_ptr<const linphone::CallStats> &callSt
break; break;
} }
stats.clear(); statsList.clear();
stats << createStat(tr("callStatsCodec"), payloadType statsList << createStat(tr("callStatsCodec"), payloadType
? QString("%1 / %2kHz").arg(Utils::linphoneStringToQString(payloadType->getMimeType())).arg(payloadType->getClockRate() / 1000) ? QString("%1 / %2kHz").arg(Utils::linphoneStringToQString(payloadType->getMimeType())).arg(payloadType->getClockRate() / 1000)
: ""); : "");
stats << createStat(tr("callStatsUploadBandwidth"), QString("%1 kbits/s").arg(int(callStats->getUploadBandwidth()))); statsList << createStat(tr("callStatsUploadBandwidth"), QString("%1 kbits/s").arg(int(callStats->getUploadBandwidth())));
stats << createStat(tr("callStatsDownloadBandwidth"), QString("%1 kbits/s").arg(int(callStats->getDownloadBandwidth()))); statsList << createStat(tr("callStatsDownloadBandwidth"), QString("%1 kbits/s").arg(int(callStats->getDownloadBandwidth())));
stats << createStat(tr("callStatsIceState"), iceStateToString(callStats->getIceState())); statsList << createStat(tr("callStatsIceState"), iceStateToString(callStats->getIceState()));
stats << createStat(tr("callStatsIpFamily"), family); statsList << createStat(tr("callStatsIpFamily"), family);
stats << createStat(tr("callStatsSenderLossRate"), QString("%1 %").arg(callStats->getSenderLossRate())); statsList << createStat(tr("callStatsSenderLossRate"), QString("%1 %").arg(callStats->getSenderLossRate()));
stats << createStat(tr("callStatsReceiverLossRate"), QString("%1 %").arg(callStats->getReceiverLossRate())); statsList << createStat(tr("callStatsReceiverLossRate"), QString("%1 %").arg(callStats->getReceiverLossRate()));
switch (callStats->getType()) { switch (callStats->getType()) {
case linphone::StreamTypeAudio: case linphone::StreamTypeAudio:
stats << createStat(tr("callStatsJitterBuffer"), QString("%1 ms").arg(callStats->getJitterBufferSizeMs())); statsList << createStat(tr("callStatsJitterBuffer"), QString("%1 ms").arg(callStats->getJitterBufferSizeMs()));
break; break;
case linphone::StreamTypeVideo: { case linphone::StreamTypeVideo: {
QString sentVideoDefinitionName = Utils::linphoneStringToQString(params->getSentVideoDefinition()->getName()); QString sentVideoDefinitionName = Utils::linphoneStringToQString(params->getSentVideoDefinition()->getName());
...@@ -476,7 +476,7 @@ void CallModel::updateStats (const shared_ptr<const linphone::CallStats> &callSt ...@@ -476,7 +476,7 @@ void CallModel::updateStats (const shared_ptr<const linphone::CallStats> &callSt
.arg(params->getSentVideoDefinition()->getWidth()) .arg(params->getSentVideoDefinition()->getWidth())
.arg(params->getSentVideoDefinition()->getHeight()); .arg(params->getSentVideoDefinition()->getHeight());
stats << createStat(tr("callStatsSentVideoDefinition"), sentVideoDefinition == sentVideoDefinitionName statsList << createStat(tr("callStatsSentVideoDefinition"), sentVideoDefinition == sentVideoDefinitionName
? sentVideoDefinition ? sentVideoDefinition
: QString("%1 (%2)").arg(sentVideoDefinition).arg(sentVideoDefinitionName)); : QString("%1 (%2)").arg(sentVideoDefinition).arg(sentVideoDefinitionName));
...@@ -485,7 +485,7 @@ void CallModel::updateStats (const shared_ptr<const linphone::CallStats> &callSt ...@@ -485,7 +485,7 @@ void CallModel::updateStats (const shared_ptr<const linphone::CallStats> &callSt
.arg(params->getReceivedVideoDefinition()->getWidth()) .arg(params->getReceivedVideoDefinition()->getWidth())
.arg(params->getReceivedVideoDefinition()->getHeight()); .arg(params->getReceivedVideoDefinition()->getHeight());
stats << createStat(tr("callStatsReceivedVideoDefinition"), receivedVideoDefinition == receivedVideoDefinitionName statsList << createStat(tr("callStatsReceivedVideoDefinition"), receivedVideoDefinition == receivedVideoDefinitionName
? receivedVideoDefinition ? receivedVideoDefinition
: QString("%1 (%2)").arg(receivedVideoDefinition).arg(receivedVideoDefinitionName)); : QString("%1 (%2)").arg(receivedVideoDefinition).arg(receivedVideoDefinitionName));
} }
......
...@@ -67,12 +67,12 @@ public: ...@@ -67,12 +67,12 @@ public:
CallModel (std::shared_ptr<linphone::Call> linphoneCall); CallModel (std::shared_ptr<linphone::Call> linphoneCall);
~CallModel (); ~CallModel ();
std::shared_ptr<linphone::Call> getLinphoneCall () const { std::shared_ptr<linphone::Call> getCall () const {
return mLinphoneCall; return mCall;
} }
static void setRecordFile (std::shared_ptr<linphone::CallParams> &callParams); 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 accept ();
Q_INVOKABLE void acceptWithVideo (); Q_INVOKABLE void acceptWithVideo ();
...@@ -103,7 +103,7 @@ private: ...@@ -103,7 +103,7 @@ private:
CallStatus getStatus () const; CallStatus getStatus () const;
bool isOutgoing () const { bool isOutgoing () const {
return mLinphoneCall->getDir() == linphone::CallDirOutgoing; return mCall->getDir() == linphone::CallDirOutgoing;
} }
int getDuration () const; int getDuration () const;
...@@ -126,7 +126,7 @@ private: ...@@ -126,7 +126,7 @@ private:
QVariantList getAudioStats () const; QVariantList getAudioStats () const;
QVariantList getVideoStats () 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; QString iceStateToString (linphone::IceState state) const;
...@@ -137,7 +137,7 @@ private: ...@@ -137,7 +137,7 @@ private:
QVariantList mAudioStats; QVariantList mAudioStats;
QVariantList mVideoStats; QVariantList mVideoStats;
std::shared_ptr<linphone::Call> mLinphoneCall; std::shared_ptr<linphone::Call> mCall;
}; };
#endif // CALL_MODEL_H_ #endif // CALL_MODEL_H_
...@@ -36,13 +36,13 @@ using namespace std; ...@@ -36,13 +36,13 @@ using namespace std;
// ============================================================================= // =============================================================================
inline QList<CallModel *>::iterator findCall ( inline QList<CallModel *>::iterator findCallModel (
QList<CallModel *> &list, QList<CallModel *> &list,
const shared_ptr<linphone::Call> &linphoneCall const shared_ptr<linphone::Call> &call
) { ) {
return find_if( return find_if(
list.begin(), list.end(), [linphoneCall](CallModel *call) { list.begin(), list.end(), [call](CallModel *callModel) {
return linphoneCall == call->getLinphoneCall(); return call == callModel->getCall();
} }
); );
} }
...@@ -53,21 +53,21 @@ CallsListModel::CallsListModel (QObject *parent) : QAbstractListModel(parent) { ...@@ -53,21 +53,21 @@ CallsListModel::CallsListModel (QObject *parent) : QAbstractListModel(parent) {
mCoreHandlers = CoreManager::getInstance()->getHandlers(); mCoreHandlers = CoreManager::getInstance()->getHandlers();
QObject::connect( QObject::connect(
&(*mCoreHandlers), &CoreHandlers::callStateChanged, &(*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) { switch (state) {
case linphone::CallStateIncomingReceived: case linphone::CallStateIncomingReceived:
case linphone::CallStateOutgoingInit: case linphone::CallStateOutgoingInit:
addCall(linphoneCall); addCall(call);
break; break;
case linphone::CallStateEnd: case linphone::CallStateEnd:
case linphone::CallStateError: case linphone::CallStateError:
removeCall(linphoneCall); removeCall(call);
break; break;
case linphone::CallStateStreamsRunning: { case linphone::CallStateStreamsRunning: {
int index = static_cast<int>(distance(mList.begin(), findCall(mList, linphoneCall))); int index = static_cast<int>(distance(mList.begin(), findCallModel(mList, call)));
emit callRunning(index, &linphoneCall->getData<CallModel>("call-model")); emit callRunning(index, &call->getData<CallModel>("call-model"));
} }
break; break;
...@@ -100,8 +100,8 @@ QVariant CallsListModel::data (const QModelIndex &index, int role) const { ...@@ -100,8 +100,8 @@ QVariant CallsListModel::data (const QModelIndex &index, int role) const {
return QVariant(); return QVariant();
} }
CallModel *CallsListModel::getCall (const shared_ptr<linphone::Call> &linphoneCall) const { CallModel *CallsListModel::getCallModel (const shared_ptr<linphone::Call> &call) const {
auto it = findCall(*(const_cast<QList<CallModel *> *>(&mList)), linphoneCall); auto it = findCallModel(*(const_cast<QList<CallModel *> *>(&mList)), call);
return it != mList.end() ? *it : nullptr; return it != mList.end() ? *it : nullptr;
} }
...@@ -170,33 +170,42 @@ bool CallsListModel::removeRows (int row, int count, const QModelIndex &parent) ...@@ -170,33 +170,42 @@ bool CallsListModel::removeRows (int row, int count, const QModelIndex &parent)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void CallsListModel::addCall (const shared_ptr<linphone::Call> &linphoneCall) { void CallsListModel::addCall (const shared_ptr<linphone::Call> &call) {
if (linphoneCall->getDir() == linphone::CallDirOutgoing) if (call->getDir() == linphone::CallDirOutgoing)
App::smartShowWindow(App::getInstance()->getCallsWindow()); 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(); int row = mList.count();
beginInsertRows(QModelIndex(), row, row); beginInsertRows(QModelIndex(), row, row);
mList << call; mList << callModel;
endInsertRows(); endInsertRows();
} }
void CallsListModel::removeCall (const shared_ptr<linphone::Call> &linphoneCall) { void CallsListModel::removeCall (const shared_ptr<linphone::Call> &call) {
QTimer::singleShot( CallModel *callModel;
DELAY_BEFORE_REMOVE_CALL, this, [this, linphoneCall]() {
CallModel *call = &linphoneCall->getData<CallModel>("call-model"); 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)) if (index == -1 || !removeRow(index))
qWarning() << QStringLiteral("Unable to remove call:") << call; qWarning() << QStringLiteral("Unable to remove call:") << callModel;
if (mList.empty()) if (mList.empty())
App::getInstance()->getCallsWindow()->close(); App::getInstance()->getCallsWindow()->close();
......
...@@ -43,7 +43,7 @@ public: ...@@ -43,7 +43,7 @@ public:
QHash<int, QByteArray> roleNames () const override; QHash<int, QByteArray> roleNames () const override;
QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) 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 launchAudioCall (const QString &sipUri) const;
Q_INVOKABLE void launchVideoCall (const QString &sipUri) const; Q_INVOKABLE void launchVideoCall (const QString &sipUri) const;
...@@ -53,14 +53,14 @@ public: ...@@ -53,14 +53,14 @@ public:
Q_INVOKABLE void terminateAllCalls () const; Q_INVOKABLE void terminateAllCalls () const;
signals: signals:
void callRunning (int index, CallModel *call); void callRunning (int index, CallModel *callModel);
private: private:
bool removeRow (int row, const QModelIndex &parent = QModelIndex()); bool removeRow (int row, const QModelIndex &parent = QModelIndex());
bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override; bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
void addCall (const std::shared_ptr<linphone::Call> &linphoneCall); void addCall (const std::shared_ptr<linphone::Call> &call);
void removeCall (const std::shared_ptr<linphone::Call> &linphoneCall); void removeCall (const std::shared_ptr<linphone::Call> &call);
QList<CallModel *> mList; QList<CallModel *> mList;
......
...@@ -57,8 +57,8 @@ CameraRenderer::~CameraRenderer () { ...@@ -57,8 +57,8 @@ CameraRenderer::~CameraRenderer () {
if (mIsPreview) if (mIsPreview)
coreManager->getCore()->setNativePreviewWindowId(nullptr); coreManager->getCore()->setNativePreviewWindowId(nullptr);
else if (mLinphoneCall) else if (mCall)
mLinphoneCall->setNativeVideoWindowId(nullptr); mCall->setNativeVideoWindowId(nullptr);
coreManager->unlockVideoRender(); coreManager->unlockVideoRender();
...@@ -104,8 +104,8 @@ void CameraRenderer::render () { ...@@ -104,8 +104,8 @@ void CameraRenderer::render () {
if (mIsPreview) if (mIsPreview)
coreManager->getCore()->previewOglRender(); coreManager->getCore()->previewOglRender();
else if (mLinphoneCall) else if (mCall)
mLinphoneCall->oglRender(); mCall->oglRender();
msFunctions->bind(nullptr); msFunctions->bind(nullptr);
coreManager->unlockVideoRender(); coreManager->unlockVideoRender();
...@@ -124,8 +124,8 @@ void CameraRenderer::synchronize (QQuickFramebufferObject *item) { ...@@ -124,8 +124,8 @@ void CameraRenderer::synchronize (QQuickFramebufferObject *item) {
Camera *camera = qobject_cast<Camera *>(item); Camera *camera = qobject_cast<Camera *>(item);
{ {
CallModel *model = camera->getCall(); CallModel *model = camera->getCallModel();
mLinphoneCall = model ? model->getLinphoneCall() : nullptr; mCall = model ? model->getCall() : nullptr;
} }
mIsPreview = camera->mIsPreview; mIsPreview = camera->mIsPreview;
...@@ -144,8 +144,8 @@ void CameraRenderer::updateWindowId () { ...@@ -144,8 +144,8 @@ void CameraRenderer::updateWindowId () {
if (mIsPreview) if (mIsPreview)
CoreManager::getInstance()->getCore()->setNativePreviewWindowId(mContextInfo); CoreManager::getInstance()->getCore()->setNativePreviewWindowId(mContextInfo);
else if (mLinphoneCall) else if (mCall)
mLinphoneCall->setNativeVideoWindowId(mContextInfo); mCall->setNativeVideoWindowId(mContextInfo);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -172,16 +172,16 @@ QQuickFramebufferObject::Renderer *Camera::createRenderer () const { ...@@ -172,16 +172,16 @@ QQuickFramebufferObject::Renderer *Camera::createRenderer () const {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
CallModel *Camera::getCall () const { CallModel *Camera::getCallModel () const {
return mCall; return mCallModel;
} }
void Camera::setCall (CallModel *call) { void Camera::setCallModel (CallModel *callModel) {
if (mCall != call) { if (mCallModel != callModel) {
mCall = call; mCallModel = callModel;
update(); update();
emit callChanged(mCall); emit callChanged(mCallModel);
} }
} }
......
...@@ -57,7 +57,7 @@ private: ...@@ -57,7 +57,7 @@ private:
bool mUpdateContextInfo = false; bool mUpdateContextInfo = false;
bool mIsPreview = false; bool mIsPreview = false;
std::shared_ptr<linphone::Call> mLinphoneCall; std::shared_ptr<linphone::Call> mCall;
QQuickWindow *mWindow; QQuickWindow *mWindow;
}; };
...@@ -69,7 +69,7 @@ class Camera : public QQuickFramebufferObject { ...@@ -69,7 +69,7 @@ class Camera : public QQuickFramebufferObject {
Q_OBJECT; 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); Q_PROPERTY(bool isPreview READ getIsPreview WRITE setIsPreview NOTIFY isPreviewChanged);
public: public:
...@@ -79,18 +79,18 @@ public: ...@@ -79,18 +79,18 @@ public:
QQuickFramebufferObject::Renderer *createRenderer () const override; QQuickFramebufferObject::Renderer *createRenderer () const override;
signals: signals:
void callChanged (CallModel *call); void callChanged (CallModel *callModel);
void isPreviewChanged (bool isPreview); void isPreviewChanged (bool isPreview);
private: private:
CallModel *getCall () const; CallModel *getCallModel () const;
void setCall (CallModel *call); void setCallModel (CallModel *callModel);
bool getIsPreview () const; bool getIsPreview () const;
void setIsPreview (bool status); void setIsPreview (bool status);
bool mIsPreview = false; bool mIsPreview = false;
CallModel *mCall = nullptr; CallModel *mCallModel = nullptr;
QTimer *mRefreshTimer; QTimer *mRefreshTimer;
}; };
......
...@@ -524,6 +524,7 @@ void ChatModel::insertCall (const shared_ptr<linphone::CallLog> &callLog) { ...@@ -524,6 +524,7 @@ void ChatModel::insertCall (const shared_ptr<linphone::CallLog> &callLog) {
case linphone::CallStatusAborted: case linphone::CallStatusAborted:
case linphone::CallStatusEarlyAborted: case linphone::CallStatusEarlyAborted:
return; // Ignore aborted calls. return; // Ignore aborted calls.
case linphone::CallStatusSuccess: case linphone::CallStatusSuccess:
case linphone::CallStatusMissed: case linphone::CallStatusMissed:
case linphone::CallStatusDeclined: case linphone::CallStatusDeclined:
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
// ============================================================================= // =============================================================================
class VcardModel : public QObject { class VcardModel : public QObject {
friend class ContactModel;
Q_OBJECT; Q_OBJECT;
Q_PROPERTY(QString username READ getUsername WRITE setUsername NOTIFY vcardUpdated); Q_PROPERTY(QString username READ getUsername WRITE setUsername NOTIFY vcardUpdated);
...@@ -39,8 +41,6 @@ class VcardModel : public QObject { ...@@ -39,8 +41,6 @@ class VcardModel : public QObject {
Q_PROPERTY(QVariantList emails READ getEmails NOTIFY vcardUpdated); Q_PROPERTY(QVariantList emails READ getEmails NOTIFY vcardUpdated);
Q_PROPERTY(QVariantList urls READ getUrls NOTIFY vcardUpdated); Q_PROPERTY(QVariantList urls READ getUrls NOTIFY vcardUpdated);
friend class ContactModel;
public: public:
VcardModel (std::shared_ptr<linphone::Vcard> vcard) : mVcard(vcard) {} VcardModel (std::shared_ptr<linphone::Vcard> vcard) : mVcard(vcard) {}
......
...@@ -256,17 +256,17 @@ void Notifier::notifyReceivedCall (const shared_ptr<linphone::Call> &call) { ...@@ -256,17 +256,17 @@ void Notifier::notifyReceivedCall (const shared_ptr<linphone::Call> &call) {
if (!notification) if (!notification)
return; return;
CallModel *model = CoreManager::getInstance()->getCallsListModel()->getCall(call); CallModel *callModel = CoreManager::getInstance()->getCallsListModel()->getCallModel(call);
QObject::connect( 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) if (status == CallModel::CallStatusEnded || status == CallModel::CallStatusConnected)
deleteNotification(QVariant::fromValue(notification)); deleteNotification(QVariant::fromValue(notification));
} }
); );
QVariantMap map; QVariantMap map;
map["call"].setValue(model); map["call"].setValue(callModel);
::setProperty(*notification, NOTIFICATION_PROPERTY_DATA, map); ::setProperty(*notification, NOTIFICATION_PROPERTY_DATA, map);
showNotification(notification, NOTIFICATION_TIMEOUT_RECEIVED_CALL); showNotification(notification, NOTIFICATION_TIMEOUT_RECEIVED_CALL);
......
...@@ -24,6 +24,7 @@ function handleCreation () { ...@@ -24,6 +24,7 @@ function handleCreation () {
contactEdit._edition = true contactEdit._edition = true
} else { } else {
contactEdit._vcard = contact.vcard 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