Changes: rename files contactfetchrequest.* to abstractcontactfetchrequest.* (to...
[qtcontacts-tracker:qtcontacts-tracker.git] / src / engine / abstractcontactfetchrequest.h
1 /*********************************************************************************
2  ** This file is part of QtContacts tracker storage plugin
3  **
4  ** Copyright (c) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
5  **
6  ** Contact:  Nokia Corporation (info@qt.nokia.com)
7  **
8  ** GNU Lesser General Public License Usage
9  ** This file may be used under the terms of the GNU Lesser General Public License
10  ** version 2.1 as published by the Free Software Foundation and appearing in the
11  ** file LICENSE.LGPL included in the packaging of this file.  Please review the
12  ** following information to ensure the GNU Lesser General Public License version
13  ** 2.1 requirements will be met:
14  ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
15  **
16  ** In addition, as a special exception, Nokia gives you certain additional rights.
17  ** These rights are described in the Nokia Qt LGPL Exception version 1.1, included
18  ** in the file LGPL_EXCEPTION.txt in this package.
19  **
20  ** Other Usage
21  ** Alternatively, this file may be used in accordance with the terms and
22  ** conditions contained in a signed written agreement between you and Nokia.
23  *********************************************************************************/
24
25 #ifndef QTRACKERCONTACTFETCHREQUEST_H
26 #define QTRACKERCONTACTFETCHREQUEST_H
27
28 #include "baserequest.h"
29
30 #include <cubi.h>
31
32 ////////////////////////////////////////////////////////////////////////////////////////////////////
33
34 class QTrackerContactDetailBuilder;
35 class QTrackerContactDetail;
36 class QTrackerContactDetailField;
37 class QTrackerScalarContactQueryBuilder;
38
39 class QSparqlResult;
40 class QSparqlResultRow;
41
42 ////////////////////////////////////////////////////////////////////////////////////////////////////
43
44 class QTrackerContactFetchRequest : public QTrackerBaseRequest<QContactFetchRequest>
45 {
46     Q_DISABLE_COPY(QTrackerContactFetchRequest)
47     Q_OBJECT
48
49     class DetailContext;
50     class QueryContext;
51
52     typedef QHash<QContactLocalId, QContact> ContactCache;
53
54 public:
55     explicit QTrackerContactFetchRequest(QContactAbstractRequest *request,
56                                          QContactTrackerEngine *engine,
57                                          QObject *parent = 0);
58     virtual ~QTrackerContactFetchRequest();
59
60     Cubi::Select query(const QString &contactType, QContactManager::Error &error) const;
61
62 protected: // QTrackerAbstractRequest API
63     void run();
64     void updateRequest(QContactManager::Error error);
65
66 private:
67     QContactManager::Error bindDetails(QueryContext &context) const;
68     QContactManager::Error buildQuery(QueryContext &context) const;
69
70     Cubi::Select baseQuery(const QTrackerScalarContactQueryBuilder &queryBuilder) const;
71     void fetchUniqueDetail(QList<QContactDetail> &details,
72                            const QueryContext &queryContext,
73                            const DetailContext &context,
74                            const QString &affiliation);
75     void fetchMultiDetails(QList<QContactDetail> &details,
76                            const QueryContext &queryContext,
77                            const DetailContext &context);
78     void fetchMultiDetail(QContactDetail &detail,
79                           const DetailContext &context,
80                           const QString &rawValueString);
81     void fetchResults(ContactCache &results, const QueryContext &context);
82     QContactDetail fetchCustomDetail(const QString &rawValue,
83                                      const QString &contactType);
84     void fetchCustomDetails(const QueryContext &queryContext,
85                             ContactCache::Iterator contact);
86     void fetchHasMemberRelationships(const QueryContext &queryContext,
87                                      ContactCache::Iterator contact);
88
89     QVariant fetchInstances(const QTrackerContactDetailField &field,
90                             const QString &rawValueString,
91                             bool &isReadOnly) const;
92     QVariant fetchField(const QTrackerContactDetailField &field,
93                         const QString &rawValueString,
94                         bool &isReadOnly) const;
95     void fetchCustomValues(const QTrackerContactDetailField &field,
96                            QVariant &fieldValue,
97                            const QString &rawValueString,
98                            bool &isReadOnly) const;
99     bool saveDetail(ContactCache::iterator contact, QContactDetail &detail,
100                     const QTrackerContactDetail &definition);
101
102     QString fieldStringWithStrippedGraph(const QTrackerContactDetailField &field,
103                                          const QString &rawValueString, bool &isOtherGraph) const;
104     QStringList fieldStringListWithStrippedGraph(const QTrackerContactDetailField &field,
105                                                  const QString &rawValueString, bool &isOtherGraph,
106                                                  bool cleanList = false) const;
107
108 private: // fields
109     const QContactFilter                m_filter;
110     const QContactFetchHint             m_fetchHint;
111     const QString                       m_nameOrder;
112     const QList<QContactSortOrder>      m_sorting;
113
114     QList<QContact>                     m_contacts;
115 };
116
117 ////////////////////////////////////////////////////////////////////////////////////////////////////
118
119 #endif // QTRACKERCONTACTFETCHREQUEST_H