1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtVersit module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34#ifndef QVERSITCONTACTIMPORTER_P_H
35#define QVERSITCONTACTIMPORTER_P_H
36
37//
38// W A R N I N G
39// -------------
40//
41// This file is not part of the Qt API. It exists purely as an
42// implementation detail. This header file may change from version to
43// version without notice, or even be removed.
44//
45// We mean it.
46//
47
48#include <QtCore/qdatetime.h>
49#include <QtCore/qhash.h>
50#include <QtCore/qlist.h>
51#include <QtCore/qmap.h>
52#include <QtCore/qpair.h>
53
54#include <QtContacts/qcontact.h>
55#include <QtContacts/qcontactdetail.h>
56
57#include <QtVersit/qversitcontactimporter.h>
58#include <QtVersit/private/qvcardrestorehandler_p.h>
59
60QT_BEGIN_NAMESPACE_CONTACTS
61class QContactOrganization;
62QT_END_NAMESPACE_CONTACTS
63
64QTCONTACTS_USE_NAMESPACE
65
66QT_BEGIN_NAMESPACE_VERSIT
67
68class QVersitProperty;
69class QVersitDocument;
70class QVersitContactHandler;
71
72class QVersitContactImporterPrivate
73{
74public:
75 QVersitContactImporterPrivate(const QStringList& profiles = QStringList());
76 ~QVersitContactImporterPrivate();
77
78 bool importContact(const QVersitDocument& versitDocument, int contactIndex,
79 QContact* contact, QVersitContactImporter::Error* error);
80
81private:
82 void importProperty(const QVersitDocument& document, const QVersitProperty& property, int contactIndex, QContact* contact);
83 bool createName(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
84 bool createPhone(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
85 bool createAddress(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
86 bool createOrganization(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
87 void setOrganizationNames(QContactOrganization& org, const QVersitProperty& property) const;
88 void setOrganizationLogo(QContactOrganization& org, const QVersitProperty& property) const;
89 bool createTimeStamp(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
90 bool createVersion(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
91 bool createAnniversary(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
92 bool createBirthday(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
93 bool createDisplaylabel(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
94 bool createNicknames(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
95 bool createTags(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
96 bool createOnlineAccount(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
97 bool createRingtone(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
98 bool createAvatar(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
99 bool createGeoLocation(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
100 bool createFamily(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
101 bool createFavorite(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
102 bool createNameValueDetail(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
103 bool createGender(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
104 bool createExtendedDetail(const QVersitProperty& property, QContact* contact, QList<QContactDetail>* updatedDetails);
105 QList<int> extractContexts(const QVersitProperty& property) const;
106 QStringList extractSubTypes(const QVersitProperty& property) const;
107 QString takeFirst(QList<QString>& list) const;
108 QDateTime parseDateTime(QString text, bool *justDate = 0) const;
109 QString saveContentToFile(const QVersitProperty& property, const QByteArray& data) const;
110 bool saveDataFromProperty(const QVersitProperty& property, QString* location, QByteArray* data) const;
111 void saveDetailWithContext(QList<QContactDetail>* updatedDetails, QContactDetail detail, const QList<int>& contexts);
112
113public: // Data
114 QList<QContact> mContacts;
115 QMap<int, QVersitContactImporter::Error> mErrors;
116 QVersitContactImporterPropertyHandler* mPropertyHandler;
117 QVersitContactImporterPropertyHandlerV2* mPropertyHandler2;
118 QList<QVersitContactHandler*> mPluginPropertyHandlers;
119 int mPropertyHandlerVersion;
120 QVersitDefaultResourceHandler* mDefaultResourceHandler;
121 QVersitResourceHandler* mResourceHandler;
122 QVCardRestoreHandler mRestoreHandler;
123
124 QHash<QString, QPair<QContactDetail::DetailType, int> > mDetailMappings;
125 QMultiHash<QString, QPair<QContactDetail::DetailType, int> > mSubTypeMappings;
126 QHash< int ,QString> mContextMappings;
127};
128
129QT_END_NAMESPACE_VERSIT
130
131#endif // QVERSITCONTACTIMPORTER_P_H
132

source code of qtpim/src/versit/qversitcontactimporter_p.h