File indexing completed on 2024-11-24 04:39:27

0001 /*
0002     This file is part of Akonadi Contact.
0003 
0004     SPDX-FileCopyrightText: 2017-2020 Laurent Montel <montel.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #include "emailaddressselectionmodel.h"
0010 #include <Akonadi/ChangeRecorder>
0011 #include <Akonadi/ContactsTreeModel>
0012 #include <Akonadi/EntityDisplayAttribute>
0013 #include <Akonadi/ItemFetchScope>
0014 #include <Akonadi/Session>
0015 #include <KContacts/Addressee>
0016 #include <KContacts/ContactGroup>
0017 
0018 using namespace Akonadi;
0019 
0020 EmailAddressSelectionModel::EmailAddressSelectionModel(QObject *parent)
0021     : QObject(parent)
0022 {
0023     auto session = new Akonadi::Session("InternalEmailAddressSelectionWidgetModel", this);
0024 
0025     Akonadi::ItemFetchScope scope;
0026     scope.fetchFullPayload(true);
0027     scope.fetchAttribute<Akonadi::EntityDisplayAttribute>();
0028 
0029     auto changeRecorder = new Akonadi::ChangeRecorder(this);
0030     changeRecorder->setSession(session);
0031     changeRecorder->fetchCollection(true);
0032     changeRecorder->setItemFetchScope(scope);
0033     changeRecorder->setCollectionMonitored(Akonadi::Collection::root());
0034     changeRecorder->setMimeTypeMonitored(KContacts::Addressee::mimeType(), true);
0035     changeRecorder->setMimeTypeMonitored(KContacts::ContactGroup::mimeType(), true);
0036 
0037     mModel = new Akonadi::ContactsTreeModel(changeRecorder, this);
0038 }
0039 
0040 EmailAddressSelectionModel::~EmailAddressSelectionModel() = default;
0041 
0042 Akonadi::ContactsTreeModel *EmailAddressSelectionModel::model() const
0043 {
0044     return mModel;
0045 }
0046 
0047 #include "moc_emailaddressselectionmodel.cpp"