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 #ifndef CNTSYMBIANFILTERSQLHELPER_H |
|
42 #define CNTSYMBIANFILTERSQLHELPER_H |
|
43 |
|
44 // System includes |
|
45 #include <qtcontactsglobal.h> |
|
46 // User includes |
|
47 #include "qcontactdetailfilter.h" |
|
48 #include "qcontactphonenumber.h" |
|
49 #include "qcontactmanager.h" |
|
50 #include "cntsymbiansrvconnection.h" |
|
51 #include "cntabstractcontactfilter.h" |
|
52 |
|
53 // Forward declarations |
|
54 class CntSqlSearch; |
|
55 // External data types |
|
56 |
|
57 // Constants |
|
58 QTM_USE_NAMESPACE |
|
59 class CntSymbianFilterSqlHelper |
|
60 { |
|
61 public: |
|
62 Q_DECLARE_LATIN1_LITERAL(CntSymbianFilterSqlHelper::SingleQuote,"'") ; |
|
63 Q_DECLARE_LATIN1_LITERAL(CntSymbianFilterSqlHelper::PercentSign,"%") ; |
|
64 Q_DECLARE_LATIN1_LITERAL(CntSymbianFilterSqlHelper::Space," ") ; |
|
65 Q_DECLARE_LATIN1_LITERAL(CntSymbianFilterSqlHelper::EqualTo,"=") ; |
|
66 Q_DECLARE_LATIN1_LITERAL(CntSymbianFilterSqlHelper::SqlLike," LIKE ") ; |
|
67 Q_DECLARE_LATIN1_LITERAL(CntSymbianFilterSqlHelper::SqlNotNull," NOT NULL ") ; |
|
68 Q_DECLARE_LATIN1_LITERAL(CntSymbianFilterSqlHelper::SqlWhere," WHERE ") ; |
|
69 Q_DECLARE_LATIN1_LITERAL(CntSymbianFilterSqlHelper::SqlOr," OR ") ; |
|
70 Q_DECLARE_LATIN1_LITERAL(CntSymbianFilterSqlHelper::contactsTable," contact ") ; |
|
71 Q_DECLARE_LATIN1_LITERAL(CntSymbianFilterSqlHelper::commAddrTable," comm_addr ") ; |
|
72 |
|
73 //This is copied from pltables.h from cntmodel. |
|
74 // This definition needs to be exported and the file included |
|
75 // so that duplicity is avoided |
|
76 enum TCommAddrType |
|
77 { |
|
78 EPhoneNumber, |
|
79 EEmailAddress, |
|
80 ESipAddress |
|
81 }; |
|
82 public: |
|
83 CntSymbianFilterSqlHelper(CContactDatabase &contactDatabase); |
|
84 virtual ~CntSymbianFilterSqlHelper(); |
|
85 |
|
86 public: |
|
87 /*Generic functions for all filters*/ |
|
88 QList<QContactLocalId> searchContacts(const QContactFilter& filter, |
|
89 const QList<QContactSortOrder>& sortOrders, |
|
90 QContactManager::Error& error); |
|
91 CntAbstractContactFilter::FilterSupport filterSupportLevel(const QContactFilter& filter); |
|
92 |
|
93 private: |
|
94 void appendSortOrderQuery(QString& sqlQuery, const QList<QContactSortOrder>& sortOrders); |
|
95 void columnName( QString &columnName, const QString &detailDefinitionName, const QString & detailFieldName); |
|
96 void createSqlQuery(const QContactFilter& filter, |
|
97 QString& sqlQuery, |
|
98 QContactManager::Error& error); |
|
99 /* Return true if this filter is leaf filter*/ |
|
100 bool isSingleFilter(const QContactFilter& filter) const; |
|
101 /*Local helper functions used for creating the sql query */ |
|
102 void updateSqlQueryForSingleFilter(const QContactFilter& filter, |
|
103 QString& sqlQuery, |
|
104 QContactManager::Error& error); |
|
105 void updateSqlQueryForDetailFilter(const QContactFilter& filter, |
|
106 QString& sqlQuery, |
|
107 QContactManager::Error& error); |
|
108 |
|
109 void getSqlDbTableAndColumnNameforDetailFilter( |
|
110 const QContactDetailFilter& filter , |
|
111 bool& isSubType, |
|
112 QString& tableName, |
|
113 QString& columnName ); |
|
114 |
|
115 |
|
116 void updateFieldForDeatilFilterMatchFlag( const QContactDetailFilter& filter, |
|
117 QString& fieldToUpdate , |
|
118 QContactManager::Error& error) const; |
|
119 QList<QContactLocalId> CntSymbianFilterSqlHelper::HandlePhonenumberDetailFilter(const QContactDetailFilter detailFilter); |
|
120 void getMatchLengthL(TInt& matchLength); |
|
121 TInt CntSymbianFilterSqlHelper::searchPhoneNumbers( |
|
122 CContactIdArray*& idArray, |
|
123 const TDesC& phoneNumber, |
|
124 const TInt matchLength); |
|
125 CntAbstractContactFilter::FilterSupport checkIfDetailFilterSupported(const QContactDetailFilter& detailFilter) const; |
|
126 QList<QContactLocalId> HandlePredictiveSearchFilter(const QContactFilter& filter, bool& isPredSearch, QContactManager::Error& error); |
|
127 |
|
128 private: |
|
129 CntSymbianSrvConnection* m_srvConnection; |
|
130 CntSqlSearch* m_sqlSearch; |
|
131 CContactDatabase &m_contactDatabase; |
|
132 bool isPhoneNumberSearchforDetailFilter; |
|
133 QHash<int,QString> contactsTableIdColumNameMapping; |
|
134 QHash<int,int> commAddrTableIdColumNameMapping; |
|
135 |
|
136 friend class ut_cntsymbianfiltersqlhelper; |
|
137 |
|
138 }; |
|
139 |
|
140 #endif//CNTSYMBIANFILTERSQLHELPER_H |
|