summaryrefslogtreecommitdiff
path: root/src/imports/location/declarativeplaces/qdeclarativeplace.cpp
blob: da968b243529c28dc055d6cde7563075a66100f7 (plain)
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
/****************************************************************************
**
** 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 tOhe 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 "qdeclarativeplace_p.h"
#include "qdeclarativegeoserviceprovider_p.h"
#include "qdeclarativeplaceattribute_p.h"

#include <QtDeclarative/QDeclarativeInfo>
#include <QtLocation/QGeoServiceProvider>
#include <QtLocation/QPlaceManager>
#include <QtLocation/QPlaceDetailsReply>
#include <QtLocation/QPlaceReply>
#include <QtLocation/QPlaceIdReply>

QT_USE_NAMESPACE

/*!
    \qmlclass Place

    \brief The Place element holds place data.
    \inherits QObject

    Place cointains many properties holding data of the place like location,
    id, name etc.

    \ingroup qml-places
*/

QDeclarativePlace::QDeclarativePlace(QObject* parent)
:   QObject(parent), m_reviewModel(0), m_imageModel(0), m_extendedAttributes(new QDeclarativePropertyMap()),
    m_reply(0), m_plugin(0),m_complete(false), m_status(QDeclarativePlace::Ready)
{
}

QDeclarativePlace::QDeclarativePlace(const QPlace &src, QObject *parent)
:   QObject(parent), m_reviewModel(0), m_imageModel(0), m_extendedAttributes(new QDeclarativePropertyMap()),
    m_src(src), m_reply(0), m_plugin(0), m_complete(false),
    m_status(QDeclarativePlace::Ready)
{
    synchronizeCategories();
    synchronizeDescriptions();
    synchronizeSuppliers();
    synchronizeExtendedAttributes();

    m_rating.setRating(m_src.rating());
    m_location.setLocation(m_src.location());
}

QDeclarativePlace::~QDeclarativePlace()
{
}

// From QDeclarativeParserStatus
void QDeclarativePlace::componentComplete()
{
    m_complete = true;
}

void QDeclarativePlace::setPlugin(QDeclarativeGeoServiceProvider *plugin)
{
    if (m_plugin == plugin)
        return;

    m_plugin = plugin;
    if (m_complete)
        emit pluginChanged();
    QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider();
    QPlaceManager *placeManager = serviceProvider->placeManager();
    if (!placeManager || serviceProvider->error() != QGeoServiceProvider::NoError) {
        qmlInfo(this) << tr("Warning: Plugin does not support places.");
        return;
    }
}

QDeclarativeGeoServiceProvider* QDeclarativePlace::plugin() const
{
    return m_plugin;
}

QDeclarativeReviewModel *QDeclarativePlace::reviewModel()
{
    if (!m_reviewModel) {
        m_reviewModel = new QDeclarativeReviewModel(this);
        m_reviewModel->setPlace(this);
    }

    return m_reviewModel;
}

QDeclarativePlaceImageModel *QDeclarativePlace::imageModel()
{
    if (!m_imageModel) {
        m_imageModel = new QDeclarativePlaceImageModel(this);
        m_imageModel->setPlace(this);
    }

    return m_imageModel;
}

void QDeclarativePlace::setPlace(const QPlace &src)
{
    QPlace previous = m_src;
    m_src = src;

    if (previous.categories() != m_src.categories()) {
        synchronizeCategories();
        emit categoriesChanged();
    }
    if (previous.descriptions() != m_src.descriptions()) {
        synchronizeDescriptions();
        emit descriptionsChanged();
    }
    if (previous.location() != m_src.location()) {
        m_location.setLocation(src.location());
        emit locationChanged();
    }
    if (previous.rating() != m_src.rating()) {
        m_rating.setRating(src.rating());
        emit ratingChanged();
    }
    if (previous.suppliers() != m_src.suppliers()) {
        synchronizeSuppliers();
        emit suppliersChanged();
    }
    if (previous.feeds() != m_src.feeds()) {
        emit feedsChanged();
    }
    if (previous.name() != m_src.name()) {
        emit nameChanged();
    }
    if (previous.placeId() != m_src.placeId()) {
        emit placeIdChanged();
    }
    if (previous.tags() != m_src.tags()) {
        emit tagsChanged();
    }
    if (previous.detailsFetched() != m_src.detailsFetched()) {
        emit detailsFetchedChanged();
    }
    if (previous.primaryPhone() != m_src.primaryPhone()) {
        emit primaryPhoneChanged();
    }
    if (previous.primaryFax() != m_src.primaryFax()) {
        emit primaryFaxChanged();
    }
    if (previous.primaryEmail() != m_src.primaryEmail()) {
        emit primaryEmailChanged();
    }
    if (previous.primaryUrl() != m_src.primaryUrl()) {
        emit primaryUrlChanged();
    }

    if (previous.placeId() != m_src.placeId()) {
        m_reviewModel->clear();
        m_imageModel->clear();
    }

    if (previous.extendedAttributes() != m_src.extendedAttributes())
    {
        synchronizeExtendedAttributes();
        emit extendedAttributesChanged();
    }
}

QPlace QDeclarativePlace::place()
{
    QList<QPlaceCategory> categories;
    foreach (QDeclarativeCategory *value, m_categories) {
        categories.append(value->category());
    }
    m_src.setCategories(categories);
    QList<QPlaceDescription> descriptions;
    foreach (QDeclarativeDescription *value, m_descriptions) {
        descriptions.append(value->description());
    }
    m_src.setDescriptions(descriptions);
    m_src.setLocation(m_location.location());
    m_src.setRating(m_rating.rating());
    QList<QPlaceSupplier> suppliers;
    foreach (QDeclarativeSupplier *value, m_suppliers) {
        suppliers.append(value->supplier());
    }
    m_src.setSuppliers(suppliers);
    return m_src;
}

/*!
    \qmlproperty string Place::location

    This property holds location of the place.

    Note: this property's changed() signal is currently emitted only if the
    whole element changes, not if only the contents of the element change.
*/
void QDeclarativePlace::setLocation(QDeclarativeGeoLocation *location)
{
    if (m_src.location() != location->location()) {
        m_location.setLocation(location->location());
        m_src.setLocation(location->location());
        emit locationChanged();
    }
}

QDeclarativeGeoLocation *QDeclarativePlace::location()
{
    return &m_location;
}

/*!
    \qmlproperty Rating Place::rating

    This property holds rating of the place.

    Note: this property's changed() signal is currently emitted only if the
    whole element changes, not if only the contents of the element change.
*/
void QDeclarativePlace::setRating(QDeclarativeRating *obj)
{
    if (m_src.rating() != obj->rating()) {
        m_rating.setRating(obj->rating());
        m_src.setRating(obj->rating());
        emit ratingChanged();
    }
}

QDeclarativeRating *QDeclarativePlace::rating()
{
    return &m_rating;
}

/*!
    \qmlproperty string Place::name

    This property holds name.
*/
void QDeclarativePlace::setName(const QString &name)
{
    if (m_src.name() != name) {
        m_src.setName(name);
        emit nameChanged();
    }
}

QString QDeclarativePlace::name() const
{
    return m_src.name();
}

/*!
    \qmlproperty string Place::placeId

    This property holds place id.
*/
void QDeclarativePlace::setPlaceId(const QString &placeId)
{
    if (m_src.placeId() != placeId) {
        m_src.setPlaceId(placeId);
        emit placeIdChanged();
    }
}

QString QDeclarativePlace::placeId() const
{
    return m_src.placeId();
}

/*!
    \qmlproperty stringlist Place::tags

    This property holds tag list.
*/
void QDeclarativePlace::setTags(const QStringList &tags)
{
    if (m_src.tags() != tags) {
        m_src.setTags(tags);
        emit tagsChanged();
    }
}

QStringList QDeclarativePlace::tags() const
{
    return m_src.tags();
}

/*!
    \qmlproperty bool Place::detailsFetched

    This property holds a boolean indicating
    whether the details of the place have been fetched
    or not.
*/
void QDeclarativePlace::setDetailsFetched(bool fetched)
{
    if (m_src.detailsFetched() != fetched) {
        m_src.setDetailsFetched(fetched);
        emit detailsFetchedChanged();
    }
}

bool QDeclarativePlace::detailsFetched() const
{
    return m_src.detailsFetched();
}

/*!
    \qmlproperty enumeration Place::status

    This property holds the status of the place.  It can be one of:
    \list
    \o Place.Ready - No Error occurred during the last operation,
                     further operations may be performed on the place.
    \o Place.Saving - The place is currently being saved, no other operations
                      may be perfomed until complete.
    \o Place.Fetching - The place details are currently being fetched, no
                        other operations may be performed until complete.
    \o Place.Removing - The place is currently being removed, no other
                        operations can be performed until complete.
    \o Place.Error - An error occurred during the last operation,
                     further operations can still be performed on the place.
    \endlist
*/
void QDeclarativePlace::setStatus(Status status)
{
    if (m_status != status) {
        m_status = status;
        emit statusChanged();
    }
}

QDeclarativePlace::Status QDeclarativePlace::status() const
{
    return m_status;
}

/*!
    \qmlproperty stringlist Place::feeds

    This property holds feeds list.
*/
void QDeclarativePlace::setFeeds(const QStringList &feeds)
{
    if (m_src.feeds() != feeds) {
        m_src.setFeeds(feeds);
        emit feedsChanged();
    }
}

QStringList QDeclarativePlace::feeds() const
{
    return m_src.feeds();
}

void QDeclarativePlace::finished()
{
    if (!m_reply)
        return;

    if (m_reply->error() == QPlaceReply::NoError) {
        switch (m_reply->type()) {
        case (QPlaceReply::IdReply) : {
            QPlaceIdReply *idReply = qobject_cast<QPlaceIdReply *>(m_reply);

            switch (idReply->operationType()) {
            case QPlaceIdReply::SavePlace:
                setPlaceId(idReply->id());
                break;
            case QPlaceIdReply::RemovePlace:
                setPlaceId(QString());
                break;
            default:
                //Other operation types shouldn't ever be received.
                break;
            }
            break;
        }
        case (QPlaceReply::PlaceDetailsReply): {
            QPlaceDetailsReply *detailsReply = qobject_cast<QPlaceDetailsReply *>(m_reply);
            setPlace(detailsReply->result());
            break;
        }
        default:
            //other types of replies shouldn't ever be received.
            break;
        }

        m_errorString.clear();

        m_reply->deleteLater();
        m_reply = 0;

        setStatus(QDeclarativePlace::Ready);
    } else {
        m_errorString = m_reply->errorString();

        m_reply->deleteLater();
        m_reply = 0;

        setStatus(QDeclarativePlace::Error);
    }
}

/*!
    \qmlmethod void Place::getDetails()

    This methods starts fetching place details.
*/
void QDeclarativePlace::getDetails()
{
    QPlaceManager *placeManager = manager();
    if (!placeManager)
        return;

    m_reply = placeManager->getPlaceDetails(placeId());
    connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
    setStatus(QDeclarativePlace::Fetching);
}

void QDeclarativePlace::ratePlace(qreal rating)
{
    QPlaceManager *placeManager = manager();
    if (!placeManager)
        return;

    placeManager->postRating(placeId(), rating);
}

/*!
    \qmlmethod void Place::savePlace()

    This method performs a save operation on the place.
*/
void QDeclarativePlace::savePlace()
{
    QPlaceManager *placeManager = manager();
    if (!placeManager)
        return;

    m_reply = placeManager->savePlace(place());
    connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
    setStatus(QDeclarativePlace::Saving);
}

/*!
    \qmlmethod void Place::removePlace()

    This method performs a remove operation on the place.
*/
void QDeclarativePlace::removePlace()
{
    QPlaceManager *placeManager = manager();
    if (!placeManager)
        return;

    m_reply = placeManager->removePlace(place());
    connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
    setStatus(QDeclarativePlace::Removing);
}

/*!
    \qmlmethod string Place::errorString()

    Returns a string description of the error of the last operation.
    If the last operation completed successfully then the string is empty.
*/
QString QDeclarativePlace::errorString() const
{
    return m_errorString;
}

/*!
    \qmlproperty string Place::primaryPhone

    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();
}

/*!
    \qmlproperty string Place::primaryFax

    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();
}

/*!
    \qmlproperty string Place::primaryEmail

    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();
}

/*!
    \qmlproperty string Place::primaryUrl

    This property holds the primary website address of the place.
*/
void QDeclarativePlace::setPrimaryUrl(const QUrl &url)
{
    if (m_src.primaryUrl() != url) {
        m_src.setPrimaryUrl(url);
        emit primaryUrlChanged();
    }
}

QUrl QDeclarativePlace::primaryUrl() const
{
    return m_src.primaryUrl();
}

/*!
    \qmlproperty ExtendedAttributes extendedAttributes

    This property holds the extended attributes of a place.
    Note: this property's changed() signal is currently only emitted
    if the whole element changes, not if only the contents of
    the element changes.
*/
void QDeclarativePlace::setExtendedAttributes(QDeclarativePropertyMap *attribs)
{
    QStringList otherKeys = attribs->keys();
    bool isSame = true;
    if (otherKeys.count() == m_src.extendedAttributes().count()) {
        foreach (const QString &key, otherKeys) {
            if (m_src.extendedAttributes().value(key) !=
                    qvariant_cast<QDeclarativePlaceAttribute*>(attribs->value(key))->attribute()) {
                isSame = false;
                break;
            }
        }
    } else {
        isSame = false;
    }

    if (!isSame) {
        m_src.extendedAttributes().clear();
        QPlace::ExtendedAttributes extendedAttributes;
        foreach (const QString &key, otherKeys)
            extendedAttributes.insert(key, (qvariant_cast<QDeclarativePlaceAttribute*>(attribs->value(key)))->attribute());
        m_src.setExtendedAttributes(extendedAttributes);

        synchronizeExtendedAttributes();
        emit extendedAttributesChanged();
    }
}

QDeclarativePropertyMap *QDeclarativePlace::extendedAttributes() const
{
    return m_extendedAttributes;
}

/*!
    \qmlproperty QDeclarativeListProperty<QDeclarativeCategory> Place::categories

    This property categories list.

    Note: this property's changed() signal is currently emitted only if the
    whole element changes, not if only the contents of the element change.
*/
QDeclarativeListProperty<QDeclarativeCategory> QDeclarativePlace::categories()
{
    return QDeclarativeListProperty<QDeclarativeCategory>(this,
                                                          0, // opaque data parameter
                                                          category_append,
                                                          category_count,
                                                          category_at,
                                                          category_clear);
}

void QDeclarativePlace::category_append(QDeclarativeListProperty<QDeclarativeCategory> *prop,
                                                  QDeclarativeCategory *value)
{
    QDeclarativePlace* object = static_cast<QDeclarativePlace*>(prop->object);
    QDeclarativeCategory *altValue = new QDeclarativeCategory(object);
    altValue->setCategory(value->category());
    object->m_categories.append(altValue);
    QList<QPlaceCategory> list = object->m_src.categories();
    list.append(value->category());
    object->m_src.setCategories(list);
    emit object->categoriesChanged();
}

int QDeclarativePlace::category_count(QDeclarativeListProperty<QDeclarativeCategory> *prop)
{
    return static_cast<QDeclarativePlace*>(prop->object)->m_categories.count();
}

QDeclarativeCategory* QDeclarativePlace::category_at(QDeclarativeListProperty<QDeclarativeCategory> *prop,
                                                                          int index)
{
    QDeclarativePlace* object = static_cast<QDeclarativePlace*>(prop->object);
    QDeclarativeCategory *res = NULL;
    if (object->m_categories.count() > index && index > -1) {
        res = object->m_categories[index];
    }
    return res;
}

void QDeclarativePlace::category_clear(QDeclarativeListProperty<QDeclarativeCategory> *prop)
{
    QDeclarativePlace* object = static_cast<QDeclarativePlace*>(prop->object);
    qDeleteAll(object->m_categories);
    object->m_categories.clear();
    object->m_src.setCategories(QList<QPlaceCategory>());
    emit object->categoriesChanged();
}

void QDeclarativePlace::synchronizeCategories()
{
    qDeleteAll(m_categories);
    m_categories.clear();
    foreach (QPlaceCategory value, m_src.categories()) {
        QDeclarativeCategory* declarativeValue = new QDeclarativeCategory(value, this);
        m_categories.append(declarativeValue);
    }
}

/*!
    \qmlproperty QDeclarativeListProperty<QDeclarativeDescription> Place::descriptions

    This property descriptions list.

    Note: this property's changed() signal is currently emitted only if the
    whole element changes, not if only the contents of the element change.
*/
QDeclarativeListProperty<QDeclarativeDescription> QDeclarativePlace::descriptions()
{
    return QDeclarativeListProperty<QDeclarativeDescription>(this,
                                                          0, // opaque data parameter
                                                          descriptions_append,
                                                          descriptions_count,
                                                          descriptions_at,
                                                          descriptions_clear);
}

void QDeclarativePlace::descriptions_append(QDeclarativeListProperty<QDeclarativeDescription> *prop,
                                                  QDeclarativeDescription *value)
{
    QDeclarativePlace* object = static_cast<QDeclarativePlace*>(prop->object);
    QDeclarativeDescription *altValue = new QDeclarativeDescription(object);
    altValue->setDescription(value->description());
    object->m_descriptions.append(altValue);
    QList<QPlaceDescription> list = object->m_src.descriptions();
    list.append(value->description());
    object->m_src.setDescriptions(list);
    emit object->descriptionsChanged();
}

int QDeclarativePlace::descriptions_count(QDeclarativeListProperty<QDeclarativeDescription> *prop)
{
    return static_cast<QDeclarativePlace*>(prop->object)->m_descriptions.count();
}

QDeclarativeDescription* QDeclarativePlace::descriptions_at(QDeclarativeListProperty<QDeclarativeDescription> *prop,
                                                                          int index)
{
    QDeclarativePlace* object = static_cast<QDeclarativePlace*>(prop->object);
    QDeclarativeDescription *res = NULL;
    if (object->m_descriptions.count() > index && index > -1) {
        res = object->m_descriptions[index];
    }
    return res;
}

void QDeclarativePlace::descriptions_clear(QDeclarativeListProperty<QDeclarativeDescription> *prop)
{
    QDeclarativePlace* object = static_cast<QDeclarativePlace*>(prop->object);
    qDeleteAll(object->m_descriptions);
    object->m_descriptions.clear();
    object->m_src.setDescriptions(QList<QPlaceDescription>());
    emit object->descriptionsChanged();
}

void QDeclarativePlace::synchronizeDescriptions()
{
    qDeleteAll(m_descriptions);
    m_descriptions.clear();
    foreach (QPlaceDescription value, m_src.descriptions()) {
        QDeclarativeDescription* declarativeValue = new QDeclarativeDescription(value, this);
        m_descriptions.append(declarativeValue);
    }
}

/*!
    \qmlproperty QDeclarativeListProperty<QDeclarativeSupplier> Place::suppliers

    This property suppliers list.

    Note: this property's changed() signal is currently emitted only if the
    whole element changes, not if only the contents of the element change.
*/
QDeclarativeListProperty<QDeclarativeSupplier> QDeclarativePlace::suppliers()
{
    return QDeclarativeListProperty<QDeclarativeSupplier>(this,
                                                          0, // opaque data parameter
                                                          suppliers_append,
                                                          suppliers_count,
                                                          suppliers_at,
                                                          suppliers_clear);
}

void QDeclarativePlace::suppliers_append(QDeclarativeListProperty<QDeclarativeSupplier> *prop,
                                                  QDeclarativeSupplier *value)
{
    QDeclarativePlace* object = static_cast<QDeclarativePlace*>(prop->object);
    QDeclarativeSupplier *altValue = new QDeclarativeSupplier(object);
    altValue->setSupplier(value->supplier());
    object->m_suppliers.append(altValue);
    QList<QPlaceSupplier> list = object->m_src.suppliers();
    list.append(value->supplier());
    object->m_src.setSuppliers(list);
    emit object->suppliersChanged();
}

int QDeclarativePlace::suppliers_count(QDeclarativeListProperty<QDeclarativeSupplier> *prop)
{
    return static_cast<QDeclarativePlace*>(prop->object)->m_suppliers.count();
}

QDeclarativeSupplier* QDeclarativePlace::suppliers_at(QDeclarativeListProperty<QDeclarativeSupplier> *prop,
                                                                          int index)
{
    QDeclarativePlace* object = static_cast<QDeclarativePlace*>(prop->object);
    QDeclarativeSupplier *res = NULL;
    if (object->m_suppliers.count() > index && index > -1) {
        res = object->m_suppliers[index];
    }
    return res;
}

void QDeclarativePlace::suppliers_clear(QDeclarativeListProperty<QDeclarativeSupplier> *prop)
{
    QDeclarativePlace* object = static_cast<QDeclarativePlace*>(prop->object);
    qDeleteAll(object->m_suppliers);
    object->m_suppliers.clear();
    object->m_src.setSuppliers(QList<QPlaceSupplier>());
    emit object->suppliersChanged();
}

void QDeclarativePlace::synchronizeSuppliers()
{
    qDeleteAll(m_suppliers);
    m_suppliers.clear();
    foreach (QPlaceSupplier value, m_src.suppliers()) {
        QDeclarativeSupplier* declarativeValue = new QDeclarativeSupplier(value, this);
        m_suppliers.append(declarativeValue);
    }
}

void QDeclarativePlace::synchronizeExtendedAttributes()
{
    QStringList keys = m_extendedAttributes->keys();
    foreach (const QString &key, keys)
        m_extendedAttributes->clear(key);

    QMapIterator<QString, QPlaceAttribute> attribIter(m_src.extendedAttributes());
    while (attribIter.hasNext()) {
        attribIter.next();
        m_extendedAttributes->insert(attribIter.key(),
            qVariantFromValue(new QDeclarativePlaceAttribute(attribIter.value())));
    }
}

/*
    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
    then return a null pointer.
*/
QPlaceManager *QDeclarativePlace::manager()
{
    if (m_status != QDeclarativePlace::Ready && m_status != QDeclarativePlace::Error)
        return 0;

    if (m_reply) {
        m_reply->abort();
        m_reply->deleteLater();
        m_reply = 0;
    }

    if (!m_plugin) {
           qmlInfo(this) << tr("Plugin not assigned to place");
           return 0;
    }

    QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider();
    if (!serviceProvider)
        return 0;

    QPlaceManager *placeManager = serviceProvider->placeManager();

    if (!placeManager) {
        qmlInfo(this) << tr("Places not supported by %1 Plugin.").arg(m_plugin->name());
        return 0;
    }

    return placeManager;
}