~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/clients/akonablog/blogmodel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Harald Sitter
  • Date: 2009-06-27 04:40:05 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090627044005-4y2vm9xz7rvmzi4p
Tags: 4:4.2.95svn20090701-0ubuntu1
[ Alessandro Ghersi ]
* New upstream release
  - Bump build-deps
* Remove akonadi-kde and libmaildir4 packages
  - remove akonadi-kde.install and libmaildir4.install
  - remove libmaildir4 from debian/rules
  - remove akonadi-kde and libmaildir4 from depends
  - remove akonadi-kde and libmaildir4 from installgen
* Update kdepim-dev.install
* Update kpilot.install
* Add akonadi-kde and libmaildir4 transitional packages

[ Harald Sitter ]
* KAddressbook replaces Kontact << 4.2.85 (LP: #378373)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2006 Volker Krause <vkrause@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 "blogmodel.h"
 
21
 
 
22
#include <microblog/statusitem.h>
 
23
#include <akonadi/itemfetchscope.h>
 
24
#include <akonadi/monitor.h>
 
25
#include <akonadi/session.h>
 
26
 
 
27
#include <kdebug.h>
 
28
#include <kglobal.h>
 
29
#include <klocale.h>
 
30
#include <kio/job.h>
 
31
 
 
32
#include <QtCore/QDebug>
 
33
 
 
34
using namespace Akonadi;
 
35
using namespace Microblog;
 
36
 
 
37
class BlogModel::Private
 
38
{
 
39
public:
 
40
};
 
41
 
 
42
BlogModel::BlogModel( QObject *parent ) :
 
43
        ItemModel( parent ),
 
44
        d( new Private() )
 
45
{
 
46
    fetchScope().fetchFullPayload();
 
47
}
 
48
 
 
49
BlogModel::~BlogModel( )
 
50
{
 
51
    delete d;
 
52
}
 
53
 
 
54
int BlogModel::columnCount( const QModelIndex & parent ) const
 
55
{
 
56
    if ( !parent.isValid() )
 
57
        return 1;
 
58
 
 
59
    return 0;
 
60
}
 
61
 
 
62
QVariant BlogModel::data( const QModelIndex & index, int role ) const
 
63
{
 
64
    if ( role != Qt::DisplayRole && role != Qt::EditRole && role < Qt::UserRole )
 
65
        return QVariant();
 
66
 
 
67
    if ( !index.isValid() )
 
68
        return QVariant();
 
69
 
 
70
    if ( index.row() >= rowCount() )
 
71
        return QVariant();
 
72
 
 
73
    Item item = itemForIndex( index );
 
74
    if ( !item.hasPayload<StatusItem>() )
 
75
        return QVariant();
 
76
 
 
77
    StatusItem msg = item.payload<StatusItem>();
 
78
    Collection col = collection();
 
79
 
 
80
    if ( role == Qt::EditRole ) {
 
81
        return msg.date();
 
82
    }
 
83
 
 
84
    if ( role == Qt::DisplayRole )
 
85
        return msg.id();
 
86
 
 
87
    switch ( role ) {
 
88
    case Date:
 
89
        return msg.date().toString();
 
90
    case User:
 
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" );
 
99
            else
 
100
                return QVariant();
 
101
        }
 
102
    case Text:
 
103
        return msg.text();
 
104
    case Picture:
 
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" );
 
113
            else
 
114
                return QVariant();
 
115
        }
 
116
    default:
 
117
        return QVariant();
 
118
    }
 
119
 
 
120
    return ItemModel::data( index, role );
 
121
}
 
122
 
 
123
QVariant BlogModel::headerData( int section, Qt::Orientation orientation, int role ) const
 
124
{
 
125
    if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) {
 
126
        return i18nc( "@title:column, item id", "Blogs by date" );
 
127
    }
 
128
    return ItemModel::headerData( section, orientation, role );
 
129
}
 
130
 
 
131
#include "blogmodel.moc"