Akonadi Calendar

calfilterpartstatusproxymodel.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Sandro Knauß <knauss@kolabsys.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "calfilterpartstatusproxymodel.h"
8#include "akonadicalendar_debug.h"
9#include "calendarutils.h"
10#include "utils_p.h"
11
12#include <Akonadi/Collection>
13#include <Akonadi/EntityTreeModel>
14#include <Akonadi/Item>
15
16#include <KCalendarCore/Incidence>
17// #include <email.h>
18
19#include <KIdentityManagementCore/IdentityManager>
20
21using namespace Akonadi;
22
23class Akonadi::CalFilterPartStatusProxyModelPrivate
24{
25public:
26 explicit CalFilterPartStatusProxyModelPrivate()
27 : mIdentityManager(KIdentityManagementCore::IdentityManager::self())
28 {
29 }
30
32 KIdentityManagementCore::IdentityManager *const mIdentityManager;
33 bool mFilterVirtual = false;
34};
35
36void CalFilterPartStatusProxyModel::slotIdentitiesChanged()
37{
39}
40
41CalFilterPartStatusProxyModel::CalFilterPartStatusProxyModel(QObject *parent)
42 : QSortFilterProxyModel(parent)
43 , d(new CalFilterPartStatusProxyModelPrivate())
44{
45 QObject::connect(d->mIdentityManager, qOverload<>(&KIdentityManagementCore::IdentityManager::changed), this, [this]() {
46 slotIdentitiesChanged();
47 });
48}
49
50CalFilterPartStatusProxyModel::~CalFilterPartStatusProxyModel() = default;
51
52const QList<KCalendarCore::Attendee::PartStat> &CalFilterPartStatusProxyModel::blockedStatusList() const
53{
54 return d->mBlockedStatusList;
55}
56
57void CalFilterPartStatusProxyModel::setBlockedStatusList(const QList<KCalendarCore::Attendee::PartStat> &blockStatusList)
58{
59 if (d->mBlockedStatusList != blockStatusList) {
60 d->mBlockedStatusList = blockStatusList;
62 }
63}
64
65bool CalFilterPartStatusProxyModel::filterVirtual() const
66{
67 return d->mFilterVirtual;
68}
69
70void CalFilterPartStatusProxyModel::setFilterVirtual(bool filterVirtual)
71{
72 if (d->mFilterVirtual != filterVirtual) {
73 d->mFilterVirtual = filterVirtual;
75 }
76}
77
78bool CalFilterPartStatusProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
79{
80 const QModelIndex idx = sourceModel()->index(source_row, 0, source_parent);
81 if (!idx.isValid()) {
82 return false;
83 }
84
86 // If it's not an item, accept it: it's not our business to filter out collections...
87 if (!item.isValid()) {
88 return true;
89 }
90
92 if (!incidence) {
93 return false;
94 }
95
96 // Incidences from virtual collections are always ok
98 if (!d->mFilterVirtual && col.isVirtual()) {
99 return true;
100 }
101
102 // always show if we are the organizer
103 if (CalendarUtils::thatIsMe(incidence->organizer().email())) {
104 return true;
105 }
106
107 const auto attendees = incidence->attendees();
108 for (const KCalendarCore::Attendee &attendee : attendees) {
109 if (CalendarUtils::thatIsMe(attendee)) {
110 return !d->mBlockedStatusList.contains(attendee.status());
111 }
112 }
113
114 // We are not attendee, so we accept the incidence
115 return true;
116}
117
118#include "moc_calfilterpartstatusproxymodel.cpp"
AKONADI_CALENDAR_EXPORT KCalendarCore::Incidence::Ptr incidence(const Akonadi::Item &item)
Returns the incidence from an Akonadi item, or a null pointer if the item has no such payload.
FreeBusyManager::Singleton.
QVariant data(int role) const const
bool isValid() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
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:14:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.