28 NmContactHistoryModelPrivate::HistoryModelType enum. |
29 NmContactHistoryModelPrivate::HistoryModelType enum. |
29 */ |
30 */ |
30 NmContactHistoryModelPrivate::NmContactHistoryModelPrivate( |
31 NmContactHistoryModelPrivate::NmContactHistoryModelPrivate( |
31 const NmContactHistoryModelType modelType) : |
32 const NmContactHistoryModelType modelType) : |
32 mType(modelType), |
33 mType(modelType), |
33 mContactManager(0), |
34 mContactManager(NULL), |
34 mModelReady(false) |
35 mModelReady(false) |
35 { |
36 { |
|
37 NM_FUNCTION; |
|
38 |
36 mContactManager = new QContactManager("symbian"); |
39 mContactManager = new QContactManager("symbian"); |
37 mNameOrder = EmailMRU::nameOrder(); |
40 mNameOrder = EmailMRU::nameOrder(); |
38 } |
41 } |
39 |
42 |
40 /*! |
43 /*! |
41 Destructor of ContactHistoryModel |
44 Destructor of ContactHistoryModel |
42 */ |
45 */ |
43 NmContactHistoryModelPrivate::~NmContactHistoryModelPrivate() |
46 NmContactHistoryModelPrivate::~NmContactHistoryModelPrivate() |
44 { |
47 { |
|
48 NM_FUNCTION; |
|
49 |
45 delete mContactManager; |
50 delete mContactManager; |
46 mPrivateItemList.clear(); |
51 mPrivateItemList.clear(); |
47 mModelItemList.clear(); |
52 mModelItemList.clear(); |
48 } |
53 } |
49 |
54 |
56 |
61 |
57 Note:: QContactManager supports max. ten characters long queries. |
62 Note:: QContactManager supports max. ten characters long queries. |
58 */ |
63 */ |
59 void NmContactHistoryModelPrivate::queryDatabases(const QString& query) |
64 void NmContactHistoryModelPrivate::queryDatabases(const QString& query) |
60 { |
65 { |
|
66 NM_FUNCTION; |
|
67 |
61 mModelReady = false; |
68 mModelReady = false; |
62 // Clear contacts in the list |
69 // Clear contacts in the list |
63 mPrivateItemList.clear(); |
70 mPrivateItemList.clear(); |
64 mModelItemList.clear(); |
71 mModelItemList.clear(); |
65 mMruList.clear(); |
72 mMruList.clear(); |
66 mMruMatches.clear(); |
73 mMruMatches.clear(); |
67 |
74 |
|
75 mNameOrder = EmailMRU::nameOrder(); |
|
76 |
68 // Modify search to suit our needs |
77 // Modify search to suit our needs |
69 // Space must be removed, because it is understood as logigal AND |
78 // Space must be removed, because it is understood as logigal AND |
70 // with QContactManager API |
79 // with QContactManager API |
71 QString modifiedQuery = query; |
80 QString modifiedQuery = query; |
72 |
81 |
73 int spcPosition = query.indexOf(" "); |
82 int spcPosition = query.indexOf(" "); |
74 |
83 |
75 if ( spcPosition != -1 ) |
84 if ( spcPosition != -1 ) |
76 { |
85 { |
77 modifiedQuery = query.left(spcPosition); |
86 modifiedQuery = query.left(spcPosition); |
78 } |
87 } |
79 |
88 |
|
89 // Get matching MRU items |
80 queryMruDatabase(modifiedQuery); |
90 queryMruDatabase(modifiedQuery); |
|
91 |
|
92 // Populate mPrivateItemList with matching MRU items. |
81 populateListWithMruItems(modifiedQuery); |
93 populateListWithMruItems(modifiedQuery); |
82 |
94 |
83 if (mContactManager) |
95 // Get matching IDs from Contacts DB |
84 { |
96 QList<QContactLocalId> cnt_ids = queryContactDatabase(modifiedQuery); |
85 // Get matching IDs from Contacts DB |
97 |
86 QList<QContactLocalId> cnt_ids = queryContactDatabase(modifiedQuery); |
98 // Populate mPrivateItemList with contact items. |
87 |
99 populateListWithContactItems(cnt_ids, modifiedQuery); |
88 // Populate mPrivateItemList with contact items. |
100 |
89 populateListWithContactItems(cnt_ids, modifiedQuery); |
101 |
90 } |
102 #ifdef _DEBUG |
91 |
103 |
92 // Currently we will always emit 0 as completion code. |
104 for (int i = 0; i < mPrivateItemList.size(); i++) |
93 |
105 { |
94 //TODO: Will be removed, Debug Code. |
106 QSharedPointer<NmContactHistoryModelItemData> itemData = mPrivateItemList[i]; |
95 for (int i = 0; i < mPrivateItemList.size(); i++) |
107 |
96 { |
108 QString dbgString = itemData->mItems[0].mItemText; |
97 QSharedPointer<NmContactHistoryModelItemData> itemData = mPrivateItemList[i]; |
109 dbgString.append(" "); |
98 |
110 dbgString.append(itemData->mItems[1].mItemText); |
99 QString dbgString = itemData->mItems[0].mItemText; |
111 |
100 dbgString.append(" "); |
112 qDebug(dbgString.toLatin1()); |
101 dbgString.append(itemData->mItems[1].mItemText); |
113 } |
102 |
114 |
103 qDebug(dbgString.toLatin1()); |
115 #endif |
104 |
116 |
105 |
|
106 } |
|
107 |
117 |
108 emit queryCompleted(0); |
118 emit queryCompleted(0); |
109 } |
119 } |
110 |
120 |
111 /*! |
121 /*! |
195 */ |
211 */ |
196 void NmContactHistoryModelPrivate::populateListWithContactItems( |
212 void NmContactHistoryModelPrivate::populateListWithContactItems( |
197 const QList<QContactLocalId> cnt_ids, |
213 const QList<QContactLocalId> cnt_ids, |
198 const QString &modifiedQuery) |
214 const QString &modifiedQuery) |
199 { |
215 { |
|
216 NM_FUNCTION; |
|
217 |
200 int cntCount = cnt_ids.count(); |
218 int cntCount = cnt_ids.count(); |
201 // Populate mPrivateItemList with contact items. |
219 // Populate mPrivateItemList with contact items. |
202 for ( int cntIndex = 0; cntIndex < cntCount; cntIndex++) |
220 for ( int cntIndex = 0; cntIndex < cntCount; cntIndex++) |
203 { |
221 { |
204 QContactLocalId cid = cnt_ids.at( cntIndex ); |
222 QContactLocalId cid = cnt_ids.at( cntIndex ); |
286 \sa queryDatabases( ) |
304 \sa queryDatabases( ) |
287 */ |
305 */ |
288 void NmContactHistoryModelPrivate::populateListWithMruItems( |
306 void NmContactHistoryModelPrivate::populateListWithMruItems( |
289 const QString &query) |
307 const QString &query) |
290 { |
308 { |
291 QMapIterator<QString, QString> i(mMruMatches); |
309 NM_FUNCTION; |
292 |
310 |
293 while (i.hasNext()) |
311 QMapIterator<QString, QString> mruMatch(mMruMatches); |
294 { |
312 |
295 i.next(); |
313 while (mruMatch.hasNext()) |
|
314 { |
|
315 mruMatch.next(); |
296 // For Display name (ex. John Doe) |
316 // For Display name (ex. John Doe) |
297 NmContactHistoryModelSubItem itemSubItem1; |
317 NmContactHistoryModelSubItem itemSubItem1; |
298 // For Email address (ex. john.doe@company.com) |
318 // For Email address (ex. john.doe@company.com) |
299 NmContactHistoryModelSubItem itemSubItem2; |
319 NmContactHistoryModelSubItem itemSubItem2; |
300 |
320 |
301 itemSubItem1.mItemText = i.key(); |
321 QString name = mruMatch.key(); |
302 itemSubItem2.mItemText = i.value(); |
322 QString address = mruMatch.value(); |
|
323 |
|
324 itemSubItem1.mItemText = name; |
|
325 itemSubItem2.mItemText = address; |
303 |
326 |
304 // markup for first item. |
327 // markup for first item. |
305 if( i.key().indexOf(query, 0, Qt::CaseInsensitive) == 0) |
328 if( name.indexOf(query, 0, Qt::CaseInsensitive) == 0) |
306 { |
329 { |
307 itemSubItem1.mMatchingRanges.append(0); |
330 itemSubItem1.mMatchingRanges.append(0); |
308 itemSubItem1.mMatchingRanges.append(query.length()-1); |
331 itemSubItem1.mMatchingRanges.append(query.length()-1); |
309 } |
332 } |
310 |
333 |
311 QRegExp rx("[,\\s]", Qt::CaseInsensitive); |
334 QRegExp rx("[,\\s]", Qt::CaseInsensitive); |
312 bool separatorExists = i.key().contains(rx); |
335 bool separatorExists = name.contains(rx); |
313 |
336 |
314 if (separatorExists) |
337 if (separatorExists) |
315 { |
338 { |
316 int indexLN = i.key().indexOf(",", 0, Qt::CaseInsensitive); |
339 int indexLN = name.indexOf(",", 0, Qt::CaseInsensitive); |
317 |
340 |
318 if (indexLN == -1) |
341 if (indexLN == -1) |
319 { |
342 { |
320 indexLN = i.key().indexOf(" ", 0, Qt::CaseInsensitive); |
343 indexLN = name.indexOf(" ", 0, Qt::CaseInsensitive); |
321 } |
344 } |
322 |
345 |
323 if (indexLN > 0) |
346 if (indexLN > 0) |
324 { |
347 { |
325 int matchPos = i.key().indexOf(query, indexLN, Qt::CaseInsensitive); |
348 int matchPos = name.indexOf(query, indexLN, Qt::CaseInsensitive); |
326 |
349 |
327 if (matchPos > 0) |
350 if (matchPos > 0) |
328 { |
351 { |
329 itemSubItem1.mMatchingRanges.append(matchPos); |
352 itemSubItem1.mMatchingRanges.append(matchPos); |
330 itemSubItem1.mMatchingRanges.append((matchPos+query.length())-1); |
353 itemSubItem1.mMatchingRanges.append((matchPos+query.length())-1); |
331 } |
354 } |
332 } |
355 } |
333 } |
356 } |
334 |
357 |
335 // markup for second item. |
358 // markup for second item. |
336 if (itemSubItem2.mItemText.indexOf(query, 0, Qt::CaseInsensitive) == 0 ) |
359 if (address.indexOf(query, 0, Qt::CaseInsensitive) == 0 ) |
337 { |
360 { |
338 itemSubItem2.mMatchingRanges.append(0); |
361 itemSubItem2.mMatchingRanges.append(0); |
339 itemSubItem2.mMatchingRanges.append(query.length()-1); |
362 itemSubItem2.mMatchingRanges.append(query.length()-1); |
340 } |
363 } |
341 |
364 |
394 mModelReady = true; |
419 mModelReady = true; |
395 |
420 |
396 } |
421 } |
397 |
422 |
398 /*! |
423 /*! |
399 This is called by public class NmContactHistoryModel when rowcount() is requested |
424 This is called by public class NmContactHistoryModel when model row count is requested |
400 Not meant to be used alone. |
425 Not meant to be used alone. |
401 |
426 |
402 */ |
427 */ |
403 int NmContactHistoryModelPrivate::rowCount(const QModelIndex &parent) const |
428 int NmContactHistoryModelPrivate::modelRowCount(const QModelIndex &parent) const |
404 { |
429 { |
|
430 NM_FUNCTION; |
|
431 |
405 Q_UNUSED(parent); |
432 Q_UNUSED(parent); |
406 return mModelItemList.count(); |
433 return mModelItemList.count(); |
407 } |
434 } |
408 |
435 |
409 /*! |
436 /*! |
|
437 This is called by public class NmContactHistoryModel when private data count is required |
|
438 ie. When model isn't populated yet but data query is complete. |
|
439 Not meant to be used alone. |
|
440 |
|
441 */ |
|
442 int NmContactHistoryModelPrivate::privateDataCount() const |
|
443 { |
|
444 NM_FUNCTION; |
|
445 return mPrivateItemList.count(); |
|
446 } |
|
447 |
|
448 /*! |
410 This is called by public class NmContactHistoryModel when data() is requested |
449 This is called by public class NmContactHistoryModel when data() is requested |
411 Not meant to be used alone. |
450 Not meant to be used alone. |
412 |
451 |
413 */ |
452 */ |
414 QVariant NmContactHistoryModelPrivate::data(const QModelIndex &index, int role) const |
453 QVariant NmContactHistoryModelPrivate::data(const QModelIndex &index, int role) const |
415 { |
454 { |
|
455 NM_FUNCTION; |
|
456 |
416 if ( mModelReady ) |
457 if ( mModelReady ) |
417 { |
458 { |
418 if (!index.isValid() || |
459 if (!index.isValid() || |
419 index.row() >= mModelItemList.count() || |
460 index.row() >= mModelItemList.count() || |
420 index.row() < 0) |
461 index.row() < 0) |
421 { |
462 { |
422 return QVariant(); |
463 return QVariant(); |
423 } |
464 } |
424 |
465 else if (role == Qt::DisplayRole) |
425 if (role == Qt::DisplayRole) |
|
426 { |
466 { |
427 QVariant v; |
467 QVariant v; |
428 NmContactHistoryModelItem i = mModelItemList.at(index.row()); |
468 NmContactHistoryModelItem i = mModelItemList.at(index.row()); |
429 v.setValue(i); |
469 v.setValue(i); |
430 return v; |
470 return v; |