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 "PhoneCall.h"
21 #include "Attachment.h"
22 #include "DBBackends/RtcomEventLogger.h"
23 #include "EventParsers/CSVSymbianEventLogParser.h"
24 #include "NumberToNameLookup.h"
33 #include <QTextStream>
37 #include <rtcom-eventlogger/event.h>
38 #include <rtcom-eventlogger/eventlogger-attach-iter.h>
40 using namespace EventTypes;
42 const DBBackends::iDBBackend &PhoneCall::DB() const
44 return DBBackends::RtcomEventLogger(CurrentSettings(), *this);
47 PhoneCall::PhoneCall(const Settings &settings) :
52 PhoneCall::~PhoneCall()
54 foreach(QSharedPointer<Attachment> attachment, m_Attachments)
60 PhoneCall::PhoneCall(const Settings &settings, const RTComElEvent &event, const QList<RTComElAttachment*> attachments) :
63 setDestination(event.fld_outgoing ? OUTGOING : INCOMING);
64 setTimestamp(QDateTime::fromTime_t(event.fld_start_time).toUTC());
65 setDurationInSeconds(QDateTime::fromTime_t(event.fld_start_time).toUTC().secsTo(QDateTime::fromTime_t(event.fld_end_time).toUTC()));
66 setTel(event.fld_remote_uid);
67 if(Tel().indexOf("0") == 0)
68 setTel(QString(Tel()).replace(QRegExp("^0"), "+44"));
70 // We directly access the m_Attachments member variable here rather than the
71 // accessor as the accessor is const
72 if(attachments.count() > 0)
73 foreach(RTComElAttachment *attachment, attachments)
74 Attachments().append(new Attachment(*attachment));
77 const uint PhoneCall::HashCode() const
79 // qDebug() << Timestamp().toUTC().toTime_t() << ", " << qHash(Tel()) << ", " << qHash(Destination()) << ", " << qHash(Contents()) << ", " << Attachments().HashCode();
81 // foreach(QChar c, Contents().toUtf8())
83 // qDebug() << c.unicode();
87 Timestamp().toUTC().toTime_t() ^
90 qHash(Destination()) ^
91 Attachments().HashCode();
94 RTComElEvent * PhoneCall::toRTComEvent(const NumberToNameLookup &numberToNameLookup) const
96 QList<QString> voiceMailList;
98 QString groupId((Tel().length() < 7 || Tel().indexOf(QRegExp("[:alpha:]+")) > -1)
102 RTComElEvent *event(rtcom_el_event_new());
103 memset(event, 0, sizeof(RTComElEvent));
105 RTCOM_EL_EVENT_SET_FIELD (event, service, g_strdup("RTCOM_EL_SERVICE_CALL"));
106 if(voiceMailList.contains(Tel()))
107 RTCOM_EL_EVENT_SET_FIELD (event, event_type, g_strdup("RTCOM_EL_EVENTTYPE_CALL_VOICEMAIL"));
109 RTCOM_EL_EVENT_SET_FIELD (event, event_type, g_strdup("RTCOM_EL_EVENTTYPE_CALL"));
110 RTCOM_EL_EVENT_SET_FIELD (event, storage_time, Timestamp().toUTC().toTime_t());
111 RTCOM_EL_EVENT_SET_FIELD (event, start_time, Timestamp().toUTC().toTime_t());
112 RTCOM_EL_EVENT_SET_FIELD (event, end_time, Timestamp().toUTC().toTime_t());
113 //RTCOM_EL_EVENT_SET_FIELD (event, is_read, 0);
114 RTCOM_EL_EVENT_SET_FIELD (event, outgoing, Destination() == PhoneCall::OUTGOING ? 1 : 0);
115 RTCOM_EL_EVENT_SET_FIELD (event, local_uid, g_strdup("ring/tel/ring"));
116 //RTCOM_EL_EVENT_SET_FIELD (&event, local_name, g_strdup("<SelfHandle>"));
117 RTCOM_EL_EVENT_SET_FIELD (event, remote_uid, g_strdup(Tel().toUtf8()));
118 //RTCOM_EL_EVENT_SET_FIELD (&event, remote_name, g_strdup(QString::number(numberToNameLookup.ContactDetails().value(Tel()).second).toUtf8()));
119 RTCOM_EL_EVENT_SET_FIELD (event, remote_ebook_uid, g_strdup(QString::number(numberToNameLookup.ContactDetails().value(Tel()).first).toUtf8()));
120 RTCOM_EL_EVENT_SET_FIELD (event, group_uid, g_strdup(groupId.toUtf8()));
121 //RTCOM_EL_EVENT_SET_FIELD (event, free_text, g_strdup(Contents().replace(0x2029, "\n").toUtf8()));
122 //RTCOM_EL_EVENT_SET_FIELD (event, free_text, g_strdup(Contents().toUtf8()));
127 void PhoneCall::Export(const QString &baseDirectory) const
129 // // Build the path and ensure it exists...
130 // QString eventFilename(baseDirectory);
131 // eventFilename += Destination() == EventTypes::PhoneCall::OUTGOING ? "/Sent/" : "/Inbox/";
132 // eventFilename += QString::number(Timestamp().toUTC().date().year()) + "/";
133 // QDir().mkpath(eventFilename);
135 // // ...then build the filename and open it.
136 // eventFilename += QString::number(Timestamp().toUTC().toTime_t()) + ".vmg";
137 // QFile data(eventFilename);
138 // if (data.open(QFile::WriteOnly | QFile::Truncate))
140 // QTextStream stream(&data);
142 // QTextCodec *oldCodec = stream.codec();
143 // stream.setAutoDetectUnicode(false);
144 // stream.setCodec("UTF-16LE");
146 // EventParsers::VMGEntities::VMessage writer(NULL, 1.1);
147 // writer.Write(stream, *this);
148 ////stream << "Test";
149 // //stream.setCodec(oldCodec);
153 // utimbuf fileTimes;
154 // fileTimes.modtime = Timestamp().toUTC().toTime_t();
155 // utime(eventFilename.toAscii(), &fileTimes);
159 QDebug operator<<(QDebug dbg, PhoneCall& event)
161 dbg.nospace() << "\tFolder:\t\t" << (event.Destination() == PhoneCall::OUTGOING ? "Sent" : "Inbox") << "\n";
162 dbg.nospace() << "\tTimestamp:\t" << event.Timestamp().toUTC() << "\n";
163 dbg.nospace() << "\tDuration:\t" << event.DurationInSeconds() << "\n";
164 dbg.nospace() << "\tRemote-Tel:\t" << event.Tel() << "\n";
165 //dbg.nospace() << "\tremote-name:\t" << event.fld_remote_name << "\n";