• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
agentfilterproxymodel.cpp
1/*
2 Copyright (c) 2007 Volker Krause <vkrause@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "agentfilterproxymodel.h"
21
22#include "agenttypemodel.h"
23#include "agentinstancemodel.h"
24
25#include <kdebug.h>
26#include <kmimetype.h>
27
28#include <QtCore/QStringList>
29
30#include <boost/static_assert.hpp>
31
32using namespace Akonadi;
33
34// ensure the role numbers are equivalent for both source models
35BOOST_STATIC_ASSERT((int)AgentTypeModel::CapabilitiesRole == (int)AgentInstanceModel::CapabilitiesRole);
36BOOST_STATIC_ASSERT((int)AgentTypeModel::MimeTypesRole == (int)AgentInstanceModel::MimeTypesRole);
37
41class AgentFilterProxyModel::Private
42{
43public:
44 QStringList mimeTypes;
45 QStringList capabilities;
46 QStringList excludeCapabilities;
47 bool filterAcceptRegExp(const QModelIndex &index, const QRegExp &filterRegExpStr);
48};
49
50AgentFilterProxyModel::AgentFilterProxyModel(QObject *parent)
51 : QSortFilterProxyModel(parent)
52 , d(new Private)
53{
54 setDynamicSortFilter(true);
55}
56
57AgentFilterProxyModel::~AgentFilterProxyModel()
58{
59 delete d;
60}
61
62void AgentFilterProxyModel::addMimeTypeFilter(const QString &mimeType)
63{
64 d->mimeTypes << mimeType;
65 invalidateFilter();
66}
67
68void AgentFilterProxyModel::addCapabilityFilter(const QString &capability)
69{
70 d->capabilities << capability;
71 invalidateFilter();
72}
73
74void AgentFilterProxyModel::excludeCapabilities(const QString &capability)
75{
76 d->excludeCapabilities << capability;
77 invalidateFilter();
78}
79
80void AgentFilterProxyModel::clearFilters()
81{
82 d->capabilities.clear();
83 d->mimeTypes.clear();
84 d->excludeCapabilities.clear();
85 invalidateFilter();
86}
87
88bool AgentFilterProxyModel::Private::filterAcceptRegExp(const QModelIndex &index, const QRegExp &filterRegExpStr)
89{
90 // First see if the name matches a set regexp filter.
91 if (!filterRegExpStr.isEmpty()) {
92 if (index.data(AgentTypeModel::IdentifierRole).toString().contains(filterRegExpStr)) {
93 return true;
94 } else if (index.data().toString().contains(filterRegExpStr)) {
95 return true;
96 } else {
97 return false;
98 }
99 }
100 return true;
101}
102
103bool AgentFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &) const
104{
105 const QModelIndex index = sourceModel()->index(row, 0);
106
107 if (!d->mimeTypes.isEmpty()) {
108 bool found = false;
109 foreach (const QString &mimeType, index.data(AgentTypeModel::MimeTypesRole).toStringList()) {
110 if (d->mimeTypes.contains(mimeType)) {
111 found = true;
112 } else {
113 KMimeType::Ptr mimeTypePtr = KMimeType::mimeType(mimeType, KMimeType::ResolveAliases);
114 if (!mimeTypePtr.isNull()) {
115 foreach (const QString &type, d->mimeTypes) {
116 if (mimeTypePtr->is(type)) {
117 found = true;
118 break;
119 }
120 }
121 }
122 }
123
124 if (found) {
125 break;
126 }
127 }
128
129 if (!found) {
130 return false;
131 }
132 }
133
134 if (!d->capabilities.isEmpty()) {
135 bool found = false;
136 foreach (const QString &capability, index.data(AgentTypeModel::CapabilitiesRole).toStringList()) {
137 if (d->capabilities.contains(capability)) {
138 found = true;
139 break;
140 }
141 }
142
143 if (!found) {
144 return false;
145 }
146
147 if (found && !d->excludeCapabilities.isEmpty()) {
148 foreach (const QString &capability, index.data(AgentTypeModel::CapabilitiesRole).toStringList()) {
149 if (d->excludeCapabilities.contains(capability)) {
150 found = false;
151 break;
152 }
153 }
154
155 if (!found) {
156 return false;
157 }
158 }
159 }
160
161 return d->filterAcceptRegExp(index, filterRegExp());
162}
Akonadi::AgentFilterProxyModel::AgentFilterProxyModel
AgentFilterProxyModel(QObject *parent=0)
Create a new agent filter proxy model.
Definition: agentfilterproxymodel.cpp:50
Akonadi::AgentFilterProxyModel::~AgentFilterProxyModel
~AgentFilterProxyModel()
Destroys the agent filter proxy model.
Definition: agentfilterproxymodel.cpp:57
Akonadi::AgentFilterProxyModel::addMimeTypeFilter
void addMimeTypeFilter(const QString &mimeType)
Accept agents supporting mimeType.
Definition: agentfilterproxymodel.cpp:62
Akonadi::AgentFilterProxyModel::addCapabilityFilter
void addCapabilityFilter(const QString &capability)
Accept agents with the given capability.
Definition: agentfilterproxymodel.cpp:68
Akonadi::AgentFilterProxyModel::excludeCapabilities
void excludeCapabilities(const QString &capability)
Excludes agents with the given capability.
Definition: agentfilterproxymodel.cpp:74
Akonadi::AgentFilterProxyModel::clearFilters
void clearFilters()
Clear the filters ( mimeTypes & capabilities ).
Definition: agentfilterproxymodel.cpp:80
Akonadi::AgentInstanceModel::MimeTypesRole
@ MimeTypesRole
A list of supported mimetypes.
Definition: agentinstancemodel.h:62
Akonadi::AgentInstanceModel::CapabilitiesRole
@ CapabilitiesRole
A list of supported capabilities.
Definition: agentinstancemodel.h:63
Akonadi::AgentTypeModel::MimeTypesRole
@ MimeTypesRole
A list of supported mimetypes.
Definition: agenttypemodel.h:62
Akonadi::AgentTypeModel::IdentifierRole
@ IdentifierRole
The identifier of the agent type.
Definition: agenttypemodel.h:60
Akonadi::AgentTypeModel::CapabilitiesRole
@ CapabilitiesRole
A list of supported capabilities.
Definition: agenttypemodel.h:63
Akonadi
FreeBusyManager::Singleton.
Definition: actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal