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

akonadi

  • sources
  • kde-4.12
  • 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 ), d( new Private( this ) )
64 {
65  connect( AgentManager::self(), SIGNAL(typeAdded(Akonadi::AgentType)),
66  this, SLOT(typeAdded(Akonadi::AgentType)) );
67  connect( AgentManager::self(), SIGNAL(typeRemoved(Akonadi::AgentType)),
68  this, SLOT(typeRemoved(Akonadi::AgentType)) );
69 }
70 
71 AgentTypeModel::~AgentTypeModel()
72 {
73  delete d;
74 }
75 
76 int AgentTypeModel::columnCount( const QModelIndex& ) const
77 {
78  return 1;
79 }
80 
81 int AgentTypeModel::rowCount( const QModelIndex& ) const
82 {
83  return d->mTypes.count();
84 }
85 
86 QVariant AgentTypeModel::data( const QModelIndex &index, int role ) const
87 {
88  if ( !index.isValid() ) {
89  return QVariant();
90  }
91 
92  if ( index.row() < 0 || index.row() >= d->mTypes.count() ) {
93  return QVariant();
94  }
95 
96  const AgentType &type = d->mTypes[ index.row() ];
97 
98  switch ( role ) {
99  case Qt::DisplayRole:
100  return type.name();
101  break;
102  case Qt::DecorationRole:
103  return type.icon();
104  break;
105  case TypeRole:
106  {
107  QVariant var;
108  var.setValue( type );
109  return var;
110  }
111  break;
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"
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
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
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:404
Akonadi::AgentType::List
QList< AgentType > List
Describes a list of agent types.
Definition: agenttype.h:67
Akonadi::AgentTypeModel::IdentifierRole
The identifier of the agent type.
Definition: agenttypemodel.h:60
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
Akonadi::AgentTypeModel::AgentTypeModel
AgentTypeModel(QObject *parent=0)
Creates a new agent type model.
Definition: agenttypemodel.cpp:62
Akonadi::AgentTypeModel
Provides a data model for agent types.
Definition: agenttypemodel.h:50
Akonadi::AgentTypeModel::~AgentTypeModel
virtual ~AgentTypeModel()
Destroys the agent type model.
Definition: agenttypemodel.cpp:71
Akonadi::AgentManager::types
AgentType::List types() const
Returns the list of all available agent types.
Definition: agentmanager.cpp:389
Akonadi::AgentManager::self
static AgentManager * self()
Returns the global instance of the agent manager.
Definition: agentmanager.cpp:380
Akonadi::AgentTypeModel::CapabilitiesRole
A list of supported capabilities.
Definition: agenttypemodel.h:63
Akonadi::AgentTypeModel::MimeTypesRole
A list of supported mimetypes.
Definition: agenttypemodel.h:62
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:26 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
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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