15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <HbIcon> |
18 #include <HbIcon> |
19 |
19 |
|
20 #include "caclient_defines.h" |
20 #include "caitemmodel.h" |
21 #include "caitemmodel.h" |
21 #include "caitemmodel_p.h" |
22 #include "caitemmodel_p.h" |
22 #include "canotifier.h" |
23 #include "canotifier.h" |
23 #include "canotifierfilter.h" |
24 #include "canotifierfilter.h" |
24 #include "caclienttest_global.h" |
25 #include "caclienttest_global.h" |
467 break; |
468 break; |
468 case CaItemModel::FullTextRole: |
469 case CaItemModel::FullTextRole: |
469 variant = QVariant(entry(modelIndex)->text() + QString(" ") |
470 variant = QVariant(entry(modelIndex)->text() + QString(" ") |
470 + entry(modelIndex)->description()); |
471 + entry(modelIndex)->description()); |
471 break; |
472 break; |
|
473 case CaItemModel::UninstalRole: |
|
474 variant = QVariant(entry(modelIndex)->attribute(UNINSTALL_PROGRESS_APPLICATION_ATTRIBUTE_NAME).toInt()); |
|
475 break; |
472 default: |
476 default: |
473 variant = QVariant(QVariant::Invalid); |
477 variant = QVariant(QVariant::Invalid); |
474 } |
478 } |
475 } |
479 } |
476 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::data"); |
480 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::data"); |
697 |
701 |
698 } |
702 } |
699 |
703 |
700 /*! |
704 /*! |
701 Updates model item with fresh data |
705 Updates model item with fresh data |
702 \param id id of item to update |
706 \param entry item to update |
703 */ |
707 */ |
704 void CaItemModelPrivate::updateItemData(int id) |
708 void CaItemModelPrivate::updateItemData(const QSharedPointer<CaEntry> &entry) |
705 { |
709 { |
706 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateItemData"); |
710 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateItemData"); |
707 |
711 |
708 mEntries.updateEntry(id); |
712 |
709 |
713 int id = entry->id(); |
710 QList<int> ids = mService->getEntryIds(mQuery); |
714 QList<int> ids = mService->getEntryIds(mQuery); |
711 if (mEntries.indexOf(id) >= 0 |
715 if (mEntries.indexOf(id) >= 0 |
712 && ids.indexOf(id) == mEntries.indexOf(id)) { |
716 && ids.indexOf(id) == mEntries.indexOf(id)) { |
713 emit m_q->dataChanged(index(mEntries.indexOf(id)), index( |
717 mEntries.updateEntry(entry); |
714 mEntries.indexOf(id))); |
718 emit m_q->dataChanged( |
|
719 index(mEntries.indexOf(id)), index(mEntries.indexOf(id))); |
715 } else if (mParentEntry && id == mParentEntry->id()) { |
720 } else if (mParentEntry && id == mParentEntry->id()) { |
716 updateParentEntry(); |
721 updateParentEntry(); |
717 m_q->reset(); |
722 m_q->reset(); |
|
723 } else if (ids.indexOf(id) < 0) { |
|
724 removeItem(id); |
|
725 } else if (mEntries.indexOf(id) < 0) { |
|
726 addItem(id); |
718 } else { |
727 } else { |
719 updateModel(); |
728 updateModel(); |
720 } |
729 } |
721 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateItemData"); |
730 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateItemData"); |
722 } |
731 } |
909 Connects slots |
918 Connects slots |
910 */ |
919 */ |
911 void CaItemModelPrivate::connectSlots() |
920 void CaItemModelPrivate::connectSlots() |
912 { |
921 { |
913 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::connectSlots"); |
922 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::connectSlots"); |
914 connect(mNotifier, SIGNAL(entryChanged(int,ChangeType)), |
923 connect(mNotifier, SIGNAL(entryChanged(CaEntry ,ChangeType)), |
915 this, SLOT(updateModelItem(int,ChangeType))); |
924 this, SLOT(updateModelItem(CaEntry, ChangeType))); |
916 |
925 |
917 if (mQuery.parentId() > 0) { |
926 if (mQuery.parentId() > 0) { |
918 connect(mNotifier, SIGNAL(groupContentChanged(int)), |
927 connect(mNotifier, SIGNAL(groupContentChanged(int)), |
919 this, SLOT(updateModelContent(int))); |
928 this, SLOT(updateModelContent(int))); |
920 } |
929 } |
925 Disconnects slots |
934 Disconnects slots |
926 */ |
935 */ |
927 void CaItemModelPrivate::disconnectSlots() |
936 void CaItemModelPrivate::disconnectSlots() |
928 { |
937 { |
929 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::disconnectSlots"); |
938 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::disconnectSlots"); |
930 disconnect(mNotifier, SIGNAL(entryChanged(int,ChangeType)), |
939 disconnect(mNotifier, SIGNAL(entryChanged(CaEntry ,ChangeType)), |
931 this, SLOT(updateModelItem(int,ChangeType))); |
940 this, SLOT(updateModelItem(CaEntry, ChangeType))); |
932 if (mQuery.parentId() > 0) { |
941 if (mQuery.parentId() > 0) { |
933 disconnect(mNotifier, SIGNAL(groupContentChanged(int)), |
942 disconnect(mNotifier, SIGNAL(groupContentChanged(int)), |
934 this, SLOT(updateModelContent(int))); |
943 this, SLOT(updateModelContent(int))); |
935 } |
944 } |
936 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::disconnectSlots"); |
945 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::disconnectSlots"); |
950 /*! |
959 /*! |
951 Updates model with fresh entries |
960 Updates model with fresh entries |
952 \param id of item to handle |
961 \param id of item to handle |
953 \param changeType change type |
962 \param changeType change type |
954 */ |
963 */ |
955 void CaItemModelPrivate::updateModelItem(int id, ChangeType changeType) |
964 void CaItemModelPrivate::updateModelItem( |
|
965 const CaEntry &entry, ChangeType changeType) |
956 { |
966 { |
957 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateModelItem"); |
967 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateModelItem"); |
|
968 QSharedPointer<CaEntry> sharedEntry(new CaEntry(entry)); |
958 int previousCount = rowCount(); |
969 int previousCount = rowCount(); |
959 switch (changeType) { |
970 switch (changeType) { |
960 case AddChangeType: |
971 case AddChangeType: |
961 addItem(id); |
972 addItem(sharedEntry->id()); |
962 break; |
973 break; |
963 case RemoveChangeType: |
974 case RemoveChangeType: |
964 removeItem(id); |
975 removeItem(sharedEntry->id()); |
965 break; |
976 break; |
966 default: |
977 default: |
967 updateItemData(id); |
978 updateItemData(sharedEntry); |
968 break; |
979 break; |
969 } |
980 } |
970 emitEmpty(previousCount); |
981 emitEmpty(previousCount); |
971 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateModelItem"); |
982 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateModelItem"); |
972 } |
983 } |
973 |
984 |