Synchronization of conference info. Allow to remove them.

This commit is contained in:
Julien Wadel 2022-07-01 17:06:50 +02:00
parent 04552762ce
commit 372697edc9
12 changed files with 68 additions and 7 deletions

View file

@ -39,6 +39,14 @@ public:
void add(QSharedPointer<X> x){
qobject_cast<T*>(sourceModel())->add(x);
}
template <class X>
void removeShared(QSharedPointer<X> x){
qobject_cast<T*>(sourceModel())->remove(x);
}
template <class X>
void remove(X x){
qobject_cast<T*>(sourceModel())->remove(x);
}
};

View file

@ -40,9 +40,16 @@
ConferenceInfoMapModel::ConferenceInfoMapModel (QObject *parent) : ProxyAbstractMapModel<QDate,SortFilterAbstractProxyModel<ProxyListModel>*>(parent) {
auto conferenceInfos = CoreManager::getInstance()->getCore()->getConferenceInformationList();
auto me = CoreManager::getInstance()->getCore()->getDefaultAccount()->getParams()->getIdentityAddress();
for(auto conferenceInfo : conferenceInfos){
std::list<std::shared_ptr<linphone::Address>> participants = conferenceInfo->getParticipants();
add(conferenceInfo, false);
}
}
// -----------------------------------------------------------------------------
void ConferenceInfoMapModel::add(const std::shared_ptr<linphone::ConferenceInfo> & conferenceInfo, const bool& sendEvents){
auto me = CoreManager::getInstance()->getCore()->getDefaultAccount()->getParams()->getIdentityAddress();
std::list<std::shared_ptr<linphone::Address>> participants = conferenceInfo->getParticipants();
bool haveMe = conferenceInfo->getOrganizer()->weakEqual(me);
if(!haveMe)
haveMe = (std::find_if(participants.begin(), participants.end(), [me](const std::shared_ptr<linphone::Address>& address){
@ -54,11 +61,19 @@ ConferenceInfoMapModel::ConferenceInfoMapModel (QObject *parent) : ProxyAbstract
if( !mMappedList.contains(conferenceDateTimeSystem)){
auto proxy = new ConferenceInfoProxyListModel(this);
connect(this, &ConferenceInfoMapModel::filterTypeChanged, proxy, &ConferenceInfoProxyListModel::setFilterType);
if(sendEvents){
int row = 0;
auto it = mMappedList.begin();
while(it != mMappedList.end() && it.key() < conferenceDateTimeSystem)
++it;
row = std::distance(it,mMappedList.begin());
beginInsertColumns(QModelIndex(), row, row);
}
mMappedList[conferenceDateTimeSystem] = proxy;
if(sendEvents)
endInsertColumns();
}
mMappedList[conferenceDateTimeSystem]->add(conferenceInfoModel);
connect(conferenceInfoModel.get(), &ConferenceInfoModel::removed, qobject_cast<ConferenceInfoProxyListModel*>(mMappedList[conferenceDateTimeSystem]), &ConferenceInfoProxyListModel::onRemoved);
}
}
}
// -----------------------------------------------------------------------------
}

View file

@ -35,6 +35,7 @@ class ConferenceInfoMapModel : public ProxyAbstractMapModel<QDate,SortFilterAbst
public:
ConferenceInfoMapModel (QObject *parent = Q_NULLPTR);
void add(const std::shared_ptr<linphone::ConferenceInfo> & conferenceInfo, const bool& sendEvents = true);
signals:
void filterTypeChanged(int filterType);

View file

@ -107,6 +107,10 @@ std::shared_ptr<linphone::ConferenceInfo> ConferenceInfoModel::getConferenceInfo
return mConferenceInfo;
}
std::shared_ptr<linphone::ConferenceInfo> ConferenceInfoModel::findConferenceInfo(const std::shared_ptr<const linphone::ConferenceInfo> & conferenceInfo){
return CoreManager::getInstance()->getCore()->findConferenceInformationFromUri(conferenceInfo->getUri()->clone());
}
//------------------------------------------------------------------------------------------------
@ -263,6 +267,13 @@ void ConferenceInfoModel::createConference(const int& securityLevel, const int&
mConferenceScheduler->getConferenceScheduler()->setInfo(mConferenceInfo);
}
void ConferenceInfoModel::deleteConferenceInfo(){
if(mConferenceInfo) {
CoreManager::getInstance()->getCore()->deleteConferenceInformation(mConferenceInfo);
emit removed();
}
}
//-------------------------------------------------------------------------------------------------
void ConferenceInfoModel::onStateChanged(linphone::ConferenceSchedulerState state){

View file

@ -52,6 +52,7 @@ public:
ConferenceInfoModel (std::shared_ptr<linphone::ConferenceInfo> conferenceInfo, QObject * parent = nullptr);
~ConferenceInfoModel ();
std::shared_ptr<linphone::ConferenceInfo> getConferenceInfo();
static std::shared_ptr<linphone::ConferenceInfo> findConferenceInfo(const std::shared_ptr<const linphone::ConferenceInfo> & conferenceInfo);
//-------------------------------
@ -82,6 +83,7 @@ public:
// Tools
Q_INVOKABLE void createConference(const int& securityLevel, const int& inviteMode);
Q_INVOKABLE void deleteConferenceInfo();// Remove completly this conference info from DB
// SCHEDULER
@ -103,6 +105,7 @@ signals:
void conferenceCreated();
void conferenceCreationFailed();
void invitationsSent();
void removed();
private:
std::shared_ptr<linphone::ConferenceInfo> mConferenceInfo;

View file

@ -63,3 +63,8 @@ bool ConferenceInfoProxyListModel::lessThan (const QModelIndex &left, const QMod
const ConferenceInfoModel* b = sourceModel()->data(right).value<ConferenceInfoModel*>();
return a->getDateTimeUtc() < b->getDateTimeUtc();
}
void ConferenceInfoProxyListModel::onRemoved(){
auto model = qobject_cast<ConferenceInfoModel*>(sender());
remove<ConferenceInfoModel*>(model);
}

View file

@ -39,6 +39,8 @@ class ConferenceInfoProxyListModel : public SortFilterAbstractProxyModel<ProxyLi
public:
ConferenceInfoProxyListModel (QObject *parent = Q_NULLPTR);
void onRemoved();
protected:
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override;

View file

@ -22,6 +22,7 @@
#include "components/call/CallModel.hpp"
#include "components/core/CoreManager.hpp"
#include "components/core/CoreHandlers.hpp"
#include "components/settings/AccountSettingsModel.hpp"
#include "ConferenceInfoMapModel.hpp"
@ -36,6 +37,7 @@ using namespace std;
ConferenceInfoProxyModel::ConferenceInfoProxyModel (QObject *parent) : SortFilterAbstractProxyModel<ConferenceInfoMapModel>(new ConferenceInfoMapModel(parent), parent) {
connect(CoreManager::getInstance()->getAccountSettingsModel(), &AccountSettingsModel::primarySipAddressChanged, this, &ConferenceInfoProxyModel::update);
connect(this, &ConferenceInfoProxyModel::filterTypeChanged, qobject_cast<ConferenceInfoMapModel*>(sourceModel()), &ConferenceInfoMapModel::filterTypeChanged);
connect(CoreManager::getInstance()->getHandlers().get(), &CoreHandlers::conferenceInfoReceived, this, &ConferenceInfoProxyModel::onConferenceInfoReceived);
setFilterType((int)Scheduled);
}
@ -61,3 +63,11 @@ bool ConferenceInfoProxyModel::filterAcceptsRow (int sourceRow, const QModelInde
}
return false;
}
void ConferenceInfoProxyModel::onConferenceInfoReceived(const std::shared_ptr<const linphone::ConferenceInfo> & conferenceInfo){
auto realConferenceInfo = ConferenceInfoModel::findConferenceInfo(conferenceInfo);
if( realConferenceInfo ){
auto model = qobject_cast<ConferenceInfoMapModel*>(sourceModel());
model->add(realConferenceInfo);
}
}

View file

@ -49,6 +49,8 @@ public:
ConferenceInfoProxyModel (QObject *parent = Q_NULLPTR);
Q_INVOKABLE void update();
void onConferenceInfoReceived(const std::shared_ptr<const linphone::ConferenceInfo> & conferenceInfo);
protected:
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override;

View file

@ -326,5 +326,5 @@ void CoreHandlers::onEcCalibrationResult(
//------------------------------ CONFERENCE INFO
void CoreHandlers::onConferenceInfoReceived(const std::shared_ptr<linphone::Core> & core, const std::shared_ptr<const linphone::ConferenceInfo> & conferenceInfo) {
qDebug() << "onConferenceInfoReceived (not implemented)";
emit conferenceInfoReceived(conferenceInfo);
}

View file

@ -58,6 +58,7 @@ signals:
void registrationStateChanged (const std::shared_ptr<linphone::Account> &account, linphone::RegistrationState state);
void ecCalibrationResult(linphone::EcCalibratorStatus status, int delayMs);
void setLastRemoteProvisioningState(const linphone::ConfiguringState &state);
void conferenceInfoReceived(const std::shared_ptr<const linphone::ConferenceInfo> & conferenceInfo);
private:
// ---------------------------------------------------------------------------

View file

@ -326,6 +326,9 @@ Loader{
isCustom: true
colorSet: ChatCalendarMessageStyle.deleteButton
backgroundRadius: width/2
onClicked: {
mainItem.conferenceInfoModel.deleteConferenceInfo()
}
}
}
}