~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to src/imports/contacts/qdeclarativecontact_p.h

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtQml module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
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 Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/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 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
#ifndef QDECLARATIVECONTACT_P_H
 
42
#define QDECLARATIVECONTACT_P_H
 
43
 
 
44
#include <qcontact.h>
 
45
#include <qcontactid.h>
 
46
#include "qdeclarativecontactdetails_p.h"
 
47
#include "qdeclarativecontacturl_p.h"
 
48
#include "qdeclarativecontacthobby_p.h"
 
49
#include "qdeclarativecontactdetail_p.h"
 
50
#include <QtQml/qqmllist.h>
 
51
 
 
52
QT_BEGIN_NAMESPACE_CONTACTS
 
53
 
 
54
class QDeclarativeContact : public QObject
 
55
{
 
56
    Q_OBJECT
 
57
 
 
58
    // basic information
 
59
    Q_PROPERTY (bool modified READ modified)
 
60
 
 
61
    Q_PROPERTY (QDeclarativeContactType::ContactType type READ type NOTIFY contactChanged)
 
62
    Q_PROPERTY (QString contactId READ contactId NOTIFY contactIdChanged)
 
63
    Q_PROPERTY (QString manager READ manager NOTIFY managerChanged)
 
64
    Q_PROPERTY (QQmlListProperty<QDeclarativeContactDetail> contactDetails READ contactDetails NOTIFY contactChanged)
 
65
    Q_PROPERTY (QDeclarativeContactAddress* address READ address NOTIFY contactChanged)
 
66
    Q_PROPERTY (QQmlListProperty<QDeclarativeContactAddress> addresses READ addresses NOTIFY contactChanged)
 
67
    Q_PROPERTY (QDeclarativeContactAnniversary* anniversary READ anniversary NOTIFY contactChanged)
 
68
    Q_PROPERTY (QDeclarativeContactAvatar* avatar READ avatar NOTIFY contactChanged)
 
69
    Q_PROPERTY (QDeclarativeContactBirthday*  birthday READ birthday NOTIFY contactChanged)
 
70
    Q_PROPERTY (QDeclarativeContactDisplayLabel*  displayLabel READ displayLabel NOTIFY contactChanged)
 
71
    Q_PROPERTY (QDeclarativeContactEmailAddress*  email READ email NOTIFY contactChanged)
 
72
    Q_PROPERTY (QQmlListProperty<QDeclarativeContactEmailAddress> emails READ emails NOTIFY contactChanged)
 
73
    Q_PROPERTY (QDeclarativeContactExtendedDetail*  extendedDetail READ extendedDetail NOTIFY contactChanged)
 
74
    Q_PROPERTY (QQmlListProperty<QDeclarativeContactExtendedDetail> extendedDetails READ extendedDetails NOTIFY contactChanged)
 
75
    Q_PROPERTY (QDeclarativeContactFamily*  family READ family NOTIFY contactChanged)
 
76
    Q_PROPERTY (QDeclarativeContactFavorite*  favorite READ favorite NOTIFY contactChanged)
 
77
    Q_PROPERTY (QDeclarativeContactGender*  gender READ gender NOTIFY contactChanged)
 
78
    Q_PROPERTY (QDeclarativeContactGeoLocation*  geolocation READ geolocation NOTIFY contactChanged)
 
79
    Q_PROPERTY (QDeclarativeContactGlobalPresence*  globalPresence READ globalPresence NOTIFY contactChanged)
 
80
    Q_PROPERTY (QDeclarativeContactGuid*  guid READ guid NOTIFY contactChanged)
 
81
    Q_PROPERTY (QDeclarativeContactHobby*  hobby READ hobby NOTIFY contactChanged)
 
82
    Q_PROPERTY (QDeclarativeContactName*  name READ name NOTIFY contactChanged)
 
83
    Q_PROPERTY (QDeclarativeContactNickname*  nickname READ nickname  NOTIFY contactChanged)
 
84
    Q_PROPERTY (QDeclarativeContactNote*  note READ note NOTIFY contactChanged)
 
85
    Q_PROPERTY (QDeclarativeContactOnlineAccount*  onlineAccount READ onlineAccount NOTIFY contactChanged)
 
86
    Q_PROPERTY (QDeclarativeContactOrganization*  organization READ organization  NOTIFY contactChanged)
 
87
    Q_PROPERTY (QQmlListProperty<QDeclarativeContactOrganization>  organizations READ organizations  NOTIFY contactChanged)
 
88
    Q_PROPERTY (QDeclarativeContactPhoneNumber*  phoneNumber READ phoneNumber NOTIFY contactChanged)
 
89
    Q_PROPERTY (QQmlListProperty<QDeclarativeContactPhoneNumber> phoneNumbers READ phoneNumbers NOTIFY contactChanged)
 
90
    Q_PROPERTY (QDeclarativeContactPresence*  presence READ presence NOTIFY contactChanged)
 
91
    Q_PROPERTY (QDeclarativeContactRingtone*  ringtone READ ringtone NOTIFY contactChanged)
 
92
    Q_PROPERTY (QDeclarativeContactSyncTarget*  syncTarget READ syncTarget NOTIFY contactChanged)
 
93
    Q_PROPERTY (QDeclarativeContactTag*  tag READ tag NOTIFY contactChanged)
 
94
    Q_PROPERTY (QDeclarativeContactTimestamp*  timestamp READ timestamp NOTIFY contactChanged)
 
95
    Q_PROPERTY (QDeclarativeContactUrl*  url READ url NOTIFY contactChanged)
 
96
    Q_PROPERTY (QQmlListProperty<QDeclarativeContactUrl> urls READ urls NOTIFY contactChanged)
 
97
    Q_PROPERTY (QDeclarativeContactVersion*  version READ version NOTIFY contactChanged)
 
98
    Q_PROPERTY (QVariantMap preferredDetails READ preferredDetails NOTIFY contactChanged)
 
99
    Q_CLASSINFO("DefaultProperty", "contactDetails")
 
100
 
 
101
public:
 
102
 
 
103
    explicit QDeclarativeContact(QObject *parent = 0);
 
104
    ~QDeclarativeContact();
 
105
 
 
106
    void setContact(const QContact& c);
 
107
    QContact contact() const;
 
108
    bool modified() const;
 
109
 
 
110
    QDeclarativeContactType::ContactType type() const;
 
111
 
 
112
    QString contactId() const;
 
113
    QString manager() const;
 
114
    QQmlListProperty<QDeclarativeContactDetail> contactDetails();
 
115
 
 
116
    // use int instead of QDeclarativeContactDetail::ContactType as a work-around for QTBUG-20639
 
117
    Q_INVOKABLE QDeclarativeContactDetail* detail(int type);
 
118
    Q_INVOKABLE QVariantList details(int type);
 
119
 
 
120
    Q_INVOKABLE bool removeDetail(QDeclarativeContactDetail* detail);
 
121
    Q_INVOKABLE bool addDetail(QDeclarativeContactDetail* detail);
 
122
 
 
123
    Q_INVOKABLE bool setPreferredDetail(const QString& actionName, QDeclarativeContactDetail* detail);
 
124
    Q_INVOKABLE bool isPreferredDetail(const QString& actionName, QDeclarativeContactDetail* detail) const;
 
125
    Q_INVOKABLE QDeclarativeContactDetail* preferredDetail(const QString& actionName) const;
 
126
    QVariantMap preferredDetails() const;
 
127
 
 
128
    QDeclarativeContactAddress* address();
 
129
    QQmlListProperty<QDeclarativeContactAddress>  addresses();
 
130
    QDeclarativeContactAnniversary* anniversary();
 
131
    QDeclarativeContactAvatar* avatar();
 
132
    QDeclarativeContactBirthday*  birthday();
 
133
    QDeclarativeContactDisplayLabel* displayLabel();
 
134
    QDeclarativeContactEmailAddress*  email();
 
135
    QQmlListProperty<QDeclarativeContactEmailAddress>  emails();
 
136
    QDeclarativeContactExtendedDetail*  extendedDetail();
 
137
    QQmlListProperty<QDeclarativeContactExtendedDetail>  extendedDetails();
 
138
    QDeclarativeContactFamily*  family();
 
139
    QDeclarativeContactFavorite*  favorite();
 
140
    QDeclarativeContactGender*  gender();
 
141
    QDeclarativeContactGeoLocation*  geolocation();
 
142
    QDeclarativeContactGlobalPresence*  globalPresence();
 
143
    QDeclarativeContactGuid*  guid();
 
144
    QDeclarativeContactHobby*  hobby();
 
145
    QDeclarativeContactName*  name();
 
146
    QDeclarativeContactNickname*  nickname();
 
147
    QDeclarativeContactNote*  note();
 
148
    QDeclarativeContactOnlineAccount*  onlineAccount();
 
149
    QDeclarativeContactOrganization*  organization();
 
150
    QQmlListProperty<QDeclarativeContactOrganization>  organizations();
 
151
    QDeclarativeContactPhoneNumber*  phoneNumber();
 
152
    QQmlListProperty<QDeclarativeContactPhoneNumber>  phoneNumbers();
 
153
    QDeclarativeContactPresence*  presence();
 
154
    QDeclarativeContactRingtone*  ringtone();
 
155
    QDeclarativeContactSyncTarget*  syncTarget();
 
156
    QDeclarativeContactTag*  tag();
 
157
    QDeclarativeContactTimestamp*  timestamp();
 
158
    QDeclarativeContactUrl*  url();
 
159
    QQmlListProperty<QDeclarativeContactUrl>  urls();
 
160
    QDeclarativeContactVersion*  version();
 
161
 
 
162
protected:
 
163
    bool m_modified;
 
164
    QContactId m_id;
 
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_CONTACTS
 
213
 
 
214
QTCONTACTS_USE_NAMESPACE
 
215
 
 
216
QML_DECLARE_TYPE(QDeclarativeContact)
 
217
 
 
218
#endif // QDECLARATIVECONTACT_P_H