qtmobility/plugins/contacts/symbian/src/filtering/cntsymbiansorterdbms.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    72 {
    72 {
    73 }
    73 }
    74 
    74 
    75 QList<QContactLocalId> CntSymbianSorterDbms::contacts(
    75 QList<QContactLocalId> CntSymbianSorterDbms::contacts(
    76             const QList<QContactSortOrder>& sortOrders,
    76             const QList<QContactSortOrder>& sortOrders,
    77             QContactManager::Error& error)
    77             QContactManager::Error* error)
    78 {
    78 {
    79     // Create an empty list
    79     // Create an empty list
    80     // See QT_TRYCATCH_LEAVING note at the begginning of this file
    80     // See QT_TRYCATCH_LEAVING note at the begginning of this file
    81     QContactLocalIdList *ids = new QContactLocalIdList();
    81     QContactLocalIdList *ids = new QContactLocalIdList();
    82 
    82 
    90 }
    90 }
    91 
    91 
    92 QList<QContactLocalId> CntSymbianSorterDbms::sort(
    92 QList<QContactLocalId> CntSymbianSorterDbms::sort(
    93             QList<QContactLocalId> contactIds,
    93             QList<QContactLocalId> contactIds,
    94             const QList<QContactSortOrder>& sortOrders,
    94             const QList<QContactSortOrder>& sortOrders,
    95             QContactManager::Error& error)
    95             QContactManager::Error* error)
    96 {
    96 {
    97     // Create an empty list
    97     // Create an empty list
    98     // See QT_TRYCATCH_LEAVING note at the begginning of this file
    98     // See QT_TRYCATCH_LEAVING note at the begginning of this file
    99     QContactLocalIdList *ids = new QContactLocalIdList();
    99     QContactLocalIdList *ids = new QContactLocalIdList();
   100 
   100 
   107     return *QScopedPointer<QContactLocalIdList>(ids);
   107     return *QScopedPointer<QContactLocalIdList>(ids);
   108 }
   108 }
   109 
   109 
   110 bool CntSymbianSorterDbms::sortOrderSupported(const QList<QContactSortOrder>& sortOrders)
   110 bool CntSymbianSorterDbms::sortOrderSupported(const QList<QContactSortOrder>& sortOrders)
   111 {
   111 {
   112     foreach( QContactSortOrder s, sortOrders ) {
   112     foreach(const QContactSortOrder& s, sortOrders ) {
   113         // Find uids for sortings
   113         // Find uids for sortings
   114         QList<TUid> fieldTypeUids = m_transformContact.supportedSortingFieldTypes(s.detailDefinitionName(), s.detailFieldName());
   114         QList<TUid> fieldTypeUids = m_transformContact.supportedSortingFieldTypes(s.detailDefinitionName(), s.detailFieldName());
   115         if( fieldTypeUids.count() == 0 )
   115         if( fieldTypeUids.count() == 0 )
   116             return false;
   116             return false;
   117 
   117 
   143     CleanupStack::PushL(ids);
   143     CleanupStack::PushL(ids);
   144 
   144 
   145     // Remove templates from the list
   145     // Remove templates from the list
   146     CContactIdArray *templateIds = m_contactDatabase.GetCardTemplateIdListL();
   146     CContactIdArray *templateIds = m_contactDatabase.GetCardTemplateIdListL();
   147     CleanupStack::PushL(templateIds);
   147     CleanupStack::PushL(templateIds);
   148     for(TInt i(0); i < templateIds->Count(); i++) {
   148     for(TInt i(0); i < templateIds->Count(); ++i) {
   149         TContactItemId id = (*templateIds)[i];
   149         TContactItemId id = (*templateIds)[i];
   150         TInt index = ids->Find(id);
   150         TInt index = ids->Find(id);
   151         if(index > KErrNotFound)
   151         if(index > KErrNotFound)
   152             ids->Remove(index);
   152             ids->Remove(index);
   153     }
   153     }
   159     ids = sortedIds;
   159     ids = sortedIds;
   160     CleanupStack::PushL(ids);
   160     CleanupStack::PushL(ids);
   161 
   161 
   162     // Add the contact ids to the returned QList
   162     // Add the contact ids to the returned QList
   163     QList<QContactLocalId> qIds;
   163     QList<QContactLocalId> qIds;
   164     for (TInt i(0); i < ids->Count(); i++) {
   164     for (TInt i(0); i < ids->Count(); ++i) {
   165         qIds.append((*ids)[i]);
   165         qIds.append((*ids)[i]);
   166     }
   166     }
   167 
   167 
   168     CleanupStack::PopAndDestroy(ids);
   168     CleanupStack::PopAndDestroy(ids);
   169 
   169 
   193     CArrayFixFlat<CContactDatabase::TSortPref> *sort =
   193     CArrayFixFlat<CContactDatabase::TSortPref> *sort =
   194         new (ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(5);
   194         new (ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(5);
   195     CleanupStack::PushL(sort);
   195     CleanupStack::PushL(sort);
   196 
   196 
   197     // Convert sort orders to TSortPref array
   197     // Convert sort orders to TSortPref array
   198     foreach (QContactSortOrder s, sortOrders)
   198     foreach (const QContactSortOrder& s, sortOrders)
   199     {
   199     {
   200         QList<TUid> fieldTypes = m_transformContact.supportedSortingFieldTypes(s.detailDefinitionName(), s.detailFieldName());
   200         QList<TUid> fieldTypes = m_transformContact.supportedSortingFieldTypes(s.detailDefinitionName(), s.detailFieldName());
   201         if (fieldTypes.count())
   201         if (fieldTypes.count())
   202         {
   202         {
   203             foreach(TUid fieldType, fieldTypes) {
   203             foreach(const TUid& fieldType, fieldTypes) {
   204                 CContactDatabase::TSortPref pref;
   204                 CContactDatabase::TSortPref pref;
   205                 // NOTE: TSortPref sets order to ascending by default
   205                 // NOTE: TSortPref sets order to ascending by default
   206                 if( s.direction() == Qt::DescendingOrder )
   206                 if( s.direction() == Qt::DescendingOrder )
   207                     pref.iOrder = CContactDatabase::TSortPref::EDesc;
   207                     pref.iOrder = CContactDatabase::TSortPref::EDesc;
   208                 pref.iFieldType = fieldType;
   208                 pref.iFieldType = fieldType;