Commit bc74c7a7 authored by Ronan's avatar Ronan
Browse files

feat(src/components/conference/ConferenceHelperModel): handle add/remove sip...

feat(src/components/conference/ConferenceHelperModel): handle add/remove sip addresses in conference
parent a0e49580
......@@ -68,6 +68,12 @@ CallModel::~CallModel () {
// -----------------------------------------------------------------------------
QString CallModel::getSipAddress () const {
return ::Utils::linphoneStringToQString(mCall->getRemoteAddress()->asStringUriOnly());
}
// -----------------------------------------------------------------------------
void CallModel::setRecordFile (shared_ptr<linphone::CallParams> &callParams) {
callParams->setRecordFile(
::Utils::qStringToLinphoneString(
......@@ -246,10 +252,6 @@ void CallModel::stopAutoAnswerTimer () const {
}
}
QString CallModel::getSipAddress () const {
return ::Utils::linphoneStringToQString(mCall->getRemoteAddress()->asStringUriOnly());
}
CallModel::CallStatus CallModel::getStatus () const {
switch (mCall->getState()) {
case linphone::CallStateConnected:
......
......@@ -72,6 +72,8 @@ public:
return mCall;
}
QString getSipAddress () const;
static void setRecordFile (std::shared_ptr<linphone::CallParams> &callParams);
void updateStats (const std::shared_ptr<const linphone::CallStats> &callStats);
......@@ -103,8 +105,6 @@ private:
void stopAutoAnswerTimer () const;
QString getSipAddress () const;
CallStatus getStatus () const;
bool isOutgoing () const {
return mCall->getDir() == linphone::CallDirOutgoing;
......
......@@ -22,16 +22,24 @@
#include "../../Utils.hpp"
#include "../core/CoreManager.hpp"
#include "../smart-search-bar/SmartSearchBarModel.hpp"
#include "ConferenceHelperModel.hpp"
// =============================================================================
ConferenceHelperModel::ConferenceHelperModel (QObject *parent) : QSortFilterProxyModel(parent) {
setSourceModel(CoreManager::getInstance()->getSipAddressesModel());
CoreManager *coreManager = CoreManager::getInstance();
for (const auto &participant : CoreManager::getInstance()->getCore()->getConference()->getParticipants())
for (const auto &participant : coreManager->getCore()->getConference()->getParticipants())
mInConference << ::Utils::linphoneStringToQString(participant->asStringUriOnly());
CallsListModel *calls = coreManager->getCallsListModel();
QObject::connect(calls, &CallsListModel::rowsAboutToBeRemoved, this, &ConferenceHelperModel::handleCallsAboutToBeRemoved);
QObject::connect(calls, &CallsListModel::callRunning, this, &ConferenceHelperModel::handleCallRunning);
setSourceModel(new SmartSearchBarModel(this));
}
QHash<int, QByteArray> ConferenceHelperModel::roleNames () const {
......@@ -40,9 +48,66 @@ QHash<int, QByteArray> ConferenceHelperModel::roleNames () const {
return roles;
}
// -----------------------------------------------------------------------------
void ConferenceHelperModel::setFilter (const QString &pattern) {
static_cast<SmartSearchBarModel *>(sourceModel())->setFilter(pattern);
}
// -----------------------------------------------------------------------------
bool ConferenceHelperModel::filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const {
const QModelIndex &index = sourceModel()->index(sourceRow, 0, sourceParent);
const QVariantMap &data = index.data().toMap();
const QString &sipAddress = data["sipAddress"].toString();
return !mInConference.contains(sipAddress) || !mToAdd.contains(sipAddress);
}
// -----------------------------------------------------------------------------
void ConferenceHelperModel::handleCallsAboutToBeRemoved (const QModelIndex &, int first, int last) {
CallsListModel *calls = CoreManager::getInstance()->getCallsListModel();
bool soFarSoGood = false;
for (int i = first; i <= last; ++i) {
const CallModel *callModel = calls->data(calls->index(first, 0)).value<CallModel *>();
const QString &sipAddress = callModel->getSipAddress();
if (removeFromConference(sipAddress))
soFarSoGood = true;
}
if (soFarSoGood) {
invalidate();
emit inConferenceChanged(mInConference);
}
}
void ConferenceHelperModel::handleCallRunning (int, CallModel *callModel) {
const QString &sipAddress = callModel->getSipAddress();
bool soFarSoGood = callModel->getCall()->getConference()
? addToConference(sipAddress)
: removeFromConference(sipAddress);
if (soFarSoGood)
emit inConferenceChanged(mInConference);
}
// -----------------------------------------------------------------------------
bool ConferenceHelperModel::addToConference (const QString &sipAddress) {
bool ret = !mInConference.contains(sipAddress);
if (ret) {
qInfo() << QStringLiteral("Add sip address to conference: `%1`.").arg(sipAddress);
mInConference << sipAddress;
}
return ret;
}
return !mInConference.contains(data["sipAddress"].toString());
bool ConferenceHelperModel::removeFromConference (const QString &sipAddress) {
bool ret = mInConference.removeOne(sipAddress);
if (ret)
qInfo() << QStringLiteral("Remove sip address from conference: `%1`.").arg(sipAddress);
return ret;
}
......@@ -24,18 +24,38 @@
// =============================================================================
class CallModel;
class ConferenceHelperModel : public QSortFilterProxyModel {
Q_OBJECT;
Q_PROPERTY(QStringList inConference READ getInConference NOTIFY inConferenceChanged);
public:
ConferenceHelperModel (QObject *parent = Q_NULLPTR);
~ConferenceHelperModel () = default;
QHash<int, QByteArray> roleNames () const override;
Q_INVOKABLE void setFilter (const QString &pattern);
signals:
void inConferenceChanged (const QStringList &inConference);
protected:
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override;
private:
void handleCallRunning (int index, CallModel *callModel);
void handleCallsAboutToBeRemoved (const QModelIndex &parent, int first, int last);
bool addToConference (const QString &sipAddress);
bool removeFromConference (const QString &sipAddress);
QStringList getInConference () {
return mInConference;
}
QStringList mInConference;
QStringList mToAdd;
};
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