Commit a6dfdd1c authored by Ronan Abhamon's avatar Ronan Abhamon

fix(ui/views/App/Calls/CallsWindow): QML must close the window if necessary, not the c++

parent 060927b8
...@@ -147,8 +147,7 @@ void CallsListModel::handleCallStateChanged (const std::shared_ptr<linphone::Cal ...@@ -147,8 +147,7 @@ void CallsListModel::handleCallStateChanged (const std::shared_ptr<linphone::Cal
case linphone::CallStateStreamsRunning: { case linphone::CallStateStreamsRunning: {
int index = findCallIndex(mList, call); int index = findCallIndex(mList, call);
emit callRunning(index, &call->getData<CallModel>("call-model")); emit callRunning(index, &call->getData<CallModel>("call-model"));
} } break;
break;
default: default:
break; break;
...@@ -186,12 +185,10 @@ void CallsListModel::addCall (const shared_ptr<linphone::Call> &call) { ...@@ -186,12 +185,10 @@ void CallsListModel::addCall (const shared_ptr<linphone::Call> &call) {
App::getInstance()->getEngine()->setObjectOwnership(callModel, QQmlEngine::CppOwnership); App::getInstance()->getEngine()->setObjectOwnership(callModel, QQmlEngine::CppOwnership);
// This connection is (only) useful for `CallsListProxyModel`. // This connection is (only) useful for `CallsListProxyModel`.
QObject::connect( QObject::connect(callModel, &CallModel::isInConferenceChanged, this, [this, callModel](bool) {
callModel, &CallModel::isInConferenceChanged, this, [this, callModel](bool) {
int id = findCallIndex(mList, *callModel); int id = findCallIndex(mList, *callModel);
emit dataChanged(index(id, 0), index(id, 0)); emit dataChanged(index(id, 0), index(id, 0));
} });
);
int row = mList.count(); int row = mList.count();
...@@ -223,9 +220,4 @@ void CallsListModel::removeCallCb (CallModel *callModel) { ...@@ -223,9 +220,4 @@ void CallsListModel::removeCallCb (CallModel *callModel) {
int index = mList.indexOf(callModel); int index = mList.indexOf(callModel);
if (index == -1 || !removeRow(index)) if (index == -1 || !removeRow(index))
qWarning() << QStringLiteral("Unable to remove call:") << callModel; 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();
}
} }
...@@ -31,8 +31,6 @@ using namespace std; ...@@ -31,8 +31,6 @@ using namespace std;
// ============================================================================= // =============================================================================
int ConferenceHelperModel::mInstancesNumber = 0;
ConferenceHelperModel::ConferenceHelperModel (QObject *parent) : QSortFilterProxyModel(parent) { ConferenceHelperModel::ConferenceHelperModel (QObject *parent) : QSortFilterProxyModel(parent) {
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore(); shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
...@@ -44,18 +42,6 @@ ConferenceHelperModel::ConferenceHelperModel (QObject *parent) : QSortFilterProx ...@@ -44,18 +42,6 @@ ConferenceHelperModel::ConferenceHelperModel (QObject *parent) : QSortFilterProx
App::getInstance()->getEngine()->setObjectOwnership(mConferenceAddModel, QQmlEngine::CppOwnership); App::getInstance()->getEngine()->setObjectOwnership(mConferenceAddModel, QQmlEngine::CppOwnership);
setSourceModel(new SipAddressesProxyModel(this)); 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<int, QByteArray> ConferenceHelperModel::roleNames () const { QHash<int, QByteArray> ConferenceHelperModel::roleNames () const {
......
...@@ -42,20 +42,16 @@ namespace linphone { ...@@ -42,20 +42,16 @@ namespace linphone {
class ConferenceHelperModel : public QSortFilterProxyModel { class ConferenceHelperModel : public QSortFilterProxyModel {
Q_OBJECT; Q_OBJECT;
Q_PROPERTY(ConferenceHelperModel::ConferenceAddModel * toAdd READ getConferenceAddModel CONSTANT); Q_PROPERTY(ConferenceHelperModel::ConferenceAddModel *toAdd READ getConferenceAddModel CONSTANT);
public: public:
class ConferenceAddModel; class ConferenceAddModel;
ConferenceHelperModel (QObject *parent = Q_NULLPTR); ConferenceHelperModel (QObject *parent = Q_NULLPTR);
~ConferenceHelperModel (); ~ConferenceHelperModel () = default;
QHash<int, QByteArray> roleNames () const override; QHash<int, QByteArray> roleNames () const override;
static int getInstancesNumber () {
return mInstancesNumber;
}
Q_INVOKABLE void setFilter (const QString &pattern); Q_INVOKABLE void setFilter (const QString &pattern);
protected: protected:
...@@ -69,8 +65,6 @@ private: ...@@ -69,8 +65,6 @@ private:
ConferenceAddModel *mConferenceAddModel; ConferenceAddModel *mConferenceAddModel;
std::shared_ptr<linphone::Conference> mConference; std::shared_ptr<linphone::Conference> mConference;
static int mInstancesNumber;
}; };
#endif // CONFERENCE_HELPER_MODEL_H_ #endif // CONFERENCE_HELPER_MODEL_H_
...@@ -6,8 +6,17 @@ import 'Window.js' as Logic ...@@ -6,8 +6,17 @@ import 'Window.js' as Logic
// ============================================================================= // =============================================================================
ApplicationWindow { ApplicationWindow {
id: window
default property alias _content: content.data default property alias _content: content.data
readonly property bool virtualWindowVisible: virtualWindow.visible
// ---------------------------------------------------------------------------
signal attachedVirtualWindow
signal detachedVirtualWindow
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function attachVirtualWindow () { function attachVirtualWindow () {
......
...@@ -23,19 +23,17 @@ function attachVirtualWindow (component, properties, exitStatusHandler) { ...@@ -23,19 +23,17 @@ function attachVirtualWindow (component, properties, exitStatusHandler) {
if (exitStatusHandler) { if (exitStatusHandler) {
object.exitStatus.connect(exitStatusHandler) object.exitStatus.connect(exitStatusHandler)
} }
object.exitStatus.connect(function () { object.exitStatus.connect(detachVirtualWindow)
var content = virtualWindow.unsetContent()
if (content) {
content.destroy()
}
})
virtualWindow.setContent(object) virtualWindow.setContent(object)
window.attachedVirtualWindow()
} }
function detachVirtualWindow () { function detachVirtualWindow () {
var object = virtualWindow.unsetContent() var object = virtualWindow.unsetContent()
if (object) { if (object) {
object.destroy() object.destroy()
window.detachedVirtualWindow()
} }
} }
...@@ -6,8 +6,17 @@ import 'Window.js' as Logic ...@@ -6,8 +6,17 @@ import 'Window.js' as Logic
// ============================================================================= // =============================================================================
Window { Window {
id: window
default property alias _content: content.data default property alias _content: content.data
readonly property bool virtualWindowVisible: virtualWindow.visible
// ---------------------------------------------------------------------------
signal attachedVirtualWindow
signal detachedVirtualWindow
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function attachVirtualWindow () { function attachVirtualWindow () {
......
...@@ -8,16 +8,12 @@ ...@@ -8,16 +8,12 @@
// ============================================================================= // =============================================================================
var forceClose = false
function handleClosing (close) { function handleClosing (close) {
var callsList = Linphone.CallsListModel var callsList = Linphone.CallsListModel
window.detachVirtualWindow() window.detachVirtualWindow()
if (forceClose || callsList.getRunningCallsNumber() === 0) { if (callsList.getRunningCallsNumber() === 0) {
forceClose = false
callsList.terminateAllCalls()
return return
} }
...@@ -25,7 +21,7 @@ function handleClosing (close) { ...@@ -25,7 +21,7 @@ function handleClosing (close) {
descriptionText: qsTr('acceptClosingDescription') descriptionText: qsTr('acceptClosingDescription')
}, function (status) { }, function (status) {
if (status) { if (status) {
forceClose = true callsList.terminateAllCalls()
window.close() window.close()
} }
}) })
...@@ -84,3 +80,19 @@ function handleCallTransferAsked (call) { ...@@ -84,3 +80,19 @@ function handleCallTransferAsked (call) {
call: 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() })
}
}
...@@ -55,6 +55,7 @@ Window { ...@@ -55,6 +55,7 @@ Window {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
onClosing: Logic.handleClosing(close) onClosing: Logic.handleClosing(close)
onDetachedVirtualWindow: Logic.handleDetachedVirtualWindow()
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -123,6 +124,8 @@ Window { ...@@ -123,6 +124,8 @@ Window {
conferenceModel: ConferenceModel {} conferenceModel: ConferenceModel {}
model: CallsListProxyModel {} model: CallsListProxyModel {}
onCountChanged: Logic.handleCountChanged(count)
} }
} }
} }
......
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