| 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 QtLocation module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
| 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 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or later as published by the Free |
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
| 29 | ** the packaging of this file. Please review the following information to |
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be |
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
| 32 | ** |
| 33 | ** $QT_END_LICENSE$ |
| 34 | ** |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | #ifndef QDECLARATIVEPLACE_P_H |
| 38 | #define QDECLARATIVEPLACE_P_H |
| 39 | |
| 40 | // |
| 41 | // W A R N I N G |
| 42 | // ------------- |
| 43 | // |
| 44 | // This file is not part of the Qt API. It exists purely as an |
| 45 | // implementation detail. This header file may change from version to |
| 46 | // version without notice, or even be removed. |
| 47 | // |
| 48 | // We mean it. |
| 49 | // |
| 50 | |
| 51 | #include <QtLocation/private/qlocationglobal_p.h> |
| 52 | #include <QtCore/QObject> |
| 53 | #include <QtQml/QQmlListProperty> |
| 54 | #include <QtQml/QQmlParserStatus> |
| 55 | #include <QtQml/QQmlPropertyMap> |
| 56 | #include <QtLocation/QPlace> |
| 57 | |
| 58 | #include <QtPositioningQuick/private/qdeclarativegeolocation_p.h> |
| 59 | #include <QtLocation/private/qdeclarativecategory_p.h> |
| 60 | #include <QtLocation/private/qdeclarativecontactdetail_p.h> |
| 61 | #include <QtLocation/private/qdeclarativesupplier_p.h> |
| 62 | #include <QtLocation/private/qdeclarativeratings_p.h> |
| 63 | #include <QtLocation/private/qdeclarativereviewmodel_p.h> |
| 64 | #include <QtLocation/private/qdeclarativeplaceimagemodel_p.h> |
| 65 | #include <QtLocation/private/qdeclarativeplaceeditorialmodel_p.h> |
| 66 | |
| 67 | QT_BEGIN_NAMESPACE |
| 68 | |
| 69 | class QPlaceReply; |
| 70 | |
| 71 | class QPlaceManager; |
| 72 | class QDeclarativePlaceIcon; |
| 73 | |
| 74 | class Q_LOCATION_PRIVATE_EXPORT QDeclarativePlace : public QObject, public QQmlParserStatus |
| 75 | { |
| 76 | Q_OBJECT |
| 77 | |
| 78 | Q_ENUMS(Status Visibility) |
| 79 | |
| 80 | Q_PROPERTY(QPlace place READ place WRITE setPlace) |
| 81 | Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged) |
| 82 | Q_PROPERTY(QQmlListProperty<QDeclarativeCategory> categories READ categories NOTIFY categoriesChanged) |
| 83 | Q_PROPERTY(QDeclarativeGeoLocation *location READ location WRITE setLocation NOTIFY locationChanged) |
| 84 | Q_PROPERTY(QDeclarativeRatings *ratings READ ratings WRITE setRatings NOTIFY ratingsChanged) |
| 85 | Q_PROPERTY(QDeclarativeSupplier *supplier READ supplier WRITE setSupplier NOTIFY supplierChanged) |
| 86 | Q_PROPERTY(QDeclarativePlaceIcon *icon READ icon WRITE setIcon NOTIFY iconChanged) |
| 87 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
| 88 | Q_PROPERTY(QString placeId READ placeId WRITE setPlaceId NOTIFY placeIdChanged) |
| 89 | Q_PROPERTY(QString attribution READ attribution WRITE setAttribution NOTIFY attributionChanged) |
| 90 | |
| 91 | Q_PROPERTY(QDeclarativeReviewModel *reviewModel READ reviewModel NOTIFY reviewModelChanged) |
| 92 | Q_PROPERTY(QDeclarativePlaceImageModel *imageModel READ imageModel NOTIFY imageModelChanged) |
| 93 | Q_PROPERTY(QDeclarativePlaceEditorialModel *editorialModel READ editorialModel NOTIFY editorialModelChanged) |
| 94 | |
| 95 | Q_PROPERTY(QObject *extendedAttributes READ extendedAttributes NOTIFY extendedAttributesChanged) |
| 96 | Q_PROPERTY(QObject *contactDetails READ contactDetails NOTIFY contactDetailsChanged) |
| 97 | Q_PROPERTY(bool detailsFetched READ detailsFetched NOTIFY detailsFetchedChanged) |
| 98 | Q_PROPERTY(Status status READ status NOTIFY statusChanged) |
| 99 | |
| 100 | Q_PROPERTY(QString primaryPhone READ primaryPhone NOTIFY primaryPhoneChanged) |
| 101 | Q_PROPERTY(QString primaryFax READ primaryFax NOTIFY primaryFaxChanged) |
| 102 | Q_PROPERTY(QString primaryEmail READ primaryEmail NOTIFY primaryEmailChanged) |
| 103 | Q_PROPERTY(QUrl primaryWebsite READ primaryWebsite NOTIFY primaryWebsiteChanged) |
| 104 | |
| 105 | Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged) |
| 106 | Q_PROPERTY(QDeclarativePlace *favorite READ favorite WRITE setFavorite NOTIFY favoriteChanged) |
| 107 | |
| 108 | Q_INTERFACES(QQmlParserStatus) |
| 109 | |
| 110 | public: |
| 111 | explicit QDeclarativePlace(QObject *parent = 0); |
| 112 | QDeclarativePlace(const QPlace &src, QDeclarativeGeoServiceProvider *plugin, QObject *parent = 0); |
| 113 | ~QDeclarativePlace(); |
| 114 | |
| 115 | enum Status {Ready, Saving, Fetching, Removing, Error}; |
| 116 | enum Visibility { |
| 117 | UnspecifiedVisibility = QLocation::UnspecifiedVisibility, |
| 118 | DeviceVisibility = QLocation::DeviceVisibility, |
| 119 | PrivateVisibility = QLocation::PrivateVisibility, |
| 120 | PublicVisibility = QLocation::PublicVisibility |
| 121 | }; |
| 122 | |
| 123 | //From QQmlParserStatus |
| 124 | virtual void classBegin() {} |
| 125 | virtual void componentComplete(); |
| 126 | |
| 127 | void setPlugin(QDeclarativeGeoServiceProvider *plugin); |
| 128 | QDeclarativeGeoServiceProvider *plugin() const; |
| 129 | |
| 130 | QDeclarativeReviewModel *reviewModel(); |
| 131 | QDeclarativePlaceImageModel *imageModel(); |
| 132 | QDeclarativePlaceEditorialModel *editorialModel(); |
| 133 | |
| 134 | QPlace place(); |
| 135 | void setPlace(const QPlace &src); |
| 136 | |
| 137 | QQmlListProperty<QDeclarativeCategory> categories(); |
| 138 | static void category_append(QQmlListProperty<QDeclarativeCategory> *prop, |
| 139 | QDeclarativeCategory *value); |
| 140 | static int category_count(QQmlListProperty<QDeclarativeCategory> *prop); |
| 141 | static QDeclarativeCategory *category_at(QQmlListProperty<QDeclarativeCategory> *prop, int index); |
| 142 | static void category_clear(QQmlListProperty<QDeclarativeCategory> *prop); |
| 143 | |
| 144 | QDeclarativeGeoLocation *location(); |
| 145 | void setLocation(QDeclarativeGeoLocation *location); |
| 146 | QDeclarativeRatings *ratings(); |
| 147 | void setRatings(QDeclarativeRatings *ratings); |
| 148 | QDeclarativeSupplier *supplier() const; |
| 149 | void setSupplier(QDeclarativeSupplier *supplier); |
| 150 | QDeclarativePlaceIcon *icon() const; |
| 151 | void setIcon(QDeclarativePlaceIcon *icon); |
| 152 | QString name() const; |
| 153 | void setName(const QString &name); |
| 154 | QString placeId() const; |
| 155 | void setPlaceId(const QString &placeId); |
| 156 | QString attribution() const; |
| 157 | void setAttribution(const QString &attribution); |
| 158 | bool detailsFetched() const; |
| 159 | |
| 160 | Status status() const; |
| 161 | void setStatus(Status status, const QString &errorString = QString()); |
| 162 | |
| 163 | Q_INVOKABLE void getDetails(); |
| 164 | Q_INVOKABLE void save(); |
| 165 | Q_INVOKABLE void remove(); |
| 166 | Q_INVOKABLE QString errorString() const; |
| 167 | |
| 168 | QString primaryPhone() const; |
| 169 | QString primaryFax() const; |
| 170 | QString primaryEmail() const; |
| 171 | QUrl primaryWebsite() const; |
| 172 | |
| 173 | QQmlPropertyMap *extendedAttributes() const; |
| 174 | |
| 175 | QDeclarativeContactDetails *contactDetails() const; |
| 176 | |
| 177 | Visibility visibility() const; |
| 178 | void setVisibility(Visibility visibility); |
| 179 | |
| 180 | QDeclarativePlace *favorite() const; |
| 181 | void setFavorite(QDeclarativePlace *favorite); |
| 182 | |
| 183 | Q_INVOKABLE void copyFrom(QDeclarativePlace *original); |
| 184 | Q_INVOKABLE void initializeFavorite(QDeclarativeGeoServiceProvider *plugin); |
| 185 | |
| 186 | Q_SIGNALS: |
| 187 | void pluginChanged(); |
| 188 | void categoriesChanged(); |
| 189 | void locationChanged(); |
| 190 | void ratingsChanged(); |
| 191 | void supplierChanged(); |
| 192 | void iconChanged(); |
| 193 | void nameChanged(); |
| 194 | void placeIdChanged(); |
| 195 | void attributionChanged(); |
| 196 | void detailsFetchedChanged(); |
| 197 | void reviewModelChanged(); |
| 198 | void imageModelChanged(); |
| 199 | void editorialModelChanged(); |
| 200 | |
| 201 | void primaryPhoneChanged(); |
| 202 | void primaryFaxChanged(); |
| 203 | void primaryEmailChanged(); |
| 204 | void primaryWebsiteChanged(); |
| 205 | |
| 206 | void extendedAttributesChanged(); |
| 207 | void contactDetailsChanged(); |
| 208 | void statusChanged(); |
| 209 | void visibilityChanged(); |
| 210 | void favoriteChanged(); |
| 211 | |
| 212 | private Q_SLOTS: |
| 213 | void finished(); |
| 214 | void contactsModified(const QString &, const QVariant &); |
| 215 | void pluginReady(); |
| 216 | void cleanupDeletedCategories(); |
| 217 | private: |
| 218 | void synchronizeCategories(); |
| 219 | void pullExtendedAttributes(); |
| 220 | void synchronizeContacts(); |
| 221 | void primarySignalsEmission(const QString &type = QString()); |
| 222 | QString primaryValue(const QString &contactType) const; |
| 223 | |
| 224 | private: |
| 225 | QPlaceManager *manager(); |
| 226 | |
| 227 | QList<QDeclarativeCategory *> m_categories; |
| 228 | QDeclarativeGeoLocation *m_location; |
| 229 | QDeclarativeRatings *m_ratings; |
| 230 | QDeclarativeSupplier *m_supplier; |
| 231 | QDeclarativePlaceIcon *m_icon; |
| 232 | QDeclarativeReviewModel *m_reviewModel; |
| 233 | QDeclarativePlaceImageModel *m_imageModel; |
| 234 | QDeclarativePlaceEditorialModel *m_editorialModel; |
| 235 | QQmlPropertyMap *m_extendedAttributes; |
| 236 | QDeclarativeContactDetails *m_contactDetails; |
| 237 | |
| 238 | QPlace m_src; |
| 239 | |
| 240 | QPlaceReply *m_reply; |
| 241 | |
| 242 | QDeclarativeGeoServiceProvider *m_plugin; |
| 243 | bool m_complete; |
| 244 | |
| 245 | QString m_prevPrimaryPhone; |
| 246 | QString m_prevPrimaryEmail; |
| 247 | QString m_prevPrimaryFax; |
| 248 | QUrl m_prevPrimaryWebsite; |
| 249 | |
| 250 | QDeclarativePlace *m_favorite; |
| 251 | |
| 252 | Status m_status; |
| 253 | QString m_errorString; |
| 254 | |
| 255 | QList<QDeclarativeCategory *>m_categoriesToBeDeleted; |
| 256 | }; |
| 257 | |
| 258 | QT_END_NAMESPACE |
| 259 | |
| 260 | QML_DECLARE_TYPE(QDeclarativePlace) |
| 261 | |
| 262 | #endif // QDECLARATIVEPLACE_P_H |
| 263 | |