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

akonadi

  • akonadi
agenttypemodel.cpp
1/*
2 Copyright (c) 2006 Tobias Koenig <tokoe@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 "agenttypemodel.h"
21#include "agenttype.h"
22#include "agentmanager.h"
23
24#include <QtCore/QStringList>
25#include <QIcon>
26
27using namespace Akonadi;
28
32class AgentTypeModel::Private
33{
34public:
35 Private(AgentTypeModel *parent)
36 : mParent(parent)
37 {
38 mTypes = AgentManager::self()->types();
39 }
40
41 AgentTypeModel *mParent;
42 AgentType::List mTypes;
43
44 void typeAdded(const AgentType &agentType);
45 void typeRemoved(const AgentType &agentType);
46};
47
48void AgentTypeModel::Private::typeAdded(const AgentType &agentType)
49{
50 mTypes.append(agentType);
51
52 emit mParent->layoutChanged();
53}
54
55void AgentTypeModel::Private::typeRemoved(const AgentType &agentType)
56{
57 mTypes.removeAll(agentType);
58
59 emit mParent->layoutChanged();
60}
61
62AgentTypeModel::AgentTypeModel(QObject *parent)
63 : QAbstractItemModel(parent)
64 , d(new Private(this))
65{
66 connect(AgentManager::self(), SIGNAL(typeAdded(Akonadi::AgentType)),
67 this, SLOT(typeAdded(Akonadi::AgentType)));
68 connect(AgentManager::self(), SIGNAL(typeRemoved(Akonadi::AgentType)),
69 this, SLOT(typeRemoved(Akonadi::AgentType)));
70}
71
72AgentTypeModel::~AgentTypeModel()
73{
74 delete d;
75}
76
77int AgentTypeModel::columnCount(const QModelIndex &) const
78{
79 return 1;
80}
81
82int AgentTypeModel::rowCount(const QModelIndex &) const
83{
84 return d->mTypes.count();
85}
86
87QVariant AgentTypeModel::data(const QModelIndex &index, int role) const
88{
89 if (!index.isValid()) {
90 return QVariant();
91 }
92
93 if (index.row() < 0 || index.row() >= d->mTypes.count()) {
94 return QVariant();
95 }
96
97 const AgentType &type = d->mTypes[index.row()];
98
99 switch (role) {
100 case Qt::DisplayRole:
101 return type.name();
102 break;
103 case Qt::DecorationRole:
104 return type.icon();
105 break;
106 case TypeRole: {
107 QVariant var;
108 var.setValue(type);
109 return var;
110 break;
111 }
112 case IdentifierRole:
113 return type.identifier();
114 break;
115 case DescriptionRole:
116 return type.description();
117 break;
118 case MimeTypesRole:
119 return type.mimeTypes();
120 break;
121 case CapabilitiesRole:
122 return type.capabilities();
123 break;
124 default:
125 break;
126 }
127 return QVariant();
128}
129
130QModelIndex AgentTypeModel::index(int row, int column, const QModelIndex &) const
131{
132 if (row < 0 || row >= d->mTypes.count()) {
133 return QModelIndex();
134 }
135
136 if (column != 0) {
137 return QModelIndex();
138 }
139
140 return createIndex(row, column);
141}
142
143QModelIndex AgentTypeModel::parent(const QModelIndex &) const
144{
145 return QModelIndex();
146}
147
148Qt::ItemFlags AgentTypeModel::flags(const QModelIndex &index) const
149{
150 if (!index.isValid() || index.row() < 0 || index.row() >= d->mTypes.count()) {
151 return QAbstractItemModel::flags(index);
152 }
153
154 const AgentType &type = d->mTypes[index.row()];
155 if (type.capabilities().contains(QLatin1String("Unique")) &&
156 AgentManager::self()->instance(type.identifier()).isValid()) {
157 return QAbstractItemModel::flags(index) &~(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
158 }
159 return QAbstractItemModel::flags(index);
160}
161
162#include "moc_agenttypemodel.cpp"
Akonadi::AgentManager::types
AgentType::List types() const
Returns the list of all available agent types.
Definition: agentmanager.cpp:386
Akonadi::AgentManager::self
static AgentManager * self()
Returns the global instance of the agent manager.
Definition: agentmanager.cpp:377
Akonadi::AgentTypeModel
Provides a data model for agent types.
Definition: agenttypemodel.h:51
Akonadi::AgentTypeModel::~AgentTypeModel
virtual ~AgentTypeModel()
Destroys the agent type model.
Definition: agenttypemodel.cpp:72
Akonadi::AgentTypeModel::AgentTypeModel
AgentTypeModel(QObject *parent=0)
Creates a new agent type model.
Definition: agenttypemodel.cpp:62
Akonadi::AgentTypeModel::MimeTypesRole
@ MimeTypesRole
A list of supported mimetypes.
Definition: agenttypemodel.h:62
Akonadi::AgentTypeModel::TypeRole
@ TypeRole
The agent type itself.
Definition: agenttypemodel.h:59
Akonadi::AgentTypeModel::IdentifierRole
@ IdentifierRole
The identifier of the agent type.
Definition: agenttypemodel.h:60
Akonadi::AgentTypeModel::DescriptionRole
@ DescriptionRole
A description of the agent type.
Definition: agenttypemodel.h:61
Akonadi::AgentTypeModel::CapabilitiesRole
@ CapabilitiesRole
A list of supported capabilities.
Definition: agenttypemodel.h:63
Akonadi::AgentType
A representation of an agent type.
Definition: agenttype.h:59
Akonadi::AgentType::List
QList< AgentType > List
Describes a list of agent types.
Definition: agenttype.h:67
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