summaryrefslogtreecommitdiffstats
path: root/src/location/landmarks/qlandmarkmanager.cpp
blob: ab43c48ed5039beab515068fe3fd3fe4689ab99b (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
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Mobility Components.
**
** $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 "qlandmarkmanager.h"
#include "qlandmarkmanager_p.h"

#include <QStringList>
#include <QString>
#include <QIODevice>
#include <QFile>
#include <QUrl>
#include <QPluginLoader>
#include <QDebug>
#include "qlandmarkcategoryid.h"
#include "qlandmarkcategory.h"
#include "qlandmark.h"
#include "qlandmarkmanagerengine.h"
#include "qlandmarkmanagerenginefactory.h"
#include "qlandmarkidfilter.h"

QTM_USE_NAMESPACE

/*!
   \variable QLandmarkManager::Gpx
   The format constant to define using the gpx format in the import and export functions.
   \sa importLandmarks(), exportLandmarks()
*/
Q_DEFINE_LATIN1_CONSTANT(QLandmarkManager::Gpx, "Gpx");

/*!
   \variable QLandmarkManager::Lmx
   The format constant to define using the lmx format in the import and export functions.
   \sa importLandmarks(), exportLandmarks()
*/
Q_DEFINE_LATIN1_CONSTANT(QLandmarkManager::Lmx, "Lmx");

/*!
   \variable QLandmarkManager::Kml
   The format constant to define using the kml format in the import and export functions.
   \sa importLandmarks(), exportLandmarks()
*/
Q_DEFINE_LATIN1_CONSTANT(QLandmarkManager::Kml, "Kml");

/*!
   \variable QLandmarkManager::Kmz
   The format constant to define using the kmz format in the import and export functions.
   \sa importLandmarks(), exportLandmarks()
*/
Q_DEFINE_LATIN1_CONSTANT(QLandmarkManager::Kmz, "Kmz");

/*!
    \class QLandmarkManager
    \brief The QLandmarkManager class provides an interface for storage
    and retrieval of landmarks from a landmark store.
    \since 1.1

    \inmodule QtLocation

    \ingroup landmarks-main

    The QLandmarkManager is the starting class to use when working with landmarks.
    It effectively represents a landmark datastore and it provides the synchronous operations for the
    creation, retrieval, updating and deletion of both landmarks and categories.  For asynchronous operations
    use the \l {Asynchronous Landmark Requests} {request classes} which use the manager as a parameter.
    The manager provides notifications whenever landmarks or categories are added, updated or removed.

    Each manager is identified by a manager name which typically takes the form of a reverse domain string
    such as \c com.nokia.qt.landmarks.engines.sqlite.  However every supported platform provides a default
    manager which may be instantiated without having to provide a name like so:
    \snippet doc/src/snippets/qtlandmarksdocsample/qtlandmarksdocsample.cpp Instantiate default QLandmarkManager

    \section1 Retrieval Operations

    To retrieve a set of landmarks we provide may provide a QLandmarkFilter, QLandmarkSortOrder and limit and offset as necessary.
    The QLandmarkFilter defines the criteria for selecting landmarks; for example, a QLandmarkCategoryFilter may be used
    to choose landmarks that belong to a certain category.  A QLandmarkSortOrder order defines how the results should
    be sorted.  (Note that if you wish to sort by distance, you should use a proxmity filter, see QLandmarkProximityFilter).
    The limit allows specification of the maximum number of items to
    return and the offset defines the index of the first item.  The following demonstrates how to search for the first 100
    landmarks belonging to a given category, sorted by name.

    \snippet doc/src/snippets/qtlandmarksdocsample/qtlandmarksdocsample.cpp Retrieve landmarks by category synchronously

    The set of parameters described above are not always necessary as defaults are provided, if we wanted to retrieve
    all landmarks, then the appropriate call is:

    \snippet doc/src/snippets/qtlandmarksdocsample/qtlandmarksdocsample.cpp Retrieve all landmarks synchronously
    \note Landmark retrieval is potentially a long operation, the synchronous API provided by the manager
    is subject to blocking.  It is generally recommended that the QLandmarkFetchRequest be used because
    it behaves asynchronously.

    Categories may be retrieved in a similar manner:
    \snippet doc/src/snippets/qtlandmarksdocsample/qtlandmarksdocsample.cpp Retrieve categories synchronously simple

    \section1 Saving and Deleting

    Saving and deleting landmarks and categories are fairly straightforward.  To add a new landmark or category
    simply instantiate a QLandmark or QLandmarkCategory, set its data fields (e.g., name, coordinate, etc.) and pass
    a pointer to the appropriate save operation.  For example:

    \snippet doc/src/snippets/qtlandmarksdocsample/qtlandmarksdocsample.cpp Add landmark synchronously simple

    We pass the landmark by pointer bcause it will be assigned a new QLandmarkId when the function call is done.
    Saving a landmark with a valid id already set will update the existing landmark.

    Removal of landmark may be done as follows:
    \snippet doc/src/snippets/qtlandmarksdocsample/qtlandmarksdocsample.cpp Remove landmark synchronously simple

    \section1 Importing and Exporting

    Import and export are potentially long operations, to perform these operations asynchronously
    see QLandmarkImportRequest and QLandmarkExportRequest.  The simplest way to perform an import
    is to supply a file name while an export will need both a file name and format.

    \snippet doc/src/snippets/qtlandmarksdocsample/qtlandmarksdocsample.cpp ImportExport landmark simple

    The formats supported for import and export can be found by calling the
    supportedFormats() function with the type of operation to be performed,
    either ImportOperation or ExportOperation.
*/

/*!
    \enum QLandmarkManager::Error
    Defines the possible errors for the landmark manager.
    \value NoError No error occurred
    \value DoesNotExistError The most recent operation failed due to an item not being found, usually an import file.
    \value LandmarkDoesNotExistError The most recent operation failed due to a specified landmark not being found.
    \value CategoryDoesNotExistError The most recent operation faied due to a specified category not being found.
    \value AlreadyExistsError The most recent operation failed because the specified landmark or category already exists.
    \value LockedError The most recent operation failed because the datastore specified is currently locked.
    \value PermissionsError The most recent operation failed because the caller does not have permission to perform the operation.
    \value OutOfMemoryError The most recent operation failed due to running out of memory.
    \value VersionMismatchError The most recent operation failed because the backend of the manager is not of the required version.
    \value NotSupportedError The most recent operation failed because the requested operation is not supported by the manager.
    \value BadArgumentError The most recent operation failed because one or more of the parameters to the operation were invalid.
    \value InvalidManagerError The most recent operation failed because the manager failed to initialize correctly and is invalid.
           This could be due using a manager name that is not recognised/available. A landmark request object will return this error if
           if is assigned a null manager pointer.
    \value ParsingError The most recent operation failed because the imported file could not be parsed.
    \value CancelError The most recent operation failed to complete due to user cancelation.
    \value UnknownError The most recent operation failed for an unknown reason.
*/

/*!
    \enum QLandmarkManager::TransferOption
    Defines the possible options when transferring landmarks during import or export.
    \value IncludeCategoryData During an import, category data is included.  If an imported category doesn't exist
                               the category is created.  If the imported category name matches an existing
                               category name, then the landmark is added to that category.  For exports, categories
                               are included in the exported file if the file format allows it.
    \value ExcludeCategoryData Landmarks are imported or exported without any categories assigned to the landmarks.
    \value AttachSingleCategory Only relevant for import operations.  When landmarks are imported they are
                                all assigned to a given category.
*/

/*!
    \enum QLandmarkManager::ManagerFeature
    Defines the possible features the landmark manager can support.
    \value ImportExportFeature The manager supports import and/or export operations
    \value NotificationsFeature The manager will emit notification signals when landmarks/categories have
                         been added/modified/removed from the datastore it manages.
*/

/*!
    \enum QLandmarkManager::SupportLevel
    Defines the possible support levels the manager can provide for a given filter or sort order list.
    \value NativeSupport The manager natively supports the filter or sort order list.
    \value EmulatedSupport The manager emulates the behaviour of the filter or sort order list.
                     Emulated behaviour will inherently be slower than a natively supported implementation.
    \value NoSupport The manager does not support the filter or sort order list at all.
*/

/*!
    \enum QLandmarkManager::TransferOperation
    Defines the type of transfer.
    \value ImportOperation Landmarks are being copied from a file to the device.
    \value ExportOperation Landmarks are being copied from the device to a file.
*/

/*!
    Constructs a QLandmarkManager. The default manager implementation for the platform will be used.

    The \a parent QObject will be used as the parent of this QLandmarkManager.
*/
QLandmarkManager::QLandmarkManager(QObject *parent)
        : QObject(parent),
          d_ptr(new QLandmarkManagerPrivate())
{
    Q_D(QLandmarkManager);
    d->q_ptr = this;
    QString managerName;

#ifdef Q_OS_SYMBIAN
     managerName = "com.nokia.qt.landmarks.engines.symbian";
#elif defined(Q_WS_MAEMO_6) || defined(Q_WS_MEEGO)
     managerName = "com.nokia.qt.landmarks.engines.qsparql";
#else
    managerName = "com.nokia.qt.landmarks.engines.sqlite";
#endif

    d->createEngine(managerName);
}

/*!
    Constructs a QLandmarkManager whose implementation is identified by \a managerName with the given
    \a parameters.

    The \a parent QObject will be used as the parent of this QLandmarkManager.

    If an empty \a managerName is specified, the default manager implementation for the platform will be used.
*/
QLandmarkManager::QLandmarkManager(const QString &managerName, const QMap<QString, QString> &parameters, QObject *parent)
        : QObject(parent),
          d_ptr(new QLandmarkManagerPrivate())
{
    Q_D(QLandmarkManager);
    d->q_ptr = this;
    d->createEngine(managerName, parameters);
}

/*!
    Frees the memory used by the QLandmarkManager
*/
QLandmarkManager::~QLandmarkManager()
{
    Q_D(QLandmarkManager);

    if (d->engine)
        delete d->engine;

    delete d;
}

/*!
    Adds the given \a landmark to the database if \a landmark has a
    default-constructed identifer, or an identifier with the manager
    URI set to the URI of this manager and an empty id.

    If the manager URI of the identifier of the \a landmark is neither
    empty nor equal to the URI of this manager, or the id member of the
    identifier is not empty, but does not exist in the manager,
    the operation will fail and calling error() will return
    \c QLandmarkManager::LandmarkDoesNotExistError.

    Alternatively, the function will update the existing landmark in the
    database if \a landmark has a non-empty id and currently exists
    within the database.

    Returns false on failure or true on success.  On successful save
    of a landmark with an empty id, it will be assigned a valid
    id and have its manager URI set to the URI of this manager.
    \since 1.1
*/
bool QLandmarkManager::saveLandmark(QLandmark *landmark)
{
    Q_D(QLandmarkManager);

    if (!d->engine) {
        return false;
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    return d->engine->saveLandmark(landmark,
                                   &(d->errorCode),
                                   &(d->errorString));
}

/*!
    Adds the list of \a landmarks to the database.
    Returns true if the landmarks were saved successfully, otherwise returns
    false.

    This function will set per-input errors in the QLandmarkManager::errorMap().

    The QLandmarkManager::error() function will only return \c
    QLandmarkManager::NoError if all landmarks were saved successfully.

    For each new landmark that was successfully saved, a landmark identifier
    is assigned to that landmark.
    \since 1.1
*/
bool QLandmarkManager::saveLandmarks(QList<QLandmark> *landmarks)
{
    Q_D(QLandmarkManager);

    if (!d->engine) {
        return false;
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    return d->engine->saveLandmarks(landmarks,
                                    &(d->errorMap),
                                    &(d->errorCode),
                                    &(d->errorString));
}

/*!
    Remove the landmark identified by \a landmarkId from the database.

    Returns true if the landmark was removed successfully, otherwise
    returnse false.
    \since 1.1
*/
bool QLandmarkManager::removeLandmark(const QLandmarkId &landmarkId)
{
    Q_D(QLandmarkManager);

    if (!d->engine) {
        return false;
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    return d->engine->removeLandmark(landmarkId,
                                     &(d->errorCode),
                                     &(d->errorString));
}


/*!
    Removes the \a landmark from the database.

    Returns true if the landmark was removed successfully,
    otherwise returns false.
    \since 1.1
*/
bool QLandmarkManager::removeLandmark(const QLandmark &landmark)
{
    Q_D(QLandmarkManager);

    if (!d->engine) {
        return false;
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    return d->engine->removeLandmark(landmark.landmarkId(),
                                     &(d->errorCode),
                                     &(d->errorString));

}

/*!
    Removes every landmark whose identifier is contained in the list
    of \a landmarkIds.  Returns true if all landmarks were removed
    successfully, otherwise false.

    This batch function will set per-input errors in the QLandmarkManager::errorMap().

    The QLandmarkManager::error() function will only return
    \c QLandmarkManager::NoError if all landmarks were removed successfully.

    \since 1.1
    \sa QLandmarkManager::removeLandmark()
*/
bool QLandmarkManager::removeLandmarks(const QList<QLandmarkId> &landmarkIds)
{
    Q_D(QLandmarkManager);

    if (!d->engine) {
        return false;
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();


    return d->engine->removeLandmarks(landmarkIds,
                                      &(d->errorMap),
                                      &(d->errorCode),
                                      &(d->errorString));
}

/*!
    Convenience function to remove the given \a landmarks from the database.
    Returns true if all landmarks were removed
    successfully, otherwise false.

    This batch function will set per input errors in the QLandmarkManager::errorMap().

    The QLandmarkManager::error() function will only return
    \c QLandmarkManager::NoError if all landmarks were removed successfully.



    \since 1.1
    \sa QLandmarkManager::removeLandmark()
*/
bool QLandmarkManager::removeLandmarks(const QList<QLandmark> &landmarks)
{
    Q_D(QLandmarkManager);

    if (!d->engine) {
        return false;
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    QList<QLandmarkId> landmarkIds;
    for (int i=0; i < landmarks.count(); ++i) {
        landmarkIds << landmarks.at(i).landmarkId();
    }

    return d->engine->removeLandmarks(landmarkIds,
                                      &(d->errorMap),
                                      &(d->errorCode),
                                      &(d->errorString));
}



/*!
    Adds the given \a category to the database if \a category has a
    default-constructed identifier, or an identifier with the manager
    URI set to the URI of this manager and an empty id.

    If the manager URI of the identifier of the \a category is neither
    empty nor equal to the URI  of this manager, or the id member of the
    identifier is not empty, but does not exist in the manager,
    the operation will fail and calling error() will return
    \c QLandmarkManager::CategoryDoesNotExistError.

    Alternatively, the function will update the existing category in the
    database if \a category has a non-empty id and currently exists
    within the database.

    Returns false on failure or true on success.  On successful save
    of a category with an invalid id, it will be assigned a valid
    id and have its manager URI set to the URI of this manager.
    \since 1.1
*/
bool QLandmarkManager::saveCategory(QLandmarkCategory *category)
{
    Q_D(QLandmarkManager);

    if (!d->engine) {
        return false;
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    return d->engine->saveCategory(category,
                                   &(d->errorCode),
                                   &(d->errorString));
}

/*!
    Remove the category identified by \a categoryId from the database.

    Returns true if the category was removed successfully, otherwise
    returns false.
    \since 1.1
*/
bool QLandmarkManager::removeCategory(const QLandmarkCategoryId &categoryId)
{
    Q_D(QLandmarkManager);

    if (!d->engine) {
        return false;
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    return d->engine->removeCategory(categoryId,
                                     &(d->errorCode),
                                     &(d->errorString));
}

/*!
    Remove the given \a category from the database

    Returns true if the category was removed successfully, otherwise
    returns false.
    \since 1.1
*/
bool QLandmarkManager::removeCategory(const QLandmarkCategory &category)
{
    Q_D(QLandmarkManager);

    if (!d->engine) {
        return false;
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    return d->engine->removeCategory(category.categoryId(),
                                     &(d->errorCode),
                                     &(d->errorString));
}

/*!
    Returns the cateory in the database identified by \a categoryId.
    \since 1.1
*/
QLandmarkCategory QLandmarkManager::category(const QLandmarkCategoryId &categoryId) const
{
    Q_D(const QLandmarkManager);

    if (!d->engine) {
        return QLandmarkCategory();
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    QLandmarkCategory cat = d->engine->category(categoryId,
                            &(d->errorCode),
                            &(d->errorString));

    if (d->errorCode != NoError)
        return QLandmarkCategory();

    return cat;
}

/*!
     Returns a list of categories which match the given \a categoryIds.

     This batch function will set per-input errors in the QLandmarkManager::errorMap();

    The QLandmarkManager::error() function will only return \c QLandmarkManager::NoError if
    all categories were successfully retrieved.
    \since 1.1
 */
QList<QLandmarkCategory> QLandmarkManager::categories(const QList<QLandmarkCategoryId> &categoryIds) const
{
    Q_D(const QLandmarkManager);

    if (!d->engine) {
        return QList<QLandmarkCategory>();
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    QList<QLandmarkCategory> cats = d->engine->categories(categoryIds,
                                    &(d->errorMap),
                                    &(d->errorCode),
                                    &(d->errorString));

    return cats;
}

/*!
    Returns a list of categories.The \a limit defines the maximum number of categories
    to return and the \a offset defines the index offset of the first category.
    A \a limit of -1 means all categories should be returned(a limit of 0 means zero
    categories are returned).  The categories
    are returned in the order as designated by \a nameSort.
    \since 1.1
*/
QList<QLandmarkCategory> QLandmarkManager::categories(int limit, int offset, const QLandmarkNameSort &nameSort) const
{
    Q_D(const QLandmarkManager);

    if (!d->engine) {
        return QList<QLandmarkCategory>();
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    QList<QLandmarkCategory> cats = d->engine->categories(limit, offset, nameSort,
                                    &(d->errorCode),
                                    &(d->errorString));

    if (d->errorCode != NoError)
        return QList<QLandmarkCategory>();

    return cats;
}

/*!
    Returns a list of category identifiers.
    The \a limit defines the maximum number of ids to return and the \a offset defines the index offset
    of the first id.  A \a limit of -1 means ids for all categories should be returned.
    The identifiers are returned in order as designed by \a nameSort.  Note that a limit
    of 0 will return zero category ids.
    \since 1.1
*/
QList<QLandmarkCategoryId> QLandmarkManager::categoryIds(int limit, int offset, const QLandmarkNameSort &nameSort) const
{
    Q_D(const QLandmarkManager);

    if (!d->engine) {
        return QList<QLandmarkCategoryId>();
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    QList<QLandmarkCategoryId> ids = d->engine->categoryIds(limit, offset, nameSort,
                                                            &(d->errorCode),
                                                            &(d->errorString));

    if (d->errorCode != NoError)
        return QList<QLandmarkCategoryId>();

    return ids;
}

/*!
    Returns the landmark in the database identified by \a landmarkId
    \since 1.1
*/
QLandmark QLandmarkManager::landmark(const QLandmarkId &landmarkId) const
{
    Q_D(const QLandmarkManager);

    if (!d->engine) {
        return QLandmark();
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    QLandmark lm = d->engine->landmark(landmarkId,
                                       &(d->errorCode),
                                       &(d->errorString));

    if (d->errorCode != NoError)
        return QLandmark();

    return lm;
}

/*!
    Returns a list of landmarks which match the given \a filter and are sorted according to the \a sortOrders.
    The \a limit defines the maximum number of landmarks to return and the \a offset defines the index offset
    of the first landmark.  A \a limit of -1 means all matching landmarks should be returned.
    \since 1.1
*/
QList<QLandmark> QLandmarkManager::landmarks(const QLandmarkFilter &filter, int limit, int offset,
                                             const QList<QLandmarkSortOrder> &sortOrders) const
{
    Q_D(const QLandmarkManager);

    if (!d->engine) {
        return QList<QLandmark>();
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    QList<QLandmark> lms = d->engine->landmarks(filter,
                           limit,
                           offset,
                           sortOrders,
                           &(d->errorCode),
                           &(d->errorString));

    if (d->errorCode != NoError)
        return QList<QLandmark>();

    return lms;
}

/*!
    Returns a list of landmarks which match the given \a filter and are sorted according to the \a sortOrder.
    The \a limit defines the maximum number of landmarks to return and the \a offset defines the index offset
    of the first landmark.  A \a limit of -1 means all matching landmarks should be returned and that
    a limit of 0 will return zero landmarks.
    \since 1.1
*/
QList<QLandmark> QLandmarkManager::landmarks(const QLandmarkFilter &filter, int limit, int offset,
                                             const QLandmarkSortOrder &sortOrder) const
{
    Q_D(const QLandmarkManager);

     if (!d->engine) {
        return QList<QLandmark>();
    }

     d->errorCode = QLandmarkManager::NoError;
     d->errorString = "";
     d->errorMap.clear();

    QList<QLandmarkSortOrder> sortOrders;
    if (sortOrder.type() != QLandmarkSortOrder::NoSort)
        sortOrders.append(sortOrder);

    QList<QLandmark> lms = d->engine->landmarks(filter,
                           limit,
                           offset,
                           sortOrders,
                           &(d->errorCode),
                           &(d->errorString));

    if (d->errorCode != NoError)
        return QList<QLandmark>();

    return lms;
}

/*!
    Returns a list of landmarks which match the given \a landmarkIds.

    This batch function will set per-input errors in the QLandmarkManager::errorMap().

    The QLandmarkManager::error() function will only return \c QLandmarkManager::NoError if
    all landmarks were successfully retrieved.

    \since 1.1
*/
QList<QLandmark> QLandmarkManager::landmarks(const QList<QLandmarkId> &landmarkIds) const
{
    Q_D(const QLandmarkManager);

     if (!d->engine) {
        return QList<QLandmark>();
    }

     d->errorCode = QLandmarkManager::NoError;
     d->errorString = "";
     d->errorMap.clear();

    QList<QLandmark> lms = d->engine->landmarks(landmarkIds,
                                                &(d->errorMap),
                                                &(d->errorCode),
                                                &(d->errorString));
    return lms;
}

/*!
    Returns a list of landmark identifiers which match the given \a filter and are sorted according to
    the given \a sortOrders. The \a limit defines the maximum number of landmark ids to return and the
    \a offset defines the index offset of the first landmark id.
    A \a limit of -1 means that ids of all matching landmarks should be returned.  Note that
    a limit of 0 will return zero landmark ids.
    \since 1.1
*/
QList<QLandmarkId> QLandmarkManager::landmarkIds(const QLandmarkFilter &filter,
                                                int limit, int offset,
                                                 const QList<QLandmarkSortOrder> &sortOrders) const
{
    Q_D(const QLandmarkManager);

     if (!d->engine) {
        return QList<QLandmarkId>();
    }

     d->errorCode = QLandmarkManager::NoError;
     d->errorString = "";
     d->errorMap.clear();

    QList<QLandmarkId> ids = d->engine->landmarkIds(filter,
                             limit,
                             offset,
                             sortOrders,
                             &(d->errorCode),
                             &(d->errorString));

    if (d->errorCode != NoError)
        return QList<QLandmarkId>();

    return ids;
}

/*!
    Convenience function to returns a list of landmark identifiers which match the given \a filter and are sorted according to
    the given \a sortOrder. The \a limit defines the maximum number of landmark ids to return and the
    \a offset defines the index offset of the first landmark id.
    A \a limit of -1 means that ids of all matching landmarks should be returned.  Note
    that a limit of 0 will return zero landmark ids.


    \since 1.1
*/
QList<QLandmarkId> QLandmarkManager::landmarkIds(const QLandmarkFilter &filter,
                                                 int limit, int offset,
                                                 const QLandmarkSortOrder &sortOrder) const
{
    Q_D(const QLandmarkManager);

     if (!d->engine) {
        return QList<QLandmarkId>();
    }

     d->errorCode = QLandmarkManager::NoError;
     d->errorString = "";
     d->errorMap.clear();

    QList<QLandmarkSortOrder> sortOrders;
    sortOrders.append(sortOrder);

    QList<QLandmarkId> ids = d->engine->landmarkIds(filter,
                                                    limit,
                                                    offset,
                                                    sortOrders,
                                                    &(d->errorCode),
                                                    &(d->errorString));

    if (d->errorCode != NoError)
        return QList<QLandmarkId>();

    return ids;
}

/*!
    Reads landmarks from the given \a device and saves them.  The data from the \a device
    is expected to adhere to the provided \a format.  If no \a format is provided,
    the manager tries to auto detect the \a format.

    The \a option can be used to control whether categories in the imported
    file will be added during the import.  If the \c AttachSingleCategory option is used, then
    all the landmarks in the import file are assigned to the category identified by
    \a categoryId, in all other circumstances \a categoryId is ignored.  If \a categoryId
    doesn't exist when using \c AttachSingleCategory, QLandmarkManager::CategoryDoesNotExistError is set.  Note that
    some file formats may not support categories at all.

    Returns true if all landmarks could be imported, otherwise
    returns false.

    \since 1.1
*/
bool QLandmarkManager::importLandmarks(QIODevice *device, const QString &format, QLandmarkManager::TransferOption option, const QLandmarkCategoryId &categoryId)
{
    Q_D(QLandmarkManager);

     if (!d->engine) {
        return false;
    }

     d->errorCode = QLandmarkManager::NoError;
     d->errorString = "";
     d->errorMap.clear();

    return d->engine->importLandmarks(device,
                                      format,
                                      option,
                                      categoryId,
                                      &(d->errorCode),
                                      &(d->errorString));
}

/*!
    Convenience function that will read landmarks from \a fileName in
    the expected \a format. If no \a format is provided, the manager tries
    to auto detect the \a format.  Internally a QFile is opened with
    QIODevice::ReadOnly permissions.

    The \a option can be used to control whether categories in the imported
    file will be added during the import.  If the \c AttachSingleCategory option is used, then
    all the landmarks in the import file are assigned to the category identified by
    \a categoryId, in all other circumstances \a categoryId is ignored.  If \a categoryId
    doesn't exist when using \c AttachSingleCategory, QLandmarkManager::CategoryDoesNotExistError is set.  Note that
    some file formats may not support categories at all.

    Returns true if all landmarks could be imported, otherwise
    returns false.
    \since 1.1
*/
bool QLandmarkManager::importLandmarks(const QString &fileName, const QString &format, QLandmarkManager::TransferOption option, const QLandmarkCategoryId &categoryId)
{
    QFile file(fileName);
    return importLandmarks(&file, format,option,categoryId);
}

/*!
    Writes landmarks to the given \a device.  The landmarks will be written
    according to the specified \a format.  If  \a landmarkIds is empty, then
    all landmarks will be exported, otherwise only those landmarks that
    match \a landmarkIds will be exported.

    The \a option can be used to control whether categories will be exported or not.
    Note that the \c AttachSingleCategory option has no meaning during
    export and the manager will export as if \a option was \c IncludeCategoryData.
    Also, be aware that some file formats may not support categories at all and for
    these formats, the \a option is always treated as if it was \c ExcludeCategoryData.

    Returns true if all specified landmarks were successfully exported,
    otherwise returns false.  It may be possible that only a subset
    of landmarks are exported.
    \since 1.1
*/
bool QLandmarkManager::exportLandmarks(QIODevice *device, const QString &format, const QList<QLandmarkId> &landmarkIds, QLandmarkManager::TransferOption option) const
{
    Q_D(const QLandmarkManager);

     if (!d->engine) {
        return false;
    }

     d->errorCode = QLandmarkManager::NoError;
     d->errorString = "";
     d->errorMap.clear();

    return d->engine->exportLandmarks(device,
                                      format,
                                      landmarkIds,
                                      option,
                                      &(d->errorCode),
                                      &(d->errorString));
}

/*!
    Convenience function that will write landmarks to \a fileName in the expected
    \a format. Internally a QFile is opened with QIODevice::WriteOnly permissions.
    If \a landmarkIds is empty, then all landmarks will be exported, otherwise
    only those landmarks that match \a landmarkIds will be exported.

    The \a option can be used to control whether categories will be exported or not.
    Note that the \c AttachSingleCategory option has no meaning during
    export and the manager will export as if \a option was \c IncludeCategoryData.
    Also, be aware that some file formats may not support categories at all and for
    these formats, the \a option is always treated as if it was \c ExcludeCategoryData.

    Returns true if all specified landmarks were successfully exported,
    otherwise returns false.  It may be possible that only a subset
    of landmarks are exported.
    \since 1.1
*/
bool QLandmarkManager::exportLandmarks(const QString &fileName, const QString &format, const QList<QLandmarkId> &landmarkIds, QLandmarkManager::TransferOption option) const
{
    QFile file(fileName);

    return exportLandmarks(&file, format,landmarkIds, option);
}

/*!
    Returns the file formats supported for the given transfer \a operation. ie import or export.
    \since 1.1
*/
QStringList QLandmarkManager::supportedFormats(QLandmarkManager::TransferOperation operation) const
{
    Q_D(const QLandmarkManager);

     if (!d->engine) {
        return QStringList();
    }

     d->errorCode = QLandmarkManager::NoError;
     d->errorString = "";
     d->errorMap.clear();

    return d->engine->supportedFormats(operation, &(d->errorCode), &(d->errorString));
}

/*!
    Returns the error code of the most recent operation.  All functions will modify the error based on whether the
    operation successfully or not.
    \since 1.1
*/
QLandmarkManager::Error QLandmarkManager::error() const
{
    Q_D(const QLandmarkManager);
    return d->errorCode;
}

/*!
    Returns a short human-readable description of the error that occurred
    in the most recent operation.  The error string is intended to be used
    by developers and is not suitable for showing to end users.
    \since 1.1
*/
QString QLandmarkManager::errorString() const
{
    Q_D(const QLandmarkManager);
    return d->errorString;
}

/*!
Returns per-input error codes for the most recent operation. This function only
returns meaningful information if the most recent operation was a batch
operation.  The keys in the map correspond to the index of the input list.
The error map is only populated for indexes at which an error occurred.
Eg If we saved 5 landmarks and an error occurred at index 3, the error map
will have only a single key for index 3.

\since 1.1
\sa error(), categories(), landmarks(), saveLandmarks(), removeCategory(),  removeLandmarks()
*/
QMap<int, QLandmarkManager::Error> QLandmarkManager::errorMap() const
{
    Q_D(const QLandmarkManager);
    return d->errorMap;
}

/*!
    Returns whether the manager supports the given \a feature.
    \since 1.1
*/
bool QLandmarkManager::isFeatureSupported(QLandmarkManager::ManagerFeature feature) const
{
    Q_D(const QLandmarkManager);

    if (!d->engine) {
        return false;
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    return d->engine->isFeatureSupported(feature, &(d->errorCode), &(d->errorString));
}

/*!
    Returns the support level the manager provides for the given \a filter.  For the case
    of intersection and union filters, whether the elements will be individually processed
    is dependent on the particular manager implementation.
    \since 1.1
*/
QLandmarkManager::SupportLevel QLandmarkManager::filterSupportLevel(const QLandmarkFilter &filter) const
{
    Q_D(const QLandmarkManager);

     if (!d->engine) {
        return QLandmarkManager::NoSupport;
    }

     d->errorCode = QLandmarkManager::NoError;
     d->errorString = "";
     d->errorMap.clear();

    return d->engine->filterSupportLevel(filter, &(d->errorCode), &(d->errorString));
}

/*!
    Returns the support level the manager provides for the given \a sortOrder.
    \since 1.1
*/
QLandmarkManager::SupportLevel QLandmarkManager::sortOrderSupportLevel(const QLandmarkSortOrder &sortOrder) const
{
    Q_D(const QLandmarkManager);

     if (!d->engine) {
        return QLandmarkManager::NoSupport;
    }

     d->errorCode = QLandmarkManager::NoError;
     d->errorString = "";
     d->errorMap.clear();

    return d->engine->sortOrderSupportLevel(sortOrder, &(d->errorCode), &(d->errorString));
}

/*!
    Returns true if the manager is entirely read-only.  Meaning
    landmarks and categories cannot be added, modified or removed.
    \since 1.1
*/
bool QLandmarkManager::isReadOnly() const
{
    Q_D(const QLandmarkManager);
    if (!d->engine) {
        return true;
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    return d->engine->isReadOnly(&(d->errorCode), &(d->errorString));
}

/*!
    Returns true if the landmark identified by \a landmarkId
    considered read-only by the manager.

    If the \a landmarkId does not refer to an existing landmark,
    it is considered writable unless the manager is exclusively read-only.
    \since 1.1
*/
bool QLandmarkManager::isReadOnly(const QLandmarkId &landmarkId) const
{
    Q_D(const QLandmarkManager);
    if (!d->engine) {
        return true;
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    return d->engine->isReadOnly(landmarkId, &(d->errorCode), &(d->errorString));
}

/*!
    Returns true if the category identified by \a categoryId is
    considered read-only by the manager.

    If \a categoryId does not refer to an existing category,
    it is considered writable unless the manager is exclusively read-only.
    \since 1.1
*/
bool QLandmarkManager::isReadOnly(const QLandmarkCategoryId &categoryId) const
{
    Q_D(const QLandmarkManager);
    if (!d->engine) {
        return true;
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    return d->engine->isReadOnly(categoryId, &(d->errorCode), &(d->errorString));
}

/*!
    Returns a list of landmark attribute keys that may be used in a
    QLandmarkAttributeFilter.
    \since 1.1
*/
QStringList QLandmarkManager::searchableLandmarkAttributeKeys() const
{
    Q_D(const QLandmarkManager);
    if (!d->engine) {
        return QStringList();
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();

    return d->engine->searchableLandmarkAttributeKeys(&(d->errorCode), &(d->errorString));
}

/*!
    Returns the manager name for this QLandmarkManager.

    The manager name usually takes the format of a reverse domain string.  An example
    of a manager name is \c com.nokia.qt.landmarks.engines.sqlite
    \since 1.1
*/
QString QLandmarkManager::managerName() const
{
    Q_D(const QLandmarkManager);

    if (!d->engine) {
        return QString();
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();
    return d->engine->managerName();
}

/*!
    Return the parameters relevant to the creation of this QLandmarkManager.

    The parameters may be viewed as a set of key-value pairs.  Each manager
    may have a different set of parameters depending upon its backend implementation.
    \since 1.1
*/
QMap<QString, QString> QLandmarkManager::managerParameters() const
{
    Q_D(const QLandmarkManager);

    if (!d->engine) {
        return QMap<QString, QString>();
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();
    return d->engine->managerParameters();
}

/*!
  Return the uri describing this QLandmarkManager, consisting of the manager name and any parameters.
  \since 1.1
 */
QString QLandmarkManager::managerUri() const
{
    Q_D(const QLandmarkManager);

    if (!d->engine) {
        return QString();
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();
    return d->engine->managerUri();
}

/*!
  Returns the engine backend implementation version number.
  \since 1.1
*/
int QLandmarkManager::managerVersion() const
{
    Q_D(const QLandmarkManager);

    if (!d->engine) {
        return 0;
    }

    d->errorCode = QLandmarkManager::NoError;
    d->errorString = "";
    d->errorMap.clear();
    return d->engine->managerVersion();
}

/*!
    Returns a list of available manager names that can
    be used when constructing a QLandmarkManager
    \since 1.1
*/
QStringList QLandmarkManager::availableManagers()
{
    return QLandmarkManagerPrivate::factories().keys();
}

/*! Returns a URI that completely describes a manager implementation/datastore,
    and the parameters with which to instantiate the manager,
    from the given \a managerName, \a params and an optional \a implementationVersion
    \since 1.1
*/
QString QLandmarkManager::buildUri(const QString& managerName, const QMap<QString, QString>& params, int implementationVersion)
{
    QString ret(QLatin1String("qtlandmarks:%1:%2"));
    // we have to escape each param
    QStringList escapedParams;
    QStringList keys = params.keys();
    for (int i=0; i < keys.size(); i++) {
        QString key = keys.at(i);
        QString arg = params.value(key);
        arg = arg.replace(QLatin1Char('&'), QLatin1String("&amp;"));
        arg = arg.replace(QLatin1Char('='), QLatin1String("&equ;"));
        key = key.replace(QLatin1Char('&'), QLatin1String("&amp;"));
        key = key.replace(QLatin1Char('='), QLatin1String("&equ;"));
        key = key + QLatin1Char('=') + arg;
        escapedParams.append(key);
    }

    if (implementationVersion != -1) {
        QString versionString = QString(QLatin1String(QTLANDMARKS_IMPLEMENTATION_VERSION_NAME));
        versionString += QString::fromAscii("=");
        versionString += QString::number(implementationVersion);
        escapedParams.append(versionString);
    }

    return ret.arg(managerName, escapedParams.join(QLatin1String("&")));
}

/*!
  Constructs a QLandmarkManager whose implementation, store and parameters are specified in the given \a storeUri,
  and whose parent object is \a parent.
  \since 1.1
 */
QLandmarkManager* QLandmarkManager::fromUri(const QString& storeUri, QObject* parent)
{
    if (storeUri.isEmpty()) {
        return new QLandmarkManager(QString(), QMap<QString, QString>(), parent);
    } else {
        QString id;
        QMap<QString, QString> parameters;
        if (parseUri(storeUri, &id, &parameters)) {
            return new QLandmarkManager(id, parameters, parent);
        } else {
            // invalid
            return NULL;
        }
    }
}

/*!
  Splits the given \a uri into the manager name and parameters that it describes, and places the information
  into the memory addressed by \a pManagerName and \a pParams respectively.  Returns true if \a uri could be split successfully,
  otherwise returns false
  \since 1.1
 */
bool QLandmarkManager::parseUri(const QString& uri, QString* pManagerName, QMap<QString, QString>* pParams)
{
    // Format: qtlandmarks:<managerid>:<key>=<value>&<key>=<value>
    // - it is assumed the prefix(qtlandmarks) and managerid cannot contain ':'
    // - it is assumed keys and values do not contain '=' or '&'
    //   but can contain &amp; and &equ;
    QStringList colonSplit = uri.split(QLatin1Char(':'));
    QString prefix = colonSplit.value(0);

    if (prefix != QLatin1String("qtlandmarks"))
        return false;

    QString managerName = colonSplit.value(1);

    if (managerName.trimmed().isEmpty())
        return false;

    QString firstParts = prefix + QLatin1Char(':') + managerName + QLatin1Char(':');
    QString paramString = uri.mid(firstParts.length());

    QMap<QString, QString> outParams;

    // Now we have to decode each parameter
    if (!paramString.isEmpty()) {
        QStringList params = paramString.split(QRegExp(QLatin1String("&(?!(amp;|equ;))")), QString::KeepEmptyParts);
        // If we have an empty string for paramstring, we get one entry in params,
        // so skip that case.
        for(int i = 0; i < params.count(); i++) {
            /* This should be something like "foo&amp;bar&equ;=grob&amp;" */
            QStringList paramChunk = params.value(i).split(QLatin1String("="), QString::KeepEmptyParts);

            if (paramChunk.count() != 2)
                return false;

            QString arg = paramChunk.value(0);
            QString param = paramChunk.value(1);
            arg.replace(QLatin1String("&equ;"), QLatin1String("="));
            arg.replace(QLatin1String("&amp;"), QLatin1String("&"));
            param.replace(QLatin1String("&equ;"), QLatin1String("="));
            param.replace(QLatin1String("&amp;"), QLatin1String("&"));
            if (arg.isEmpty())
                return false;
            outParams.insert(arg, param);
        }
    }

    if (pParams)
        *pParams = outParams;
    if (pManagerName)
        *pManagerName = managerName;
    return true;
}

/*!
    \internal
    \since 1.1
*/
void QLandmarkManager::connectNotify(const char *signal)
{

    if (!d_ptr->isConnected) {
        if (d_ptr->engine) {
            if (QLatin1String(signal) == QLatin1String(SIGNAL(landmarksAdded(QList<QLandmarkId>)))
                || (QLatin1String(signal) == QLatin1String(SIGNAL(landmarksChanged(QList<QLandmarkId>))))
                || (QLatin1String(signal) == QLatin1String(SIGNAL(landmarksRemoved(QList<QLandmarkId>))))
                || (QLatin1String(signal) == QLatin1String(SIGNAL(landmarksChanged(QList<QLandmarkId>))))
                || (QLatin1String(signal) == QLatin1String(SIGNAL(categoriesAdded(QList<QLandmarkCategoryId>))))
                || (QLatin1String(signal) == QLatin1String(SIGNAL(categoriesChanged(QList<QLandmarkCategoryId>))))
                || (QLatin1String(signal) == QLatin1String(SIGNAL(categoriesRemoved(QList<QLandmarkCategoryId>))))
                || (QLatin1String(signal) == QLatin1String(SIGNAL(dataChanged())))) {
                connect(d_ptr->engine,SIGNAL(landmarksAdded(QList<QLandmarkId>)),
                        this, SIGNAL(landmarksAdded(QList<QLandmarkId>)));
                connect(d_ptr->engine,SIGNAL(landmarksChanged(QList<QLandmarkId>)),
                        this, SIGNAL(landmarksChanged(QList<QLandmarkId>)));
                connect(d_ptr->engine,SIGNAL(landmarksRemoved(QList<QLandmarkId>)),
                        this, SIGNAL(landmarksRemoved(QList<QLandmarkId>)));
                connect(d_ptr->engine,SIGNAL(categoriesAdded(QList<QLandmarkCategoryId>)),
                        this, SIGNAL(categoriesAdded(QList<QLandmarkCategoryId>)));
                connect(d_ptr->engine,SIGNAL(categoriesChanged(QList<QLandmarkCategoryId>)),
                        this, SIGNAL(categoriesChanged(QList<QLandmarkCategoryId>)));
                connect(d_ptr->engine,SIGNAL(categoriesRemoved(QList<QLandmarkCategoryId>)),
                        this, SIGNAL(categoriesRemoved(QList<QLandmarkCategoryId>)));
                connect(d_ptr->engine,SIGNAL(dataChanged()),
                        this, SIGNAL(dataChanged()));
                d_ptr->isConnected = true;
            }
        }
    }
    QObject::connectNotify(signal);
}

/*!
    \internal
    \since 1.1
*/
void QLandmarkManager::disconnectNotify(const char *signal)
{
    if (d_ptr->isConnected) {
        if (d_ptr->engine) {
            if ((QLatin1String(signal) == QLatin1String(SIGNAL(landmarksAdded(QList<QLandmarkId>))))
                || (QLatin1String(signal) == QLatin1String(SIGNAL(landmarksChanged(QList<QLandmarkId>))))
                || (QLatin1String(signal) == QLatin1String(SIGNAL(landmarksRemoved(QList<QLandmarkId>))))
                || (QLatin1String(signal) == QLatin1String(SIGNAL(categoriesAdded(QList<QLandmarkCategoryId>))))
                || (QLatin1String(signal) == QLatin1String(SIGNAL(categoriesChanged(QList<QLandmarkCategoryId>))))
                || (QLatin1String(signal) == QLatin1String(SIGNAL(categoriesRemoved(QList<QLandmarkCategoryId>))))
                || (QLatin1String(signal) == QLatin1String(SIGNAL(dataChanged())))) {
                disconnect(d_ptr->engine,SIGNAL(landmarksAdded(QList<QLandmarkId>)),
                           this, SIGNAL(landmarksAdded(QList<QLandmarkId>)));
                disconnect(d_ptr->engine,SIGNAL(landmarksChanged(QList<QLandmarkId>)),
                           this, SIGNAL(landmarksChanged(QList<QLandmarkId>)));
                disconnect(d_ptr->engine,SIGNAL(landmarksRemoved(QList<QLandmarkId>)),
                           this, SIGNAL(landmarksRemoved(QList<QLandmarkId>)));
                disconnect(d_ptr->engine,SIGNAL(categoriesAdded(QList<QLandmarkCategoryId>)),
                           this, SIGNAL(categoriesAdded(QList<QLandmarkCategoryId>)));
                disconnect(d_ptr->engine,SIGNAL(categoriesChanged(QList<QLandmarkCategoryId>)),
                           this, SIGNAL(categoriesChanged(QList<QLandmarkCategoryId>)));
                disconnect(d_ptr->engine,SIGNAL(categoriesRemoved(QList<QLandmarkCategoryId>)),
                           this, SIGNAL(categoriesRemoved(QList<QLandmarkCategoryId>)));
                disconnect(d_ptr->engine,SIGNAL(dataChanged()),
                           this, SIGNAL(dataChanged()));
                d_ptr->isConnected = false;
            }
        }
    }
    QObject::disconnectNotify(signal);
}

QLandmarkManagerEngine *QLandmarkManager::engine()
{
    return d_ptr->engine;
}

/*!
    \fn QLandmarkManager::dataChanged()
    This signal is emitted by the manager if its internal state changes and it is unable to precisely determine
    the changes which occurred, or if the manager considers the changes to be radical enough to require clients to reload
    all data.  If the signal is emitted, no other signals will be emitted for the associated changes.
    \since 1.1
*/

/*!
    \fn void QLandmarkManager::landmarksAdded(const QList<QLandmarkId> &landmarkIds)

    This signal is emitted when landmarks (identified by \a landmarkIds) have been added to the datastore managed by this manager.
    This signal is not emitted if the dataChanged() signal was previously emitted for these changes.
    \since 1.1
    \sa landmarksChanged(), landmarksRemoved()
*/

/*!
    \fn void QLandmarkManager::landmarksChanged(const QList<QLandmarkId> &landmarkIds)

    This signal is emitted when landmarks (identified by \a landmarkIds) have been modified in the datastore managed by this manager.
    This signal is not emitted if the dataChanged() signal was previously emitted for these changes.  Note that removal
    of a category will not trigger a \c landmarksChanged signal for landmarks belonging to that category.

    \since 1.1
    \sa landmarksAdded(), landmarksRemoved()
*/

/*!
    \fn void QLandmarkManager::landmarksRemoved(const QList<QLandmarkId> &landmarkIds)

    This signal is emitted when landmarks (identified by \a landmarkIds) have been removed from the datastore managed by this manager.
    This signal is not emitted if the dataChanged() signal was previously emitted for these changes.
    \since 1.1
    \sa landmarksAdded(), landmarksChanged()
*/

/*!
    \fn void QLandmarkManager::categoriesAdded(const QList<QLandmarkCategoryId> &categoryIds)

    This signal is emitted when categories (identified by \a categoryIds) have been added to the datastore managed by this manager.
    This signal is not emitted if the dataChanged() signal was previously emitted for these changes.
    \since 1.1
    \sa categoriesChanged(), categoriesRemoved()
*/

/*!
    \fn void QLandmarkManager::categoriesChanged(const QList<QLandmarkCategoryId> &categoryIds)

    This signal is emitted when categories (identified by \a categoryIds) have been modified in the datastore managed by this manager.
    This signal is not emitted if the dataChanged() signal was previously emitted for these changes.
    \since 1.1
    \sa categoriesAdded(), categoriesRemoved()
*/

/*!
    \fn void QLandmarkManager::categoriesRemoved(const QList<QLandmarkCategoryId> &categoryIds)

    This signal is emitted when categories (identified by \a categoryIds) have been removed from the datastore managed by this manager.
    This signal is not emitted if the dataChanged() signal was previously emitted for these changes.
    \since 1.1
    \sa categoriesAdded(), categoriesChanged()
*/

#include "moc_qlandmarkmanager.cpp"