30
|
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 |
|
50
|
18 |
// Version : %version: 24.1.3 %
|
36
|
19 |
|
30
|
20 |
// INCLUDE FILES
|
34
|
21 |
#include <qapplication.h>
|
|
22 |
#include <qpixmap.h>
|
|
23 |
#include <qtimer.h>
|
38
|
24 |
#include <qpainter.h>
|
30
|
25 |
#include <mpxmediageneraldefs.h>
|
35
|
26 |
#include <hbicon.h>
|
|
27 |
|
34
|
28 |
#include <vcxmyvideosdefs.h>
|
36
|
29 |
#include <videocollectioncommon.h>
|
30
|
30 |
|
|
31 |
#include "videothumbnaildata_p.h"
|
|
32 |
#include "videocollectionwrapper.h"
|
|
33 |
#include "videosortfilterproxymodel.h"
|
34
|
34 |
#include "videothumbnailfetcher.h"
|
36
|
35 |
#include "videocollectiontrace.h"
|
30
|
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 |
|
38
|
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 |
|
30
|
53 |
/**
|
|
54 |
* global qHash function required fo creating hash values for TMPXItemId -keys
|
|
55 |
*/
|
|
56 |
inline uint qHash(TMPXItemId key)
|
38
|
57 |
{
|
|
58 |
QPair<uint, uint> keyPair(key.iId1, key.iId2);
|
30
|
59 |
|
|
60 |
return qHash(keyPair);
|
|
61 |
}
|
|
62 |
|
|
63 |
// ================= MEMBER FUNCTIONS =======================
|
|
64 |
//
|
|
65 |
|
|
66 |
// -----------------------------------------------------------------------------
|
|
67 |
// VideoThumbnailDataPrivate::VideoThumbnailDataPrivate()
|
|
68 |
// -----------------------------------------------------------------------------
|
|
69 |
//
|
36
|
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 )
|
30
|
79 |
{
|
36
|
80 |
FUNC_LOG;
|
37
|
81 |
initialize();
|
30
|
82 |
}
|
|
83 |
|
|
84 |
// -----------------------------------------------------------------------------
|
|
85 |
// VideoThumbnailDataPrivate::~VideoThumbnailDataPrivate()
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
//
|
|
88 |
VideoThumbnailDataPrivate::~VideoThumbnailDataPrivate()
|
|
89 |
{
|
36
|
90 |
FUNC_LOG;
|
30
|
91 |
cleanup();
|
|
92 |
}
|
|
93 |
|
|
94 |
// -----------------------------------------------------------------------------
|
|
95 |
// VideoThumbnailDataPrivate::initialize()
|
|
96 |
// -----------------------------------------------------------------------------
|
|
97 |
//
|
|
98 |
int VideoThumbnailDataPrivate::initialize()
|
|
99 |
{
|
36
|
100 |
FUNC_LOG;
|
30
|
101 |
mThumbnailData.setMaxCost(THUMBNAIL_CACHE_SIZE);
|
|
102 |
|
34
|
103 |
if(!mThumbnailFetcher)
|
30
|
104 |
{
|
34
|
105 |
mThumbnailFetcher = new VideoThumbnailFetcher();
|
30
|
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 |
{
|
36
|
120 |
ERROR(-1, "VideoThumbnailDataPrivate::initialize() failed to connect signals.");
|
30
|
121 |
cleanup();
|
|
122 |
return -1;
|
|
123 |
}
|
37
|
124 |
|
30
|
125 |
return 0;
|
|
126 |
}
|
|
127 |
|
|
128 |
// -----------------------------------------------------------------------------
|
|
129 |
// VideoThumbnailDataPrivate::cleanup()
|
|
130 |
// -----------------------------------------------------------------------------
|
|
131 |
//
|
|
132 |
void VideoThumbnailDataPrivate::cleanup()
|
|
133 |
{
|
36
|
134 |
FUNC_LOG;
|
30
|
135 |
disconnectSignals();
|
|
136 |
|
34
|
137 |
delete mThumbnailFetcher;
|
|
138 |
mThumbnailFetcher = 0;
|
|
139 |
|
30
|
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 |
{
|
36
|
163 |
FUNC_LOG;
|
30
|
164 |
if(mSignalsConnected)
|
|
165 |
{
|
37
|
166 |
disconnect(mThumbnailFetcher, SIGNAL(thumbnailReady(QPixmap , const TMPXItemId &, int )),
|
|
167 |
this, SLOT(thumbnailReadySlot(QPixmap , const TMPXItemId &, int )));
|
34
|
168 |
disconnect(mThumbnailFetcher, SIGNAL(allThumbnailsFetched()),
|
|
169 |
this, SLOT(allThumbnailsFetchedSlot()));
|
30
|
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 |
{
|
36
|
182 |
FUNC_LOG;
|
30
|
183 |
if(!mSignalsConnected)
|
|
184 |
{
|
34
|
185 |
VideoSortFilterProxyModel *model =
|
36
|
186 |
VideoCollectionWrapper::instance().getModel(VideoCollectionCommon::EModelTypeAllVideos);
|
34
|
187 |
if(!model)
|
|
188 |
return -1;
|
37
|
189 |
if(!connect(mThumbnailFetcher, SIGNAL(thumbnailReady( QPixmap , const TMPXItemId &, int )),
|
|
190 |
this, SLOT(thumbnailReadySlot( QPixmap , const TMPXItemId &, int))) ||
|
34
|
191 |
!connect(mThumbnailFetcher, SIGNAL(allThumbnailsFetched()),
|
|
192 |
this, SLOT(allThumbnailsFetchedSlot())) ||
|
30
|
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 |
//
|
50
|
214 |
const QIcon* VideoThumbnailDataPrivate::getThumbnail( const TMPXItemId &mediaId)
|
30
|
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 |
{
|
36
|
230 |
FUNC_LOG;
|
34
|
231 |
if(!mCurrentModel || !mThumbnailFetcher)
|
30
|
232 |
{
|
|
233 |
return -1;
|
|
234 |
}
|
|
235 |
if(indexes.count() == 0)
|
|
236 |
{
|
|
237 |
return 0;
|
|
238 |
}
|
|
239 |
|
34
|
240 |
mThumbnailFetcher->pauseFetching();
|
|
241 |
|
|
242 |
int fetchCountBefore = mThumbnailFetcher->fetchCount();
|
30
|
243 |
|
34
|
244 |
// Fetch the thumbnails
|
30
|
245 |
for(int i = 0; i < indexes.count(); i++)
|
|
246 |
{
|
34
|
247 |
startFetchingThumbnail(mCurrentModel->getMediaIdAtIndex(indexes[i]), priority--);
|
30
|
248 |
}
|
|
249 |
|
34
|
250 |
int started = mThumbnailFetcher->fetchCount() - fetchCountBefore;
|
|
251 |
|
37
|
252 |
// Start the fetches and cancel previous ones.
|
|
253 |
mThumbnailFetcher->continueFetching(true);
|
34
|
254 |
|
|
255 |
return started;
|
30
|
256 |
}
|
|
257 |
|
|
258 |
// -----------------------------------------------------------------------------
|
|
259 |
// VideoThumbnailDataPrivate::startFetchingThumbnail()
|
|
260 |
// -----------------------------------------------------------------------------
|
|
261 |
//
|
50
|
262 |
int VideoThumbnailDataPrivate::startFetchingThumbnail(const TMPXItemId &mediaId, int priority)
|
30
|
263 |
{
|
34
|
264 |
if(!mCurrentModel || !mThumbnailFetcher)
|
30
|
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 |
|
34
|
275 |
QString fileName = mCurrentModel->getMediaFilePathForId(mediaId);
|
|
276 |
|
|
277 |
// Thumbnail fetcher signals into thumbnailReadySlot when thumbnail ready
|
30
|
278 |
if(fileName.length() > 0)
|
|
279 |
{
|
37
|
280 |
mThumbnailFetcher->addFetch(fileName, mediaId, priority);
|
30
|
281 |
}
|
|
282 |
|
34
|
283 |
return 0;
|
30
|
284 |
}
|
|
285 |
|
|
286 |
// -----------------------------------------------------------------------------
|
|
287 |
// VideoThumbnailDataPrivate::doBackgroundFetching()
|
|
288 |
// -----------------------------------------------------------------------------
|
|
289 |
//
|
|
290 |
void VideoThumbnailDataPrivate::doBackgroundFetching()
|
|
291 |
{
|
36
|
292 |
FUNC_LOG;
|
44
|
293 |
INFO_1("VideoThumbnailDataPrivate::doBackgroundFetching() bg fetch count: %d", mCurrentBackgroundFetchCount);
|
|
294 |
|
34
|
295 |
if(!mCurrentModel || !mThumbnailFetcher)
|
30
|
296 |
{
|
|
297 |
return;
|
|
298 |
}
|
44
|
299 |
|
30
|
300 |
if(mCurrentBackgroundFetchCount >= THUMBNAIL_CACHE_SIZE)
|
|
301 |
{
|
|
302 |
return;
|
|
303 |
}
|
|
304 |
|
34
|
305 |
int maxIndex = mCurrentModel->rowCount();
|
30
|
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 |
|
34
|
319 |
// Items after the current fetch index.
|
|
320 |
int startIndex = mCurrentFetchIndex+currentDelta;
|
|
321 |
int endIndex = mCurrentFetchIndex+currentDelta+fetchAmount;
|
30
|
322 |
getModelIndexes(indexes, startIndex, endIndex);
|
|
323 |
|
34
|
324 |
// Items before the current fetch index.
|
|
325 |
startIndex = mCurrentFetchIndex-currentDelta-fetchAmount;
|
|
326 |
endIndex = mCurrentFetchIndex-currentDelta;
|
30
|
327 |
getModelIndexes(indexes, startIndex, endIndex);
|
34
|
328 |
|
30
|
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 |
//
|
50
|
344 |
void VideoThumbnailDataPrivate::getModelIndexes(QList<QModelIndex> &indexes, int &startIndex, int &endIndex)
|
30
|
345 |
{
|
36
|
346 |
FUNC_LOG;
|
44
|
347 |
INFO_2("VideoThumbnailDataPrivate::getModelIndexes() from %d to %d", startIndex, endIndex);
|
|
348 |
|
30
|
349 |
QModelIndex index;
|
|
350 |
for(int i = startIndex; i < endIndex; i++)
|
|
351 |
{
|
|
352 |
if(i >= 0)
|
|
353 |
{
|
34
|
354 |
index = mCurrentModel->index(i, 0);
|
30
|
355 |
if(index.isValid())
|
|
356 |
{
|
|
357 |
indexes.append(index);
|
|
358 |
}
|
|
359 |
}
|
|
360 |
}
|
|
361 |
}
|
|
362 |
|
|
363 |
// -----------------------------------------------------------------------------
|
|
364 |
// VideoThumbnailDataPrivate::thumbnailReadySlot()
|
|
365 |
// -----------------------------------------------------------------------------
|
|
366 |
//
|
37
|
367 |
void VideoThumbnailDataPrivate::thumbnailReadySlot(QPixmap tnData, const TMPXItemId &mediaId, int error)
|
30
|
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 |
{
|
36
|
392 |
FUNC_LOG;
|
30
|
393 |
emit thumbnailsFetched(mReadyThumbnailMediaIds);
|
|
394 |
mReadyThumbnailMediaIds.clear();
|
|
395 |
}
|
|
396 |
|
|
397 |
// -----------------------------------------------------------------------------
|
34
|
398 |
// VideoThumbnailDataPrivate::allThumbnailsFetchedSlot()
|
30
|
399 |
// -----------------------------------------------------------------------------
|
|
400 |
//
|
34
|
401 |
void VideoThumbnailDataPrivate::allThumbnailsFetchedSlot()
|
30
|
402 |
{
|
36
|
403 |
FUNC_LOG;
|
34
|
404 |
continueBackgroundFetch();
|
30
|
405 |
}
|
|
406 |
|
|
407 |
// -----------------------------------------------------------------------------
|
|
408 |
// VideoThumbnailDataPrivate::defaultThumbnail()
|
|
409 |
// -----------------------------------------------------------------------------
|
|
410 |
//
|
50
|
411 |
const QIcon* VideoThumbnailDataPrivate::defaultThumbnail(const TMPXItemId &mediaId)
|
30
|
412 |
{
|
35
|
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
|
34
|
419 |
if(mediaId.iId2 == KVcxMvcMediaTypeVideo)
|
30
|
420 |
{
|
35
|
421 |
if(!mDefaultThumbnails.contains(defaultIdVideo))
|
|
422 |
{
|
38
|
423 |
mDefaultThumbnails[defaultIdVideo] = loadIcon("qtg_large_video");
|
35
|
424 |
}
|
|
425 |
return &mDefaultThumbnails[defaultIdVideo].qicon();
|
30
|
426 |
}
|
|
427 |
else
|
|
428 |
{
|
35
|
429 |
// Default thumbnail for user defined album.
|
|
430 |
if(mediaId.iId2 == KVcxMvcMediaTypeAlbum)
|
|
431 |
{
|
|
432 |
if(!mDefaultThumbnails.contains(defaultIdAlbum))
|
|
433 |
{
|
38
|
434 |
mDefaultThumbnails[defaultIdAlbum] = loadIcon("qtg_large_video_collection");
|
35
|
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 |
{
|
38
|
446 |
mDefaultThumbnails[defaultIdDownloads] = loadIcon("qtg_large_video_download");
|
35
|
447 |
}
|
|
448 |
return &mDefaultThumbnails[defaultIdDownloads].qicon();
|
|
449 |
}
|
|
450 |
|
|
451 |
case KVcxMvcCategoryIdCaptured:
|
|
452 |
{
|
|
453 |
if(!mDefaultThumbnails.contains(defaultIdCaptured))
|
|
454 |
{
|
38
|
455 |
mDefaultThumbnails[defaultIdCaptured] = loadIcon("qtg_large_video_capture");
|
35
|
456 |
}
|
|
457 |
return &mDefaultThumbnails[defaultIdCaptured].qicon();
|
|
458 |
}
|
|
459 |
|
|
460 |
default:
|
|
461 |
{
|
|
462 |
if(!mDefaultThumbnails.contains(defaultIdAlbum))
|
|
463 |
{
|
38
|
464 |
mDefaultThumbnails[defaultIdAlbum] = loadIcon("qtg_large_video_collection");
|
35
|
465 |
}
|
|
466 |
return &mDefaultThumbnails[defaultIdAlbum].qicon();
|
|
467 |
}
|
|
468 |
}
|
30
|
469 |
}
|
|
470 |
}
|
|
471 |
|
|
472 |
// -----------------------------------------------------------------------------
|
38
|
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 |
// -----------------------------------------------------------------------------
|
30
|
523 |
// VideoThumbnailDataPrivate::removeThumbnail()
|
|
524 |
// -----------------------------------------------------------------------------
|
|
525 |
//
|
50
|
526 |
bool VideoThumbnailDataPrivate::removeThumbnail(const TMPXItemId &mediaId)
|
30
|
527 |
{
|
36
|
528 |
FUNC_LOG;
|
30
|
529 |
return mThumbnailData.remove(mediaId);
|
|
530 |
}
|
|
531 |
|
|
532 |
// -----------------------------------------------------------------------------
|
|
533 |
// VideoThumbnailDataPrivate::enableBackgroundFetching()
|
|
534 |
// -----------------------------------------------------------------------------
|
|
535 |
//
|
|
536 |
void VideoThumbnailDataPrivate::enableBackgroundFetching(bool enable)
|
|
537 |
{
|
36
|
538 |
FUNC_LOG;
|
|
539 |
INFO_1("VideoThumbnailDataPrivate::enableBackgroundFetching() enable: %d", enable);
|
30
|
540 |
mBackgroundFetchingEnabled = enable;
|
34
|
541 |
startBackgroundFetching(mCurrentModel, 0);
|
|
542 |
}
|
|
543 |
|
|
544 |
// -----------------------------------------------------------------------------
|
|
545 |
// VideoThumbnailDataPrivate::enableThumbnailCreation()
|
|
546 |
// -----------------------------------------------------------------------------
|
|
547 |
//
|
|
548 |
void VideoThumbnailDataPrivate::enableThumbnailCreation(bool enable)
|
|
549 |
{
|
36
|
550 |
FUNC_LOG;
|
|
551 |
INFO_1("VideoThumbnailDataPrivate::enableThumbnailCreation() enable: %d", enable);
|
34
|
552 |
if(mThumbnailFetcher)
|
36
|
553 |
{
|
34
|
554 |
mThumbnailFetcher->enableThumbnailCreation(enable);
|
36
|
555 |
}
|
30
|
556 |
}
|
|
557 |
|
|
558 |
// -----------------------------------------------------------------------------
|
50
|
559 |
// VideoThumbnailDataPrivate::backgroundFetchingEnabled()
|
|
560 |
// -----------------------------------------------------------------------------
|
|
561 |
//
|
|
562 |
bool VideoThumbnailDataPrivate::backgroundFetchingEnabled()
|
|
563 |
{
|
|
564 |
return mBackgroundFetchingEnabled;
|
|
565 |
}
|
|
566 |
|
|
567 |
// -----------------------------------------------------------------------------
|
30
|
568 |
// VideoThumbnailDataPrivate::freeThumbnailData()
|
|
569 |
// -----------------------------------------------------------------------------
|
|
570 |
//
|
|
571 |
void VideoThumbnailDataPrivate::freeThumbnailData()
|
|
572 |
{
|
36
|
573 |
FUNC_LOG;
|
30
|
574 |
// Stop timers.
|
37
|
575 |
if(mBgFetchTimer)
|
36
|
576 |
{
|
30
|
577 |
mBgFetchTimer->stop();
|
36
|
578 |
}
|
30
|
579 |
|
|
580 |
if(mTbnReportTimer)
|
36
|
581 |
{
|
30
|
582 |
mTbnReportTimer->stop();
|
36
|
583 |
}
|
30
|
584 |
|
34
|
585 |
if(mThumbnailFetcher)
|
36
|
586 |
{
|
34
|
587 |
mThumbnailFetcher->cancelFetches();
|
36
|
588 |
}
|
34
|
589 |
|
30
|
590 |
// Clear data.
|
|
591 |
mReadyThumbnailMediaIds.clear();
|
|
592 |
mThumbnailData.clear();
|
35
|
593 |
mDefaultThumbnails.clear();
|
30
|
594 |
}
|
|
595 |
|
|
596 |
// -----------------------------------------------------------------------------
|
|
597 |
// VideoThumbnailDataPrivate::startBackgroundFetching()
|
|
598 |
// -----------------------------------------------------------------------------
|
|
599 |
//
|
34
|
600 |
void VideoThumbnailDataPrivate::startBackgroundFetching(VideoSortFilterProxyModel *model, int fetchIndex)
|
30
|
601 |
{
|
36
|
602 |
FUNC_LOG;
|
37
|
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.
|
34
|
606 |
if(model)
|
36
|
607 |
{
|
34
|
608 |
mCurrentModel = model;
|
36
|
609 |
}
|
34
|
610 |
|
30
|
611 |
mCurrentFetchIndex = fetchIndex;
|
|
612 |
mCurrentBackgroundFetchCount = 0;
|
37
|
613 |
|
|
614 |
if(!mBackgroundFetchingEnabled || !mThumbnailFetcher)
|
|
615 |
{
|
|
616 |
INFO("VideoThumbnailDataPrivate::startBackgroundFetching() fetching is disabled.");
|
|
617 |
return;
|
|
618 |
}
|
44
|
619 |
|
|
620 |
if(mBgFetchTimer)
|
|
621 |
{
|
|
622 |
mBgFetchTimer->stop();
|
|
623 |
}
|
|
624 |
|
30
|
625 |
doBackgroundFetching();
|
|
626 |
}
|
|
627 |
|
|
628 |
// -----------------------------------------------------------------------------
|
|
629 |
// VideoThumbnailDataPrivate::continueBackgroundFetch()
|
|
630 |
// -----------------------------------------------------------------------------
|
|
631 |
//
|
|
632 |
void VideoThumbnailDataPrivate::continueBackgroundFetch()
|
|
633 |
{
|
36
|
634 |
FUNC_LOG;
|
30
|
635 |
if(!mBackgroundFetchingEnabled)
|
36
|
636 |
{
|
37
|
637 |
INFO("VideoThumbnailDataPrivate::continueBackgroundFetch() fetching is disabled.")
|
30
|
638 |
return;
|
36
|
639 |
}
|
30
|
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 |
{
|
36
|
655 |
FUNC_LOG;
|
30
|
656 |
cleanup();
|
|
657 |
}
|
|
658 |
|
|
659 |
// End of file
|