Implement changelog filter.
[qtcontacts-tracker:qtcontacts-tracker.git] / src / dao / querybuilder.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 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 Qt Mobility Components.
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 #ifndef QTRACKERCONTACTQUERYBUILDER_H
43 #define QTRACKERCONTACTQUERYBUILDER_H
44
45 #include "contactdetailschema.h"
46 #include <QtTracker/rdfunbound.h>
47
48 QTM_BEGIN_NAMESPACE;
49
50 ////////////////////////////////////////////////////////////////////////////////////////////////////
51
52 using SopranoLive::RDFSelect;
53 using SopranoLive::RDFVariable;
54
55 class QTrackerContactDetail;
56 class QTrackerContactDetailField;
57
58 typedef QHash<QString, RDFVariable>                     RDFVariableHash;
59 typedef RDFVariableHash::iterator                       RDFVariableHashIter;
60 typedef RDFVariableHash::const_iterator                 RDFVariableHashConstIter;
61
62 typedef QList<QUrl>                                     PredicateList;
63 typedef QMultiHash<PredicateList, class RDFVariable>    PredicateVariableHash;
64 typedef PredicateVariableHash::iterator                 PredicateVariableHashIter;
65 typedef PredicateVariableHash::const_iterator           PredicateVariableHashConstIter;
66
67 ////////////////////////////////////////////////////////////////////////////////////////////////////
68
69 class QTrackerContactQueryBuilder
70 {
71     Q_DISABLE_COPY(QTrackerContactQueryBuilder);
72
73 public:
74     enum SubjectRole { Contact, Affiliation };
75
76     explicit QTrackerContactQueryBuilder(const QTrackerContactDetailSchema &schema,
77                                          const QTrackerContactDetail *queryDetail = 0);
78     virtual ~QTrackerContactQueryBuilder();
79
80     static QString name(const QString &prefix, const QString &suffix);
81     static QString name(const RDFVariable &variable, const QString &suffix = QString());
82     static QString name(const QTrackerContactDetail &detail, const QString &suffix = QString());
83     static QString name(const QTrackerContactDetail &detail, const QTrackerContactDetailField &field);
84
85     void bindColumns(const QTrackerContactDetail &detail,
86                      RDFSelect &query);
87     void bindFields(const QTrackerContactDetail &detail,
88                     const QContactFilter &filter,
89                     RDFSelect &query);
90
91     RDFVariable bindFilter(const QContactFilter &filter,
92                            SubjectRole role, RDFVariable &subject);
93
94     static bool isFilterSupported(const QContactFilter &filter);
95     QContactManager::Error error() const { return mError; }
96
97 private:
98     void bindColumns(const QTrackerContactDetail &detail,
99                      const QTrackerContactDetailField &field,
100                      RDFSelect &query);
101
102     void bindFields(const QTrackerContactDetail &detail,
103                     SubjectRole role, RDFVariable &subject);
104
105     void bindProperties(const QTrackerContactDetail &detail,
106                         const QTrackerContactDetailField &field,
107                         RDFVariable subject, RDFVariable &object);
108     void bindSubTypes(const QTrackerContactDetail &detail,
109                       const QTrackerContactDetailField &field,
110                       RDFVariable &subject);
111     void bindDetailUri(const QTrackerContactDetail &detail,
112                        const QTrackerContactDetailField &field);
113
114     const QTrackerContactDetailField *
115     bindFilterField(const QString &detailName, QString fieldName,
116                     SubjectRole role, RDFVariable subject,
117                     RDFVariable &object);
118
119     RDFVariable bindFilter(const QContactLocalIdFilter &filter,
120                            SubjectRole role, RDFVariable &subject);
121     RDFVariable bindFilter(const QContactIntersectionFilter &filter,
122                            SubjectRole role, RDFVariable &subject);
123     RDFVariable bindFilter(const QContactUnionFilter &filter,
124                            SubjectRole role, RDFVariable &subject);
125     RDFVariable bindFilter(const QContactDetailFilter &filter,
126                            SubjectRole role, RDFVariable subject);
127     RDFVariable bindFilter(const QContactDetailRangeFilter &filter,
128                            SubjectRole role, RDFVariable subject);
129     RDFVariable bindFilter(const QContactChangeLogFilter &filter,
130                            SubjectRole role, RDFVariable subject);
131
132     RDFVariable tagLabel(RDFVariable &subject);
133
134 private:
135     QContactManager::Error              mError;
136     const QTrackerContactDetailSchema  &mSchema;
137     const QTrackerContactDetail *const  mQueryDetail;
138     RDFVariableHash                     mVariables;
139     PredicateVariableHash               mProperties;
140     PredicateList                       mContext;
141 };
142
143 ////////////////////////////////////////////////////////////////////////////////////////////////////
144
145 QTM_END_NAMESPACE;
146
147 #endif // QTRACKERCONTACTQUERYBUILDER_H