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

« back to all changes in this revision

Viewing changes to kcontactmanager/contactstreemodel.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
 
    This file is part of KContactManager.
3
 
 
4
 
    Copyright (c) 2009 Stephen Kelly <steveire@gmail.com>
5
 
    Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
6
 
 
7
 
    This program is free software; you can redistribute it and/or modify
8
 
    it under the terms of the GNU General Public License as published by
9
 
    the Free Software Foundation; either version 2 of the License, or
10
 
    (at your option) any later version.
11
 
 
12
 
    This program is distributed in the hope that it will be useful,
13
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 
    GNU General Public License for more details.
16
 
 
17
 
    You should have received a copy of the GNU General Public License along
18
 
    with this program; if not, write to the Free Software Foundation, Inc.,
19
 
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 
*/
21
 
 
22
 
#include "contactstreemodel.h"
23
 
 
24
 
#include <kabc/addressee.h>
25
 
#include <kabc/contactgroup.h>
26
 
#include <kicon.h>
27
 
#include <klocale.h>
28
 
 
29
 
using namespace Akonadi;
30
 
 
31
 
ContactsTreeModel::ContactsTreeModel( Session *session, Monitor *monitor, QObject *parent )
32
 
  : EntityTreeModel( session, monitor, parent )
33
 
{
34
 
}
35
 
 
36
 
ContactsTreeModel::~ContactsTreeModel()
37
 
{
38
 
}
39
 
 
40
 
QVariant ContactsTreeModel::getData( const Item &item, int column, int role ) const
41
 
{
42
 
  if ( item.mimeType() == KABC::Addressee::mimeType() ) {
43
 
    if ( !item.hasPayload<KABC::Addressee>() ) {
44
 
 
45
 
      // Pass modeltest
46
 
      if ( role == Qt::DisplayRole )
47
 
        return item.remoteId();
48
 
 
49
 
      return QVariant();
50
 
    }
51
 
 
52
 
    const KABC::Addressee contact = item.payload<KABC::Addressee>();
53
 
 
54
 
    if ( role == Qt::DecorationRole ) {
55
 
      if ( column == 0 ) {
56
 
        const KABC::Picture picture = contact.photo();
57
 
        if ( picture.isIntern() ) {
58
 
          return picture.data().scaled( QSize( 16, 16 ) );
59
 
        } else {
60
 
          return KIcon( QLatin1String( "x-office-contact" ) );
61
 
        }
62
 
      }
63
 
      return QVariant();
64
 
    } else if ( (role == Qt::DisplayRole) || (role == Qt::EditRole) ) {
65
 
      switch ( column ) {
66
 
        case 0:
67
 
          if ( !contact.formattedName().isEmpty() )
68
 
            return contact.formattedName();
69
 
          else
70
 
            return contact.assembledName();
71
 
        case 1:
72
 
          return contact.givenName();
73
 
          break;
74
 
        case 2:
75
 
          return contact.familyName();
76
 
          break;
77
 
        case 3:
78
 
          return contact.preferredEmail();
79
 
          break;
80
 
        default:
81
 
          break;
82
 
      }
83
 
    }
84
 
  } else if ( item.mimeType() == KABC::ContactGroup::mimeType() ) {
85
 
    if ( !item.hasPayload<KABC::ContactGroup>() ) {
86
 
 
87
 
      // Pass modeltest
88
 
      if ( role == Qt::DisplayRole )
89
 
        return item.remoteId();
90
 
 
91
 
      return QVariant();
92
 
    }
93
 
 
94
 
    if ( role == Qt::DecorationRole ) {
95
 
      if ( column == 0 )
96
 
        return KIcon( QLatin1String( "x-mail-distribution-list" ) );
97
 
      else
98
 
        return QVariant();
99
 
    } else if ( (role == Qt::DisplayRole) || (role == Qt::EditRole) ) {
100
 
      switch ( column ) {
101
 
        case 0:
102
 
          {
103
 
            const KABC::ContactGroup group = item.payload<KABC::ContactGroup>();
104
 
            return group.name();
105
 
          }
106
 
          break;
107
 
        default:
108
 
          break;
109
 
      }
110
 
    }
111
 
  }
112
 
 
113
 
  return EntityTreeModel::getData( item, column, role );
114
 
}
115
 
 
116
 
QVariant ContactsTreeModel::getData( const Collection &collection, int column, int role ) const
117
 
{
118
 
  if ( role == Qt::DisplayRole ) {
119
 
    switch ( column ) {
120
 
      case 0:
121
 
        return EntityTreeModel::getData( collection, column, role );
122
 
      default:
123
 
        return QString(); // pass model test
124
 
    }
125
 
  }
126
 
 
127
 
  return EntityTreeModel::getData( collection, column, role );
128
 
}
129
 
 
130
 
int ContactsTreeModel::columnCount( const QModelIndex &index ) const
131
 
{
132
 
  Q_UNUSED(index);
133
 
  return 4;
134
 
}
135
 
 
136
 
QVariant ContactsTreeModel::getHeaderData( int section, Qt::Orientation orientation, int role, int headerSet ) const
137
 
{
138
 
  if ( role == Qt::DisplayRole ) {
139
 
    if ( orientation == Qt::Horizontal ) {
140
 
      if ( headerSet == EntityTreeModel::CollectionTreeHeaders ) {
141
 
 
142
 
        if ( section >= 1 )
143
 
          return QVariant();
144
 
 
145
 
        switch ( section ) {
146
 
          case 0:
147
 
            return i18nc( "@title:column, address books overview", "Address Books" );
148
 
            break;
149
 
        }
150
 
      } else if ( headerSet == EntityTreeModel::ItemListHeaders ) {
151
 
        if ( section >= 4 )
152
 
          return QVariant();
153
 
 
154
 
        switch ( section ) {
155
 
          case 0:
156
 
            return i18nc( "@title:column, name of a person", "Name" );
157
 
            break;
158
 
          case 1:
159
 
            return KABC::Addressee::givenNameLabel();
160
 
            break;
161
 
          case 2:
162
 
            return KABC::Addressee::familyNameLabel();
163
 
            break;
164
 
          case 3:
165
 
            return KABC::Addressee::emailLabel();
166
 
            break;
167
 
        }
168
 
      }
169
 
    }
170
 
  }
171
 
 
172
 
  return EntityTreeModel::getHeaderData( section, orientation, role, headerSet );
173
 
}
174
 
 
175
 
#include "contactstreemodel.moc"