52 QString unnamed = hbTrId("txt_phob_dblist_unnamed"); |
62 QString unnamed = hbTrId("txt_phob_dblist_unnamed"); |
53 QString noFavs = hbTrId("txt_phob_dblist_favorites_val_no_favorites_selecte"); |
63 QString noFavs = hbTrId("txt_phob_dblist_favorites_val_no_favorites_selecte"); |
54 QString noMembers = hbTrId("txt_phob_dblist_val_no_members_selected"); |
64 QString noMembers = hbTrId("txt_phob_dblist_val_no_members_selected"); |
55 mThread = new CntCollectionListModelWorker(unnamed, noFavs, noMembers, order); |
65 mThread = new CntCollectionListModelWorker(unnamed, noFavs, noMembers, order); |
56 |
66 |
57 connect(mThread, SIGNAL(fetchDone(int, const QString&, int)), this, SLOT(informationUpdated(int, const QString&, int))); |
67 connect(mThread, SIGNAL(fetchDone(int, const QString&, const QList<int>&)), this, |
|
68 SLOT(informationUpdated(int, const QString&, const QList<int>&))); |
58 connect(d->mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void *, int, int)), |
69 connect(d->mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void *, int, int)), |
59 this, SLOT(onIconReady(QPixmap, void *, int, int))); |
70 this, SLOT(onIconReady(QPixmap, void *, int, int))); |
60 |
71 |
61 doConstruct(); |
72 doConstruct(); |
62 |
73 |
188 /*! |
201 /*! |
189 Remove given group from the model. Ignore plugin groups. |
202 Remove given group from the model. Ignore plugin groups. |
190 |
203 |
191 \param localId QContactLocalId of the group that should be removed |
204 \param localId QContactLocalId of the group that should be removed |
192 */ |
205 */ |
193 void CntCollectionListModel::removeGroup(int localId) |
206 bool CntCollectionListModel::removeGroup(int localId) |
194 { |
207 { |
195 CNT_ENTRY |
208 CNT_ENTRY_ARGS(localId) |
|
209 |
|
210 bool groupRemoved = false; |
196 |
211 |
197 for (int i = 0;i < rowCount();i++) |
212 for (int i = 0;i < rowCount();i++) |
198 { |
213 { |
199 if (!d->mList.at(i)->isPlugin && d->mList.at(i)->id == localId) |
214 if (!d->mList.at(i)->isPlugin && d->mList.at(i)->id == localId) |
200 { |
215 { |
201 removeRow(i); |
216 removeRow(i); |
|
217 groupRemoved = true; |
202 break; |
218 break; |
203 } |
219 } |
204 } |
220 } |
205 |
221 |
206 CNT_EXIT |
222 CNT_EXIT_ARGS(groupRemoved) |
|
223 |
|
224 return groupRemoved; |
207 } |
225 } |
208 |
226 |
209 /*! |
227 /*! |
210 Add a new group to the model. This also takes care of putting it in the |
228 Add a new group to the model. This also takes care of putting it in the |
211 correct row. |
229 correct row. |
212 |
230 |
213 \param localId QContactLocalId of the group that should be added |
231 \param localId QContactLocalId of the group that should be added |
214 */ |
232 */ |
215 void CntCollectionListModel::addGroup(int localId) |
233 void CntCollectionListModel::addGroup(int localId) |
216 { |
234 { |
217 CNT_ENTRY |
235 CNT_ENTRY_ARGS(localId) |
218 |
236 |
219 QContactDetailFilter groupFilter; |
237 QContactDetailFilter groupFilter; |
220 groupFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType); |
238 groupFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType); |
221 groupFilter.setValue(QString(QLatin1String(QContactType::TypeGroup))); |
239 groupFilter.setValue(QString(QLatin1String(QContactType::TypeGroup))); |
222 |
240 |
310 \param row the row of the activated plugin item |
328 \param row the row of the activated plugin item |
311 \return view parameters used for view switching |
329 \return view parameters used for view switching |
312 */ |
330 */ |
313 CntViewParameters CntCollectionListModel::extensionGroupActivated(int row) |
331 CntViewParameters CntCollectionListModel::extensionGroupActivated(int row) |
314 { |
332 { |
|
333 CNT_ENTRY_ARGS(row) |
|
334 |
315 CntViewParameters params; |
335 CntViewParameters params; |
316 for(int i = 0;i < d->mExtensions.value(row)->groupCount();i++) |
336 for(int i = 0;i < d->mExtensions.value(row)->groupCount();i++) |
317 { |
337 { |
318 CntUiExtensionGroup& group = d->mExtensions.value(row)->groupAt(i); |
338 CntUiExtensionGroup& group = d->mExtensions.value(row)->groupAt(i); |
319 if (group.serviceId() == d->mList.at(row)->id) |
339 if (group.serviceId() == d->mList.at(row)->id) |
320 { |
340 { |
321 group.activated(params); |
341 group.activated(params); |
322 break; |
342 break; |
323 } |
343 } |
324 } |
344 } |
|
345 |
|
346 CNT_EXIT_ARGS(params) |
|
347 |
325 return params; |
348 return params; |
326 } |
349 } |
327 |
350 |
328 /*! |
351 /*! |
329 Called when a list item from a plugin is long pressed. Callback is done asynch, as HbMenu usage |
352 Called when a list item from a plugin is long pressed. Callback is done asynch, as HbMenu usage |
377 CNT_ENTRY |
407 CNT_ENTRY |
378 |
408 |
379 initializeStaticGroups(); |
409 initializeStaticGroups(); |
380 initializeExtensions(); |
410 initializeExtensions(); |
381 initializeUserGroups(); |
411 initializeUserGroups(); |
|
412 |
|
413 connect(d->mContactManager, SIGNAL(contactsAdded(const QList<QContactLocalId>&)), this, SLOT(handleAdded(const QList<QContactLocalId>&))); |
|
414 connect(d->mContactManager, SIGNAL(contactsChanged(const QList<QContactLocalId>&)), this, SLOT(handleChanged(const QList<QContactLocalId>&))); |
|
415 connect(d->mContactManager, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), this, SLOT(handleRemoved(const QList<QContactLocalId>&))); |
|
416 connect(d->mContactManager, SIGNAL(relationshipsAdded(const QList<QContactLocalId>&)), this, SLOT(handleAddedRelationship(const QList<QContactLocalId>&))); |
|
417 connect(d->mContactManager, SIGNAL(relationshipsRemoved(const QList<QContactLocalId>&)), this, SLOT(handleRemovedRelationship(const QList<QContactLocalId>&))); |
|
418 |
382 |
419 |
383 CNT_EXIT |
420 CNT_EXIT |
384 } |
421 } |
385 |
422 |
386 /*! |
423 /*! |
578 |
623 |
579 \param row the row receiving the updated information |
624 \param row the row receiving the updated information |
580 \param secondRowText text to be shown in the second row |
625 \param secondRowText text to be shown in the second row |
581 \param memberCount the amount of members the group has (shown in text-3 in HbListViewItem) |
626 \param memberCount the amount of members the group has (shown in text-3 in HbListViewItem) |
582 */ |
627 */ |
583 void CntCollectionListModel::informationUpdated(int id, const QString& secondRowText, int memberCount) |
628 void CntCollectionListModel::informationUpdated(int id, const QString& secondRowText, const QList<int>& members) |
584 { |
629 { |
585 CNT_ENTRY |
630 CNT_ENTRY_ARGS(id << secondRowText << members) |
586 |
631 |
587 for (int i = 0;i < d->mList.count();i++) |
632 for (int i = 0;i < d->mList.count();i++) |
588 { |
633 { |
589 if (d->mList.at(i)->id == id && !d->mList.at(i)->isPlugin) |
634 if (d->mList.at(i)->id == id && !d->mList.at(i)->isPlugin) |
590 { |
635 { |
591 CollectionItemPointer item = d->mList.at(i); |
636 CollectionItemPointer item = d->mList.at(i); |
592 |
637 |
593 item->secondLineText = secondRowText; |
638 item->secondLineText = secondRowText; |
594 item->memberCount = memberCount; |
639 item->memberCount = members.count(); |
|
640 item->members = members; |
595 |
641 |
596 int idx = d->mList.indexOf(item); |
642 int idx = d->mList.indexOf(item); |
597 emit dataChanged(index(idx, 0), index(idx, 0)); |
643 emit dataChanged(index(idx, 0), index(idx, 0)); |
598 |
644 |
599 break; |
645 break; |
691 d->mList.insert(1 + j, item); |
739 d->mList.insert(1 + j, item); |
692 } |
740 } |
693 |
741 |
694 endInsertRows(); |
742 endInsertRows(); |
695 } |
743 } |
696 } |
744 |
|
745 CNT_EXIT |
|
746 } |
|
747 |
|
748 void CntCollectionListModel::handleAdded(const QList<QContactLocalId>& contactIds) |
|
749 { |
|
750 CNT_ENTRY_ARGS(contactIds) |
|
751 |
|
752 if (contactIds.count() == 1) |
|
753 { |
|
754 QContactFetchHint noRelationshipsFetchHint; |
|
755 noRelationshipsFetchHint.setOptimizationHints(QContactFetchHint::NoRelationships); |
|
756 |
|
757 QContact contact = d->mContactManager->contact(contactIds.first(), noRelationshipsFetchHint); |
|
758 |
|
759 if (contact.type() == QContactType::TypeGroup) |
|
760 { |
|
761 addGroup(contactIds.first()); |
|
762 emit groupCountChanged(); |
|
763 } |
|
764 } |
|
765 else |
|
766 { |
|
767 QList<QContact> addedGroups; |
|
768 |
|
769 foreach (QContactLocalId id, contactIds) |
|
770 { |
|
771 QContactFetchHint noRelationshipsFetchHint; |
|
772 noRelationshipsFetchHint.setOptimizationHints(QContactFetchHint::NoRelationships); |
|
773 |
|
774 QContact contact = d->mContactManager->contact(id, noRelationshipsFetchHint); |
|
775 |
|
776 if (contact.type() == QContactType::TypeGroup) |
|
777 { |
|
778 addedGroups << contact; |
|
779 } |
|
780 } |
|
781 |
|
782 if (addedGroups.count() == 1) |
|
783 { |
|
784 addGroup(addedGroups.first().localId()); |
|
785 emit groupCountChanged(); |
|
786 } |
|
787 else if (addedGroups.count() > 1) |
|
788 { |
|
789 qSort(addedGroups.begin(), addedGroups.end(), caseInsensitiveLessThan); |
|
790 |
|
791 foreach (QContact c, addedGroups) |
|
792 { |
|
793 addGroup(c.localId()); |
|
794 } |
|
795 emit groupCountChanged(); |
|
796 } |
|
797 } |
|
798 |
|
799 CNT_EXIT |
|
800 } |
|
801 |
|
802 void CntCollectionListModel::handleRemoved(const QList<QContactLocalId>& contactIds) |
|
803 { |
|
804 CNT_ENTRY_ARGS(contactIds) |
|
805 |
|
806 foreach (QContactLocalId id, contactIds) |
|
807 { |
|
808 if (removeGroup(id)) |
|
809 { |
|
810 emit groupCountChanged(); |
|
811 } |
|
812 else |
|
813 { |
|
814 for (int i = 0;i < d->mList.count();i++) |
|
815 { |
|
816 if (d->mList.at(i)->members.contains(id)) |
|
817 { |
|
818 CollectionItemPointer item = d->mList.at(i); |
|
819 |
|
820 item->fetched = false; |
|
821 |
|
822 int idx = d->mList.indexOf(item); |
|
823 emit dataChanged(index(idx, 0), index(idx, 0)); |
|
824 } |
|
825 } |
|
826 } |
|
827 } |
|
828 |
|
829 CNT_EXIT |
|
830 } |
|
831 |
|
832 void CntCollectionListModel::handleChanged(const QList<QContactLocalId>& contactIds) |
|
833 { |
|
834 CNT_ENTRY_ARGS(contactIds) |
|
835 |
|
836 foreach (QContactLocalId id, contactIds) |
|
837 { |
|
838 QContact contact = d->mContactManager->contact(id); |
|
839 |
|
840 if (contact.type() == QContactType::TypeGroup) |
|
841 { |
|
842 for (int i = 0;i < d->mList.count();i++) |
|
843 { |
|
844 if (d->mList.at(i)->id == id && !d->mList.at(i)->isPlugin) |
|
845 { |
|
846 CollectionItemPointer item = d->mList.at(i); |
|
847 |
|
848 QContactName contactName = contact.detail<QContactName>(); |
|
849 QString groupName = contactName.customLabel(); |
|
850 |
|
851 if (groupName != item->groupName) |
|
852 { |
|
853 if (groupName.isNull()) |
|
854 { |
|
855 item->groupName = hbTrId("txt_phob_dblist_unnamed"); |
|
856 } |
|
857 else |
|
858 { |
|
859 item->groupName = groupName; |
|
860 } |
|
861 |
|
862 int idx = d->mList.indexOf(item); |
|
863 emit dataChanged(index(idx, 0), index(idx, 0)); |
|
864 } |
|
865 |
|
866 break; |
|
867 } |
|
868 } |
|
869 } |
|
870 else if (contact.type() == QContactType::TypeContact) |
|
871 { |
|
872 for (int i = 0;i < d->mList.count();i++) |
|
873 { |
|
874 if (d->mList.at(i)->members.contains(id)) |
|
875 { |
|
876 CollectionItemPointer item = d->mList.at(i); |
|
877 |
|
878 item->fetched = false; |
|
879 |
|
880 int idx = d->mList.indexOf(item); |
|
881 emit dataChanged(index(idx, 0), index(idx, 0)); |
|
882 } |
|
883 } |
|
884 } |
|
885 } |
|
886 |
|
887 CNT_EXIT |
|
888 } |
|
889 |
|
890 void CntCollectionListModel::handleAddedRelationship(const QList<QContactLocalId>& contactIds) |
|
891 { |
|
892 CNT_ENTRY_ARGS(contactIds) |
|
893 |
|
894 foreach (QContactLocalId id, contactIds) |
|
895 { |
|
896 for (int i = 0;i < d->mList.count();i++) |
|
897 { |
|
898 if (d->mList.at(i)->id == id && !d->mList.at(i)->isPlugin) |
|
899 { |
|
900 CollectionItemPointer item = d->mList.at(i); |
|
901 |
|
902 item->fetched = false; |
|
903 |
|
904 int idx = d->mList.indexOf(item); |
|
905 emit dataChanged(index(idx, 0), index(idx, 0)); |
|
906 |
|
907 break; |
|
908 } |
|
909 } |
|
910 } |
|
911 |
|
912 CNT_EXIT |
|
913 } |
|
914 |
|
915 void CntCollectionListModel::handleRemovedRelationship(const QList<QContactLocalId>& contactIds) |
|
916 { |
|
917 CNT_ENTRY_ARGS(contactIds) |
|
918 |
|
919 foreach (QContactLocalId id, contactIds) |
|
920 { |
|
921 for (int i = 0;i < d->mList.count();i++) |
|
922 { |
|
923 if (d->mList.at(i)->id == id && !d->mList.at(i)->isPlugin) |
|
924 { |
|
925 CollectionItemPointer item = d->mList.at(i); |
|
926 |
|
927 item->fetched = false; |
|
928 |
|
929 int idx = d->mList.indexOf(item); |
|
930 emit dataChanged(index(idx, 0), index(idx, 0)); |
|
931 |
|
932 break; |
|
933 } |
|
934 } |
|
935 } |
|
936 |
|
937 CNT_EXIT |
|
938 } |