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
case linphone::CallStateStreamsRunning: {
int index = findCallIndex(mList, call);
emit callRunning(index, &call->getData<CallModel>("call-model"));
}
break;
} break;
default:
break;
......@@ -186,12 +185,10 @@ void CallsListModel::addCall (const shared_ptr<linphone::Call> &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();
}
}
......@@ -31,8 +31,6 @@ using namespace std;
// =============================================================================
int ConferenceHelperModel::mInstancesNumber = 0;
ConferenceHelperModel::ConferenceHelperModel (QObject *parent) : QSortFilterProxyModel(parent) {
shared_ptr<linphone::Core> 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<int, QByteArray> ConferenceHelperModel::roleNames () const {
......
......@@ -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<int, QByteArray> 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<linphone::Conference> mConference;
static int mInstancesNumber;
};
#endif // CONFERENCE_HELPER_MODEL_H_
......@@ -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 () {
......
......@@ -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()
}
}
......@@ -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 () {
......
......@@ -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() })
}
}
......@@ -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)
}
}
}
......
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