locationpickerservice/src/locationpickerdatamanager_p.cpp
changeset 31 8db05346071b
parent 30 96df3ab41000
child 35 59575560d1e6
equal deleted inserted replaced
30:96df3ab41000 31:8db05346071b
    14 * Description: LocationPickerDataManager private implementation
    14 * Description: LocationPickerDataManager private implementation
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <HbIcon>
    18 #include <HbIcon>
    19 #include <QPixmap>  
       
    20 #include <QPainter>
       
    21 #include <QIcon>
       
    22 #include <locationdatalookupdb.h>
    19 #include <locationdatalookupdb.h>
    23 #include <QFile>
    20 #include <QFile>
    24 #include "locationpickerdatamanager_p.h"
    21 #include "locationpickerdatamanager_p.h"
    25 
    22 
    26 
    23 
    54 
    51 
    55 // ----------------------------------------------------------------------------
    52 // ----------------------------------------------------------------------------
    56 // LocationPickerDataManagerPrivate::populateModel()
    53 // LocationPickerDataManagerPrivate::populateModel()
    57 // ----------------------------------------------------------------------------
    54 // ----------------------------------------------------------------------------
    58 bool LocationPickerDataManagerPrivate::populateModel(  QStandardItemModel &aModel, 
    55 bool LocationPickerDataManagerPrivate::populateModel(  QStandardItemModel &aModel, 
    59         TViewType aViewType, const Qt::Orientations aOrientation, quint32 aCollectionId )
    56         TViewType aViewType, quint32 aCollectionId )
    60 {
    57 {
    61     mModel = &aModel;
    58     mModel = &aModel;
    62     mViewType = aViewType;
    59     mViewType = aViewType;
    63     mOrientation = aOrientation;
       
    64 
    60 
    65     if( !mDb )
    61     if( !mDb )
    66     {
    62     {
    67         // no items in the landmark database, so return false.
    63         // no items in the landmark database, so return false.
    68         return false;
    64         return false;
   110     {
   106     {
   111         return false;
   107         return false;
   112     }
   108     }
   113     QString lmAddressLine1;
   109     QString lmAddressLine1;
   114     QString lmAddressLine2;
   110     QString lmAddressLine2;
       
   111     QString contextAddress;
       
   112     QString contextAddressCountry;
   115     
   113     
   116     for( int i = 0; i < aItemArray.count(); i++ )
   114     for( int i = 0; i < aItemArray.count(); i++ )
   117     {
   115     {
       
   116         contextAddress.clear();
       
   117         contextAddressCountry.clear();
       
   118         lmAddressLine1.clear();
       
   119         lmAddressLine2.clear();
   118     
   120     
   119         if( !aItemArray[i].mIsDuplicate )
   121         if( !aItemArray[i].mIsDuplicate )
   120         {
   122         {
   121             lmAddressLine1 = aItemArray[i].mName;
   123             lmAddressLine1 = aItemArray[i].mName;
   122             
   124             
   173                         lmAddressLine2 = aItemArray[i].mState;
   175                         lmAddressLine2 = aItemArray[i].mState;
   174                         addressEmtpy = EFalse;
   176                         addressEmtpy = EFalse;
   175                     }
   177                     }
   176                 }
   178                 }
   177             }
   179             }
       
   180             contextAddress = lmAddressLine2;
   178             if( !aItemArray[i].mCountry.isEmpty() )
   181             if( !aItemArray[i].mCountry.isEmpty() )
   179             {
   182             {
   180                 if( !addressEmtpy )
   183                 if( !addressEmtpy )
   181                 {
   184                 {
   182                     lmAddressLine2 = lmAddressLine2 + KSeparator;
   185                     lmAddressLine2 = lmAddressLine2 + KSeparator;
   186                 else
   189                 else
   187                 {
   190                 {
   188                     lmAddressLine2 = aItemArray[i].mCountry;
   191                     lmAddressLine2 = aItemArray[i].mCountry;
   189                     addressEmtpy = EFalse;
   192                     addressEmtpy = EFalse;
   190                 }
   193                 }
       
   194                 contextAddressCountry = aItemArray[i].mCountry;
   191             }
   195             }
   192             // set icons based on contact address type
   196             // set icons based on contact address type
   193             QVariantList icons;
   197             QVariantList icons;
   194             
   198             HbIcon adressTypeIcon;
   195             QString adressType;
   199             QString adressType;
   196             bool adressIconPresent = false;
   200             bool adressIconPresent = false;
   197             if( aItemArray[i].mSourceType == ESourceContactsHome )
   201             if( aItemArray[i].mSourceType == ESourceContactsHome )
   198             {
   202             {
       
   203                 adressTypeIcon = HbIcon(KContactHomeIcon);
   199                 adressType = KContactHomeIcon;
   204                 adressType = KContactHomeIcon;
   200                 adressIconPresent = true;
   205                 adressIconPresent = true;
   201             }
   206             }
   202             else if( aItemArray[i].mSourceType == ESourceContactsWork )
   207             else if( aItemArray[i].mSourceType == ESourceContactsWork )
   203             {
   208             {
       
   209                 adressTypeIcon = HbIcon(KContactWorkIcon);
   204                 adressType = KContactWorkIcon;
   210                 adressType = KContactWorkIcon;
   205                 adressIconPresent = true;
       
   206             }
       
   207             else if( aItemArray[i].mSourceType == ESourceContactsPref )
       
   208             {
       
   209                 adressType = KContactPrefIcon;
       
   210                 adressIconPresent = true;
   211                 adressIconPresent = true;
   211             }
   212             }
   212         
   213         
   213             // create a list item and set to model
   214             // create a list item and set to model
   214             QStringList addressData;
   215             QStringList addressData;
   215             //create model for grid view in landscape mode
   216             QString landscapeIconPath;
   216             if( mOrientation == Qt::Horizontal && ( mViewType == ELocationPickerCollectionContent || 
   217 
   217                 mViewType == ELocationPickerContent ) )
   218             if( QFile::exists( aItemArray[i].mMapTilePath ) )
   218             {   
   219             { 
   219                 addressData.clear();
   220                 //draw maptile Icon            
       
   221                 landscapeIconPath = QString( aItemArray[i].mMapTilePath );
       
   222             }
       
   223             else
       
   224             {
       
   225                 //draw dummy icon
       
   226                 landscapeIconPath = QString("");
       
   227             }
       
   228             addressData.clear();
       
   229             HbIcon potraitIcon( KDummyImage );
       
   230             icons<<potraitIcon;
       
   231             if(adressIconPresent)
       
   232             {
       
   233                 icons<<adressTypeIcon;
       
   234             }
       
   235             QStringList contextList;
       
   236             contextList<<lmAddressLine1<<contextAddress<<contextAddressCountry;
       
   237             QStandardItem *modelItem = new QStandardItem();
       
   238             addressData << lmAddressLine1 << lmAddressLine2;
       
   239             modelItem->setData(QVariant(addressData), Qt::DisplayRole);
       
   240             modelItem->setData( icons, Qt::DecorationRole );
       
   241             modelItem->setData( aItemArray[i].mId, Qt::UserRole );
       
   242             modelItem->setData(landscapeIconPath,Qt::UserRole+1);
       
   243             modelItem->setData(adressType,Qt::UserRole+2);
       
   244             modelItem->setData(QVariant(contextList), Qt::UserRole+3);
   220             
   245             
   221                 QString landscapeIconPath;
   246             mModel->appendRow( modelItem );
   222             
       
   223                 if( QFile::exists( aItemArray[i].mMapTilePath ) )
       
   224                 { 
       
   225                     //draw maptile Icon            
       
   226            
       
   227                     landscapeIconPath = QString( QString( aItemArray[i].mMapTilePath ) );
       
   228                 }
       
   229                 else
       
   230                 {
       
   231                     //draw dummy icon
       
   232                     landscapeIconPath = QString("");
       
   233                 }
       
   234 
       
   235                 icons<<landscapeIconPath;
       
   236                 QStandardItem *modelItem = new QStandardItem();
       
   237                 lmAddressLine1 = lmAddressLine1.append(KSeparator);
       
   238                 lmAddressLine1 = lmAddressLine1.append(KSpace);
       
   239                 QString landMark = lmAddressLine1.append(lmAddressLine2);
       
   240                 addressData <<landMark;
       
   241                 modelItem->setData(QVariant(addressData), Qt::DisplayRole);
       
   242                 modelItem->setData( icons[0], Qt::DecorationRole );
       
   243                 modelItem->setData( aItemArray[i].mId, Qt::UserRole );
       
   244                 modelItem->setData(adressType,Qt::UserRole+1);
       
   245                 mModel->appendRow( modelItem );
       
   246             }
       
   247             else
       
   248             {   
       
   249                 //create model for list view in potrait mode
       
   250                 addressData.clear();
       
   251                 HbIcon potraitIcon( KDummyImage );
       
   252                 icons<<potraitIcon;
       
   253                 if(adressIconPresent)
       
   254                 {
       
   255                     icons<<adressType;
       
   256                 }
       
   257                 QStandardItem *modelItem = new QStandardItem();
       
   258                 addressData << lmAddressLine1 << lmAddressLine2;
       
   259                 modelItem->setData(QVariant(addressData), Qt::DisplayRole);
       
   260                 modelItem->setData( icons, Qt::DecorationRole );
       
   261                 modelItem->setData( aItemArray[i].mId, Qt::UserRole );
       
   262                 mModel->appendRow( modelItem );
       
   263             }
       
   264          }
   247          }
   265    }
   248    }
   266     
   249     
   267     return true;
   250     return true;
   268 }
   251 }
   279     QString contactCollectionNum;
   262     QString contactCollectionNum;
   280     contactCollectionNum.setNum(conNum);
   263     contactCollectionNum.setNum(conNum);
   281     contactCollectionNum.append(" items");
   264     contactCollectionNum.append(" items");
   282     QString contactCollectionName( hbTrId("txt_lint_list_contact_addresses") );
   265     QString contactCollectionName( hbTrId("txt_lint_list_contact_addresses") );
   283  
   266  
   284     if( mOrientation  == Qt::Vertical)
   267 
   285     {
   268     QStringList contact = (QStringList()<<contactCollectionName<<contactCollectionNum);
   286         QStringList contact = (QStringList()<<contactCollectionName<<contactCollectionNum);
   269     modelItemContact->setData( QVariant( contact ), Qt::DisplayRole );
   287         modelItemContact->setData( QVariant( contact ), Qt::DisplayRole );
       
   288     }
       
   289     else
       
   290     {
       
   291         QString contact =  contactCollectionName.append(contactCollectionNum);
       
   292         modelItemContact->setData( QVariant( contact ), Qt::DisplayRole );
       
   293     }
       
   294       
   270       
   295     modelItemContact->setData( HbIcon ( KCollectionsContacts ), Qt::DecorationRole );
   271     modelItemContact->setData( HbIcon ( KCollectionsContacts ), Qt::DecorationRole );
   296     modelItemContact->setData( ESourceLandmarksContactsCat, Qt::UserRole );
   272     modelItemContact->setData( ESourceLandmarksContactsCat, Qt::UserRole );
   297     mModel->appendRow( modelItemContact );
   273     mModel->appendRow( modelItemContact );
   298    
   274