qtmobility/plugins/contacts/symbian/src/filtering/cntfilterdetail.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    72 
    72 
    73 QList<QContactLocalId> CntFilterDetail::contacts(
    73 QList<QContactLocalId> CntFilterDetail::contacts(
    74         const QContactFilter &filter,
    74         const QContactFilter &filter,
    75         const QList<QContactSortOrder> &sortOrders,
    75         const QList<QContactSortOrder> &sortOrders,
    76         bool &filterSupportedflag,
    76         bool &filterSupportedflag,
    77         QContactManager::Error &error)  
    77         QContactManager::Error* error)
    78 {
    78 {
    79     Q_UNUSED(sortOrders);
    79     Q_UNUSED(sortOrders);
    80     Q_UNUSED(filterSupportedflag);
    80     Q_UNUSED(filterSupportedflag);
    81     //Check if any invalid filter is passed 
    81     //Check if any invalid filter is passed 
    82     if(!filterSupported(filter) )
    82     if(!filterSupported(filter) )
    83         {
    83         {
    84         error =  QContactManager::NotSupportedError;
    84         *error =  QContactManager::NotSupportedError;
    85         return QList<QContactLocalId>();
    85         return QList<QContactLocalId>();
    86         }
    86         }
    87     QList<QContactLocalId> idList;
    87     QList<QContactLocalId> idList;
    88     QContactDetailFilter detailFilter(filter);
    88     QContactDetailFilter detailFilter(filter);
    89     QString sqlQuery;
    89     QString sqlQuery;
    90     //Check for phonenumber. Special handling needed
    90     //Check for phonenumber. Special handling needed
    91     if(detailFilter.detailDefinitionName() == QContactPhoneNumber::DefinitionName )
    91     if( (detailFilter.detailDefinitionName() == QContactPhoneNumber::DefinitionName ) &&
       
    92             (detailFilter.detailFieldName() != QContactPhoneNumber::FieldSubTypes))
    92     {
    93     {
    93         //Handle phonenumber ...
    94         //Handle phonenumber ...
    94     
       
    95         idList = HandlePhonenumberDetailFilter(filter);
    95         idList = HandlePhonenumberDetailFilter(filter);
       
    96         
    96     }
    97     }
    97     else if (detailFilter.matchFlags() == QContactFilter::MatchKeypadCollation) 
    98     else if (detailFilter.matchFlags() == QContactFilter::MatchKeypadCollation) 
    98     {
    99     {
    99         //predictive search filter
   100         //predictive search filter
   100         idList = HandlePredictiveSearchFilter(filter,error);
   101         idList = HandlePredictiveSearchFilter(filter,error);
   102             
   103             
   103     // handle other cases
   104     // handle other cases
   104     else 
   105     else 
   105     {
   106     {
   106         createSelectQuery(filter,sqlQuery,error);
   107         createSelectQuery(filter,sqlQuery,error);
   107         if(error == QContactManager::NoError)
   108         QString sortQuery = m_dbInfo.getSortQuery(sortOrders, sqlQuery, error);
       
   109         
       
   110         if(*error == QContactManager::NoError)
   108             {
   111             {
   109             //fetch the contacts
   112             //fetch the contacts
   110             idList =  m_srvConnection.searchContacts(sqlQuery, error);
   113             idList =  m_srvConnection.searchContacts(sortQuery, error);
   111             }
   114             }
   112     }
   115     }
   113     
   116     
   114     return idList;
   117     return idList;
   115 
   118 
   129     return result;
   132     return result;
   130 }
   133 }
   131 
   134 
   132 void CntFilterDetail::createSelectQuery(const QContactFilter& filter,
   135 void CntFilterDetail::createSelectQuery(const QContactFilter& filter,
   133                               QString& sqlQuery,
   136                               QString& sqlQuery,
   134                               QContactManager::Error& error)
   137                               QContactManager::Error* error)
   135 
   138 
   136 {
   139 {
   137       if(!filterSupported(filter) )
   140       if(!filterSupported(filter) )
   138       {
   141       {
   139           error = QContactManager::NotSupportedError;
   142           *error = QContactManager::NotSupportedError;
   140           return;
   143           return;
   141       }
   144       }
   142       QContactDetailFilter detailFilter(filter);
   145       QContactDetailFilter detailFilter(filter);
   143       //display label
   146       //display label
   144       if (detailFilter.detailDefinitionName() == QContactDisplayLabel::DefinitionName)
   147       if (detailFilter.detailDefinitionName() == QContactDisplayLabel::DefinitionName)
   157        }
   160        }
   158        else if(detailFilter.detailDefinitionName() == QContactGuid::DefinitionName)
   161        else if(detailFilter.detailDefinitionName() == QContactGuid::DefinitionName)
   159        {
   162        {
   160            if(detailFilter.detailFieldName() == QContactGuid::FieldGuid)
   163            if(detailFilter.detailFieldName() == QContactGuid::FieldGuid)
   161            {
   164            {
   162                QStringList fullGuidValue = detailFilter.value().toString().split("-");
   165                QStringList fullGuidValue = detailFilter.value().toString().split('-');
   163                if (fullGuidValue.count() == 3) {
   166                if (fullGuidValue.count() == 3) {
   164                    QString localGuidValue = fullGuidValue.at(1);
   167                    QString localGuidValue = fullGuidValue.at(1);
   165                    sqlQuery = "SELECT contact_id FROM contact WHERE guid_string = '" + localGuidValue + "'";
   168                    sqlQuery = "SELECT contact_id FROM contact WHERE guid_string = '" + localGuidValue + '\'';
   166                 }
   169                 }
   167             }
   170             }
   168        }
   171        }
   169        //everything else
   172        //everything else
   170        else
   173        else
   181 /*!
   184 /*!
   182  * Updates match flage for columns.
   185  * Updates match flage for columns.
   183  */
   186  */
   184 void CntFilterDetail::updateForMatchFlag( const QContactDetailFilter& filter,
   187 void CntFilterDetail::updateForMatchFlag( const QContactDetailFilter& filter,
   185                                           QString& fieldToUpdate ,
   188                                           QString& fieldToUpdate ,
   186                                           QContactManager::Error& error) const
   189                                           QContactManager::Error* error) const
   187 {
   190 {
   188     // Modify the filed depending on the query
   191     // Modify the filed depending on the query
   189     switch(filter.matchFlags())
   192     switch(filter.matchFlags())
   190         {
   193         {
   191             case QContactFilter::MatchExactly:
   194             case QContactFilter::MatchExactly:
   192                 {
   195                 {
   193                 // Pattern for MatchExactly:
   196                 // Pattern for MatchExactly:
   194                 // " ='xyz'"
   197                 // " ='xyz'"
   195                 fieldToUpdate = " ='"
   198                 fieldToUpdate = " ='"
   196                                + filter.value().toString() + "'";
   199                                + filter.value().toString() + '\'';
   197                 error = QContactManager::NoError;
   200                 *error = QContactManager::NoError;
   198                 break;
   201                 break;
   199                 }
   202                 }
   200             case QContactFilter::MatchContains:
   203             case QContactFilter::MatchContains:
   201                 {
   204                 {
   202                 // Pattern for MatchContains:
   205                 // Pattern for MatchContains:
   203                 // " LIKE '%xyz%'"
   206                 // " LIKE '%xyz%'"
   204                 fieldToUpdate = " LIKE '%" + filter.value().toString() + "%'" ;
   207                 fieldToUpdate = " LIKE '%" + filter.value().toString() + "%'" ;
   205                 error = QContactManager::NoError;
   208                 *error = QContactManager::NoError;
   206                 break;
   209                 break;
   207                 }
   210                 }
   208             case QContactFilter::MatchStartsWith:
   211             case QContactFilter::MatchStartsWith:
   209                 {
   212                 {
   210                 // Pattern for MatchStartsWith:
   213                 // Pattern for MatchStartsWith:
   211                 // " LIKE 'xyz%'"
   214                 // " LIKE 'xyz%'"
   212                 fieldToUpdate = " LIKE '" +  filter.value().toString() + "%'"  ;
   215                 fieldToUpdate = " LIKE '" +  filter.value().toString() + "%'"  ;
   213                 error = QContactManager::NoError;
   216                 *error = QContactManager::NoError;
   214                 break;
   217                 break;
   215                 }
   218                 }
   216             case QContactFilter::MatchEndsWith:
   219             case QContactFilter::MatchEndsWith:
   217                 {
   220                 {
   218                 // Pattern for MatchEndsWith:
   221                 // Pattern for MatchEndsWith:
   219                 // " LIKE '%xyz'"
   222                 // " LIKE '%xyz'"
   220                 fieldToUpdate = " LIKE '%" + filter.value().toString() + "'" ;
   223                 fieldToUpdate = " LIKE '%" + filter.value().toString() + '\'' ;
   221                 error = QContactManager::NoError;
   224                 *error = QContactManager::NoError;
   222                 break;
   225                 break;
   223                 }
   226                 }
   224             case QContactFilter::MatchFixedString:
   227             case QContactFilter::MatchFixedString:
   225                 {
   228                 {
   226                 error = QContactManager::NotSupportedError;
   229                 *error = QContactManager::NotSupportedError;
   227                 break;
   230                 break;
   228                 }
   231                 }
   229             case QContactFilter::MatchCaseSensitive:
   232             case QContactFilter::MatchCaseSensitive:
   230                 {
   233                 {
   231                 error = QContactManager::NotSupportedError;
   234                 *error = QContactManager::NotSupportedError;
   232                 break;
   235                 break;
   233                 }
   236                 }
   234             default:
   237             default:
   235                 {
   238                 {
   236                 error = QContactManager::NotSupportedError;
   239                 *error = QContactManager::NotSupportedError;
   237                 break;
   240                 break;
   238                 }
   241                 }
   239         }
   242         }
   240         
   243         
   241 }
   244 }
   242 
   245 
   243 void CntFilterDetail::getTableNameWhereClause( const QContactDetailFilter& detailfilter,
   246 void CntFilterDetail::getTableNameWhereClause( const QContactDetailFilter& detailfilter,
   244                                                QString& tableName,
   247                                                QString& tableName,
   245                                                QString& sqlWhereClause ,
   248                                                QString& sqlWhereClause ,
   246                                                QContactManager::Error& error) const
   249                                                QContactManager::Error* error) const
   247 {
   250 {
   248     //Get the table name and the column name
   251     //Get the table name and the column name
   249     bool isSubType;
   252     bool isSubType;
   250     QString columnName;
   253     QString columnName;
   251 
   254 
   252     //Get the field id for the detail field name
   255     //Get the field id for the detail field name
   253     CntTransformContact transformContact;
   256     CntTransformContact transformContact;
   254     quint32 fieldId  = transformContact.GetIdForDetailL(detailfilter, isSubType);
   257     quint32 fieldId  = transformContact.GetIdForDetailL(detailfilter, isSubType);
   255     m_dbInfo.getDbTableAndColumnName(fieldId,tableName,columnName);
   258     m_dbInfo.getDbTableAndColumnName(fieldId,tableName,columnName);
   256 
   259     
   257     //return if tableName is empty
   260     //return if tableName is empty
   258     if(tableName == "" ){
   261     if(tableName.isEmpty())
   259         error = QContactManager::NotSupportedError;
   262         {
       
   263         *error = QContactManager::NotSupportedError;
   260         return;
   264         return;
   261     }
   265         }
   262 
   266 
   263     //check columnName
   267     //check columnName
   264     if(columnName == "") {
   268     if(columnName.isEmpty())
   265         error = QContactManager::NotSupportedError;
   269         {
       
   270         *error = QContactManager::NotSupportedError;
   266         return;
   271         return;
   267     }
   272         }
   268     else if(isSubType) {
   273     else if(isSubType) 
       
   274         {
   269         sqlWhereClause += columnName;
   275         sqlWhereClause += columnName;
   270         sqlWhereClause += " NOT NULL ";
   276         sqlWhereClause += " NOT NULL ";
   271     }
   277         }
   272     else {
   278     else 
   273 
   279         {
   274         sqlWhereClause += " " + columnName + " ";
   280         sqlWhereClause += ' ' + columnName + ' ';
   275         QString fieldToUpdate;
   281         QString fieldToUpdate;
   276         //Update the value depending on the match flag
   282         //Update the value depending on the match flag
   277         updateForMatchFlag(detailfilter,fieldToUpdate,error);
   283         updateForMatchFlag(detailfilter,fieldToUpdate,error);
   278         sqlWhereClause +=  fieldToUpdate;
   284         sqlWhereClause +=  fieldToUpdate;
   279     }
   285         }
   280 
   286 }
   281    
   287 
   282 }
   288 QList<QContactLocalId>  CntFilterDetail::HandlePredictiveSearchFilter(const QContactFilter& filter,QContactManager::Error* error)
   283 
       
   284 QList<QContactLocalId>  CntFilterDetail::HandlePredictiveSearchFilter(const QContactFilter& filter,QContactManager::Error& error)
       
   285     {
   289     {
   286     
   290     
   287     QString sqlQuery;
   291     QString sqlQuery;
   288     
   292     
   289     if(filter.type() == QContactFilter::ContactDetailFilter){
   293     if(filter.type() == QContactFilter::ContactDetailFilter){