diff options
18 files changed, 867 insertions, 180 deletions
diff --git a/examples/declarative/qmlplaces/SearchResultDelegate.qml b/examples/declarative/qmlplaces/SearchResultDelegate.qml index b5cfb877..a5bfaab8 100644 --- a/examples/declarative/qmlplaces/SearchResultDelegate.qml +++ b/examples/declarative/qmlplaces/SearchResultDelegate.qml @@ -151,10 +151,10 @@ Rectangle { } Text { - text: '<b>Website: </b> <a href=\"' + place.primaryUrl + '\">' + place.primaryUrl + '</a>' + text: '<b>Website: </b> <a href=\"' + place.primaryWebsite + '\">' + place.primaryWebsite + '</a>' font.pixelSize: 16 - visible: String(place.primaryUrl).length > 0 - onLinkActivated: Qt.openUrlExternally(place.primaryUrl) + visible: String(place.primaryWebsite).length > 0 + onLinkActivated: Qt.openUrlExternally(place.primaryWebsite) } Text { text: '<b>Tags: </b> ' + place.tags; font.pixelSize: 16 } diff --git a/src/imports/location/declarativeplaces/declarativeplaces.pri b/src/imports/location/declarativeplaces/declarativeplaces.pri index 0b6a749c..f27a3ed2 100644 --- a/src/imports/location/declarativeplaces/declarativeplaces.pri +++ b/src/imports/location/declarativeplaces/declarativeplaces.pri @@ -10,6 +10,7 @@ SOURCES += \ declarativeplaces/qdeclarativeplaceimagemodel.cpp \ declarativeplaces/qdeclarativeplaceeditorialmodel.cpp \ #data + declarativeplaces/qdeclarativecontactdetail.cpp \ declarativeplaces/qdeclarativecategory.cpp \ declarativeplaces/qdeclarativeplace.cpp \ declarativeplaces/qdeclarativeplaceattribute.cpp \ @@ -30,6 +31,7 @@ HEADERS += \ declarativeplaces/qdeclarativeplaceimagemodel_p.h \ declarativeplaces/qdeclarativeplaceeditorialmodel.h \ #data + declarativeplaces/qdeclarativecontactdetail_p.h \ declarativeplaces/qdeclarativecategory_p.h \ declarativeplaces/qdeclarativeplace_p.h \ declarativeplaces/qdeclarativeplaceattribute_p.h \ diff --git a/src/imports/location/declarativeplaces/qdeclarativecontactdetail.cpp b/src/imports/location/declarativeplaces/qdeclarativecontactdetail.cpp new file mode 100644 index 00000000..79d4197c --- /dev/null +++ b/src/imports/location/declarativeplaces/qdeclarativecontactdetail.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativecontactdetail_p.h" + +/*! + \qmlclass ContactDetail QDeclarativeContactDetail + + \inqmlmodule QtLocation 5 + + \ingroup qml-QtLocation5-places + + \since QtLocation 5.0 + + \brief The ContactDetail element holds a contact detail such as phone number or website address. +*/ +QDeclarativeContactDetail::QDeclarativeContactDetail(QObject *parent) + : QObject(parent) +{ +} + +QDeclarativeContactDetail::QDeclarativeContactDetail(const QPlaceContactDetail &src, QObject *parent) + : QObject(parent), m_contactDetail(src) +{ +} + +QDeclarativeContactDetail::~QDeclarativeContactDetail() +{ +} + +void QDeclarativeContactDetail::setContactDetail(const QPlaceContactDetail &src) +{ + QPlaceContactDetail prevContactDetail = m_contactDetail; + m_contactDetail = src; + + if (m_contactDetail.label() != prevContactDetail.label()) + emit labelChanged(); + if (m_contactDetail.value() != prevContactDetail.value()) + emit valueChanged(); +} + +QPlaceContactDetail QDeclarativeContactDetail::contactDetail() const +{ + return m_contactDetail; +} + +/*! + \qmlproperty string ContactDetail::label + + This property holds a localized label describing the contact detail. +*/ +QString QDeclarativeContactDetail::label() const +{ + return m_contactDetail.label(); +} + +void QDeclarativeContactDetail::setLabel(const QString &label) +{ + if (m_contactDetail.label()!= label) { + m_contactDetail.setLabel(label); + emit labelChanged(); + } +} + +/*! + \qmlproperty string ContactDetail::value + + This property holds the value of the contact detail which + may be a phone number, email address, website url etc. +*/ +QString QDeclarativeContactDetail::value() const +{ + return m_contactDetail.value(); +} + +void QDeclarativeContactDetail::setValue(const QString &value) +{ + if (m_contactDetail.value()!= value) { + m_contactDetail.setValue(value); + emit valueChanged(); + } +} diff --git a/src/imports/location/declarativeplaces/qdeclarativecontactdetail_p.h b/src/imports/location/declarativeplaces/qdeclarativecontactdetail_p.h new file mode 100644 index 00000000..98aa43a2 --- /dev/null +++ b/src/imports/location/declarativeplaces/qdeclarativecontactdetail_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVECONTACTDETAIL_P_H +#define QDECLARATIVECONTACTDETAIL_P_H + +#include <QtCore/QObject> +#include <QtLocation/QPlaceContactDetail> +#include <QtDeclarative/qdeclarative.h> + +QT_BEGIN_NAMESPACE + +class QDeclarativeContactDetail : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) + Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged) + +public: + explicit QDeclarativeContactDetail(QObject *parent = 0); + explicit QDeclarativeContactDetail(const QPlaceContactDetail &src, QObject *parent = 0); + ~QDeclarativeContactDetail(); + + QPlaceContactDetail contactDetail() const; + void setContactDetail(const QPlaceContactDetail &contactDetail); + + QString label() const; + void setLabel(const QString &label); + + QString value() const; + void setValue(const QString &value); + +signals: + void labelChanged(); + void valueChanged(); + +private: + QPlaceContactDetail m_contactDetail; + +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeContactDetail)); + +#endif diff --git a/src/imports/location/declarativeplaces/qdeclarativeplace.cpp b/src/imports/location/declarativeplaces/qdeclarativeplace.cpp index 925760f4..7c416aa9 100644 --- a/src/imports/location/declarativeplaces/qdeclarativeplace.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativeplace.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qdeclarativeplace_p.h" +#include "qdeclarativecontactdetail_p.h" #include "qdeclarativegeoserviceprovider_p.h" #include "qdeclarativeplaceattribute_p.h" #include "qdeclarativeplaceicon_p.h" @@ -50,6 +51,7 @@ #include <QtLocation/QPlaceDetailsReply> #include <QtLocation/QPlaceReply> #include <QtLocation/QPlaceIdReply> +#include <QtLocation/QPlaceContactDetail> QT_USE_NAMESPACE @@ -69,7 +71,8 @@ QDeclarativePlace::QDeclarativePlace(QObject* parent) : QObject(parent), m_location(0), m_rating(0), m_supplier(0), m_icon(0), m_reviewModel(0), m_imageModel(0), m_editorialModel(0), m_extendedAttributes(new QDeclarativePropertyMap(this)), - m_reply(0), m_plugin(0),m_complete(false), m_status(QDeclarativePlace::Ready) + m_contactDetails(0), m_reply(0), m_plugin(0), m_complete(false), + m_status(QDeclarativePlace::Ready), m_errorString(QString()) { setPlace(QPlace()); } @@ -77,7 +80,7 @@ QDeclarativePlace::QDeclarativePlace(QObject* parent) QDeclarativePlace::QDeclarativePlace(const QPlace &src, QDeclarativeGeoServiceProvider *plugin, QObject *parent) : QObject(parent), m_location(0), m_rating(0), m_supplier(0), m_icon(0), m_reviewModel(0), m_imageModel(0), m_editorialModel(0), - m_extendedAttributes(new QDeclarativePropertyMap(this)), + m_extendedAttributes(new QDeclarativePropertyMap(this)), m_contactDetails(0), m_src(src), m_reply(0), m_plugin(plugin), m_complete(false), m_status(QDeclarativePlace::Ready) { @@ -207,8 +210,8 @@ void QDeclarativePlace::setPlace(const QPlace &src) if (previous.primaryEmail() != m_src.primaryEmail()) { emit primaryEmailChanged(); } - if (previous.primaryUrl() != m_src.primaryUrl()) { - emit primaryUrlChanged(); + if (previous.primaryWebsite() != m_src.primaryWebsite()) { + emit primaryWebsiteChanged(); } if (previous.placeId() != m_src.placeId()) { @@ -227,6 +230,16 @@ void QDeclarativePlace::setPlace(const QPlace &src) synchronizeExtendedAttributes(); emit extendedAttributesChanged(); } + + if (m_contactDetails && m_contactDetails->parent() == this) { + synchronizeContacts(); + } else if (!m_contactDetails || m_contactDetails->parent() != this) { + m_contactDetails = new QDeclarativePropertyMap(this); + connect(m_contactDetails, SIGNAL(valueChanged(QString,QVariant)), this, SLOT(contactsModified(QString,QVariant))); + synchronizeContacts(); + + emit contactDetailsChanged(); + } } QPlace QDeclarativePlace::place() @@ -509,6 +522,11 @@ void QDeclarativePlace::finished() } } +void QDeclarativePlace::contactsModified(const QString &key, const QVariant &value) +{ + primarySignalsEmission(key); +} + /*! \qmlmethod void Place::getDetails() @@ -573,17 +591,15 @@ QString QDeclarativePlace::errorString() const This property holds the primary phone number of the place. */ -void QDeclarativePlace::setPrimaryPhone(const QString &phone) -{ - if (m_src.primaryPhone() != phone) { - m_src.setPrimaryPhone(phone); - emit primaryPhoneChanged(); - } -} - QString QDeclarativePlace::primaryPhone() const { - return m_src.primaryPhone(); + QVariantList phoneNumbers = m_contactDetails->value(QPlaceContactDetail::Phone).toList(); + if (!phoneNumbers.isEmpty()) { + QDeclarativeContactDetail *primaryPhone = qobject_cast<QDeclarativeContactDetail*>(phoneNumbers.at(0).value<QObject *>()); + return primaryPhone->value(); + } else { + return QString(); + } } /*! @@ -591,17 +607,15 @@ QString QDeclarativePlace::primaryPhone() const This property holds the primary fax number of the place. */ -void QDeclarativePlace::setPrimaryFax(const QString &fax) -{ - if (m_src.primaryFax() != fax) { - m_src.setPrimaryFax(fax); - emit primaryFaxChanged(); - } -} - QString QDeclarativePlace::primaryFax() const { - return m_src.primaryFax(); + QVariantList faxNumbers = m_contactDetails->value(QPlaceContactDetail::Fax).toList(); + if (!faxNumbers.isEmpty()) { + QDeclarativeContactDetail *primaryFax = qobject_cast<QDeclarativeContactDetail*>(faxNumbers.at(0).value<QObject *>()); + return primaryFax->value(); + } else { + return QString(); + } } /*! @@ -609,35 +623,32 @@ QString QDeclarativePlace::primaryFax() const This property holds the primary email address of the place. */ -void QDeclarativePlace::setPrimaryEmail(const QString &email) -{ - if (m_src.primaryEmail() != email) { - m_src.setPrimaryEmail(email); - emit primaryEmailChanged(); - } -} - QString QDeclarativePlace::primaryEmail() const { - return m_src.primaryEmail(); + QVariantList emailAddresses = m_contactDetails->value(QPlaceContactDetail::Email).toList(); + if (!emailAddresses.isEmpty()) { + QDeclarativeContactDetail *primaryEmail = qobject_cast<QDeclarativeContactDetail*>(emailAddresses.at(0).value<QObject *>()); + return primaryEmail->value(); + } else { + return QString(); + } } /*! - \qmlproperty string Place::primaryUrl + \qmlproperty string Place::primaryWebsite - This property holds the primary website address of the place. + This property holds the primary website url of the place. */ -void QDeclarativePlace::setPrimaryUrl(const QUrl &url) -{ - if (m_src.primaryUrl() != url) { - m_src.setPrimaryUrl(url); - emit primaryUrlChanged(); - } -} -QUrl QDeclarativePlace::primaryUrl() const +QUrl QDeclarativePlace::primaryWebsite() const { - return m_src.primaryUrl(); + QVariantList websites = m_contactDetails->value(QPlaceContactDetail::Website).toList(); + if (!websites.isEmpty()) { + QDeclarativeContactDetail *primaryWebsite = qobject_cast<QDeclarativeContactDetail*>(websites.at(0).value<QObject *>()); + return primaryWebsite->value(); + } else { + return QUrl(); + } } /*! @@ -666,6 +677,27 @@ QDeclarativePropertyMap *QDeclarativePlace::extendedAttributes() const } /*! + \qmlproperty Contacts contacts + This property holds the contact information for this place. +*/ +void QDeclarativePlace::setContactDetails(QDeclarativePropertyMap *contactDetails) +{ + if (m_contactDetails == contactDetails) + return; + + if (m_contactDetails && m_contactDetails->parent() == this) + delete m_contactDetails; + + m_contactDetails = contactDetails; + emit contactDetailsChanged(); +} + +QDeclarativePropertyMap *QDeclarativePlace::contactDetails() const +{ + return m_contactDetails; +} + +/*! \qmlproperty QDeclarativeListProperty<QDeclarativeCategory> Place::categories This property categories list. @@ -764,6 +796,75 @@ void QDeclarativePlace::synchronizeExtendedAttributes() emit extendedAttributesChanged(); } +void QDeclarativePlace::synchronizeContacts() +{ + //clear out contact data + foreach (const QString &contactType, m_contactDetails->keys()) { + QList<QVariant> contacts = m_contactDetails->value(contactType).toList(); + foreach (const QVariant &var, contacts) { + QObject *obj = var.value<QObject*>(); + if (obj->parent() == this) + delete obj; + } + m_contactDetails->insert(contactType, QVariantList()); + } + + //insert new contact data from source place + foreach (const QString &contactType, m_src.contactTypes()) { + QList<QPlaceContactDetail> sourceContacts = m_src.contactDetails(contactType); + QVariantList declContacts; + foreach (const QPlaceContactDetail &sourceContact, sourceContacts) { + QDeclarativeContactDetail *declContact = new QDeclarativeContactDetail(this); + declContact->setContactDetail(sourceContact); + declContacts.append(QVariant::fromValue(qobject_cast<QObject *>(declContact))); + } + m_contactDetails->insert(contactType, declContacts); + } + primarySignalsEmission(); +} + +/* + Helper function to emit the signals for the primary___() + fields. It is expected that the values of the primary___() + functions have alread been modified to new values. +*/ +void QDeclarativePlace::primarySignalsEmission(const QString &type) +{ + if (type.isEmpty() || type == QPlaceContactDetail::Phone) { + if (m_prevPrimaryPhone != primaryPhone()) { + m_prevPrimaryPhone = primaryPhone(); + emit primaryPhoneChanged(); + } + if (!type.isEmpty()) + return; + } + + if (type.isEmpty() || type == QPlaceContactDetail::Email) { + if (m_prevPrimaryEmail != primaryEmail()) { + m_prevPrimaryEmail = primaryEmail(); + emit primaryEmailChanged(); + } + if (!type.isEmpty()) + return; + } + + if (type.isEmpty() || type == QPlaceContactDetail::Website) { + if (m_prevPrimaryWebsite != primaryWebsite()) { + m_prevPrimaryWebsite = primaryWebsite(); + emit primaryWebsiteChanged(); + } + if (!type.isEmpty()) + return; + } + + if (type.isEmpty() || type == QPlaceContactDetail::Fax) { + if (m_prevPrimaryFax != primaryFax()) { + m_prevPrimaryFax = primaryFax(); + emit primaryFaxChanged(); + } + } +} + /* Helper function to return the manager, this manager is intended to be used to perform the next operation. If a an operation is currently underway diff --git a/src/imports/location/declarativeplaces/qdeclarativeplace_p.h b/src/imports/location/declarativeplaces/qdeclarativeplace_p.h index d379854f..00946790 100644 --- a/src/imports/location/declarativeplaces/qdeclarativeplace_p.h +++ b/src/imports/location/declarativeplaces/qdeclarativeplace_p.h @@ -47,6 +47,7 @@ #include <qplace.h> #include "qdeclarativegeolocation_p.h" #include "qdeclarativecategory_p.h" +#include "qdeclarativecontactdetail_p.h" #include "qdeclarativesupplier_p.h" #include "qdeclarativerating_p.h" #include "qdeclarativereviewmodel_p.h" @@ -82,13 +83,14 @@ class QDeclarativePlace : public QObject, public QDeclarativeParserStatus Q_PROPERTY(QDeclarativePlaceEditorialModel *editorialModel READ editorialModel NOTIFY editorialModelChanged) Q_PROPERTY(QDeclarativePropertyMap *extendedAttributes READ extendedAttributes WRITE setExtendedAttributes NOTIFY extendedAttributesChanged); + Q_PROPERTY(QDeclarativePropertyMap *contactDetails READ contactDetails WRITE setContactDetails NOTIFY contactDetailsChanged); Q_PROPERTY(bool detailsFetched READ detailsFetched WRITE setDetailsFetched NOTIFY detailsFetchedChanged); Q_PROPERTY(Status status READ status NOTIFY statusChanged); - Q_PROPERTY(QString primaryPhone READ primaryPhone WRITE setPrimaryPhone NOTIFY primaryPhoneChanged); - Q_PROPERTY(QString primaryFax READ primaryFax WRITE setPrimaryFax NOTIFY primaryFaxChanged); - Q_PROPERTY(QString primaryEmail READ primaryEmail WRITE setPrimaryEmail NOTIFY primaryEmailChanged); - Q_PROPERTY(QUrl primaryUrl READ primaryUrl WRITE setPrimaryUrl NOTIFY primaryUrlChanged); + Q_PROPERTY(QString primaryPhone READ primaryPhone NOTIFY primaryPhoneChanged); + Q_PROPERTY(QString primaryFax READ primaryFax NOTIFY primaryFaxChanged); + Q_PROPERTY(QString primaryEmail READ primaryEmail NOTIFY primaryEmailChanged); + Q_PROPERTY(QUrl primaryWebsite READ primaryWebsite NOTIFY primaryWebsiteChanged); Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged) @@ -154,20 +156,16 @@ public: Q_INVOKABLE QString errorString() const; QString primaryPhone() const; - void setPrimaryPhone(const QString &phone); - QString primaryFax() const; - void setPrimaryFax(const QString &fax); - QString primaryEmail() const; - void setPrimaryEmail(const QString &email); - - QUrl primaryUrl() const; - void setPrimaryUrl(const QUrl &url); + QUrl primaryWebsite() const; QDeclarativePropertyMap *extendedAttributes() const; void setExtendedAttributes(QDeclarativePropertyMap *attrib); + QDeclarativePropertyMap *contactDetails() const; + void setContactDetails(QDeclarativePropertyMap *contactDetails); + Visibility visibility() const; void setVisibility(Visibility visibility); @@ -189,18 +187,22 @@ signals: void primaryPhoneChanged(); void primaryFaxChanged(); void primaryEmailChanged(); - void primaryUrlChanged(); + void primaryWebsiteChanged(); void extendedAttributesChanged(); + void contactDetailsChanged(); void statusChanged(); void visibilityChanged(); private slots: void finished(); + void contactsModified(const QString &, const QVariant &); private: void synchronizeCategories(); void synchronizeExtendedAttributes(); + void synchronizeContacts(); + void primarySignalsEmission(const QString &type = QString()); private: QPlaceManager *manager(); @@ -214,6 +216,7 @@ private: QDeclarativePlaceImageModel *m_imageModel; QDeclarativePlaceEditorialModel *m_editorialModel; QDeclarativePropertyMap *m_extendedAttributes; + QDeclarativePropertyMap *m_contactDetails; QPlace m_src; @@ -222,6 +225,11 @@ private: QDeclarativeGeoServiceProvider *m_plugin; bool m_complete; + QString m_prevPrimaryPhone; + QString m_prevPrimaryEmail; + QString m_prevPrimaryFax; + QUrl m_prevPrimaryWebsite; + Status m_status; QString m_errorString; }; diff --git a/src/imports/location/location.cpp b/src/imports/location/location.cpp index 9a8e8186..a1d0fa57 100644 --- a/src/imports/location/location.cpp +++ b/src/imports/location/location.cpp @@ -72,6 +72,7 @@ #include "qdeclarativerating_p.h" #include "qdeclarativesupplier_p.h" #include "qdeclarativeplaceuser_p.h" +#include "qdeclarativecontactdetail_p.h" #include "qdeclarativerecommendationmodel_p.h" #include "qdeclarativesupportedcategoriesmodel_p.h" @@ -142,6 +143,8 @@ public: qmlRegisterType<QDeclarativeTextPredictionModel>(uri, 5, 0, "TextPredictionModel"); qmlRegisterType<QDeclarativePropertyMap>(uri, 5,0,"ExtendedAttributes"); qmlRegisterType<QDeclarativePlaceAttribute>(uri, 5,0, "PlaceAttribute"); + qmlRegisterType<QDeclarativeContactDetail>(uri, 5, 0, "ContactDetail"); + } else { qDebug() << "Unsupported URI given to load location QML plugin: " << QLatin1String(uri); } diff --git a/src/location/places/places.pri b/src/location/places/places.pri index b0fb97fc..34978b6b 100644 --- a/src/location/places/places.pri +++ b/src/location/places/places.pri @@ -1,10 +1,10 @@ -#TODO: remove when plugin is refactored out INCLUDEPATH += places PUBLIC_HEADERS += \ places/placemacro.h \ #data classes places/qplaceattribute.h \ + places/qplacecontactdetail.h \ places/qplacecategory.h \ places/qplacecontent.h \ places/qplacecontentreply.h \ @@ -35,6 +35,7 @@ PRIVATE_HEADERS += \ places/qplaceattribute_p.h \ places/qplacecategory_p.h \ places/qplacecontent_p.h \ + places/qplacecontactdetail_p.h \ places/qplaceeditorial_p.h \ places/qplaceicon_p.h \ places/qplaceimage_p.h \ @@ -52,6 +53,7 @@ SOURCES += \ #data classes places/qplaceattribute.cpp \ places/qplacecategory.cpp \ + places/qplacecontactdetail.cpp \ places/qplacecontent.cpp \ places/qplacecontentreply.cpp \ places/qplaceeditorial.cpp \ diff --git a/src/location/places/qplacecontactdetail.cpp b/src/location/places/qplacecontactdetail.cpp new file mode 100644 index 00000000..a29529b5 --- /dev/null +++ b/src/location/places/qplacecontactdetail.cpp @@ -0,0 +1,176 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qplacecontactdetail_p.h" +#include "qplacecontactdetail.h" + +QT_USE_NAMESPACE + +QPlaceContactDetailPrivate::QPlaceContactDetailPrivate(const QPlaceContactDetailPrivate &other) + : QSharedData(other), + label(other.label), + value(other.value) +{ +} + +bool QPlaceContactDetailPrivate::operator== (const QPlaceContactDetailPrivate &other) const +{ + return label == other.label + && value == other.value; +} + +/*! +\class QPlaceContactDetail +\brief The QPlaceContactDetail class represents a contact detail such as a phone number or url. +\inmodule QtLocation + +\ingroup QtLocation-places + +*/ + +/*! + \variable QPlaceContactDetail::Phone + The constant to specify phone contact details +*/ +Q_DEFINE_LATIN1_CONSTANT(QPlaceContactDetail::Phone, "Phone"); + +/*! + \variable QPlaceContactDetail::Email + The constant to specify email contact contact details. +*/ +Q_DEFINE_LATIN1_CONSTANT(QPlaceContactDetail::Email, "Email"); + +/*! + \variable QPlaceContactDetail::Website + The constant used to specify website contact details. +*/ +Q_DEFINE_LATIN1_CONSTANT(QPlaceContactDetail::Website, "Website"); + +/*! + \variable QPlaceContactDetail::Fax + The constant used to specify fax contact details. +*/ +Q_DEFINE_LATIN1_CONSTANT(QPlaceContactDetail::Fax, "Fax"); + +/*! + Constructs an contact detail. +*/ +QPlaceContactDetail::QPlaceContactDetail() + : d_ptr(new QPlaceContactDetailPrivate) +{ +} + +/*! + Destroys the contact detail. +*/ +QPlaceContactDetail::~QPlaceContactDetail() +{ +} + +/*! + Creates a copy of \a other. +*/ +QPlaceContactDetail::QPlaceContactDetail(const QPlaceContactDetail &other) + :d_ptr(other.d_ptr) +{ +} + +/*! + Assigns \a other to this contact detail and returns a reference to this + contact detail. +*/ +QPlaceContactDetail &QPlaceContactDetail::operator=(const QPlaceContactDetail &other) +{ + d_ptr = other.d_ptr; + return *this; +} + +/*! + Returns true if \a other is equal to this contact detail, otherwise + returns false. +*/ +bool QPlaceContactDetail::operator== (const QPlaceContactDetail &other) const +{ + if (d_ptr == other.d_ptr) + return true; + return ( *(d_ptr.constData()) == *(other.d_ptr.constData())); +} + +/*! + Returns true if \a other is not equal to this contact detail, + otherwise returns false. +*/ +bool QPlaceContactDetail::operator!= (const QPlaceContactDetail &other) const +{ + return (!this->operator ==(other)); +} + +/*! + Returns a localized label describing the contact detail. +*/ +QString QPlaceContactDetail::label() const +{ + return d_ptr->label; +} + +/*! + Sets the \a label of the contact detail. +*/ +void QPlaceContactDetail::setLabel(const QString &label) +{ + d_ptr->label = label; +} + +/*! + Returns the value of the contact detail. +*/ +QString QPlaceContactDetail::value() const +{ + return d_ptr->value; +} + +/*! + Sets the \a value of the this contact detail. +*/ +void QPlaceContactDetail::setValue(const QString &value) +{ + d_ptr->value = value; +} diff --git a/src/location/places/qplacecontactdetail.h b/src/location/places/qplacecontactdetail.h new file mode 100644 index 00000000..ba65e324 --- /dev/null +++ b/src/location/places/qplacecontactdetail.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPLACECONTACTDETAIL_H +#define QPLACECONTACTDETAIL_H + +#include <QString> +#include <QVariant> +#include <QSharedDataPointer> +#include <QLatin1Constant> + +#include <QtLocation/qlocationglobal.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QPlaceContactDetailPrivate; +class Q_LOCATION_EXPORT QPlaceContactDetail +{ +public: +#ifdef Q_QDOC + static const QLatin1Constant Phone; + static const QLatin1Constant Email; + static const QLatin1Constant Website; + static const QLatin1Constant Fax; +#else + Q_DECLARE_LATIN1_CONSTANT(Phone, "Phone"); + Q_DECLARE_LATIN1_CONSTANT(Email, "Email"); + Q_DECLARE_LATIN1_CONSTANT(Website, "Website"); + Q_DECLARE_LATIN1_CONSTANT(Fax, "Fax"); +#endif + + QPlaceContactDetail(); + QPlaceContactDetail(const QPlaceContactDetail &other); + virtual ~QPlaceContactDetail(); + + QPlaceContactDetail &operator=(const QPlaceContactDetail &other); + + bool operator==(const QPlaceContactDetail &other) const; + bool operator!=(const QPlaceContactDetail &other) const; + + QString label() const; + void setLabel(const QString &label); + + QString value() const; + void setValue(const QString &value); + +private: + QSharedDataPointer<QPlaceContactDetailPrivate> d_ptr; + +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QPlaceContactDetail)); + +#endif diff --git a/src/location/places/qplacecontactdetail_p.h b/src/location/places/qplacecontactdetail_p.h new file mode 100644 index 00000000..94c4ed44 --- /dev/null +++ b/src/location/places/qplacecontactdetail_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPLACECONTACTDETAIL_P_H +#define QPLACECONTACTDETAIL_P_H + + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QSharedData> +#include <QString> + +QT_BEGIN_NAMESPACE + +class QPlaceContactDetailPrivate : public QSharedData +{ +public: + QPlaceContactDetailPrivate(){} + QPlaceContactDetailPrivate(const QPlaceContactDetailPrivate &other); + virtual ~QPlaceContactDetailPrivate(){} + + bool operator== (const QPlaceContactDetailPrivate &other) const; + + QString label; + QString value; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/location/qplace.cpp b/src/location/qplace.cpp index b8ae333f..361b995f 100644 --- a/src/location/qplace.cpp +++ b/src/location/qplace.cpp @@ -46,6 +46,8 @@ #include <QDebug> #endif +#include <QStringList> + QT_BEGIN_NAMESPACE /*! @@ -328,106 +330,127 @@ void QPlace::setIcon(const QPlaceIcon &icon) QString QPlace::primaryPhone() const { Q_D(const QPlace); - return d->primaryPhone; + QList<QPlaceContactDetail> phoneNumbers = d->contacts.value(QPlaceContactDetail::Phone); + if (!phoneNumbers.isEmpty()) + return phoneNumbers.at(0).value(); + else + return QString(); } /*! - Sets the primary \a phone number of this place. + Returns the primary fax number for this place. */ -void QPlace::setPrimaryPhone(const QString &phone) +QString QPlace::primaryFax() const { - Q_D(QPlace); - d->primaryPhone = phone; + Q_D(const QPlace); + QList<QPlaceContactDetail> faxNumbers = d->contacts.value(QPlaceContactDetail::Fax); + if (!faxNumbers.isEmpty()) + return faxNumbers.at(0).value(); + else + return QString(); } /*! - Returns the primary fax number for this place. + Returns the primary email address for this place. */ -QString QPlace::primaryFax() const +QString QPlace::primaryEmail() const { Q_D(const QPlace); - return d->primaryFax; + QList<QPlaceContactDetail> emailAddresses = d->contacts.value(QPlaceContactDetail::Email); + if (!emailAddresses.isEmpty()) + return emailAddresses.at(0).value(); + else + return QString(); } /*! - Sets the primary \a fax number for this place + Returns the primary URL of this place. */ -void QPlace::setPrimaryFax(const QString fax) +QUrl QPlace::primaryWebsite() const { - Q_D(QPlace); - d->primaryFax = fax; + Q_D(const QPlace); + QList<QPlaceContactDetail> websites = d->contacts.value(QPlaceContactDetail::Website); + if (!websites.isEmpty()) + return QUrl(websites.at(0).value().toAscii()); + else + return QString(); } /*! - Returns the primary email address for this place. + Returns whether the details of this place have been fetched or not. */ -QString QPlace::primaryEmail() const +bool QPlace::detailsFetched() const { Q_D(const QPlace); - return d->primaryEmail; + return d->detailsFetched; } /*! - Sets the primary \a email address for this place. + Sets whether the details of this place have been \a fetched or not. */ -void QPlace::setPrimaryEmail(const QString &email) +void QPlace::setDetailsFetched(bool fetched) { Q_D(QPlace); - d->primaryEmail = email; + d->detailsFetched = fetched; } /*! - Returns the primary URL of this place. + Returns the extended attributes of the place */ -QUrl QPlace::primaryUrl() const +QPlace::ExtendedAttributes QPlace::extendedAttributes() const { Q_D(const QPlace); - return d->primaryUrl; + return d->extendedAttributes; } /*! - Sets the primary \a url of this place. + Sets the extended attributes of the place. */ -void QPlace::setPrimaryUrl(const QUrl &url) +void QPlace::setExtendedAttributes(const ExtendedAttributes &attributes) { Q_D(QPlace); - d->primaryUrl = url; + d->extendedAttributes = attributes; } /*! - Returns whether the details of this place have been fetched or not. + Returns the type of contact details this place has. */ -bool QPlace::detailsFetched() const +QStringList QPlace::contactTypes() const { Q_D(const QPlace); - return d->detailsFetched; + return d->contacts.keys(); } /*! - Sets whether the details of this place have been \a fetched or not. + Returns a list of contact details of the specified \a contactType */ -void QPlace::setDetailsFetched(bool fetched) +QList<QPlaceContactDetail> QPlace::contactDetails(const QString &contactType) { - Q_D(QPlace); - d->detailsFetched = fetched; + Q_D(const QPlace); + return d->contacts.value(contactType); } /*! - Returns the extended attributes of the place + Sets the contact \a details of a specified \a contactType. */ -QPlace::ExtendedAttributes QPlace::extendedAttributes() const +void QPlace::setContactDetails(const QString &contactType, QList<QPlaceContactDetail> details) { - Q_D(const QPlace); - return d->extendedAttributes; + Q_D(QPlace); + if (details.isEmpty()) + d->contacts.remove(contactType); + else + d->contacts.insert(contactType, details); } /*! - Sets the extended attributes of the place. + Appends a contact \a detail of a specified \a contactType. */ -void QPlace::setExtendedAttributes(const ExtendedAttributes &attributes) +void QPlace::appendContactDetail(const QString &contactType, const QPlaceContactDetail &detail) { Q_D(QPlace); - d->extendedAttributes = attributes; + QList<QPlaceContactDetail> details = d->contacts.value(contactType); + details.append(detail); + d->contacts.insert(contactType, details); } /*! @@ -477,10 +500,7 @@ QPlacePrivate::QPlacePrivate(const QPlacePrivate &other) attribution(other.attribution), contentCollections(other.contentCollections), contentCounts(other.contentCounts), - primaryPhone(other.primaryPhone), - primaryFax(other.primaryFax), - primaryEmail(other.primaryEmail), - primaryUrl(other.primaryUrl), + contacts(other.contacts), extendedAttributes(other.extendedAttributes), visibility(other.visibility), detailsFetched(other.detailsFetched) @@ -500,10 +520,7 @@ QPlacePrivate& QPlacePrivate::operator= (const QPlacePrivate & other) attribution = other.attribution; contentCollections = other.contentCollections; contentCounts = other.contentCounts; - primaryPhone = other.primaryPhone; - primaryFax = other.primaryFax; - primaryEmail = other.primaryEmail; - primaryUrl = other.primaryUrl; + contacts = other.contacts; extendedAttributes = other.extendedAttributes; visibility = other.visibility; detailsFetched = other.detailsFetched; @@ -523,10 +540,7 @@ bool QPlacePrivate::operator== (const QPlacePrivate &other) const qDebug() << "name " << (name == other.name); qDebug() << "placeId" << (placeId == other.placeId); qDebug() << "attribution" << (attribution == other.attribution); - qDebug() << "phone" << (primaryPhone == other.primaryPhone); - qDebug() << "fax" << (primaryFax == other.primaryFax); - qDebug() << "email" << (primaryEmail == other.primaryEmail); - qDebug() << "url" << (primaryUrl == other.primaryUrl); + qDebug() << "contacts" << (contacts == other.contacts); qDebug() << "extendedAttributes" << (extendedAttributes == other.extendedAttributes); qDebug() << "visibility" << (visibility == other.visibility); #endif @@ -540,14 +554,10 @@ bool QPlacePrivate::operator== (const QPlacePrivate &other) const && name == other.name && placeId == other.placeId && attribution == other.attribution - && primaryPhone == other.primaryPhone - && primaryFax == other.primaryFax - && primaryEmail == other.primaryEmail - && primaryUrl == other.primaryUrl + && contacts == other.contacts && extendedAttributes == other.extendedAttributes && visibility == other.visibility ); } QT_END_NAMESPACE - diff --git a/src/location/qplace.h b/src/location/qplace.h index 9b785f86..7686551e 100644 --- a/src/location/qplace.h +++ b/src/location/qplace.h @@ -54,6 +54,7 @@ #include "qplacerating.h" #include "qplacereview.h" #include "qplaceattribute.h" +#include "qplacecontactdetail.h" QT_BEGIN_HEADER @@ -107,16 +108,9 @@ public: void setPlaceId(const QString &placeId); QString primaryPhone() const; - void setPrimaryPhone(const QString &phone); - QString primaryFax() const; - void setPrimaryFax(const QString fax); - QString primaryEmail() const; - void setPrimaryEmail(const QString &email); - - QUrl primaryUrl() const; - void setPrimaryUrl(const QUrl &url); + QUrl primaryWebsite() const; bool detailsFetched() const; void setDetailsFetched(bool fetched); @@ -125,6 +119,11 @@ public: void setExtendedAttributes(const QPlace::ExtendedAttributes &attributes); void insertExtendedAttribute(const QString &key, const QPlaceAttribute &); + QStringList contactTypes() const; + QList<QPlaceContactDetail> contactDetails(const QString &contactType); + void setContactDetails(const QString &contactType, QList<QPlaceContactDetail> details); + void appendContactDetail(const QString &contactType, const QPlaceContactDetail &detail); + QtLocation::Visibility visibility() const; void setVisibility(QtLocation::Visibility visibility); diff --git a/src/location/qplace_p.h b/src/location/qplace_p.h index 00d57a67..6db6d650 100644 --- a/src/location/qplace_p.h +++ b/src/location/qplace_p.h @@ -87,12 +87,8 @@ public: QMap<QPlaceContent::Type, QPlaceContent::Collection> contentCollections; QMap<QPlaceContent::Type, int> contentCounts; - QString primaryPhone; - QString primaryFax; - QString primaryEmail; - QUrl primaryUrl; - QPlace::ExtendedAttributes extendedAttributes; + QMap<QString, QList<QPlaceContactDetail> > contacts; QtLocation::Visibility visibility; QPlaceIcon icon; diff --git a/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.cpp b/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.cpp index a0e2f7ce..9b9cfef0 100644 --- a/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.cpp +++ b/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.cpp @@ -53,6 +53,7 @@ #include <QtScript/QScriptEngine> #include <QtScript/QScriptValue> #include <QtScript/QScriptValueIterator> +#include <QtLocation/QPlaceContactDetail> #include <qgeoaddress.h> #include <qgeocoordinate.h> @@ -297,32 +298,25 @@ void QPlaceJSonDetailsParser::processMainProvider(const QScriptValue &placeValue void QPlaceJSonDetailsParser::processContacts(const QScriptValue &contactsValue, QPlace *targetPlace) { QScriptValueIterator it(contactsValue); - bool phoneRetrieved = false; - bool faxRetrieved = false; - bool emailRetrieved = false; - bool urlRetrieved = false; + QPlaceContactDetail contactDetail; while (it.hasNext()) { it.next(); if (it.name() == place_contact_website_element) { - if (!urlRetrieved) { - targetPlace->setPrimaryUrl(QUrl::fromEncoded(it.value().toString().toAscii())); - urlRetrieved = true; - } + contactDetail.setLabel(tr("Website")); + contactDetail.setValue(it.value().toString()); + targetPlace->appendContactDetail(QPlaceContactDetail::Website, contactDetail); } else if (it.name() == place_contact_phone_element) { - if (!phoneRetrieved) { - targetPlace->setPrimaryPhone(it.value().toString()); - phoneRetrieved = true; - } + contactDetail.setLabel(tr("Phone")); + contactDetail.setValue(it.value().toString()); + targetPlace->appendContactDetail(QPlaceContactDetail::Phone, contactDetail); } else if (it.name() == place_contact_fax_element) { - if (!faxRetrieved) { - targetPlace->setPrimaryFax(it.value().toString()); - faxRetrieved = true; - } + contactDetail.setLabel(tr("Fax")); + contactDetail.setValue(it.value().toString()); + targetPlace->appendContactDetail(QPlaceContactDetail::Fax, contactDetail); } else if (it.name() == place_contact_email_element) { - if (!emailRetrieved) { - targetPlace->setPrimaryEmail(it.value().toString()); - faxRetrieved = true; - } + contactDetail.setLabel(tr("Email")); + contactDetail.setValue(it.value().toString()); + targetPlace->appendContactDetail(QPlaceContactDetail::Email, contactDetail); } else { //unknown contact element, do nothing } diff --git a/src/plugins/geoservices/nokia/places/qplacejsonsearchparser.cpp b/src/plugins/geoservices/nokia/places/qplacejsonsearchparser.cpp index 1217c69a..8fac0b10 100644 --- a/src/plugins/geoservices/nokia/places/qplacejsonsearchparser.cpp +++ b/src/plugins/geoservices/nokia/places/qplacejsonsearchparser.cpp @@ -226,11 +226,17 @@ void QPlaceJSonSearchParser::processContacts(const QScriptValue &properties, QPl { QScriptValue value = properties.property(search_properties_url_value); if (value.isValid() && !value.toString().isEmpty()) { - place->setPrimaryUrl(QUrl::fromEncoded(value.toString().toAscii())); + QPlaceContactDetail contactDetail; + contactDetail.setLabel(tr("Website")); + contactDetail.setValue(value.toString()); + place->appendContactDetail(QPlaceContactDetail::Website, contactDetail); } value = properties.property(search_properties_phone_value); if (value.isValid() && !value.toString().isEmpty()) { - place->setPrimaryPhone(value.toString()); + QPlaceContactDetail contactDetail; + contactDetail.setLabel(tr("Phone")); + contactDetail.setValue(value.toString()); + place->appendContactDetail(QPlaceContactDetail::Phone, contactDetail); } } diff --git a/tests/auto/declarative/tst_place.qml b/tests/auto/declarative/tst_place.qml index 051b73dd..20704de0 100644 --- a/tests/auto/declarative/tst_place.qml +++ b/tests/auto/declarative/tst_place.qml @@ -64,11 +64,6 @@ TestCase { name: "Test place" - primaryPhone: "11111111" - primaryFax: "22222222" - primaryEmail: "test-place@example.com" - primaryUrl: "http://www.example.com/test-place" - visibility: Place.DeviceVisibility location: Location { @@ -281,7 +276,7 @@ TestCase { compare(emptyPlace.primaryPhone, ""); compare(emptyPlace.primaryFax, ""); compare(emptyPlace.primaryEmail, ""); - compare(emptyPlace.primaryUrl, ""); + compare(emptyPlace.primaryWebsite, ""); compare(emptyPlace.visibility, Place.UnspecifiedVisibility); // complex properties @@ -314,10 +309,6 @@ TestCase { return [ { tag: "name", property: "name", signal: "nameChanged", value: "Test Place", reset: "" }, { tag: "placeId", property: "placeId", signal: "placeIdChanged", value: "test-place-id-1", reset: "" }, - { tag: "primaryPhone", property: "primaryPhone", signal: "primaryPhoneChanged", value: "11111111", reset: "" }, - { tag: "primaryFax", property: "primaryFax", signal: "primaryFaxChanged", value: "22222222", reset: "" }, - { tag: "primaryEmail", property: "primaryEmail", signal: "primaryEmailChanged", value: "test@example.com", reset: "" }, - { tag: "primaryUrl", property: "primaryUrl", signal: "primaryUrlChanged", value: "http://www.example.com/test-place-id-1", reset: "" }, { tag: "visibility", property: "visibility", signal: "visibilityChanged", value: Place.PublicVisibility, reset: Place.UnspecifiedVisibility }, ]; } diff --git a/tests/auto/qplace/tst_qplace.cpp b/tests/auto/qplace/tst_qplace.cpp index ad251203..c245fb25 100644 --- a/tests/auto/qplace/tst_qplace.cpp +++ b/tests/auto/qplace/tst_qplace.cpp @@ -73,7 +73,7 @@ private Q_SLOTS: void primaryPhoneTest(); void primaryFaxTest(); void primaryEmailTest(); - void primaryUrlTest(); + void primaryWebsiteTest(); void operatorsTest(); void extendedAttributeTest(); void visibilityTest(); @@ -352,48 +352,67 @@ void tst_Place::primaryPhoneTest() QPlace place; QVERIFY2(place.primaryPhone().isEmpty(), "Wrong default value"); - place.setPrimaryPhone("555-5555"); + QPlaceContactDetail contactDetail; + contactDetail.setLabel(QLatin1String("Phone")); + contactDetail.setValue(QLatin1String("555-5555")); + place.appendContactDetail(QPlaceContactDetail::Phone, contactDetail); + QCOMPARE(place.primaryPhone(), QString("555-5555")); - place.setPrimaryPhone(QString()); + //try clearing the primary phone number + place.setContactDetails(QPlaceContactDetail::Phone, QList<QPlaceContactDetail>()); QCOMPARE(place.primaryPhone(), QString()); } -void tst_Place::primaryFaxTest() +void tst_Place::primaryEmailTest() { QPlace place; - QVERIFY2(place.primaryFax().isEmpty(), "Wrong default value"); + QVERIFY2(place.primaryEmail().isEmpty(), "Wrong default value"); - place.setPrimaryFax("555-5555"); - QCOMPARE(place.primaryFax(), QString("555-5555")); + QPlaceContactDetail contactDetail; + contactDetail.setLabel(QLatin1String("Email")); + contactDetail.setValue(QLatin1String("test@test.com")); + place.appendContactDetail(QPlaceContactDetail::Email, contactDetail); - place.setPrimaryFax(QString()); - QCOMPARE(place.primaryFax(), QString()); + QCOMPARE(place.primaryEmail(), QLatin1String("test@test.com")); + + //try clearing the primary email address + place.setContactDetails(QPlaceContactDetail::Email, QList<QPlaceContactDetail>()); + QCOMPARE(place.primaryEmail(), QString()); } -void tst_Place::primaryEmailTest() +void tst_Place::primaryFaxTest() { QPlace place; - QVERIFY2(place.primaryEmail().isEmpty(), "Wrong default value"); + QVERIFY2(place.primaryFax().isEmpty(), "Wrong default value"); - place.setPrimaryEmail("test@test.com"); - QCOMPARE(place.primaryEmail(), QString("test@test.com")); + QPlaceContactDetail contactDetail; + contactDetail.setLabel(QLatin1String("Fax")); + contactDetail.setValue(QLatin1String("555-5555")); + place.appendContactDetail(QPlaceContactDetail::Fax, contactDetail); + QCOMPARE(place.primaryFax(), QLatin1String("555-5555")); - place.setPrimaryEmail(QString()); - QCOMPARE(place.primaryEmail(), QString()); + //try clearing the primary fax number + place.setContactDetails(QPlaceContactDetail::Fax, QList<QPlaceContactDetail>()); + QCOMPARE(place.primaryFax(), QString()); } -void tst_Place::primaryUrlTest() +void tst_Place::primaryWebsiteTest() { QPlace place; - QVERIFY2(place.primaryUrl().isEmpty(), "Wron default value"); + QVERIFY2(place.primaryWebsite().isEmpty(), "Wrong default value"); + + QPlaceContactDetail contactDetail; + contactDetail.setLabel(QLatin1String("Website")); + contactDetail.setValue(QLatin1String("www.example.com")); + place.appendContactDetail(QPlaceContactDetail::Website, contactDetail); - place.setPrimaryUrl(QUrl("www.winterfell.com")); - QCOMPARE(place.primaryUrl(), QUrl("www.winterfell.com")); + QCOMPARE(place.primaryWebsite(), QUrl("www.example.com")); - place.setPrimaryUrl(QUrl()); - QCOMPARE(place.primaryUrl(), QUrl()); + //try clearing the primary website number + place.setContactDetails(QPlaceContactDetail::Website, QList<QPlaceContactDetail>()); + QCOMPARE(place.primaryWebsite(), QUrl()); } void tst_Place::operatorsTest() |