#include <QDebug>
#include <QDateTime>
#include "EventLog.h"


void EventLog::LogMessage(const char* a_location, const char* a_message)
{
  qWarning() << a_message;

  Transaction transaction(*this);
  EventLogItem item;
  QString timeStr = QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss.zzz");
  item.m_dateTime = timeStr.toUtf8().data();
  item.m_location = a_location;
  item.m_message = a_message;
  push_back(item);
}


void EventLog::LogError(const char* a_location, const char* a_error)
{
  qWarning() << a_error;

  Transaction transaction(*this);
  EventLogItem item;
  QString timeStr = QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss.zzz");
  item.m_dateTime = timeStr.toUtf8().data();
  item.m_location = a_location;
  item.m_message = a_error;
  item.m_message = "Error: " + item.m_message;
  push_back(item);
}


QVariant EventLogItem::value(int a_column) const
{
  switch (a_column)
  {
  case 0:
    return QDateTime::fromString(m_dateTime.c_str(), "dd/MM/yyyy hh:mm:ss.zzz");
  case 1:
    return m_location.c_str();
  case 2:
    return m_message.c_str();
  }
  return "Bad column index";
}

