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 | #ifndef QDECLARATIVECONTACT_P_H |
35 | #define QDECLARATIVECONTACT_P_H |
36 | |
37 | #include <QtQml/qqml.h> |
38 | |
39 | #include <QtContacts/qcontact.h> |
40 | #include <QtContacts/qcontactid.h> |
41 | #include <QtContacts/qcontactcollectionid.h> |
42 | |
43 | #include "qdeclarativecontactdetails_p.h" |
44 | |
45 | QTCONTACTS_USE_NAMESPACE |
46 | |
47 | QT_BEGIN_NAMESPACE |
48 | |
49 | class QDeclarativeContact : public QObject |
50 | { |
51 | Q_OBJECT |
52 | |
53 | // basic information |
54 | Q_PROPERTY (bool modified READ modified) |
55 | |
56 | Q_PROPERTY (QDeclarativeContactType::ContactType type READ type NOTIFY contactChanged) |
57 | Q_PROPERTY (QString contactId READ contactId NOTIFY contactIdChanged) |
58 | Q_PROPERTY (QString manager READ manager NOTIFY managerChanged) |
59 | Q_PROPERTY (QQmlListProperty<QDeclarativeContactDetail> contactDetails READ contactDetails NOTIFY contactChanged) |
60 | Q_PROPERTY (QDeclarativeContactAddress* address READ address NOTIFY contactChanged) |
61 | Q_PROPERTY (QQmlListProperty<QDeclarativeContactAddress> addresses READ addresses NOTIFY contactChanged) |
62 | Q_PROPERTY (QDeclarativeContactAnniversary* anniversary READ anniversary NOTIFY contactChanged) |
63 | Q_PROPERTY (QDeclarativeContactAvatar* avatar READ avatar NOTIFY contactChanged) |
64 | Q_PROPERTY (QDeclarativeContactBirthday* birthday READ birthday NOTIFY contactChanged) |
65 | Q_PROPERTY (QDeclarativeContactDisplayLabel* displayLabel READ displayLabel NOTIFY contactChanged) |
66 | Q_PROPERTY (QDeclarativeContactEmailAddress* email READ email NOTIFY contactChanged) |
67 | Q_PROPERTY (QQmlListProperty<QDeclarativeContactEmailAddress> emails READ emails NOTIFY contactChanged) |
68 | Q_PROPERTY (QDeclarativeContactExtendedDetail* extendedDetail READ extendedDetail NOTIFY contactChanged) |
69 | Q_PROPERTY (QQmlListProperty<QDeclarativeContactExtendedDetail> extendedDetails READ extendedDetails NOTIFY contactChanged) |
70 | Q_PROPERTY (QDeclarativeContactFamily* family READ family NOTIFY contactChanged) |
71 | Q_PROPERTY (QDeclarativeContactFavorite* favorite READ favorite NOTIFY contactChanged) |
72 | Q_PROPERTY (QDeclarativeContactGender* gender READ gender NOTIFY contactChanged) |
73 | Q_PROPERTY (QDeclarativeContactGeoLocation* geolocation READ geolocation NOTIFY contactChanged) |
74 | Q_PROPERTY (QDeclarativeContactGlobalPresence* globalPresence READ globalPresence NOTIFY contactChanged) |
75 | Q_PROPERTY (QDeclarativeContactGuid* guid READ guid NOTIFY contactChanged) |
76 | Q_PROPERTY (QDeclarativeContactHobby* hobby READ hobby NOTIFY contactChanged) |
77 | Q_PROPERTY (QDeclarativeContactName* name READ name NOTIFY contactChanged) |
78 | Q_PROPERTY (QDeclarativeContactNickname* nickname READ nickname NOTIFY contactChanged) |
79 | Q_PROPERTY (QDeclarativeContactNote* note READ note NOTIFY contactChanged) |
80 | Q_PROPERTY (QDeclarativeContactOnlineAccount* onlineAccount READ onlineAccount NOTIFY contactChanged) |
81 | Q_PROPERTY (QDeclarativeContactOrganization* organization READ organization NOTIFY contactChanged) |
82 | Q_PROPERTY (QQmlListProperty<QDeclarativeContactOrganization> organizations READ organizations NOTIFY contactChanged) |
83 | Q_PROPERTY (QDeclarativeContactPhoneNumber* phoneNumber READ phoneNumber NOTIFY contactChanged) |
84 | Q_PROPERTY (QQmlListProperty<QDeclarativeContactPhoneNumber> phoneNumbers READ phoneNumbers NOTIFY contactChanged) |
85 | Q_PROPERTY (QDeclarativeContactPresence* presence READ presence NOTIFY contactChanged) |
86 | Q_PROPERTY (QDeclarativeContactRingtone* ringtone READ ringtone NOTIFY contactChanged) |
87 | Q_PROPERTY (QDeclarativeContactSyncTarget* syncTarget READ syncTarget NOTIFY contactChanged) |
88 | Q_PROPERTY (QDeclarativeContactTag* tag READ tag NOTIFY contactChanged) |
89 | Q_PROPERTY (QDeclarativeContactTimestamp* timestamp READ timestamp NOTIFY contactChanged) |
90 | Q_PROPERTY (QDeclarativeContactUrl* url READ url NOTIFY contactChanged) |
91 | Q_PROPERTY (QQmlListProperty<QDeclarativeContactUrl> urls READ urls NOTIFY contactChanged) |
92 | Q_PROPERTY (QDeclarativeContactVersion* version READ version NOTIFY contactChanged) |
93 | Q_PROPERTY (QVariantMap preferredDetails READ preferredDetails NOTIFY contactChanged) |
94 | Q_PROPERTY (QString collectionId READ collectionId WRITE setCollectionId NOTIFY contactChanged) |
95 | Q_CLASSINFO("DefaultProperty" , "contactDetails" ) |
96 | |
97 | public: |
98 | |
99 | explicit QDeclarativeContact(QObject *parent = Q_NULLPTR); |
100 | ~QDeclarativeContact(); |
101 | |
102 | void setContact(const QContact& c); |
103 | QContact contact() const; |
104 | bool modified() const; |
105 | |
106 | QDeclarativeContactType::ContactType type() const; |
107 | |
108 | QString contactId() const; |
109 | QString manager() const; |
110 | QQmlListProperty<QDeclarativeContactDetail> contactDetails(); |
111 | |
112 | // use int instead of QDeclarativeContactDetail::ContactType as a work-around for QTBUG-20639 |
113 | Q_INVOKABLE QDeclarativeContactDetail* detail(int type); |
114 | Q_INVOKABLE QVariantList details(int type); |
115 | |
116 | Q_INVOKABLE bool removeDetail(QDeclarativeContactDetail* detail); |
117 | Q_INVOKABLE bool addDetail(QDeclarativeContactDetail* detail); |
118 | |
119 | Q_INVOKABLE bool setPreferredDetail(const QString& actionName, QDeclarativeContactDetail* detail); |
120 | Q_INVOKABLE bool isPreferredDetail(const QString& actionName, QDeclarativeContactDetail* detail) const; |
121 | Q_INVOKABLE QDeclarativeContactDetail* preferredDetail(const QString& actionName) const; |
122 | QVariantMap preferredDetails() const; |
123 | |
124 | QString collectionId() const; |
125 | void setCollectionId(const QString& collectionId); |
126 | |
127 | QDeclarativeContactAddress* address(); |
128 | QQmlListProperty<QDeclarativeContactAddress> addresses(); |
129 | QDeclarativeContactAnniversary* anniversary(); |
130 | QDeclarativeContactAvatar* avatar(); |
131 | QDeclarativeContactBirthday* birthday(); |
132 | QDeclarativeContactDisplayLabel* displayLabel(); |
133 | QDeclarativeContactEmailAddress* email(); |
134 | QQmlListProperty<QDeclarativeContactEmailAddress> emails(); |
135 | QDeclarativeContactExtendedDetail* extendedDetail(); |
136 | QQmlListProperty<QDeclarativeContactExtendedDetail> extendedDetails(); |
137 | QDeclarativeContactFamily* family(); |
138 | QDeclarativeContactFavorite* favorite(); |
139 | QDeclarativeContactGender* gender(); |
140 | QDeclarativeContactGeoLocation* geolocation(); |
141 | QDeclarativeContactGlobalPresence* globalPresence(); |
142 | QDeclarativeContactGuid* guid(); |
143 | QDeclarativeContactHobby* hobby(); |
144 | QDeclarativeContactName* name(); |
145 | QDeclarativeContactNickname* nickname(); |
146 | QDeclarativeContactNote* note(); |
147 | QDeclarativeContactOnlineAccount* onlineAccount(); |
148 | QDeclarativeContactOrganization* organization(); |
149 | QQmlListProperty<QDeclarativeContactOrganization> organizations(); |
150 | QDeclarativeContactPhoneNumber* phoneNumber(); |
151 | QQmlListProperty<QDeclarativeContactPhoneNumber> phoneNumbers(); |
152 | QDeclarativeContactPresence* presence(); |
153 | QDeclarativeContactRingtone* ringtone(); |
154 | QDeclarativeContactSyncTarget* syncTarget(); |
155 | QDeclarativeContactTag* tag(); |
156 | QDeclarativeContactTimestamp* timestamp(); |
157 | QDeclarativeContactUrl* url(); |
158 | QQmlListProperty<QDeclarativeContactUrl> urls(); |
159 | QDeclarativeContactVersion* version(); |
160 | |
161 | protected: |
162 | bool m_modified; |
163 | QContactId m_id; |
164 | QContactCollectionId m_collectionId; |
165 | |
166 | // always create a copy of the detail for QML |
167 | // however, seems the garbage collection can't delete all of them (QTBUG-20377) |
168 | QList<QDeclarativeContactDetail *> m_details; |
169 | QMap<QString, int> m_preferredDetails; |
170 | |
171 | public slots: |
172 | void clearDetails(); |
173 | void save(); |
174 | Q_SIGNALS: |
175 | void contactIdChanged(); |
176 | void managerChanged(); |
177 | void contactChanged(); |
178 | |
179 | private slots: |
180 | void setModified(); |
181 | |
182 | private: |
183 | Q_DISABLE_COPY(QDeclarativeContact) |
184 | |
185 | template<typename T> T* getDetail(const QDeclarativeContactDetail::DetailType &type) |
186 | { |
187 | foreach (QDeclarativeContactDetail *detail, m_details) { |
188 | if (type == detail->detailType()) |
189 | { |
190 | T* tempDetail = static_cast<T *>(detail); |
191 | return tempDetail; |
192 | } |
193 | } |
194 | T* detail = new T; |
195 | if (detail) { |
196 | m_details.append(detail); |
197 | emit contactChanged(); |
198 | return detail; |
199 | } |
200 | return 0; |
201 | } |
202 | |
203 | void removePreferredDetail(QDeclarativeContactDetail *detail); |
204 | |
205 | // call-back functions for list property |
206 | static void _q_detail_append(QQmlListProperty<QDeclarativeContactDetail> *property, QDeclarativeContactDetail *value); |
207 | static QDeclarativeContactDetail *_q_detail_at(QQmlListProperty<QDeclarativeContactDetail> *property, int index); |
208 | static void _q_detail_clear(QQmlListProperty<QDeclarativeContactDetail> *property); |
209 | static int _q_detail_count(QQmlListProperty<QDeclarativeContactDetail> *property); |
210 | }; |
211 | |
212 | QT_END_NAMESPACE |
213 | |
214 | QML_DECLARE_TYPE(QDeclarativeContact) |
215 | |
216 | #endif // QDECLARATIVECONTACT_P_H |
217 | |