--- a/ui/uiengine/model/mediamodel/src/glxmediamodel.cpp Tue Jul 06 14:16:16 2010 +0300
+++ b/ui/uiengine/model/mediamodel/src/glxmediamodel.cpp Wed Aug 18 09:48:53 2010 +0300
@@ -33,17 +33,23 @@
#include <glxperformancemacro.h>
#include "glxicondefs.h" //Contains the icon names/Ids
-#include<glxviewids.h>
+#include "glxcollectionpluginall.hrh"
+#include "glxviewids.h"
+
+#define DELTA_IMAGE 5
+#define INITIAL_POPULATE_IMAGE_COUNT 30
GlxMediaModel::GlxMediaModel(GlxModelParm & modelParm)
{
qDebug("GlxMediaModel::GlxMediaModel");
+ thumbnailPopulatedFlag = modelParm.collection() == KGlxCollectionPluginAllImplementationUid ? false : true;
mMLWrapper = new GlxMLWrapper(modelParm.collection(),0,EGlxFilterImage);
mMLWrapper->setContextMode( modelParm.contextMode() );
mContextMode = modelParm.contextMode( ) ;
mDRMUtilityWrapper = new GlxDRMUtilityWrapper();
- int err = connect(mMLWrapper, SIGNAL(updateItem(int, GlxTBContextType)), this, SLOT(itemUpdated1(int, GlxTBContextType)));
+
+ int err = connect(mMLWrapper, SIGNAL(updateItem(int, GlxTBContextType)), this, SLOT(itemUpdated(int, GlxTBContextType)));
qDebug("updateItem() connection status %d", err);
err = connect(mMLWrapper, SIGNAL(itemCorrupted(int)), this, SLOT(itemCorrupted(int)));
qDebug("itemCorrupted() connection status %d", err);
@@ -62,8 +68,8 @@
itemFsIconCache.setMaxCost(5);
itemExternalIconCache.setMaxCost(0);
- //todo get this Default icon from some generic path and not directly.
- m_DefaultIcon = new HbIcon(GLXICON_DEFAULT);
+ m_DefaultIcon = new HbIcon( GLXICON_DEFAULT );
+ m_CorruptIcon = new HbIcon( GLXICON_CORRUPT );
mExternalItems = NULL;
externalDataCount = 0;
mFocusIndex = -1;
@@ -79,15 +85,9 @@
itemFsIconCache.clear();
delete m_DefaultIcon;
m_DefaultIcon = NULL;
+ delete m_CorruptIcon;
+ m_CorruptIcon = NULL;
clearExternalItems();
- int err = disconnect(mMLWrapper, SIGNAL(updateItem(int, GlxTBContextType)), this, SLOT(itemUpdated1(int, GlxTBContextType)));
- err = disconnect(mMLWrapper, SIGNAL(itemCorrupted(int)), this, SLOT(itemCorrupted(int)));
- err = disconnect(mMLWrapper, SIGNAL(insertItems(int, int)), this, SLOT(itemsAdded(int, int)));
- err = disconnect(mMLWrapper, SIGNAL(removeItems(int, int)), this, SLOT(itemsRemoved(int, int)));
- err = disconnect(this, SIGNAL(iconAvailable(int, HbIcon*, GlxTBContextType)), this, SLOT(updateItemIcon(int, HbIcon*, GlxTBContextType)));
- err = disconnect(mMLWrapper, SIGNAL(updateAlbumTitle(QString)), this, SLOT(albumTitleUpdated(QString)));
- err = disconnect(mMLWrapper, SIGNAL(populated()), this, SLOT(modelpopulated()));
- err = disconnect(mMLWrapper, SIGNAL(updateDetails()), this, SLOT(updateDetailItems()));
delete mMLWrapper;
delete mDRMUtilityWrapper;
}
@@ -177,12 +177,11 @@
//todo refactor this whole function ... too many return statements are not good
-QVariant GlxMediaModel::data(const QModelIndex &index, int role) const
+QVariant GlxMediaModel::data( const QModelIndex &index, int role ) const
{
- if (role == GlxViewTitle)
- {
+ if (role == GlxViewTitle) {
return mMLWrapper->retrieveViewTitle();
- }
+ }
if(role == GlxPopulated) {
return mMLWrapper->IsPopulated();
@@ -204,12 +203,11 @@
if(!m_DefaultIcon->isNull()) {
// this image Creation is Slow.
// But what to do, Q class's Does not undersatnd our Localised File names
- return m_DefaultIcon->pixmap().toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
- }
+ return m_DefaultIcon->pixmap().toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
+ }
else {
return QImage();
- }
-
+ }
}
HbIcon* itemIcon = NULL;
@@ -220,31 +218,18 @@
return QVariant();
}
-//external data are always placed at the beginning of the Media List
-//Check if the index can be mapped to the external data
-//if not then map the index to Ml Index
- if(itemIndex < externalDataCount) {
- if(role == Qt::DecorationRole || role == GlxFsImageRole){
- return *(GetExternalIconItem(itemIndex,GlxTBContextExternal));
- }
- }
- else {
- itemIndex -= externalDataCount;
- }
-
-//retrieve Data from Media List
- if (role == Qt::DecorationRole) {
+ //retrieve Data from Media List
+ if ( role == Qt::DecorationRole ) {
itemIcon = GetGridIconItem(itemIndex,GlxTBContextGrid);
- if(itemIcon == NULL || itemIcon->isNull() ){
- itemIcon = m_DefaultIcon;
+ if( itemIcon == NULL || itemIcon->isNull() ) {
+ itemIcon = getCorruptDefaultIcon( index );
}
return *itemIcon;
}
- if (role == GlxQImageSmall)
- {
+ if (role == GlxQImageSmall) {
return mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextGrid);
- }
+ }
if (role == GlxFsImageRole){
if(mContextMode == GlxContextLsFs){
@@ -254,14 +239,17 @@
itemIcon = GetFsIconItem(itemIndex,GlxTBContextPtFs);
}
- if ( itemIcon == NULL) {
- //itemIcon = GetGridIconItem(itemIndex,GlxTBContextGrid);
+ if ( itemIcon == NULL ) {
HbIcon* tempIcon = GetGridIconItem( itemIndex, GlxTBContextGrid );
if (tempIcon && !tempIcon->isNull()) {
qDebug("GlxMediaModel::scaling thumbnail");
QPixmap tempPixmap = tempIcon->qicon().pixmap(128, 128);
+ QSize itemSize = mMLWrapper->retrieveItemDimension(itemIndex);
QSize sz = ( mContextMode == GlxContextLsFs ) ? QSize ( 640, 360) : QSize ( 360, 640 );
- tempPixmap = tempPixmap.scaled(sz, Qt::KeepAspectRatio );
+ if( !( ( itemSize.width() < sz.width() ) && ( itemSize.height() < sz.height() ) ) ) {
+ itemSize.scale(sz, Qt::KeepAspectRatio);
+ }
+ tempPixmap = tempPixmap.scaled(itemSize, Qt::IgnoreAspectRatio );
HbIcon tmp = HbIcon( QIcon(tempPixmap)) ;
if(!tmp.isNull()){
return tmp;
@@ -270,79 +258,76 @@
}
if ( itemIcon == NULL || itemIcon->isNull() ) {
- itemIcon = m_DefaultIcon;
+ itemIcon = getCorruptDefaultIcon( index ) ;
}
return *itemIcon;
}
- if (role == GlxQImageLarge)
- {
- if(mContextMode == GlxContextLsFs)
- {
+ if (role == GlxQImageLarge) {
+ if(mContextMode == GlxContextLsFs) {
itemImage = mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextLsFs);
- }
- else
- {
+ }
+ else {
itemImage = mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextPtFs);
- }
- if(!itemImage.isNull())
- {
+ }
+ if(!itemImage.isNull()) {
return itemImage;
- }
- else
- {
+ }
+ else {
itemImage = mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextGrid);
- if (!itemImage.isNull())
- {
+ if (!itemImage.isNull()) {
QSize sz = ( mContextMode == GlxContextLsFs ) ? QSize ( 640, 360) : QSize ( 360, 640 );
itemImage = itemImage.scaled(sz,Qt::KeepAspectRatio);
- }
- return itemImage;
}
+ return itemImage;
}
+ }
- if (role == GlxVisualWindowIndex)
- {
+ if (role == GlxVisualWindowIndex) {
return mMLWrapper->getVisibleWindowIndex();
- }
+ }
QModelIndex idx;
if ( GlxFocusIndexRole == role ) {
idx = getFocusIndex();
return idx.row();
}
+
if(role == GlxUriRole) {
return (mMLWrapper->retrieveItemUri(itemIndex));
}
+
if(role == GlxDimensionsRole) {
return (mMLWrapper->retrieveItemDimension(itemIndex));
}
if(role == GlxDateRole ) {
- qDebug("GlxMediaModel::data GlxDateRole ");
return (mMLWrapper->retrieveItemDate(itemIndex));
}
if (role == GlxFrameCount) {
- qDebug("GlxMediaModel:: GlxFrameCount ");
- return (mMLWrapper->retrieveItemFrameCount(itemIndex));
+ return (mMLWrapper->retrieveItemFrameCount(itemIndex));
}
if (role == GlxHdmiBitmap) {
return mMLWrapper->RetrieveBitmap(itemIndex);
}
+
+ if ( role == GlxImageCorruptRole ) {
+ return mMLWrapper->isCorruptedImage( itemIndex );
+ }
if (role == GlxTimeRole) {
return mMLWrapper->retrieveItemTime(itemIndex);
}
if (role == GlxSizeRole) {
- return mMLWrapper->retrieveItemSize(itemIndex);
- }
+ return mMLWrapper->retrieveItemSize(itemIndex);
+ }
- if (role == GlxDescRole) {
- return mMLWrapper->retrieveListDesc(itemIndex);
- }
+ if (role == GlxDescRole) {
+ return mMLWrapper->retrieveListDesc(itemIndex);
+ }
return QVariant();
}
@@ -411,32 +396,43 @@
}
-void GlxMediaModel::itemUpdated1(int mlIndex,GlxTBContextType tbContextType )
+void GlxMediaModel::itemUpdated(int mlIndex,GlxTBContextType tbContextType )
{
qDebug("GlxMediaModel::itemUpdated %d", mlIndex);
//clear the grid and FS cache if they have any icons with them for that index
- if(tbContextType == GlxTBContextGrid) {
- itemIconCache.remove(mlIndex);
+ if( tbContextType == GlxTBContextGrid ) {
+ if ( !thumbnailPopulatedFlag ) {
+ thumbnailPopulatedCheck( mlIndex );
+ }
+ itemIconCache.remove(mlIndex);
}
if(tbContextType == GlxTBContextLsFs || tbContextType == GlxTBContextPtFs) {
itemFsIconCache.remove(mlIndex);
}
- emit dataChanged(index(mlIndex+externalDataCount,0),index(mlIndex+externalDataCount,0));
-
+ emit dataChanged( index( mlIndex , 0 ), index( mlIndex, 0 ) );
}
void GlxMediaModel::itemCorrupted(int itemIndex)
{
qDebug("GlxMediaModel::itemCorrupted %d", itemIndex);
- emit dataChanged(index(itemIndex+externalDataCount,0),index(itemIndex+externalDataCount,0));
+ if ( !thumbnailPopulatedFlag ) {
+ thumbnailPopulatedCheck( itemIndex );
+ }
+ emit dataChanged( index( itemIndex , 0 ), index( itemIndex, 0 ) );
}
void GlxMediaModel::modelpopulated()
{
if ( mTempVisibleWindowIndex!=-1) {
- mMLWrapper->setVisibleWindowIndex(mTempVisibleWindowIndex);
+ //Set the visible Window index only ff the index stored in the activity manager is not out of range
+ if( rowCount() > mTempVisibleWindowIndex && mTempVisibleWindowIndex > 0 ) {
+ mMLWrapper->setVisibleWindowIndex(mTempVisibleWindowIndex);
+ }
+ else {
+ mMLWrapper->setVisibleWindowIndex(0);
+ }
mTempVisibleWindowIndex = -1;
- }
+ }
emit populated();
}
@@ -550,6 +546,24 @@
mMLWrapper->setSelectedIndex(itemIndex);
}
+HbIcon * GlxMediaModel::getCorruptDefaultIcon( const QModelIndex &index ) const
+{
+ if ( mMLWrapper->isCorruptedImage( index.row() ) ) {
+ return m_CorruptIcon ;
+ }
+ return m_DefaultIcon ;
+}
+
+void GlxMediaModel::thumbnailPopulatedCheck( int index )
+{
+ int count = rowCount() - DELTA_IMAGE ;
+ int maxRange = INITIAL_POPULATE_IMAGE_COUNT + DELTA_IMAGE ;
+ if ( index >= count || ( index >= INITIAL_POPULATE_IMAGE_COUNT && index < maxRange ) ) {
+ thumbnailPopulatedFlag = TRUE;
+ emit thumbnailPopulated();
+ }
+}
+
bool GlxMediaModel::setData ( const QModelIndex & idx, const QVariant & value, int role )
{
Q_UNUSED( idx )