videocollection/videocollectionwrapper/inc/videothumbnaildata_p.h
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 definition
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef __VIDEOTHUMBNAILDATAPRIVATE_H__
       
    19 #define __VIDEOTHUMBNAILDATAPRIVATE_H__
       
    20 
       
    21 // INCLUDES
       
    22 #include <qobject.h>
       
    23 #include <qpointer.h>
       
    24 #include <qcache.h>
       
    25 #include <qicon.h>
       
    26 #include <qset.h>
       
    27 #include <qlist.h>
       
    28 #include <qhash.h>
       
    29 #include <e32const.h>
       
    30 #include <mpxitemid.h>
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 class VideoCollectionWrapper;
       
    34 class VideoSortFilterProxyModel;
       
    35 class QModelIndex;
       
    36 class QTimer;
       
    37 class VideoThumbnailFetcher;
       
    38 class HbIcon;
       
    39 
       
    40 class VideoThumbnailDataPrivate : public QObject
       
    41 {
       
    42     /**
       
    43      * defined to be able to use signals and slots
       
    44      */
       
    45     Q_OBJECT
       
    46 
       
    47 public:
       
    48 
       
    49     /**
       
    50      * Default constructor
       
    51      */
       
    52     VideoThumbnailDataPrivate();
       
    53 
       
    54     /**
       
    55      * Destructor
       
    56      */
       
    57     virtual ~VideoThumbnailDataPrivate();
       
    58 
       
    59     /**
       
    60      * Method returns a pointer to video's thumbnail.
       
    61      *
       
    62      * If thumbnail fetching is ongoing or not yet started, pointer to default thumbnail
       
    63      * is returned.
       
    64      *
       
    65      * @param mediaId media id for which to get thumbnail
       
    66      * @param tnData reference to thumbnail data where data is ocpied
       
    67      *
       
    68      * @return QIcon* thumbnail pointer
       
    69      *
       
    70      */
       
    71     const QIcon* getThumbnail(const TMPXItemId &mediaId);
       
    72 
       
    73     /**
       
    74      * Method removes thumbnail data from the icon cache.
       
    75      *
       
    76      * @param mediaId id for media whose thumbnail is to be removed
       
    77      *
       
    78      * @return bool: true if item removed correctly, false if not.
       
    79      *
       
    80      */
       
    81     bool removeThumbnail(const TMPXItemId &mediaId);
       
    82 
       
    83     /**
       
    84      * Starts background thumbnail fetching from the given fetch index.
       
    85      *
       
    86      * @param model model of the items for the fetching.  
       
    87      * @param fetchIndex index where to start the background thumbnail fetching.
       
    88      */
       
    89     void startBackgroundFetching(VideoSortFilterProxyModel *model, int fetchIndex);
       
    90     
       
    91     /**
       
    92      * Enables or disables thumbnail background fetching.
       
    93      * 
       
    94      * @param enable true enables and false disables thumbnail background fetching.
       
    95      */
       
    96     void enableBackgroundFetching(bool enable);
       
    97 
       
    98     /**
       
    99      * Enables or disables thumbnail creation. Default is enabled. Thumbnails
       
   100      * that have been already generated are fetched still.  
       
   101      * 
       
   102      * @param enable true enables and false disables thumbnail creation.
       
   103      */
       
   104     void enableThumbnailCreation(bool enable); 
       
   105     
       
   106     /**
       
   107      * Returns if background fetching is enabled.
       
   108      * 
       
   109      * @return bool: true if background fetching is enabled, otherwise false.
       
   110      */
       
   111     bool backgroundFetchingEnabled();
       
   112     
       
   113     /**
       
   114      * Frees allocated data for thumbnails and cancels ongoing fetches.
       
   115      */
       
   116     void freeThumbnailData();
       
   117     
       
   118 protected:    
       
   119     
       
   120     /**
       
   121      * Method creates member objects and connects signals.
       
   122      *
       
   123      * @return int 0 initialization ok, -1 initialization failed
       
   124      *
       
   125      */
       
   126     int initialize();
       
   127 
       
   128     /**
       
   129      * Cleanup internal data. This must be called before UI environment is destroyed.
       
   130      */
       
   131     void cleanup();
       
   132 
       
   133     /**
       
   134      * Connects the signals.
       
   135      *
       
   136      * @return int 0 connecting ok, -1 connecting failed.
       
   137      */
       
   138     int connectSignals();
       
   139 
       
   140     /**
       
   141      * Disconnects the signals.
       
   142      *
       
   143      */
       
   144     void disconnectSignals();
       
   145     
       
   146     /**
       
   147      * Starts fetching thumbnails for medias in the model defined by the indexes 
       
   148      * parameter. Priority for the thumbnails is ascending starting from the 
       
   149      * defined priority.
       
   150      *
       
   151      * param @indexes indexes of the medias in the model
       
   152      * param @priority starting priority for the thumbnails
       
   153      *
       
   154      * @return int count of fetches started or -1 in case of error.
       
   155      */
       
   156     int startFetchingThumbnails(const QList<QModelIndex> &indexes, int priority);
       
   157 
       
   158     /**
       
   159      * Method starts fetching thumbnail for the video specified by given mediaId
       
   160      * Media IDs are used as a key identification in the thumbnail map where data is
       
   161      * collected.
       
   162      *
       
   163      * @param mediaId media id for which to start fetching thumbnail
       
   164      * @param priority priority for the fetch
       
   165      *
       
   166      * @return int: thumbnail id or -1 if fetch starting fails.
       
   167      *
       
   168      */
       
   169     int startFetchingThumbnail(const TMPXItemId &mediaId, int priority);
       
   170     
       
   171     /**
       
   172      * Appends indexes in the source model to the list between start and end.
       
   173      *
       
   174      * @param indexes list of indexes
       
   175      * @param startIndex start index
       
   176      * @param endIndex end index
       
   177      */
       
   178     void getModelIndexes(QList<QModelIndex> &indexes, int &startIndex, int &endIndex);
       
   179 
       
   180     /**
       
   181      * Method returns default thumbnail data.
       
   182      *
       
   183      * @param mediaId media id for which to get thumbnail
       
   184      * 
       
   185      * @return QIcon: reference to default thumbnail data
       
   186      *
       
   187      */
       
   188     const QIcon* defaultThumbnail(const TMPXItemId &mediaId);
       
   189     
       
   190     /**
       
   191      * Loads icon from file or resource, the icon is scaled to size of the 
       
   192      * video list view thumbnail.
       
   193      * 
       
   194      * @param iconName name of the file or resource.
       
   195      * 
       
   196      * @return HbIcon the icon load from resource or file.
       
   197      * 
       
   198      */
       
   199     HbIcon loadIcon(QString iconName);
       
   200 
       
   201     /**
       
   202      * Starts timer that continues the background thumbnail fetching at timeout.
       
   203      */
       
   204     void continueBackgroundFetch();
       
   205 
       
   206 signals:
       
   207 
       
   208     /**
       
   209      * This signal is emitted from thumbnailReadySlot, when
       
   210      *
       
   211      * @param mediaIds: media ids of the videos whose thumbnail is ready.
       
   212      *
       
   213      */
       
   214     void thumbnailsFetched(QList<TMPXItemId>& mediaIds);
       
   215 
       
   216 private slots:
       
   217 
       
   218     /**
       
   219      * Thumbnail fetcher signals this slot when thumbnail is ready
       
   220      * for some item. Thumbnail data is saved to icon cache.
       
   221      *
       
   222      * @param tnData: thumbnail
       
   223      * @param mediaId: pointer to the media id used in emitted signal
       
   224      * @param error: possible error code from thumbnail manager ( 0 == ok )
       
   225      *
       
   226      */
       
   227     void thumbnailReadySlot(QPixmap tnData, const TMPXItemId &mediaId, int error);
       
   228 
       
   229     /**
       
   230      * Fetches thumbnails around of mCurrentFetchIndex in batches of THUMBNAIL_BACKGROUND_FETCH_AMOUNT.
       
   231      * The fetch index is set by startFetchingThumbnails which also resets
       
   232      * mCurrentBackgroundFetchCount. Maximum of THUMBNAIL_MAX_BACKGROUND_FETCH thumbnails are
       
   233      * fetched between the count resets.
       
   234      *
       
   235      */
       
   236     void doBackgroundFetching();
       
   237     
       
   238     /**
       
   239      * Signaled when UI environment is about to be destroyed. Thumbnails must be cleaned before that.
       
   240      * 
       
   241      */
       
   242     void aboutToQuitSlot();
       
   243     
       
   244     /**
       
   245      * Emits thumbnailReady signals for list of thumbnails. 
       
   246      * 
       
   247      */
       
   248     void reportThumbnailsReadySlot();
       
   249 
       
   250     /**
       
   251      * Thumbnail fetcher signals this when all thumbnails have been fetched.
       
   252      */
       
   253     void allThumbnailsFetchedSlot();
       
   254     
       
   255 private: // Data
       
   256 
       
   257     VideoThumbnailFetcher            *mThumbnailFetcher;
       
   258     
       
   259     /**
       
   260      * Local cache for thumbnail data:
       
   261      * - key is the video's media id
       
   262      * - data is the actual thumbnail data.
       
   263      * If thumbnail data is not yet fetched, QIcon is default thumbnail.
       
   264      */
       
   265     QCache<TMPXItemId, QIcon>        mThumbnailData;
       
   266 
       
   267     /**
       
   268      * Local hash for default thumbnails.
       
   269      * - key is mpx item id defining default tn type 
       
   270      *  - data is the actual thumbnail data.
       
   271      */
       
   272     QHash<TMPXItemId, HbIcon>       mDefaultThumbnails;
       
   273 
       
   274     /**
       
   275      * Current model, set at call to startBackgroundFetching.
       
   276      */
       
   277     QPointer<VideoSortFilterProxyModel>     mCurrentModel;
       
   278     
       
   279     /**
       
   280      * Current index for background thumbnail fetching.
       
   281      */
       
   282     int                             mCurrentFetchIndex;
       
   283 
       
   284     /**
       
   285      * Current count of background thumbnails fetched around the fetch index.
       
   286      */
       
   287     int                             mCurrentBackgroundFetchCount;
       
   288 
       
   289     /**
       
   290      * Timer for background fetching.
       
   291      */
       
   292     QTimer                          *mBgFetchTimer;
       
   293 
       
   294     /**
       
   295      * Timer for thumbnail ready signaling.
       
   296      */
       
   297     QTimer                          *mTbnReportTimer;
       
   298     
       
   299     /**
       
   300      * List of media ids for thumbnails that are ready.
       
   301      */
       
   302     QList<TMPXItemId>               mReadyThumbnailMediaIds;
       
   303     
       
   304     /**
       
   305      * Flag for signal connections.
       
   306      */
       
   307     bool                            mSignalsConnected;
       
   308     
       
   309     /**
       
   310      * Indicates if background thumbnail fetching is enabled.
       
   311      */
       
   312     bool                            mBackgroundFetchingEnabled;
       
   313 };
       
   314 
       
   315 #endif  // __VIDEOTHUMBNAILDATAPRIVATE_H__
       
   316 
       
   317 // End of file