40 ****************************************************************************/ |
40 ****************************************************************************/ |
41 |
41 |
42 #ifndef QTRACKERCONTACTASYNCREQUEST_H_ |
42 #ifndef QTRACKERCONTACTASYNCREQUEST_H_ |
43 #define QTRACKERCONTACTASYNCREQUEST_H_ |
43 #define QTRACKERCONTACTASYNCREQUEST_H_ |
44 |
44 |
45 #include <QObject> |
|
46 |
|
47 #include <QtTracker/Tracker> |
|
48 #include <QtTracker/QLive> |
|
49 |
|
50 #include <qmobilityglobal.h> |
45 #include <qmobilityglobal.h> |
51 #include <qcontact.h> |
46 #include <qcontactabstractrequest.h> |
52 #include <qcontactonlineaccount.h> |
|
53 #include <qcontactmanager.h> |
|
54 |
|
55 QTM_BEGIN_NAMESPACE |
|
56 class QContactAbstractRequest; |
|
57 class QContactManagerEngine; |
|
58 QTM_END_NAMESPACE |
|
59 |
47 |
60 QTM_USE_NAMESPACE |
48 QTM_USE_NAMESPACE |
61 |
49 |
62 /*! |
50 /*! |
63 * Current implementation only server get all contacts requests. |
51 * Current implementation only server get all contacts requests. |
71 |
59 |
72 protected: |
60 protected: |
73 QContactAbstractRequest* req; |
61 QContactAbstractRequest* req; |
74 }; |
62 }; |
75 |
63 |
76 namespace IMAccount { |
|
77 enum IMResultColumn { |
|
78 URI, |
|
79 ContactIMId, |
|
80 ContactPresence, |
|
81 ContactMessage, |
|
82 ContactNickname, |
|
83 ContactDisplayname |
|
84 }; |
|
85 }; |
|
86 |
|
87 namespace IMContact { |
|
88 enum IMResultColumn { |
|
89 URI, |
|
90 ContactId, |
|
91 ContactIMId, |
|
92 ContactPresence, |
|
93 ContactMessage, |
|
94 ContactNickname, |
|
95 AccountType, |
|
96 Capabilities, |
|
97 MetaContact, |
|
98 ServiceProvider |
|
99 }; |
|
100 }; |
|
101 |
|
102 /*! |
|
103 * Running QContactFetchRequest. Doing the async tracker query and when data is ready setting the |
|
104 * finished status of request. \sa QTrackerContactFetchRequest |
|
105 */ |
|
106 class QTrackerContactFetchRequest : public QObject, public QTrackerContactAsyncRequest |
|
107 { |
|
108 Q_OBJECT |
|
109 // Q_ENUMS(IMResultColumn) |
|
110 public: |
|
111 QTrackerContactFetchRequest(QContactAbstractRequest* req, QContactManagerEngine* parent); |
|
112 public slots: |
|
113 void contactsReady(); |
|
114 void phoneNumbersReady(); |
|
115 void emailAddressesReady(); |
|
116 void iMAcountsReady(); |
|
117 |
|
118 protected slots: |
|
119 virtual void run(); |
|
120 virtual void emitFinished(QContactManager::Error error = QContactManager::NoError); |
|
121 |
|
122 protected: |
|
123 QContactManager::Error applyFilterToContact(SopranoLive::RDFVariable &variable, const QContactFilter &filter); |
|
124 QContactManager::Error applyDetailRangeFilterToContact(SopranoLive::RDFVariable &variable, const QContactFilter &filter); |
|
125 |
|
126 // contacts query |
|
127 SopranoLive::LiveNodes query; |
|
128 |
|
129 QList<SopranoLive::LiveNodes> queryPhoneNumbersNodes; // 2 - one for affiliations and another one for PersonContact |
|
130 int queryPhoneNumbersNodesPending; |
|
131 QList<SopranoLive::LiveNodes> queryEmailAddressNodes; // 2 - one for affiliations and another one for PersonContact |
|
132 int queryEmailAddressNodesPending; |
|
133 SopranoLive::LiveNodes queryIMAccountNodes; |
|
134 int queryIMAccountNodesPending; |
|
135 |
|
136 // result of the request - multiple queries updating it |
|
137 QList<QContact> result; |
|
138 |
|
139 private: |
|
140 bool isMeContact(const QContactFilter &filter); |
|
141 // fills received phone number from tracker to list of contacts to QContactPhoneMumber details |
|
142 // all the following methods update \sa result |
|
143 void processQueryPhoneNumbers(SopranoLive::LiveNodes queryPhoneNumbers, bool affiliationNumbers); |
|
144 void processQueryEmailAddresses(SopranoLive::LiveNodes queryEmailAddresses, bool affiliationEmails); |
|
145 void processQueryIMContacts(SopranoLive::LiveNodes queryIMContacts); |
|
146 void validateRequest(); |
|
147 void readFromQueryRowToContact(QContact &contact, int queryRow); |
|
148 QContact &linkContactsWithSameMetaContact(QContact &first, QContact &second); |
|
149 void addContactToResultSet(QContact &contact, const QString &metacontact); |
|
150 QContactOnlineAccount getOnlineAccountFromIMQuery(SopranoLive::LiveNodes imAccountQuery, int queryRow); |
|
151 QContactOnlineAccount getIMAccountFromIMQuery(SopranoLive::LiveNodes imAccountQuery, int queryRow) ; |
|
152 QContactOnlineAccount getIMContactFromIMQuery(SopranoLive::LiveNodes imAccountQuery, int queryRow); |
|
153 |
|
154 // access existing contacts in result list, contactid to index in \sa result lookup |
|
155 QHash<quint32, int> id2ContactLookup; |
|
156 // metacontact to index in \sa result lookup - index of metacontact contact: only 1 contact returned when multiple have the same metacontact |
|
157 QHash<QString, int> metacontactLookup; |
|
158 }; |
|
159 |
|
160 #endif /* QTRACKERCONTACTASYNCREQUEST_H_ */ |
64 #endif /* QTRACKERCONTACTASYNCREQUEST_H_ */ |