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 "qdeclarativecontactfetchhint_p.h" |
35 | |
36 | #include <QtCore/qset.h> |
37 | |
38 | QTCONTACTS_USE_NAMESPACE |
39 | |
40 | QT_BEGIN_NAMESPACE |
41 | |
42 | /*! |
43 | \qmltype FetchHint |
44 | \instantiates QDeclarativeContactFetchHint |
45 | \brief The FetchHint element provides hints to the manager about which contact |
46 | information needs to be retrieved in an asynchronous fetch request or a synchronous |
47 | function call. |
48 | |
49 | \ingroup qml-contacts-main |
50 | \inqmlmodule QtContacts |
51 | |
52 | This element is part of the \b{QtContacts} module. |
53 | |
54 | \sa QContactFetchHint |
55 | */ |
56 | |
57 | QDeclarativeContactFetchHint::QDeclarativeContactFetchHint(QObject* parent) |
58 | :QObject(parent) |
59 | { |
60 | } |
61 | |
62 | /*! |
63 | \qmlproperty list<int> FetchHint::detailTypesHint |
64 | |
65 | This property holds a list of contact detail types |
66 | the manager should (at a minimum) retrieve when fetching contacts. |
67 | */ |
68 | QList<int> QDeclarativeContactFetchHint::detailTypesHint() const |
69 | { |
70 | QList<int> savedList; |
71 | foreach (const QContactDetail::DetailType &detailTypeHint, m_fetchHint.detailTypesHint()) { |
72 | savedList << static_cast<int>(detailTypeHint); |
73 | } |
74 | |
75 | return savedList; |
76 | } |
77 | void QDeclarativeContactFetchHint::setDetailTypesHint(const QList<int> &detailTypes) |
78 | { |
79 | if (detailTypes.toSet() != detailTypesHint().toSet()) { |
80 | QList<QContactDetail::DetailType> convertedDetailTypes; |
81 | foreach (const int detailType, detailTypes) { |
82 | convertedDetailTypes << static_cast<QContactDetail::DetailType>(detailType); |
83 | } |
84 | m_fetchHint.setDetailTypesHint(convertedDetailTypes); |
85 | emit fetchHintChanged(); |
86 | } |
87 | } |
88 | |
89 | /*! |
90 | \qmlproperty list<string> FetchHint::relationshipTypesHint |
91 | |
92 | This property holds a list of relationship types that the manager should (at a minimum) retrieve |
93 | when fetching contacts. |
94 | */ |
95 | QStringList QDeclarativeContactFetchHint::relationshipTypesHint() const |
96 | { |
97 | return m_fetchHint.relationshipTypesHint(); |
98 | } |
99 | void QDeclarativeContactFetchHint::setRelationshipTypesHint(const QStringList& relationshipTypes) |
100 | { |
101 | if (relationshipTypes.toSet() != m_fetchHint.relationshipTypesHint().toSet()) { |
102 | m_fetchHint.setRelationshipTypesHint(relationshipTypes); |
103 | emit fetchHintChanged(); |
104 | } |
105 | } |
106 | |
107 | |
108 | /*! |
109 | \qmlproperty int FetchHint::imageWidth |
110 | |
111 | This property holds the preferred pixel width for any images returned |
112 | by the manager for a given request. This hint may be ignored by the manager. |
113 | */ |
114 | int QDeclarativeContactFetchHint::preferredImageWidth() const |
115 | { |
116 | return m_fetchHint.preferredImageSize().width(); |
117 | } |
118 | void QDeclarativeContactFetchHint::setPreferredImageWidth(int w) |
119 | { |
120 | if (m_fetchHint.preferredImageSize().width() != w) { |
121 | QSize s = m_fetchHint.preferredImageSize(); |
122 | s.setWidth(w); |
123 | m_fetchHint.setPreferredImageSize(s); |
124 | emit fetchHintChanged(); |
125 | } |
126 | } |
127 | |
128 | /*! |
129 | \qmlproperty int FetchHint::imageHeight |
130 | |
131 | This property holds the preferred pixel height for any images returned |
132 | by the manager for a given request. This hint may be ignored by the manager. |
133 | */ |
134 | int QDeclarativeContactFetchHint::preferredImageHeight() const |
135 | { |
136 | return m_fetchHint.preferredImageSize().height(); |
137 | } |
138 | void QDeclarativeContactFetchHint::setPreferredImageHeight(int h) |
139 | { |
140 | if (m_fetchHint.preferredImageSize().height() != h) { |
141 | QSize s = m_fetchHint.preferredImageSize(); |
142 | s.setHeight(h); |
143 | m_fetchHint.setPreferredImageSize(s); |
144 | emit fetchHintChanged(); |
145 | } |
146 | } |
147 | |
148 | /*! |
149 | \qmlproperty FetchHint::OptimizationHints FetchHint::optimizationHints |
150 | |
151 | This property holds the optimization hint flags specified by the client. |
152 | These hints may be ignored by the backend, in which case it will return |
153 | the full set of information accessible in a contact, including |
154 | relationships, action preferences, and binary blobs. The value of the flags can be: |
155 | \list |
156 | \li FetchHint.AllRequired - (default). |
157 | \li FetchHint.NoRelationships |
158 | \li FetchHint.NoActionPreferences |
159 | \li FetchHint.NoBinaryBlobs |
160 | \endlist |
161 | |
162 | */ |
163 | QDeclarativeContactFetchHint::OptimizationHints QDeclarativeContactFetchHint::optimizationHints() const |
164 | { |
165 | QDeclarativeContactFetchHint::OptimizationHints hints; |
166 | hints = ~hints & (int)m_fetchHint.optimizationHints(); |
167 | return hints; |
168 | } |
169 | void QDeclarativeContactFetchHint::setOptimizationHints(QDeclarativeContactFetchHint::OptimizationHints hints) |
170 | { |
171 | QContactFetchHint::OptimizationHints newHints; |
172 | newHints = ~newHints & (int)hints; |
173 | if (newHints != m_fetchHint.optimizationHints()) { |
174 | m_fetchHint.setOptimizationHints(newHints); |
175 | emit fetchHintChanged(); |
176 | } |
177 | } |
178 | |
179 | QContactFetchHint QDeclarativeContactFetchHint::fetchHint() const |
180 | { |
181 | return m_fetchHint; |
182 | } |
183 | |
184 | void QDeclarativeContactFetchHint::setFetchHint(const QContactFetchHint& fetchHint) |
185 | { |
186 | m_fetchHint = fetchHint; |
187 | emit fetchHintChanged(); |
188 | } |
189 | |
190 | #include "moc_qdeclarativecontactfetchhint_p.cpp" |
191 | |
192 | QT_END_NAMESPACE |
193 | |