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 "CSVSymbianEventLogWriter.h"
21 #include "EventTypes/iCSVSymbianEvent.h"
22 #include "EventTypes/iEvent.h"
29 #include <QTextStream>
34 using namespace EventWriters;
36 CSVSymbianEventLogWriter::CSVSymbianEventLogWriter(const Settings &settings, const NumberToNameLookup &numberToNameLookup)
37 : m_Settings(settings), m_NumberToNameLookup(numberToNameLookup), m_Stream(NULL), m_Delimiter('|'), m_File(NULL)
39 m_Headers << "EType" << "ETime" << "DType" << "Flag1" << "Flag2" << "Flag3"
40 << "Flag4" << "Id" << "Remote" << "Direction" << "Duration"
41 << "Status" << "Subject" << "Number" << "Contact" << "Link"
42 << "Data" << "Recent" << "Duplicate";
45 CSVSymbianEventLogWriter::~CSVSymbianEventLogWriter()
59 // Build the strings filepath
60 QString stringsFilename(CurrentSettings().Directory());
61 stringsFilename += "/Call Logs/Strings.csv";
63 QFile stringsFile(stringsFilename);
64 if (stringsFile.open(QFile::WriteOnly | QFile::Truncate))
66 QTextStream stream(&stringsFile);
67 stream.setAutoDetectUnicode(false);
68 stream.setCodec("UTF-16LE");
74 void CSVSymbianEventLogWriter::Write(EventTypes::iEvent &event)
76 EventTypes::iCSVSymbianEvent *csvEvent(dynamic_cast<EventTypes::iCSVSymbianEvent *>(&event));
82 csvEvent->WriteCSVSymbian(*Stream(), Headers(), Delimiter(), NameLookup(), Strings());
86 void CSVSymbianEventLogWriter::OpenStream()
88 // Build the path and ensure it exists...
89 QString eventFilename(CurrentSettings().Directory());
90 eventFilename += "/Call Logs";
91 QDir().mkpath(eventFilename);
93 // ...then build the filename and open it.
94 eventFilename += "/Symbian Event Log.csv";
95 File(new QFile(eventFilename));
96 if (File()->open(QFile::WriteOnly | QFile::Truncate))
98 Stream(new QTextStream(File()));
99 Stream()->setAutoDetectUnicode(false);
100 Stream()->setCodec("UTF-16LE");
106 void CSVSymbianEventLogWriter::WriteHeaders()
108 foreach(QString header, Headers())
111 if(Headers().back() != header)
117 void CSVSymbianEventLogWriter::WriteStrings(QTextStream &stringsStream)
119 foreach(QString string, Strings().keys())
120 stringsStream << "\"" << string << "\"|" << Strings().value(string) << endl;