• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

akonadi/kabc

kabcmodel.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2007 Tobias Koenig <tokoe@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "kabcmodel.h"
00021 
00022 #include <kabc/addressee.h>
00023 #include <akonadi/item.h>
00024 #include <akonadi/itemfetchjob.h>
00025 #include <akonadi/itemfetchscope.h>
00026 
00027 using namespace Akonadi;
00028 
00029 class KABCModel::Private
00030 {
00031   public:
00032 };
00033 
00034 KABCModel::KABCModel( QObject *parent )
00035   : Akonadi::ItemModel( parent ),
00036     d( new Private() )
00037 {
00038   fetchScope().fetchFullPayload();
00039 }
00040 
00041 KABCModel::~KABCModel()
00042 {
00043   delete d;
00044 }
00045 
00046 int KABCModel::columnCount( const QModelIndex& ) const
00047 {
00048   return 3;
00049 }
00050 
00051 QVariant KABCModel::data( const QModelIndex &index, int role ) const
00052 {
00053   if ( role == ItemModel::IdRole )
00054     return ItemModel::data( index, role );
00055 
00056   if ( role != Qt::DisplayRole )
00057     return QVariant();
00058 
00059   if ( !index.isValid() )
00060     return QVariant();
00061 
00062   if ( index.row() >= rowCount() )
00063     return QVariant();
00064 
00065   const Item item = itemForIndex( index );
00066 
00067   if ( !item.hasPayload<KABC::Addressee>() )
00068     return QVariant();
00069 
00070   const KABC::Addressee addr = item.payload<KABC::Addressee>();
00071   switch ( index.column() ) {
00072     case 0:
00073       return addr.givenName();
00074       break;
00075     case 1:
00076       return addr.familyName();
00077       break;
00078     case 2:
00079       return addr.preferredEmail();
00080       break;
00081     default:
00082       break;
00083   }
00084 
00085   return QVariant();
00086 }
00087 
00088 QVariant KABCModel::headerData( int section, Qt::Orientation orientation, int role ) const
00089 {
00090   if ( role != Qt::DisplayRole )
00091     return QVariant();
00092 
00093   if ( orientation != Qt::Horizontal )
00094     return QVariant();
00095 
00096   switch ( section ) {
00097     case 0:
00098       return KABC::Addressee::givenNameLabel();
00099       break;
00100     case 1:
00101       return KABC::Addressee::familyNameLabel();
00102       break;
00103     case 2:
00104       return KABC::Addressee::emailLabel();
00105       break;
00106     default:
00107       break;
00108   }
00109 
00110   return QVariant();
00111 }

akonadi/kabc

Skip menu "akonadi/kabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal