Added CSV parsing and export of Symbian-format Event logs that have had their tables...
[qwerkisync] / EventTypes / SMS.cpp
index e147c8d..c067fe6 100644 (file)
 #include "NumberToNameLookup.h"
 #include "Settings.h"
 
-#include <QDateTime>
-#include <QDir>
-#include <QFile>
-#include <QList>
 #include <QRegExp>
 #include <QString>
 #include <QTextStream>
 
-#include <utime.h>
-
 #include <rtcom-eventlogger/event.h>
 #include <rtcom-eventlogger/eventlogger-attach-iter.h>
 
@@ -127,36 +121,96 @@ RTComElEvent * SMS::toRTComEvent(const NumberToNameLookup &numberToNameLookup) c
        return event;
 }
 
-void SMS::Export(const QString &baseDirectory, const NumberToNameLookup &numberToNameLookup) const
+void SMS::WriteCSVSymbian(QTextStream &stream, const ColumnIndicesByIndexHash &headerIndices, const QChar delimiter, const NumberToNameLookup &numberToNameLookup, SymbianEventLogStrings &strings) const
 {
-       // Build the path and ensure it exists...
-       QString eventFilename(baseDirectory);
-       eventFilename += Destination() == EventTypes::SMS::SENT ? "/Sent/" : "/Inbox/";
-       eventFilename += QString::number(Timestamp().toUTC().date().year()) + "/";
-       QDir().mkpath(eventFilename);
-
-       // ...then build the filename and open it.
-       eventFilename += QString::number(Timestamp().toUTC().toTime_t()) + ".vmg";
-       QFile data(eventFilename);
-       if (data.open(QFile::WriteOnly | QFile::Truncate))
+       // 0|05/09/2007 11:25:12 am|1||||||<name>|3|8|0|0|<number>|||Unrecognized||
+       for(uint columnIndex(0); columnIndex < headerIndices.count(); ++columnIndex)
        {
-               QTextStream stream(&data);
-
-               QTextCodec *oldCodec = stream.codec();
-               stream.setAutoDetectUnicode(false);
-               stream.setCodec("UTF-16LE");
-
-               EventParsers::VMGEntities::VMessage writer(CurrentSettings(), NULL, 1.1);
-               writer.Write(stream, *this, numberToNameLookup);
-//stream << "Test";
-               //stream.setCodec(oldCodec);
-               stream.flush();
-               data.close();
-
-               utimbuf fileTimes;
-               fileTimes.modtime = Timestamp().toUTC().toTime_t();
-               utime(eventFilename.toAscii(), &fileTimes);
+               const QString &heading(headerIndices.value(columnIndex));
+               if("etype" == heading.toLower())
+               {
+                       stream << "3"; // SMSes are type '3'
+               }
+               else if("etime" == heading.toLower())
+               {
+                       stream << Timestamp().toUTC().toString("dd/MM/yyyy h:mm:ss ap");
+               }
+               else if("remote" == heading.toLower())
+               {
+                       stream << numberToNameLookup.ContactDetails().value(Tel()).second;
+               }
+               else if("direction" == heading.toLower())
+               {
+                       if(Settings::OUTGOING == Destination())
+                       {
+                               if(!strings.contains("Outgoing"))
+                                       strings.insert("Outgoing", strings.count());
+                               stream << strings.value("Outgoing");
+                       }
+                       else if (Settings::INCOMING == Destination())
+                       {
+                               if(!strings.contains("Incoming"))
+                                       strings.insert("Incoming", strings.count());
+                               stream << strings.value("Incoming");
+                       }
+               }
+               else if("duration" == heading.toLower())
+               {
+                       stream << "0"; // SMSes are always 0
+               }
+               else if("dtype" == heading.toLower())
+               {
+                       stream << "-1"; // -1 seems to match KLogDurationNone
+               }
+               else if("status" == heading.toLower())
+               {
+                       stream << "0"; // Always '0' for phone calls.
+               }
+               else if("subject" == heading.toLower())
+               {
+                       // Subject seems to be ignored - this makes sense, but I
+                       // suspect that non-zero values are a bug that I can't duplicate...
+                       stream << "0";
+               }
+               else if("number" == heading.toLower())
+               {
+                       stream << Tel();
+               }
+               else if("data" == heading.toLower())
+               {
+                       // Event-specfic data - but not supported by DBU-SCV tool
+                       // Hex editing the DBU suggests there is SIP account info in here...
+                       // ...along the lines of:
+                       // "VOIP.URL=sip:<remote#>@<remote domain>.MA=sip:<my#>@<my domain>"
+                       stream << "Unrecognised";
+               }
+               else
+               {
+                       // Don't print anything. Makes it obvious which fields we've
+                       // generated.
+               }
+
+               if(columnIndex < headerIndices.count() - 1)
+                       stream << delimiter;
        }
+
+       stream << endl;
+}
+
+const QString SMS::PathForVMG() const
+{
+       QString eventPath("/sms");
+       eventPath += Destination() == EventTypes::SMS::SENT ? "/Sent/" : "/Inbox/";
+       eventPath += QString::number(Timestamp().toUTC().date().year()) + "/";
+
+       return eventPath;
+}
+
+void SMS::WriteVMG(QTextStream &stream, const NumberToNameLookup &numberToNameLookup) const
+{
+       EventParsers::VMGEntities::VMessage writer(CurrentSettings(), NULL, 1.1);
+       writer.Write(stream, *this, numberToNameLookup);
+       stream.flush();
 }
 
 QDebug operator<<(QDebug dbg, SMS& event)