13 * |
13 * |
14 * Description: VideoThumbnailDataPrivate class implementation |
14 * Description: VideoThumbnailDataPrivate class implementation |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
|
18 // Version : %version: 20 % |
|
19 |
18 // INCLUDE FILES |
20 // INCLUDE FILES |
19 #include <qapplication.h> |
21 #include <qapplication.h> |
20 #include <qpixmap.h> |
22 #include <qpixmap.h> |
21 #include <qtimer.h> |
23 #include <qtimer.h> |
22 #include <mpxmediageneraldefs.h> |
24 #include <mpxmediageneraldefs.h> |
23 #include <hbicon.h> |
25 #include <hbicon.h> |
24 |
26 |
25 #include <vcxmyvideosdefs.h> |
27 #include <vcxmyvideosdefs.h> |
|
28 #include <videocollectioncommon.h> |
26 |
29 |
27 #include "videothumbnaildata_p.h" |
30 #include "videothumbnaildata_p.h" |
28 #include "videocollectionwrapper.h" |
31 #include "videocollectionwrapper.h" |
29 #include "videosortfilterproxymodel.h" |
32 #include "videosortfilterproxymodel.h" |
30 #include "videothumbnailfetcher.h" |
33 #include "videothumbnailfetcher.h" |
|
34 #include "videocollectiontrace.h" |
31 |
35 |
32 // Maximum thumbnails kept in memory. |
36 // Maximum thumbnails kept in memory. |
33 const int THUMBNAIL_CACHE_SIZE = 60; |
37 const int THUMBNAIL_CACHE_SIZE = 60; |
34 // Maximum of thumbnail fetches done at one background fetch round. |
38 // Maximum of thumbnail fetches done at one background fetch round. |
35 const int THUMBNAIL_BACKGROUND_FETCH_AMOUNT = 20; |
39 const int THUMBNAIL_BACKGROUND_FETCH_AMOUNT = 20; |
56 |
60 |
57 // ----------------------------------------------------------------------------- |
61 // ----------------------------------------------------------------------------- |
58 // VideoThumbnailDataPrivate::VideoThumbnailDataPrivate() |
62 // VideoThumbnailDataPrivate::VideoThumbnailDataPrivate() |
59 // ----------------------------------------------------------------------------- |
63 // ----------------------------------------------------------------------------- |
60 // |
64 // |
61 VideoThumbnailDataPrivate::VideoThumbnailDataPrivate() : |
65 VideoThumbnailDataPrivate::VideoThumbnailDataPrivate() |
62 mThumbnailFetcher(0), |
66 : mThumbnailFetcher( 0 ) |
63 mCurrentModel(0), |
67 , mCurrentModel( 0 ) |
64 mCurrentFetchIndex(0), |
68 , mCurrentFetchIndex( 0 ) |
65 mCurrentBackgroundFetchCount(0), |
69 , mCurrentBackgroundFetchCount( 0 ) |
66 mBgFetchTimer(0), |
70 , mBgFetchTimer( 0 ) |
67 mTbnReportTimer(0), |
71 , mTbnReportTimer( 0 ) |
68 mSignalsConnected(false), |
72 , mSignalsConnected( false ) |
69 mBackgroundFetchingEnabled(true) |
73 , mBackgroundFetchingEnabled( true ) |
70 { |
74 { |
|
75 FUNC_LOG; |
71 initialize(); |
76 initialize(); |
72 } |
77 } |
73 |
78 |
74 // ----------------------------------------------------------------------------- |
79 // ----------------------------------------------------------------------------- |
75 // VideoThumbnailDataPrivate::~VideoThumbnailDataPrivate() |
80 // VideoThumbnailDataPrivate::~VideoThumbnailDataPrivate() |
76 // ----------------------------------------------------------------------------- |
81 // ----------------------------------------------------------------------------- |
77 // |
82 // |
78 VideoThumbnailDataPrivate::~VideoThumbnailDataPrivate() |
83 VideoThumbnailDataPrivate::~VideoThumbnailDataPrivate() |
79 { |
84 { |
|
85 FUNC_LOG; |
80 cleanup(); |
86 cleanup(); |
81 } |
87 } |
82 |
88 |
83 // ----------------------------------------------------------------------------- |
89 // ----------------------------------------------------------------------------- |
84 // VideoThumbnailDataPrivate::initialize() |
90 // VideoThumbnailDataPrivate::initialize() |
85 // ----------------------------------------------------------------------------- |
91 // ----------------------------------------------------------------------------- |
86 // |
92 // |
87 int VideoThumbnailDataPrivate::initialize() |
93 int VideoThumbnailDataPrivate::initialize() |
88 { |
94 { |
|
95 FUNC_LOG; |
89 mThumbnailData.setMaxCost(THUMBNAIL_CACHE_SIZE); |
96 mThumbnailData.setMaxCost(THUMBNAIL_CACHE_SIZE); |
90 |
97 |
91 if(!mThumbnailFetcher) |
98 if(!mThumbnailFetcher) |
92 { |
99 { |
93 mThumbnailFetcher = new VideoThumbnailFetcher(); |
100 mThumbnailFetcher = new VideoThumbnailFetcher(); |
144 // VideoThumbnailDataPrivate::disconnectSignals() |
153 // VideoThumbnailDataPrivate::disconnectSignals() |
145 // ----------------------------------------------------------------------------- |
154 // ----------------------------------------------------------------------------- |
146 // |
155 // |
147 void VideoThumbnailDataPrivate::disconnectSignals() |
156 void VideoThumbnailDataPrivate::disconnectSignals() |
148 { |
157 { |
|
158 FUNC_LOG; |
149 if(mSignalsConnected) |
159 if(mSignalsConnected) |
150 { |
160 { |
151 VideoSortFilterProxyModel *model = |
161 VideoSortFilterProxyModel *model = |
152 VideoCollectionWrapper::instance().getModel(VideoCollectionWrapper::EAllVideos); |
162 VideoCollectionWrapper::instance().getModel(VideoCollectionCommon::EModelTypeAllVideos); |
153 if(model) |
163 if(model) |
154 { |
164 { |
155 disconnect(model->sourceModel(), SIGNAL(modelReady()), this, SLOT(modelChangedSlot())); |
165 disconnect(model->sourceModel(), SIGNAL(modelReady()), this, SLOT(modelChangedSlot())); |
156 disconnect(model->sourceModel(), SIGNAL(modelChanged()), this, SLOT(modelChangedSlot())); |
166 disconnect(model->sourceModel(), SIGNAL(modelChanged()), this, SLOT(modelChangedSlot())); |
157 } |
167 } |
169 // VideoThumbnailDataPrivate::connectSignals() |
179 // VideoThumbnailDataPrivate::connectSignals() |
170 // ----------------------------------------------------------------------------- |
180 // ----------------------------------------------------------------------------- |
171 // |
181 // |
172 int VideoThumbnailDataPrivate::connectSignals() |
182 int VideoThumbnailDataPrivate::connectSignals() |
173 { |
183 { |
|
184 FUNC_LOG; |
174 if(!mSignalsConnected) |
185 if(!mSignalsConnected) |
175 { |
186 { |
176 VideoSortFilterProxyModel *model = |
187 VideoSortFilterProxyModel *model = |
177 VideoCollectionWrapper::instance().getModel(VideoCollectionWrapper::EAllVideos); |
188 VideoCollectionWrapper::instance().getModel(VideoCollectionCommon::EModelTypeAllVideos); |
178 if(!model) |
189 if(!model) |
179 return -1; |
190 return -1; |
180 if(!connect(mThumbnailFetcher, SIGNAL(thumbnailReady( QPixmap , void *, int )), |
191 if(!connect(mThumbnailFetcher, SIGNAL(thumbnailReady( QPixmap , void *, int )), |
181 this, SLOT(thumbnailReadySlot( QPixmap , void *, int))) || |
192 this, SLOT(thumbnailReadySlot( QPixmap , void *, int))) || |
182 !connect(mThumbnailFetcher, SIGNAL(allThumbnailsFetched()), |
193 !connect(mThumbnailFetcher, SIGNAL(allThumbnailsFetched()), |
263 return 0; |
275 return 0; |
264 } |
276 } |
265 |
277 |
266 QString fileName = mCurrentModel->getMediaFilePathForId(mediaId); |
278 QString fileName = mCurrentModel->getMediaFilePathForId(mediaId); |
267 |
279 |
268 // object containing media id to be passed throught |
|
269 // thumbnail generation process. |
|
270 TMPXItemId *internal = new TMPXItemId(mediaId.iId1, mediaId.iId2); |
|
271 |
|
272 // Thumbnail fetcher signals into thumbnailReadySlot when thumbnail ready |
280 // Thumbnail fetcher signals into thumbnailReadySlot when thumbnail ready |
273 if(fileName.length() > 0) |
281 if(fileName.length() > 0) |
274 { |
282 { |
|
283 // object containing media id to be passed throught |
|
284 // thumbnail generation process. |
|
285 TMPXItemId *internal = new TMPXItemId(mediaId.iId1, mediaId.iId2); |
|
286 |
275 mThumbnailFetcher->addFetch(fileName, internal, priority); |
287 mThumbnailFetcher->addFetch(fileName, internal, priority); |
276 } |
288 } |
277 |
289 |
278 return 0; |
290 return 0; |
279 } |
291 } |
387 // VideoThumbnailDataPrivate::reportThumbnailsReadySlot() |
401 // VideoThumbnailDataPrivate::reportThumbnailsReadySlot() |
388 // ----------------------------------------------------------------------------- |
402 // ----------------------------------------------------------------------------- |
389 // |
403 // |
390 void VideoThumbnailDataPrivate::reportThumbnailsReadySlot() |
404 void VideoThumbnailDataPrivate::reportThumbnailsReadySlot() |
391 { |
405 { |
|
406 FUNC_LOG; |
392 emit thumbnailsFetched(mReadyThumbnailMediaIds); |
407 emit thumbnailsFetched(mReadyThumbnailMediaIds); |
393 mReadyThumbnailMediaIds.clear(); |
408 mReadyThumbnailMediaIds.clear(); |
394 } |
409 } |
395 |
410 |
396 // ----------------------------------------------------------------------------- |
411 // ----------------------------------------------------------------------------- |
397 // VideoThumbnailDataPrivate::allThumbnailsFetchedSlot() |
412 // VideoThumbnailDataPrivate::allThumbnailsFetchedSlot() |
398 // ----------------------------------------------------------------------------- |
413 // ----------------------------------------------------------------------------- |
399 // |
414 // |
400 void VideoThumbnailDataPrivate::allThumbnailsFetchedSlot() |
415 void VideoThumbnailDataPrivate::allThumbnailsFetchedSlot() |
401 { |
416 { |
|
417 FUNC_LOG; |
402 continueBackgroundFetch(); |
418 continueBackgroundFetch(); |
403 } |
419 } |
404 |
420 |
405 // ----------------------------------------------------------------------------- |
421 // ----------------------------------------------------------------------------- |
406 // VideoThumbnailDataPrivate::modelChangedSlot() |
422 // VideoThumbnailDataPrivate::modelChangedSlot() |
407 // ----------------------------------------------------------------------------- |
423 // ----------------------------------------------------------------------------- |
408 // |
424 // |
409 void VideoThumbnailDataPrivate::modelChangedSlot() |
425 void VideoThumbnailDataPrivate::modelChangedSlot() |
410 { |
426 { |
|
427 FUNC_LOG; |
411 startBackgroundFetching(mCurrentModel, mCurrentFetchIndex); |
428 startBackgroundFetching(mCurrentModel, mCurrentFetchIndex); |
412 } |
429 } |
413 |
430 |
414 // ----------------------------------------------------------------------------- |
431 // ----------------------------------------------------------------------------- |
415 // VideoThumbnailDataPrivate::defaultThumbnail() |
432 // VideoThumbnailDataPrivate::defaultThumbnail() |
436 // Default thumbnail for user defined album. |
453 // Default thumbnail for user defined album. |
437 if(mediaId.iId2 == KVcxMvcMediaTypeAlbum) |
454 if(mediaId.iId2 == KVcxMvcMediaTypeAlbum) |
438 { |
455 { |
439 if(!mDefaultThumbnails.contains(defaultIdAlbum)) |
456 if(!mDefaultThumbnails.contains(defaultIdAlbum)) |
440 { |
457 { |
441 mDefaultThumbnails[defaultIdAlbum] = HbIcon(":/icons/default_thumbnail_collection.svg"); |
458 mDefaultThumbnails[defaultIdAlbum] = HbIcon("qtg_large_video_collection"); |
442 } |
459 } |
443 return &mDefaultThumbnails[defaultIdAlbum].qicon(); |
460 return &mDefaultThumbnails[defaultIdAlbum].qicon(); |
444 } |
461 } |
445 |
462 |
446 // Thumbnails for default collections. |
463 // Thumbnails for default collections. |
480 // VideoThumbnailDataPrivate::removeThumbnail() |
497 // VideoThumbnailDataPrivate::removeThumbnail() |
481 // ----------------------------------------------------------------------------- |
498 // ----------------------------------------------------------------------------- |
482 // |
499 // |
483 bool VideoThumbnailDataPrivate::removeThumbnail(TMPXItemId mediaId) |
500 bool VideoThumbnailDataPrivate::removeThumbnail(TMPXItemId mediaId) |
484 { |
501 { |
|
502 FUNC_LOG; |
485 return mThumbnailData.remove(mediaId); |
503 return mThumbnailData.remove(mediaId); |
486 } |
504 } |
487 |
505 |
488 // ----------------------------------------------------------------------------- |
506 // ----------------------------------------------------------------------------- |
489 // VideoThumbnailDataPrivate::enableBackgroundFetching() |
507 // VideoThumbnailDataPrivate::enableBackgroundFetching() |
490 // ----------------------------------------------------------------------------- |
508 // ----------------------------------------------------------------------------- |
491 // |
509 // |
492 void VideoThumbnailDataPrivate::enableBackgroundFetching(bool enable) |
510 void VideoThumbnailDataPrivate::enableBackgroundFetching(bool enable) |
493 { |
511 { |
|
512 FUNC_LOG; |
|
513 INFO_1("VideoThumbnailDataPrivate::enableBackgroundFetching() enable: %d", enable); |
494 mBackgroundFetchingEnabled = enable; |
514 mBackgroundFetchingEnabled = enable; |
495 startBackgroundFetching(mCurrentModel, 0); |
515 startBackgroundFetching(mCurrentModel, 0); |
496 } |
516 } |
497 |
517 |
498 // ----------------------------------------------------------------------------- |
518 // ----------------------------------------------------------------------------- |
499 // VideoThumbnailDataPrivate::enableThumbnailCreation() |
519 // VideoThumbnailDataPrivate::enableThumbnailCreation() |
500 // ----------------------------------------------------------------------------- |
520 // ----------------------------------------------------------------------------- |
501 // |
521 // |
502 void VideoThumbnailDataPrivate::enableThumbnailCreation(bool enable) |
522 void VideoThumbnailDataPrivate::enableThumbnailCreation(bool enable) |
503 { |
523 { |
|
524 FUNC_LOG; |
|
525 INFO_1("VideoThumbnailDataPrivate::enableThumbnailCreation() enable: %d", enable); |
504 if(mThumbnailFetcher) |
526 if(mThumbnailFetcher) |
|
527 { |
505 mThumbnailFetcher->enableThumbnailCreation(enable); |
528 mThumbnailFetcher->enableThumbnailCreation(enable); |
|
529 } |
506 } |
530 } |
507 |
531 |
508 // ----------------------------------------------------------------------------- |
532 // ----------------------------------------------------------------------------- |
509 // VideoThumbnailDataPrivate::freeThumbnailData() |
533 // VideoThumbnailDataPrivate::freeThumbnailData() |
510 // ----------------------------------------------------------------------------- |
534 // ----------------------------------------------------------------------------- |
511 // |
535 // |
512 void VideoThumbnailDataPrivate::freeThumbnailData() |
536 void VideoThumbnailDataPrivate::freeThumbnailData() |
513 { |
537 { |
|
538 FUNC_LOG; |
514 // Stop timers. |
539 // Stop timers. |
515 if(mBgFetchTimer) |
540 if(mBgFetchTimer) |
|
541 { |
516 mBgFetchTimer->stop(); |
542 mBgFetchTimer->stop(); |
|
543 } |
517 |
544 |
518 if(mTbnReportTimer) |
545 if(mTbnReportTimer) |
|
546 { |
519 mTbnReportTimer->stop(); |
547 mTbnReportTimer->stop(); |
|
548 } |
520 |
549 |
521 if(mThumbnailFetcher) |
550 if(mThumbnailFetcher) |
|
551 { |
522 mThumbnailFetcher->cancelFetches(); |
552 mThumbnailFetcher->cancelFetches(); |
|
553 } |
523 |
554 |
524 // Clear data. |
555 // Clear data. |
525 mReadyThumbnailMediaIds.clear(); |
556 mReadyThumbnailMediaIds.clear(); |
526 mThumbnailData.clear(); |
557 mThumbnailData.clear(); |
527 mDefaultThumbnails.clear(); |
558 mDefaultThumbnails.clear(); |
531 // VideoThumbnailDataPrivate::startBackgroundFetching() |
562 // VideoThumbnailDataPrivate::startBackgroundFetching() |
532 // ----------------------------------------------------------------------------- |
563 // ----------------------------------------------------------------------------- |
533 // |
564 // |
534 void VideoThumbnailDataPrivate::startBackgroundFetching(VideoSortFilterProxyModel *model, int fetchIndex) |
565 void VideoThumbnailDataPrivate::startBackgroundFetching(VideoSortFilterProxyModel *model, int fetchIndex) |
535 { |
566 { |
|
567 FUNC_LOG; |
536 if(!mBackgroundFetchingEnabled || !mThumbnailFetcher) |
568 if(!mBackgroundFetchingEnabled || !mThumbnailFetcher) |
|
569 { |
537 return; |
570 return; |
|
571 } |
538 |
572 |
539 mThumbnailFetcher->cancelFetches(); |
573 mThumbnailFetcher->cancelFetches(); |
540 |
574 |
541 // If model is null, we continue using the current one. |
575 // If model is null, we continue using the current one. |
542 if(model) |
576 if(model) |
|
577 { |
543 mCurrentModel = model; |
578 mCurrentModel = model; |
|
579 } |
544 |
580 |
545 mCurrentFetchIndex = fetchIndex; |
581 mCurrentFetchIndex = fetchIndex; |
546 mCurrentBackgroundFetchCount = 0; |
582 mCurrentBackgroundFetchCount = 0; |
547 doBackgroundFetching(); |
583 doBackgroundFetching(); |
548 } |
584 } |