1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34#include "qdeclarativecontact_p.h"
35
36#include <QtCore/qurl.h>
37
38#include <QtQml/qqmlengine.h>
39
40#include <QtContacts/qcontactdetails.h>
41#include <QtContacts/qcontactmanager.h>
42
43#include "qdeclarativecontactmodel_p.h"
44
45QTCONTACTS_USE_NAMESPACE
46
47QT_BEGIN_NAMESPACE
48
49/*!
50 \qmltype Contact
51 \instantiates QDeclarativeContact
52 \brief The Contact element represents an addressbook contact.
53 \ingroup qml-contacts-main
54 \inqmlmodule QtContacts
55
56 The Contact element is part of the \b{QtContacts} module.
57
58 A Contact object has a collection of details (like a name, phone numbers and
59 email addresses). Each detail (which can have multiple fields) is stored
60 in an appropriate subclass of ContactDetail, and the Contact allows
61 retrieving these details in various ways.
62
63 If some of the contact details are not unique details, all of this type of detail values
64 can be accessed by the property with the name in plural. For example, if there are 3 phone numbers stored in
65 a contact, they can be accessed by contact.phoneNumbers property, which holds a list of
66 all PhoneNumber details. If a contact does not contain a detail of particular type,
67 the value of the corresponding singular property (e.g. phoneNumber) in undefined and the
68 plural (e.g. phoneNumbers) is empty. The list of properties which support multiple detail
69 instances depends on the contact engine implementations.
70
71 \sa QContact
72*/
73
74// call-back function templates for list properties
75template <typename T, QDeclarativeContactDetail::DetailType detailType>
76static void list_property_append(QQmlListProperty<T> *, T *)
77{
78}
79
80template <typename T, QDeclarativeContactDetail::DetailType detailType>
81static int list_property_count(QQmlListProperty<T> *property)
82{
83 QDeclarativeContact *object = qobject_cast<QDeclarativeContact *>(property->object);
84 if (object)
85 return object->details(type: detailType).size();
86 else
87 return 0;
88}
89
90template <typename T, QDeclarativeContactDetail::DetailType detailType>
91static T *list_property_at(QQmlListProperty<T> *property, int index)
92{
93 QDeclarativeContact *object = qobject_cast<QDeclarativeContact *>(property->object);
94 if (object)
95 return qobject_cast<T *>(qvariant_cast<QObject*>(v: object->details(type: detailType).at(i: index)));
96 else
97 return 0;
98}
99
100template <typename T, QDeclarativeContactDetail::DetailType detailType>
101static void list_property_clear(QQmlListProperty<T> *)
102{
103}
104
105QDeclarativeContact::QDeclarativeContact(QObject *parent)
106 :QObject(parent)
107 , m_modified(false)
108{
109 connect(asender: this, SIGNAL(contactChanged()), SLOT(setModified()));
110}
111
112QDeclarativeContact::~QDeclarativeContact()
113{
114 clearDetails();
115}
116
117void QDeclarativeContact::setContact(const QContact& contact)
118{
119 m_id = contact.id();
120 m_collectionId = contact.collectionId();
121 foreach (QDeclarativeContactDetail *detail, m_details)
122 delete detail;
123 m_details.clear();
124 m_preferredDetails.clear();
125
126 QList<QContactDetail> details(contact.details());
127 foreach (const QContactDetail &detail, details) {
128 QDeclarativeContactDetail *contactDetail = QDeclarativeContactDetailFactory::createContactDetail(type: static_cast<QDeclarativeContactDetail::DetailType>(detail.type()));
129 contactDetail->setParent(this);
130 contactDetail->setDetail(detail);
131 connect(sender: contactDetail, SIGNAL(detailChanged()), receiver: this, SIGNAL(contactChanged()));
132 m_details.append(t: contactDetail);
133 }
134
135 QMap<QString, QContactDetail> prefDetails(contact.preferredDetails());
136 QMap<QString, QContactDetail>::const_iterator it = prefDetails.begin();
137 while (it != prefDetails.end()) {
138 m_preferredDetails.insert(akey: it.key(), avalue: it.value().key());
139 it++;
140 }
141
142 m_modified = false;
143 emit contactChanged();
144}
145
146QContact QDeclarativeContact::contact() const
147{
148 QContact contact;
149 contact.setId(m_id);
150 contact.setCollectionId(m_collectionId);
151 foreach (QDeclarativeContactDetail *detail, m_details)
152 contact.saveDetail(detail: &detail->detail());
153
154 QVariantMap prefDetails = preferredDetails();
155 QVariantMap::const_iterator it = prefDetails.begin();
156 while (it != prefDetails.end()) {
157 contact.setPreferredDetail(actionName: it.key(), preferredDetail: it.value().value<QDeclarativeContactDetail *>()->detail());
158 it++;
159 }
160 return contact;
161}
162
163/*!
164 \qmlproperty bool Contact::modified
165
166 This property holds the dirty flag of the Contact object.
167 If the Contact has been changed, returns true, otherwise returns false.
168*/
169bool QDeclarativeContact::modified() const
170{
171 return m_modified;
172}
173
174void QDeclarativeContact::setModified()
175{
176 m_modified = true;
177}
178
179/*!
180 \qmlproperty enumeration Contact::type
181
182 This property holds type of the Contact, the value can be one of:
183
184 \list
185 \li Contact.Contact
186 \li Contact.Group
187 \li Contact.Facet
188 \endlist
189*/
190QDeclarativeContactType::ContactType QDeclarativeContact::type() const
191{
192 foreach (QDeclarativeContactDetail *detail, m_details) {
193 if (QDeclarativeContactDetail::Type == detail->detailType())
194 return static_cast<QDeclarativeContactType *>(detail)->type();
195 }
196 return QDeclarativeContactType::Contact;
197}
198
199/*!
200 \qmlmethod Contact::removeDetail(detail)
201
202 Removes the given contact \a detail from the contact, returns true if successful, otherwise returns false.
203*/
204
205bool QDeclarativeContact::removeDetail(QDeclarativeContactDetail* detail)
206{
207 if (detail) {
208 if (!detail->removable())
209 return false;
210 int key = detail->detail().key();
211 int i = 0;
212 foreach (QDeclarativeContactDetail *contactDetail, m_details) {
213 if (key == contactDetail->detail().key()) {
214 removePreferredDetail(detail);
215 delete contactDetail;
216 m_details.removeAt(i);
217 emit contactChanged();
218 return true;
219 }
220 ++i;
221 }
222 }
223 return false;
224}
225
226void QDeclarativeContact::removePreferredDetail(QDeclarativeContactDetail* detail)
227{
228 QMap<QString, int> cpy = m_preferredDetails;
229 QMap<QString, int>::const_iterator it = cpy.begin();
230 while (it != cpy.end()) {
231 if (it.value() == detail->detail().key()) {
232 m_preferredDetails.remove(akey: it.key());
233 break;
234 }
235 it++;
236 }
237}
238
239/*!
240 \qmlmethod Contact::addDetail(detail)
241
242 Adds the given contact \a detail to the contact, returns true if successful, otherwise returns false.
243
244 Note: If the \a detail has been added into the same contact before, this operation will be ignored,
245 so if you want to add a \a detail multiple times, the \a detail should be copied before calling this function.
246*/
247bool QDeclarativeContact::addDetail(QDeclarativeContactDetail* detail)
248{
249 if (!detail || m_details.contains(t: detail))
250 return false;
251
252 QDeclarativeContactDetail *contactDetail = QDeclarativeContactDetailFactory::createContactDetail(type: detail->detailType());
253 contactDetail->setParent(this);
254 contactDetail->setDetail(detail->detail());
255 connect(sender: contactDetail, SIGNAL(detailChanged()), receiver: this, SIGNAL(contactChanged()));
256 m_details.append(t: contactDetail);
257
258 m_modified = true;
259 emit contactChanged();
260 return true;
261}
262
263/*!
264 \qmlmethod Contact::setPreferredDetail(actionName, detail)
265
266 Set a particular detail (\a preferredDetail) as the preferred detail for any actions with the given \a actionName.
267
268 The \a preferredDetail object must exist in this object, and the \a actionName cannot be empty.
269
270 Returns true if the preference could be recorded, and false otherwise.
271
272 \sa preferredDetail()
273 */
274bool QDeclarativeContact::setPreferredDetail(const QString& actionName, QDeclarativeContactDetail* detail)
275{
276 if (actionName.isEmpty() || !detail || !m_details.contains(t: detail))
277 return false;
278
279 if (m_preferredDetails.contains(akey: actionName) && m_preferredDetails[actionName] == detail->detail().key())
280 return false;
281
282 m_preferredDetails.insert(akey: actionName, avalue: detail->detail().key());
283 m_modified = true;
284 emit contactChanged();
285 return true;
286}
287
288/*!
289 \qmlmethod Contact::isPreferredDetail(actionName, detail)
290
291 Returns true if the given \a detail is a preferred detail for the given \a actionName,
292 or for any action if the \a actionName is empty.
293
294 \sa preferredDetail()
295 */
296bool QDeclarativeContact::isPreferredDetail(const QString& actionName, QDeclarativeContactDetail* detail) const
297{
298 if (actionName.isEmpty() || !detail || !m_details.contains(t: detail))
299 return false;
300
301 if (!m_preferredDetails.contains(akey: actionName))
302 return false;
303
304 return (m_preferredDetails[actionName] == detail->detail().key());
305}
306
307/*!
308 \qmlmethod Contact::preferredDetail(actionName, detail)
309
310 Returns the preferred detail for a given \a actionName.
311
312 If the \a actionName is empty, or there is no preference recorded for
313 the supplied \a actionName, returns null.
314
315 \sa preferredDetails()
316 */
317QDeclarativeContactDetail* QDeclarativeContact::preferredDetail(const QString& actionName) const
318{
319 int id = m_preferredDetails.value(akey: actionName, adefaultValue: -1);
320 if (id == -1)
321 return 0;
322
323 foreach (QDeclarativeContactDetail* detail, m_details) {
324 if (detail->detail().key() == id)
325 return detail;
326 }
327 return 0;
328}
329
330
331/*!
332 \qmlproperty map<string, ContactDetail> Contact::preferredDetails
333
334 This property holds the recorded detail preferences for action names.
335
336 Each entry in the map has the action name as the key, and the corresponding
337 preferred detail as the value.
338 */
339QVariantMap QDeclarativeContact::preferredDetails() const
340{
341 QVariantMap result;
342 QMap<QString, int>::const_iterator it = m_preferredDetails.begin();
343 while (it != m_preferredDetails.end()) {
344 result.insert(akey: it.key(), avalue: QVariant::fromValue<QDeclarativeContactDetail*>(value: preferredDetail(actionName: it.key())));
345 it++;
346 }
347 return result;
348}
349
350/*!
351 \qmlproperty string OContact::collectionId
352
353 This property holds the id of collection where the contact belongs to.
354*/
355QString QDeclarativeContact::collectionId() const
356{
357 return m_collectionId.toString();
358}
359
360void QDeclarativeContact::setCollectionId(const QString &collectionId)
361{
362 QContactCollectionId newCollectionId(QContactCollectionId::fromString(idString: collectionId));
363
364 // in case invalid collectionId-string, fromString() will return default collectionId-string
365 // instead of the intended collectionId-string
366 if (newCollectionId.toString() == collectionId && m_collectionId.toString() != collectionId) {
367 m_collectionId = newCollectionId;
368 m_modified = true;
369 emit contactChanged();
370 }
371}
372
373/*!
374 \qmlproperty list<ContactDetail> Contact::contactDetails
375
376 This property holds the list of all the details that the contact has.
377*/
378QQmlListProperty<QDeclarativeContactDetail> QDeclarativeContact::contactDetails()
379{
380 return QQmlListProperty<QDeclarativeContactDetail>(this, 0,
381 &QDeclarativeContact::_q_detail_append,
382 &QDeclarativeContact::_q_detail_count,
383 &QDeclarativeContact::_q_detail_at,
384 &QDeclarativeContact::_q_detail_clear);
385}
386
387/*!
388 \qmlproperty int Contact::contactId
389
390 This property holds the id of the Contact object.
391 This property is read only.
392*/
393QString QDeclarativeContact::contactId() const
394{
395 return m_id.toString();
396}
397
398/*!
399 \qmlproperty string Contact::manager
400
401 This property holds the manager name which the Contact object comes from.
402*/
403QString QDeclarativeContact::manager() const
404{
405 return m_id.managerUri();
406}
407
408/*!
409 \qmlmethod QDeclarativeContactDetail* QDeclarativeContact::detail(int type)
410
411 Returns contactDetail object which detail name or detail type is \a name.
412*/
413QDeclarativeContactDetail* QDeclarativeContact::detail(int type)
414{
415 foreach (QDeclarativeContactDetail *detail, m_details) {
416 if (type == detail->detailType()) {
417 return detail;
418 }
419 }
420 return 0;
421}
422
423/*!
424 \qmlmethod QVariantList QDeclarativeContact::details(int type)
425
426 Returns a list of ContactDetail objects which detail name or detail type is \a name.
427*/
428QVariantList QDeclarativeContact::details(int type)
429{
430 QVariantList list;
431 foreach (QDeclarativeContactDetail *detail, m_details) {
432 if (type == detail->detailType()) {
433 list.append(t: QVariant::fromValue(value: (QObject*)detail));
434 }
435 }
436 return list;
437}
438
439/*!
440 \qmlmethod Contact::clearDetails()
441
442 Remove all detail objects in this contact.
443*/
444void QDeclarativeContact::clearDetails()
445{
446 if (m_details.isEmpty())
447 return;
448
449 foreach (QDeclarativeContactDetail *detail, m_details)
450 delete detail;
451 m_details.clear();
452 m_modified = true;
453 emit contactChanged();
454}
455
456
457/*!
458 \qmlmethod Contact::save()
459
460 Saves this Contact if the contact has been modified.
461
462 \sa Contact::modified
463*/
464void QDeclarativeContact::save()
465{
466 if (modified()) {
467 QDeclarativeContactModel* model = qobject_cast<QDeclarativeContactModel*>(object: parent());
468 if (model) {
469 model->saveContact(dc: this);
470 m_modified = false;
471 }
472 }
473}
474
475// convenient access to most frequently used details
476/*!
477 \qmlproperty Address Contact::address
478
479 This property holds the address detail of the Contact object. In case a contact has several addresses then
480 the first one is returned.
481*/
482QDeclarativeContactAddress* QDeclarativeContact::address()
483{
484 return getDetail<QDeclarativeContactAddress>(type: QDeclarativeContactDetail::Address);
485}
486
487/*!
488 \qmlproperty list<Address> Contact::addresses
489
490 This property holds the address details of the Contact object.
491*/
492QQmlListProperty<QDeclarativeContactAddress> QDeclarativeContact::addresses()
493{
494 return QQmlListProperty<QDeclarativeContactAddress>(
495 this,
496 0,
497 &list_property_append<QDeclarativeContactAddress, QDeclarativeContactDetail::Address>,
498 &list_property_count<QDeclarativeContactAddress, QDeclarativeContactDetail::Address>,
499 &list_property_at<QDeclarativeContactAddress, QDeclarativeContactDetail::Address>,
500 &list_property_clear<QDeclarativeContactAddress, QDeclarativeContactDetail::Address>);
501}
502
503/*!
504 \qmlproperty Anniversary Contact::anniversary
505
506 This property holds the anniversary detail of the Contact object.
507*/
508QDeclarativeContactAnniversary* QDeclarativeContact::anniversary()
509{
510 return getDetail<QDeclarativeContactAnniversary>(type: QDeclarativeContactDetail::Anniversary);
511}
512
513/*!
514 \qmlproperty Avatar Contact::avatar
515
516 This property holds the avatar detail of the Contact object.
517*/
518QDeclarativeContactAvatar* QDeclarativeContact::avatar()
519{
520 return getDetail<QDeclarativeContactAvatar>(type: QDeclarativeContactDetail::Avatar);
521}
522
523/*!
524 \qmlproperty Birthday Contact::birthday
525
526 This property holds the birthday detail of the Contact object.
527*/
528QDeclarativeContactBirthday* QDeclarativeContact::birthday()
529{
530 return getDetail<QDeclarativeContactBirthday>(type: QDeclarativeContactDetail::Birthday);
531}
532
533/*!
534 \qmlproperty DisplayLabel Contact::displayLabel
535
536 This property holds the displayLabel detail of the Contact object.
537 display label is the one which gets displayed when a contact is created as per versit doc specs this is a "FN" property
538*/
539QDeclarativeContactDisplayLabel* QDeclarativeContact::displayLabel()
540{
541 return getDetail<QDeclarativeContactDisplayLabel>(type: QDeclarativeContactDetail::DisplayLabel);
542}
543
544/*!
545 \qmlproperty EmailAddress Contact::email
546
547 This property holds the email address detail of the Contact object. In case a contact has several email addresses then
548 the first one is returned.
549*/
550QDeclarativeContactEmailAddress* QDeclarativeContact::email()
551{
552 return getDetail<QDeclarativeContactEmailAddress>(type: QDeclarativeContactDetail::Email);
553}
554
555/*!
556 \qmlproperty list<EmailAddress> Contact::emails
557
558 This property holds the email address details of the Contact object.
559*/
560QQmlListProperty<QDeclarativeContactEmailAddress> QDeclarativeContact::emails()
561{
562 return QQmlListProperty<QDeclarativeContactEmailAddress>(
563 this,
564 0,
565 &list_property_append<QDeclarativeContactEmailAddress, QDeclarativeContactDetail::Email>,
566 &list_property_count<QDeclarativeContactEmailAddress, QDeclarativeContactDetail::Email>,
567 &list_property_at<QDeclarativeContactEmailAddress, QDeclarativeContactDetail::Email>,
568 &list_property_clear<QDeclarativeContactEmailAddress, QDeclarativeContactDetail::Email>);
569}
570
571/*!
572 \qmlproperty ExtendedDetail Contact::extendedDetail
573
574 This property holds the extended detail of the Contact object. In case a contact has several extended
575 details then the first one is returned.
576*/
577QDeclarativeContactExtendedDetail* QDeclarativeContact::extendedDetail()
578{
579 return getDetail<QDeclarativeContactExtendedDetail>(type: QDeclarativeContactDetail::ExtendedDetail);
580}
581
582/*!
583 \qmlproperty list<ExtendedDetail> Contact::extendedDetails
584
585 This property holds the extended details of the Contact object.
586*/
587QQmlListProperty<QDeclarativeContactExtendedDetail> QDeclarativeContact::extendedDetails()
588{
589 return QQmlListProperty<QDeclarativeContactExtendedDetail>(
590 this,
591 0,
592 &list_property_append<QDeclarativeContactExtendedDetail, QDeclarativeContactDetail::ExtendedDetail>,
593 &list_property_count<QDeclarativeContactExtendedDetail, QDeclarativeContactDetail::ExtendedDetail>,
594 &list_property_at<QDeclarativeContactExtendedDetail, QDeclarativeContactDetail::ExtendedDetail>,
595 &list_property_clear<QDeclarativeContactExtendedDetail, QDeclarativeContactDetail::ExtendedDetail>);
596}
597
598/*!
599 \qmlproperty Family Contact::family
600
601 This property holds the family detail of the Contact object.
602*/
603QDeclarativeContactFamily* QDeclarativeContact::family()
604{
605 return getDetail<QDeclarativeContactFamily>(type: QDeclarativeContactDetail::Family);
606}
607
608/*!
609 \qmlproperty Favorite Contact::favorite
610
611 This property holds the favorite detail of the Contact object.
612*/
613QDeclarativeContactFavorite* QDeclarativeContact::favorite()
614{
615 return getDetail<QDeclarativeContactFavorite>(type: QDeclarativeContactDetail::Favorite);
616}
617
618/*!
619 \qmlproperty Gender Contact::gender
620
621 This property holds the gender detail of the Contact object.
622*/
623QDeclarativeContactGender* QDeclarativeContact::gender()
624{
625 return getDetail<QDeclarativeContactGender>(type: QDeclarativeContactDetail::Gender);
626}
627
628/*!
629 \qmlproperty GeoLocation Contact::geolocation
630
631 This property holds the geolocation detail of the Contact object.
632*/
633QDeclarativeContactGeoLocation* QDeclarativeContact::geolocation()
634{
635 return getDetail<QDeclarativeContactGeoLocation>(type: QDeclarativeContactDetail::Geolocation);
636}
637
638/*!
639 \qmlproperty GlobalPresence Contact::globalPresence
640
641 This property holds the globalPresence detail of the Contact object.
642*/
643QDeclarativeContactGlobalPresence* QDeclarativeContact::globalPresence()
644{
645 return getDetail<QDeclarativeContactGlobalPresence>(type: QDeclarativeContactDetail::GlobalPresence);
646}
647
648/*!
649 \qmlproperty Guid Contact::guid
650
651 This property holds the guid detail of the Contact object.
652*/
653QDeclarativeContactGuid* QDeclarativeContact::guid()
654{
655 return getDetail<QDeclarativeContactGuid>(type: QDeclarativeContactDetail::Guid);
656}
657
658/*!
659 \qmlproperty Hobby Contact::hobby
660
661 This property holds the hobby detail of the Contact object.
662*/
663QDeclarativeContactHobby* QDeclarativeContact::hobby()
664{
665 return getDetail<QDeclarativeContactHobby>(type: QDeclarativeContactDetail::Hobby);
666}
667
668/*!
669 \qmlproperty Name Contact::name
670
671 This property holds the name detail of the Contact object.
672*/
673QDeclarativeContactName* QDeclarativeContact::name()
674{
675 return getDetail<QDeclarativeContactName>(type: QDeclarativeContactDetail::Name);
676}
677
678/*!
679 \qmlproperty Nickname Contact::nickname
680
681 This property holds the nickname detail of the Contact object.
682*/
683QDeclarativeContactNickname* QDeclarativeContact::nickname()
684{
685 return getDetail<QDeclarativeContactNickname>(type: QDeclarativeContactDetail::NickName);
686}
687
688/*!
689 \qmlproperty Note Contact::note
690
691 This property holds the note detail of the Contact object.
692*/
693QDeclarativeContactNote* QDeclarativeContact::note()
694{
695 return getDetail<QDeclarativeContactNote>(type: QDeclarativeContactDetail::Note);
696}
697
698/*!
699 \qmlproperty OnlineAccount Contact::onlineAccount
700
701 This property holds the onlineAccount detail of the Contact object. In case a contact has several accounts then
702 the first one is returned.
703*/
704QDeclarativeContactOnlineAccount* QDeclarativeContact::onlineAccount()
705{
706 return getDetail<QDeclarativeContactOnlineAccount>(type: QDeclarativeContactDetail::OnlineAccount);
707}
708
709/*!
710 \qmlproperty Organization Contact::organization
711
712 This property holds the organization detail of the Contact object.
713*/
714QDeclarativeContactOrganization* QDeclarativeContact::organization()
715{
716 return getDetail<QDeclarativeContactOrganization>(type: QDeclarativeContactDetail::Organization);
717}
718
719/*!
720 \qmlproperty list<Organization> Contact::organizations
721
722 This property holds the organization details of the Contact object.
723*/
724QQmlListProperty<QDeclarativeContactOrganization> QDeclarativeContact::organizations()
725{
726 return QQmlListProperty<QDeclarativeContactOrganization>(
727 this,
728 0,
729 &list_property_append<QDeclarativeContactOrganization, QDeclarativeContactDetail::Organization>,
730 &list_property_count<QDeclarativeContactOrganization, QDeclarativeContactDetail::Organization>,
731 &list_property_at<QDeclarativeContactOrganization, QDeclarativeContactDetail::Organization>,
732 &list_property_clear<QDeclarativeContactOrganization, QDeclarativeContactDetail::Organization>);
733}
734
735/*!
736 \qmlproperty PhoneNumber Contact::phoneNumber
737
738 This property holds the phone number detail of the Contact object. In case a contact has several numbers then
739 the first one is returned.
740*/
741QDeclarativeContactPhoneNumber* QDeclarativeContact::phoneNumber()
742{
743 return getDetail<QDeclarativeContactPhoneNumber>(type: QDeclarativeContactDetail::PhoneNumber);
744}
745
746/*!
747 \qmlproperty list<PhoneNumber> Contact::phoneNumbers
748
749 This property holds the phone number details of the Contact object.
750*/
751QQmlListProperty<QDeclarativeContactPhoneNumber> QDeclarativeContact::phoneNumbers()
752{
753 return QQmlListProperty<QDeclarativeContactPhoneNumber>(
754 this,
755 0,
756 &list_property_append<QDeclarativeContactPhoneNumber, QDeclarativeContactDetail::PhoneNumber>,
757 &list_property_count<QDeclarativeContactPhoneNumber, QDeclarativeContactDetail::PhoneNumber>,
758 &list_property_at<QDeclarativeContactPhoneNumber, QDeclarativeContactDetail::PhoneNumber>,
759 &list_property_clear<QDeclarativeContactPhoneNumber, QDeclarativeContactDetail::PhoneNumber>);
760}
761
762/*!
763 \qmlproperty Presence Contact::presence
764
765 This property holds the presence detail of the Contact object.
766*/
767QDeclarativeContactPresence* QDeclarativeContact::presence()
768{
769 return getDetail<QDeclarativeContactPresence>(type: QDeclarativeContactDetail::Presence);
770}
771
772/*!
773 \qmlproperty Ringtone Contact::ringtone
774
775 This property holds the ringtone detail of the Contact object.
776*/
777QDeclarativeContactRingtone* QDeclarativeContact::ringtone()
778{
779 return getDetail<QDeclarativeContactRingtone>(type: QDeclarativeContactDetail::Ringtone);
780}
781
782/*!
783 \qmlproperty SyncTarget Contact::syncTarget
784
785 This property holds the syncTarget detail of the Contact object.
786*/
787QDeclarativeContactSyncTarget* QDeclarativeContact::syncTarget()
788{
789 return getDetail<QDeclarativeContactSyncTarget>(type: QDeclarativeContactDetail::SyncTarget);
790}
791
792/*!
793 \qmlproperty Tag Contact::tag
794
795 This property holds the tag detail of the Contact object.
796*/
797QDeclarativeContactTag* QDeclarativeContact::tag()
798{
799 return getDetail<QDeclarativeContactTag>(type: QDeclarativeContactDetail::Tag);
800}
801
802/*!
803 \qmlproperty Timestamp Contact::timestamp
804
805 This property holds the timestamp detail of the Contact object.
806*/
807QDeclarativeContactTimestamp* QDeclarativeContact::timestamp()
808{
809 return getDetail<QDeclarativeContactTimestamp>(type: QDeclarativeContactDetail::Timestamp);
810}
811
812/*!
813 \qmlproperty Url Contact::url
814
815 This property holds the url detail of the Contact object.
816*/
817QDeclarativeContactUrl* QDeclarativeContact::url()
818{
819 return getDetail<QDeclarativeContactUrl>(type: QDeclarativeContactDetail::Url);
820}
821
822/*!
823 \qmlproperty list<Url> Contact::urls
824
825 This property holds the url details of the Contact object.
826*/
827QQmlListProperty<QDeclarativeContactUrl> QDeclarativeContact::urls()
828{
829 return QQmlListProperty<QDeclarativeContactUrl>(
830 this,
831 0,
832 &list_property_append<QDeclarativeContactUrl, QDeclarativeContactDetail::Url>,
833 &list_property_count<QDeclarativeContactUrl, QDeclarativeContactDetail::Url>,
834 &list_property_at<QDeclarativeContactUrl, QDeclarativeContactDetail::Url>,
835 &list_property_clear<QDeclarativeContactUrl, QDeclarativeContactDetail::Url>);
836}
837
838/*!
839 \qmlproperty Version Contact::version
840
841 This property holds the version detail of the Contact object.
842*/
843QDeclarativeContactVersion* QDeclarativeContact::version()
844{
845 return getDetail<QDeclarativeContactVersion>(type: QDeclarativeContactDetail::Version);
846}
847
848// call-back functions for list property
849
850/*!
851 \internal
852 */
853void QDeclarativeContact::_q_detail_append(QQmlListProperty<QDeclarativeContactDetail> *property, QDeclarativeContactDetail *value)
854{
855 QDeclarativeContact *object = qobject_cast<QDeclarativeContact *>(object: property->object);
856 if (object)
857 {
858 object->m_details.append(t: value);
859 value->connect(asender: value, SIGNAL(valueChanged()), SIGNAL(detailChanged()), atype: Qt::UniqueConnection);
860 value->connect(sender: value, SIGNAL(detailChanged()), receiver: object, SIGNAL(contactChanged()), Qt::UniqueConnection);
861 }
862}
863
864/*!
865 \internal
866 */
867QDeclarativeContactDetail *QDeclarativeContact::_q_detail_at(QQmlListProperty<QDeclarativeContactDetail> *property, int index)
868{
869 QDeclarativeContact *object = qobject_cast<QDeclarativeContact *>(object: property->object);
870 if (object)
871 return object->m_details.at(i: index);
872 else
873 return 0;
874}
875
876/*!
877 \internal
878 */
879void QDeclarativeContact::_q_detail_clear(QQmlListProperty<QDeclarativeContactDetail> *property)
880{
881 QDeclarativeContact *object = qobject_cast<QDeclarativeContact *>(object: property->object);
882 if (object) {
883 foreach (QDeclarativeContactDetail *obj, object->m_details)
884 delete obj;
885 object->m_details.clear();
886 }
887}
888
889/*!
890 \internal
891 */
892int QDeclarativeContact::_q_detail_count(QQmlListProperty<QDeclarativeContactDetail> *property)
893{
894 QDeclarativeContact *object = qobject_cast<QDeclarativeContact *>(object: property->object);
895 if (object)
896 return object->m_details.size();
897 else
898 return 0;
899}
900
901#include "moc_qdeclarativecontact_p.cpp"
902
903QT_END_NAMESPACE
904

source code of qtpim/src/imports/contacts/qdeclarativecontact.cpp