Mailcommon

favoritecollectionorderproxymodel.cpp
1/*
2
3 SPDX-FileCopyrightText: 2017 David Faure <faure@kde.org>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#include "favoritecollectionorderproxymodel.h"
9#include <Akonadi/AccountActivitiesAbstract>
10#include <Akonadi/AgentManager>
11#include <Akonadi/Collection>
12#include <Akonadi/EntityTreeModel>
13using namespace MailCommon;
14
15FavoriteCollectionOrderProxyModel::FavoriteCollectionOrderProxyModel(QObject *parent)
16 : EntityOrderProxyModel(parent)
17{
18}
19
20FavoriteCollectionOrderProxyModel::~FavoriteCollectionOrderProxyModel() = default;
21
22Akonadi::Collection FavoriteCollectionOrderProxyModel::parentCollection(const QModelIndex &index) const
23{
24 Q_UNUSED(index)
25 return {};
26}
27
28void FavoriteCollectionOrderProxyModel::setAccountActivities(Akonadi::AccountActivitiesAbstract *accountActivities)
29{
30 if (mAccountActivities) {
31 disconnect(mAccountActivities, &Akonadi::AccountActivitiesAbstract::activitiesChanged, this, &FavoriteCollectionOrderProxyModel::invalidateFilter);
32 }
33 mAccountActivities = accountActivities;
34 connect(mAccountActivities, &Akonadi::AccountActivitiesAbstract::activitiesChanged, this, &FavoriteCollectionOrderProxyModel::invalidateFilter);
36}
37
38bool FavoriteCollectionOrderProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
39{
40 if (mAccountActivities) {
41 const QModelIndex modelIndex = sourceModel()->index(sourceRow, 0, sourceParent);
42
44 const Akonadi::AgentInstance instance = Akonadi::AgentManager::self()->instance(collection.resource());
45 if (instance.activitiesEnabled()) {
46 return mAccountActivities->filterAcceptsRow(instance.activities());
47 }
48 }
49 return Akonadi::EntityOrderProxyModel::filterAcceptsColumn(sourceRow, sourceParent);
50}
51
52#include "moc_favoritecollectionorderproxymodel.cpp"
static AgentManager * self()
AgentInstance instance(const QString &identifier) const
The filter dialog.
QVariant data(int role) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
virtual bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.