From 7001386fb6519ab2326e4c30a55893c0360c015e Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Tue, 6 Jun 2023 16:36:07 +0200 Subject: [PATCH] Fix crash on using call parameters while being ended. Fix Mosaic layout refreshing. Add missing header of avatar. Fix hidden header in chats by using a var instead of qvariant coming from model (seems to be unconsistant as $chatEntry could be defined as undefined while having still its value). --- .../src/components/call/CallModel.cpp | 18 ++++--- .../ui/modules/Common/Form/Mosaic.qml | 6 +++ .../modules/Linphone/Calls/IncallAvatar.qml | 1 + .../ui/modules/Linphone/Chat/Chat.qml | 54 +++++++++---------- 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/linphone-app/src/components/call/CallModel.cpp b/linphone-app/src/components/call/CallModel.cpp index cb441f0de..a5ef8fa1a 100644 --- a/linphone-app/src/components/call/CallModel.cpp +++ b/linphone-app/src/components/call/CallModel.cpp @@ -68,7 +68,7 @@ CallModel::CallModel (shared_ptr call){ if(mCall) mCall->setData("call-model", *this); updateIsInConference(); - if(mCall) { + if(mCall && mCall->getState() != linphone::Call::State::End) { mCallListener = std::make_shared(); connectTo(mCallListener.get()); mCall->addListener(mCallListener); @@ -244,7 +244,7 @@ ConferenceInfoModel * CallModel::getConferenceInfoModel(){ } QSharedPointer CallModel::getConferenceSharedModel(){ - if(mCall->getConference() && !mConferenceModel){ + if(mCall->getState() != linphone::Call::State::End && mCall->getConference() && !mConferenceModel){ mConferenceModel = ConferenceModel::create(mCall->getConference()); connect(mConferenceModel.get(), &ConferenceModel::participantAdminStatusChanged, this, &CallModel::onParticipantAdminStatusChanged); emit conferenceModelChanged(); @@ -487,7 +487,7 @@ void CallModel::stopRecording () { // ----------------------------------------------------------------------------- void CallModel::handleCallEncryptionChanged (const shared_ptr &call) { - if (call == mCall){ + if (call == mCall && mCall->getState() != linphone::Call::State::End){ if(!setEncryption(static_cast(mCall->getCurrentParams()->getMediaEncryption()))) emit securityUpdated(); } @@ -607,7 +607,7 @@ void CallModel::accept (bool withVideo) { // ----------------------------------------------------------------------------- void CallModel::updateIsInConference () { - if (mIsInConference != (mCall && mCall->getCurrentParams()->getLocalConferenceMode() )) { + if (mIsInConference != (mCall && mCall->getState() != linphone::Call::State::End && mCall->getCurrentParams()->getLocalConferenceMode() )) { mIsInConference = !mIsInConference; } emit isInConferenceChanged(mIsInConference); @@ -782,7 +782,7 @@ void CallModel::setMicroMuted (bool status) { // ----------------------------------------------------------------------------- bool CallModel::getCameraEnabled () const{ - return mCall && (((int)mCall->getCurrentParams()->getVideoDirection() & (int)linphone::MediaDirection::SendOnly) == (int)linphone::MediaDirection::SendOnly); + return mCall && mCall->getState() != linphone::Call::State::End && (((int)mCall->getCurrentParams()->getVideoDirection() & (int)linphone::MediaDirection::SendOnly) == (int)linphone::MediaDirection::SendOnly); } void CallModel::setCameraEnabled (bool status){ @@ -854,6 +854,8 @@ bool CallModel::getLocalVideoEnabled () const { bool CallModel::getVideoEnabled () const { if(mCall){ + if(mCall->getState() == linphone::Call::State::End ) + return false; shared_ptr params = mCall->getCurrentParams(); return params && params->videoEnabled(); }else @@ -1102,7 +1104,7 @@ bool CallModel::setEncryption(const CallModel::CallEncryption& encryption){ } void CallModel::updateEncryption(){ - if(mCall){ + if(mCall && mCall->getState() != linphone::Call::State::End){ auto currentParams = mCall->getCurrentParams(); if( currentParams){ setEncryption(static_cast(currentParams->getMediaEncryption())); @@ -1190,7 +1192,7 @@ static inline QVariantMap createStat (const QString &key, const QString &value) } void CallModel::updateStats (const shared_ptr &callStats, QVariantList &statsList) { - if(mCall){ + if(mCall && mCall->getState() != linphone::Call::State::End){ shared_ptr params = mCall->getCurrentParams(); shared_ptr payloadType; @@ -1264,7 +1266,7 @@ void CallModel::updateStats (const shared_ptr &callSt } } void CallModel::updateEncrypionStats (const shared_ptr &callStats, QVariantList &statsList) { - if( callStats->getType() == linphone::StreamType::Audio) {// just in case + if( callStats->getType() == linphone::StreamType::Audio && mCall->getState() != linphone::Call::State::End) {// just in case statsList.clear(); if(isSecured()) { //: 'Media encryption' : label in encryption section of call statistics diff --git a/linphone-app/ui/modules/Common/Form/Mosaic.qml b/linphone-app/ui/modules/Common/Form/Mosaic.qml index 0aec5d752..43e8958f5 100644 --- a/linphone-app/ui/modules/Common/Form/Mosaic.qml +++ b/linphone-app/ui/modules/Common/Form/Mosaic.qml @@ -89,9 +89,15 @@ ColumnLayout{ if( columns != bestLayout[1]) columns = bestLayout[1] } + function updateCells(){ + cellWidth = Math.min(computedWidth, computedHeight) + cellHeight = Math.min(computedWidth, computedHeight) + } onItemCountChanged: updateLayout() property int computedWidth: (mainLayout.width - grid.margin ) / columns property int computedHeight: (mainLayout.height - grid.margin ) / rows + onComputedHeightChanged: Qt.callLater(updateCells) + onComputedWidthChanged: Qt.callLater(updateCells) cellWidth: Math.min(computedWidth, computedHeight) cellHeight: Math.min(computedWidth, computedHeight) diff --git a/linphone-app/ui/modules/Linphone/Calls/IncallAvatar.qml b/linphone-app/ui/modules/Linphone/Calls/IncallAvatar.qml index 6aea629ea..7436c5e19 100644 --- a/linphone-app/ui/modules/Linphone/Calls/IncallAvatar.qml +++ b/linphone-app/ui/modules/Linphone/Calls/IncallAvatar.qml @@ -2,6 +2,7 @@ import QtQuick 2.7 import Linphone 1.0 +import Units 1.0 import UtilsCpp 1.0 import App.Styles 1.0 diff --git a/linphone-app/ui/modules/Linphone/Chat/Chat.qml b/linphone-app/ui/modules/Linphone/Chat/Chat.qml index b923981a9..88dd129ac 100644 --- a/linphone-app/ui/modules/Linphone/Chat/Chat.qml +++ b/linphone-app/ui/modules/Linphone/Chat/Chat.qml @@ -123,14 +123,16 @@ Rectangle { delegate: Rectangle { id: entry - property bool isNotice : $chatEntry && ($chatEntry.type === ChatRoomModel.NoticeEntry) - property bool isCall : $chatEntry && ($chatEntry.type === ChatRoomModel.CallEntry) - property bool isMessage : $chatEntry && ($chatEntry.type === ChatRoomModel.MessageEntry) + property var chatEntry: $chatEntry + property bool isNotice : chatEntry && (chatEntry.type === ChatRoomModel.NoticeEntry) + property bool isCall : chatEntry && (chatEntry.type === ChatRoomModel.CallEntry) + property bool isMessage : chatEntry && (chatEntry.type === ChatRoomModel.MessageEntry) property var previousItem : proxyModel.count > 0 && index >0 ? proxyModel.getAt(index-1) : null property var nextItem : proxyModel.count > 0 ? proxyModel.getAt(index+1) : null // bind to count - property bool displayDate: $chatEntry && !Utils.equalDate(new Date($chatEntry.timestamp), new Date()) - property bool isTopGrouped: isGrouped(entry.previousItem, $chatEntry) || false - property bool isBottomGrouped: isGrouped($chatEntry, entry.nextItem) || false + property bool displayDate: chatEntry && !Utils.equalDate(new Date(chatEntry.timestamp), new Date()) + property bool isTopGrouped: isGrouped(entry.previousItem, chatEntry) || false + property bool isBottomGrouped: isGrouped(chatEntry, entry.nextItem) || false + onIsBottomGroupedChanged: if(loader.item) loader.item.isBottomGrouped = isBottomGrouped onIsTopGroupedChanged: if(loader.item) loader.item.isTopGrouped = isTopGrouped @@ -154,10 +156,7 @@ Rectangle { width: chat.contentWidth // Fill all space clip: false - - // --------------------------------------------------------------------- - MouseArea { id: mouseArea @@ -177,48 +176,49 @@ Rectangle { RowLayout{ id: headerLayout Layout.fillWidth: true - Layout.alignment: Qt.AlignTop | ($chatEntry && $chatEntry.isOutgoing ? Qt.AlignRight : Qt.AlignLeft) + Layout.alignment: Qt.AlignTop | (entry.chatEntry && entry.chatEntry.isOutgoing ? Qt.AlignRight : Qt.AlignLeft) Layout.leftMargin: ChatStyle.entry.metaWidth// + ChatStyle.entry.message.extraContent.spacing Layout.rightMargin: ChatStyle.entry.message.outgoing.areaSize spacing:0 // Display time. visible: !entry.isTopGrouped + Text { id:timeDisplay - Layout.alignment: Qt.AlignTop | ($chatEntry && $chatEntry.isOutgoing ? Qt.AlignRight : Qt.AlignLeft) + Layout.alignment: Qt.AlignTop | (entry.chatEntry && entry.chatEntry.isOutgoing ? Qt.AlignRight : Qt.AlignLeft) Layout.preferredHeight: implicitHeight// ChatStyle.entry.lineHeight //Layout.preferredWidth: ChatStyle.entry.time.width color: ChatStyle.entry.event.text.colorModel.color font.pointSize: ChatStyle.entry.time.pointSize - property bool displayYear: entry.displayDate && (new Date($chatEntry.timestamp)).getFullYear() != (new Date()).getFullYear() - text: $chatEntry - ? (entry.displayDate ? UtilsCpp.toDateString($chatEntry.timestamp, (displayYear ? 'yyyy/':'') + 'MM/dd') + ' ' : '') - + UtilsCpp.toTimeString($chatEntry.timestamp, 'hh:mm') + (authorName.visible ? ' - ' : '') + property bool displayYear: entry.displayDate && (new Date(entry.chatEntry.timestamp)).getFullYear() != (new Date()).getFullYear() + text: entry.chatEntry + ? (entry.displayDate ? UtilsCpp.toDateString(entry.chatEntry.timestamp, (displayYear ? 'yyyy/':'') + 'MM/dd') + ' ' : '') + + UtilsCpp.toTimeString(entry.chatEntry.timestamp, 'hh:mm') + (authorName.visible ? ' - ' : '') : '' verticalAlignment: Text.AlignVCenter TooltipArea { - text: $chatEntry ? UtilsCpp.toDateTimeString($chatEntry.timestamp) : '' + text: entry.chatEntry ? UtilsCpp.toDateTimeString(entry.chatEntry.timestamp) : '' } - visible:!isNotice + visible:!entry.isNotice } Text{ id:authorName //Layout.leftMargin: timeDisplay.width + ChatStyle.entry.metaWidth + ChatStyle.entry.message.extraContent.spacing - property var displayName: $chatEntry ? $chatEntry.fromDisplayName ? $chatEntry.fromDisplayName : $chatEntry.name : '' + property var displayName: entry.chatEntry ? entry.chatEntry.fromDisplayName ? entry.chatEntry.fromDisplayName : entry.chatEntry.name : '' text : displayName != undefined ? displayName : '' color: ChatStyle.entry.event.text.colorModel.color font.pointSize: ChatStyle.entry.event.text.pointSize - visible: isMessage - && $chatEntry != undefined - && !$chatEntry.isOutgoing // Only outgoing + visible: entry.isMessage + && entry.chatEntry + && !entry.chatEntry.isOutgoing // Only outgoing && (!entry.previousItem //No previous entry || entry.previousItem.type != ChatRoomModel.MessageEntry // Previous entry is a message - || entry.previousItem.fromSipAddress != $chatEntry.fromSipAddress // Different user - || (new Date(entry.previousItem.timestamp)).setHours(0, 0, 0, 0) != (new Date($chatEntry.timestamp)).setHours(0, 0, 0, 0) // Same day == section + || entry.previousItem.fromSipAddress != entry.chatEntry.fromSipAddress // Different user + || (new Date(entry.previousItem.timestamp)).setHours(0, 0, 0, 0) != (new Date(entry.chatEntry.timestamp)).setHours(0, 0, 0, 0) // Same day == section ) } } @@ -227,7 +227,7 @@ Rectangle { id: loader height: (item !== null && typeof(item)!== 'undefined')? item.height: 0 Layout.fillWidth: true - source: Logic.getComponentFromEntry($chatEntry) + source: Logic.getComponentFromEntry(entry.chatEntry) property int loaderIndex: 0 // index of loader from remaining loaders property int remainingIndex : loaderIndex % ((chat.remainingLoadersCount) / chat.syncLoaderBatch) != 0 // Check loader index to remaining loader. onRemainingIndexChanged: if( remainingIndex == 0 && asynchronous) asynchronous = false @@ -255,7 +255,7 @@ Rectangle { //: "Selection copied to clipboard" : when a user copy a text from the menu, this message show up. onCopySelectionDone: container.noticeBannerText = qsTr("selectedTextCopied") onReplyClicked: { - proxyModel.chatRoomModel.reply = $chatEntry + proxyModel.chatRoomModel.reply = entry.chatEntry } onForwardClicked:{ window.attachVirtualWindow(Qt.resolvedUrl('../Dialog/SipAddressDialog.qml') @@ -264,13 +264,13 @@ Rectangle { addressSelectedCallback: function (sipAddress) { var chat = CallsListModel.createChatRoom( '', proxyModel.chatRoomModel.haveEncryption, [sipAddress], false ) if(chat){ - chat.chatRoomModel.forwardMessage($chatEntry) + chat.chatRoomModel.forwardMessage(entry.chatEntry) TimelineListModel.select(chat.chatRoomModel) } }, chatRoomSelectedCallback: function (chatRoomModel){ if(chatRoomModel){ - chatRoomModel.forwardMessage($chatEntry) + chatRoomModel.forwardMessage(entry.chatEntry) TimelineListModel.select(chatRoomModel) } }