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 "EventWriters/VMGWriter.h"
21 #include "EventTypes/iVMGEvent.h"
22 #include "EventTypes/iEvent.h"
28 #include <QTextStream>
33 using namespace EventWriters;
35 VMGWriter::VMGWriter(const Settings &settings, const NumberToNameLookup &numberToNameLookup)
36 : m_Settings(settings), m_NumberToNameLookup(numberToNameLookup)
40 void VMGWriter::Write(EventTypes::iEvent &event)
42 EventTypes::iVMGEvent *vmgEvent(dynamic_cast<EventTypes::iVMGEvent *>(&event));
45 // Build the path and ensure it exists...
46 QString eventFilename(CurrentSettings().Directory());
47 eventFilename += vmgEvent->PathForVMG();
48 QDir().mkpath(eventFilename);
50 // ...then build the filename and open it.
51 eventFilename += QString::number(event.Timestamp().toUTC().toTime_t()) + ".vmg";
52 QFile data(eventFilename);
53 if (data.open(QFile::WriteOnly | QFile::Truncate))
55 QTextStream stream(&data);
57 //QTextCodec *oldCodec = stream.codec();
58 stream.setAutoDetectUnicode(false);
59 stream.setCodec("UTF-16LE");
61 vmgEvent->WriteVMG(stream, NameLookup());
67 fileTimes.modtime = event.Timestamp().toUTC().toTime_t();
68 utime(eventFilename.toAscii(), &fileTimes);