71 , mTbnReportTimer( 0 ) |
71 , mTbnReportTimer( 0 ) |
72 , mSignalsConnected( false ) |
72 , mSignalsConnected( false ) |
73 , mBackgroundFetchingEnabled( true ) |
73 , mBackgroundFetchingEnabled( true ) |
74 { |
74 { |
75 FUNC_LOG; |
75 FUNC_LOG; |
76 initialize(); |
76 initialize(); |
77 } |
77 } |
78 |
78 |
79 // ----------------------------------------------------------------------------- |
79 // ----------------------------------------------------------------------------- |
80 // VideoThumbnailDataPrivate::~VideoThumbnailDataPrivate() |
80 // VideoThumbnailDataPrivate::~VideoThumbnailDataPrivate() |
81 // ----------------------------------------------------------------------------- |
81 // ----------------------------------------------------------------------------- |
163 if(model) |
163 if(model) |
164 { |
164 { |
165 disconnect(model->sourceModel(), SIGNAL(modelReady()), this, SLOT(modelChangedSlot())); |
165 disconnect(model->sourceModel(), SIGNAL(modelReady()), this, SLOT(modelChangedSlot())); |
166 disconnect(model->sourceModel(), SIGNAL(modelChanged()), this, SLOT(modelChangedSlot())); |
166 disconnect(model->sourceModel(), SIGNAL(modelChanged()), this, SLOT(modelChangedSlot())); |
167 } |
167 } |
168 disconnect(mThumbnailFetcher, SIGNAL(thumbnailReady( QPixmap , void *, int )), |
168 disconnect(mThumbnailFetcher, SIGNAL(thumbnailReady(QPixmap , const TMPXItemId &, int )), |
169 this, SLOT(thumbnailReadySlot( QPixmap , void *, int ))); |
169 this, SLOT(thumbnailReadySlot(QPixmap , const TMPXItemId &, int ))); |
170 disconnect(mThumbnailFetcher, SIGNAL(allThumbnailsFetched()), |
170 disconnect(mThumbnailFetcher, SIGNAL(allThumbnailsFetched()), |
171 this, SLOT(allThumbnailsFetchedSlot())); |
171 this, SLOT(allThumbnailsFetchedSlot())); |
172 disconnect(mBgFetchTimer, SIGNAL(timeout()), this, SLOT(doBackgroundFetching())); |
172 disconnect(mBgFetchTimer, SIGNAL(timeout()), this, SLOT(doBackgroundFetching())); |
173 disconnect(mTbnReportTimer, SIGNAL(timeout()), this, SLOT(reportThumbnailsReadySlot())); |
173 disconnect(mTbnReportTimer, SIGNAL(timeout()), this, SLOT(reportThumbnailsReadySlot())); |
174 } |
174 } |
186 { |
186 { |
187 VideoSortFilterProxyModel *model = |
187 VideoSortFilterProxyModel *model = |
188 VideoCollectionWrapper::instance().getModel(VideoCollectionCommon::EModelTypeAllVideos); |
188 VideoCollectionWrapper::instance().getModel(VideoCollectionCommon::EModelTypeAllVideos); |
189 if(!model) |
189 if(!model) |
190 return -1; |
190 return -1; |
191 if(!connect(mThumbnailFetcher, SIGNAL(thumbnailReady( QPixmap , void *, int )), |
191 if(!connect(mThumbnailFetcher, SIGNAL(thumbnailReady( QPixmap , const TMPXItemId &, int )), |
192 this, SLOT(thumbnailReadySlot( QPixmap , void *, int))) || |
192 this, SLOT(thumbnailReadySlot( QPixmap , const TMPXItemId &, int))) || |
193 !connect(mThumbnailFetcher, SIGNAL(allThumbnailsFetched()), |
193 !connect(mThumbnailFetcher, SIGNAL(allThumbnailsFetched()), |
194 this, SLOT(allThumbnailsFetchedSlot())) || |
194 this, SLOT(allThumbnailsFetchedSlot())) || |
195 !connect(model->sourceModel(), SIGNAL(modelReady()), this, SLOT(modelChangedSlot())) || |
195 !connect(model->sourceModel(), SIGNAL(modelReady()), this, SLOT(modelChangedSlot())) || |
196 !connect(model->sourceModel(), SIGNAL(modelChanged()), this, SLOT(modelChangedSlot())) || |
196 !connect(model->sourceModel(), SIGNAL(modelChanged()), this, SLOT(modelChangedSlot())) || |
197 !connect(mBgFetchTimer, SIGNAL(timeout()), this, SLOT(doBackgroundFetching())) || |
197 !connect(mBgFetchTimer, SIGNAL(timeout()), this, SLOT(doBackgroundFetching())) || |
251 startFetchingThumbnail(mCurrentModel->getMediaIdAtIndex(indexes[i]), priority--); |
251 startFetchingThumbnail(mCurrentModel->getMediaIdAtIndex(indexes[i]), priority--); |
252 } |
252 } |
253 |
253 |
254 int started = mThumbnailFetcher->fetchCount() - fetchCountBefore; |
254 int started = mThumbnailFetcher->fetchCount() - fetchCountBefore; |
255 |
255 |
256 mThumbnailFetcher->continueFetching(); |
256 // Start the fetches and cancel previous ones. |
|
257 mThumbnailFetcher->continueFetching(true); |
257 |
258 |
258 return started; |
259 return started; |
259 } |
260 } |
260 |
261 |
261 // ----------------------------------------------------------------------------- |
262 // ----------------------------------------------------------------------------- |
278 QString fileName = mCurrentModel->getMediaFilePathForId(mediaId); |
279 QString fileName = mCurrentModel->getMediaFilePathForId(mediaId); |
279 |
280 |
280 // Thumbnail fetcher signals into thumbnailReadySlot when thumbnail ready |
281 // Thumbnail fetcher signals into thumbnailReadySlot when thumbnail ready |
281 if(fileName.length() > 0) |
282 if(fileName.length() > 0) |
282 { |
283 { |
283 // object containing media id to be passed throught |
284 mThumbnailFetcher->addFetch(fileName, mediaId, priority); |
284 // thumbnail generation process. |
|
285 TMPXItemId *internal = new TMPXItemId(mediaId.iId1, mediaId.iId2); |
|
286 |
|
287 mThumbnailFetcher->addFetch(fileName, internal, priority); |
|
288 } |
285 } |
289 |
286 |
290 return 0; |
287 return 0; |
291 } |
288 } |
292 |
289 |
365 |
362 |
366 // ----------------------------------------------------------------------------- |
363 // ----------------------------------------------------------------------------- |
367 // VideoThumbnailDataPrivate::thumbnailReadySlot() |
364 // VideoThumbnailDataPrivate::thumbnailReadySlot() |
368 // ----------------------------------------------------------------------------- |
365 // ----------------------------------------------------------------------------- |
369 // |
366 // |
370 void VideoThumbnailDataPrivate::thumbnailReadySlot(QPixmap tnData, void *internal, int error) |
367 void VideoThumbnailDataPrivate::thumbnailReadySlot(QPixmap tnData, const TMPXItemId &mediaId, int error) |
371 { |
368 { |
372 TMPXItemId mediaId(0, 0); |
|
373 if(internal) |
|
374 { |
|
375 mediaId = *(static_cast<TMPXItemId*>(internal)); |
|
376 delete internal; |
|
377 } |
|
378 else |
|
379 { |
|
380 return; |
|
381 } |
|
382 |
|
383 if(!error && !tnData.isNull()) |
369 if(!error && !tnData.isNull()) |
384 { |
370 { |
385 mThumbnailData.insert(mediaId, new QIcon(tnData)); |
371 mThumbnailData.insert(mediaId, new QIcon(tnData)); |
386 |
372 |
387 // Gather list of media ids and emit thumbnailReady signals in larger set |
373 // Gather list of media ids and emit thumbnailReady signals in larger set |
563 // ----------------------------------------------------------------------------- |
549 // ----------------------------------------------------------------------------- |
564 // |
550 // |
565 void VideoThumbnailDataPrivate::startBackgroundFetching(VideoSortFilterProxyModel *model, int fetchIndex) |
551 void VideoThumbnailDataPrivate::startBackgroundFetching(VideoSortFilterProxyModel *model, int fetchIndex) |
566 { |
552 { |
567 FUNC_LOG; |
553 FUNC_LOG; |
568 if(!mBackgroundFetchingEnabled || !mThumbnailFetcher) |
554 |
569 { |
555 // If model is null, we continue using the current one. Model and index are kept up to date even |
570 return; |
556 // fetching is not enabled. |
571 } |
|
572 |
|
573 mThumbnailFetcher->cancelFetches(); |
|
574 |
|
575 // If model is null, we continue using the current one. |
|
576 if(model) |
557 if(model) |
577 { |
558 { |
578 mCurrentModel = model; |
559 mCurrentModel = model; |
579 } |
560 } |
580 |
561 |
581 mCurrentFetchIndex = fetchIndex; |
562 mCurrentFetchIndex = fetchIndex; |
582 mCurrentBackgroundFetchCount = 0; |
563 mCurrentBackgroundFetchCount = 0; |
|
564 |
|
565 if(!mBackgroundFetchingEnabled || !mThumbnailFetcher) |
|
566 { |
|
567 INFO("VideoThumbnailDataPrivate::startBackgroundFetching() fetching is disabled."); |
|
568 return; |
|
569 } |
|
570 |
583 doBackgroundFetching(); |
571 doBackgroundFetching(); |
584 } |
572 } |
585 |
573 |
586 // ----------------------------------------------------------------------------- |
574 // ----------------------------------------------------------------------------- |
587 // VideoThumbnailDataPrivate::continueBackgroundFetch() |
575 // VideoThumbnailDataPrivate::continueBackgroundFetch() |