1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQml module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QDECLARATIVECONTACT_P_H
#define QDECLARATIVECONTACT_P_H
#include <QtQml/qqml.h>
#include <QtContacts/qcontact.h>
#include <QtContacts/qcontactid.h>
#include <QtContacts/qcontactcollectionid.h>
#include "qdeclarativecontactdetails_p.h"
QTCONTACTS_USE_NAMESPACE
QT_BEGIN_NAMESPACE
class QDeclarativeContact : public QObject
{
Q_OBJECT
// basic information
Q_PROPERTY (bool modified READ modified)
Q_PROPERTY (QDeclarativeContactType::ContactType type READ type NOTIFY contactChanged)
Q_PROPERTY (QString contactId READ contactId NOTIFY contactIdChanged)
Q_PROPERTY (QString manager READ manager NOTIFY managerChanged)
Q_PROPERTY (QQmlListProperty<QDeclarativeContactDetail> contactDetails READ contactDetails NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactAddress* address READ address NOTIFY contactChanged)
Q_PROPERTY (QQmlListProperty<QDeclarativeContactAddress> addresses READ addresses NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactAnniversary* anniversary READ anniversary NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactAvatar* avatar READ avatar NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactBirthday* birthday READ birthday NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactDisplayLabel* displayLabel READ displayLabel NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactEmailAddress* email READ email NOTIFY contactChanged)
Q_PROPERTY (QQmlListProperty<QDeclarativeContactEmailAddress> emails READ emails NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactExtendedDetail* extendedDetail READ extendedDetail NOTIFY contactChanged)
Q_PROPERTY (QQmlListProperty<QDeclarativeContactExtendedDetail> extendedDetails READ extendedDetails NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactFamily* family READ family NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactFavorite* favorite READ favorite NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactGender* gender READ gender NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactGeoLocation* geolocation READ geolocation NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactGlobalPresence* globalPresence READ globalPresence NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactGuid* guid READ guid NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactHobby* hobby READ hobby NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactName* name READ name NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactNickname* nickname READ nickname NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactNote* note READ note NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactOnlineAccount* onlineAccount READ onlineAccount NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactOrganization* organization READ organization NOTIFY contactChanged)
Q_PROPERTY (QQmlListProperty<QDeclarativeContactOrganization> organizations READ organizations NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactPhoneNumber* phoneNumber READ phoneNumber NOTIFY contactChanged)
Q_PROPERTY (QQmlListProperty<QDeclarativeContactPhoneNumber> phoneNumbers READ phoneNumbers NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactPresence* presence READ presence NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactRingtone* ringtone READ ringtone NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactSyncTarget* syncTarget READ syncTarget NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactTag* tag READ tag NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactTimestamp* timestamp READ timestamp NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactUrl* url READ url NOTIFY contactChanged)
Q_PROPERTY (QQmlListProperty<QDeclarativeContactUrl> urls READ urls NOTIFY contactChanged)
Q_PROPERTY (QDeclarativeContactVersion* version READ version NOTIFY contactChanged)
Q_PROPERTY (QVariantMap preferredDetails READ preferredDetails NOTIFY contactChanged)
Q_PROPERTY (QString collectionId READ collectionId WRITE setCollectionId NOTIFY contactChanged)
Q_CLASSINFO("DefaultProperty", "contactDetails")
public:
explicit QDeclarativeContact(QObject *parent = nullptr);
~QDeclarativeContact();
void setContact(const QContact& c);
QContact contact() const;
bool modified() const;
QDeclarativeContactType::ContactType type() const;
QString contactId() const;
QString manager() const;
QQmlListProperty<QDeclarativeContactDetail> contactDetails();
// use int instead of QDeclarativeContactDetail::ContactType as a work-around for QTBUG-20639
Q_INVOKABLE QDeclarativeContactDetail* detail(int type);
Q_INVOKABLE QVariantList details(int type);
Q_INVOKABLE bool removeDetail(QDeclarativeContactDetail* detail);
Q_INVOKABLE bool addDetail(QDeclarativeContactDetail* detail);
Q_INVOKABLE bool setPreferredDetail(const QString& actionName, QDeclarativeContactDetail* detail);
Q_INVOKABLE bool isPreferredDetail(const QString& actionName, QDeclarativeContactDetail* detail) const;
Q_INVOKABLE QDeclarativeContactDetail* preferredDetail(const QString& actionName) const;
QVariantMap preferredDetails() const;
QString collectionId() const;
void setCollectionId(const QString& collectionId);
QDeclarativeContactAddress* address();
QQmlListProperty<QDeclarativeContactAddress> addresses();
QDeclarativeContactAnniversary* anniversary();
QDeclarativeContactAvatar* avatar();
QDeclarativeContactBirthday* birthday();
QDeclarativeContactDisplayLabel* displayLabel();
QDeclarativeContactEmailAddress* email();
QQmlListProperty<QDeclarativeContactEmailAddress> emails();
QDeclarativeContactExtendedDetail* extendedDetail();
QQmlListProperty<QDeclarativeContactExtendedDetail> extendedDetails();
QDeclarativeContactFamily* family();
QDeclarativeContactFavorite* favorite();
QDeclarativeContactGender* gender();
QDeclarativeContactGeoLocation* geolocation();
QDeclarativeContactGlobalPresence* globalPresence();
QDeclarativeContactGuid* guid();
QDeclarativeContactHobby* hobby();
QDeclarativeContactName* name();
QDeclarativeContactNickname* nickname();
QDeclarativeContactNote* note();
QDeclarativeContactOnlineAccount* onlineAccount();
QDeclarativeContactOrganization* organization();
QQmlListProperty<QDeclarativeContactOrganization> organizations();
QDeclarativeContactPhoneNumber* phoneNumber();
QQmlListProperty<QDeclarativeContactPhoneNumber> phoneNumbers();
QDeclarativeContactPresence* presence();
QDeclarativeContactRingtone* ringtone();
QDeclarativeContactSyncTarget* syncTarget();
QDeclarativeContactTag* tag();
QDeclarativeContactTimestamp* timestamp();
QDeclarativeContactUrl* url();
QQmlListProperty<QDeclarativeContactUrl> urls();
QDeclarativeContactVersion* version();
protected:
bool m_modified;
QContactId m_id;
QContactCollectionId m_collectionId;
// always create a copy of the detail for QML
// however, seems the garbage collection can't delete all of them (QTBUG-20377)
QList<QDeclarativeContactDetail *> m_details;
QMap<QString, int> m_preferredDetails;
public slots:
void clearDetails();
void save();
Q_SIGNALS:
void contactIdChanged();
void managerChanged();
void contactChanged();
private slots:
void setModified();
private:
Q_DISABLE_COPY(QDeclarativeContact)
template<typename T> T* getDetail(const QDeclarativeContactDetail::DetailType &type)
{
foreach (QDeclarativeContactDetail *detail, m_details) {
if (type == detail->detailType())
{
T* tempDetail = static_cast<T *>(detail);
return tempDetail;
}
}
T* detail = new T;
if (detail) {
m_details.append(detail);
emit contactChanged();
return detail;
}
return 0;
}
void removePreferredDetail(QDeclarativeContactDetail *detail);
// call-back functions for list property
static void _q_detail_append(QQmlListProperty<QDeclarativeContactDetail> *property, QDeclarativeContactDetail *value);
static QDeclarativeContactDetail *_q_detail_at(QQmlListProperty<QDeclarativeContactDetail> *property, int index);
static void _q_detail_clear(QQmlListProperty<QDeclarativeContactDetail> *property);
static int _q_detail_count(QQmlListProperty<QDeclarativeContactDetail> *property);
};
QT_END_NAMESPACE
QML_DECLARE_TYPE(QDeclarativeContact)
#endif // QDECLARATIVECONTACT_P_H
|