feat(src/components/calls/CallsListProxyModel): handle conference changes on calls

This commit is contained in:
Ronan Abhamon 2017-05-22 14:07:28 +02:00
parent 777017f40c
commit 25ea28191f
4 changed files with 47 additions and 13 deletions

View file

@ -197,6 +197,8 @@ void CallModel::handleCallStateChanged (const shared_ptr<linphone::Call> &call,
if (call != mCall)
return;
updateIsInConference();
switch (state) {
case linphone::CallStateError:
case linphone::CallStateEnd:
@ -251,6 +253,15 @@ void CallModel::handleCallStateChanged (const shared_ptr<linphone::Call> &call,
// -----------------------------------------------------------------------------
void CallModel::updateIsInConference () {
if (mIsInConference != !!mCall->getConference()) {
mIsInConference = !mIsInConference;
emit isInConferenceChanged(mIsInConference);
}
}
// -----------------------------------------------------------------------------
void CallModel::stopAutoAnswerTimer () const {
QTimer *timer = findChild<QTimer *>(AUTO_ANSWER_OBJECT_NAME, Qt::FindDirectChildrenOnly);
if (timer) {
@ -259,6 +270,8 @@ void CallModel::stopAutoAnswerTimer () const {
}
}
// -----------------------------------------------------------------------------
CallModel::CallStatus CallModel::getStatus () const {
switch (mCall->getState()) {
case linphone::CallStateConnected:

View file

@ -37,6 +37,8 @@ class CallModel : public QObject {
Q_PROPERTY(bool isOutgoing READ isOutgoing CONSTANT);
Q_PROPERTY(bool isInConference READ isInConference NOTIFY isInConferenceChanged);
Q_PROPERTY(int duration READ getDuration CONSTANT); // Constants but called with a timer in qml.
Q_PROPERTY(float quality READ getQuality CONSTANT);
Q_PROPERTY(float microVu READ getMicroVu CONSTANT);
@ -94,6 +96,7 @@ public:
signals:
void callErrorChanged (const QString &callError);
void isInConferenceChanged (bool status);
void microMutedChanged (bool status);
void recordingChanged (bool status);
void statsUpdated ();
@ -106,10 +109,17 @@ private:
void stopAutoAnswerTimer () const;
CallStatus getStatus () const;
bool isOutgoing () const {
return mCall->getDir() == linphone::CallDirOutgoing;
}
bool isInConference () const {
return mIsInConference;
}
void updateIsInConference ();
void acceptWithAutoAnswerDelay ();
QString getCallError () const;
@ -139,6 +149,8 @@ private:
QString iceStateToString (linphone::IceState state) const;
bool mIsInConference = false;
bool mPausedByRemote = false;
bool mPausedByUser = false;
bool mRecording = false;

View file

@ -37,15 +37,18 @@ using namespace std;
// =============================================================================
inline QList<CallModel *>::iterator findCallModel (
QList<CallModel *> &list,
const shared_ptr<linphone::Call> &call
) {
return find_if(
list.begin(), list.end(), [call](CallModel *callModel) {
return call == callModel->getCall();
}
);
inline int findCallIndex (QList<CallModel *> &list, const shared_ptr<linphone::Call> &call) {
auto it = find_if(list.begin(), list.end(), [call](CallModel *callModel) {
return call == callModel->getCall();
});
Q_ASSERT(it != list.end());
return static_cast<int>(distance(list.begin(), it));
}
inline int findCallIndex (QList<CallModel *> &list, const CallModel &callModel) {
return findCallIndex(list, callModel.getCall());
}
// -----------------------------------------------------------------------------
@ -136,7 +139,7 @@ void CallsListModel::handleCallStateChanged (const std::shared_ptr<linphone::Cal
break;
case linphone::CallStateStreamsRunning: {
int index = static_cast<int>(distance(mList.begin(), findCallModel(mList, call)));
int index = findCallIndex(mList, call);
emit callRunning(index, &call->getData<CallModel>("call-model"));
}
break;
@ -173,11 +176,17 @@ void CallsListModel::addCall (const shared_ptr<linphone::Call> &call) {
App::smartShowWindow(App::getInstance()->getCallsWindow());
CallModel *callModel = new CallModel(call);
qInfo() << QStringLiteral("Add call:") << callModel;
App::getInstance()->getEngine()->setObjectOwnership(callModel, QQmlEngine::CppOwnership);
// This connection is (only) useful for `CallsListProxyModel`.
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();
beginInsertRows(QModelIndex(), row, row);

View file

@ -45,5 +45,5 @@ bool CallsListProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex &so
const QModelIndex &index = sourceModel()->index(sourceRow, 0, sourceParent);
shared_ptr<linphone::Call> call = index.data().value<CallModel *>()->getCall();
return call->getConference() != nullptr;
return call->getConference() == nullptr;
}