95 } |
95 } |
96 |
96 |
97 /* Synthesise the display label of a contact */ |
97 /* Synthesise the display label of a contact */ |
98 QString QContactMaemo5Engine::synthesizedDisplayLabel(const QContact& contact, QContactManager::Error* error) const |
98 QString QContactMaemo5Engine::synthesizedDisplayLabel(const QContact& contact, QContactManager::Error* error) const |
99 { |
99 { |
100 Q_UNUSED(error) |
100 QString label; |
101 QString label = QContactManagerEngine::synthesizedDisplayLabel(contact, error); |
101 |
102 |
102 // Try to get the display name from the OSSO-ABook Contact |
103 if (label.isEmpty()) { |
103 label = d->m_abook->getDisplayName(contact); |
104 QContactNickname n = contact.detail(QContactNickname::DefinitionName); |
104 |
105 label = n.nickname(); |
105 // Synthesise the display label for not saved contacts |
106 } |
106 // A. FirstName + LastName |
107 |
107 if (label.isEmpty()){ |
108 if (label.isEmpty()) |
108 QContactName name = contact.detail(QContactName::DefinitionName); |
109 label = "No name"; |
109 QStringList nameList; |
110 |
110 |
|
111 nameList << name.firstName(); |
|
112 if (name.lastName().count()){ |
|
113 nameList << name.lastName(); |
|
114 } |
|
115 |
|
116 label = nameList.join(QString(' ')); |
|
117 } |
|
118 |
|
119 // B. Email |
|
120 if (label.isEmpty()){ |
|
121 QContactEmailAddress email = contact.detail(QContactEmailAddress::DefinitionName); |
|
122 label = email.emailAddress(); |
|
123 } |
|
124 |
|
125 // |
|
126 if (label.isEmpty()){ |
|
127 *error = QContactManager::UnspecifiedError; |
|
128 return QString("No name"); |
|
129 } |
|
130 |
|
131 *error = QContactManager::NoError; |
111 return label; |
132 return label; |
112 } |
133 } |
113 |
134 |
114 bool QContactMaemo5Engine::validateContact(const QContact& contact, QContactManager::Error* error) const |
135 bool QContactMaemo5Engine::validateContact(const QContact& contact, QContactManager::Error* error) const |
115 { |
136 { |
142 |
163 |
143 QList<QContactLocalId> QContactMaemo5Engine::contactIds(const QContactFilter& filter, const QList<QContactSortOrder>& sortOrders, QContactManager::Error* error) const |
164 QList<QContactLocalId> QContactMaemo5Engine::contactIds(const QContactFilter& filter, const QList<QContactSortOrder>& sortOrders, QContactManager::Error* error) const |
144 { |
165 { |
145 Q_CHECK_PTR(d->m_abook); |
166 Q_CHECK_PTR(d->m_abook); |
146 |
167 |
147 //return QContactManagerEngine::contactIds(filter, sortOrders, error); |
168 QList<QContactLocalId> rtn; |
148 return d->m_abook->contactIds(filter, sortOrders, error); |
169 |
|
170 // do this naively for now... |
|
171 QContactManager::Error tempError = QContactManager::NoError; |
|
172 QList<QContactLocalId> allIds = d->m_abook->contactIds(filter, sortOrders, error); |
|
173 QList<QContact> sortedAndFiltered; |
|
174 |
|
175 foreach (const QContactLocalId& currId, allIds) { |
|
176 QContact curr = contact(currId, QContactFetchHint(), &tempError); |
|
177 if (tempError != QContactManager::NoError) |
|
178 *error = tempError; |
|
179 if (QContactManagerEngine::testFilter(filter, curr)) { |
|
180 QContactManagerEngine::addSorted(&sortedAndFiltered, curr, sortOrders); |
|
181 } |
|
182 } |
|
183 |
|
184 foreach (const QContact& contact, sortedAndFiltered) { |
|
185 rtn.append(contact.localId()); |
|
186 } |
|
187 return rtn; |
149 } |
188 } |
150 |
189 |
151 QList<QContact> QContactMaemo5Engine::contacts(const QContactFilter & filter, const QList<QContactSortOrder> & sortOrders, const QContactFetchHint & fetchHint, |
190 QList<QContact> QContactMaemo5Engine::contacts(const QContactFilter & filter, const QList<QContactSortOrder> & sortOrders, const QContactFetchHint & fetchHint, |
152 QContactManager::Error* error ) const |
191 QContactManager::Error* error ) const |
153 { |
192 { |
164 QContact QContactMaemo5Engine::contact(const QContactLocalId& contactId, const QContactFetchHint& fetchHint, QContactManager::Error* error) const |
203 QContact QContactMaemo5Engine::contact(const QContactLocalId& contactId, const QContactFetchHint& fetchHint, QContactManager::Error* error) const |
165 { |
204 { |
166 Q_UNUSED(fetchHint); //TODO |
205 Q_UNUSED(fetchHint); //TODO |
167 Q_CHECK_PTR(d->m_abook); |
206 Q_CHECK_PTR(d->m_abook); |
168 |
207 |
|
208 //NOTE getQContact can't set the displayLabel |
169 QContact *contact = d->m_abook->getQContact(contactId, error); |
209 QContact *contact = d->m_abook->getQContact(contactId, error); |
170 QContact rtn(*contact); |
210 QContact rtn(*contact); |
171 delete contact; |
211 delete contact; |
172 if (*error == QContactManager::NoError) { |
212 if (*error == QContactManager::NoError) { |
173 setContactDisplayLabel(&rtn, synthesizedDisplayLabel(rtn, error)); |
213 setContactDisplayLabel(&rtn, synthesizedDisplayLabel(rtn, error)); |
336 fields.remove(QContactDetail::FieldContext); |
376 fields.remove(QContactDetail::FieldContext); |
337 fields.remove(QContactOrganization::FieldAssistantName); |
377 fields.remove(QContactOrganization::FieldAssistantName); |
338 fields.remove(QContactOrganization::FieldDepartment); |
378 fields.remove(QContactOrganization::FieldDepartment); |
339 fields.remove(QContactOrganization::FieldLocation); |
379 fields.remove(QContactOrganization::FieldLocation); |
340 fields.remove(QContactOrganization::FieldLogoUrl); |
380 fields.remove(QContactOrganization::FieldLogoUrl); |
341 fields.remove(QContactOrganization::FieldName); |
381 fields.remove(QContactOrganization::FieldTitle); |
342 fields.remove(QContactOrganization::FieldRole); |
382 fields.remove(QContactOrganization::FieldRole); |
343 defns[contactType][QContactOrganization::DefinitionName].setFields(fields); |
383 defns[contactType][QContactOrganization::DefinitionName].setFields(fields); |
344 |
384 |
345 // QContactPhoneNumber |
385 // QContactPhoneNumber |
346 fields = defns[contactType][QContactPhoneNumber::DefinitionName].fields(); |
386 fields = defns[contactType][QContactPhoneNumber::DefinitionName].fields(); |