|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtCore module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "cntfilterrelationship.h" |
|
43 #include "qcontactrelationshipfilter.h" |
|
44 #include "cnttransformcontact.h" |
|
45 |
|
46 QTM_USE_NAMESPACE |
|
47 |
|
48 |
|
49 |
|
50 CntFilterRelationship::CntFilterRelationship(CContactDatabase& contactDatabase,CntSymbianSrvConnection &cntServer,CntDbInfo& dbInfo) |
|
51 : m_contactdatabase(contactDatabase), |
|
52 m_srvConnection(cntServer), |
|
53 m_dbInfo(dbInfo) |
|
54 { |
|
55 |
|
56 } |
|
57 |
|
58 CntFilterRelationship::~CntFilterRelationship() |
|
59 { |
|
60 |
|
61 } |
|
62 |
|
63 QList<QContactLocalId> CntFilterRelationship::contacts( |
|
64 const QContactFilter &filter, |
|
65 const QList<QContactSortOrder> &sortOrders, |
|
66 bool &filterSupportedflag, |
|
67 QContactManager::Error &error) |
|
68 { |
|
69 Q_UNUSED(sortOrders); |
|
70 Q_UNUSED(filterSupportedflag); |
|
71 //Check if any invalid filter is passed |
|
72 if(!filterSupported(filter) ) |
|
73 { |
|
74 error = QContactManager::NotSupportedError; |
|
75 return QList<QContactLocalId>(); |
|
76 } |
|
77 QList<QContactLocalId> idList; |
|
78 QContactRelationshipFilter relationfilter(filter); |
|
79 |
|
80 QString sqlQuery; |
|
81 getSqlquery(relationfilter,sqlQuery,error); |
|
82 |
|
83 |
|
84 //fetch the contacts |
|
85 idList = m_srvConnection.searchContacts(sqlQuery, error); |
|
86 return idList; |
|
87 |
|
88 |
|
89 |
|
90 } |
|
91 |
|
92 |
|
93 bool CntFilterRelationship::filterSupported(const QContactFilter& filter) |
|
94 { |
|
95 bool result = false; |
|
96 if(QContactFilter::RelationshipFilter == filter.type()) |
|
97 { |
|
98 QContactRelationshipFilter relationfilter(filter); |
|
99 if(relationfilter.relationshipType() == QContactRelationship::HasMember) |
|
100 { |
|
101 result = true; |
|
102 } |
|
103 } |
|
104 |
|
105 return result; |
|
106 } |
|
107 |
|
108 void CntFilterRelationship::createSelectQuery(const QContactFilter& filter, |
|
109 QString& sqlQuery, |
|
110 QContactManager::Error& error) |
|
111 |
|
112 { |
|
113 //Notthing done as of now |
|
114 Q_UNUSED(filter); |
|
115 Q_UNUSED(sqlQuery); |
|
116 Q_UNUSED(error); |
|
117 |
|
118 } |
|
119 |
|
120 |
|
121 void CntFilterRelationship::getSqlquery( const QContactRelationshipFilter& relationfilter, |
|
122 QString& sqlquery , |
|
123 QContactManager::Error& error) const |
|
124 { |
|
125 |
|
126 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 } |
|
147 |