~ubuntu-branches/ubuntu/lucid/kdepim-runtime/lucid

« back to all changes in this revision

Viewing changes to akonadi_next/contactsmodel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2009-12-03 15:38:40 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20091203153840-x5fxfsfby0czyqu6
Tags: 4:4.3.80-0ubuntu1
* New upstream beta release:
  - Refresh all patches
  - Bump build-depend versions
  - Remove build-depend on libknotificationitem-dev, it's part of
    kdelibs5-dev now
  - Add build-depend on shared-desktop-ontologies for nepomuk support
  - Add build-depend on libstreamanalyzer-dev for strigi support
  - Add build-depend on libx11-dev to prevent FTBFS
  - Update various .install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <kabc/contactgroup.h>
24
24
 
25
25
#include <kdebug.h>
 
26
#include <akonadi/entitydisplayattribute.h>
26
27
 
27
28
using namespace Akonadi;
28
29
 
32
33
  ContactsModelPrivate(ContactsModel *model)
33
34
    : q_ptr(model)
34
35
  {
35
 
    m_collectionHeaders << "Collection" << "Count";
36
 
    m_itemHeaders << "Given Name" << "Family Name" << "Email";
 
36
    m_collectionHeaders << QLatin1String( "Collection" ) << QLatin1String( "Count" );
 
37
    m_itemHeaders << QLatin1String( "Given Name" ) << QLatin1String( "Family Name" ) << QLatin1String( "Email" );
37
38
  }
38
39
 
39
40
  Q_DECLARE_PUBLIC(ContactsModel)
44
45
 
45
46
};
46
47
 
47
 
ContactsModel::ContactsModel(Session *session, Monitor *monitor, QObject *parent)
 
48
 
 
49
bool ContactsModel::entityMatch(Item item, const QVariant& matchData, Qt::MatchFlags flags) const
 
50
{
 
51
  Q_UNUSED( flags );
 
52
  if (!item.hasPayload<KABC::Addressee>())
 
53
    return false;
 
54
 
 
55
  if (!matchData.canConvert(QVariant::String))
 
56
    return false;
 
57
 
 
58
  const QString matchString = matchData.toString();
 
59
 
 
60
  const KABC::Addressee addressee = item.payload<KABC::Addressee>();
 
61
 
 
62
  if ( addressee.familyName().startsWith(matchString, Qt::CaseInsensitive)
 
63
      || addressee.givenName().startsWith(matchString, Qt::CaseInsensitive)
 
64
      || addressee.preferredEmail().startsWith(matchString, Qt::CaseInsensitive))
 
65
    return true;
 
66
 
 
67
 
 
68
  if (item.hasAttribute<EntityDisplayAttribute>() &&
 
69
    !item.attribute<EntityDisplayAttribute>()->displayName().isEmpty() )
 
70
  {
 
71
    if (item.attribute<EntityDisplayAttribute>()->displayName().startsWith(matchString))
 
72
      return true;
 
73
  }
 
74
 
 
75
  return false;
 
76
}
 
77
 
 
78
 
 
79
bool ContactsModel::entityMatch(Collection col, const QVariant& matchData, Qt::MatchFlags flags) const
 
80
{
 
81
  Q_UNUSED( flags );
 
82
  if (!matchData.canConvert(QVariant::String))
 
83
    return false;
 
84
 
 
85
  const QString matchString = matchData.toString();
 
86
 
 
87
  if (col.hasAttribute<EntityDisplayAttribute>() &&
 
88
      !col.attribute<EntityDisplayAttribute>()->displayName().isEmpty() )
 
89
    return col.attribute<EntityDisplayAttribute>()->displayName().startsWith(matchString);
 
90
  return col.name().startsWith(matchString);
 
91
}
 
92
 
 
93
 
 
94
ContactsModel::ContactsModel(Session *session, ChangeRecorder *monitor, QObject *parent)
48
95
  : EntityTreeModel(session, monitor, parent), d_ptr(new ContactsModelPrivate(this))
49
96
{
50
97
 
55
102
   delete d_ptr;
56
103
}
57
104
 
58
 
QVariant ContactsModel::getData(const Item &item, int column, int role) const
 
105
QVariant ContactsModel::entityData(const Item &item, int column, int role) const
59
106
{
60
 
  if ( item.mimeType() == "text/directory" )
 
107
  if ( item.mimeType() == QLatin1String( "text/directory" ) )
61
108
  {
62
109
    if ( !item.hasPayload<KABC::Addressee>() )
63
110
    {
78
125
        return addr.familyName();
79
126
      case 2:
80
127
        return addr.preferredEmail();
81
 
      case 3:
82
 
        return addr.givenName() + " " + addr.familyName() + " " + "<" + addr.preferredEmail() + ">";
83
128
      }
84
129
    }
85
130
  }
86
 
  return EntityTreeModel::getData(item, column, role);
 
131
  return EntityTreeModel::entityData(item, column, role);
87
132
}
88
133
 
89
 
QVariant ContactsModel::getData(const Collection &collection, int column, int role) const
 
134
QVariant ContactsModel::entityData(const Collection &collection, int column, int role) const
90
135
{
91
136
  if (role == Qt::DisplayRole)
92
137
  {
93
138
    switch (column)
94
139
    {
95
140
    case 0:
96
 
      return EntityTreeModel::getData(collection, column, role);
 
141
      return EntityTreeModel::entityData(collection, column, role);
97
142
    case 1:
98
 
      return rowCount(EntityTreeModel::indexForCollection(collection));
 
143
    {
 
144
      QModelIndexList indexList = match( QModelIndex(), collection.id(), EntityTreeModel::CollectionIdRole );
 
145
      Q_ASSERT( indexList.size() == 1 );
 
146
      return rowCount(indexList.at( 0 ) );
 
147
    }
99
148
    default:
100
149
      // Return a QString to pass modeltest.
101
150
      return QString();
102
151
  //     return QVariant();
103
152
    }
104
153
  }
105
 
  return EntityTreeModel::getData(collection, column, role);
 
154
  return EntityTreeModel::entityData(collection, column, role);
106
155
}
107
156
 
108
157
int ContactsModel::columnCount(const QModelIndex &index) const
111
160
  return 4;
112
161
}
113
162
 
114
 
QVariant ContactsModel::getHeaderData( int section, Qt::Orientation orientation, int role, int headerSet ) const
 
163
QVariant ContactsModel::entityHeaderData( int section, Qt::Orientation orientation, int role, HeaderGroup headerGroup ) const
115
164
{
116
165
  Q_D(const ContactsModel);
117
166
 
118
167
  if (orientation == Qt::Horizontal)
119
168
  {
120
 
    if ( headerSet == EntityTreeModel::CollectionTreeHeaders )
 
169
    if ( headerGroup == EntityTreeModel::CollectionTreeHeaders )
121
170
    {
122
171
      if (role == Qt::DisplayRole)
123
172
      {
125
174
          return QVariant();
126
175
        return d->m_collectionHeaders.at(section);
127
176
      }
128
 
    } else if (headerSet == EntityTreeModel::ItemListHeaders)
 
177
    } else if (headerGroup == EntityTreeModel::ItemListHeaders)
129
178
    {
130
179
      if (role == Qt::DisplayRole)
131
180
      {
136
185
    }
137
186
  }
138
187
 
139
 
  return EntityTreeModel::getHeaderData(section, orientation, role, headerSet);
 
188
  return EntityTreeModel::entityHeaderData(section, orientation, role, headerGroup);
140
189
}
141
190
 
142
191
#include "contactsmodel.moc"