ui/uiengine/model/mediamodel/src/glxmediamodel.cpp
changeset 50 a0f57508af73
parent 45 863223ea6961
child 54 0f0f3f26f787
equal deleted inserted replaced
45:863223ea6961 50:a0f57508af73
    60 	
    60 	
    61 	itemIconCache.setMaxCost(20);  //Changed While Doing Media Wall
    61 	itemIconCache.setMaxCost(20);  //Changed While Doing Media Wall
    62 	itemFsIconCache.setMaxCost(5);
    62 	itemFsIconCache.setMaxCost(5);
    63 	itemExternalIconCache.setMaxCost(0);
    63 	itemExternalIconCache.setMaxCost(0);
    64 	
    64 	
    65 	//todo get this Default icon from some generic path and not directly.
       
    66 	m_DefaultIcon = new HbIcon(GLXICON_DEFAULT);
    65 	m_DefaultIcon = new HbIcon(GLXICON_DEFAULT);
       
    66 	m_CorruptIcon = new HbIcon( GLXICON_CORRUPT );
    67 	mExternalItems = NULL;
    67 	mExternalItems = NULL;
    68 	externalDataCount = 0;
    68 	externalDataCount = 0;
    69 	mFocusIndex = -1;
    69 	mFocusIndex = -1;
    70 	mSubState = -1;
    70 	mSubState = -1;
    71 	mTempVisibleWindowIndex = 0;
    71 	mTempVisibleWindowIndex = 0;
    77 	qDebug("GlxMediaModel::~GlxMediaModel");
    77 	qDebug("GlxMediaModel::~GlxMediaModel");
    78 	itemIconCache.clear();
    78 	itemIconCache.clear();
    79 	itemFsIconCache.clear();
    79 	itemFsIconCache.clear();
    80 	delete m_DefaultIcon;
    80 	delete m_DefaultIcon;
    81 	m_DefaultIcon = NULL;
    81 	m_DefaultIcon = NULL;
       
    82 	delete m_CorruptIcon;
       
    83 	m_CorruptIcon = NULL;
    82 	clearExternalItems();
    84 	clearExternalItems();
    83   int err = disconnect(mMLWrapper, SIGNAL(updateItem(int, GlxTBContextType)), this, SLOT(itemUpdated1(int, GlxTBContextType)));
    85     int err = disconnect(mMLWrapper, SIGNAL(updateItem(int, GlxTBContextType)), this, SLOT(itemUpdated1(int, GlxTBContextType)));
    84 	err = disconnect(mMLWrapper, SIGNAL(itemCorrupted(int)), this, SLOT(itemCorrupted(int)));
    86 	err = disconnect(mMLWrapper, SIGNAL(itemCorrupted(int)), this, SLOT(itemCorrupted(int)));
    85 	err = disconnect(mMLWrapper, SIGNAL(insertItems(int, int)), this, SLOT(itemsAdded(int, int)));
    87 	err = disconnect(mMLWrapper, SIGNAL(insertItems(int, int)), this, SLOT(itemsAdded(int, int)));
    86 	err = disconnect(mMLWrapper, SIGNAL(removeItems(int, int)), this, SLOT(itemsRemoved(int, int)));
    88 	err = disconnect(mMLWrapper, SIGNAL(removeItems(int, int)), this, SLOT(itemsRemoved(int, int)));
    87 	err = disconnect(this, SIGNAL(iconAvailable(int, HbIcon*, GlxTBContextType)), this, SLOT(updateItemIcon(int, HbIcon*, GlxTBContextType)));
    89 	err = disconnect(this, SIGNAL(iconAvailable(int, HbIcon*, GlxTBContextType)), this, SLOT(updateItemIcon(int, HbIcon*, GlxTBContextType)));
    88 	err = disconnect(mMLWrapper, SIGNAL(updateAlbumTitle(QString)), this, SLOT(albumTitleUpdated(QString)));	    
    90 	err = disconnect(mMLWrapper, SIGNAL(updateAlbumTitle(QString)), this, SLOT(albumTitleUpdated(QString)));	    
   175     return QModelIndex();
   177     return QModelIndex();
   176 }
   178 }
   177 
   179 
   178 
   180 
   179 //todo refactor this whole function ... too many return statements are not good
   181 //todo refactor this whole function ... too many return statements are not good
   180 QVariant GlxMediaModel::data(const QModelIndex &index, int role) const
   182 QVariant GlxMediaModel::data( const QModelIndex &index, int role ) const
   181 {
   183 {
   182     if (role == GlxViewTitle)
   184     if (role == GlxViewTitle) {
   183         {
       
   184         return mMLWrapper->retrieveViewTitle();
   185         return mMLWrapper->retrieveViewTitle();
   185         }
   186     }
   186 
   187 
   187     if(role == GlxPopulated) {
   188     if(role == GlxPopulated) {
   188         return mMLWrapper->IsPopulated();
   189         return mMLWrapper->IsPopulated();
   189     }
   190     }
   190 
   191 
   202     
   203     
   203     if ( role == GlxDefaultImage ) {
   204     if ( role == GlxDefaultImage ) {
   204         if(!m_DefaultIcon->isNull()) {
   205         if(!m_DefaultIcon->isNull()) {
   205             // this image Creation is Slow. 
   206             // this image Creation is Slow. 
   206             // But what to do, Q class's Does not undersatnd our Localised File names
   207             // But what to do, Q class's Does not undersatnd our Localised File names
   207         return m_DefaultIcon->pixmap().toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
   208             return m_DefaultIcon->pixmap().toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
   208     }
   209         }
   209         else {
   210         else {
   210             return QImage();
   211             return QImage();
   211         }
   212         }            
   212             
       
   213     }
   213     }
   214 
   214 
   215     HbIcon* itemIcon = NULL;
   215     HbIcon* itemIcon = NULL;
   216     QImage itemImage;
   216     QImage itemImage;
   217     int itemIndex = index.row();
   217     int itemIndex = index.row();
   218     qDebug("GlxMediaModel::data buffer concept index %d role %d", index.row(), role);
   218     qDebug("GlxMediaModel::data buffer concept index %d role %d", index.row(), role);
   219     if ((!index.isValid()) || (index.row() > rowCount()-1)) {
   219     if ((!index.isValid()) || (index.row() > rowCount()-1)) {
   220          return QVariant();
   220          return QVariant();
   221     }
   221     }
   222     
   222     
   223 //external data are always placed at the beginning of the Media List
   223     //retrieve Data from Media List		
   224 //Check if the index can be mapped to the external data
   224     if ( role == Qt::DecorationRole ) {
   225 //if not then map the index to Ml Index
       
   226     if(itemIndex < externalDataCount) {
       
   227         if(role == Qt::DecorationRole || role == GlxFsImageRole){
       
   228             return *(GetExternalIconItem(itemIndex,GlxTBContextExternal));
       
   229         }
       
   230     }
       
   231     else {
       
   232         itemIndex -=  externalDataCount;
       
   233     }
       
   234     
       
   235 //retrieve Data from Media List		
       
   236     if (role == Qt::DecorationRole) {
       
   237         itemIcon = GetGridIconItem(itemIndex,GlxTBContextGrid);
   225         itemIcon = GetGridIconItem(itemIndex,GlxTBContextGrid);
   238         if(itemIcon == NULL || itemIcon->isNull() ){
   226         if( itemIcon == NULL || itemIcon->isNull() ) {
   239             itemIcon = m_DefaultIcon;
   227             itemIcon = getCorruptDefaultIcon( index );
   240         }
   228         }
   241         return *itemIcon;
   229         return *itemIcon;
   242     }
   230     }
   243 		
   231 		
   244     if (role == GlxQImageSmall)
   232     if (role == GlxQImageSmall) {
   245         {
       
   246         return mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextGrid);
   233         return mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextGrid);
   247         }
   234     }
   248 
   235 
   249     if (role == GlxFsImageRole){
   236     if (role == GlxFsImageRole){
   250         if(mContextMode == GlxContextLsFs){
   237         if(mContextMode == GlxContextLsFs){
   251             itemIcon = GetFsIconItem(itemIndex,GlxTBContextLsFs);
   238             itemIcon = GetFsIconItem(itemIndex,GlxTBContextLsFs);
   252         }
   239         }
   253         else if (mContextMode == GlxContextPtFs){
   240         else if (mContextMode == GlxContextPtFs){
   254             itemIcon = GetFsIconItem(itemIndex,GlxTBContextPtFs);
   241             itemIcon = GetFsIconItem(itemIndex,GlxTBContextPtFs);
   255         }
   242         }
   256         
   243         
   257         if ( itemIcon == NULL) {
   244         if ( itemIcon == NULL ) {  
   258             //itemIcon = GetGridIconItem(itemIndex,GlxTBContextGrid);    
       
   259             HbIcon* tempIcon = GetGridIconItem( itemIndex, GlxTBContextGrid );
   245             HbIcon* tempIcon = GetGridIconItem( itemIndex, GlxTBContextGrid );
   260             if (tempIcon && !tempIcon->isNull()) {
   246             if (tempIcon && !tempIcon->isNull()) {
   261                 qDebug("GlxMediaModel::scaling thumbnail");
   247                 qDebug("GlxMediaModel::scaling thumbnail");
   262                 QPixmap tempPixmap = tempIcon->qicon().pixmap(128, 128);
   248                 QPixmap tempPixmap = tempIcon->qicon().pixmap(128, 128);
       
   249                 QSize itemSize = mMLWrapper->retrieveItemDimension(itemIndex);
   263                 QSize sz = ( mContextMode == GlxContextLsFs ) ? QSize ( 640, 360) : QSize ( 360, 640 );
   250                 QSize sz = ( mContextMode == GlxContextLsFs ) ? QSize ( 640, 360) : QSize ( 360, 640 );
   264                 tempPixmap = tempPixmap.scaled(sz, Qt::KeepAspectRatio );
   251                 if(!((itemSize.width() < sz.width()) && (itemSize.height() < sz.height()))); {
       
   252                     itemSize.scale(sz, Qt::KeepAspectRatio);
       
   253                 }
       
   254                 tempPixmap = tempPixmap.scaled(itemSize, Qt::IgnoreAspectRatio );
   265                 HbIcon tmp = HbIcon( QIcon(tempPixmap)) ;
   255                 HbIcon tmp = HbIcon( QIcon(tempPixmap)) ;
   266 				if(!tmp.isNull()){
   256 				if(!tmp.isNull()){
   267 					return tmp;
   257 					return tmp;
   268 				}
   258 				}
   269             }
   259             }
   270         }
   260         }
   271 		  
   261 		  
   272         if ( itemIcon == NULL || itemIcon->isNull() ) {
   262         if ( itemIcon == NULL || itemIcon->isNull() ) {
   273             itemIcon = m_DefaultIcon;
   263             itemIcon = getCorruptDefaultIcon( index ) ;
   274         }
   264         }
   275         return *itemIcon;
   265         return *itemIcon;
   276     }
   266     }
   277 	
   267 	
   278     if (role == GlxQImageLarge)
   268     if (role == GlxQImageLarge) {
   279         {
   269         if(mContextMode == GlxContextLsFs) {
   280         if(mContextMode == GlxContextLsFs)
       
   281             {
       
   282             itemImage = mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextLsFs);
   270             itemImage = mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextLsFs);
   283             }
   271         }
   284         else
   272         else {
   285             {
       
   286             itemImage = mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextPtFs);
   273             itemImage = mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextPtFs);
   287             }
   274         }
   288         if(!itemImage.isNull()) 
   275         if(!itemImage.isNull()) {
   289             {
       
   290             return itemImage;
   276             return itemImage;
   291             }
   277         }
   292         else 
   278         else {
   293             {
       
   294             itemImage =  mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextGrid);
   279             itemImage =  mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextGrid);
   295             if (!itemImage.isNull()) 
   280             if (!itemImage.isNull()) {
   296                 {
       
   297                 QSize sz = ( mContextMode == GlxContextLsFs ) ? QSize ( 640, 360) : QSize ( 360, 640 );
   281                 QSize sz = ( mContextMode == GlxContextLsFs ) ? QSize ( 640, 360) : QSize ( 360, 640 );
   298                 itemImage = itemImage.scaled(sz,Qt::KeepAspectRatio); 
   282                 itemImage = itemImage.scaled(sz,Qt::KeepAspectRatio); 
   299                 }
       
   300                 return itemImage;
       
   301             }
   283             }
   302         }
   284             return itemImage;
   303     
   285         }
   304     if (role == GlxVisualWindowIndex)
   286     }
   305         {
   287     
       
   288     if (role == GlxVisualWindowIndex) {
   306         return mMLWrapper->getVisibleWindowIndex();
   289         return mMLWrapper->getVisibleWindowIndex();
   307         }
   290     }
   308 	
   291 	
   309     QModelIndex idx;
   292     QModelIndex idx;
   310     if ( GlxFocusIndexRole == role ) {
   293     if ( GlxFocusIndexRole == role ) {
   311         idx = getFocusIndex();
   294         idx = getFocusIndex();
   312         return idx.row();
   295         return idx.row();
   313     }
   296     }
       
   297     
   314     if(role == GlxUriRole) {
   298     if(role == GlxUriRole) {
   315         return (mMLWrapper->retrieveItemUri(itemIndex));
   299         return (mMLWrapper->retrieveItemUri(itemIndex));
   316     }
   300     }
       
   301     
   317     if(role == GlxDimensionsRole) {
   302     if(role == GlxDimensionsRole) {
   318         return (mMLWrapper->retrieveItemDimension(itemIndex));
   303         return (mMLWrapper->retrieveItemDimension(itemIndex));
   319     }
   304     }
   320     
   305     
   321     if(role == GlxDateRole ) {
   306     if(role == GlxDateRole ) {
   322     	qDebug("GlxMediaModel::data GlxDateRole ");
       
   323     	return (mMLWrapper->retrieveItemDate(itemIndex));
   307     	return (mMLWrapper->retrieveItemDate(itemIndex));
   324     }
   308     }
   325     
   309     
   326     if (role == GlxFrameCount) {
   310     if (role == GlxFrameCount) {
   327     qDebug("GlxMediaModel:: GlxFrameCount ");
   311         return (mMLWrapper->retrieveItemFrameCount(itemIndex));
   328     return (mMLWrapper->retrieveItemFrameCount(itemIndex));
       
   329     }
   312     }
   330     
   313     
   331     if (role == GlxHdmiBitmap) {
   314     if (role == GlxHdmiBitmap) {
   332         return mMLWrapper->RetrieveBitmap(itemIndex);
   315         return mMLWrapper->RetrieveBitmap(itemIndex);
   333     }
   316     }
       
   317 
       
   318     if ( role == GlxImageCorruptRole ) {
       
   319         return mMLWrapper->isCorruptedImage( itemIndex );
       
   320     }
   334     
   321     
   335     if (role == GlxTimeRole) {
   322     if (role == GlxTimeRole) {
   336         return mMLWrapper->retrieveItemTime(itemIndex);
   323         return mMLWrapper->retrieveItemTime(itemIndex);
   337     }
   324     }
   338 	
   325 	
   339     if (role == GlxSizeRole) {
   326     if (role == GlxSizeRole) {
   340             return mMLWrapper->retrieveItemSize(itemIndex);
   327         return mMLWrapper->retrieveItemSize(itemIndex);
   341         }
   328      }
   342     
   329     
   343     if (role == GlxDescRole) {
   330      if (role == GlxDescRole) {
   344               return mMLWrapper->retrieveListDesc(itemIndex);
   331         return mMLWrapper->retrieveListDesc(itemIndex);
   345           }
   332      }
   346     return QVariant();
   333     return QVariant();
   347 }
   334 }
   348 
   335 
   349 //GetGridIconItem
   336 //GetGridIconItem
   350 HbIcon* GlxMediaModel::GetGridIconItem(int itemIndex, GlxTBContextType tbContextType) const
   337 HbIcon* GlxMediaModel::GetGridIconItem(int itemIndex, GlxTBContextType tbContextType) const
   432 }
   419 }
   433 
   420 
   434 void GlxMediaModel::modelpopulated()
   421 void GlxMediaModel::modelpopulated()
   435 {
   422 {
   436     if ( mTempVisibleWindowIndex!=-1) {
   423     if ( mTempVisibleWindowIndex!=-1) {
   437         mMLWrapper->setVisibleWindowIndex(mTempVisibleWindowIndex);
   424         //Set the visible Window index only ff the index stored in the activity manager is not out of range
       
   425         if( rowCount() > mTempVisibleWindowIndex && mTempVisibleWindowIndex > 0 ) {
       
   426             mMLWrapper->setVisibleWindowIndex(mTempVisibleWindowIndex);
       
   427         }
       
   428         else {
       
   429             mMLWrapper->setVisibleWindowIndex(0);
       
   430         }
   438         mTempVisibleWindowIndex = -1;
   431         mTempVisibleWindowIndex = -1;
   439 	}
   432     }
   440     emit populated();
   433     emit populated();
   441 }
   434 }
   442 
   435 
   443 //------------------------------------------------------------------------------------------------------------
   436 //------------------------------------------------------------------------------------------------------------
   444 //updateDetailItems
   437 //updateDetailItems
   548     int itemIndex = index.row();
   541     int itemIndex = index.row();
   549     qDebug("GlxMediaModel::setSelectedIndex()%d", itemIndex);    
   542     qDebug("GlxMediaModel::setSelectedIndex()%d", itemIndex);    
   550     mMLWrapper->setSelectedIndex(itemIndex);
   543     mMLWrapper->setSelectedIndex(itemIndex);
   551 }
   544 }
   552 
   545 
       
   546 HbIcon * GlxMediaModel::getCorruptDefaultIcon( const QModelIndex &index ) const
       
   547 {
       
   548     if ( mMLWrapper->isCorruptedImage( index.row() ) ) {
       
   549         return m_CorruptIcon ;
       
   550     }
       
   551     return m_DefaultIcon ;
       
   552 }
       
   553 
   553 bool GlxMediaModel::setData ( const QModelIndex & idx, const QVariant & value, int role )
   554 bool GlxMediaModel::setData ( const QModelIndex & idx, const QVariant & value, int role )
   554 {
   555 {
   555     Q_UNUSED( idx )
   556     Q_UNUSED( idx )
   556     
   557     
   557     if ( GlxContextRole == role ) {
   558     if ( GlxContextRole == role ) {