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

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • 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 
27 using namespace Akonadi;
28 
32 class AgentTypeModel::Private
33 {
34 public:
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 
48 void AgentTypeModel::Private::typeAdded(const AgentType &agentType)
49 {
50  mTypes.append(agentType);
51 
52  emit mParent->layoutChanged();
53 }
54 
55 void AgentTypeModel::Private::typeRemoved(const AgentType &agentType)
56 {
57  mTypes.removeAll(agentType);
58 
59  emit mParent->layoutChanged();
60 }
61 
62 AgentTypeModel::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 
72 AgentTypeModel::~AgentTypeModel()
73 {
74  delete d;
75 }
76 
77 int AgentTypeModel::columnCount(const QModelIndex &) const
78 {
79  return 1;
80 }
81 
82 int AgentTypeModel::rowCount(const QModelIndex &) const
83 {
84  return d->mTypes.count();
85 }
86 
87 QVariant 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 
130 QModelIndex 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 
143 QModelIndex AgentTypeModel::parent(const QModelIndex &) const
144 {
145  return QModelIndex();
146 }
147 
148 Qt::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"
QModelIndex
Akonadi::AgentType::icon
QIcon icon() const
Returns the icon of the agent type.
Definition: agenttype.cpp:66
Akonadi::AgentType::description
QString description() const
Returns the description of the agent type.
Definition: agenttype.cpp:56
Akonadi::AgentType::name
QString name() const
Returns the i18n'ed name of the agent type.
Definition: agenttype.cpp:51
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
Akonadi::AgentType::identifier
QString identifier() const
Returns the unique identifier of the agent type.
Definition: agenttype.cpp:46
Akonadi::AgentTypeModel::TypeRole
The agent type itself.
Definition: agenttypemodel.h:59
QModelIndex::isValid
bool isValid() const
Akonadi::AgentType
A representation of an agent type.
Definition: agenttype.h:58
Akonadi::AgentType::mimeTypes
QStringList mimeTypes() const
Returns the list of supported mime types of the agent type.
Definition: agenttype.cpp:71
Akonadi::AgentManager::instance
AgentInstance instance(const QString &identifier) const
Returns the agent instance with the given identifier or an invalid agent instance if the identifier d...
Definition: agentmanager.cpp:401
QObject
Akonadi::AgentTypeModel::IdentifierRole
The identifier of the agent type.
Definition: agenttypemodel.h:60
QModelIndex::row
int row() const
Akonadi::AgentType::capabilities
QStringList capabilities() const
Returns the list of supported capabilities of the agent type.
Definition: agenttype.cpp:76
Akonadi::AgentTypeModel::DescriptionRole
A description of the agent type.
Definition: agenttypemodel.h:61
QList
Akonadi::AgentTypeModel::AgentTypeModel
AgentTypeModel(QObject *parent=0)
Creates a new agent type model.
Definition: agenttypemodel.cpp:62
QAbstractItemModel::createIndex
QModelIndex createIndex(int row, int column, void *ptr) const
Akonadi::AgentTypeModel
Provides a data model for agent types.
Definition: agenttypemodel.h:50
QVariant::setValue
void setValue(const T &value)
Akonadi::AgentTypeModel::~AgentTypeModel
virtual ~AgentTypeModel()
Destroys the agent type model.
Definition: agenttypemodel.cpp:72
QLatin1String
Akonadi::AgentManager::types
AgentType::List types() const
Returns the list of all available agent types.
Definition: agentmanager.cpp:386
QAbstractItemModel
Akonadi::AgentManager::self
static AgentManager * self()
Returns the global instance of the agent manager.
Definition: agentmanager.cpp:377
QAbstractItemModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Akonadi::AgentTypeModel::CapabilitiesRole
A list of supported capabilities.
Definition: agenttypemodel.h:63
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const
QVariant
Qt::ItemFlags
typedef ItemFlags
Akonadi::AgentTypeModel::MimeTypesRole
A list of supported mimetypes.
Definition: agenttypemodel.h:62
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:02 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs 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

Search



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