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

akonadi/kcal

kcalmodel.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2008 Bruno Virlet <bvirlet@kdemail.net>
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 "kcalmodel.h"
00021 
00022 #include <akonadi/item.h>
00023 #include <akonadi/itemfetchjob.h>
00024 #include <akonadi/itemfetchscope.h>
00025 
00026 #include <kcal/incidence.h>
00027 #include <kcal/event.h>
00028 
00029 #include <klocale.h>
00030 #include <boost/shared_ptr.hpp>
00031 
00032 #include <kiconloader.h>
00033 #include <QtGui/QPixmap>
00034 
00035 typedef boost::shared_ptr<KCal::Incidence> IncidencePtr;
00036 
00037 using namespace Akonadi;
00038 
00039 class KCalModel::Private
00040 {
00041   public:
00042 };
00043 
00044 KCalModel::KCalModel( QObject *parent )
00045   : ItemModel( parent ),
00046     d( new Private() )
00047 {
00048   fetchScope().fetchFullPayload();
00049 }
00050 
00051 KCalModel::~KCalModel()
00052 {
00053   delete d;
00054 }
00055 
00056 int KCalModel::columnCount( const QModelIndex& ) const
00057 {
00058   return 4;
00059 }
00060 
00061 QVariant KCalModel::data( const QModelIndex &index,  int role ) const
00062 {
00063   if ( role == ItemModel::IdRole )
00064     return ItemModel::data( index, role );
00065 
00066   if ( !index.isValid() || index.row() >= rowCount() )
00067     return QVariant();
00068 
00069   const Item item = itemForIndex( index );
00070 
00071   if ( !item.hasPayload<IncidencePtr>() )
00072     return QVariant();
00073 
00074   const IncidencePtr incidence = item.payload<IncidencePtr>();
00075 
00076   // Icon for the model entry
00077   switch( role ) {
00078   case Qt::DecorationRole:
00079     if ( index.column() == 0 ) {
00080       if ( incidence->type() == "Todo" ) {
00081         return SmallIcon( QLatin1String( "view-pim-tasks" ) );
00082       } else if ( incidence->type() == "Journal" ) {
00083         return SmallIcon( QLatin1String( "view-pim-journal" ) );
00084       } else if ( incidence->type() == "Event" ) {
00085         return SmallIcon( QLatin1String( "view-pim-calendar" ) );
00086       } else {
00087         return SmallIcon( QLatin1String( "network-wired" ) );
00088       }
00089     }
00090     break;
00091   case Qt::DisplayRole:
00092     switch( index.column() ) {
00093     case Summary:
00094       return incidence->summary();
00095       break;
00096     case DateTimeStart:
00097       return incidence->dtStart().toString();
00098       break;
00099     case DateTimeEnd:
00100       return incidence->dtEnd().toString();
00101       break;
00102     case Type:
00103       return incidence->type();
00104       break;
00105     default:
00106       break;
00107     }
00108     break;
00109   default:
00110     return QVariant();
00111     break;
00112   }
00113 
00114   return QVariant();
00115 }
00116 
00117 QVariant KCalModel::headerData( int section, Qt::Orientation orientation, int role ) const
00118 {
00119   if ( role == Qt::DisplayRole && orientation == Qt::Horizontal ) {
00120     switch( section ) {
00121     case Summary:
00122       return i18nc( "@title:column, calendar event summary", "Summary" );
00123     case DateTimeStart:
00124       return i18nc( "@title:column, calendar event start date and time", "Start date and time" );
00125     case DateTimeEnd:
00126       return i18nc( "@title:column, calendar event end date and time", "End date and time" );
00127     case Type:
00128       return i18nc( "@title:column, calendar event type", "Type" );
00129     default:
00130       return QString();
00131     }
00132   }
00133 
00134   return ItemModel::headerData( section, orientation, role );
00135 }

akonadi/kcal

Skip menu "akonadi/kcal"
  • 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
  •   doc
  • 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