locationpickerservice/src/locationpickerdatamanager_p.cpp
changeset 17 0f22fb80ebba
parent 15 13ae750350c9
child 20 cd10d5b85554
equal deleted inserted replaced
15:13ae750350c9 17:0f22fb80ebba
    33 // LocationPickerDataManagerPrivate::LocationPickerDataManagerPrivate()
    33 // LocationPickerDataManagerPrivate::LocationPickerDataManagerPrivate()
    34 // ----------------------------------------------------------------------------
    34 // ----------------------------------------------------------------------------
    35 
    35 
    36 LocationPickerDataManagerPrivate::LocationPickerDataManagerPrivate() :
    36 LocationPickerDataManagerPrivate::LocationPickerDataManagerPrivate() :
    37         mModel( NULL ),
    37         mModel( NULL ),
    38         mViewType( ELocationPickerAllView ),
    38         mViewType( ELocationPickerContent ),
    39         mIterator(NULL),
    39         mIterator(NULL),
    40         mLandmarkDb(NULL),
    40         mLandmarkDb(NULL),
    41         mLmCategoryManager(NULL),
    41         mLmCategoryManager(NULL),
    42         mLandmarkSearch(NULL)
    42         mLandmarkSearch(NULL)
    43 {
    43 {
    76 }
    76 }
    77 
    77 
    78 // ----------------------------------------------------------------------------
    78 // ----------------------------------------------------------------------------
    79 // LocationPickerDataManagerPrivate::populateModel()
    79 // LocationPickerDataManagerPrivate::populateModel()
    80 // ----------------------------------------------------------------------------
    80 // ----------------------------------------------------------------------------
    81 bool LocationPickerDataManagerPrivate::populateModel( quint32 aCollectionId )
    81 bool LocationPickerDataManagerPrivate::populateModel( const Qt::Orientations aOrientation, quint32 aCollectionId )
    82 {
    82 {
    83     bool retValue = false;
    83     bool retValue = false;
       
    84     mOrientation = aOrientation;
    84     TRAP_IGNORE( retValue = populateModelL( aCollectionId ) );
    85     TRAP_IGNORE( retValue = populateModelL( aCollectionId ) );
    85     return retValue;
    86     return retValue;
    86 }
    87 }
    87 
    88 
    88 // ----------------------------------------------------------------------------
    89 // ----------------------------------------------------------------------------
    90 // ----------------------------------------------------------------------------
    91 // ----------------------------------------------------------------------------
    91 bool LocationPickerDataManagerPrivate::populateModelL( quint32 aCollectionId )
    92 bool LocationPickerDataManagerPrivate::populateModelL( quint32 aCollectionId )
    92 {
    93 {
    93     // Handle to the landmark database
    94     // Handle to the landmark database
    94     mLandmarkDb = NULL;
    95     mLandmarkDb = NULL;
    95 
    96     
    96     //Open and intialize Landmark DB
    97     //Open and intialize Landmark DB
    97     mLandmarkDb = CPosLandmarkDatabase::OpenL();
    98     mLandmarkDb = CPosLandmarkDatabase::OpenL();
    98     ExecuteAndDeleteLD( mLandmarkDb->InitializeL() );
    99     ExecuteAndDeleteLD( mLandmarkDb->InitializeL() );
    99 
   100 
   100     switch( mViewType )
   101     switch( mViewType )
   101     {
   102     {
   102         case ELocationPickerAllView:
   103         case ELocationPickerContent:
   103         case ELocationPickerSearchView:
   104         case ELocationPickerSearchView:
   104              {
   105              {
   105                  // Create an iterator for iterating the landmarks in the database
   106                  // Create an iterator for iterating the landmarks in the database
   106                  mIterator = mLandmarkDb->LandmarkIteratorL();
   107                  mIterator = mLandmarkDb->LandmarkIteratorL();
   107 
   108 
   108                  if( ( mIterator == NULL ) || (mIterator->NumOfItemsL() == 0) )
   109                  if( ( !mIterator ) || (mIterator->NumOfItemsL() == 0) )
   109                  {
   110                  {
   110                      // no items in the landmark database, so return false.
   111                      // no items in the landmark database, so return false.
   111                      return false;
   112                      return false;
   112                  }
   113                  }
   113                  CleanupStack::PushL(mIterator);
   114                  CleanupStack::PushL(mIterator);
   114                  populateLandmarksL();
   115                  populateLandmarksL();
   115                  CleanupStack::Pop( mIterator );
   116                  CleanupStack::Pop( mIterator );
   116              }
   117              }
   117              break;
   118              break;
   118         case ELocationPickerCollectionListView:
   119         case ELocationPickerCollectionListContent:
   119              {
   120              {
   120 
   121 
   121                  // Create category manager for landmarks
   122                  // Create category manager for landmarks
   122                  mLmCategoryManager = CPosLmCategoryManager::NewL( *mLandmarkDb );
   123                  mLmCategoryManager = CPosLmCategoryManager::NewL( *mLandmarkDb );
   123 
   124 
   126                      return false;
   127                      return false;
   127                  }
   128                  }
   128                  // Create an iterator for iterating the referenced categories in the database
   129                  // Create an iterator for iterating the referenced categories in the database
   129                  mIterator = mLmCategoryManager->ReferencedCategoryIteratorL();
   130                  mIterator = mLmCategoryManager->ReferencedCategoryIteratorL();
   130 
   131 
   131                  if( ( mIterator == NULL ) || (mIterator->NumOfItemsL() == 0) )
   132                  if( ( !mIterator ) || (mIterator->NumOfItemsL() == 0) )
   132                  {
   133                  {
   133                      // no items in the landmark database, so return false.
   134                      // no items in the landmark database, so return false.
   134                      return false;
   135                      return false;
   135                  }
   136                  }
   136                  CleanupStack::PushL(mIterator);
   137                  CleanupStack::PushL(mIterator);
   138                  CleanupStack::Pop( mIterator );
   139                  CleanupStack::Pop( mIterator );
   139 
   140 
   140              }
   141              }
   141              break;
   142              break;
   142 
   143 
   143         case ELocationPickerCollectionContentView:
   144         case ELocationPickerCollectionContent:
   144              {
   145              {
   145 
   146 
   146                  // create a search object.
   147                  // create a search object.
   147                  mLandmarkSearch = CPosLandmarkSearch::NewL( *mLandmarkDb );
   148                  mLandmarkSearch = CPosLandmarkSearch::NewL( *mLandmarkDb );
   148                  CleanupStack::PushL( mLandmarkSearch );
   149                  CleanupStack::PushL( mLandmarkSearch );
   155                  ExecuteAndDeleteLD( mLandmarkSearch->StartLandmarkSearchL( *criteria ) );
   156                  ExecuteAndDeleteLD( mLandmarkSearch->StartLandmarkSearchL( *criteria ) );
   156                  CleanupStack::PopAndDestroy( criteria );
   157                  CleanupStack::PopAndDestroy( criteria );
   157 
   158 
   158                  // Retrieve an iterator to access the matching landmarks.
   159                  // Retrieve an iterator to access the matching landmarks.
   159                  mIterator = mLandmarkSearch->MatchIteratorL();
   160                  mIterator = mLandmarkSearch->MatchIteratorL();
   160                  if( ( mIterator == NULL ) || (mIterator->NumOfItemsL() == 0) )
   161                  if( ( !mIterator ) || (mIterator->NumOfItemsL() == 0) )
   161                  {
   162                  {
   162                      // no landmarks in this collection
   163                      // no landmarks in this collection
   163                      CleanupStack::Pop(mLandmarkSearch);
   164                      CleanupStack::Pop(mLandmarkSearch);
   164                      return false;
   165                      return false;
   165                  }
   166                  }
   179 
   180 
   180 void LocationPickerDataManagerPrivate::populateLandmarksL()
   181 void LocationPickerDataManagerPrivate::populateLandmarksL()
   181 {
   182 {
   182     // Read each landmark in the database and copy to the model.
   183     // Read each landmark in the database and copy to the model.
   183     TPosLmItemId lmId;
   184     TPosLmItemId lmId;
   184     while ((lmId = mIterator->NextL()) != KPosLmNullItemId )
   185     mModel->clear();
       
   186     while ( ( lmId = mIterator->NextL() ) != KPosLmNullItemId )
   185     {
   187     {
   186         CPosLandmark* readLandmark = mLandmarkDb->ReadLandmarkLC(lmId );
   188         CPosLandmark* readLandmark = mLandmarkDb->ReadLandmarkLC(lmId );
   187 
   189         
   188         if( readLandmark )
   190         if( readLandmark )
   189         {
   191         {
   190             QString lmAddressLine1(" ");
   192             QString lmAddressLine1(" ");
   191             QString lmAddressLine2("");
   193             QString lmAddressLine2("");
   192 
   194 
   268             {
   270             {
   269                 contactAddressType = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
   271                 contactAddressType = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
   270             }
   272             }
   271 
   273 
   272             // set icons based on contact address type
   274             // set icons based on contact address type
   273             QVariantList icons;;
   275             QVariantList icons;
   274             if( contactAddressType == KContactHome )
   276             if( contactAddressType == KContactHome )
   275             {
   277             {
   276                 icons << HbIcon(KDummyImage) << HbIcon(KContactHomeIcon);
   278                 icons << HbIcon(KDummyImage) << HbIcon(KContactHomeIcon);
   277             }
   279             }
   278             else if( contactAddressType == KContactWork )
   280             else if( contactAddressType == KContactWork )
   281             }
   283             }
   282             else
   284             else
   283             {
   285             {
   284                 icons << HbIcon(KDummyImage) << HbIcon(KContactPrefIcon);
   286                 icons << HbIcon(KDummyImage) << HbIcon(KContactPrefIcon);
   285             }
   287             }
   286 
   288             
   287 
       
   288             // create a list item and set to model
   289             // create a list item and set to model
   289             QStringList addressData;
   290             QStringList addressData;
   290             addressData << lmAddressLine1 << lmAddressLine2;
   291             //create model for grid view in landscape mode
   291             QStandardItem *modelItem = new QStandardItem();
   292             if(mOrientation == Qt::Horizontal && ( mViewType == ELocationPickerCollectionContent || mViewType == ELocationPickerContent) )
   292             modelItem->setData(QVariant(addressData), Qt::DisplayRole);
   293             {   
   293             modelItem->setData( icons, Qt::DecorationRole );
   294                 addressData.clear();
   294             mModel->appendRow( modelItem );
   295                 QStandardItem *modelItem = new QStandardItem();
       
   296                 addressData << lmAddressLine1;
       
   297                 modelItem->setData(QVariant(addressData), Qt::DisplayRole);
       
   298                 modelItem->setData( icons[0], Qt::DecorationRole );
       
   299                 modelItem->setData(QString("contact"),Qt::UserRole);
       
   300                 mModel->appendRow( modelItem );
       
   301             }
       
   302             else
       
   303             {   
       
   304                 //create model for list view in potrai mode
       
   305                 addressData.clear();
       
   306                 QStandardItem *modelItem = new QStandardItem();
       
   307                 addressData << lmAddressLine1 << lmAddressLine2;
       
   308                 modelItem->setData(QVariant(addressData), Qt::DisplayRole);
       
   309                 modelItem->setData( icons, Qt::DecorationRole );
       
   310                 mModel->appendRow( modelItem );
       
   311             }
   295 
   312 
   296             CleanupStack::PopAndDestroy( readLandmark );
   313             CleanupStack::PopAndDestroy( readLandmark );
   297         }
   314         }
   298    }
   315    }
   299 }
   316 }
   321             if( retStatus == KErrNone && tempStr.Length() > 0)
   338             if( retStatus == KErrNone && tempStr.Length() > 0)
   322             {
   339             {
   323                 categoryName = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
   340                 categoryName = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
   324                 if(categoryName == KContactsString)
   341                 if(categoryName == KContactsString)
   325                 {
   342                 {
   326                     categoryName = KContactsCollection;
   343                     categoryName = hbTrId("txt_lint_list_contact_addresses");
   327                 }
   344                 }
   328             }
   345             }
   329 
   346 
   330             // create a list item and copy to model
   347             // create a list item and copy to model
   331 
   348 
   332             QString iconPath;
   349             QString iconPath;
   333             QStandardItem *modelItem = new QStandardItem();
   350             QStandardItem *modelItem = new QStandardItem();
   334             modelItem->setData(QVariant(categoryName), Qt::DisplayRole);
   351             modelItem->setData(QVariant(categoryName), Qt::DisplayRole);
   335             modelItem->setData( QIcon (KCollectionsContacts), Qt::DecorationRole );
   352             modelItem->setData( HbIcon (KCollectionsContacts), Qt::DecorationRole );
   336             mModel->appendRow( modelItem );
   353             mModel->appendRow( modelItem );
   337 
   354 
   338             CleanupStack::PopAndDestroy( readCategory );
   355             CleanupStack::PopAndDestroy( readCategory );
   339         }
   356         }
   340     }
   357     }