• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.4 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 <QtGui/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  if ( index.row() < 0 || index.row() >= d->mTypes.count() )
92  return QVariant();
93 
94  const AgentType &type = d->mTypes[ index.row() ];
95 
96  switch ( role ) {
97  case Qt::DisplayRole:
98  return type.name();
99  break;
100  case Qt::DecorationRole:
101  return type.icon();
102  break;
103  case TypeRole:
104  {
105  QVariant var;
106  var.setValue( type );
107  return var;
108  }
109  break;
110  case IdentifierRole:
111  return type.identifier();
112  break;
113  case DescriptionRole:
114  return type.description();
115  break;
116  case MimeTypesRole:
117  return type.mimeTypes();
118  break;
119  case CapabilitiesRole:
120  return type.capabilities();
121  break;
122  default:
123  break;
124  }
125  return QVariant();
126 }
127 
128 QModelIndex AgentTypeModel::index( int row, int column, const QModelIndex& ) const
129 {
130  if ( row < 0 || row >= d->mTypes.count() )
131  return QModelIndex();
132 
133  if ( column != 0 )
134  return QModelIndex();
135 
136  return createIndex( row, column, 0 );
137 }
138 
139 QModelIndex AgentTypeModel::parent( const QModelIndex& ) const
140 {
141  return QModelIndex();
142 }
143 
144 Qt::ItemFlags AgentTypeModel::flags(const QModelIndex& index) const
145 {
146  if ( !index.isValid() || index.row() < 0 || index.row() >= d->mTypes.count() )
147  return QAbstractItemModel::flags( index );
148 
149  const AgentType &type = d->mTypes[ index.row() ];
150  if ( type.capabilities().contains( QLatin1String( "Unique" ) ) &&
151  AgentManager::self()->instance( type.identifier() ).isValid() )
152  {
153  return QAbstractItemModel::flags( index ) & ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
154  }
155  return QAbstractItemModel::flags(index);
156 }
157 
158 #include "agenttypemodel.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue Dec 4 2012 14:36:03 by doxygen 1.8.1.2 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.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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