videocollection/videocollectionwrapper/src/videothumbnaildata_p.cpp
changeset 36 8aed59de29f9
parent 35 3738fe97f027
child 37 4eb2df7f7cbe
equal deleted inserted replaced
35:3738fe97f027 36:8aed59de29f9
    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();        
   103         mTbnReportTimer = new QTimer();
   110         mTbnReportTimer = new QTimer();
   104     }
   111     }
   105 
   112 
   106     if(connectSignals() < 0)
   113     if(connectSignals() < 0)
   107     {
   114     {
       
   115         ERROR(-1, "VideoThumbnailDataPrivate::initialize() failed to connect signals.");
   108         cleanup();
   116         cleanup();
   109         return -1;
   117         return -1;
   110     }
   118     }
   111     
   119     
   112     return 0;
   120     return 0;
   116 // VideoThumbnailDataPrivate::cleanup()
   124 // VideoThumbnailDataPrivate::cleanup()
   117 // -----------------------------------------------------------------------------
   125 // -----------------------------------------------------------------------------
   118 //
   126 //
   119 void VideoThumbnailDataPrivate::cleanup()
   127 void VideoThumbnailDataPrivate::cleanup()
   120 {
   128 {
       
   129 	FUNC_LOG;
   121     disconnectSignals();
   130     disconnectSignals();
   122 
   131 
   123     delete mThumbnailFetcher;
   132     delete mThumbnailFetcher;
   124     mThumbnailFetcher = 0;
   133     mThumbnailFetcher = 0;
   125     
   134     
   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()),
   218 // VideoThumbnailDataPrivate::startFetchingThumbnails()
   229 // VideoThumbnailDataPrivate::startFetchingThumbnails()
   219 // -----------------------------------------------------------------------------
   230 // -----------------------------------------------------------------------------
   220 //
   231 //
   221 int VideoThumbnailDataPrivate::startFetchingThumbnails(const QList<QModelIndex> &indexes, int priority)
   232 int VideoThumbnailDataPrivate::startFetchingThumbnails(const QList<QModelIndex> &indexes, int priority)
   222 {
   233 {
       
   234 	FUNC_LOG;
   223     if(!mCurrentModel || !mThumbnailFetcher)
   235     if(!mCurrentModel || !mThumbnailFetcher)
   224     {
   236     {
   225         return -1;
   237         return -1;
   226     }
   238     }
   227     if(indexes.count() == 0)
   239     if(indexes.count() == 0)
   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 }
   282 // VideoThumbnailDataPrivate::doBackgroundFetching()
   294 // VideoThumbnailDataPrivate::doBackgroundFetching()
   283 // -----------------------------------------------------------------------------
   295 // -----------------------------------------------------------------------------
   284 //
   296 //
   285 void VideoThumbnailDataPrivate::doBackgroundFetching()
   297 void VideoThumbnailDataPrivate::doBackgroundFetching()
   286 {
   298 {
       
   299 	FUNC_LOG;
   287     if(!mCurrentModel || !mThumbnailFetcher)
   300     if(!mCurrentModel || !mThumbnailFetcher)
   288     {
   301     {
   289         return;
   302         return;
   290     }
   303     }
   291 
   304 
   333 // VideoThumbnailDataPrivate::getModelIndexes()
   346 // VideoThumbnailDataPrivate::getModelIndexes()
   334 // -----------------------------------------------------------------------------
   347 // -----------------------------------------------------------------------------
   335 //
   348 //
   336 void VideoThumbnailDataPrivate::getModelIndexes(QList<QModelIndex> &indexes, int startIndex, int endIndex)
   349 void VideoThumbnailDataPrivate::getModelIndexes(QList<QModelIndex> &indexes, int startIndex, int endIndex)
   337 {
   350 {
       
   351 	FUNC_LOG;
   338     QModelIndex index;
   352     QModelIndex index;
   339     for(int i = startIndex; i < endIndex; i++)
   353     for(int i = startIndex; i < endIndex; i++)
   340     {
   354     {
   341         if(i >= 0)
   355         if(i >= 0)
   342         {
   356         {
   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.
   466 
   483 
   467             default:
   484             default:
   468             {
   485             {
   469                 if(!mDefaultThumbnails.contains(defaultIdAlbum))
   486                 if(!mDefaultThumbnails.contains(defaultIdAlbum))
   470                 {
   487                 {
   471                     mDefaultThumbnails[defaultIdAlbum] = HbIcon(":/icons/default_thumbnail_collection.svg");
   488                     mDefaultThumbnails[defaultIdAlbum] = HbIcon("qtg_large_video_collection");
   472                 }
   489                 }
   473                 return &mDefaultThumbnails[defaultIdAlbum].qicon();
   490                 return &mDefaultThumbnails[defaultIdAlbum].qicon();
   474             }
   491             }
   475         }
   492         }
   476     }
   493     }
   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 }
   551 // VideoThumbnailDataPrivate::continueBackgroundFetch()
   587 // VideoThumbnailDataPrivate::continueBackgroundFetch()
   552 // -----------------------------------------------------------------------------
   588 // -----------------------------------------------------------------------------
   553 //
   589 //
   554 void VideoThumbnailDataPrivate::continueBackgroundFetch()
   590 void VideoThumbnailDataPrivate::continueBackgroundFetch()
   555 {
   591 {
       
   592 	FUNC_LOG;
   556     if(!mBackgroundFetchingEnabled)
   593     if(!mBackgroundFetchingEnabled)
       
   594     {
   557         return;
   595         return;
       
   596     }
   558 
   597 
   559     if(mBgFetchTimer)
   598     if(mBgFetchTimer)
   560     {
   599     {
   561         mBgFetchTimer->stop();
   600         mBgFetchTimer->stop();
   562         mBgFetchTimer->setSingleShot(true);
   601         mBgFetchTimer->setSingleShot(true);
   568 // VideoThumbnailDataPrivate::aboutToQuitSlot()
   607 // VideoThumbnailDataPrivate::aboutToQuitSlot()
   569 // -----------------------------------------------------------------------------
   608 // -----------------------------------------------------------------------------
   570 //
   609 //
   571 void VideoThumbnailDataPrivate::aboutToQuitSlot()
   610 void VideoThumbnailDataPrivate::aboutToQuitSlot()
   572 {
   611 {
       
   612 	FUNC_LOG;
   573     cleanup();
   613     cleanup();
   574 }
   614 }
   575 
   615 
   576 // End of file
   616 // End of file