videocollection/videocollectionwrapper/src/videothumbnaildata_p.cpp
changeset 37 4eb2df7f7cbe
parent 36 8aed59de29f9
child 38 ff53afa8ad05
equal deleted inserted replaced
36:8aed59de29f9 37:4eb2df7f7cbe
    13 *
    13 *
    14 * Description:  VideoThumbnailDataPrivate class implementation
    14 * Description:  VideoThumbnailDataPrivate class implementation
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // Version : %version: 20 %
    18 // Version : %version: 21 %
    19 
    19 
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 #include <qapplication.h>
    21 #include <qapplication.h>
    22 #include <qpixmap.h>
    22 #include <qpixmap.h>
    23 #include <qtimer.h>
    23 #include <qtimer.h>
    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 // -----------------------------------------------------------------------------
   114     {
   114     {
   115         ERROR(-1, "VideoThumbnailDataPrivate::initialize() failed to connect signals.");
   115         ERROR(-1, "VideoThumbnailDataPrivate::initialize() failed to connect signals.");
   116         cleanup();
   116         cleanup();
   117         return -1;
   117         return -1;
   118     }
   118     }
   119     
   119 
   120     return 0;
   120     return 0;
   121 }
   121 }
   122 
   122 
   123 // -----------------------------------------------------------------------------
   123 // -----------------------------------------------------------------------------
   124 // VideoThumbnailDataPrivate::cleanup()
   124 // VideoThumbnailDataPrivate::cleanup()
   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
   535 //
   521 //
   536 void VideoThumbnailDataPrivate::freeThumbnailData()
   522 void VideoThumbnailDataPrivate::freeThumbnailData()
   537 {
   523 {
   538 	FUNC_LOG;
   524 	FUNC_LOG;
   539     // Stop timers.
   525     // Stop timers.
   540     if(mBgFetchTimer)
   526 	if(mBgFetchTimer)
   541     {
   527     {
   542         mBgFetchTimer->stop();
   528         mBgFetchTimer->stop();
   543     }
   529     }
   544     
   530     
   545     if(mTbnReportTimer)
   531     if(mTbnReportTimer)
   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()
   590 void VideoThumbnailDataPrivate::continueBackgroundFetch()
   578 void VideoThumbnailDataPrivate::continueBackgroundFetch()
   591 {
   579 {
   592 	FUNC_LOG;
   580 	FUNC_LOG;
   593     if(!mBackgroundFetchingEnabled)
   581     if(!mBackgroundFetchingEnabled)
   594     {
   582     {
       
   583         INFO("VideoThumbnailDataPrivate::continueBackgroundFetch() fetching is disabled.")
   595         return;
   584         return;
   596     }
   585     }
   597 
   586 
   598     if(mBgFetchTimer)
   587     if(mBgFetchTimer)
   599     {
   588     {