1
/****************************************************************************
5
** Copyright © 2011 Aleksey Sidorov <gorthauer87@yandex.ru>
7
*****************************************************************************
9
** $JREEN_BEGIN_LICENSE$
10
** This program is free software: you can redistribute it and/or modify
11
** it under the terms of the GNU General Public License as published by
12
** the Free Software Foundation, either version 2 of the License, or
13
** (at your option) any later version.
15
** This program is distributed in the hope that it will be useful,
16
** but WITHOUT ANY WARRANTY; without even the implied warranty of
17
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
** See the GNU General Public License for more details.
20
** You should have received a copy of the GNU General Public License
21
** along with this program. If not, see http://www.gnu.org/licenses/.
22
** $JREEN_END_LICENSE$
24
****************************************************************************/
26
#ifndef VCARDFACTORY_P_H
27
#define VCARDFACTORY_P_H
29
#include "stanzaextension.h"
33
class JREEN_AUTOTEST_EXPORT VCardFactoryPrivate;
35
class AbstractStructureParser : public XmlStreamParser
38
AbstractStructureParser(const QLatin1String &name);
39
bool canParse(const QStringRef &name, const QStringRef &uri, const QXmlStreamAttributes &attributes);
40
void handleStartElement(const QStringRef &name, const QStringRef &uri, const QXmlStreamAttributes &attributes);
41
void handleEndElement(const QStringRef &name, const QStringRef &uri);
42
void handleCharacterData(const QStringRef &text);
44
void serialize(void *zero, void *data, QXmlStreamWriter *writer);
45
void addByteArray(const QLatin1String &name, QByteArray *str);
46
void addString(const QLatin1String &name, QString *str);
47
void addFlag(const char **table, int size, int *value);
49
void addFlag(const char *(&table)[N], int *value)
50
{ addFlag(table, N, value); }
62
QList<QPair<QLatin1String, QString*> > m_strings;
63
QList<QPair<QLatin1String, QByteArray*> > m_byteArrays;
64
QList<FlagInfo> m_flags;
66
QString *m_currentString;
67
QByteArray *m_currentArray;
71
class StructureParser : public AbstractStructureParser
74
StructureParser(const QLatin1String &name) : AbstractStructureParser(name) {}
75
T create() { return m_data; }
76
void serialize(const T &data, QXmlStreamWriter *writer)
77
{ AbstractStructureParser::serialize(&m_data, const_cast<T*>(&data), writer); }
83
template <typename TPrivate, typename T>
84
class StructurePrivateParser : public AbstractStructureParser
87
StructurePrivateParser(const QLatin1String &name) : AbstractStructureParser(name) {}
88
T create() { return T(*new TPrivate(m_data)); }
89
void serialize(const T &data, QXmlStreamWriter *writer)
91
TPrivate *t1 = &m_data;
92
TPrivate *t2 = const_cast<TPrivate*>(TPrivate::get(&data));
93
AbstractStructureParser::serialize(t1, t2, writer);
100
class JREEN_AUTOTEST_EXPORT VCardFactory : public PayloadFactory<VCard>
102
Q_DECLARE_PRIVATE(VCardFactory)
105
virtual ~VCardFactory();
106
QStringList features() const;
107
bool canParse(const QStringRef &name, const QStringRef &uri, const QXmlStreamAttributes &attributes);
108
void handleStartElement(const QStringRef &name, const QStringRef &uri, const QXmlStreamAttributes &attributes);
109
void handleEndElement(const QStringRef &name, const QStringRef &uri);
110
void handleCharacterData(const QStringRef &text);
111
void serialize(Payload *extension, QXmlStreamWriter *writer);
112
Payload::Ptr createPayload();
114
QScopedPointer<VCardFactoryPrivate> d_ptr;
130
#endif // VCARDFACTORY_P_H