2
Copyright (c) 2006 Volker Krause <vkrause@kde.org>
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.
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.
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
20
#include "blogmodel.h"
22
#include <microblog/statusitem.h>
23
#include <akonadi/itemfetchscope.h>
24
#include <akonadi/monitor.h>
25
#include <akonadi/session.h>
32
#include <QtCore/QDebug>
34
using namespace Akonadi;
35
using namespace Microblog;
37
class BlogModel::Private
42
BlogModel::BlogModel( QObject *parent ) :
46
fetchScope().fetchFullPayload();
49
BlogModel::~BlogModel( )
54
int BlogModel::columnCount( const QModelIndex & parent ) const
56
if ( !parent.isValid() )
62
QVariant BlogModel::data( const QModelIndex & index, int role ) const
64
if ( role != Qt::DisplayRole && role != Qt::EditRole && role < Qt::UserRole )
67
if ( !index.isValid() )
70
if ( index.row() >= rowCount() )
73
Item item = itemForIndex( index );
74
if ( !item.hasPayload<StatusItem>() )
77
StatusItem msg = item.payload<StatusItem>();
78
Collection col = collection();
80
if ( role == Qt::EditRole ) {
84
if ( role == Qt::DisplayRole )
89
return msg.date().toString();
91
if ( role == Qt::UserRole+1 ) {
92
if ( col.remoteId() == "home" || col.remoteId() == "replies" ||
93
col.remoteId() == "favorites" )
94
return msg.value( "user_-_screen_name" );
95
else if ( col.remoteId() == "inbox" )
96
return msg.value( "sender_screen_name" );
97
else if ( col.remoteId() == "outbox" )
98
return msg.value( "recipient_screen_name" );
105
if ( role == Qt::UserRole+3 ) {
106
if ( col.remoteId() == "home" || col.remoteId() == "replies" ||
107
col.remoteId() == "favorites" )
108
return msg.value( "user_-_profile_image_url" );
109
else if ( col.remoteId() == "inbox" )
110
return msg.value( "sender_-_profile_image_url" );
111
else if ( col.remoteId() == "outbox" )
112
return msg.value( "recipient_-_profile_image_url" );
120
return ItemModel::data( index, role );
123
QVariant BlogModel::headerData( int section, Qt::Orientation orientation, int role ) const
125
if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) {
126
return i18nc( "@title:column, item id", "Blogs by date" );
128
return ItemModel::headerData( section, orientation, role );
131
#include "blogmodel.moc"