diff --git a/linphone-desktop/resources.qrc b/linphone-desktop/resources.qrc index 18fac771a..89d419a28 100644 --- a/linphone-desktop/resources.qrc +++ b/linphone-desktop/resources.qrc @@ -265,6 +265,7 @@ ui/modules/Common/Window/Window.qml ui/modules/Linphone/Account/AccountStatus.qml ui/modules/Linphone/Calls/CallControls.qml + ui/modules/Linphone/Calls/Calls.js ui/modules/Linphone/Calls/Calls.qml ui/modules/Linphone/CardBlock.qml ui/modules/Linphone/Chat/Chat.js diff --git a/linphone-desktop/src/app/object-builders/AsyncObjectBuilder.cpp b/linphone-desktop/src/app/object-builders/AsyncObjectBuilder.cpp index d7562a2d6..5dbb86c29 100644 --- a/linphone-desktop/src/app/object-builders/AsyncObjectBuilder.cpp +++ b/linphone-desktop/src/app/object-builders/AsyncObjectBuilder.cpp @@ -92,6 +92,9 @@ void AsyncObjectBuilder::createObject (QQmlEngine *engine, const char *path, Dec #ifdef QT_DEBUG Q_ASSERT(!m_block_creation); m_block_creation = true; + + Q_ASSERT(engine != nullptr); + Q_ASSERT(path != nullptr); #endif // ifdef QT_DEBUG m_component = new QQmlComponent(engine, QUrl(path), QQmlComponent::Asynchronous, this); diff --git a/linphone-desktop/ui/modules/Linphone/Calls/CallControls.qml b/linphone-desktop/ui/modules/Linphone/Calls/CallControls.qml index 27753d981..474551d54 100644 --- a/linphone-desktop/ui/modules/Linphone/Calls/CallControls.qml +++ b/linphone-desktop/ui/modules/Linphone/Calls/CallControls.qml @@ -21,10 +21,6 @@ Rectangle { // --------------------------------------------------------------------------- - property var _sipAddressObserver: SipAddressesModel.getSipAddressObserver(sipAddress) - - // --------------------------------------------------------------------------- - signal clicked // --------------------------------------------------------------------------- @@ -56,10 +52,7 @@ Rectangle { displayUnreadMessagesCount: true - entry: ({ - contact: _sipAddressObserver.contact, - sipAddress: callControls.sipAddress - }) + entry: SipAddressesModel.getSipAddressObserver(sipAddress) } Item { diff --git a/linphone-desktop/ui/modules/Linphone/Calls/Calls.js b/linphone-desktop/ui/modules/Linphone/Calls/Calls.js new file mode 100644 index 000000000..367177c67 --- /dev/null +++ b/linphone-desktop/ui/modules/Linphone/Calls/Calls.js @@ -0,0 +1,148 @@ +// ============================================================================= +// `Calls.qml` Logic. +// ============================================================================= + +.import Linphone 1.0 as Linphone + +// ============================================================================= + +var MAP_STATUS_TO_PARAMS = (function () { + var CallModel = Linphone.CallModel + var map = {} + + map[CallModel.CallStatusConnected] = (function (call) { + return { + actions: [{ + handler: (function () { call.pausedByUser = true }), + name: qsTr('pauseCall') + }, { + handler: (function () { call.transfer() }), + name: qsTr('transferCall') + }, { + handler: (function () { call.terminate() }), + name: qsTr('terminateCall') + }], + component: callActions, + string: 'connected' + } + }) + + map[CallModel.CallStatusEnded] = (function (call) { + return { + string: 'ended' + } + }) + + map[CallModel.CallStatusIncoming] = (function (call) { + return { + actions: [{ + name: qsTr('acceptAudioCall'), + handler: (function () { call.accept() }) + }, { + name: qsTr('acceptVideoCall'), + handler: (function () { call.acceptWithVideo() }) + }, { + name: qsTr('terminateCall'), + handler: (function () { call.terminate() }) + }], + component: callActions, + string: 'incoming' + } + }) + + map[CallModel.CallStatusOutgoing] = (function (call) { + return { + component: callAction, + handler: (function () { call.terminate() }), + icon: 'hangup', + string: 'outgoing' + } + }) + + map[CallModel.CallStatusPaused] = (function (call) { + return { + actions: [(call.pausedByUser ? { + handler: (function () { call.pausedByUser = false }), + name: qsTr('resumeCall') + } : { + handler: (function () { call.pausedByUser = true }), + name: qsTr('pauseCall') + }), { + handler: (function () { call.transfer() }), + name: qsTr('transferCall') + }, { + handler: (function () { call.terminate() }), + name: qsTr('terminateCall') + }], + component: callActions, + string: 'paused' + } + }) + + return map; +})() + +// ----------------------------------------------------------------------------- + +function getParams (call) { + if (call) { + return MAP_STATUS_TO_PARAMS[call.status](call) + } +} + +// ----------------------------------------------------------------------------- + +function handleCallRunning (index, call) { + calls.currentIndex = index + calls._selectedCall = call +} + +function handleRowsAboutToBeRemoved (_, first, last) { + var index = calls.currentIndex + + if (index >= first && index <= last) { // Remove current call. + var model = calls.model + + if (model.rowCount() - (last - first + 1) <= 0) { + calls._selectedCall = null + } else { + if (first === 0) { + calls._selectedCall = model.data(model.index(last + 1, 0)) + } else { + calls._selectedCall = model.data(model.index(0, 0)) + } + } + } +} + +function handleRowsRemoved (_, first, last) { + var index = calls.currentIndex + + // The current call has been removed. + if (index >= first && index <= last) { + if (calls.model.rowCount() === 0) { + calls.currentIndex = -1 // No calls. + } else { + calls.currentIndex = 0 // The first call becomes the selected call. + } + } + + // Update the current index of the selected call if it was after the removed calls. + else if (last < index) { + calls.currentIndex = index - (last - first + 1) + } +} + +function handleRowsInserted (_, first, last) { + // The last inserted outgoing element become the selected call. + var model = calls.model + + for (var index = last; index >= first; index--) { + var call = model.data(model.index(index, 0)) + + if (call.isOutgoing) { + calls.currentIndex = first + calls._selectedCall = model.data(model.index(first, 0)) + } + } +} diff --git a/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml b/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml index c894b306e..755000086 100644 --- a/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml +++ b/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml @@ -4,6 +4,8 @@ import Common 1.0 import Linphone 1.0 import Linphone.Styles 1.0 +import 'Calls.js' as Logic + // ============================================================================= ListView { @@ -13,153 +15,23 @@ ListView { readonly property var selectedCall: _selectedCall - property var _mapStatusToParams property var _selectedCall // --------------------------------------------------------------------------- - function _getParams (call) { - if (call) { - return _mapStatusToParams[call.status](call) - } - } - - // --------------------------------------------------------------------------- - boundsBehavior: Flickable.StopAtBounds clip: true spacing: 0 // --------------------------------------------------------------------------- - Component.onCompleted: { - _mapStatusToParams = {} - - _mapStatusToParams[CallModel.CallStatusConnected] = (function (call) { - return { - actions: [{ - handler: (function () { call.pausedByUser = true }), - name: qsTr('pauseCall') - }, { - handler: (function () { call.transfer() }), - name: qsTr('transferCall') - }, { - handler: (function () { call.terminate() }), - name: qsTr('terminateCall') - }], - component: callActions, - string: 'connected' - } - }) - - _mapStatusToParams[CallModel.CallStatusEnded] = (function (call) { - return { - string: 'ended' - } - }) - - _mapStatusToParams[CallModel.CallStatusIncoming] = (function (call) { - return { - actions: [{ - name: qsTr('acceptAudioCall'), - handler: (function () { call.accept() }) - }, { - name: qsTr('acceptVideoCall'), - handler: (function () { call.acceptWithVideo() }) - }, { - name: qsTr('terminateCall'), - handler: (function () { call.terminate() }) - }], - component: callActions, - string: 'incoming' - } - }) - - _mapStatusToParams[CallModel.CallStatusOutgoing] = (function (call) { - return { - component: callAction, - handler: (function () { call.terminate() }), - icon: 'hangup', - string: 'outgoing' - } - }) - - _mapStatusToParams[CallModel.CallStatusPaused] = (function (call) { - return { - actions: [(call.pausedByUser ? { - handler: (function () { call.pausedByUser = false }), - name: qsTr('resumeCall') - } : { - handler: (function () { call.pausedByUser = true }), - name: qsTr('pauseCall') - }), { - handler: (function () { call.transfer() }), - name: qsTr('transferCall') - }, { - handler: (function () { call.terminate() }), - name: qsTr('terminateCall') - }], - component: callActions, - string: 'paused' - } - }) - } - - // --------------------------------------------------------------------------- - Connections { target: model - onRowsAboutToBeRemoved: { - var index = calls.currentIndex - - if (index >= first && index <= last) { // Remove current call. - if (model.rowCount() - (last - first + 1) <= 0) { - _selectedCall = null - } else { - if (first === 0) { - _selectedCall = model.data(model.index(last + 1, 0)) - } else { - _selectedCall = model.data(model.index(0, 0)) - } - } - } - } - - onRowsRemoved: { - var index = calls.currentIndex - - // The current call has been removed. - if (index >= first && index <= last) { - if (model.rowCount() === 0) { - calls.currentIndex = -1 // No calls. - } else { - calls.currentIndex = 0 // The first call becomes the selected call. - } - } - - // Update the current index of the selected call if it was after the removed calls. - else if (last < index) { - calls.currentIndex = index - (last - first + 1) - } - } - - // The last inserted outgoing element become the selected call. - onRowsInserted: { - for (var index = last; index >= first; index--) { - var call = model.data(model.index(index, 0)) - - if (call.isOutgoing) { - calls.currentIndex = first - _selectedCall = model.data(model.index(first, 0)) - } - } - } - - onCallRunning: { - calls.currentIndex = index - _selectedCall = call - } + onCallRunning: Logic.handleCallRunning(index, call) + onRowsAboutToBeRemoved: Logic.handleRowsAboutToBeRemoved(parent, first, last) + onRowsInserted: Logic.handleRowsInserted(parent, first, last) + onRowsRemoved: Logic.handleRowsRemoved(parent, first, last) } // --------------------------------------------------------------------------- @@ -260,10 +132,11 @@ ListView { Loader { id: loader - property int callId: index - property var call: $call - property var callControls: _callControls - property var params: _getParams($call) + readonly property int callId: index + + readonly property var call: $call + readonly property var callControls: _callControls + readonly property var params: Logic.getParams($call) anchors.centerIn: parent sourceComponent: params.component diff --git a/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedCall.qml b/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedCall.qml index 31b7f3172..c1b3c0501 100644 --- a/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedCall.qml +++ b/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedCall.qml @@ -13,8 +13,6 @@ Notification { // --------------------------------------------------------------------------- property var _call: notificationData && notificationData.call - property var _contact: _sipAddressObserver.contact - property var _sipAddressObserver: SipAddressesModel.getSipAddressObserver(_call ? _call.sipAddress : '') // --------------------------------------------------------------------------- @@ -49,10 +47,10 @@ Notification { Contact { Layout.fillWidth: true - entry: ({ - contact: notification._contact, - sipAddress: notification._sipAddressObserver.sipAddress - }) + entry: { + var call = notification._call + return SipAddressesModel.getSipAddressObserver(call ? call.sipAddress : '') + } } // --------------------------------------------------------------------- diff --git a/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml b/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml index 6d182c3f8..2678868cf 100644 --- a/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml +++ b/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml @@ -13,8 +13,6 @@ Notification { // --------------------------------------------------------------------------- property string _sipAddress: notificationData && notificationData.sipAddress || '' - property var _contact: _sipAddressObserver.contact - property var _sipAddressObserver: SipAddressesModel.getSipAddressObserver(_sipAddress) // --------------------------------------------------------------------------- @@ -49,10 +47,7 @@ Notification { Contact { Layout.fillWidth: true - entry: ({ - contact: notification._contact, - sipAddress: notification._sipAddress - }) + entry: SipAddressesModel.getSipAddressObserver(notification._sipAddress) } Rectangle { diff --git a/linphone-desktop/ui/modules/Linphone/SmartSearchBar.qml b/linphone-desktop/ui/modules/Linphone/SmartSearchBar.qml index 9e55bdf11..99372595f 100644 --- a/linphone-desktop/ui/modules/Linphone/SmartSearchBar.qml +++ b/linphone-desktop/ui/modules/Linphone/SmartSearchBar.qml @@ -77,6 +77,7 @@ SearchBox { Layout.fillHeight: true Layout.fillWidth: true + entry: ({ sipAddress: interpretableSipAddress })