/* * Copyright (c) 2010-2024 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 "LdapList.hpp" #include "LdapGui.hpp" #include "core/App.hpp" #include "model/object/VariantObject.hpp" #include #include // ============================================================================= DEFINE_ABSTRACT_OBJECT(LdapList) QSharedPointer LdapList::create() { auto model = QSharedPointer(new LdapList(), &QObject::deleteLater); model->moveToThread(App::getInstance()->thread()); model->setSelf(model); return model; } QSharedPointer LdapList::createLdapCore(const std::shared_ptr &ldap) { auto LdapCore = LdapCore::create(ldap); return LdapCore; } LdapList::LdapList(QObject *parent) : ListProxy(parent) { mustBeInMainThread(getClassName()); } LdapList::~LdapList() { mustBeInMainThread("~" + getClassName()); mModelConnection = nullptr; } void LdapList::setSelf(QSharedPointer me) { mModelConnection = QSharedPointer>( new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); mModelConnection->makeConnectToCore(&LdapList::lUpdate, [this]() { mModelConnection->invokeToModel([this]() { QList> *ldaps = new QList>(); mustBeInLinphoneThread(getClassName()); for (auto ldap : CoreModel::getInstance()->getCore()->getLdapList()) { auto model = createLdapCore(ldap); ldaps->push_back(model); } mModelConnection->invokeToCore([this, ldaps]() { mustBeInMainThread(getClassName()); resetData(); add(*ldaps); delete ldaps; }); }); }); emit lUpdate(); } void LdapList::removeAllEntries() { beginResetModel(); for (auto it = mList.rbegin(); it != mList.rend(); ++it) { auto ldap = it->objectCast(); ldap->remove(); } mList.clear(); endResetModel(); } void LdapList::remove(const int &row) { beginRemoveRows(QModelIndex(), row, row); auto item = mList[row].objectCast(); item->remove(); mList.takeAt(row); endRemoveRows(); } QVariant LdapList::data(const QModelIndex &index, int role) const { int row = index.row(); if (!index.isValid() || row < 0 || row >= mList.count()) return QVariant(); if (role == Qt::DisplayRole) { return QVariant::fromValue(new LdapGui(mList[row].objectCast())); } return QVariant(); }