qtmobility/plugins/contacts/symbian/src/filtering/cntdbinfo.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 #include <cntdef.h>
    41 #include <cntdef.h>
    42 #include "cntdbinfo.h"
    42 #include "cntdbinfo.h"
    43 #include "cntmodelextuids.h"
    43 #include "cntmodelextuids.h"
       
    44 #include "cntfilterdetail.h"
       
    45 #include "cnttransformcontact.h"
    44 
    46 
    45 
    47 
    46 CntDbInfo::CntDbInfo()       
    48 CntDbInfo::CntDbInfo()       
    47 {
    49 {
    48 
    50 
    56     commAddrTableIdColumNameMapping.insert(KUidContactFieldSIPID.iUid,ESipAddress );
    58     commAddrTableIdColumNameMapping.insert(KUidContactFieldSIPID.iUid,ESipAddress );
    57     commAddrTableIdColumNameMapping.insert(KUidContactFieldVCardMapVOIP.iUid,ESipAddress );
    59     commAddrTableIdColumNameMapping.insert(KUidContactFieldVCardMapVOIP.iUid,ESipAddress );
    58     commAddrTableIdColumNameMapping.insert(KUidContactFieldVCardMapSWIS.iUid,ESipAddress );
    60     commAddrTableIdColumNameMapping.insert(KUidContactFieldVCardMapSWIS.iUid,ESipAddress );
    59     commAddrTableIdColumNameMapping.insert(KUidContactFieldIMPP.iUid,ESipAddress );
    61     commAddrTableIdColumNameMapping.insert(KUidContactFieldIMPP.iUid,ESipAddress );
    60     commAddrTableIdColumNameMapping.insert(KUidContactFieldEMail.iUid,EEmailAddress );
    62     commAddrTableIdColumNameMapping.insert(KUidContactFieldEMail.iUid,EEmailAddress );
       
    63     commAddrTableIdColumNameMapping.insert(KUidContactFieldPhoneNumber.iUid,EPhoneNumber );
    61 }
    64 }
    62 
    65 
    63 CntDbInfo::~CntDbInfo()
    66 CntDbInfo::~CntDbInfo()
    64 {
    67 {
    65 
    68 
    98     if (contactsTableIdColumNameMapping.contains(fieldId)){
   101     if (contactsTableIdColumNameMapping.contains(fieldId)){
    99          columnName = contactsTableIdColumNameMapping.value(fieldId);
   102          columnName = contactsTableIdColumNameMapping.value(fieldId);
   100          tableName = "contact";
   103          tableName = "contact";
   101      }
   104      }
   102 
   105 
   103     if( ("" == columnName)  || ("" == tableName)){
   106     if( (columnName.isEmpty())  || (tableName.isEmpty())){
   104         //Search comm Addr table
   107         //Search comm Addr table
   105         if (commAddrTableIdColumNameMapping.contains(fieldId)){
   108         if (commAddrTableIdColumNameMapping.contains(fieldId)){
   106                 // communication address table has slightly differnt format, so we make the column name as
   109                 // communication address table has slightly differnt format, so we make the column name as
   107                 //  "type = <type> and value "
   110                 //  "type = <type> and value "
   108                 int typeval = commAddrTableIdColumNameMapping.value(fieldId) ;
   111                 int typeval = commAddrTableIdColumNameMapping.value(fieldId) ;
   113 
   116 
   114     }
   117     }
   115 
   118 
   116 }
   119 }
   117 
   120 
       
   121 QString CntDbInfo::getSortQuery( const QList<QContactSortOrder> &sortOrders,
       
   122                                  const QString& selectQuery,
       
   123                                  QContactManager::Error* error)
       
   124 {
       
   125     // Set to initial select query
       
   126     QString sortQuery =  selectQuery;
       
   127     
       
   128     if(*error == QContactManager::NoError)
       
   129         {
       
   130         QList<QString> list;
       
   131         foreach(const QContactSortOrder& s, sortOrders )
       
   132             {
       
   133             // Find uids for sortings
       
   134             // Get the field id for the detail field name
       
   135             bool isSubType;
       
   136             QString tableName;
       
   137             QString columnName;
       
   138             CntTransformContact transformContact;
       
   139             QContactDetailFilter filter;
       
   140             
       
   141             // Get column names for sort order
       
   142             filter.setDetailDefinitionName(s.detailDefinitionName(), s.detailFieldName());
       
   143             quint32 fieldId  = transformContact.GetIdForDetailL(filter, isSubType);
       
   144             getDbTableAndColumnName(fieldId,tableName,columnName);
       
   145             
       
   146             if (tableName.compare("contact") != 0
       
   147                 || columnName.isEmpty())
       
   148                 {
       
   149                 // Skip invalid sort clause
       
   150                 continue;
       
   151                 }
       
   152             else
       
   153                 {
       
   154                 if( s.direction() == Qt::DescendingOrder )
       
   155                     {
       
   156                     QString col;
       
   157                     if(s.caseSensitivity() == Qt::CaseInsensitive)
       
   158                         col= ' ' + columnName + ' ' + "COLLATE NOCASE DESC";
       
   159                     else
       
   160                         col= ' ' + columnName + ' ' + "DESC";
       
   161                     list.append(col);
       
   162                     }
       
   163                 else
       
   164                     {
       
   165                     // Default sort order
       
   166                     QString col;
       
   167                     if(s.caseSensitivity() == Qt::CaseInsensitive)
       
   168                         col= ' ' + columnName + ' ' + "COLLATE NOCASE ASC";
       
   169                     else
       
   170                         col= ' ' + columnName + ' ' + "ASC";
       
   171                     list.append(col);
       
   172                     }
       
   173                 }
       
   174             }
       
   175         
       
   176         if(list.count() > 0)
       
   177             {
       
   178             // Recreate query
       
   179             // SELECT DISTINCT contact_id FROM contact WHERE contact_id in (
       
   180             //      SELECT ..
       
   181             // )  ORDER BY  <field> <order>
       
   182             sortQuery = " SELECT DISTINCT contact_id FROM contact WHERE contact_id in (";
       
   183             QString clause = " ORDER BY " + list.at(0);
       
   184             for (int i = 1; i < list.size(); ++i)
       
   185                 {
       
   186                 clause += " ," + list.at(i);
       
   187                 }
       
   188             sortQuery += selectQuery + ')';
       
   189             sortQuery += clause;
       
   190             }
       
   191         }
       
   192     
       
   193     return sortQuery;
       
   194 }
       
   195 
       
   196