ui/uiengine/model/mediamodel/src/glxmediamodel.cpp
changeset 54 0f0f3f26f787
parent 50 a0f57508af73
child 58 383b67fbdb11
equal deleted inserted replaced
52:a3a4c0de738e 54:0f0f3f26f787
    31 #include <glximageviewermanager.h>
    31 #include <glximageviewermanager.h>
    32 //#define GLXPERFORMANCE_LOG  
    32 //#define GLXPERFORMANCE_LOG  
    33 #include <glxperformancemacro.h>
    33 #include <glxperformancemacro.h>
    34 
    34 
    35 #include "glxicondefs.h" //Contains the icon names/Ids
    35 #include "glxicondefs.h" //Contains the icon names/Ids
    36 #include<glxviewids.h>
    36 #include "glxcollectionpluginall.hrh"
       
    37 #include "glxviewids.h"
       
    38 
       
    39 #define DELTA_IMAGE 5
       
    40 #define INITIAL_POPULATE_IMAGE_COUNT 30
    37 
    41 
    38 GlxMediaModel::GlxMediaModel(GlxModelParm & modelParm)
    42 GlxMediaModel::GlxMediaModel(GlxModelParm & modelParm)
    39 {
    43 {
    40 	qDebug("GlxMediaModel::GlxMediaModel");
    44 	qDebug("GlxMediaModel::GlxMediaModel");
    41 	
    45 	
       
    46 	thumbnailPopulatedFlag = modelParm.collection() == KGlxCollectionPluginAllImplementationUid ? false : true;
    42 	mMLWrapper = new GlxMLWrapper(modelParm.collection(),0,EGlxFilterImage);
    47 	mMLWrapper = new GlxMLWrapper(modelParm.collection(),0,EGlxFilterImage);
    43 	mMLWrapper->setContextMode( modelParm.contextMode() );
    48 	mMLWrapper->setContextMode( modelParm.contextMode() );
    44 	mContextMode = modelParm.contextMode( ) ; 
    49 	mContextMode = modelParm.contextMode( ) ; 
    45 	mDRMUtilityWrapper = new GlxDRMUtilityWrapper();
    50 	mDRMUtilityWrapper = new GlxDRMUtilityWrapper();
    46 	int err = connect(mMLWrapper, SIGNAL(updateItem(int, GlxTBContextType)), this, SLOT(itemUpdated1(int, GlxTBContextType)));
    51 	
       
    52 	int err = connect(mMLWrapper, SIGNAL(updateItem(int, GlxTBContextType)), this, SLOT(itemUpdated(int, GlxTBContextType)));
    47 	qDebug("updateItem() connection status %d", err);
    53 	qDebug("updateItem() connection status %d", err);
    48 	err = connect(mMLWrapper, SIGNAL(itemCorrupted(int)), this, SLOT(itemCorrupted(int)));
    54 	err = connect(mMLWrapper, SIGNAL(itemCorrupted(int)), this, SLOT(itemCorrupted(int)));
    49 	qDebug("itemCorrupted() connection status %d", err);
    55 	qDebug("itemCorrupted() connection status %d", err);
    50 	err = connect(mMLWrapper, SIGNAL(insertItems(int, int)), this, SLOT(itemsAdded(int, int)));
    56 	err = connect(mMLWrapper, SIGNAL(insertItems(int, int)), this, SLOT(itemsAdded(int, int)));
    51 	qDebug("updateItem() connection status %d", err);
    57 	qDebug("updateItem() connection status %d", err);
    60 	
    66 	
    61 	itemIconCache.setMaxCost(20);  //Changed While Doing Media Wall
    67 	itemIconCache.setMaxCost(20);  //Changed While Doing Media Wall
    62 	itemFsIconCache.setMaxCost(5);
    68 	itemFsIconCache.setMaxCost(5);
    63 	itemExternalIconCache.setMaxCost(0);
    69 	itemExternalIconCache.setMaxCost(0);
    64 	
    70 	
    65 	m_DefaultIcon = new HbIcon(GLXICON_DEFAULT);
    71 	m_DefaultIcon = new HbIcon( GLXICON_DEFAULT );
    66 	m_CorruptIcon = new HbIcon( GLXICON_CORRUPT );
    72 	m_CorruptIcon = new HbIcon( GLXICON_CORRUPT );
    67 	mExternalItems = NULL;
    73 	mExternalItems = NULL;
    68 	externalDataCount = 0;
    74 	externalDataCount = 0;
    69 	mFocusIndex = -1;
    75 	mFocusIndex = -1;
    70 	mSubState = -1;
    76 	mSubState = -1;
    80 	delete m_DefaultIcon;
    86 	delete m_DefaultIcon;
    81 	m_DefaultIcon = NULL;
    87 	m_DefaultIcon = NULL;
    82 	delete m_CorruptIcon;
    88 	delete m_CorruptIcon;
    83 	m_CorruptIcon = NULL;
    89 	m_CorruptIcon = NULL;
    84 	clearExternalItems();
    90 	clearExternalItems();
    85     int err = disconnect(mMLWrapper, SIGNAL(updateItem(int, GlxTBContextType)), this, SLOT(itemUpdated1(int, GlxTBContextType)));
       
    86 	err = disconnect(mMLWrapper, SIGNAL(itemCorrupted(int)), this, SLOT(itemCorrupted(int)));
       
    87 	err = disconnect(mMLWrapper, SIGNAL(insertItems(int, int)), this, SLOT(itemsAdded(int, int)));
       
    88 	err = disconnect(mMLWrapper, SIGNAL(removeItems(int, int)), this, SLOT(itemsRemoved(int, int)));
       
    89 	err = disconnect(this, SIGNAL(iconAvailable(int, HbIcon*, GlxTBContextType)), this, SLOT(updateItemIcon(int, HbIcon*, GlxTBContextType)));
       
    90 	err = disconnect(mMLWrapper, SIGNAL(updateAlbumTitle(QString)), this, SLOT(albumTitleUpdated(QString)));	    
       
    91 	err = disconnect(mMLWrapper, SIGNAL(populated()), this, SLOT(modelpopulated()));
       
    92 	err = disconnect(mMLWrapper, SIGNAL(updateDetails()), this, SLOT(updateDetailItems()));
       
    93     delete mMLWrapper;
    91     delete mMLWrapper;
    94 	delete mDRMUtilityWrapper;
    92 	delete mDRMUtilityWrapper;
    95 }
    93 }
    96 
    94 
    97 //------------------------------------------------------------------------------------------------------------
    95 //------------------------------------------------------------------------------------------------------------
   246             if (tempIcon && !tempIcon->isNull()) {
   244             if (tempIcon && !tempIcon->isNull()) {
   247                 qDebug("GlxMediaModel::scaling thumbnail");
   245                 qDebug("GlxMediaModel::scaling thumbnail");
   248                 QPixmap tempPixmap = tempIcon->qicon().pixmap(128, 128);
   246                 QPixmap tempPixmap = tempIcon->qicon().pixmap(128, 128);
   249                 QSize itemSize = mMLWrapper->retrieveItemDimension(itemIndex);
   247                 QSize itemSize = mMLWrapper->retrieveItemDimension(itemIndex);
   250                 QSize sz = ( mContextMode == GlxContextLsFs ) ? QSize ( 640, 360) : QSize ( 360, 640 );
   248                 QSize sz = ( mContextMode == GlxContextLsFs ) ? QSize ( 640, 360) : QSize ( 360, 640 );
   251                 if(!((itemSize.width() < sz.width()) && (itemSize.height() < sz.height()))); {
   249                 if( !( ( itemSize.width() < sz.width() ) && ( itemSize.height() < sz.height() ) ) ) {
   252                     itemSize.scale(sz, Qt::KeepAspectRatio);
   250                     itemSize.scale(sz, Qt::KeepAspectRatio);
   253                 }
   251                 }
   254                 tempPixmap = tempPixmap.scaled(itemSize, Qt::IgnoreAspectRatio );
   252                 tempPixmap = tempPixmap.scaled(itemSize, Qt::IgnoreAspectRatio );
   255                 HbIcon tmp = HbIcon( QIcon(tempPixmap)) ;
   253                 HbIcon tmp = HbIcon( QIcon(tempPixmap)) ;
   256 				if(!tmp.isNull()){
   254 				if(!tmp.isNull()){
   396 	}
   394 	}
   397 	return itemIcon;
   395 	return itemIcon;
   398 }
   396 }
   399 
   397 
   400 
   398 
   401 void GlxMediaModel::itemUpdated1(int mlIndex,GlxTBContextType tbContextType  )
   399 void GlxMediaModel::itemUpdated(int mlIndex,GlxTBContextType tbContextType  )
   402 {
   400 {
   403 	qDebug("GlxMediaModel::itemUpdated %d", mlIndex);
   401 	qDebug("GlxMediaModel::itemUpdated %d", mlIndex);
   404 	//clear the grid and FS cache if they have any icons with them for that index
   402 	//clear the grid and FS cache if they have any icons with them for that index
   405 	if(tbContextType == GlxTBContextGrid) {
   403 	if( tbContextType == GlxTBContextGrid ) {
   406 		itemIconCache.remove(mlIndex);
   404 	    if ( !thumbnailPopulatedFlag ) {
       
   405 	        thumbnailPopulatedCheck( mlIndex ); 
       
   406 	    }		
       
   407 	    itemIconCache.remove(mlIndex);
   407 	}
   408 	}
   408 	if(tbContextType == GlxTBContextLsFs || tbContextType == GlxTBContextPtFs) {
   409 	if(tbContextType == GlxTBContextLsFs || tbContextType == GlxTBContextPtFs) {
   409 		itemFsIconCache.remove(mlIndex);
   410 		itemFsIconCache.remove(mlIndex);
   410 	}
   411 	}
   411 	emit dataChanged(index(mlIndex+externalDataCount,0),index(mlIndex+externalDataCount,0));
   412 	emit dataChanged( index( mlIndex , 0 ), index( mlIndex, 0 ) );	
   412 	
       
   413 }
   413 }
   414 
   414 
   415 void GlxMediaModel::itemCorrupted(int itemIndex)
   415 void GlxMediaModel::itemCorrupted(int itemIndex)
   416 {
   416 {
   417 	qDebug("GlxMediaModel::itemCorrupted %d", itemIndex);
   417 	qDebug("GlxMediaModel::itemCorrupted %d", itemIndex);
   418 	emit dataChanged(index(itemIndex+externalDataCount,0),index(itemIndex+externalDataCount,0));	
   418     if ( !thumbnailPopulatedFlag ) {
       
   419         thumbnailPopulatedCheck( itemIndex ); 
       
   420     }
       
   421 	emit dataChanged( index( itemIndex , 0 ), index( itemIndex, 0 ) );	
   419 }
   422 }
   420 
   423 
   421 void GlxMediaModel::modelpopulated()
   424 void GlxMediaModel::modelpopulated()
   422 {
   425 {
   423     if ( mTempVisibleWindowIndex!=-1) {
   426     if ( mTempVisibleWindowIndex!=-1) {
   549         return m_CorruptIcon ;
   552         return m_CorruptIcon ;
   550     }
   553     }
   551     return m_DefaultIcon ;
   554     return m_DefaultIcon ;
   552 }
   555 }
   553 
   556 
       
   557 void GlxMediaModel::thumbnailPopulatedCheck( int index )
       
   558 {
       
   559     int count = rowCount() - DELTA_IMAGE ;
       
   560     int maxRange = INITIAL_POPULATE_IMAGE_COUNT + DELTA_IMAGE ;
       
   561     if ( index >= count ||  ( index >= INITIAL_POPULATE_IMAGE_COUNT && index < maxRange ) ) {
       
   562         thumbnailPopulatedFlag = TRUE;
       
   563         emit thumbnailPopulated();
       
   564     }
       
   565 }
       
   566 
   554 bool GlxMediaModel::setData ( const QModelIndex & idx, const QVariant & value, int role )
   567 bool GlxMediaModel::setData ( const QModelIndex & idx, const QVariant & value, int role )
   555 {
   568 {
   556     Q_UNUSED( idx )
   569     Q_UNUSED( idx )
   557     
   570     
   558     if ( GlxContextRole == role ) {
   571     if ( GlxContextRole == role ) {