138
ContactProxyModel::ContactProxyModel(AbstractContactBackend* parent,int role, bool showAll) : QAbstractItemModel(QCoreApplication::instance()),
139
m_pModel(parent),m_Role(role),m_ShowAll(showAll),m_lCategoryCounter()
139
ContactProxyModel::ContactProxyModel(int role, bool showAll) : QAbstractItemModel(QCoreApplication::instance()),
140
m_Role(role),m_ShowAll(showAll),m_lCategoryCounter()
141
142
setObjectName("ContactProxyModel");
142
143
m_lCategoryCounter.reserve(32);
143
144
m_lMimes << MIME_PLAIN_TEXT << MIME_PHONENUMBER;
144
connect(m_pModel,SIGNAL(collectionChanged()),this,SLOT(reloadCategories()));
145
connect(m_pModel,SIGNAL(newContactAdded(Contact*)),this,SLOT(slotContactAdded(Contact*)));
145
connect(ContactModel::instance(),SIGNAL(reloaded()),this,SLOT(reloadCategories()));
146
connect(ContactModel::instance(),SIGNAL(newContactAdded(Contact*)),this,SLOT(slotContactAdded(Contact*)));
146
147
QHash<int, QByteArray> roles = roleNames();
147
roles.insert(AbstractContactBackend::Role::Organization ,QByteArray("organization") );
148
roles.insert(AbstractContactBackend::Role::Group ,QByteArray("group") );
149
roles.insert(AbstractContactBackend::Role::Department ,QByteArray("department") );
150
roles.insert(AbstractContactBackend::Role::PreferredEmail ,QByteArray("preferredEmail") );
151
roles.insert(AbstractContactBackend::Role::FormattedLastUsed ,QByteArray("formattedLastUsed"));
152
roles.insert(AbstractContactBackend::Role::IndexedLastUsed ,QByteArray("indexedLastUsed") );
153
roles.insert(AbstractContactBackend::Role::DatedLastUsed ,QByteArray("datedLastUsed") );
154
roles.insert(AbstractContactBackend::Role::Filter ,QByteArray("filter") );
155
roles.insert(AbstractContactBackend::Role::DropState ,QByteArray("dropState") );
148
roles.insert(ContactModel::Role::Organization ,QByteArray("organization") );
149
roles.insert(ContactModel::Role::Group ,QByteArray("group") );
150
roles.insert(ContactModel::Role::Department ,QByteArray("department") );
151
roles.insert(ContactModel::Role::PreferredEmail ,QByteArray("preferredEmail") );
152
roles.insert(ContactModel::Role::FormattedLastUsed ,QByteArray("formattedLastUsed"));
153
roles.insert(ContactModel::Role::IndexedLastUsed ,QByteArray("indexedLastUsed") );
154
roles.insert(ContactModel::Role::DatedLastUsed ,QByteArray("datedLastUsed") );
155
roles.insert(ContactModel::Role::Filter ,QByteArray("filter") );
156
roles.insert(ContactModel::Role::DropState ,QByteArray("dropState") );
156
157
setRoleNames(roles);
192
193
m_lCategoryCounter.clear();
193
foreach(Contact* cont, m_pModel->getContactList()) {
194
foreach(const Contact* cont, ContactModel::instance()->contacts()) {
195
196
const QString val = category(cont);
196
197
TopLevelItem* item = getTopLevelItem(val);
197
ContactTreeNode* contactNode = new ContactTreeNode(cont,this);
198
ContactTreeNode* contactNode = new ContactTreeNode(const_cast<Contact*>(cont),this);
198
199
contactNode->m_pParent3 = item;
199
200
contactNode->m_Index = item->m_lChildren.size();
200
201
item->m_lChildren << contactNode;
244
245
case Qt::DisplayRole:
245
246
return static_cast<const TopLevelItem*>(modelItem)->m_Name;
246
case AbstractContactBackend::Role::IndexedLastUsed:
247
return index.child(0,0).data(AbstractContactBackend::Role::IndexedLastUsed);
248
case AbstractContactBackend::Role::Active:
247
case ContactModel::Role::IndexedLastUsed:
248
return index.child(0,0).data(ContactModel::Role::IndexedLastUsed);
249
case ContactModel::Role::Active:
257
258
case Qt::DisplayRole:
258
259
return QVariant(c->formattedName());
259
case AbstractContactBackend::Role::Organization:
260
case ContactModel::Role::Organization:
260
261
return QVariant(c->organization());
261
case AbstractContactBackend::Role::Group:
262
case ContactModel::Role::Group:
262
263
return QVariant(c->group());
263
case AbstractContactBackend::Role::Department:
264
case ContactModel::Role::Department:
264
265
return QVariant(c->department());
265
case AbstractContactBackend::Role::PreferredEmail:
266
case ContactModel::Role::PreferredEmail:
266
267
return QVariant(c->preferredEmail());
267
case AbstractContactBackend::Role::DropState:
268
case ContactModel::Role::DropState:
268
269
return QVariant(modelItem->dropState());
269
case AbstractContactBackend::Role::FormattedLastUsed:
270
case ContactModel::Role::FormattedLastUsed:
270
271
return QVariant(HistoryTimeCategoryModel::timeToHistoryCategory(c->phoneNumbers().lastUsedTimeStamp()));
271
case AbstractContactBackend::Role::IndexedLastUsed:
272
case ContactModel::Role::IndexedLastUsed:
272
273
return QVariant((int)HistoryTimeCategoryModel::timeToHistoryConst(c->phoneNumbers().lastUsedTimeStamp()));
273
case AbstractContactBackend::Role::Active:
274
case ContactModel::Role::Active:
274
275
return c->isActive();
275
case AbstractContactBackend::Role::DatedLastUsed:
276
case ContactModel::Role::DatedLastUsed:
276
277
return QVariant(QDateTime::fromTime_t( c->phoneNumbers().lastUsedTimeStamp()));
277
case AbstractContactBackend::Role::Filter: {
278
//Strip non essential characters like accents from the filter string
279
QString normStripppedC;
280
foreach(QChar char2,QString(c->formattedName()+'\n'+c->organization()+'\n'+c->group()+'\n'+
281
c->department()+'\n'+c->preferredEmail()).toLower().normalized(QString::NormalizationForm_KD) ) {
282
if (!char2.combiningClass())
283
normStripppedC += char2;
285
return normStripppedC;
278
case ContactModel::Role::Filter:
279
return c->filterString();
505
498
****************************************************************************/
508
QString ContactProxyModel::category(Contact* ct) const {
501
QString ContactProxyModel::category(const Contact* ct) const {
510
503
return QString();
512
505
switch (m_Role) {
513
case AbstractContactBackend::Role::Organization:
506
case ContactModel::Role::Organization:
514
507
cat = ct->organization();
516
case AbstractContactBackend::Role::Group:
509
case ContactModel::Role::Group:
517
510
cat = ct->group();
519
case AbstractContactBackend::Role::Department:
512
case ContactModel::Role::Department:
520
513
cat = ct->department();
522
case AbstractContactBackend::Role::PreferredEmail:
515
case ContactModel::Role::PreferredEmail:
523
516
cat = ct->preferredEmail();
525
case AbstractContactBackend::Role::FormattedLastUsed:
518
case ContactModel::Role::FormattedLastUsed:
526
519
cat = HistoryTimeCategoryModel::timeToHistoryCategory(ct->phoneNumbers().lastUsedTimeStamp());
528
case AbstractContactBackend::Role::IndexedLastUsed:
521
case ContactModel::Role::IndexedLastUsed:
529
522
cat = QString::number((int)HistoryTimeCategoryModel::timeToHistoryConst(ct->phoneNumbers().lastUsedTimeStamp()));
531
case AbstractContactBackend::Role::DatedLastUsed:
524
case ContactModel::Role::DatedLastUsed:
532
525
cat = QDateTime::fromTime_t(ct->phoneNumbers().lastUsedTimeStamp()).toString();