117 * \param role The data should be relevant to this particular purpose. |
125 * \param role The data should be relevant to this particular purpose. |
118 * \return QVariant The data for the specified index and role. |
126 * \return QVariant The data for the specified index and role. |
119 */ |
127 */ |
120 QVariant CntHistoryModelPrivate::data(const QModelIndex& index, int role) const |
128 QVariant CntHistoryModelPrivate::data(const QModelIndex& index, int role) const |
121 { |
129 { |
|
130 CNT_ENTRY_ARGS(index << role) |
122 // Invalid index |
131 // Invalid index |
123 int row = index.row(); |
132 int row = index.row(); |
124 |
133 |
125 if ( !validateRowIndex(row) ) |
134 if ( !validateRowIndex(row) ) |
126 return QVariant(); |
135 return QVariant(); |
127 |
136 |
128 HItemPointer p = m_List.at(row); |
137 HItemPointer p = m_List.at(row); |
129 if ( p.isNull() ) |
138 if ( p.isNull() ) |
130 return QVariant(); |
139 return QVariant(); |
131 |
140 |
132 switch( role ) |
141 switch( role ) |
133 { |
142 { |
134 case Qt::DisplayRole: |
143 case Qt::DisplayRole: |
135 return displayRoleData(*p); |
144 return displayRoleData(*p); |
136 case Qt::DecorationRole: |
145 case Qt::DecorationRole: |
181 * \param item The History item to return data about. |
194 * \param item The History item to return data about. |
182 * return QVariant String of the icon path. |
195 * return QVariant String of the icon path. |
183 */ |
196 */ |
184 QVariant CntHistoryModelPrivate::decorationRoleData(const HistoryItem& item) const |
197 QVariant CntHistoryModelPrivate::decorationRoleData(const HistoryItem& item) const |
185 { |
198 { |
|
199 CNT_ENTRY |
|
200 |
186 // Messages |
201 // Messages |
187 if (item.flags & CntMessage) |
202 if (item.flags & CntMessage) |
188 return QVariant(HbIcon(MESSAGE_ICON)); |
203 return QVariant(HbIcon(MESSAGE_ICON)); |
189 |
204 |
190 // Call logs |
205 // Call logs |
251 * \param column Column to be sorted. It is not used. |
266 * \param column Column to be sorted. It is not used. |
252 * \param order Order to sort the list items. |
267 * \param order Order to sort the list items. |
253 */ |
268 */ |
254 void CntHistoryModelPrivate::sort(int /*column*/, Qt::SortOrder order) |
269 void CntHistoryModelPrivate::sort(int /*column*/, Qt::SortOrder order) |
255 { |
270 { |
|
271 CNT_ENTRY_ARGS(order) |
|
272 |
256 if ( order == Qt::AscendingOrder ) |
273 if ( order == Qt::AscendingOrder ) |
257 qStableSort(m_List.begin(), m_List.end(), lessThan); |
274 qStableSort(m_List.begin(), m_List.end(), lessThan); |
258 else |
275 else |
259 qStableSort(m_List.begin(), m_List.end(), greaterThan); |
276 qStableSort(m_List.begin(), m_List.end(), greaterThan); |
|
277 |
|
278 CNT_EXIT |
260 } |
279 } |
261 |
280 |
262 /*! |
281 /*! |
263 * Clear history from the database. If the history cached |
282 * Clear history from the database. If the history cached |
264 * is specific to one contact, only that history is cleared. |
283 * is specific to one contact, only that history is cleared. |
265 * |
284 * |
266 */ |
285 */ |
267 void CntHistoryModelPrivate::clearHistory() |
286 void CntHistoryModelPrivate::clearHistory() |
268 { |
287 { |
|
288 CNT_ENTRY |
|
289 |
269 Q_Q(CntHistoryModel); |
290 Q_Q(CntHistoryModel); |
270 |
291 |
271 if ( m_List.isEmpty() ) |
292 if ( m_List.isEmpty() ) |
272 return; |
293 return; |
|
294 |
|
295 // Clear all data from the history model. |
|
296 int count = rowCount(); |
|
297 |
|
298 q->doBeginRemoveRows( QModelIndex(), 0, count ); |
273 |
299 |
274 // Call logs |
300 // Call logs |
275 if ( !m_isMyCard && m_logsFilter ) |
301 if ( !m_isMyCard && m_logsFilter ) |
276 m_logsFilter->clearEvents(); |
302 m_logsFilter->clearEvents(); |
277 else if ( m_logsModel ) |
303 else if ( m_logsModel ) |
279 |
305 |
280 // Messages |
306 // Messages |
281 if (m_msgHistory) |
307 if (m_msgHistory) |
282 m_msgHistory->clearMessages( (int)m_contactId ); |
308 m_msgHistory->clearMessages( (int)m_contactId ); |
283 |
309 |
284 // Clear all data from the history model. |
|
285 int count = rowCount(); |
|
286 |
|
287 m_List.clear(); |
310 m_List.clear(); |
288 m_msgMap.clear(); |
311 m_msgMap.clear(); |
289 m_logsMap.clear(); |
312 m_logsMap.clear(); |
290 |
313 |
291 q->doBeginRemoveRows( QModelIndex(), 0, count ); |
314 |
292 q->doEndRemoveRows(); |
315 q->doEndRemoveRows(); |
|
316 |
|
317 CNT_EXIT |
293 } |
318 } |
294 |
319 |
295 /*! |
320 /*! |
296 * Mark all the conversations in the view as seen. |
321 * Mark all the conversations in the view as seen. |
297 * |
322 * |
298 */ |
323 */ |
299 void CntHistoryModelPrivate::markAllAsSeen() |
324 void CntHistoryModelPrivate::markAllAsSeen() |
300 { |
325 { |
|
326 CNT_ENTRY |
|
327 |
301 if ( m_isMarkedAsSeen ) |
328 if ( m_isMarkedAsSeen ) |
302 return; |
329 return; |
303 |
330 |
304 // Messages |
331 // Messages |
305 if (m_msgHistory->markRead( m_contactId )) |
332 if (m_msgHistory->markRead( m_contactId )) |
306 m_isMarkedAsSeen = true; |
333 m_isMarkedAsSeen = true; |
|
334 |
|
335 CNT_EXIT |
307 } |
336 } |
308 |
337 |
309 /*! |
338 /*! |
310 * Create the model structure and cache history data from |
339 * Create the model structure and cache history data from |
311 * conversations and call logs databases. |
340 * conversations and call logs databases. |
312 * |
341 * |
313 */ |
342 */ |
314 void CntHistoryModelPrivate::initializeModel() |
343 void CntHistoryModelPrivate::initializeModel() |
315 { |
344 { |
|
345 CNT_ENTRY |
|
346 |
316 initializeLogsModel(); |
347 initializeLogsModel(); |
317 initializeMsgModel(); |
348 initializeMsgModel(); |
|
349 |
|
350 CNT_EXIT |
318 } |
351 } |
319 |
352 |
320 void CntHistoryModelPrivate::initializeMsgModel() |
353 void CntHistoryModelPrivate::initializeMsgModel() |
321 { |
354 { |
|
355 CNT_ENTRY |
|
356 |
322 if( m_isMyCard ) |
357 if( m_isMyCard ) |
323 return; |
358 return; |
324 |
359 |
325 // Contact centric |
360 // Contact centric |
326 MsgHistory* m = new MsgHistory(); |
361 MsgHistory* m = new MsgHistory(); |
337 // received from this contact |
372 // received from this contact |
338 m->subscribe(m_contactId); |
373 m->subscribe(m_contactId); |
339 |
374 |
340 // Initial fetch of all messages |
375 // Initial fetch of all messages |
341 m->getMessages(m_contactId); |
376 m->getMessages(m_contactId); |
|
377 |
|
378 CNT_EXIT |
342 } |
379 } |
343 |
380 |
344 void CntHistoryModelPrivate::initializeLogsModel() |
381 void CntHistoryModelPrivate::initializeLogsModel() |
345 { |
382 { |
|
383 CNT_ENTRY |
|
384 |
346 //populate model with call events |
385 //populate model with call events |
347 m_logsModel = new LogsModel(LogsModel::LogsFullModel); |
386 m_logsModel = new LogsModel(LogsModel::LogsFullModel); |
348 if (!m_isMyCard) { |
387 if (!m_isMyCard) { |
349 //do the filtering to get call events for the target contact |
388 //do the filtering to get call events for the target contact |
350 m_logsFilter = new LogsCustomFilter; |
389 m_logsFilter = new LogsCustomFilter; |
375 this, SLOT(logsRowsRemoved(const QModelIndex &, int, int))); |
414 this, SLOT(logsRowsRemoved(const QModelIndex &, int, int))); |
376 connect(m_AbstractLogsModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), |
415 connect(m_AbstractLogsModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), |
377 this, SLOT(logsDataChanged(const QModelIndex &, const QModelIndex &))); |
416 this, SLOT(logsDataChanged(const QModelIndex &, const QModelIndex &))); |
378 connect(m_AbstractLogsModel, SIGNAL(modelReset()), this, SLOT(handleLogsReset())); |
417 connect(m_AbstractLogsModel, SIGNAL(modelReset()), this, SLOT(handleLogsReset())); |
379 |
418 |
|
419 CNT_EXIT |
380 } |
420 } |
381 |
421 |
382 /*! |
422 /*! |
383 * Read call event into a history item |
423 * Read call event into a history item |
384 * |
424 * |
385 * \param event Call log event |
425 * \param event Call log event |
386 * \param item Conversation history item |
426 * \param item Conversation history item |
387 */ |
427 */ |
388 void CntHistoryModelPrivate::readLogEvent(LogsEvent* event, HistoryItem& item) |
428 void CntHistoryModelPrivate::readLogEvent(LogsEvent* event, HistoryItem& item) |
389 { |
429 { |
390 QString bodyText; |
430 QString bodyText; |
391 QString title; |
431 QString title; |
392 |
432 |
393 if ( m_isMyCard ) { |
433 if ( m_isMyCard ) { |
394 if ( event->remoteParty().length() > 0 ) { |
434 if ( event->remoteParty().length() > 0 ) { |
433 * \param first The first row item to be received from the model. |
473 * \param first The first row item to be received from the model. |
434 * \param last The last row item to be received from the model. |
474 * \param last The last row item to be received from the model. |
435 */ |
475 */ |
436 void CntHistoryModelPrivate::logsRowsInserted(const QModelIndex& /*parent*/, int first, int last) |
476 void CntHistoryModelPrivate::logsRowsInserted(const QModelIndex& /*parent*/, int first, int last) |
437 { |
477 { |
|
478 CNT_ENTRY_ARGS(first << last) |
|
479 |
438 Q_Q(CntHistoryModel); |
480 Q_Q(CntHistoryModel); |
439 |
481 |
440 int oldRowCount = rowCount(); |
482 // Check if this is the first time to receive events |
|
483 if ( !m_initLogs ) { |
|
484 q->doBeginResetModel(); |
|
485 } |
|
486 else { |
|
487 q->doBeginInsertRows( QModelIndex(), rowCount(), rowCount() + (last - first) ); |
|
488 } |
|
489 |
441 QList<HItemPointer> l; |
490 QList<HItemPointer> l; |
442 |
491 |
443 for ( int i = first; i < m_AbstractLogsModel->rowCount() && i <= last; ++i ) { |
492 for ( int i = first; i < m_AbstractLogsModel->rowCount() && i <= last; ++i ) { |
444 LogsEvent* event = qVariantValue<LogsEvent*>( |
493 LogsEvent* event = qVariantValue<LogsEvent*>( |
445 m_AbstractLogsModel->data(m_AbstractLogsModel->index(i, 0), LogsModel::RoleFullEvent) ); |
494 m_AbstractLogsModel->data(m_AbstractLogsModel->index(i, 0), LogsModel::RoleFullEvent) ); |
454 |
503 |
455 // Check if this is the first time to receive events |
504 // Check if this is the first time to receive events |
456 // and sort the entire list. |
505 // and sort the entire list. |
457 if ( !m_initLogs ) { |
506 if ( !m_initLogs ) { |
458 sort(); |
507 sort(); |
459 oldRowCount = 0; |
|
460 m_initLogs = true; |
508 m_initLogs = true; |
461 } |
509 q->doEndResetModel(); |
462 |
510 } |
463 q->doBeginInsertRows(QModelIndex(), oldRowCount, rowCount()); |
511 else { |
464 q->doEndInsertRows(); |
512 q->doEndInsertRows(); |
|
513 } |
|
514 |
|
515 CNT_EXIT |
465 } |
516 } |
466 |
517 |
467 /*! |
518 /*! |
468 * Slot used for receiving new rows from the LogsModel. |
519 * Slot used for receiving new rows from the LogsModel. |
469 * |
520 * |
471 * \param first The first row item to be received from the model. |
522 * \param first The first row item to be received from the model. |
472 * \param last The last row item to be received from the model. |
523 * \param last The last row item to be received from the model. |
473 */ |
524 */ |
474 void CntHistoryModelPrivate::logsRowsRemoved(const QModelIndex& /*parent*/, int first, int last) |
525 void CntHistoryModelPrivate::logsRowsRemoved(const QModelIndex& /*parent*/, int first, int last) |
475 { |
526 { |
|
527 CNT_ENTRY_ARGS(first << last) |
|
528 |
476 Q_Q(CntHistoryModel); |
529 Q_Q(CntHistoryModel); |
477 |
530 |
478 QList< int > indices; |
531 QList< int > indices; |
479 |
532 |
480 for ( int i = first; i <= last; ++i ) { |
533 for ( int i = first; i <= last; ++i ) { |
496 foreach( QList<int> l, batches ) { |
549 foreach( QList<int> l, batches ) { |
497 q->doBeginRemoveRows(QModelIndex(), l.first(), l.last()); |
550 q->doBeginRemoveRows(QModelIndex(), l.first(), l.last()); |
498 q->doEndRemoveRows(); |
551 q->doEndRemoveRows(); |
499 } |
552 } |
500 } |
553 } |
|
554 |
|
555 CNT_EXIT |
501 } |
556 } |
502 |
557 |
503 /*! |
558 /*! |
504 * Update events from logs model. Events are |
559 * Update events from logs model. Events are |
505 * received as a batch |
560 * received as a batch |
507 * \param first First updated model index |
562 * \param first First updated model index |
508 * \param last Last updated model index |
563 * \param last Last updated model index |
509 */ |
564 */ |
510 void CntHistoryModelPrivate::logsDataChanged(const QModelIndex& first, const QModelIndex& last) |
565 void CntHistoryModelPrivate::logsDataChanged(const QModelIndex& first, const QModelIndex& last) |
511 { |
566 { |
|
567 CNT_ENTRY_ARGS(first << last) |
|
568 |
512 Q_Q(CntHistoryModel); |
569 Q_Q(CntHistoryModel); |
513 |
570 |
514 int f = first.row(); |
571 int f = first.row(); |
515 int l = last.row(); |
572 int l = last.row(); |
516 QList< int > indices; |
573 QList< int > indices; |
535 if ( !indices.isEmpty() ) { |
592 if ( !indices.isEmpty() ) { |
536 QList< QList<int> > batches = findIndices( indices ); |
593 QList< QList<int> > batches = findIndices( indices ); |
537 foreach( QList<int> l, batches ) |
594 foreach( QList<int> l, batches ) |
538 q->doDataChanged( q->index(l.first(), 0), q->index(l.last(), 0) ); |
595 q->doDataChanged( q->index(l.first(), 0), q->index(l.last(), 0) ); |
539 } |
596 } |
|
597 |
|
598 CNT_EXIT |
540 } |
599 } |
541 |
600 |
542 /* |
601 /* |
543 * Clear all call logs after receiving a reset model |
602 * Clear all call logs and refetches new call events after |
544 * signal from logs model |
603 * receiving a reset model signal from logs model |
545 */ |
604 */ |
546 void CntHistoryModelPrivate::handleLogsReset() |
605 void CntHistoryModelPrivate::handleLogsReset() |
547 { |
606 { |
|
607 CNT_ENTRY |
|
608 |
548 Q_Q(CntHistoryModel); |
609 Q_Q(CntHistoryModel); |
|
610 |
|
611 q->doBeginResetModel(); |
549 |
612 |
550 // Remove all call logs |
613 // Remove all call logs |
551 QList<HItemPointer> values = m_logsMap.values(); |
614 QList<HItemPointer> values = m_logsMap.values(); |
552 foreach(HItemPointer p, values) { |
615 foreach(HItemPointer p, values) { |
553 m_List.removeOne( p ); |
616 m_List.removeOne( p ); |
590 * \param indices List of indices |
655 * \param indices List of indices |
591 * \return sequences of indices |
656 * \return sequences of indices |
592 */ |
657 */ |
593 QList< QList<int> > CntHistoryModelPrivate::findIndices( const QList< int >& indices ) |
658 QList< QList<int> > CntHistoryModelPrivate::findIndices( const QList< int >& indices ) |
594 { |
659 { |
|
660 CNT_ENTRY_ARGS(indices) |
|
661 |
595 QList< QList<int> > sequences; |
662 QList< QList<int> > sequences; |
596 QList<int> currSequence; |
663 QList<int> currSequence; |
597 int prevIndex = indices.at(0) - 1; |
664 int prevIndex = indices.at(0) - 1; |
598 |
665 |
599 foreach( int currIndex, indices ) |
666 foreach( int currIndex, indices ) |
625 * \param event Message event |
694 * \param event Message event |
626 * \param item Conversation history item |
695 * \param item Conversation history item |
627 */ |
696 */ |
628 void CntHistoryModelPrivate::readMsgEvent(MsgItem& event, HistoryItem& item) |
697 void CntHistoryModelPrivate::readMsgEvent(MsgItem& event, HistoryItem& item) |
629 { |
698 { |
|
699 CNT_ENTRY |
|
700 |
630 // Msg direction |
701 // Msg direction |
631 if ( event.direction() == MsgItem::MsgDirectionIncoming ) { |
702 if ( event.direction() == MsgItem::MsgDirectionIncoming ) { |
632 item.flags |= CntIncoming; |
703 item.flags |= CntIncoming; |
633 // Read status |
704 // Read status |
634 if ( event.isAttributeSet(MsgItem::MsgAttributeUnread) ) |
705 if ( event.isAttributeSet(MsgItem::MsgAttributeUnread) ) |
666 * \param event Message event |
739 * \param event Message event |
667 * \param item Conversation history item |
740 * \param item Conversation history item |
668 */ |
741 */ |
669 void CntHistoryModelPrivate::messagesReady(QList<MsgItem>& msgs) |
742 void CntHistoryModelPrivate::messagesReady(QList<MsgItem>& msgs) |
670 { |
743 { |
|
744 CNT_ENTRY |
|
745 |
671 Q_Q(CntHistoryModel); |
746 Q_Q(CntHistoryModel); |
|
747 |
|
748 q->doBeginResetModel(); |
672 |
749 |
673 foreach( MsgItem m, msgs ) { |
750 foreach( MsgItem m, msgs ) { |
674 // Create a new hst item |
751 // Create a new hst item |
675 HItemPointer item(new HistoryItem()); |
752 HItemPointer item(new HistoryItem()); |
676 |
753 |
684 m_List.append( item ); |
761 m_List.append( item ); |
685 } |
762 } |
686 |
763 |
687 sort(); |
764 sort(); |
688 |
765 |
689 q->doBeginInsertRows(QModelIndex(), 0, rowCount()); |
766 q->doEndResetModel(); |
690 q->doEndInsertRows(); |
767 |
|
768 CNT_EXIT |
691 } |
769 } |
692 |
770 |
693 /*! |
771 /*! |
694 * Slot to receive new messages from the messages model |
772 * Slot to receive new messages from the messages model |
695 * |
773 * |
696 * \param event Message event |
774 * \param event Message event |
697 * \param item Conversation history item |
775 * \param item Conversation history item |
698 */ |
776 */ |
699 void CntHistoryModelPrivate::messageAdded(MsgItem& msg) |
777 void CntHistoryModelPrivate::messageAdded(MsgItem& msg) |
700 { |
778 { |
|
779 CNT_ENTRY |
|
780 |
701 Q_Q(CntHistoryModel); |
781 Q_Q(CntHistoryModel); |
702 |
782 |
703 int oldRowCount = rowCount(); |
783 q->doBeginInsertRows( QModelIndex(), rowCount(), rowCount() ); |
704 |
784 |
705 // Create a new hst item |
785 // Create a new hst item |
706 HItemPointer item(new HistoryItem()); |
786 HItemPointer item(new HistoryItem()); |
707 |
787 |
708 // Parse the MsgItem and add data into hst item |
788 // Parse the MsgItem and add data into hst item |
712 m_msgMap.insert( msg.id(), item ); |
792 m_msgMap.insert( msg.id(), item ); |
713 |
793 |
714 // Append the hst item to our list |
794 // Append the hst item to our list |
715 m_List.append( item ); |
795 m_List.append( item ); |
716 |
796 |
717 q->doBeginInsertRows( QModelIndex(), oldRowCount, rowCount() ); |
|
718 q->doEndInsertRows(); |
797 q->doEndInsertRows(); |
|
798 |
|
799 CNT_EXIT |
719 } |
800 } |
720 |
801 |
721 /*! |
802 /*! |
722 * Slot to update a message from the messages model |
803 * Slot to update a message from the messages model |
723 * |
804 * |
724 * \param event Message event |
805 * \param event Message event |
725 * \param item Conversation history item |
806 * \param item Conversation history item |
726 */ |
807 */ |
727 void CntHistoryModelPrivate::messageChanged(MsgItem& msg) |
808 void CntHistoryModelPrivate::messageChanged(MsgItem& msg) |
728 { |
809 { |
|
810 CNT_ENTRY |
|
811 |
729 Q_Q(CntHistoryModel); |
812 Q_Q(CntHistoryModel); |
730 |
813 |
731 // Fetch the hst item that maps to this MsgItem |
814 // Fetch the hst item that maps to this MsgItem |
732 HItemPointer p = m_msgMap.value( msg.id() ); |
815 HItemPointer p = m_msgMap.value( msg.id() ); |
733 |
816 |
740 |
823 |
741 // Get the index of the the hst item in the list |
824 // Get the index of the the hst item in the list |
742 int pIndex = m_List.indexOf( p ); |
825 int pIndex = m_List.indexOf( p ); |
743 |
826 |
744 q->doDataChanged(q->index(pIndex, 0), q->index(pIndex, 0)); |
827 q->doDataChanged(q->index(pIndex, 0), q->index(pIndex, 0)); |
|
828 |
|
829 CNT_EXIT |
745 } |
830 } |
746 |
831 |
747 /*! |
832 /*! |
748 * Slot to delete a message from the messages model |
833 * Slot to delete a message from the messages model |
749 * |
834 * |
750 * \param event Message event |
835 * \param event Message event |
751 * \param item Conversation history item |
836 * \param item Conversation history item |
752 */ |
837 */ |
753 void CntHistoryModelPrivate::messageDeleted(MsgItem& msg) |
838 void CntHistoryModelPrivate::messageDeleted(MsgItem& msg) |
754 { |
839 { |
|
840 CNT_ENTRY |
|
841 |
755 Q_Q(CntHistoryModel); |
842 Q_Q(CntHistoryModel); |
756 |
843 |
757 // Fetch the hst item that maps to this MsgItem |
844 // Fetch the hst item that maps to this MsgItem |
758 HItemPointer p = m_msgMap.value( msg.id() ); |
845 HItemPointer p = m_msgMap.value( msg.id() ); |
759 |
846 |
763 |
850 |
764 // Remove the item in stored containers |
851 // Remove the item in stored containers |
765 m_msgMap.remove( msg.id() ); |
852 m_msgMap.remove( msg.id() ); |
766 int index = m_List.indexOf( p ); |
853 int index = m_List.indexOf( p ); |
767 if ( index > -1 ) { |
854 if ( index > -1 ) { |
|
855 q->doBeginRemoveRows(QModelIndex(), index, index); |
768 m_List.removeAt( index ); |
856 m_List.removeAt( index ); |
769 q->doBeginRemoveRows(QModelIndex(), index, index); |
|
770 q->doEndRemoveRows(); |
857 q->doEndRemoveRows(); |
771 } |
858 } |
772 } |
859 |
|
860 CNT_EXIT |
|
861 } |