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