/*
* Copyright (c) 2021 Belledonne Communications SARL.
*
* This file is part of linphone-desktop
* (see https://www.linphone.org).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "ConferenceInfoProxyListModel.hpp"
#include "components/call/CallModel.hpp"
#include "components/core/CoreManager.hpp"
#include "ConferenceInfoListModel.hpp"
#include "ConferenceInfoMapModel.hpp"
#include "utils/Utils.hpp"
// =============================================================================
using namespace std;
//---------------------------------------------------------------------------------------------
ConferenceInfoProxyListModel::ConferenceInfoProxyListModel (QObject *parent) : SortFilterAbstractProxyModel(new ConferenceInfoListModel(parent), parent) {
//setFilterType(0);
//connect(this, &ConferenceInfoProxyListModel::filterTypeChanged, qobject_cast(sourceModel()), &ConferenceInfoListModel::filterTypeChanged);
}
bool ConferenceInfoProxyListModel::filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const {
auto listModel = qobject_cast(sourceModel());
if(listModel){
QModelIndex index = listModel->index(sourceRow, 0, QModelIndex());
const ConferenceInfoModel* ics = sourceModel()->data(index).value();
if(ics){
QDateTime currentDateTime = QDateTime::currentDateTime();
if( mFilterType == 0){
return ics->getEndDateTime() < currentDateTime;
}else if( mFilterType == 1){
return ics->getEndDateTime() >= currentDateTime;
}else if( mFilterType == 2){
return !Utils::isMe(ics->getOrganizer());
}else
return mFilterType == -1;
}
}
return true;
/*
bool show = false;
QModelIndex index = sourceModel()->index(sourceRow, 0, QModelIndex());
const ConferenceInfoListModel* ics = sourceModel()->data(index).value();
if( mEntryTypeFilter == ConferenceType::Ended && ics->eventModel.value() != nullptr)
show = true;
else if( mEntryTypeFilter == ChatRoomModel::EntryType::MessageEntry && eventModel.value() != nullptr)
show = true;
else if( mEntryTypeFilter == ChatRoomModel::EntryType::NoticeEntry && eventModel.value() != nullptr)
show = true;
}
if( show && mFilterText != ""){
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
auto eventModel = sourceModel()->data(index);
ChatMessageModel * chatModel = eventModel.value();
if( chatModel){
QRegularExpression search(QRegularExpression::escape(mFilterText), QRegularExpression::CaseInsensitiveOption | QRegularExpression::UseUnicodePropertiesOption);
show = chatModel->mContent.contains(search);
}
}
return show;*/
}
bool ConferenceInfoProxyListModel::lessThan (const QModelIndex &left, const QModelIndex &right) const {
return true;
/*
const ConferenceInfoListModel* deviceA = sourceModel()->data(left).value();
const ConferenceInfoListModel* deviceB = sourceModel()->data(right).value();
return deviceA->getAt(0)->getDateTime() < deviceB->getAt(0)->getDateTime();
*/
}
/*
QVariant ConferenceInfoProxyModel::getAt(int row){
QModelIndex sourceIndex = mapToSource(this->index(row, 0));
return sourceModel()->data(sourceIndex);
}
void ConferenceInfoProxyModel::add(QSharedPointer conferenceInfoModel){
qobject_cast(sourceModel())->add(conferenceInfoModel);
}*/