Commit a8059a80 authored by Laurent Montel's avatar Laurent Montel 😁

Extract default selectionmodel

parent 4b7d90fa
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
set(PIM_VERSION "5.4.40") set(PIM_VERSION "5.4.41")
project(Akonadi-Contact VERSION ${PIM_VERSION}) project(Akonadi-Contact VERSION ${PIM_VERSION})
......
...@@ -161,6 +161,7 @@ set(akonadicontact_LIB_SRC ...@@ -161,6 +161,7 @@ set(akonadicontact_LIB_SRC
emailaddressselectionproxymodel.cpp emailaddressselectionproxymodel.cpp
emailaddressselectionwidget.cpp emailaddressselectionwidget.cpp
emailaddressrequester.cpp emailaddressrequester.cpp
emailaddressselectionmodel.cpp
textbrowser.cpp textbrowser.cpp
leafextensionproxymodel.cpp leafextensionproxymodel.cpp
standardcontactactionmanager.cpp standardcontactactionmanager.cpp
...@@ -277,6 +278,7 @@ ecm_generate_headers(AkonadiContact_CamelCase_HEADERS ...@@ -277,6 +278,7 @@ ecm_generate_headers(AkonadiContact_CamelCase_HEADERS
EmailAddressSelection EmailAddressSelection
EmailAddressSelectionDialog EmailAddressSelectionDialog
EmailAddressSelectionWidget EmailAddressSelectionWidget
EmailAddressSelectionModel
EmailAddressRequester EmailAddressRequester
StandardContactActionManager StandardContactActionManager
StandardContactFormatter StandardContactFormatter
......
/*
This file is part of Akonadi Contact.
Copyright (C) 2017 Laurent Montel <laurent.montel@kdab.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "emailaddressselectionmodel.h"
#include <AkonadiCore/Session>
#include <AkonadiCore/ItemFetchScope>
#include <AkonadiCore/EntityDisplayAttribute>
#include <AkonadiCore/ChangeRecorder>
#include <Akonadi/Contact/ContactsTreeModel>
#include <KContacts/Addressee>
#include <KContacts/ContactGroup>
using namespace Akonadi;
EmailAddressSelectionModel::EmailAddressSelectionModel(QObject *parent)
: QObject(parent)
{
Akonadi::Session *session = new Akonadi::Session("InternalEmailAddressSelectionWidgetModel", this);
Akonadi::ItemFetchScope scope;
scope.fetchFullPayload(true);
scope.fetchAttribute<Akonadi::EntityDisplayAttribute>();
Akonadi::ChangeRecorder *changeRecorder = new Akonadi::ChangeRecorder(this);
changeRecorder->setSession(session);
changeRecorder->fetchCollection(true);
changeRecorder->setItemFetchScope(scope);
changeRecorder->setCollectionMonitored(Akonadi::Collection::root());
changeRecorder->setMimeTypeMonitored(KContacts::Addressee::mimeType(), true);
changeRecorder->setMimeTypeMonitored(KContacts::ContactGroup::mimeType(), true);
mModel = new Akonadi::ContactsTreeModel(changeRecorder, this);
}
EmailAddressSelectionModel::~EmailAddressSelectionModel()
{
}
Akonadi::ContactsTreeModel *EmailAddressSelectionModel::model() const
{
return mModel;
}
/*
This file is part of Akonadi Contact.
Copyright (C) 2017 Laurent Montel <laurent.montel@kdab.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef EMAILADDRESSSELECTIONMODEL_H
#define EMAILADDRESSSELECTIONMODEL_H
#include <QObject>
#include "akonadi-contact_export.h"
namespace Akonadi
{
class ContactsTreeModel;
class AKONADI_CONTACT_EXPORT EmailAddressSelectionModel : public QObject
{
Q_OBJECT
public:
explicit EmailAddressSelectionModel(QObject *parent = nullptr);
~EmailAddressSelectionModel();
Akonadi::ContactsTreeModel *model() const;
private:
Akonadi::ContactsTreeModel *mModel;
};
}
#endif // EMAILADDRESSSELECTIONMODEL_H
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "emailaddressselectionwidget.h" #include "emailaddressselectionwidget.h"
#include "emailaddressselection_p.h" #include "emailaddressselection_p.h"
#include "emailaddressselectionmodel.h"
#include "emailaddressselectionproxymodel_p.h" #include "emailaddressselectionproxymodel_p.h"
#include <changerecorder.h> #include <changerecorder.h>
...@@ -104,24 +105,8 @@ void EmailAddressSelectionWidget::Private::init() ...@@ -104,24 +105,8 @@ void EmailAddressSelectionWidget::Private::init()
{ {
// setup internal model if needed // setup internal model if needed
if (!mModel) { if (!mModel) {
Akonadi::Session *session = new Akonadi::Session("InternalEmailAddressSelectionWidgetModel", q); Akonadi::EmailAddressSelectionModel *model = new Akonadi::EmailAddressSelectionModel(q);
mModel = model->model();
Akonadi::ItemFetchScope scope;
scope.fetchFullPayload(true);
scope.fetchAttribute<Akonadi::EntityDisplayAttribute>();
Akonadi::ChangeRecorder *changeRecorder = new Akonadi::ChangeRecorder(q);
changeRecorder->setSession(session);
changeRecorder->fetchCollection(true);
changeRecorder->setItemFetchScope(scope);
changeRecorder->setCollectionMonitored(Akonadi::Collection::root());
changeRecorder->setMimeTypeMonitored(KContacts::Addressee::mimeType(), true);
changeRecorder->setMimeTypeMonitored(KContacts::ContactGroup::mimeType(), true);
Akonadi::ContactsTreeModel *model = new Akonadi::ContactsTreeModel(changeRecorder, q);
// model->setCollectionFetchStrategy( Akonadi::ContactsTreeModel::InvisibleFetch );
mModel = model;
} }
// setup ui // setup ui
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment