29 #include "videosortfilterproxymodel.h" |
29 #include "videosortfilterproxymodel.h" |
30 #include "videolistdatamodel.h" |
30 #include "videolistdatamodel.h" |
31 #include "videocollectionclient.h" |
31 #include "videocollectionclient.h" |
32 #include "videocollectionwrapper.h" |
32 #include "videocollectionwrapper.h" |
33 #include "videocollectiontrace.h" |
33 #include "videocollectiontrace.h" |
|
34 |
|
35 const TMPXItemId INVALID_ID = TMPXItemId::InvalidId(); |
34 |
36 |
35 // ----------------------------------------------------------------------------- |
37 // ----------------------------------------------------------------------------- |
36 // VideoSortFilterProxyModel::VideoSortFilterProxyModel |
38 // VideoSortFilterProxyModel::VideoSortFilterProxyModel |
37 // ----------------------------------------------------------------------------- |
39 // ----------------------------------------------------------------------------- |
38 // |
40 // |
94 // ----------------------------------------------------------------------------- |
96 // ----------------------------------------------------------------------------- |
95 // |
97 // |
96 bool VideoSortFilterProxyModel::connectSignals() |
98 bool VideoSortFilterProxyModel::connectSignals() |
97 { |
99 { |
98 FUNC_LOG_ADDR(this); |
100 FUNC_LOG_ADDR(this); |
99 if(!connect(mModel, SIGNAL(modelReady()), |
101 |
100 this, SIGNAL(modelReady()))) |
|
101 { |
|
102 return false; |
|
103 } |
|
104 if(!connect(mModel, SIGNAL(modelChanged()), |
102 if(!connect(mModel, SIGNAL(modelChanged()), |
105 this, SIGNAL(modelChanged()))) |
103 this, SLOT(invalidate()))) |
106 { |
104 { |
107 return false; |
105 return false; |
108 } |
106 } |
109 if(mType == VideoCollectionCommon::EModelTypeCollectionContent) |
107 if(mType == VideoCollectionCommon::EModelTypeCollectionContent) |
110 { |
108 { |
112 this, SLOT(albumChangedSlot()))) |
110 this, SLOT(albumChangedSlot()))) |
113 { |
111 { |
114 return false; |
112 return false; |
115 } |
113 } |
116 } |
114 } |
117 if(mType == VideoCollectionCommon::EModelTypeCollections) |
115 |
118 { |
|
119 if(!connect(mModel, SIGNAL(itemModified(const TMPXItemId &)), |
|
120 this, SLOT(itemModifiedSlot(const TMPXItemId &)))) |
|
121 { |
|
122 return false; |
|
123 } |
|
124 } |
|
125 return true; |
116 return true; |
126 } |
117 } |
127 |
118 |
128 // ----------------------------------------------------------------------------- |
119 // ----------------------------------------------------------------------------- |
129 // VideoSortFilterProxyModel::disconnectSignals |
120 // VideoSortFilterProxyModel::disconnectSignals |
130 // ----------------------------------------------------------------------------- |
121 // ----------------------------------------------------------------------------- |
131 // |
122 // |
132 void VideoSortFilterProxyModel::disconnectSignals() |
123 void VideoSortFilterProxyModel::disconnectSignals() |
133 { |
124 { |
134 FUNC_LOG_ADDR(this); |
125 FUNC_LOG_ADDR(this); |
135 disconnect(mModel, SIGNAL(modelReady()), this, SIGNAL(modelReady())); |
126 disconnect(mModel, SIGNAL(modelChanged()), this, SLOT(invalidate())); |
136 disconnect(mModel, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); |
|
137 if(mType == VideoCollectionCommon::EModelTypeCollectionContent) |
127 if(mType == VideoCollectionCommon::EModelTypeCollectionContent) |
138 { |
128 { |
139 disconnect(mModel, SIGNAL(albumChanged()), this, SLOT(albumChangedSlot())); |
129 disconnect(mModel, SIGNAL(albumChanged()), this, SLOT(albumChangedSlot())); |
140 } |
130 } |
141 if(mType == VideoCollectionCommon::EModelTypeCollections) |
131 if(mType == VideoCollectionCommon::EModelTypeCollections) |
156 |
146 |
157 if(!mCollectionClient) |
147 if(!mCollectionClient) |
158 { |
148 { |
159 return -1; |
149 return -1; |
160 } |
150 } |
161 |
151 |
162 if(mLevel != level) |
152 if(mLevel != level) |
163 { |
153 { |
164 INFO_1("VideoSortFilterProxyModel::open() [0x%x] opening different level, invalidating.", this); |
154 INFO_1("VideoSortFilterProxyModel::open() [0x%x] opening different level, invalidating.", this); |
165 mLevel = level; |
155 mLevel = level; |
166 invalidateFilter(); |
156 invalidateFilter(); |
|
157 // sorting call required here to setup correct sort order in cases where source model allready |
|
158 // contains items but proxy is not yet updated. (invalidate -call does not work since it updates proxy and |
|
159 // calls sort in different order for us to use) |
|
160 sort(0, mWantedSortOrder); |
167 } |
161 } |
168 // need to call open every time to make sure all items are |
162 // need to call open every time to make sure all items are |
169 // inserted to UI ( recent open might have been cancelled) |
163 // inserted to UI ( recent open might have been cancelled) |
170 return mCollectionClient->startOpenCollection(level); |
164 return mCollectionClient->startOpenCollection(level); |
171 } |
165 } |
239 // ----------------------------------------------------------------------------- |
233 // ----------------------------------------------------------------------------- |
240 // |
234 // |
241 int VideoSortFilterProxyModel::deleteItems(const QModelIndexList &indexList) |
235 int VideoSortFilterProxyModel::deleteItems(const QModelIndexList &indexList) |
242 { |
236 { |
243 FUNC_LOG_ADDR(this); |
237 FUNC_LOG_ADDR(this); |
|
238 |
|
239 // Disable thumbnail fetching while items are removed from the model. |
|
240 VideoThumbnailData::instance().enableBackgroundFetching(false); |
|
241 |
244 if(mModel) |
242 if(mModel) |
245 { |
243 { |
246 QModelIndexList mappedList; |
244 QModelIndexList mappedList; |
247 for(int i = 0; i < indexList.count(); ++i) |
245 for(int i = 0; i < indexList.count(); ++i) |
248 { |
246 { |
250 } |
248 } |
251 |
249 |
252 if(mModel->removeRows(mappedList)) |
250 if(mModel->removeRows(mappedList)) |
253 { |
251 { |
254 // Start fetching thumbnails at start of the model. |
252 // Start fetching thumbnails at start of the model. |
|
253 VideoThumbnailData::instance().enableBackgroundFetching(true); |
255 VideoThumbnailData::instance().startBackgroundFetching(0, 0); |
254 VideoThumbnailData::instance().startBackgroundFetching(0, 0); |
256 return 0; |
255 return 0; |
257 } |
256 } |
258 } |
257 } |
|
258 |
|
259 VideoThumbnailData::instance().enableBackgroundFetching(true); |
259 return -1; |
260 return -1; |
260 } |
261 } |
261 |
262 |
262 // ----------------------------------------------------------------------------- |
263 // ----------------------------------------------------------------------------- |
263 // VideoSortFilterProxyModel::openItem |
264 // VideoSortFilterProxyModel::openItem |
274 { |
275 { |
275 mLevel = VideoCollectionCommon::ELevelAlbum; |
276 mLevel = VideoCollectionCommon::ELevelAlbum; |
276 mModel->setAlbumInUse(mediaId); |
277 mModel->setAlbumInUse(mediaId); |
277 INFO_1("VideoSortFilterProxyModel::open() [0x%x] opening album or category, invalidating.", this); |
278 INFO_1("VideoSortFilterProxyModel::open() [0x%x] opening album or category, invalidating.", this); |
278 invalidateFilter(); |
279 invalidateFilter(); |
|
280 // sorting call required here to setup correct sort order in cases where source model allready |
|
281 // contains items but proxy is not yet updated. (invalidate -call does not work since it updates proxy and |
|
282 // calls sort in different order for us to use) |
|
283 sort(0, mWantedSortOrder); |
279 } |
284 } |
280 return 0; |
285 return 0; |
281 } |
286 } |
282 } |
287 } |
283 return -1; |
288 return -1; |
369 { |
374 { |
370 if (!mModel) |
375 if (!mModel) |
371 { |
376 { |
372 return false; |
377 return false; |
373 } |
378 } |
374 TMPXItemId leftId = mModel->mediaIdAtIndex(left.row()); |
379 int index = left.row(); |
375 TMPXItemId rightId = mModel->mediaIdAtIndex(right.row()); |
380 TMPXItemId leftId = mModel->mediaIdAtIndex(index); |
|
381 index = right.row(); |
|
382 TMPXItemId rightId = mModel->mediaIdAtIndex(index); |
376 |
383 |
377 // Default categories are always first in the following order: |
384 // Default categories are always first in the following order: |
378 // Recently played (missing currently) |
385 // Recently played (missing currently) |
379 // Captured |
386 // Captured |
380 // Downloaded |
387 // Downloaded |
521 |
528 |
522 // ----------------------------------------------------------------------------- |
529 // ----------------------------------------------------------------------------- |
523 // VideoSortFilterProxyModel::getMediaIdAtIndex() |
530 // VideoSortFilterProxyModel::getMediaIdAtIndex() |
524 // ----------------------------------------------------------------------------- |
531 // ----------------------------------------------------------------------------- |
525 // |
532 // |
526 TMPXItemId VideoSortFilterProxyModel::getMediaIdAtIndex(const QModelIndex &index) const |
533 const TMPXItemId& VideoSortFilterProxyModel::getMediaIdAtIndex(const QModelIndex &index) const |
527 { |
534 { |
528 TMPXItemId mpxId = TMPXItemId::InvalidId(); |
|
529 if(index.isValid()) |
535 if(index.isValid()) |
530 { |
536 { |
531 QModelIndex sourceIndex = mapToSource(index); |
537 int rowIndex = mapToSource(index).row(); |
532 if(mModel && sourceIndex.isValid()) |
538 if(mModel) |
533 { |
539 { |
534 mpxId = mModel->mediaIdAtIndex(sourceIndex.row()); |
540 return mModel->mediaIdAtIndex(rowIndex); |
535 } |
541 } |
536 } |
542 } |
537 return mpxId; |
543 return INVALID_ID; |
538 } |
544 } |
539 |
545 |
540 // ----------------------------------------------------------------------------- |
546 // ----------------------------------------------------------------------------- |
541 // VideoSortFilterProxyModel::indexOfId() |
547 // VideoSortFilterProxyModel::indexOfId() |
542 // ----------------------------------------------------------------------------- |
548 // ----------------------------------------------------------------------------- |
543 // |
549 // |
544 QModelIndex VideoSortFilterProxyModel::indexOfId(TMPXItemId id) |
550 QModelIndex VideoSortFilterProxyModel::indexOfId(const TMPXItemId &id) |
545 { |
551 { |
546 QModelIndex sourceIndex; |
552 QModelIndex sourceIndex; |
547 if(!mModel || id == TMPXItemId::InvalidId()) |
553 if(!mModel || id == TMPXItemId::InvalidId()) |
548 { |
554 { |
549 return sourceIndex; |
555 return sourceIndex; |
554 |
560 |
555 // ----------------------------------------------------------------------------- |
561 // ----------------------------------------------------------------------------- |
556 // VideoSortFilterProxyModel::getMediaFilePathForId() |
562 // VideoSortFilterProxyModel::getMediaFilePathForId() |
557 // ----------------------------------------------------------------------------- |
563 // ----------------------------------------------------------------------------- |
558 // |
564 // |
559 QString VideoSortFilterProxyModel::getMediaFilePathForId(TMPXItemId mediaId) |
565 QString VideoSortFilterProxyModel::getMediaFilePathForId(const TMPXItemId &mediaId) |
560 { |
566 { |
561 QString filePath; |
567 QString filePath; |
562 if(mModel) |
568 if(mModel) |
563 { |
569 { |
564 filePath = mModel->mediaFilePathForId(mediaId); |
570 filePath = mModel->mediaFilePathForId(mediaId); |
690 int VideoSortFilterProxyModel::removeItemsFromAlbum(TMPXItemId &albumId, |
696 int VideoSortFilterProxyModel::removeItemsFromAlbum(TMPXItemId &albumId, |
691 const QList<TMPXItemId> &mediaIds) |
697 const QList<TMPXItemId> &mediaIds) |
692 { |
698 { |
693 FUNC_LOG_ADDR(this); |
699 FUNC_LOG_ADDR(this); |
694 int err(-1); |
700 int err(-1); |
695 |
701 |
|
702 // Disable thumbnail fetching while items are removed from the model. |
|
703 VideoThumbnailData::instance().enableBackgroundFetching(false); |
|
704 |
696 if (mModel) |
705 if (mModel) |
697 { |
706 { |
698 // remove items in album |
707 // remove items in album |
699 err = mModel->removeItemsFromAlbum(albumId, mediaIds); |
708 err = mModel->removeItemsFromAlbum(albumId, mediaIds); |
700 if(err > 0) |
709 if(err > 0) |
701 { |
710 { |
702 // if there really were items to be removed, invalid filter |
711 // if there really were items to be removed, invalid filter |
703 INFO_1("VideoSortFilterProxyModel::removeItemsFromAlbum() [0x%x] items removed, invaliding.", this); |
712 INFO_1("VideoSortFilterProxyModel::removeItemsFromAlbum() [0x%x] items removed, invaliding.", this); |
704 invalidateFilter(); |
713 invalidateFilter(); |
705 err = 0; |
714 err = 0; |
706 } |
715 } |
707 } |
716 } |
|
717 |
|
718 VideoThumbnailData::instance().enableBackgroundFetching(true); |
708 return err; |
719 return err; |
709 } |
720 } |
710 |
721 |
711 // ----------------------------------------------------------------------------- |
722 // ----------------------------------------------------------------------------- |
712 // VideoSortFilterProxyModel::renameAlbum() |
723 // VideoSortFilterProxyModel::renameItem() |
713 // ----------------------------------------------------------------------------- |
724 // ----------------------------------------------------------------------------- |
714 // |
725 // |
715 int VideoSortFilterProxyModel::renameAlbum(const TMPXItemId &albumId, const QString &newTitle) |
726 int VideoSortFilterProxyModel::renameItem(const TMPXItemId &itemId, const QString &newTitle) |
716 { |
727 { |
717 FUNC_LOG_ADDR(this); |
728 FUNC_LOG_ADDR(this); |
718 int err(-1); |
729 int err(-1); |
719 |
730 |
720 if(mCollectionClient) |
731 if(mCollectionClient) |
721 { |
732 { |
722 return mCollectionClient->renameAlbum(albumId, newTitle); |
733 return mCollectionClient->renameItem(itemId, newTitle); |
723 } |
734 } |
724 return err; |
735 return err; |
725 } |
736 } |
726 |
737 |
727 // ----------------------------------------------------------------------------- |
738 // ----------------------------------------------------------------------------- |
753 |
764 |
754 // ----------------------------------------------------------------------------- |
765 // ----------------------------------------------------------------------------- |
755 // VideoSortFilterProxyModel::setGenericIdFilter() |
766 // VideoSortFilterProxyModel::setGenericIdFilter() |
756 // ----------------------------------------------------------------------------- |
767 // ----------------------------------------------------------------------------- |
757 // |
768 // |
758 void VideoSortFilterProxyModel::setGenericIdFilter(TMPXItemId itemId, bool filterValue) |
769 void VideoSortFilterProxyModel::setGenericIdFilter(const TMPXItemId &itemId, bool filterValue) |
759 { |
770 { |
760 FUNC_LOG_ADDR(this); |
771 FUNC_LOG_ADDR(this); |
761 if(mType == VideoCollectionCommon::EModelTypeGeneric) |
772 if(mType == VideoCollectionCommon::EModelTypeGeneric) |
762 { |
773 { |
763 INFO_3("VideoSortFilterProxyModel::setGenericIdFilter() [0x%x] itemId.iId2: %d, filterValue: %d", this, itemId.iId2, filterValue); |
774 INFO_3("VideoSortFilterProxyModel::setGenericIdFilter() [0x%x] itemId.iId2: %d, filterValue: %d", this, itemId.iId2, filterValue); |
770 |
781 |
771 // ----------------------------------------------------------------------------- |
782 // ----------------------------------------------------------------------------- |
772 // VideoSortFilterProxyModel::setAlbumInUse() |
783 // VideoSortFilterProxyModel::setAlbumInUse() |
773 // ----------------------------------------------------------------------------- |
784 // ----------------------------------------------------------------------------- |
774 // |
785 // |
775 void VideoSortFilterProxyModel::setAlbumInUse(TMPXItemId albumId) |
786 void VideoSortFilterProxyModel::setAlbumInUse(const TMPXItemId &albumId) |
776 { |
787 { |
777 FUNC_LOG_ADDR(this); |
788 FUNC_LOG_ADDR(this); |
778 if(mModel) |
789 if(mModel) |
779 { |
790 { |
780 INFO_1("VideoSortFilterProxyModel::setAlbumInUse() [0x%x] invalidating.", this); |
791 INFO_1("VideoSortFilterProxyModel::setAlbumInUse() [0x%x] invalidating.", this); |
792 FUNC_LOG_ADDR(this); |
803 FUNC_LOG_ADDR(this); |
793 // ignore if not collection content model |
804 // ignore if not collection content model |
794 if (mType == VideoCollectionCommon::EModelTypeCollectionContent) |
805 if (mType == VideoCollectionCommon::EModelTypeCollectionContent) |
795 { |
806 { |
796 INFO_1("VideoSortFilterProxyModel::albumChangedSlot() [0x%x] invalidating.", this); |
807 INFO_1("VideoSortFilterProxyModel::albumChangedSlot() [0x%x] invalidating.", this); |
797 // sort and invalidate filtering, otherwise newle created album content won't sort |
808 // sort and invalidate filtering, otherwise newly created album content won't sort |
798 invalidateFilter(); |
809 invalidateFilter(); |
799 setSortRole(mWantedSortRole); |
810 setSortRole(mWantedSortRole); |
800 sort(0, mWantedSortOrder); |
811 sort(0, mWantedSortOrder); |
801 } |
812 } |
802 } |
813 } |
803 |
814 |
804 // ----------------------------------------------------------------------------- |
815 // ----------------------------------------------------------------------------- |
805 // VideoSortFilterProxyModel::itemModifiedSlot() |
|
806 // ----------------------------------------------------------------------------- |
|
807 // |
|
808 void VideoSortFilterProxyModel::itemModifiedSlot(const TMPXItemId &itemId) |
|
809 { |
|
810 FUNC_LOG_ADDR(this); |
|
811 if(mType == VideoCollectionCommon::EModelTypeCollections && |
|
812 (itemId.iId2 == KVcxMvcMediaTypeAlbum || itemId.iId2 == KVcxMvcMediaTypeCategory)) |
|
813 { |
|
814 INFO_1("VideoSortFilterProxyModel::itemModifiedSlot() [0x%x] invalidating.", this); |
|
815 invalidate(); |
|
816 } |
|
817 } |
|
818 |
|
819 // ----------------------------------------------------------------------------- |
|
820 // VideoSortFilterProxyModel::getType() |
816 // VideoSortFilterProxyModel::getType() |
821 // ----------------------------------------------------------------------------- |
817 // ----------------------------------------------------------------------------- |
822 // |
818 // |
823 VideoCollectionCommon::TModelType VideoSortFilterProxyModel::getType() |
819 VideoCollectionCommon::TModelType VideoSortFilterProxyModel::getType() |
824 { |
820 { |