52 Constructs the collection data model. |
52 Constructs the collection data model. |
53 */ |
53 */ |
54 HgWidgetTestDataModel::HgWidgetTestDataModel(QObject *parent) |
54 HgWidgetTestDataModel::HgWidgetTestDataModel(QObject *parent) |
55 : QAbstractListModel(parent), |
55 : QAbstractListModel(parent), |
56 mCachingInProgress(false), |
56 mCachingInProgress(false), |
57 mImageType(TypeQImage), |
57 mImageType(ImageTypeNone), |
58 mDefaultIcon((":/images/default.svg")), |
58 mDefaultIcon((":/images/default.svg")), |
59 mUseLowResImages(false) |
59 mUseLowResImages(false), |
|
60 mWrapper( new ThumbnailManager() ), |
|
61 mThumbnailRequestPending(false), |
|
62 mThumbnailRequestIndex(-1), |
|
63 mThumbnailRequestID(-1), |
|
64 mBufferManager(0) |
60 { |
65 { |
61 FUNC_LOG; |
66 FUNC_LOG; |
62 |
67 mWrapper->setQualityPreference( ThumbnailManager::OptimizeForPerformance ); |
63 mAlbumArtManager = new HgWidgetTestAlbumArtManager; |
68 |
64 connect( mAlbumArtManager, SIGNAL(albumArtReady(int)), this, SLOT(updateAlbumArt(int)) ); |
69 mWrapper->setProperty("qimageSupport","true"); |
65 connect( mAlbumArtManager, SIGNAL(albumCacheReady()), this, SLOT(albumCacheReady()) ); |
70 |
|
71 QObject::connect( mWrapper, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ), |
|
72 this, SLOT( thumbnailReady( QPixmap , void* , int , int ))); |
|
73 |
66 init(); |
74 init(); |
67 } |
75 } |
68 |
76 |
69 /*! |
77 /*! |
70 Destructs the collection data model. |
78 Destructs the collection data model. |
71 */ |
79 */ |
72 HgWidgetTestDataModel::~HgWidgetTestDataModel() |
80 HgWidgetTestDataModel::~HgWidgetTestDataModel() |
73 { |
81 { |
74 FUNC_LOG; |
82 FUNC_LOG; |
75 |
83 |
76 disconnect( mAlbumArtManager, SIGNAL(albumArtReady(int)), this, SLOT(updateAlbumArt(int)) ); |
84 disconnect( mWrapper, SIGNAL(thumbnailReady( QPixmap , void* , int , int )), this, SLOT(thumbnailReady( QPixmap , void* , int , int )) ); |
77 disconnect( mAlbumArtManager, SIGNAL(albumCacheReady()), this, SLOT(albumCacheReady()) ); |
85 delete mWrapper; |
78 delete mAlbumArtManager; |
86 delete mBufferManager; |
79 } |
87 } |
80 |
88 |
81 void HgWidgetTestDataModel::setThumbnailSize(ThumbnailManager::ThumbnailSize size) |
89 void HgWidgetTestDataModel::setThumbnailSize(ThumbnailManager::ThumbnailSize size) |
82 { |
90 { |
83 mAlbumArtManager->setThumbnailSize(size); |
91 mWrapper->setThumbnailSize(size); |
84 } |
92 } |
85 |
93 |
86 void HgWidgetTestDataModel::init() |
94 void HgWidgetTestDataModel::init() |
87 { |
95 { |
88 FUNC_LOG; |
96 FUNC_LOG; |
101 QFileInfo fileInfo = list.at(i); |
109 QFileInfo fileInfo = list.at(i); |
102 if (fileInfo.isFile()){ |
110 if (fileInfo.isFile()){ |
103 QString s = fileInfo.filePath(); |
111 QString s = fileInfo.filePath(); |
104 if (s.indexOf(QString(".jpg"),0,Qt::CaseInsensitive)>0){ |
112 if (s.indexOf(QString(".jpg"),0,Qt::CaseInsensitive)>0){ |
105 mFiles.append(s); |
113 mFiles.append(s); |
|
114 mImages.append(QImage()); |
106 mVisibility.append(true); |
115 mVisibility.append(true); |
107 } |
116 } |
108 } |
117 } |
109 } |
118 } |
110 |
119 |
111 QPixmap pixmap(":/images/default.svg"); |
120 QPixmap pixmap(":/images/default.svg"); |
112 if (!pixmap.isNull()){ |
121 if (!pixmap.isNull()){ |
113 mQIcon = QIcon(pixmap); |
122 mQIcon = QIcon(pixmap); |
114 if (!mQIcon.isNull()){ |
123 if (!mQIcon.isNull()){ |
115 mHbIcon = HbIcon(mQIcon); |
124 mHbIcon = HbIcon(mQIcon); |
116 } |
125 } |
117 } |
126 } |
118 } |
127 } |
119 |
128 |
120 /*! |
129 /*! |
173 // INFO("Requesting model item" << row << ", " << mFiles.at(row)); |
185 // INFO("Requesting model item" << row << ", " << mFiles.at(row)); |
174 if (mFiles.at(row).isEmpty()) { |
186 if (mFiles.at(row).isEmpty()) { |
175 returnValue = mDefaultIcon; |
187 returnValue = mDefaultIcon; |
176 } |
188 } |
177 else { |
189 else { |
178 QImage icon = mAlbumArtManager->albumArt(mFiles.at(row), row); |
190 QImage icon = mImages.at(row); |
179 if ( !icon.isNull() ) |
191 if ( !icon.isNull() ) |
180 { |
192 { |
181 if (mUseLowResImages) { |
193 if (mUseLowResImages) { |
182 QSize size = icon.size(); |
194 QSize size = icon.size(); |
183 icon = icon.scaled(QSize(size.width()/4, size.height()/4)); |
195 icon = icon.scaled(QSize(size.width()/4, size.height()/4)); |
184 } |
196 } |
185 |
197 |
186 switch(mImageType) |
198 switch(mImageType) |
187 { |
199 { |
188 case TypeHbIcon: |
200 case ImageTypeHbIcon: |
189 { |
201 { |
190 returnValue = mHbIcon; |
202 returnValue = mHbIcon; |
191 break; |
203 break; |
192 } |
204 } |
193 case TypeQImage: |
205 case ImageTypeQImage: |
194 { |
206 { |
195 returnValue = icon; |
207 returnValue = icon; |
196 break; |
208 break; |
197 } |
209 } |
198 case TypeQIcon: |
210 case ImageTypeQIcon: |
199 { |
211 { |
200 returnValue = mQIcon; |
212 returnValue = mQIcon; |
201 break; |
213 break; |
202 } |
214 } |
203 default: |
215 default: |
204 break; |
216 break; |
205 } |
217 } |
206 |
218 |
207 } |
219 } |
208 else |
220 else |
209 { |
221 { |
210 returnValue = mDefaultIcon; |
222 returnValue = mDefaultIcon; |
211 } |
223 } |
250 to reflect the new data. |
262 to reflect the new data. |
251 */ |
263 */ |
252 void HgWidgetTestDataModel::refreshModel() |
264 void HgWidgetTestDataModel::refreshModel() |
253 { |
265 { |
254 // Cancel all outstanding album art request first, then reset the model. |
266 // Cancel all outstanding album art request first, then reset the model. |
255 mAlbumArtManager->cancel(); |
267 |
256 |
268 // TODO FIX |
257 // Before providing the new data to the view (list, grid, etc.), we want |
269 |
258 // to make sure that we have enough album arts for the first screen. |
|
259 /* mFiles.count() = mCollectionData->count(); |
|
260 if ( mFiles.count() > 0 ) { |
|
261 int initCount = ( mFiles.count() > KInitCacheSize ) ? KInitCacheSize : mFiles.count(); |
|
262 QStringList albumArtList; |
|
263 QString albumArtUri; |
|
264 for ( int i = 0; i < initCount; i++ ) { |
|
265 albumArtUri = mCollectionData->itemData(i, MpMpxCollectionData::AlbumArtUri); |
|
266 if ( !albumArtUri.isEmpty() ) { |
|
267 albumArtList << albumArtUri; |
|
268 } |
|
269 } |
|
270 mCachingInProgress = mAlbumArtManager->cacheAlbumArt(albumArtList); |
|
271 if ( !mCachingInProgress ) { |
|
272 reset(); |
|
273 } |
|
274 } |
|
275 else { |
|
276 reset(); |
|
277 } |
|
278 */ |
|
279 } |
270 } |
280 |
271 |
281 /*! |
272 /*! |
282 Remove items from model (do not actually delete them). |
273 Remove items from model (do not actually delete them). |
283 */ |
274 */ |
414 bool HgWidgetTestDataModel::lowResImagesEnabled() const { |
418 bool HgWidgetTestDataModel::lowResImagesEnabled() const { |
415 |
419 |
416 return mUseLowResImages; |
420 return mUseLowResImages; |
417 } |
421 } |
418 |
422 |
|
423 void HgWidgetTestDataModel::getNextThumbnail() |
|
424 { |
|
425 if ( !mThumbnailRequestPending && mWaitingThumbnails.count()){ |
|
426 QString image = mWaitingThumbnails.takeFirst(); |
|
427 int index = mFiles.indexOf(image); |
|
428 int *clientData = new int(index); |
|
429 mThumbnailRequestID = mWrapper->getThumbnail(image, clientData, -1); |
|
430 mThumbnailRequestIndex = index; |
|
431 mThumbnailRequestPending = true; |
|
432 } |
|
433 } |
|
434 |
|
435 void HgWidgetTestDataModel::setBuffer(int buffer, int treshhold) |
|
436 { |
|
437 mWaitingThumbnails.clear(); |
|
438 |
|
439 if (mThumbnailRequestID!=-1){ |
|
440 mWrapper->cancelRequest(mThumbnailRequestID); |
|
441 } |
|
442 |
|
443 mThumbnailRequestID = -1; |
|
444 mThumbnailRequestIndex = -1; |
|
445 mThumbnailRequestPending = false; |
|
446 |
|
447 delete mBufferManager; |
|
448 mBufferManager = 0; |
|
449 mBufferManager = new BufferManager(this, buffer, treshhold, 0, mFiles.count()); |
|
450 for (int i = 0; i<mImages.count();i++) { |
|
451 mImages.replace(i, QImage()); |
|
452 } |
|
453 } |
|
454 |
|
455 void HgWidgetTestDataModel::release(int start, int end) |
|
456 { |
|
457 bool requestNew = false; |
|
458 int first = (start<=end)?start:end; |
|
459 if (first<0) |
|
460 first =0; |
|
461 |
|
462 int last = end>=start?end:start; |
|
463 if (last>=mFiles.count()) |
|
464 last=mFiles.count()-1; |
|
465 |
|
466 |
|
467 for (int i(first); i<=last; i++){ |
|
468 mWaitingThumbnails.removeOne(mFiles.at(i)); |
|
469 if (mThumbnailRequestIndex==i && mThumbnailRequestID!=-1){ |
|
470 mWrapper->cancelRequest(mThumbnailRequestID); |
|
471 requestNew = true; |
|
472 } |
|
473 mImages.replace(i,QImage()); |
|
474 } |
|
475 |
|
476 if (requestNew){ |
|
477 mThumbnailRequestIndex = -1; |
|
478 mThumbnailRequestID = -1; |
|
479 mThumbnailRequestPending = false; |
|
480 getNextThumbnail(); |
|
481 } |
|
482 } |
|
483 |
|
484 void HgWidgetTestDataModel::request(int start, int end, requestsOrder order) |
|
485 { |
|
486 int first = start; |
|
487 int last = end; |
|
488 |
|
489 if (first<0) |
|
490 first =0; |
|
491 |
|
492 if (last>=mFiles.count()) |
|
493 last=mFiles.count()-1; |
|
494 |
|
495 if (order == ascending){ |
|
496 for (int i(first); i<=last; i++){ |
|
497 mWaitingThumbnails.append(mFiles.at(i)); |
|
498 } |
|
499 } else if (order ==descending){ |
|
500 for (int i(last); i>=first; i--){ |
|
501 mWaitingThumbnails.append(mFiles.at(i)); |
|
502 } |
|
503 } |
|
504 |
|
505 getNextThumbnail(); |
|
506 } |
|
507 |
|
508 void HgWidgetTestDataModel::thumbnailReady( QPixmap pixmap, void* data, int /*id*/, int error ) |
|
509 { |
|
510 if (!error && !pixmap.isNull() ){ |
|
511 // int idx = reinterpret_cast<int>(data); |
|
512 mImages.replace(mThumbnailRequestIndex,pixmap.toImage().convertToFormat(QImage::Format_RGB16)); |
|
513 QModelIndex modelIndex = QAbstractItemModel::createIndex(mThumbnailRequestIndex, 0); |
|
514 emit dataChanged(modelIndex, modelIndex); |
|
515 } |
|
516 mThumbnailRequestIndex = -1; |
|
517 mThumbnailRequestID = -1; |
|
518 mThumbnailRequestPending = false; |
|
519 getNextThumbnail(); |
|
520 } |
|
521 |