From a6dfdd1cd1603a050b477e0ccba43b5786b5d27a Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Mon, 5 Jun 2017 17:02:55 +0200 Subject: [PATCH] fix(ui/views/App/Calls/CallsWindow): QML must close the window if necessary, not the c++ --- .../src/components/calls/CallsListModel.cpp | 14 +++-------- .../conference/ConferenceHelperModel.cpp | 14 ----------- .../conference/ConferenceHelperModel.hpp | 10 ++------ .../Common/Window/ApplicationWindow.qml | 9 +++++++ .../ui/modules/Common/Window/Window.js | 10 ++++---- .../ui/modules/Common/Window/Window.qml | 9 +++++++ .../ui/views/App/Calls/CallsWindow.js | 24 ++++++++++++++----- .../ui/views/App/Calls/CallsWindow.qml | 3 +++ 8 files changed, 48 insertions(+), 45 deletions(-) diff --git a/linphone-desktop/src/components/calls/CallsListModel.cpp b/linphone-desktop/src/components/calls/CallsListModel.cpp index 5fff3da5c..269445c64 100644 --- a/linphone-desktop/src/components/calls/CallsListModel.cpp +++ b/linphone-desktop/src/components/calls/CallsListModel.cpp @@ -147,8 +147,7 @@ void CallsListModel::handleCallStateChanged (const std::shared_ptrgetData("call-model")); - } - break; + } break; default: break; @@ -186,12 +185,10 @@ void CallsListModel::addCall (const shared_ptr &call) { App::getInstance()->getEngine()->setObjectOwnership(callModel, QQmlEngine::CppOwnership); // This connection is (only) useful for `CallsListProxyModel`. - QObject::connect( - callModel, &CallModel::isInConferenceChanged, this, [this, callModel](bool) { + QObject::connect(callModel, &CallModel::isInConferenceChanged, this, [this, callModel](bool) { int id = findCallIndex(mList, *callModel); emit dataChanged(index(id, 0), index(id, 0)); - } - ); + }); int row = mList.count(); @@ -223,9 +220,4 @@ void CallsListModel::removeCallCb (CallModel *callModel) { int index = mList.indexOf(callModel); if (index == -1 || !removeRow(index)) qWarning() << QStringLiteral("Unable to remove call:") << callModel; - - if (mList.empty() && ConferenceHelperModel::getInstancesNumber() == 0) { - qInfo() << QStringLiteral("Last call terminated, close calls window."); - App::getInstance()->getCallsWindow()->close(); - } } diff --git a/linphone-desktop/src/components/conference/ConferenceHelperModel.cpp b/linphone-desktop/src/components/conference/ConferenceHelperModel.cpp index d98a8b617..4ca7f49fe 100644 --- a/linphone-desktop/src/components/conference/ConferenceHelperModel.cpp +++ b/linphone-desktop/src/components/conference/ConferenceHelperModel.cpp @@ -31,8 +31,6 @@ using namespace std; // ============================================================================= -int ConferenceHelperModel::mInstancesNumber = 0; - ConferenceHelperModel::ConferenceHelperModel (QObject *parent) : QSortFilterProxyModel(parent) { shared_ptr core = CoreManager::getInstance()->getCore(); @@ -44,18 +42,6 @@ ConferenceHelperModel::ConferenceHelperModel (QObject *parent) : QSortFilterProx App::getInstance()->getEngine()->setObjectOwnership(mConferenceAddModel, QQmlEngine::CppOwnership); setSourceModel(new SipAddressesProxyModel(this)); - - mInstancesNumber++; -} - -ConferenceHelperModel::~ConferenceHelperModel () { - mInstancesNumber--; - Q_ASSERT(mInstancesNumber >= 0); - - if (mInstancesNumber == 0 && CoreManager::getInstance()->getCallsListModel()->rowCount() == 0) { - qInfo() << QStringLiteral("Conference terminated and no calls, close calls window."); - App::getInstance()->getCallsWindow()->close(); - } } QHash ConferenceHelperModel::roleNames () const { diff --git a/linphone-desktop/src/components/conference/ConferenceHelperModel.hpp b/linphone-desktop/src/components/conference/ConferenceHelperModel.hpp index c65124b8f..fc3ee62cb 100644 --- a/linphone-desktop/src/components/conference/ConferenceHelperModel.hpp +++ b/linphone-desktop/src/components/conference/ConferenceHelperModel.hpp @@ -42,20 +42,16 @@ namespace linphone { class ConferenceHelperModel : public QSortFilterProxyModel { Q_OBJECT; - Q_PROPERTY(ConferenceHelperModel::ConferenceAddModel * toAdd READ getConferenceAddModel CONSTANT); + Q_PROPERTY(ConferenceHelperModel::ConferenceAddModel *toAdd READ getConferenceAddModel CONSTANT); public: class ConferenceAddModel; ConferenceHelperModel (QObject *parent = Q_NULLPTR); - ~ConferenceHelperModel (); + ~ConferenceHelperModel () = default; QHash roleNames () const override; - static int getInstancesNumber () { - return mInstancesNumber; - } - Q_INVOKABLE void setFilter (const QString &pattern); protected: @@ -69,8 +65,6 @@ private: ConferenceAddModel *mConferenceAddModel; std::shared_ptr mConference; - - static int mInstancesNumber; }; #endif // CONFERENCE_HELPER_MODEL_H_ diff --git a/linphone-desktop/ui/modules/Common/Window/ApplicationWindow.qml b/linphone-desktop/ui/modules/Common/Window/ApplicationWindow.qml index 012f5d396..afdbbbc6c 100644 --- a/linphone-desktop/ui/modules/Common/Window/ApplicationWindow.qml +++ b/linphone-desktop/ui/modules/Common/Window/ApplicationWindow.qml @@ -6,8 +6,17 @@ import 'Window.js' as Logic // ============================================================================= ApplicationWindow { + id: window + default property alias _content: content.data + readonly property bool virtualWindowVisible: virtualWindow.visible + + // --------------------------------------------------------------------------- + + signal attachedVirtualWindow + signal detachedVirtualWindow + // --------------------------------------------------------------------------- function attachVirtualWindow () { diff --git a/linphone-desktop/ui/modules/Common/Window/Window.js b/linphone-desktop/ui/modules/Common/Window/Window.js index b3eb80804..0ae78c5c0 100644 --- a/linphone-desktop/ui/modules/Common/Window/Window.js +++ b/linphone-desktop/ui/modules/Common/Window/Window.js @@ -23,19 +23,17 @@ function attachVirtualWindow (component, properties, exitStatusHandler) { if (exitStatusHandler) { object.exitStatus.connect(exitStatusHandler) } - object.exitStatus.connect(function () { - var content = virtualWindow.unsetContent() - if (content) { - content.destroy() - } - }) + object.exitStatus.connect(detachVirtualWindow) virtualWindow.setContent(object) + + window.attachedVirtualWindow() } function detachVirtualWindow () { var object = virtualWindow.unsetContent() if (object) { object.destroy() + window.detachedVirtualWindow() } } diff --git a/linphone-desktop/ui/modules/Common/Window/Window.qml b/linphone-desktop/ui/modules/Common/Window/Window.qml index 884629619..b27de3e0e 100644 --- a/linphone-desktop/ui/modules/Common/Window/Window.qml +++ b/linphone-desktop/ui/modules/Common/Window/Window.qml @@ -6,8 +6,17 @@ import 'Window.js' as Logic // ============================================================================= Window { + id: window + default property alias _content: content.data + readonly property bool virtualWindowVisible: virtualWindow.visible + + // --------------------------------------------------------------------------- + + signal attachedVirtualWindow + signal detachedVirtualWindow + // --------------------------------------------------------------------------- function attachVirtualWindow () { diff --git a/linphone-desktop/ui/views/App/Calls/CallsWindow.js b/linphone-desktop/ui/views/App/Calls/CallsWindow.js index 8c3ff67ba..f0c37d978 100644 --- a/linphone-desktop/ui/views/App/Calls/CallsWindow.js +++ b/linphone-desktop/ui/views/App/Calls/CallsWindow.js @@ -8,16 +8,12 @@ // ============================================================================= -var forceClose = false - function handleClosing (close) { var callsList = Linphone.CallsListModel window.detachVirtualWindow() - if (forceClose || callsList.getRunningCallsNumber() === 0) { - forceClose = false - callsList.terminateAllCalls() + if (callsList.getRunningCallsNumber() === 0) { return } @@ -25,7 +21,7 @@ function handleClosing (close) { descriptionText: qsTr('acceptClosingDescription') }, function (status) { if (status) { - forceClose = true + callsList.terminateAllCalls() window.close() } }) @@ -84,3 +80,19 @@ function handleCallTransferAsked (call) { call: call }) } + +function handleDetachedVirtualWindow () { + handleCountChanged(calls.count) +} + +function windowMustBeClosed () { + return calls.count === 0 && !window.virtualWindowVisible +} + +function handleCountChanged () { + if (windowMustBeClosed()) { + // Workaround, it's necessary to use a timeout because at last call termination + // a segfault is emit in `QOpenGLContext::functions() const ()`. + Utils.setTimeout(window, 0, function () { windowMustBeClosed() && window.close() }) + } +} diff --git a/linphone-desktop/ui/views/App/Calls/CallsWindow.qml b/linphone-desktop/ui/views/App/Calls/CallsWindow.qml index 2a48b7575..c511a3998 100644 --- a/linphone-desktop/ui/views/App/Calls/CallsWindow.qml +++ b/linphone-desktop/ui/views/App/Calls/CallsWindow.qml @@ -55,6 +55,7 @@ Window { // --------------------------------------------------------------------------- onClosing: Logic.handleClosing(close) + onDetachedVirtualWindow: Logic.handleDetachedVirtualWindow() // --------------------------------------------------------------------------- @@ -123,6 +124,8 @@ Window { conferenceModel: ConferenceModel {} model: CallsListProxyModel {} + + onCountChanged: Logic.handleCountChanged(count) } } }