62 |
61 |
63 QList<QContactLocalId> CntFilterRelationship::contacts( |
62 QList<QContactLocalId> CntFilterRelationship::contacts( |
64 const QContactFilter &filter, |
63 const QContactFilter &filter, |
65 const QList<QContactSortOrder> &sortOrders, |
64 const QList<QContactSortOrder> &sortOrders, |
66 bool &filterSupportedflag, |
65 bool &filterSupportedflag, |
67 QContactManager::Error &error) |
66 QContactManager::Error *error) |
68 { |
67 { |
69 Q_UNUSED(sortOrders); |
68 Q_UNUSED(sortOrders); |
70 Q_UNUSED(filterSupportedflag); |
69 Q_UNUSED(filterSupportedflag); |
71 //Check if any invalid filter is passed |
70 //Check if any invalid filter is passed |
72 if(!filterSupported(filter) ) |
71 if(!filterSupported(filter) ) |
73 { |
72 { |
74 error = QContactManager::NotSupportedError; |
73 *error = QContactManager::NotSupportedError; |
75 return QList<QContactLocalId>(); |
74 return QList<QContactLocalId>(); |
76 } |
75 } |
77 QList<QContactLocalId> idList; |
76 QList<QContactLocalId> idList; |
78 QContactRelationshipFilter relationfilter(filter); |
|
79 |
|
80 QString sqlQuery; |
77 QString sqlQuery; |
81 getSqlquery(relationfilter,sqlQuery,error); |
78 createSelectQuery(filter,sqlQuery,error); |
82 |
|
83 |
|
84 //fetch the contacts |
79 //fetch the contacts |
85 idList = m_srvConnection.searchContacts(sqlQuery, error); |
80 if(*error == QContactManager::NoError ) |
|
81 { |
|
82 idList = m_srvConnection.searchContacts(sqlQuery, error); |
|
83 } |
86 return idList; |
84 return idList; |
87 |
|
88 |
|
89 |
|
90 } |
85 } |
91 |
86 |
92 |
87 |
93 bool CntFilterRelationship::filterSupported(const QContactFilter& filter) |
88 bool CntFilterRelationship::filterSupported(const QContactFilter& filter) |
94 { |
89 { |
105 return result; |
100 return result; |
106 } |
101 } |
107 |
102 |
108 void CntFilterRelationship::createSelectQuery(const QContactFilter& filter, |
103 void CntFilterRelationship::createSelectQuery(const QContactFilter& filter, |
109 QString& sqlQuery, |
104 QString& sqlQuery, |
110 QContactManager::Error& error) |
105 QContactManager::Error* error) |
111 |
106 |
112 { |
107 { |
113 //Notthing done as of now |
108 if(!filterSupported(filter)) |
114 Q_UNUSED(filter); |
109 { |
115 Q_UNUSED(sqlQuery); |
110 *error = QContactManager::NotSupportedError; |
116 Q_UNUSED(error); |
111 return; |
117 |
112 } |
|
113 |
|
114 QContactRelationshipFilter relationfilter(filter); |
|
115 QContactId id_to_search = relationfilter.relatedContactId(); |
|
116 |
|
117 if(relationfilter.relatedContactRole() == QContactRelationship::First ) |
|
118 { |
|
119 sqlQuery = QString("SELECT DISTINCT contact_group_member_id FROM groups WHERE contact_group_id = %1").arg(id_to_search.localId()); |
|
120 } |
|
121 else if(relationfilter.relatedContactRole() == QContactRelationship::Second ) |
|
122 { |
|
123 sqlQuery = QString("SELECT DISTINCT contact_group_id FROM groups WHERE contact_group_member_id = %1").arg(id_to_search.localId()); |
|
124 } |
|
125 else if(relationfilter.relatedContactRole() == QContactRelationship::Either ) |
|
126 { |
|
127 sqlQuery = QString("SELECT contact_group_member_id FROM groups WHERE contact_group_id = %1").arg(id_to_search.localId()); |
|
128 + " union " + |
|
129 QString("SELECT DISTINCT contact_group_id FROM groups WHERE contact_group_id = %1").arg(id_to_search.localId()); |
|
130 } |
118 } |
131 } |
119 |
132 |
120 |
133 |
121 void CntFilterRelationship::getSqlquery( const QContactRelationshipFilter& relationfilter, |
134 void CntFilterRelationship::getSqlquery( const QContactRelationshipFilter& relationfilter, |
122 QString& sqlquery , |
135 QString& sqlquery , |
123 QContactManager::Error& error) const |
136 QContactManager::Error* error) const |
124 { |
137 { |
125 |
138 Q_UNUSED(relationfilter); |
|
139 Q_UNUSED(sqlquery); |
126 Q_UNUSED(error); |
140 Q_UNUSED(error); |
127 QContactId id_to_search = relationfilter.otherParticipantId(); |
|
128 |
|
129 if(relationfilter.role() == QContactRelationshipFilter::First ) |
|
130 { |
|
131 sqlquery = QString("SELECT DISTINCT contact_group_id FROM groups WHERE contact_group_member_id = %1").arg(id_to_search.localId()); |
|
132 |
|
133 } |
|
134 else if(relationfilter.role() == QContactRelationshipFilter::Second ) |
|
135 { |
|
136 sqlquery = QString("SELECT DISTINCT contact_group_member_id FROM groups WHERE contact_group_id = %1").arg(id_to_search.localId()); |
|
137 |
|
138 } |
|
139 else if(relationfilter.role() == QContactRelationshipFilter::Either ) |
|
140 { |
|
141 sqlquery = QString("SELECT contact_group_member_id FROM groups WHERE contact_group_id = %1").arg(id_to_search.localId()); |
|
142 + " union " + |
|
143 QString("SELECT DISTINCT contact_group_id FROM groups WHERE contact_group_id = %1").arg(id_to_search.localId()); |
|
144 } |
|
145 |
|
146 } |
141 } |
147 |
142 |