2 * Copyright (C) 2011, Jamie Thompson
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; If not, see
16 * <http://www.gnu.org/licenses/>.
19 #include "VEnvelope.h"
24 #include <QTextStream>
28 using namespace EventParsers::VMGEntities;
30 VEnvelope::VEnvelope(const SMSEntity* parent) :
35 //VEnvelope::VEnvelope(QTextStream& stream)
39 VEnvelope::~VEnvelope()
41 foreach(iWriter *contentWriter, m_ContentWriters)
44 m_ContentWriters.empty();
47 void VEnvelope::Write(QTextStream &stream, const EventTypes::SMS &event)
49 stream << "BEGIN:" << getTagName() << "\n";
51 foreach(iWriter *contentWriter, m_ContentWriters)
52 contentWriter->Write(stream, event);
54 stream << "END:" << getTagName() << "\n";
57 bool VEnvelope::Read(const QString &initialLine, QTextStream &stream, EventTypes::SMS &event)
61 // Stream may or may not have a 'BEGIN' present. Swallow it if it's ours.
62 QString lineData(initialLine.length() > 0 ? initialLine : stream.readLine());
63 if(lineData.startsWith("BEGIN:"))
65 if(lineData != QString("BEGIN:") + getTagName())
67 qDebug() << "Invalid stream";
70 else // ...discard this line
71 lineData = stream.readLine();
76 if(lineData.startsWith("BEGIN:"))
78 iReader* reader = Factory::Instantiate(lineData, this);
79 bool valid(NULL != reader && reader->Read(lineData, stream, event));
82 // Quit processing if the nested content is not valid
86 else if(lineData.startsWith("END:"))
88 if(lineData != QString("END:") + getTagName())
90 qDebug() << getTagName() << " parser mismatch error" << lineData;
100 lineData = stream.readLine();
101 }while(!hasEnded && !stream.atEnd());
105 //event.fld_is_read = isRead;
106 //event.fld_outgoing = isOutgoing;
107 //event.fld_start_time = timestamp.toUTC().toTime_t();