mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-07 14:44:01 +00:00
feat(src/components/conference/ConferenceHelperModel): handle add/remove sip addresses in conference
This commit is contained in:
parent
a0e49580e8
commit
bc74c7a7b0
4 changed files with 96 additions and 9 deletions
|
|
@ -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(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;
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue