videocollection/videocollectionwrapper/src/videothumbnaildata_p.cpp
branchRCL_3
changeset 56 839377eedc2b
equal deleted inserted replaced
54:315810614048 56:839377eedc2b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  VideoThumbnailDataPrivate class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: 24.1.3 %
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <qapplication.h>
       
    22 #include <qpixmap.h>
       
    23 #include <qtimer.h>
       
    24 #include <qpainter.h>
       
    25 #include <mpxmediageneraldefs.h>
       
    26 #include <hbicon.h>
       
    27 
       
    28 #include <vcxmyvideosdefs.h>
       
    29 #include <videocollectioncommon.h>
       
    30 
       
    31 #include "videothumbnaildata_p.h"
       
    32 #include "videocollectionwrapper.h"
       
    33 #include "videosortfilterproxymodel.h"
       
    34 #include "videothumbnailfetcher.h"
       
    35 #include "videocollectiontrace.h"
       
    36 
       
    37 // Maximum thumbnails kept in memory.
       
    38 const int THUMBNAIL_CACHE_SIZE = 60;
       
    39 // Maximum of thumbnail fetches done at one background fetch round.
       
    40 const int THUMBNAIL_BACKGROUND_FETCH_AMOUNT = 20;
       
    41 // Milliseconds for the background fetch timer.
       
    42 const int THUMBNAIL_BACKGROUND_TIMEOUT = 100;
       
    43 // Milliseconds while thumbnail ready events are gathered before they 
       
    44 // are signaled.
       
    45 const int THUMBNAIL_READY_SIGNAL_TIMEOUT = 50;
       
    46 // Priority for background thumbnail fetches.
       
    47 const int BACKGROUND_FETCH_PRIORITY = 3000;
       
    48 
       
    49 // Size for default thumbnail, these match with large thumbnail in lists. 
       
    50 const int DEFAULT_THUMBNAIL_WIDTH = 114;
       
    51 const int DEFAULT_THUMBNAIL_HEIGHT = 64;
       
    52 
       
    53 /**
       
    54  * global qHash function required fo creating hash values for TMPXItemId -keys
       
    55  */
       
    56 inline uint qHash(TMPXItemId key) 
       
    57 {
       
    58     QPair<uint, uint> keyPair(key.iId1, key.iId2);
       
    59 
       
    60     return qHash(keyPair);
       
    61 }
       
    62 
       
    63 // ================= MEMBER FUNCTIONS =======================
       
    64 //
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // VideoThumbnailDataPrivate::VideoThumbnailDataPrivate()
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 VideoThumbnailDataPrivate::VideoThumbnailDataPrivate() 
       
    71     : mThumbnailFetcher( 0 )
       
    72     , mCurrentModel( 0 )
       
    73     , mCurrentFetchIndex( 0 )
       
    74     , mCurrentBackgroundFetchCount( 0 )
       
    75     , mBgFetchTimer( 0 )
       
    76     , mTbnReportTimer( 0 )
       
    77     , mSignalsConnected( false )
       
    78     , mBackgroundFetchingEnabled( true )
       
    79 {
       
    80 	FUNC_LOG;
       
    81 	initialize();
       
    82 }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // VideoThumbnailDataPrivate::~VideoThumbnailDataPrivate()
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 VideoThumbnailDataPrivate::~VideoThumbnailDataPrivate()
       
    89 {
       
    90 	FUNC_LOG;
       
    91     cleanup();
       
    92 }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // VideoThumbnailDataPrivate::initialize()
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 int VideoThumbnailDataPrivate::initialize()
       
    99 {
       
   100 	FUNC_LOG;
       
   101     mThumbnailData.setMaxCost(THUMBNAIL_CACHE_SIZE);
       
   102     
       
   103     if(!mThumbnailFetcher)
       
   104     {
       
   105         mThumbnailFetcher = new VideoThumbnailFetcher();        
       
   106     }
       
   107 
       
   108     if(!mBgFetchTimer)
       
   109     {
       
   110         mBgFetchTimer = new QTimer();
       
   111     }
       
   112     
       
   113     if(!mTbnReportTimer)
       
   114     {
       
   115         mTbnReportTimer = new QTimer();
       
   116     }
       
   117 
       
   118     if(connectSignals() < 0)
       
   119     {
       
   120         ERROR(-1, "VideoThumbnailDataPrivate::initialize() failed to connect signals.");
       
   121         cleanup();
       
   122         return -1;
       
   123     }
       
   124 
       
   125     return 0;
       
   126 }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // VideoThumbnailDataPrivate::cleanup()
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void VideoThumbnailDataPrivate::cleanup()
       
   133 {
       
   134 	FUNC_LOG;
       
   135     disconnectSignals();
       
   136 
       
   137     delete mThumbnailFetcher;
       
   138     mThumbnailFetcher = 0;
       
   139     
       
   140     freeThumbnailData();
       
   141     
       
   142     if(mTbnReportTimer)
       
   143     {
       
   144         mTbnReportTimer->stop();
       
   145         delete mTbnReportTimer;
       
   146         mTbnReportTimer = 0;
       
   147     }
       
   148     
       
   149     if(mBgFetchTimer)
       
   150     {
       
   151         mBgFetchTimer->stop();
       
   152         delete mBgFetchTimer;
       
   153         mBgFetchTimer = 0;
       
   154     }
       
   155 }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // VideoThumbnailDataPrivate::disconnectSignals()
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 void VideoThumbnailDataPrivate::disconnectSignals()
       
   162 {
       
   163 	FUNC_LOG;
       
   164     if(mSignalsConnected)
       
   165     {
       
   166 		disconnect(mThumbnailFetcher, SIGNAL(thumbnailReady(QPixmap , const TMPXItemId &, int )),
       
   167                     this, SLOT(thumbnailReadySlot(QPixmap , const TMPXItemId &, int )));
       
   168         disconnect(mThumbnailFetcher, SIGNAL(allThumbnailsFetched()),
       
   169                  this, SLOT(allThumbnailsFetchedSlot()));          
       
   170         disconnect(mBgFetchTimer, SIGNAL(timeout()), this, SLOT(doBackgroundFetching()));
       
   171         disconnect(mTbnReportTimer, SIGNAL(timeout()), this, SLOT(reportThumbnailsReadySlot()));
       
   172     }
       
   173     mSignalsConnected = false;
       
   174 }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // VideoThumbnailDataPrivate::connectSignals()
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 int VideoThumbnailDataPrivate::connectSignals()
       
   181 {
       
   182 	FUNC_LOG;
       
   183     if(!mSignalsConnected)
       
   184     {
       
   185         VideoSortFilterProxyModel *model = 
       
   186                 VideoCollectionWrapper::instance().getModel(VideoCollectionCommon::EModelTypeAllVideos);
       
   187         if(!model)
       
   188             return -1;
       
   189         if(!connect(mThumbnailFetcher, SIGNAL(thumbnailReady( QPixmap , const TMPXItemId &, int )),
       
   190                     this, SLOT(thumbnailReadySlot( QPixmap , const TMPXItemId &, int))) ||
       
   191             !connect(mThumbnailFetcher, SIGNAL(allThumbnailsFetched()),
       
   192                      this, SLOT(allThumbnailsFetchedSlot())) ||
       
   193            !connect(mBgFetchTimer, SIGNAL(timeout()), this, SLOT(doBackgroundFetching())) ||
       
   194            !connect(mTbnReportTimer, SIGNAL(timeout()), this, SLOT(reportThumbnailsReadySlot())))
       
   195         {
       
   196             return -1;
       
   197         }
       
   198         
       
   199         QApplication *app = qApp;
       
   200         if(!connect(app, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuitSlot())))
       
   201         {
       
   202             return -1;
       
   203         }
       
   204         
       
   205         mSignalsConnected = true;
       
   206     }
       
   207     return 0;
       
   208 }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // VideoThumbnailDataPrivate::getThumbnail()
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 const QIcon* VideoThumbnailDataPrivate::getThumbnail( const TMPXItemId &mediaId)
       
   215 {
       
   216     const QIcon *thumbnail = mThumbnailData[mediaId];
       
   217     if(!thumbnail)
       
   218     {
       
   219         return defaultThumbnail(mediaId);
       
   220     }
       
   221     return thumbnail;
       
   222 }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // VideoThumbnailDataPrivate::startFetchingThumbnails()
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 int VideoThumbnailDataPrivate::startFetchingThumbnails(const QList<QModelIndex> &indexes, int priority)
       
   229 {
       
   230 	FUNC_LOG;
       
   231     if(!mCurrentModel || !mThumbnailFetcher)
       
   232     {
       
   233         return -1;
       
   234     }
       
   235     if(indexes.count() == 0)
       
   236     {
       
   237         return 0;
       
   238     }
       
   239     
       
   240     mThumbnailFetcher->pauseFetching();
       
   241 
       
   242     int fetchCountBefore = mThumbnailFetcher->fetchCount();
       
   243     
       
   244     // Fetch the thumbnails
       
   245     for(int i = 0; i < indexes.count(); i++)
       
   246     {
       
   247         startFetchingThumbnail(mCurrentModel->getMediaIdAtIndex(indexes[i]), priority--);
       
   248     }
       
   249     
       
   250     int started = mThumbnailFetcher->fetchCount() - fetchCountBefore;
       
   251     
       
   252 	// Start the fetches and cancel previous ones.
       
   253     mThumbnailFetcher->continueFetching(true);
       
   254     
       
   255     return started;
       
   256 }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // VideoThumbnailDataPrivate::startFetchingThumbnail()
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 int VideoThumbnailDataPrivate::startFetchingThumbnail(const TMPXItemId &mediaId, int priority)
       
   263 {
       
   264     if(!mCurrentModel || !mThumbnailFetcher)
       
   265     {
       
   266         return -1;
       
   267     }
       
   268 
       
   269     // Check that it's not fetched before.
       
   270     if(mThumbnailData.contains(mediaId))
       
   271     {
       
   272         return 0;
       
   273     }
       
   274 
       
   275     QString fileName = mCurrentModel->getMediaFilePathForId(mediaId);
       
   276     
       
   277     // Thumbnail fetcher signals into thumbnailReadySlot when thumbnail ready
       
   278     if(fileName.length() > 0)
       
   279     {
       
   280         mThumbnailFetcher->addFetch(fileName, mediaId, priority);
       
   281     }
       
   282 
       
   283     return 0;
       
   284 }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // VideoThumbnailDataPrivate::doBackgroundFetching()
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 void VideoThumbnailDataPrivate::doBackgroundFetching()
       
   291 {
       
   292 	FUNC_LOG;
       
   293 	INFO_1("VideoThumbnailDataPrivate::doBackgroundFetching() bg fetch count: %d", mCurrentBackgroundFetchCount);
       
   294 	
       
   295     if(!mCurrentModel || !mThumbnailFetcher)
       
   296     {
       
   297         return;
       
   298     }
       
   299     
       
   300     if(mCurrentBackgroundFetchCount >= THUMBNAIL_CACHE_SIZE)
       
   301     {
       
   302         return;
       
   303     }
       
   304     
       
   305     int maxIndex = mCurrentModel->rowCount();
       
   306     if(maxIndex == 0)
       
   307     {
       
   308         return;
       
   309     }
       
   310 
       
   311     // Delta to UI index where fetch has been done already.  
       
   312     int currentDelta = mCurrentBackgroundFetchCount/2;
       
   313     
       
   314     // How many will be fetched.  
       
   315     const int fetchAmount = THUMBNAIL_BACKGROUND_FETCH_AMOUNT/2;
       
   316 
       
   317     QList<QModelIndex> indexes;
       
   318 
       
   319     // Items after the current fetch index.
       
   320     int startIndex = mCurrentFetchIndex+currentDelta;
       
   321     int endIndex = mCurrentFetchIndex+currentDelta+fetchAmount;
       
   322     getModelIndexes(indexes, startIndex, endIndex);
       
   323 
       
   324     // Items before the current fetch index.
       
   325     startIndex = mCurrentFetchIndex-currentDelta-fetchAmount;
       
   326     endIndex = mCurrentFetchIndex-currentDelta;
       
   327     getModelIndexes(indexes, startIndex, endIndex);
       
   328     
       
   329     mCurrentBackgroundFetchCount += THUMBNAIL_BACKGROUND_FETCH_AMOUNT;
       
   330 
       
   331     int fetchesStarted = startFetchingThumbnails(indexes, BACKGROUND_FETCH_PRIORITY);
       
   332     
       
   333     // No thumbnails to fetch, start again.
       
   334     if(fetchesStarted == 0)
       
   335     {
       
   336         continueBackgroundFetch();
       
   337     }
       
   338 }
       
   339 
       
   340 // -----------------------------------------------------------------------------
       
   341 // VideoThumbnailDataPrivate::getModelIndexes()
       
   342 // -----------------------------------------------------------------------------
       
   343 //
       
   344 void VideoThumbnailDataPrivate::getModelIndexes(QList<QModelIndex> &indexes, int &startIndex, int &endIndex)
       
   345 {
       
   346 	FUNC_LOG;
       
   347     INFO_2("VideoThumbnailDataPrivate::getModelIndexes() from %d to %d", startIndex, endIndex);
       
   348 	
       
   349     QModelIndex index;
       
   350     for(int i = startIndex; i < endIndex; i++)
       
   351     {
       
   352         if(i >= 0)
       
   353         {
       
   354             index = mCurrentModel->index(i, 0);
       
   355             if(index.isValid())
       
   356             {
       
   357                 indexes.append(index);
       
   358             }
       
   359         }
       
   360     }
       
   361 }
       
   362 
       
   363 // -----------------------------------------------------------------------------
       
   364 // VideoThumbnailDataPrivate::thumbnailReadySlot()
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 void VideoThumbnailDataPrivate::thumbnailReadySlot(QPixmap tnData, const TMPXItemId &mediaId, int error)
       
   368 {
       
   369     if(!error && !tnData.isNull())
       
   370     {
       
   371         mThumbnailData.insert(mediaId, new QIcon(tnData));
       
   372         
       
   373         // Gather list of media ids and emit thumbnailReady signals in larger set
       
   374         // when timer goes off.
       
   375         if(mTbnReportTimer && !mTbnReportTimer->isActive())
       
   376         {
       
   377             mTbnReportTimer->setSingleShot(true);
       
   378             mTbnReportTimer->start(THUMBNAIL_READY_SIGNAL_TIMEOUT);
       
   379         }
       
   380 
       
   381         // Save the media id for the signal.  
       
   382         mReadyThumbnailMediaIds.append(mediaId);
       
   383     }
       
   384 }
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // VideoThumbnailDataPrivate::reportThumbnailsReadySlot()
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 void VideoThumbnailDataPrivate::reportThumbnailsReadySlot()
       
   391 {
       
   392 	FUNC_LOG;
       
   393     emit thumbnailsFetched(mReadyThumbnailMediaIds);
       
   394     mReadyThumbnailMediaIds.clear();
       
   395 }
       
   396 
       
   397 // -----------------------------------------------------------------------------
       
   398 // VideoThumbnailDataPrivate::allThumbnailsFetchedSlot()
       
   399 // -----------------------------------------------------------------------------
       
   400 //
       
   401 void VideoThumbnailDataPrivate::allThumbnailsFetchedSlot()
       
   402 {
       
   403 	FUNC_LOG;
       
   404     continueBackgroundFetch();
       
   405 }
       
   406 
       
   407 // -----------------------------------------------------------------------------
       
   408 // VideoThumbnailDataPrivate::defaultThumbnail()
       
   409 // -----------------------------------------------------------------------------
       
   410 //
       
   411 const QIcon* VideoThumbnailDataPrivate::defaultThumbnail(const TMPXItemId &mediaId)
       
   412 {
       
   413     const TMPXItemId defaultIdVideo(KMaxTUint32-1, KVcxMvcMediaTypeVideo);
       
   414     const TMPXItemId defaultIdAlbum(KMaxTUint32-1, KVcxMvcMediaTypeAlbum);
       
   415     const TMPXItemId defaultIdDownloads(KVcxMvcCategoryIdDownloads, KVcxMvcMediaTypeCategory);
       
   416     const TMPXItemId defaultIdCaptured(KVcxMvcCategoryIdCaptured, KVcxMvcMediaTypeCategory);
       
   417 
       
   418     // Default thumbnail for video
       
   419     if(mediaId.iId2 == KVcxMvcMediaTypeVideo) 
       
   420     {
       
   421         if(!mDefaultThumbnails.contains(defaultIdVideo))
       
   422         {
       
   423             mDefaultThumbnails[defaultIdVideo] = loadIcon("qtg_large_video");
       
   424         }
       
   425         return &mDefaultThumbnails[defaultIdVideo].qicon();
       
   426     }
       
   427     else
       
   428     {
       
   429         // Default thumbnail for user defined album.
       
   430         if(mediaId.iId2 == KVcxMvcMediaTypeAlbum)
       
   431         {
       
   432             if(!mDefaultThumbnails.contains(defaultIdAlbum))
       
   433             {
       
   434                 mDefaultThumbnails[defaultIdAlbum] = loadIcon("qtg_large_video_collection");
       
   435             }
       
   436             return &mDefaultThumbnails[defaultIdAlbum].qicon();
       
   437         }
       
   438 
       
   439         // Thumbnails for default collections.
       
   440         switch(mediaId.iId1)
       
   441         {
       
   442             case KVcxMvcCategoryIdDownloads:
       
   443             {
       
   444                 if(!mDefaultThumbnails.contains(defaultIdDownloads))
       
   445                 {
       
   446                     mDefaultThumbnails[defaultIdDownloads] = loadIcon("qtg_large_video_download");
       
   447                 }
       
   448                 return &mDefaultThumbnails[defaultIdDownloads].qicon();
       
   449             }
       
   450             
       
   451             case KVcxMvcCategoryIdCaptured:
       
   452             {
       
   453                 if(!mDefaultThumbnails.contains(defaultIdCaptured))
       
   454                 {
       
   455                     mDefaultThumbnails[defaultIdCaptured] = loadIcon("qtg_large_video_capture");
       
   456                 }
       
   457                 return &mDefaultThumbnails[defaultIdCaptured].qicon();
       
   458             }
       
   459 
       
   460             default:
       
   461             {
       
   462                 if(!mDefaultThumbnails.contains(defaultIdAlbum))
       
   463                 {
       
   464                     mDefaultThumbnails[defaultIdAlbum] = loadIcon("qtg_large_video_collection");
       
   465                 }
       
   466                 return &mDefaultThumbnails[defaultIdAlbum].qicon();
       
   467             }
       
   468         }
       
   469     }
       
   470 }
       
   471 
       
   472 // -----------------------------------------------------------------------------
       
   473 // VideoThumbnailDataPrivate::loadIcon()
       
   474 // -----------------------------------------------------------------------------
       
   475 //
       
   476 HbIcon VideoThumbnailDataPrivate::loadIcon(QString iconName)
       
   477 {
       
   478     HbIcon icon(iconName);
       
   479     
       
   480     if(!icon.isNull())
       
   481     {
       
   482         QPixmap dest = QPixmap(DEFAULT_THUMBNAIL_WIDTH, DEFAULT_THUMBNAIL_HEIGHT);
       
   483 
       
   484         // Scale the icon into the thumbnail area.
       
   485         QPixmap source = icon.pixmap();
       
   486         // Smooth scaling is very expensive (size^2). Therefore we reduce the size
       
   487         // to 2x of the destination size and using fast transformation before doing final smooth scaling.
       
   488         if(source.size().width() > (6*dest.width()) || source.size().height() > (6*dest.height()))
       
   489         {
       
   490             QSize intermediate_size = QSize( dest.width() * 2, dest.height() * 2 );
       
   491             source = source.scaled(intermediate_size, Qt::KeepAspectRatio, Qt::FastTransformation );
       
   492         }
       
   493         QPixmap scaled = source.scaled(dest.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
       
   494 
       
   495         // Center the icon.
       
   496         int xDiff = 0;
       
   497         int yDiff = 0;
       
   498         if(dest.width() > scaled.width())
       
   499         {
       
   500             xDiff = (dest.width() - scaled.width()) / 2;
       
   501         }
       
   502         if(dest.height() > scaled.height())
       
   503         {
       
   504             yDiff = (dest.height() - scaled.height()) / 2;
       
   505         }
       
   506         
       
   507         // Paint it.
       
   508         QPainter painter(&dest);
       
   509         painter.setCompositionMode(QPainter::CompositionMode_Source);
       
   510         painter.fillRect(dest.rect(), Qt::transparent);
       
   511         painter.drawPixmap(xDiff, yDiff, scaled.width(), scaled.height(), scaled);
       
   512         painter.end();
       
   513         
       
   514         return HbIcon(dest);
       
   515     }
       
   516     else
       
   517     {
       
   518         return HbIcon();
       
   519     }
       
   520 }
       
   521 
       
   522 // -----------------------------------------------------------------------------
       
   523 // VideoThumbnailDataPrivate::removeThumbnail()
       
   524 // -----------------------------------------------------------------------------
       
   525 //
       
   526 bool VideoThumbnailDataPrivate::removeThumbnail(const TMPXItemId &mediaId)
       
   527 {
       
   528 	FUNC_LOG;
       
   529     return mThumbnailData.remove(mediaId);
       
   530 }
       
   531 
       
   532 // -----------------------------------------------------------------------------
       
   533 // VideoThumbnailDataPrivate::enableBackgroundFetching()
       
   534 // -----------------------------------------------------------------------------
       
   535 //
       
   536 void VideoThumbnailDataPrivate::enableBackgroundFetching(bool enable)
       
   537 {
       
   538 	FUNC_LOG;
       
   539     INFO_1("VideoThumbnailDataPrivate::enableBackgroundFetching() enable: %d", enable);
       
   540     mBackgroundFetchingEnabled = enable;
       
   541     startBackgroundFetching(mCurrentModel, 0);
       
   542 }
       
   543 
       
   544 // -----------------------------------------------------------------------------
       
   545 // VideoThumbnailDataPrivate::enableThumbnailCreation()
       
   546 // -----------------------------------------------------------------------------
       
   547 //
       
   548 void VideoThumbnailDataPrivate::enableThumbnailCreation(bool enable)
       
   549 {
       
   550 	FUNC_LOG;
       
   551 	INFO_1("VideoThumbnailDataPrivate::enableThumbnailCreation() enable: %d", enable);
       
   552     if(mThumbnailFetcher)
       
   553     {
       
   554         mThumbnailFetcher->enableThumbnailCreation(enable);
       
   555     }
       
   556 }
       
   557 
       
   558 // -----------------------------------------------------------------------------
       
   559 // VideoThumbnailDataPrivate::backgroundFetchingEnabled()
       
   560 // -----------------------------------------------------------------------------
       
   561 //
       
   562 bool VideoThumbnailDataPrivate::backgroundFetchingEnabled()
       
   563 {
       
   564     return mBackgroundFetchingEnabled;
       
   565 }
       
   566 
       
   567 // -----------------------------------------------------------------------------
       
   568 // VideoThumbnailDataPrivate::freeThumbnailData()
       
   569 // -----------------------------------------------------------------------------
       
   570 //
       
   571 void VideoThumbnailDataPrivate::freeThumbnailData()
       
   572 {
       
   573 	FUNC_LOG;
       
   574     // Stop timers.
       
   575 	if(mBgFetchTimer)
       
   576     {
       
   577         mBgFetchTimer->stop();
       
   578     }
       
   579     
       
   580     if(mTbnReportTimer)
       
   581     {
       
   582         mTbnReportTimer->stop();
       
   583     }
       
   584 
       
   585     if(mThumbnailFetcher)
       
   586     {
       
   587         mThumbnailFetcher->cancelFetches();
       
   588     }
       
   589     
       
   590     // Clear data.
       
   591     mReadyThumbnailMediaIds.clear();
       
   592     mThumbnailData.clear();
       
   593     mDefaultThumbnails.clear();
       
   594 }
       
   595 
       
   596 // -----------------------------------------------------------------------------
       
   597 // VideoThumbnailDataPrivate::startBackgroundFetching()
       
   598 // -----------------------------------------------------------------------------
       
   599 //
       
   600 void VideoThumbnailDataPrivate::startBackgroundFetching(VideoSortFilterProxyModel *model, int fetchIndex)
       
   601 {
       
   602 	FUNC_LOG;
       
   603 
       
   604     // If model is null, we continue using the current one. Model and index are kept up to date even
       
   605 	// fetching is not enabled.
       
   606     if(model)
       
   607     {
       
   608         mCurrentModel = model;
       
   609     }
       
   610     
       
   611     mCurrentFetchIndex = fetchIndex;
       
   612     mCurrentBackgroundFetchCount = 0;
       
   613 	
       
   614 	if(!mBackgroundFetchingEnabled || !mThumbnailFetcher)
       
   615     {
       
   616         INFO("VideoThumbnailDataPrivate::startBackgroundFetching() fetching is disabled.");
       
   617         return;
       
   618     }
       
   619 
       
   620     if(mBgFetchTimer)
       
   621     {
       
   622         mBgFetchTimer->stop();
       
   623     }
       
   624 	
       
   625     doBackgroundFetching();
       
   626 }
       
   627 
       
   628 // -----------------------------------------------------------------------------
       
   629 // VideoThumbnailDataPrivate::continueBackgroundFetch()
       
   630 // -----------------------------------------------------------------------------
       
   631 //
       
   632 void VideoThumbnailDataPrivate::continueBackgroundFetch()
       
   633 {
       
   634 	FUNC_LOG;
       
   635     if(!mBackgroundFetchingEnabled)
       
   636     {
       
   637         INFO("VideoThumbnailDataPrivate::continueBackgroundFetch() fetching is disabled.")
       
   638         return;
       
   639     }
       
   640 
       
   641     if(mBgFetchTimer)
       
   642     {
       
   643         mBgFetchTimer->stop();
       
   644         mBgFetchTimer->setSingleShot(true);
       
   645         mBgFetchTimer->start(THUMBNAIL_BACKGROUND_TIMEOUT);
       
   646     }
       
   647 }
       
   648 
       
   649 // -----------------------------------------------------------------------------
       
   650 // VideoThumbnailDataPrivate::aboutToQuitSlot()
       
   651 // -----------------------------------------------------------------------------
       
   652 //
       
   653 void VideoThumbnailDataPrivate::aboutToQuitSlot()
       
   654 {
       
   655 	FUNC_LOG;
       
   656     cleanup();
       
   657 }
       
   658 
       
   659 // End of file