ui/uiengine/model/mediamodel/src/glxmediamodel.cpp
changeset 40 112f0ac2d1f0
parent 26 c499df2dbb33
child 33 1ee2af37811f
equal deleted inserted replaced
26:c499df2dbb33 40:112f0ac2d1f0
    17 
    17 
    18 
    18 
    19 
    19 
    20 #include <glxmediamodel.h>
    20 #include <glxmediamodel.h>
    21 #include <hbicon.h>
    21 #include <hbicon.h>
       
    22 #include <qimage.h>
    22 #include <glxmodelparm.h>
    23 #include <glxmodelparm.h>
    23 #include <QCache>
    24 #include <QCache>
    24 #include <QDebug>
    25 #include <QDebug>
    25 #include <hal.h>
    26 #include <hal.h>
    26 #include <hal_data.h>
    27 #include <hal_data.h>
       
    28 #include <glxmlwrapper.h>
    27 
    29 
    28 #include <glxfiltergeneraldefs.h>
    30 #include <glxfiltergeneraldefs.h>
    29 
    31 
    30 //#define GLXPERFORMANCE_LOG  
    32 //#define GLXPERFORMANCE_LOG  
    31 #include <glxperformancemacro.h>
    33 #include <glxperformancemacro.h>
    50 	qDebug("updateItem() connection status %d", err);
    52 	qDebug("updateItem() connection status %d", err);
    51 	err = connect(this, SIGNAL(iconAvailable(int, HbIcon*, GlxTBContextType)), this, SLOT(updateItemIcon(int, HbIcon*, GlxTBContextType)));
    53 	err = connect(this, SIGNAL(iconAvailable(int, HbIcon*, GlxTBContextType)), this, SLOT(updateItemIcon(int, HbIcon*, GlxTBContextType)));
    52 	qDebug("iconAvailable() connection status %d", err);
    54 	qDebug("iconAvailable() connection status %d", err);
    53 	//itemadded.resize(mMLWrapper->getItemCount());
    55 	//itemadded.resize(mMLWrapper->getItemCount());
    54 	
    56 	
    55 	itemIconCache.setMaxCost(50);
    57 	itemIconCache.setMaxCost(20);  //Changed While Doing Media Wall
    56 	itemFsIconCache.setMaxCost(5);
    58 	itemFsIconCache.setMaxCost(5);
    57 	itemExternalIconCache.setMaxCost(0);
    59 	itemExternalIconCache.setMaxCost(0);
    58 	
    60 	
    59 	//todo get this Default icon from some generic path and not directly.
    61 	//todo get this Default icon from some generic path and not directly.
    60 	m_DefaultIcon = new HbIcon(GLXICON_DEFAULT);
    62 	m_DefaultIcon = new HbIcon(GLXICON_DEFAULT);
    93 		itemFsIconCache.clear();
    95 		itemFsIconCache.clear();
    94 		mMLWrapper->setContextMode(contextMode);
    96 		mMLWrapper->setContextMode(contextMode);
    95 		mContextMode = contextMode;
    97 		mContextMode = contextMode;
    96 		if ( mContextMode == GlxContextLsGrid || mContextMode == GlxContextPtGrid ) {
    98 		if ( mContextMode == GlxContextLsGrid || mContextMode == GlxContextPtGrid ) {
    97             itemIconCache.clear();
    99             itemIconCache.clear();
    98             emit dataChanged( index( 0, 0), index( rowCount() - 1, 0) );
   100             //emit dataChanged( index( 0, 0), index( rowCount() - 1, 0) );  // Not Needed for HgWidget
    99         }
   101         }
   100 	}
   102 	}
   101 }
   103 }
   102 
   104 
   103 //to add external data to the model
   105 //to add external data to the model
   115 /*
   117 /*
   116 *for removing all external image data from the model. 
   118 *for removing all external image data from the model. 
   117 */
   119 */
   118 void GlxMediaModel::clearExternalItems()
   120 void GlxMediaModel::clearExternalItems()
   119 {
   121 {
   120 	beginRemoveRows(QModelIndex(), 0, externalDataCount);
   122 	if(externalDataCount) {
   121 	if(mExternalItems) {
   123 	    beginRemoveRows(QModelIndex(), 0, externalDataCount);	
       
   124         if(mExternalItems) {
   122 		delete mExternalItems;
   125 		delete mExternalItems;
   123 		mExternalItems = NULL;
   126 		mExternalItems = NULL;
   124 		externalDataCount = 0;
   127 		externalDataCount = 0;
   125 	}
   128         }
   126 	itemExternalIconCache.clear();
   129         itemExternalIconCache.clear();
   127 	endRemoveRows();
   130         endRemoveRows();
       
   131     }
       
   132 
   128 }
   133 }
   129 
   134 
   130 int GlxMediaModel::rowCount(const QModelIndex &parent ) const
   135 int GlxMediaModel::rowCount(const QModelIndex &parent ) const
   131 {
   136 {
   132 	Q_UNUSED(parent);
   137 	Q_UNUSED(parent);
   154 {
   159 {
   155     if ( role == GlxSubStateRole ) {
   160     if ( role == GlxSubStateRole ) {
   156         return mSubState;
   161         return mSubState;
   157     }
   162     }
   158 
   163 
       
   164     if ( role == GlxHgVisibilityRole ) {
       
   165         return TRUE;
       
   166     }
       
   167     
       
   168     if ( role == Qt::DisplayRole ) {
       
   169         return QVariant();
       
   170     }
       
   171     
       
   172     if ( role == GlxDefaultImage ) {
       
   173         return m_DefaultIcon->pixmap().toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
       
   174     }
       
   175 
   159     HbIcon* itemIcon = NULL;
   176     HbIcon* itemIcon = NULL;
       
   177     QImage itemImage;
   160     int itemIndex = index.row();
   178     int itemIndex = index.row();
   161     qDebug("GlxMediaModel::data buffer concept index %d role %d", index.row(), role);
   179     qDebug("GlxMediaModel::data buffer concept index %d role %d", index.row(), role);
   162     if ((!index.isValid()) || (index.row() > rowCount()-1)) {
   180     if ((!index.isValid()) || (index.row() > rowCount()-1)) {
   163          return QVariant();
   181          return QVariant();
   164     }
   182     }
   178 //retrieve Data from Media List		
   196 //retrieve Data from Media List		
   179     if (role == Qt::DecorationRole) {
   197     if (role == Qt::DecorationRole) {
   180         itemIcon = GetGridIconItem(itemIndex,GlxTBContextGrid);
   198         itemIcon = GetGridIconItem(itemIndex,GlxTBContextGrid);
   181         if(itemIcon == NULL || itemIcon->isNull() ){
   199         if(itemIcon == NULL || itemIcon->isNull() ){
   182             itemIcon = m_DefaultIcon;
   200             itemIcon = m_DefaultIcon;
   183         // }
       
   184         }
   201         }
   185         return *itemIcon;
   202         return *itemIcon;
   186     }
   203     }
   187 		
   204 		
       
   205     if (role == GlxQImageSmall)
       
   206         {
       
   207         return mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextGrid);
       
   208         }
       
   209 
   188     if (role == GlxFsImageRole){
   210     if (role == GlxFsImageRole){
   189         if(mContextMode == GlxContextLsFs){
   211         if(mContextMode == GlxContextLsFs){
   190             itemIcon = GetFsIconItem(itemIndex,GlxTBContextLsFs);
   212             itemIcon = GetFsIconItem(itemIndex,GlxTBContextLsFs);
   191         }
   213         }
   192         else if (mContextMode == GlxContextPtFs){
   214         else if (mContextMode == GlxContextPtFs){
   212             itemIcon = m_DefaultIcon;
   234             itemIcon = m_DefaultIcon;
   213         }
   235         }
   214         return *itemIcon;
   236         return *itemIcon;
   215     }
   237     }
   216 	
   238 	
       
   239     if (role == GlxQImageLarge)
       
   240         {
       
   241         if(mContextMode == GlxContextLsFs)
       
   242             {
       
   243             itemImage = mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextLsFs);
       
   244             }
       
   245         else
       
   246             {
       
   247             itemImage = mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextPtFs);
       
   248             }
       
   249         if(!itemImage.isNull()) 
       
   250             {
       
   251             return itemImage;
       
   252             }
       
   253         else 
       
   254             {
       
   255             itemImage =  mMLWrapper->retrieveItemImage(itemIndex, GlxTBContextGrid);
       
   256             if (!itemImage.isNull()) 
       
   257                 {
       
   258                 QSize sz = ( mContextMode == GlxContextLsFs ) ? QSize ( 640, 360) : QSize ( 360, 640 );
       
   259                 itemImage = itemImage.scaled(sz,Qt::KeepAspectRatio); 
       
   260                 }
       
   261                 return itemImage;
       
   262             }
       
   263         }
       
   264     
       
   265     if (role == GlxVisualWindowIndex)
       
   266         {
       
   267         return mMLWrapper->getVisibleWindowIndex();
       
   268         }
       
   269 	
   217     QModelIndex idx;
   270     QModelIndex idx;
   218     if ( GlxFocusIndexRole == role ) {
   271     if ( GlxFocusIndexRole == role ) {
   219         idx = getFocusIndex();
   272         idx = getFocusIndex();
   220         return idx.row();
   273         return idx.row();
   221     }
   274     }
   266 		itemIcon =  mMLWrapper->retrieveItemIcon(itemIndex, tbContextType);
   319 		itemIcon =  mMLWrapper->retrieveItemIcon(itemIndex, tbContextType);
   267 		if(itemIcon){
   320 		if(itemIcon){
   268             emit iconAvailable(itemIndex,itemIcon, tbContextType);
   321             emit iconAvailable(itemIndex,itemIcon, tbContextType);
   269 		}
   322 		}
   270 		itemIcon = itemFsIconCache[itemIndex];
   323 		itemIcon = itemFsIconCache[itemIndex];
   271 		/*if(!itemIcon){
       
   272 		itemIcon = GetGridIconItem(itemIndex, GlxTBContextGrid);
       
   273 		}*/
       
   274 	}
   324 	}
   275 	return itemIcon;
   325 	return itemIcon;
   276 
   326 
   277 }
   327 }
   278 
   328